-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
250 lines (223 loc) · 9.21 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace StokTkip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string conString = "Data Source=DESKTOP-POJFHO5;Initial Catalog=StokTKP;Integrated Security=True";
SqlConnection baglantı = new SqlConnection(conString);
DataSet dsat = new DataSet();
private void hesapla()
{
//toplam fiyat
try
{
baglantı.Open();
SqlCommand komut = new SqlCommand("select sum(toplamfiyati) from sepet ", baglantı);
lblgeneltop.Text = komut.ExecuteScalar() + "TL";
baglantı.Close();
}
catch (Exception)
{
throw;
}
}
private void sepetlistelem()
{
//kayıt yenileme için
baglantı.Open();
SqlDataAdapter adtr = new SqlDataAdapter("select *from sepet", baglantı);
adtr.Fill(dsat, "sepet");
dataGridView1.Columns[0].Visible = false;//ilk üç sutunu gizlemek için kullanıldı
dataGridView1.Columns[1].Visible = false;
dataGridView1.Columns[2].Visible = false;
dataGridView1.DataSource = dsat.Tables["sepet"];
baglantı.Close();
}
private void button5_Click(object sender, EventArgs e)
{
frmMusteriEkle ekle = new frmMusteriEkle();
ekle.ShowDialog();
}
private void Form1_Load(object sender, EventArgs e)
{
sepetlistelem();
}
private void button6_Click(object sender, EventArgs e)
{
MusteriListeleme LİSTE = new MusteriListeleme();
LİSTE.ShowDialog();
}
private void button11_Click(object sender, EventArgs e)
{
Kategori ktg = new Kategori();
ktg.ShowDialog();
}
private void button10_Click(object sender, EventArgs e)
{
Marka mrk = new Marka();
mrk.ShowDialog();
}
private void button8_Click(object sender, EventArgs e)
{
ÜrünListeleme asda = new ÜrünListeleme();
asda.ShowDialog();
}
private void txttc_TextChanged(object sender, EventArgs e)
{
//tc ye göre arama yaptırıp müşteri bilgileri almak
if (txttc.Text == "")
{
txtadsyd.Text = "";
txttel.Text = "";
}
baglantı.Open();
SqlCommand komut = new SqlCommand("select *from musteri where tc like '" + txttc.Text + "'", baglantı);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
txtadsyd.Text = read["adsoyad"].ToString();
txttel.Text = read["telefon"].ToString();
}
}
private void txtbarkod_TextChanged(object sender, EventArgs e)
{
//barkod no ya bağlı olarak ürün bilgisi çekme
//eğere girilen değer txtmktr değilse diğerlerini temizlet
temizle();
baglantı.Open();
SqlCommand komut = new SqlCommand("select *from urun where tc like '" + txtbarkod.Text + "'", baglantı);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
txturn.Text = read["ürünadı"].ToString();
txtsts.Text = read["satısfiyati"].ToString();
}
}
private void temizle()
{
//
if (txtbarkod.Text == "")
{
foreach (Control item in groupBox2.Controls)
{
if (item != txtmktr)
{
item.Text = "";
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
//sepetten ürün çıkarma
baglantı.Open();
SqlCommand komut = new SqlCommand("delete from sepet", baglantı);
komut.ExecuteNonQuery();
baglantı.Close();
MessageBox.Show("ürünler sepeten çıkarıldı");
dsat.Tables["sepet"].Clear();
sepetlistelem();
hesapla();
}
private void button3_Click(object sender, EventArgs e)
{
//sepete veri ekleme
baglantı.Open();
SqlCommand komut = new SqlCommand("insert into sepet(tc, adsoyad,barkodno,urunadı,miktarı,satısfiyati,toplamfiyati,tarih) values(@tc, @adsoyad,@barkodno,@urunadı,@miktarı,@satısfiyati,@toplamfiyati,@tarih)", baglantı);
komut.Parameters.AddWithValue("@tc", txttc.Text);
komut.Parameters.AddWithValue("@adsoyad", txtadsyd.Text);
komut.Parameters.AddWithValue("@barkodno", txtbarkod.Text);
komut.Parameters.AddWithValue("@urunadı", txturn.Text);
komut.Parameters.AddWithValue("@miktarı", int.Parse(txtmktr.Text));
komut.Parameters.AddWithValue("@satısfiyati", int.Parse(txtsts.Text));
komut.Parameters.AddWithValue("@toplamfiyati", int.Parse(txttpl.Text));
komut.Parameters.AddWithValue("@telefon", DateTime.Now.ToString());
komut.ExecuteNonQuery();
baglantı.Close();
hesapla();
dsat.Tables["tables"].Clear();
sepetlistelem();
temizle();
}
private void txtmktr_TextChanged(object sender, EventArgs e)
{//miktarı ve satış fiyatı çarpma toplam fiyatı vermesi için
try
{
txttpl.Text = (double.Parse(txtmktr.Text) * double.Parse(txtsts.Text)).ToString();
}
catch (Exception)
{
throw;
}
}
private void txtsts_TextChanged(object sender, EventArgs e)
{
try
{
txttpl.Text = (double.Parse(txtmktr.Text) * double.Parse(txtsts.Text)).ToString();
}
catch (Exception)
{
throw;
}
}
private void button1_Click(object sender, EventArgs e)
{
//kayıt silme işlemi
baglantı.Open();
SqlCommand komut = new SqlCommand("delete from sepet where barkodno='" + dataGridView1.CurrentRow.Cells["barkodno"].Value.ToString() + "'", baglantı);
komut.ExecuteNonQuery();
baglantı.Close();
MessageBox.Show("kayıt silindi");
hesapla();
dsat.Tables["sepet"].Clear();
sepetlistelem();
}
private void button9_Click(object sender, EventArgs e)
{
Satıslisteleme st = new Satıslisteleme();
st.ShowDialog();
}
private void button4_Click(object sender, EventArgs e)
{// satış işlemi aynı zamanda stoktan düşmede yapılıyor
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
baglantı.Open();
SqlCommand komut = new SqlCommand("insert into satıs(tc, adsoyad,barkodno,urunadı,miktarı,satısfiyati,toplamfiyati,tarih) values(@tc, @adsoyad,@barkodno,@urunadı,@miktarı,@satısfiyati,@toplamfiyati,@tarih)", baglantı);
komut.Parameters.AddWithValue("@tc", txttc.Text);
komut.Parameters.AddWithValue("@adsoyad", txtadsyd.Text);
komut.Parameters.AddWithValue("@barkodno", dataGridView1.Rows[i].Cells["barkodno"].Value.ToString());//kaç kayıt varsa aktarmak için
komut.Parameters.AddWithValue("@urunadı", dataGridView1.Rows[i].Cells["urunadı"].Value.ToString());
komut.Parameters.AddWithValue("@miktarı", int.Parse(dataGridView1.Rows[i].Cells["miktarı"].Value.ToString()));
komut.Parameters.AddWithValue("@satısfiyati", int.Parse(dataGridView1.Rows[i].Cells["satısfiyati"].Value.ToString()));
komut.Parameters.AddWithValue("@toplamfiyati", int.Parse(dataGridView1.Rows[i].Cells["toplamfiyati "].Value.ToString()));
komut.Parameters.AddWithValue("@telefon", DateTime.Now.ToString());
komut.ExecuteNonQuery();
SqlCommand komut2 = new SqlCommand("update urun set mikarı=mikarı-'" + int.Parse(dataGridView1.Rows[i].Cells["miktarı"].Value.ToString()) + "' where barkodno'" + dataGridView1.Rows[i].Cells["barkodno"].Value.ToString() + "'", baglantı);
komut2.ExecuteNonQuery();
baglantı.Close();
}
//bütün kayıtları silip hesap, sepetlistesinin güncel halini çağırıyor
baglantı.Open();
SqlCommand komut3 = new SqlCommand("delete from sepet", baglantı);
komut3.ExecuteNonQuery();
baglantı.Close();
hesapla();
dsat.Tables["tables"].Clear();
sepetlistelem();
}
}
}