-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrmSiparisler.cs
285 lines (265 loc) · 12.2 KB
/
frmSiparisler.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RestoranOtomasyonu
{
public partial class frmSiparisler : Form
{
public int MasaKodu, MasaNumarasi, MasaDurumu;
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter adpt = new OleDbDataAdapter();
DataSet ds = new DataSet();
public frmSiparisler()
{
InitializeComponent();
}
private void btnGoBack_Click(object sender, EventArgs e)
{
frmMasalar form_Masalar = new frmMasalar();
form_Masalar.Show();
this.Hide();
}
private void CountButtons(object sender, EventArgs e)
{
Button btn = sender as Button;
if (txtCount.Text == "0" && btn.Text != "C" && txtCount.Text.Length < 4)
{
txtCount.Text = btn.Text;
}
else if (txtCount.Text != "0" && btn.Text != "C" && txtCount.Text.Length < 4)
{
txtCount.Text = txtCount.Text + btn.Text;
}
else if (btn.Text == "C")
{
txtCount.Text = "0";
}
}
private void frmSiparisler_Load(object sender, EventArgs e)
{
this.Text = "Masa " + MasaNumarasi;
con.ConnectionString = cDataController.ConnectionString;
dgvProducts.ForeColor = Color.Black;
if (con.State == ConnectionState.Closed) con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT KategoriKodu,KategoriAdi FROM Kategoriler";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Kategoriler");
lbCategories.DataSource = ds.Tables["Kategoriler"];
lbCategories.DisplayMember = "KategoriAdi";
lbCategories.ValueMember = "KategoriKodu";
cmd.CommandText = "SELECT UrunKodu AS [Ürün Kodu], KategoriKodu AS [Kategori Kodu], UrunAdi AS [Ürün Adı], Fiyat FROM Urunler";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Ürünler");
dgvProducts.DataSource = ds.Tables["Ürünler"];
dgvProducts.Columns["Kategori Kodu"].Visible = false;
dgvProducts.Columns["Ürün Kodu"].Visible = false;
dgvProducts.Columns["Ürün Adı"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataColumn[] keyColumns = new DataColumn[1];
keyColumns[0] = ds.Tables["Ürünler"].Columns["Ürün Kodu"];
ds.Tables["Ürünler"].PrimaryKey = keyColumns;
if (MasaDurumu == 1 || MasaDurumu == 3)
{
btnCancel.Visible = false;
btnPay.Visible = false;
}
else if (MasaDurumu == 2)
{
btnCancel.Visible = true;
btnPay.Visible = true;
AdisyonCek();
}
lbCategories_SelectedIndexChanged(sender, e);
}
private void lbCategories_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new OleDbCommand();
if (ds.Tables["Ürünler"] != null) ds.Tables["Ürünler"].Clear();
if (con.State == ConnectionState.Closed) con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT UrunKodu AS [Ürün Kodu], KategoriKodu AS [Kategori Kodu], UrunAdi AS [Ürün Adı], Fiyat FROM Urunler WHERE KategoriKodu=@kkodu";
cmd.Parameters.AddWithValue("@kkodu",lbCategories.SelectedValue.ToString());
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Ürünler");
dgvProducts.DataSource = ds.Tables["Ürünler"];
txtSearch.Text = "";
}
private void dgvProducts_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
decimal ToplamFiyat = int.Parse(txtCount.Text) * decimal.Parse(dgvProducts.CurrentRow.Cells["Fiyat"].Value.ToString());
if (txtCount.Text != "0")
{
bool KayitVar = false;
for (int i = 0; i < lvOrders.Items.Count; i++)
{
if (lvOrders.Items[i].Text == dgvProducts.CurrentRow.Cells["Ürün Adı"].Value.ToString())
{
KayitVar = true;
lvOrders.Items[i].SubItems[1].Text = (Convert.ToInt32(lvOrders.Items[i].SubItems[1].Text) + int.Parse(txtCount.Text)).ToString();
lvOrders.Items[i].SubItems[2].Text = (int.Parse(lvOrders.Items[i].SubItems[1].Text) * decimal.Parse(dgvProducts.CurrentRow.Cells["Fiyat"].Value.ToString())).ToString();
}
}
if (!KayitVar)
{
lvOrders.Items.Add(dgvProducts.CurrentRow.Cells["Ürün Adı"].Value.ToString());
lvOrders.Items[lvOrders.Items.Count - 1].SubItems.Add(txtCount.Text);
lvOrders.Items[lvOrders.Items.Count - 1].SubItems.Add(ToplamFiyat.ToString());
lvOrders.Items[lvOrders.Items.Count - 1].SubItems.Add(dgvProducts.CurrentRow.Cells["Ürün Kodu"].Value.ToString());
}
AraToplamHesapla();
}
txtCount.Text = "1";
}
private void lvOrders_DoubleClick(object sender, EventArgs e)
{
if (lvOrders.SelectedItems != null)
{
lvOrders.Items.Remove(lvOrders.SelectedItems[0]);
AraToplamHesapla();
}
}
void AraToplamHesapla()
{
decimal Fiyat = 0.0m;
foreach (ListViewItem urun in lvOrders.Items)
{
Fiyat += decimal.Parse(urun.SubItems[2].Text.ToString());
}
lblAraToplam.Text = Fiyat.ToString() + " TL";
}
private void btnOrder_Click(object sender, EventArgs e)
{
if (lvOrders.Items.Count == 0)
{
MessageBox.Show("Sipariş alabilmeniz için öncelikle ürünlerin üzerine çift\ntıklayarak siparişler listesine eklemeniz gerekmektedir.", "Hata");
}
else if (lvOrders.Items.Count > 0 && (MasaDurumu == 1 || MasaDurumu == 3))
{
AdisyonYaz();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Masalar SET Durum=2 WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
cmd.ExecuteNonQuery();
btnCancel.Visible = true;
btnPay.Visible = true;
MessageBox.Show("Sipariş eklenmiş ve masa dolu olarak işaretlenmiştir.", "Bilgilendirme");
}
else if (lvOrders.Items.Count > 0 && MasaDurumu == 2)
{
DialogResult dR = MessageBox.Show("Masanın mevcut siparişlerini değiştirdiyseniz veya sildiyseniz bu işlemin geri alınamayacağını unutmayınız.\nBu işlemi gerçekleştirmek istediğinize emin misiniz?", "Uyarı", MessageBoxButtons.YesNo);
if (dR == DialogResult.Yes)
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "DELETE FROM Adisyon WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
cmd.ExecuteNonQuery();
AdisyonYaz();
}
}
}
void AdisyonCek()
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM Adisyon WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Adisyon");
for (int i = 0; i < ds.Tables["Adisyon"].Rows.Count; i++)
{
DataRow satir = ds.Tables["Ürünler"].Rows.Find(ds.Tables["Adisyon"].Rows[i]["UrunKodu"]);
lvOrders.Items.Add(satir["Ürün Adı"].ToString());
lvOrders.Items[i].SubItems.Add(ds.Tables["Adisyon"].Rows[i]["UrunAdet"].ToString());
int Fiyat = int.Parse(ds.Tables["Adisyon"].Rows[i]["UrunAdet"].ToString()) * int.Parse(satir["Fiyat"].ToString());
lvOrders.Items[i].SubItems.Add(Fiyat.ToString());
lvOrders.Items[i].SubItems.Add(satir["Ürün Kodu"].ToString());
}
AraToplamHesapla();
}
void UrunAra()
{
if (ds.Tables["Ürünler"] != null) ds.Tables["Ürünler"].Clear();
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT UrunKodu AS [Ürün Kodu], KategoriKodu AS [Kategori Kodu], UrunAdi AS [Ürün Adı], Fiyat FROM Urunler WHERE UrunAdi Like '%" + txtSearch.Text + "%'";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Ürünler");
dgvProducts.DataSource = ds.Tables["Ürünler"];
}
void AdisyonYaz()
{
for (int i = 0; i < lvOrders.Items.Count; i++)
{
if (con.State == ConnectionState.Closed) con.Open();
int Day = DateTime.Now.Day;
int Month = DateTime.Now.Month;
int Year = DateTime.Now.Year;
int Hour = DateTime.Now.Hour;
int Minute = DateTime.Now.Minute;
int Second = DateTime.Now.Second;
string Tarih = Day + "." + Month + "." + Year + " " + Hour + ":" + Minute + ":" + Second;
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "INSERT INTO Adisyon(PersonelKodu,UrunKodu,MasaKodu,UrunAdet,Tarih) VALUES(@pkodu,@ukodu,@mkodu,@uadet,@tarih)";
cmd.Parameters.AddWithValue("@pkodu", frmLogin.PersonelKodu);
cmd.Parameters.AddWithValue("@ukodu", int.Parse(lvOrders.Items[i].SubItems[3].Text));
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
cmd.Parameters.AddWithValue("@uadet", int.Parse(lvOrders.Items[i].SubItems[1].Text));
cmd.Parameters.AddWithValue("@tarih", Tarih);
cmd.ExecuteNonQuery();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult dR = MessageBox.Show("Bu masanın siparişleri iptal edilecektir ve masa boşa çıkarılacaktır.\nOnaylıyor musunuz?", "Uyarı", MessageBoxButtons.YesNo);
if (dR == DialogResult.Yes)
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "DELETE FROM Adisyon WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Masalar SET Durum=1 WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", MasaKodu);
cmd.ExecuteNonQuery();
lvOrders.Items.Clear();
btnCancel.Visible = false;
btnPay.Visible = false;
AraToplamHesapla();
}
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
UrunAra();
}
private void btnPay_Click(object sender, EventArgs e)
{
frmPay form_Pay = new frmPay();
form_Pay.MasaKodu = MasaKodu;
form_Pay.MasaNumarasi = MasaNumarasi;
form_Pay.Show();
this.Hide();
}
}
}