-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmSwapTables.cs
182 lines (170 loc) · 7.54 KB
/
frmSwapTables.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
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.OleDb;
namespace RestoranOtomasyonu
{
public partial class frmSwapTables : Form
{
OleDbConnection con = new OleDbConnection(cDataController.ConnectionString);
OleDbDataAdapter adpt = new OleDbDataAdapter();
OleDbCommand cmd = new OleDbCommand();
DataSet ds = new DataSet();
public frmSwapTables()
{
InitializeComponent();
}
private void frmSwapTables_Load(object sender, EventArgs e)
{
MasalariCek();
}
void MasalariCek()
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
if (ds.Tables["Boş Masalar"] == null || ds.Tables["Boş Masalar"].Rows.Count == 0)
{
cmd.CommandText = "SELECT * FROM Masalar WHERE Durum=1 ORDER BY MasaNumarasi";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Boş Masalar");
}
if (ds.Tables["Dolu Masalar 1"] == null || ds.Tables["Dolu Masalar 1"].Rows.Count == 0 || ds.Tables["Dolu Masalar 2"] == null || ds.Tables["Dolu Masalar 2"].Rows.Count == 0)
{
cmd.CommandText = "SELECT * FROM Masalar WHERE Durum=2 ORDER BY MasaNumarasi";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Dolu Masalar 1");
adpt.Fill(ds, "Dolu Masalar 2");
}
if (rbDolu.Checked)
{
lbSecondTable.DataSource = ds.Tables["Dolu Masalar 2"];
lbSecondTable.ValueMember = "MasaKodu";
lbSecondTable.DisplayMember = "MasaNumarasi";
}
else if (rbBos.Checked)
{
lbSecondTable.DataSource = ds.Tables["Boş Masalar"];
lbSecondTable.ValueMember = "MasaKodu";
lbSecondTable.DisplayMember = "MasaNumarasi";
}
lbFirstTable.DataSource = ds.Tables["Dolu Masalar 1"];
lbFirstTable.ValueMember = "MasaKodu";
lbFirstTable.DisplayMember = "MasaNumarasi";
}
private void RadioButtonStateChange(object sender, EventArgs e)
{
if (ds.Tables["Boş Masalar"] != null) ds.Tables["Boş Masalar"].Clear();
if (ds.Tables["Dolu Masalar 1"] != null) ds.Tables["Dolu Masalar 1"].Clear();
if (ds.Tables["Dolu Masalar 2"] != null) ds.Tables["Dolu Masalar 2"].Clear();
MasalariCek();
Kontrol();
}
void Kontrol()
{
if (lbFirstTable.SelectedItem != null && lbSecondTable.SelectedItem != null && lbFirstTable.SelectedValue.ToString() == lbSecondTable.SelectedValue.ToString())
{
btnPay.Enabled = false;
btnPay.BackColor = Color.FromArgb(2, 46, 48);
}
else
{
btnPay.Enabled = true;
btnPay.BackColor = Color.FromArgb(0, 173, 181);
}
}
private void btnGoBack_Click(object sender, EventArgs e)
{
frmMasalar form_Masalar = new frmMasalar();
form_Masalar.Show();
this.Hide();
}
private void lbFirstTable_SelectedIndexChanged(object sender, EventArgs e)
{
Kontrol();
}
private void lbSecondTable_SelectedIndexChanged(object sender, EventArgs e)
{
Kontrol();
}
private void btnSwap_EnabledChanged(object sender, EventArgs e)
{
lblWarning.Visible = !lblWarning.Visible;
}
private void btnSwap_Click(object sender, EventArgs e)
{
if (rbBos.Checked)
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Adisyon SET MasaKodu=@ymkodu WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@ymkodu",lbSecondTable.SelectedValue);
cmd.Parameters.AddWithValue("@mkodu", lbFirstTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Masalar SET Durum=1 WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbFirstTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Masalar SET Durum=2 WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbSecondTable.SelectedValue);
cmd.ExecuteNonQuery();
MessageBox.Show("Masa " + lbFirstTable.Text + ", Masa "+lbSecondTable.Text+"'ye taşınmıştır.", "Bilgi");
frmMasalar frm = new frmMasalar();
frm.Show();
this.Hide();
}
else if (rbDolu.Checked)
{
if (con.State == ConnectionState.Closed) con.Open();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "INSERT INTO MasaTasima SELECT * FROM Adisyon WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbFirstTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "DELETE FROM Adisyon WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbFirstTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Adisyon SET MasaKodu=@ymkodu WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@ymkodu", lbFirstTable.SelectedValue);
cmd.Parameters.AddWithValue("@mkodu", lbSecondTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE MasaTasima SET MasaKodu=@ymkodu WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@ymkodu", lbSecondTable.SelectedValue);
cmd.Parameters.AddWithValue("@mkodu", lbFirstTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "INSERT INTO Adisyon SELECT * FROM MasaTasima WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbSecondTable.SelectedValue);
cmd.ExecuteNonQuery();
cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "DELETE FROM MasaTasima WHERE MasaKodu=@mkodu";
cmd.Parameters.AddWithValue("@mkodu", lbSecondTable.SelectedValue);
cmd.ExecuteNonQuery();
MessageBox.Show("Masa " + lbFirstTable.Text + " ile Masa "+lbSecondTable.Text+" değiştirilmiştir.", "Bilgi");
frmMasalar frm = new frmMasalar();
frm.Show();
this.Hide();
}
}
}
}