-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfFee.cs
283 lines (212 loc) · 10 KB
/
fFee.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
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;
using System.Configuration;
namespace Thuc_Tap_CSDL
{
public partial class fFee : Form
{
public fFee()
{
InitializeComponent();
}
SqlConnection con;
private void fFee_Load(object sender, EventArgs e)
{
string conString = ConfigurationManager.ConnectionStrings["QLTrungTamHocThem"].ConnectionString.ToString();
con = new SqlConnection(conString);
con.Open();
loadCombobox();
}
public void Display(string code)
{
SqlCommand cmd = new SqlCommand(code, con);
SqlDataReader dataReader = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(dataReader);
dgvFee.DataSource = dataTable;
}
public void autoLoadBillID()
{
string sqlCode = "SELECT TOP(1) MaBLThuHP FROM BLTHUHP ORDER BY MaBLThuHP DESC";
SqlCommand cmd = new SqlCommand(sqlCode, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
int id = Convert.ToInt32(dr.GetValue(0).ToString().Substring(7)) + 1;
string ID = "";
if (id < 100) ID = "0" + id.ToString();
else ID = id.ToString();
txtFeeBill_id.Text = "BLTHUHP" + ID;
}
dr.Close();
}
public void Display1(string code)
{
SqlCommand cmd = new SqlCommand(code, con);
SqlDataReader dataReader = cmd.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Load(dataReader);
dgvFee_bill.DataSource = dataTable;
}
private void dgvFee_bill_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int i;
i = dgvFee_bill.CurrentRow.Index;
txtFeeBill_id.Text = dgvFee_bill.Rows[i].Cells[0].Value.ToString();
txtFeeBill_studentID.Text = dgvFee_bill.Rows[i].Cells[1].Value.ToString();
txtFeeBill_classID.Text = dgvFee_bill.Rows[i].Cells[2].Value.ToString();
txtFeeBill_sumDay.Text = dgvFee_bill.Rows[i].Cells[3].Value.ToString();
txtFeeBill_feePerDay.Text = dgvFee_bill.Rows[i].Cells[4].Value.ToString();
txtFeeBill_sumFee.Text = dgvFee_bill.Rows[i].Cells[5].Value.ToString();
//txtFeeBill_dateTake.Text = convertDate(dgvFee_bill.Rows[i].Cells[6].Value.ToString())
txtFeeBill_dateTake.Text = dgvFee_bill.Rows[i].Cells[6].Value.ToString();
txtFeeBill_takeForDate.Text = dgvFee_bill.Rows[i].Cells[7].Value.ToString();
if (dgvFee_bill.Rows[i].Cells[8].Value.ToString() == "1") ckbTaked.Checked = true;
else ckbTaked.Checked = false;
}
private void ckbTaked_CheckedChanged(object sender, EventArgs e)
{
if (ckbTaked.Checked)
ckbTaked.Text = "đã thu";
else
ckbTaked.Text = "chưa thu";
}
private void btnFeeBill_add_Click(object sender, EventArgs e)
{
string isCheck = "";
if (ckbTaked.Checked) isCheck = "1";
else isCheck = "0";
string sqlInsert = "exec PROC_INSERT_BLTHUHP '" + txtFeeBill_id.Text + "','" + txtFeeBill_studentID.Text + "','" + txtFeeBill_classID.Text + "','" + txtFeeBill_sumDay.Text + "','" + txtFeeBill_feePerDay.Text + "', '" + txtFeeBill_sumFee.Text + "','" + txtFeeBill_dateTake.Text + "','" + txtFeeBill_takeForDate.Text + "', '" + isCheck + "'";
SqlCommand cmd = new SqlCommand(sqlInsert, con);
cmd.ExecuteNonQuery();
string sqlCode = "select top(20) * from BLTHUHP where MaHocSinh = '" + txtFeeBill_studentID.Text + "' order by NgayThu desc";
Display1(sqlCode);
btnFeeBill_add.Enabled = false;
}
private void btnFeeBill_edit_Click(object sender, EventArgs e)
{
string isCheck = "";
if (ckbTaked.Checked) isCheck = "1";
else isCheck = "0";
string sqlEdit = "exec PROC_UPDATE_BLTHUHP '" + txtFeeBill_id.Text + "','" + txtFeeBill_studentID.Text + "','" + txtFeeBill_classID.Text + "','" + txtFeeBill_sumDay.Text + "','" + txtFeeBill_feePerDay.Text + "', '" + txtFeeBill_sumFee.Text + "','" + txtFeeBill_dateTake.Text + "','" + txtFeeBill_takeForDate.Text + "', '" + isCheck + "' ";
SqlCommand cmd = new SqlCommand(sqlEdit, con);
cmd.ExecuteNonQuery();
string sqlCode = "select top(20) * from BLTHUHP where MaHocSinh = '" + txtFeeBill_studentID.Text + "' order by NgayThu desc";
Display1(sqlCode);
}
private void btnFeeBill_delete_Click(object sender, EventArgs e)
{
string sqlDelete = "exec PROC_DELETE_BLTHUHP '" + txtFeeBill_id.Text + "'";
SqlCommand cmd = new SqlCommand(sqlDelete, con);
cmd.ExecuteNonQuery();
string sqlCode = "select top(20) * from BLTHUHP where MaHocSinh = '" + txtFeeBill_studentID.Text + "' order by NgayThu desc";
Display1(sqlCode);
}
//func sql
public string getSumDay(string ClassID, string StudentID, string months)
{
string result = "";
string sqlCode = "select * from FUNC_TINH_TONGSOBUOI('" + ClassID + "','" + StudentID + "','" + months + "')";
SqlCommand cmd = new SqlCommand(sqlCode, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result = dr.GetValue(0).ToString();
}
dr.Close();
return result;
}
//func sql
public string getFeePerDay(string ClassID)
{
string result = "";
string sqlCode = "SELECT SoHocPhi FROM MUCHOCPHI, LOPHOC WHERE MUCHOCPHI.MaMHP = LOPHOC.MaMHP and MaLopHoc = '" + ClassID + "'";
SqlCommand cmd = new SqlCommand(sqlCode, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result = dr.GetValue(0).ToString();
}
dr.Close();
return result;
}
//func sql
public string getSumFee(string feePerDay, string sumDay)
{
return (int.Parse(feePerDay) * int.Parse(sumDay)).ToString();
}
//func sql
public string convertDate(string date)
{
string[] info = date.Split('/');
return info[1] + "/" + info[0] + "/" + info[2];
}
private void dgvFee_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int i;
i = dgvFee.CurrentRow.Index;
autoLoadBillID(); //MaBienLai
txtFeeBill_studentID.Text = dgvFee.Rows[i].Cells[0].Value.ToString(); //MaHocSinh
txtFeeBill_classID.Text = txtFeeSearch.Text; //MaLopHoc
txtFeeBill_feePerDay.Text = getFeePerDay(txtFeeBill_classID.Text); //HocPhi/Buoi
txtFeeBill_dateTake.Text = DateTime.Now.ToString("MM/dd/yyyy"); //NgayThu
txtFeeBill_takeForDate.Text = (DateTime.Now.Month - 1).ToString(); //ThuChoThangNam
txtFeeBill_sumDay.Text = getSumDay(txtFeeBill_classID.Text, txtFeeBill_studentID.Text, txtFeeBill_takeForDate.Text); //TongSoBuoi
txtFeeBill_sumFee.Text = getSumFee(txtFeeBill_feePerDay.Text, txtFeeBill_sumDay.Text); //TongHocPhi
string sqlCode = "select top(20) * from BLTHUHP where MaHocSinh = '" + txtFeeBill_studentID.Text + "' order by NgayThu desc";
Display1(sqlCode);
btnFeeBill_add.Enabled = true;
}
public void loadCombobox()
{
var sqlCode = "Select TenLopHoc from LOPHOC";
SqlCommand cmd = new SqlCommand(sqlCode, con);
///cmd.ExecuteNonQuery();
var dr = cmd.ExecuteReader();
var dt = new DataTable();
dt.Load(dr);
dr.Dispose();
cbbMLH.ValueMember = "TenLopHoc";
cbbMLH.DataSource = dt;
}
private void cbbMLH_SelectedIndexChanged(object sender, EventArgs e)
{
string sqlCode = "SELECT MaLopHoc FROM LOPHOC WHERE TenLopHoc = '" + cbbMLH.SelectedValue.ToString() + "'";
SqlCommand cmd = new SqlCommand(sqlCode, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
txtFeeSearch.Text = dr.GetValue(0).ToString();
}
dr.Close();
string sqlCode2 = "select MaHocSinh, TenHocSinh from FUNC_LIST_STUDENT_CLASS('" + txtFeeSearch.Text + "')";
Display(sqlCode2);
}
private void btnFeeBill_Export_Click(object sender, EventArgs e)
{
fBillStudent form = new fBillStudent(txtFeeBill_id.Text,
txtFeeBill_studentID.Text,
txtFeeBill_classID.Text,
txtFeeBill_sumDay.Text,
txtFeeBill_feePerDay.Text,
txtFeeBill_sumFee.Text,
txtFeeBill_dateTake.Text,
txtFeeBill_takeForDate.Text);
form.ShowDialog();
}
private void btnApply_Click(object sender, EventArgs e)
{
if (txtFeeBill_takeForDate.Text == "") txtFeeBill_takeForDate.Text = "0";
txtFeeBill_sumDay.Text = getSumDay(txtFeeBill_classID.Text, txtFeeBill_studentID.Text, txtFeeBill_takeForDate.Text); //TongSoBuoi
txtFeeBill_sumFee.Text = getSumFee(txtFeeBill_feePerDay.Text, txtFeeBill_sumDay.Text); //TongHocPhi
}
}
}