-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmPersonel.cs
238 lines (215 loc) · 9.15 KB
/
frmPersonel.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
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 frmPersonel : Form
{
cDataController Controller = new cDataController();
OleDbConnection con = new OleDbConnection(cDataController.ConnectionString);
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter adpt = new OleDbDataAdapter();
DataSet ds = new DataSet();
BindingSource bs = new BindingSource();
bool YeniKayitMi = false;
public frmPersonel()
{
InitializeComponent();
}
private void frmPersonel_Load(object sender, EventArgs e)
{
GorevCek();
PersonelCek();
txtName.ReadOnly = true;
txtSurname.ReadOnly = true;
cbTask.Enabled = false;
txtTC.ReadOnly = true;
txtUsername.ReadOnly = true;
txtPassword.ReadOnly = true;
btnSave.Enabled = false;
btnCancel.Enabled = false;
bs.DataSource = ds.Tables["Personeller"];
dataGridView1.DataSource = bs;
dataGridView1.Columns["PersonelKodu"].Visible = false;
dataGridView1.Columns["GorevKodu"].Visible = false;
lblPersonelKodu.DataBindings.Add("Text",bs,"PersonelKodu");
txtName.DataBindings.Add("Text", bs, "Adı");
txtSurname.DataBindings.Add("Text", bs, "Soyadı");
cbTask.DataBindings.Add("Text", bs, "Görev");
txtTC.DataBindings.Add("Text", bs, "TCNO");
txtUsername.DataBindings.Add("Text", bs, "Kullanıcı Adı");
txtPassword.DataBindings.Add("Text", bs, "Parola");
}
// Personel tablosunu getir
void PersonelCek()
{
if (con.State == ConnectionState.Closed) con.Open();
if (ds.Tables["Personeller"] != null) ds.Tables["Personeller"].Clear();
if (ds.Tables["Personeller1"] != null) ds.Tables["Personeller1"].Clear();
cmd.Connection = con;
cmd.CommandText = "SELECT PersonelKodu,Personel.GorevKodu,Gorevler.Aciklama as [Görev],TCNO,Adi as [Adı],Soyadi as [Soyadı],KullaniciAdi as [Kullanıcı Adı],Parola,SonGiris as [Son Giriş] FROM Personel,Gorevler WHERE Personel.GorevKodu=Gorevler.GorevKodu";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Personeller");
adpt.Fill(ds, "Personeller1");
}
// Personel tablosundan ARAMA yaparak veri çek
void PersonelCek(string SearchText)
{
if (con.State == ConnectionState.Closed) con.Open();
if (ds.Tables["Personeller"] != null) ds.Tables["Personeller"].Clear();
cmd.Connection = con;
cmd.CommandText = "SELECT PersonelKodu,Personel.GorevKodu,Gorevler.Aciklama as [Görev],TCNO,Adi as [Adı],Soyadi as [Soyadı],KullaniciAdi as [Kullanıcı Adı],Parola,SonGiris as [Son Giriş] FROM Personel,Gorevler WHERE (Personel.GorevKodu=Gorevler.GorevKodu) and (Adi Like '%" + SearchText + "%' or Soyadi Like '%" + SearchText + "%' or KullaniciAdi Like '%" + SearchText + "%' or SonGiris Like '%" + SearchText + "%' or Gorevler.Aciklama Like '%" + SearchText + "%' or TCNO Like '%" + SearchText + "%')";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Personeller");
}
// Veritabanından görev tiplerini çek
void GorevCek()
{
if (con.State == ConnectionState.Closed) con.Open();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM Gorevler";
adpt = new OleDbDataAdapter(cmd);
cmd.ExecuteNonQuery();
adpt.Fill(ds, "Görevler");
cbTask.DataSource = ds.Tables["Görevler"];
cbTask.ValueMember = "GorevKodu";
cbTask.DisplayMember = "Aciklama";
}
// Giriş alanlarının KAPALI/AÇIK kontrolleri
void Fields(bool State)
{
btnSave.Enabled = State;
btnCancel.Enabled = State;
btnNew.Enabled = !State;
btnActions.Enabled = !State;
btnEdit.Enabled = !State;
btnDelete.Enabled = !State;
txtName.ReadOnly = !State;
txtSurname.ReadOnly = !State;
cbTask.Enabled = State;
txtTC.ReadOnly = !State;
txtUsername.ReadOnly = !State;
txtPassword.ReadOnly = !State;
}
private void DisabledColorChange(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn.Enabled) btn.BackColor = Color.FromArgb(0, 173, 181);
else btn.BackColor = Color.FromArgb(2, 82, 86);
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
PersonelCek(txtSearch.Text);
if (dataGridView1.Rows.Count == 0)
{
btnNew.Enabled = false;
btnEdit.Enabled = false;
btnDelete.Enabled = false;
btnActions.Enabled = false;
}
else
{
btnNew.Enabled = true;
btnEdit.Enabled = true;
btnDelete.Enabled = true;
btnActions.Enabled = true;
}
}
private void btnNew_Click(object sender, EventArgs e)
{
YeniKayitMi = true;
Fields(true);
txtName.Text = "";
txtSurname.Text = "";
txtTC.Text = "";
txtUsername.Text = "";
txtPassword.Text = "";
}
private void btnEdit_Click(object sender, EventArgs e)
{
YeniKayitMi = false;
Fields(true);
}
private void btnDelete_Click(object sender, EventArgs e)
{
DialogResult dR = MessageBox.Show("Bu personeli gerçekten silmek istiyor musunuz?\nUyarı: Personelin tüm kayıtlı hareketleri silinecektir.", "Uyarı", MessageBoxButtons.YesNo);
if (dR == DialogResult.Yes)
{
cmd.CommandText = "DELETE FROM PersonelHareketleri WHERE PersonelKodu=@pkodu";
cmd.Parameters.AddWithValue("@pkodu", int.Parse(lblPersonelKodu.Text));
cmd.ExecuteNonQuery();
cmd.CommandText = "DELETE FROM Personel WHERE PersonelKodu=@pkodu";
cmd.Parameters.AddWithValue("@pkodu", int.Parse(lblPersonelKodu.Text));
cmd.ExecuteNonQuery();
MessageBox.Show("Seçilmiş olan personel ve kayıtlı hareketleri silindi!","Bilgilendirme");
PersonelCek();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Fields(false);
PersonelCek();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (Controller.Connection.State == ConnectionState.Closed) Controller.Connection.Open();
int GorevKodu = int.Parse(cbTask.SelectedValue.ToString());
int PersonelKodu = int.Parse(lblPersonelKodu.Text);
bool kadi = false;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (ds.Tables["Personeller1"].Rows[i]["Kullanıcı Adı"].ToString() == txtUsername.Text)
{
kadi = true;
}
}
if (txtName.Text.Trim() == "" || txtSurname.Text.Trim() == "" || txtTC.Text.Trim() == "" || txtUsername.Text.Trim() == "" || txtPassword.Text.Trim() == "")
{
MessageBox.Show("Alanlar boş olamaz!", "Hata");
}
else
{
if (kadi && YeniKayitMi)
{
MessageBox.Show("Kullanıcı adı zaten var!", "Hata");
}
else
{
if (YeniKayitMi)
{
Controller.Insert_Personel(GorevKodu, txtTC.Text, txtName.Text, txtSurname.Text, txtUsername.Text, txtPassword.Text);
MessageBox.Show("Personel başarıyla eklenmiştir.", "Bilgilendirme");
}
else
{
Controller.Update_Personel(GorevKodu, txtTC.Text, txtName.Text, txtSurname.Text, txtUsername.Text, txtPassword.Text, PersonelKodu);
MessageBox.Show("Personel başarıyla düzenlenmiştir.", "Bilgilendirme");
}
Fields(false);
PersonelCek();
}
}
}
private void btnGoBack_Click(object sender, EventArgs e)
{
frmMain main = new frmMain();
main.Show();
this.Hide();
}
private void btnActions_Click(object sender, EventArgs e)
{
frmActions ac = new frmActions();
ac.PersonelKodu = int.Parse(lblPersonelKodu.Text);
ac.Show();
}
}
}