-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddEmployee.cs
204 lines (185 loc) · 9.29 KB
/
AddEmployee.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
namespace FighyGym2
{
public partial class AddEmployee : DevExpress.XtraEditors.XtraUserControl
{
private static AddEmployee _instance;
Database db = new Database();
DataTable tbl = new DataTable();
public static AddEmployee Instance
{
get
{
if (_instance == null)
_instance = new AddEmployee();
return _instance;
}
}
public AddEmployee()
{
InitializeComponent();
}
//private void AutoNumber()
//{
// string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
// // ds.Clear();
// SqlConnection conn = new SqlConnection(ConString);
// SqlDataAdapter da = new SqlDataAdapter("select max (ID) from Tbl_eshtrackat", conn);
// DataSet ds = new DataSet();
// da.Fill(ds, "Tbl_eshtrackat");
// // firstName.DataSource = ds.Tables[0].DefaultView;
// // firstName.DisplayMember = ds.Tables[0].Columns["Employee_Id"].ToString();
// // firstName.DisplayMember = ds.Tables[1].Columns["Employee_Name"].ToString();
// //tbl.Clear();
// //tbl = db.readData("", "");
// if (ds.Tables[0].Rows[0][0].ToString() == "")
// {
// txtID.Text = "1";
// }
// else
// {
// txtID.Text = (Convert.ToInt16(ds.Tables[0].Rows[0][0]) + 1).ToString();
// //(Convert.ToInt32(tbl.Rows[0][0]) + 1).ToString();
// }
// // firstName.Clear();
// // txtEmpname.Clear();
// // txtName.Clear();
// // txtPenStatus.Clear();
// //txtratio.Clear();
// btnDelete.Enabled = false;
// //// btnNew.Enabled = true;
// btnSave.Enabled = false;
// btnAdd.Enabled = true;
//}
private void btnAdd_Click(object sender, EventArgs e)
{
string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
SqlConnection cnn = new SqlConnection(ConString);
SqlCommand sc, insertStudent, scd, cscd3;
cnn.Open();
// string datecurrent = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// string datecreatinAccount = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
// string sql = "INSERT INTO [dbo].[Tbl_eshtrackat] ([ID] ,[Student_id],[From] ,[To] ,[emp_id] ,[class_name],mount) values ('" + txtID.Text + "','" + firstName.SelectedValue + "','" + date1 + "', '" + date2 + "','" + txtEmpname.SelectedValue + "','" + typecourse.Text + "','" + txtMony.Text + "')";
DataTable tblemp = new DataTable();
tblemp = db.readData("SELECT [Employee_Id],[Employee_Name] ,[Phone_Number] ,[Employee_Job] FROM [fightGym].[dbo].[Employees] where Employee_Name='"+txtEmpname.Text+"'", "");
if(tblemp.Rows.Count > 0)
{
MessageBox.Show("تم حفظ الموظف سابقاً ");
return;
}
else
{
string sql = "INSERT INTO[dbo].[Employees]([Employee_Name] ,[Phone_Number] ,[Employee_Job] ) VALUES('" + txtEmpname.Text + "','" + txtPhonNumb.Text + "','" + comboBox1.Text + "')";
try
{
//cnn.Open();
// MessageBox.Show("Data Saved..");
sc = new SqlCommand(sql, cnn);
sc.ExecuteNonQuery();
sc.Dispose();
MessageBox.Show("تم الحفظ بنجاح");
// AutoNumber();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
tbl = db.readData("SELECT [Employee_Name] ,[Phone_Number],[Employee_Job] FROM [fightGym].[dbo].[Employees] where Employee_Name like N'%" +texname.Text+ "%'", "");
try
{
txtPhonNumb.Text = tbl.Rows[0][1].ToString();
txtEmpname.Text = tbl.Rows[0][0].ToString();
comboBox1.Text= tbl.Rows[0][2].ToString();
btnDelete.Enabled = true;
//// btnNew.Enabled = true;
btnSave.Enabled = true;
btnAdd.Enabled = true;
// }
}
catch (Exception) { }
}
private void btnSave_Click(object sender, EventArgs e)
{
//date2 = To.Value.ToString("yyyy-MM-dd");
string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
SqlConnection cnn = new SqlConnection(ConString);
SqlCommand sc, insertStudent, scd, cscd3;
cnn.Open();
// string datecurrent = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// string datecreatinAccount = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
// string sql = "INSERT INTO [dbo].[Tbl_eshtrackat] ([ID] ,[Student_id],[From] ,[To] ,[emp_id] ,[class_name]) values ('" + txtID.Text + "','" + firstName.SelectedValue + "','" + date1 + "', '" + date2 + "','" + txtEmpname.SelectedValue + "','" + typecourse.Text + "')";
// string sql = "UPDATE [dbo].[Tbl_eshtrackat] set Student_id='" + firstName.SelectedValue + "', [From]='" + date1 + "', [To]='" + date2 + "' , emp_id='" + txtEmpname.SelectedValue + "',class_name='" + typecourse.Text + "',mount='" + txtMony.Text + "' where Tbl_eshtrackat.[ID]='" + txtID.Text + "' ";
if (txtEmpname.Text == "") { }
else
{
string sql = "UPDATE [dbo].[Employees] SET [Employee_Name] = '" + txtEmpname.Text + "' ,[Phone_Number] = '" + txtPhonNumb.Text + "' ,[Employee_Job] = '" + comboBox1.Text + "' WHERE Employee_Name='" + txtEmpname.Text + "'";
try
{
//cnn.Open();
// MessageBox.Show("Data Saved..");
sc = new SqlCommand(sql, cnn);
sc.ExecuteNonQuery();
sc.Dispose();
MessageBox.Show("تم التعديل بنجاح");
// AutoNumber();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
//date2 = To.Value.ToString("yyyy-MM-dd");
if (MessageBox.Show("هل انت متاكد من المسح ", "تأكيد", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
string ConString = System.Configuration.ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ConnectionString;
SqlConnection cnn = new SqlConnection(ConString);
SqlCommand sc, insertStudent, scd, cscd3;
cnn.Open();
// string datecurrent = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// string datecreatinAccount = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
// string sql = "INSERT INTO [dbo].[Tbl_eshtrackat] ([ID] ,[Student_id],[From] ,[To] ,[emp_id] ,[class_name]) values ('" + txtID.Text + "','" + firstName.SelectedValue + "','" + date1 + "', '" + date2 + "','" + txtEmpname.SelectedValue + "','" + typecourse.Text + "')";
// string sql = "UPDATE [dbo].[Tbl_eshtrackat] set Student_id='" + firstName.SelectedValue + "', [From]='" + date1 + "', [To]='" + date2 + "' , emp_id='" + txtEmpname.SelectedValue + "',class_name='" + typecourse.Text + "',mount='" + txtMony.Text + "' where Tbl_eshtrackat.[ID]='" + txtID.Text + "' ";
if (txtEmpname.Text == "") { }
else
{
string sql = "Delete from [dbo].[Employees] WHERE Phone_Number='" + txtPhonNumb.Text + "'";
try
{
//cnn.Open();
// MessageBox.Show("Data Saved..");
sc = new SqlCommand(sql, cnn);
sc.ExecuteNonQuery();
sc.Dispose();
MessageBox.Show("تم الحذف بنجاح");
// AutoNumber();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
private void AddEmployee_Load(object sender, EventArgs e)
{
}
}
}