appendix - bc.msu.ac.th

153
194

Upload: others

Post on 23-Mar-2022

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: appendix - bc.msu.ac.th

194

������ก

Page 2: appendix - bc.msu.ac.th

195

������ก ก ��� �ก������������ก��

Page 3: appendix - bc.msu.ac.th

1. ����ก�� Visual Studio

1.1 Visual Studio 2008 ���� DVD ��� ���� !�����"#�$�% ก'()"#�$!*�ก$+,-�,�.�/��/0 ,$1+*%,�2�%�0.

��"#$% ก

1.2 ($ก��.�()"#�$!*�ก$+3���42135"��,6!7$�+�8ก$+,-�,�.� ����3���"!+'( ��"�92ก,�:"�92ก I have read and accept C

��"#$% ก

��� �ก������������ก��

Visual Studio 2008

1.1 Visual Studio 2008 ()2D*� �+*%�88 DVD �����.�"4+9E2�/0E(),-�,�.�,�2�!$1$+F2�$���� ���� !�����"#�$�% ก'()"#�$!*�ก$+,-�,�.�/��/0 ,$1+*%,�2�%�0.

��"#$% ก-1 "#�$!*�ก$+,-�,�.�3%+�ก+1 Visual Studio 2008

($ก��.�()"#�$!*�ก$+3���42135"��,6!7$�+�8ก$+,-�,�.� ����3���"!+'( ��"�92กI have read and accept C ���:4�-ก%GH1 Next "59E2�%D��#�.�,2�,�2�%

��"#$% ก-2 ก$+3���42135"��,6!7$�+�8ก$+,-�,�.�

196

�����.�"4+9E2�/0E(),-�,�.�,�2�!$1$+F2�$�

Visual Studio 2008

($ก��.�()"#�$!*�ก$+3���42135"��,6!7$�+�8ก$+,-�,�.� ����3���"!+'( ��"�92ก

Page 4: appendix - bc.msu.ac.th

197

1.3 "19E2"#�$!*�#�.�ก$+"�92ก+*%�88ก$+,-�,�.� ��)�7$ ��"�92ก�88 Custom "59E2 ��"+$!$1$+Fก7$���!-E�/0E(),-�,�.����%"2���� ���:4�-%%GH1 Next

��"#$% ก-3 ก$+"�92ก+*%�88ก$+,-�,�.�

1.4 "19E21$FP�ก$+"�92ก!-E�/0E(),-�,�.� !-E�!7$4�Q/0E"+$,�2�"�92ก2D*����:492 Visual C# �2ก($ก�0.!-E�/0E4:+"�92ก"5-E1",-1 "S�� SQL Server Express, Crystal Reports "%Z�,�� ���:4�-ก%GH1 Install

��"#$% ก-4 "�92ก!-E�/0E(),-�,�.�

Page 5: appendix - bc.msu.ac.th

198

1.5 ($กก$+"�92ก �#�2/0E 1.4 ก'()"#�$!*�#�.�,2�ก$+,-�,�.� �%(�ก:�$()���:"!+'(

��"#$% ก-5 #�.�,2�ก$+,-�,�.� 1.6 "19E2"!+'(!-.�ก$+,-�,�.����:4�-ก%GH1 Finish

��"#$% ก-6 "!+'(!-.�ก$+,-�,�.�3%+�ก+1

Page 6: appendix - bc.msu.ac.th

199

2. ����ก�� Microsoft SQL Server 2005

2.1 �7$���� CD ,-�,�.�3%+�ก+1"#�$"4+9E2�4215-:",2+6 ����($ก��.� ��"#�$�%D�� My

Computer -> Drive CD-ROM -> Setup -> 3`�"�2+6 SQL Server 2005 Express ��)/7$ก$+��8"8-.�4�-ก�`�6/0ES9E2 SQL Server 2005 Express Edition "19E2��8"8-.�/0E�`�6���ก��$: 3%+�ก+1()/7$ก$+�,ก�`�6 "59E2"+-E1ก+)8:�ก$+,-�,�.�3%+�ก+1

��"#$% ก-7 "+-E1ก$+,-�,�.� SQL

Page 7: appendix - bc.msu.ac.th

200

2.1 4�-ก"4+9E2��1$D ���$ I accept the licensing terms and conditions "59E2D21+�8"�9E2��#ก$+ S��$�3%+�ก+1 ��)4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-8 D21+�8#�2,ก

2.3 4�-ก Install "59E2�%D��#�.�,2�F���%

��"#$% ก-9 ,+:(!28+)88"59E2ก$+,-�,�.� SQL

Page 8: appendix - bc.msu.ac.th

201

2.4 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���% ��)4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-10 ,+:(!28+)88"59E2ก$+,-�,�.� SQL "+0D8+�2D

.

2.5 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-11 +)88/7$ก$+,-�,�.� SQL

Page 9: appendix - bc.msu.ac.th

202

2.64�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-12 ก$+ก7$��� Registration Information

8. 4�-ก"�92ก Tool /0E,�2�ก$+,-�,�.��� �"4+9E2�4215-:",2+6�+924�-ก"�92ก,-�,�.�/�.��1� (���+*%) ��)4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-13 "�92ก,�:,-�,�.�

Page 10: appendix - bc.msu.ac.th

203

9. 4�-ก"�92ก Mixed Mode (Windows Authentication and SQL Server Authentication) -> !� Password /0ES�2� Enter password: ��) Confirm password: ("%Z� password #2� sa kPE�,�:2D�$����ก+2ก"%Z� : qwaszx) "19E2%n2�"!+'( ��4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-14 ก$+ก7$��� user

10. 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-15 "�92ก,�:Configuration Options

Page 11: appendix - bc.msu.ac.th

204

11. 4�-ก Install "59E2"+-E1/7$ก$+,-�,�.�3%+�ก+1

��"#$% ก-16 ,+:(!28+)88"59E2!��8!�G�ก$+,-�,�.�

12. +)88"+-E1/7$ก$+,-�,�.�3%+�ก+1 "19E2,-�,�.�"!+'( ��4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-17 +$D�)"20D�,+:(!284:$15+�21#2�+)88

Page 12: appendix - bc.msu.ac.th

205

13. 4�-ก Finish F92:�$,-�,�.�3%+�ก+1"!+'(!18*+o6

��"#$% ก-18 !+G%#�21*�ก$+,-�,�.�ก�2�"+-E1,-�,�.�

Page 13: appendix - bc.msu.ac.th

206

��� �ก������������ก�� Microsoft SQL Server Management Studio Express

1. 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-19 #�.�,2�ก$+,-�,�.�3%+�ก+1

2. 4�-ก"4+9E2��1$D ���$ I accept the terms in the license agreement "59E2D21+�8"�9E2��#ก$+ S��$�3%+�ก+1 ��)4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-20 #�.�,2�D21+�8#�2,ก��

Page 14: appendix - bc.msu.ac.th

207

3. 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-21 ก+2ก#�21*� User 4. 4�-ก%GH1 Next "59E2�%D��#�.�,2�F���%

��"#$% ก-22 "�92กก$+,-�,�.�

Page 15: appendix - bc.msu.ac.th

208

5. 4�-ก%GH1 Install "59E2"+-E1/7$ก$+,-�,�.�3%+�ก+1

��"#$% ก-23 �7$"�-�ก$+,-�,�.� SQL 6. 3%+�ก+1/7$ก$+,-�,�.��� �"4+9E2�4215-:",2+6 "19E2,-�,�.�"!+'( ��4�-ก%GH1 Finish "%Z�2��

"!+'(!-.�ก+)8:�ก$+,-�,�.�3%+�ก+1

��"#$% ก-24 "!+'(!-.�ก$+,-�,�.� SQL

Page 16: appendix - bc.msu.ac.th

209

������ก SOURCE CODE

Page 17: appendix - bc.msu.ac.th

210

SOURCE CODE

Class : ConnetDB (FG�H�IJKL% ��M กIN��O �PQ) using System.Data.SqlClient; namespace Project_desktop { class ConnetDB { public string strConn = "Data Source =202.28.32.173; Initial Catalog=53010972340db; User=53010972340; Password=72340";

public SqlConnection conn1; public void Conn() { conn1 = new SqlConnection(); conn1.ConnectionString = strConn; if (conn1.State == ConnectionState.Open) { conn1.Close(); } conn1.Open(); } }

}

Form : Login.cs (FG�H�IJO�FPM�TII) using System.Data.SqlClient; namespace Project_desktop

{ public partial class Login : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr;

Page 18: appendix - bc.msu.ac.th

211

DataTable dt; private string AgeID,AgeName, ofID,ofName,typeLogin; public Login() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { objcon.Conn(); string sql = "SELECT Agent_id, Agent_fname + ' ' + Agent_lname AS a, Useragent,

Passwordagent FROM Agent WHERE (Useragent = '"+txtUser.Text+"') AND (Passwordagent = '"+txtPass.Text+"')";

comSql = new SqlCommand(sql,objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); AgeID = dr["Agent_id"].ToString(); AgeName = dr["a"].ToString(); typeLogin = "agent"; } else { AgeID =""; AgeName =""; } objcon.Conn(); string sql2 ="SELECT Of_id, Of_fname+ ' '+Of_lname as Name2 ,UserOf, PassOf

FROM Officer WHERE UserOf='"+txtUser.Text+"' AND PassOf='"+txtPass.Text+"'"; comSql = new SqlCommand(sql2,objcon.conn1); dr = comSql.ExecuteReader();

Page 19: appendix - bc.msu.ac.th

212

if (dr.HasRows == true) { dr.Read(); ofID = dr["Of_id"].ToString(); ofName = dr["Name2"].ToString(); typeLogin = "office"; } else { ofID =""; ofName =""; }

if (AgeID != "" || ofID != "") { if (AgeID != "") { frmMain Main = new frmMain(AgeID, AgeName,typeLogin); Main.Show(); this.Hide(); dr.Close(); } else { frmMain Main = new frmMain(ofID, ofName,typeLogin); Main.Show(); this.Hide(); dr.Close(); } } else { MessageBox.Show("4Goก+2ก#�21*��1�F*ก4�) \nก+Go$ก+2ก#�21*� �1�", "��ก$+ Login"); txtUser.Text = ""; txtPass.Text = ""; }

Page 20: appendix - bc.msu.ac.th

213

} catch { } } private void button2_Click(object sender, EventArgs e) { this.Close(); }

} }

Form : Member.cs (FG�H�Iก��F���F��K�ก) using System.Data.SqlClient; namespace Project_desktop { public partial class Member : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string AgeID,id,idME; private string kum;

string y; public Member(string aID) { InitializeComponent(); AgeID = aID; } public void ShowKum() { objcon.Conn(); string Sql = "Select Kum_id, Kum_name From Kum";

Page 21: appendix - bc.msu.ac.th

214

comSql = new SqlCommand(Sql,objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); cboKname.DataSource = dt; cboKname.DisplayMember = "Kum_name"; cboKname.ValueMember = "Kum_id"; } public void clear() { idME = getMem_Pay(); id = getMemID(); lblMemID.Text = id; txtCard.Focus(); txtCard.Text = ""; cboTname.SelectedItem = ""; txtName.Text = ""; txtLname.Text = ""; dtpBirth.Value = DateTime.Parse(y); txtMoney.Text = ""; txtAge.Text = ""; txtAdd.Text = ""; txtStred.Text = ""; txtTel.Text = ""; txtCheck.Text = ""; } private void ShowMember() { objcon.Conn(); string strSql = "Select Mem_id,Mem_idcard,Mem_tname,Mem_fname,Mem_lname,Mem_gender,Mem_birthday,Mem_date,Mem_address,Mem_stred,Mem_road,Mem_subdistrict,Mem_district,Mem_province,Mem_code,Mem_tel,k.Kum_name From Member m, Kum k WHERE m.Kum_id = k.Kum_id AND k.Kum_id='K01' Order by Mem_id DESC"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader();

Page 22: appendix - bc.msu.ac.th

215

dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!!1$S-ก"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = ""5�"; dataGridView1.Columns[6].HeaderText = ":��"ก-�"; dataGridView1.Columns[7].HeaderText = ":��/0E!1�4+"; dataGridView1.Columns[8].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[9].HeaderText = "k2D"; dataGridView1.Columns[10].HeaderText = "F��"; dataGridView1.Columns[11].HeaderText = ",7$8�"; dataGridView1.Columns[12].HeaderText = "27$"�2"; dataGridView1.Columns[13].HeaderText = "(���:��"; dataGridView1.Columns[14].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[15].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[16].HeaderText = "4G�1"; public string getMemID() { objcon.Conn(); string sql1 = "SELECT MAX(Mem_id) FROM Member "; comSql = new SqlCommand(sql1, objcon.conn1); string last_id;//M00005 last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "M"; string id_s;

Page 23: appendix - bc.msu.ac.th

216

objcon.Conn(); string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Member"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString();//id_s2 =2 objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString();//id_s3 =3 objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString();//id_s4 =4 objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString();//id_s5 =5 id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0;

Page 24: appendix - bc.msu.ac.th

217

//====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9 { id2 += 1; } else if (id2 == 9) { id2 = 0; } } } } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s; } public string getMem_Pay() { objcon.Conn();

Page 25: appendix - bc.msu.ac.th

218

string sql1 = "SELECT MAX(Mem_number) FROM Member "; comSql = new SqlCommand(sql1, objcon.conn1); string last_id;//M00005 last_id = comSql.ExecuteScalar().ToString(); int id3, id4, id5, id6; string id_s6; string id_s5; string id_s4; string id_s3; string id_s2 = "E"; string id_s1 = "M"; string id_s; objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); objcon.Conn(); string sql6 = "SELECT SUBSTRING('" + last_id + "',6, 1)AS id1 FROM Member"; comSql = new SqlCommand(sql6, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read();

Page 26: appendix - bc.msu.ac.th

219

id_s6 = dr["id1"].ToString(); id5 = int.Parse(id_s5); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); if (id6 <= 0 && id6 < 9) { id6 += 1; } else if (id6 == 9) { id6 = 0; if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0; if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; } }

Page 27: appendix - bc.msu.ac.th

220

} } id_s = id_s1 + id_s2 + id3.ToString() + id4.ToString() + id5.ToString()+id6.ToString(); dr.Close(); return id_s; } } private void Member_Load(object sender, EventArgs e) { objcon.Conn(); ShowMember(); id = getMemID(); lblMemID.Text = id; idME = getMem_Pay(); lblfee.Text = "100"; ShowKum(); cboTname.SelectedIndex = 0; radioButton1.Checked = true; int curyear = DateTime.Today.Year + 543; int y2 = curyear - 60; string mount = DateTime.Today.Month.ToString(); string day = DateTime.Today.Day.ToString(); y = day + "/" + mount + "/" + y2.ToString(); dtpBirth.Value = DateTime.Parse(y); txtRoad.Text = "�4+!:++46"; txtSub.Text = ",�$�"; txtDistrict.Text = ""192�"; txtProvince.Text = "1�$!$+4$1"; txtCode.Text = "44000"; btnUpdate.Enabled = false; txtAge.Text = ""; txtCheck.Focus();

Page 28: appendix - bc.msu.ac.th

221

private void callOld() { //:��/0E%�((G8�� int curyear2 = DateTime.Today.Year + 543; //=================================================== string day = DateTime.Today.Day.ToString(); string mount = DateTime.Today.Month.ToString(); //=================================================== int y3 = curyear2 ; string y4 = day + "/" + mount + "/" + y3.ToString(); int cDay, cMount; cDay = int.Parse(day); cMount = int.Parse(mount); //"ก-� //========="5-E1",-1 string a, b, c, strDay; int year99,yearMem; DateTime dt1 = new DateTime(); dt1 = DateTime.Parse(dtpBirth.Text); a = dt1.Day.ToString(); DateTime dt2 = new DateTime(); dt2 = DateTime.Parse(dtpBirth.Text); b = dt2.Month.ToString(); DateTime dt3 = new DateTime(); dt3 = DateTime.Parse(dtpBirth.Text); c = dt3.Year.ToString(); year99 = int.Parse(c); yearMem = year99 + 543; strDay = a + "/" + b + "/" + yearMem; string btd = strDay; //=========!-.�!G�"5-E1",-1 string[] x; x = strDay.Split('/'); string btdDay, btdMount, btdYear; int btDay, btMount, btYear;

Page 29: appendix - bc.msu.ac.th

222

btdDay = x[0]; btdMount = x[1]; btdYear = x[2]; btDay = int.Parse(btdDay); btMount = int.Parse(btdMount); btYear = int.Parse(btdYear); string cNumDay = DateTime.DaysInMonth(y3, cMount).ToString();//:��/0E!*�!G�#2�"�92���)%�%�((G8�� string NumDay = DateTime.DaysInMonth(btYear, btMount).ToString();//:��/0E!*�!G�#2�"�92���)%�"ก-� //,+:(!28:�� int numD, numBtd = 0; numD = int.Parse(NumDay); if (cMount > btMount) { numBtd = curyear2 - btYear; } else if (cMount < btMount) { numBtd = curyear2 - btYear - 1; } else { if (cDay > btDay) { numBtd = curyear2 - btYear; } else if (cDay < btDay) { numBtd = curyear2 - btYear - 1; } else { numBtd = curyear2 - btYear; } } txtAge.Text = numBtd.ToString();

Page 30: appendix - bc.msu.ac.th

223

} private void btnDelete_Click(object sender, EventArgs e) { if (lblMemID.Text == "") { return; } DialogResult dlgResult = MessageBox.Show("4Go,�2�ก$+�8#�21*��0. S��+92�1�", "D9�D��ก$+�8#�21*�", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { string strSql = "DELETE Member WHERE Mem_id = '" + lblMemID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1); int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("�8#�21*�"+0D8+�2D���:", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F�8#�21*����", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowMember(); } private void btnUpdate_Click(object sender, EventArgs e) { if (lblMemID.Text != "" && txtCard.Text != "") { string strSql = "UPDATE Member SET Mem_id=@Mem_id,Mem_idcard=@Mem_idcard,Mem_tname=@Mem_tname,Mem_fname=@Mem_fname,Mem_lname=@Mem_lname,Mem_gender=@Mem_gender,Mem_address=@Mem_address,Mem_stred=@Mem_stred,Mem_tel=@Mem_tel WHERE Mem_id = '" + lblMemID.Text + "'";

Page 31: appendix - bc.msu.ac.th

224

comSql = new SqlCommand(strSql, objcon.conn1); string sex; if (radioButton1.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = lblMemID.Text; string idcard = txtCard.Text; comSql.Parameters.Add("Mem_idcard", SqlDbType.VarChar).Value = idcard; comSql.Parameters.Add("Mem_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem; comSql.Parameters.Add("Mem_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Mem_lname", SqlDbType.VarChar).Value = txtLname.Text; comSql.Parameters.Add("Mem_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Mem_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Mem_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Mem_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Mem_subscription", SqlDbType.VarChar).Value = lblfee.Text; string Kum = "K01"; comSql.Parameters.Add("Kum_id", SqlDbType.Char).Value = Kum; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }

Page 32: appendix - bc.msu.ac.th

225

ShowMember(); clear(); button2.Enabled = true; btnUpdate.Enabled = false; } private void txtMoney_TextChanged(object sender, EventArgs e) { int money; money = int.Parse(txtMoney.Text) - int.Parse(lblfee.Text); lblMoney.Text = money.ToString(); } private void cboKname_SelectedIndexChanged(object sender, EventArgs e) { kum = cboKname.SelectedValue.ToString(); string sqlK = "SELECT SELECT m.Mem_id, m.Mem_idcard, m.Mem_tname, m.Mem_fname, m.Mem_lname, m.Mem_gender, m.Mem_birthday, m.Mem_date, m.Mem_address,m.Mem_stred, m.Mem_road, m.Mem_subdistrict, m.Mem_district, m.Mem_province, m.Mem_code, m.Mem_tel, m.Mem_status, k.Kum_name FROM Member AS m ,Kum AS k WHERE m.Kum_id = k.Kum_id AND m.Kum_id = '"+kum+"' ORDER BY m.Mem_id DESC"; comSql = new SqlCommand(sqlK, objcon.conn1); } private void button2_Click(object sender, EventArgs e)// %GH18��/Pก { int money2=0; try { money2 = int.Parse(txtMoney.Text); } catch { } if (txtName.Text != "" && txtLname.Text != "") { if (money2 >= int.Parse(lblfee.Text)) {

Page 33: appendix - bc.msu.ac.th

226

string strSql = "INSERT INTO Member (Mem_id,Mem_idcard,Mem_tname,Mem_fname,Mem_lname,Mem_gender,Mem_birthday,Mem_date,Mem_address,Mem_stred,Mem_road,Mem_subdistrict,Mem_district,Mem_province,Mem_code,Mem_tel,Mem_subscription,Mem_status,Kum_id,Mem_Number)VALUES(@Mem_id,@Mem_idcard,@Mem_tname,@Mem_fname,@Mem_lname,@Mem_gender,@Mem_birthday,@Mem_date,@Mem_address,@Mem_stred,@Mem_road,@Mem_subdistrict,@Mem_district,@Mem_province,@Mem_code,@Mem_tel,@Mem_subscription,@Mem_status,@Kum_id,@Mem_Number)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = lblMemID.Text; string idcard = txtCard.Text; comSql.Parameters.Add("Mem_idcard", SqlDbType.VarChar).Value = idcard; comSql.Parameters.Add("Mem_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem; comSql.Parameters.Add("Mem_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Mem_lname", SqlDbType.VarChar).Value = txtLname.Text; string sex; if (radioButton1.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } comSql.Parameters.Add("Mem_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Mem_birthday", SqlDbType.DateTime).Value = dtpBirth.Value; comSql.Parameters.Add("Mem_date", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Mem_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Mem_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Mem_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Mem_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Mem_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Mem_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Mem_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Mem_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Mem_subscription", SqlDbType.Int).Value = int.Parse(lblfee.Text);

Page 34: appendix - bc.msu.ac.th

227

comSql.Parameters.Add("Mem_status", SqlDbType.VarChar).Value = ""%Z�!1$S-ก"; comSql.Parameters.Add("Kum_id", SqlDbType.Char).Value = cboKname.SelectedValue.ToString(); comSql.Parameters.Add("Mem_number", SqlDbType.VarChar).Value =idME; try { int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); dtpBirth.Value = DateTime.Parse(y); ShowMember(); controlButton(); objcon.conn1.Close(); clear(); } } catch (Exception ex) { ShowMember(); controlButton(); } } else { MessageBox.Show("(7$�:�"�-��1�524�)"); } } else { MessageBox.Show("4Go�1����ก+2ก#�21*�4�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); }

Page 35: appendix - bc.msu.ac.th

228

private void ShowCheck() { objcon.Conn(); string strSql; strSql = "SELECT * FROM Member WHERE (Mem_id LIKE '%" + txtCheck.Text + "%') OR(Mem_fname LIKE '%" + txtCheck.Text + "%') OR(Mem_lname LIKE '%" + txtCheck.Text + "%')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!!1$S-ก"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = ""5�"; dataGridView1.Columns[6].HeaderText = ":��"ก-�"; dataGridView1.Columns[7].HeaderText = ":��/0E!1�4+"; dataGridView1.Columns[8].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[9].HeaderText = "k2D"; dataGridView1.Columns[10].HeaderText = "F��"; dataGridView1.Columns[11].HeaderText = ",7$8�"; dataGridView1.Columns[12].HeaderText = "27$"�2"; dataGridView1.Columns[13].HeaderText = "(���:��"; dataGridView1.Columns[14].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[15].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[16].HeaderText = "4G�1"; } private void btnCheck_Click(object sender, EventArgs e) { ShowCheck(); }

Page 36: appendix - bc.msu.ac.th

229

private void txtAdd_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) { e.KeyChar = Convert.ToChar(Keys.None); } } private bool isNumeric(string strNum) { double x; if (double.TryParse(strNum, out x)) { return true; } else { return false; } } private void txtTel_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtTel.Text != "") { if (int.Parse(txtTel.Text) > 0) { btnSave_Click(sender, e); } } } private void txtTel_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.�

Page 37: appendix - bc.msu.ac.th

230

e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } } private void txtMoney_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.� e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } } private void txtMoney_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtAdd.Text != "") { if (int.Parse(txtAdd.Text) > 0) { btnSave_Click(sender, e); } } }

Page 38: appendix - bc.msu.ac.th

231

private void txtStred_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) { e.KeyChar = Convert.ToChar(Keys.None); } } private void dtpBirth_ValueChanged(object sender, EventArgs e) { int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtAge.Text = year.ToString(); int d = 60; int f; f = int.Parse(txtAge.Text); if (d > f) { MessageBox.Show("2$DG�1�FP� 60 %� �1�!$1$+F!1�4+��� !!!", "#�2�-�5�$�", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAge.Focus(); txtAge.SelectAll(); return; } } private void printMoney_Click(object sender, EventArgs e) { fcr_Member printMem = new fcr_Member(lblMemID.Text); printMem.Show(); } private void printMember_Click(object sender, EventArgs e) { frm_prMemPay f = new frm_prMemPay(AgeID, lblMemID.Text); f.Show(); }

Page 39: appendix - bc.msu.ac.th

232

private void btnExit_Click(object sender, EventArgs e) { clear(); button2.Enabled = true; btnUpdate.Enabled = false; } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblMemID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); txtCard.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); cboTname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtLname.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); string sex = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); if (sex == "S$D") { radioButton1.Checked = true; } else { radioButton2.Checked = true; } dtpBirth.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); txtAdd.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); txtStred.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); txtRoad.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString(); txtSub.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(); txtDistrict.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString(); txtProvince.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString(); txtCode.Text = dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString(); txtTel.Text = dataGridView1.Rows[e.RowIndex].Cells[15].Value.ToString();

Page 40: appendix - bc.msu.ac.th

233

string kum_name; kum_name = dataGridView1.Rows[e.RowIndex].Cells[16].Value.ToString(); cboKname.Text = kum_name; button2.Enabled = false; btnUpdate.Enabled = true; callOld(); } } }

Form : Receive.cs (FG�H�Iก���IKG��TJ���) using System.Data.SqlClient; namespace Project_desktop { public partial class Receive : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id, AgeID,receID; int numDeath ; public Receive(string aID) { InitializeComponent(); AgeID =aID ; } public void Clear() { id = getReceive(); lblReID.Text = id; txtCheck.Text = ""; lblAmount.Text = ""; lblName.Text = "";

Page 41: appendix - bc.msu.ac.th

234

lblTname.Text = ""; lblLname.Text = ""; txtCome.Text = ""; lblChange.Text = ""; dataGridView1.Columns.Clear(); button1.Enabled = true; button6.Enabled = false; } public string getReceive() { objcon.Conn(); string sql1 = "SELECT MAX(Receive_id) FROM Receive"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id;//M00005 last_id = comSql.ExecuteScalar().ToString(); int id3, id4, id5, id6; string id_s6; string id_s5; string id_s4; string id_s3; string id_s2 = "e"; string id_s1 = "R"; string id_s; objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Receive"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString();//id_s3 =3 objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Receive"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString();//id_s4 =3

Page 42: appendix - bc.msu.ac.th

235

objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Receive"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString();//id_s5 =5 objcon.Conn(); string sql6 = "SELECT SUBSTRING('" + last_id + "',6, 1)AS id1 FROM Receive"; comSql = new SqlCommand(sql6, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s6 = dr["id1"].ToString();//id_s6 =6 dr.Close(); id6 = int.Parse(id_s6); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); //id2 = int.Parse(id_s2); if (id6 >= 0 && id6 < 9) { id6 += 1; } else if (id6 == 9) { id6 = 0; if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) {

Page 43: appendix - bc.msu.ac.th

236

id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; } } } } id_s = id_s1 + id_s2 + id3.ToString() + id4.ToString() + id5.ToString() + id6.ToString(); dr.Close(); return id_s; } private void ShowMem() { objcon.Conn(); string strSql = "SELECT m.Mem_id, m.Mem_tname,m.Mem_fname,m.Mem_lname FROM Member AS m WHERE (m.Mem_status = '"%Z�!1$S-ก') AND(m.Mem_id = '" + txtCheck.Text + "') AND m.Kum_id ='K01'"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtCheck.Text = dr["Mem_id"].ToString(); lblTname.Text = dr["Mem_tname"].ToString(); lblName.Text = dr["Mem_fname"].ToString();

Page 44: appendix - bc.msu.ac.th

237

lblLname.Text = dr["Mem_lname"].ToString(); dr.Close(); ShowDeath(); ShowDetailReceivek(); } else { MessageBox.Show("10#�21*��*�"!0DS0:-,���:4)"); dataGridView1.Columns.Clear(); dataGridView2.Columns.Clear(); txtCheck.Text = ""; lblTname.Text = ""; lblName.Text = ""; lblLname.Text = ""; dr.Close(); } } private void ShowDeath() { objcon.Conn(); string sql = "SELECT d.Death_id, m.Mem_fname, m.Mem_lname, k.Kum_name FROM Death d,Member m,Kum k WHERE d.Mem_id =m.Mem_id AND m.Kum_id = k.Kum_id AND (d.Death_id NOT IN (SELECT red.Death_id FROM Receive AS re INNER JOIN Receive_Detail AS red ON re.Receive_id = red.Receive_id WHERE (re.Mem_id = '" + txtCheck.Text + "')))"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!�*�"!0DS0:-,"; dataGridView1.Columns[1].HeaderText = "S9E2"; dataGridView1.Columns[2].HeaderText = "�$1!กG�"; dataGridView1.Columns[3].HeaderText = "4G�1"; dr.Close(); }

Page 45: appendix - bc.msu.ac.th

238

private void ShowDetailReceivek() { objcon.Conn(); string sql = "SELECT rd.Receive_id, rd.MoneyRate, rd.Death_id FROM Receive_Detail AS rd INNER JOIN Receive AS r ON rd.Receive_id = r.Receive_id WHERE (r.Mem_id = '" + txtCheck.Text + "')Order by Receive_id DESC"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dataGridView2.Columns[0].HeaderText = ""�#/0Eก$+S7$+)"�-�"; dataGridView2.Columns[1].HeaderText = "S9E2"; dataGridView2.Columns[2].HeaderText = "�$1!กG�"; dr.Close(); } private void Receive_Load(object sender, EventArgs e) { id = getReceive(); lblReID.Text = id; } private void btnCheck_Click(object sender, EventArgs e) { dataGridView1.Columns.Clear(); dataGridView1.DataSource = dt; DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn(); dataGridView1.Columns.Add(chk); ShowMem(); } private void button1_Click(object sender, EventArgs e) { int money2 = 0; receID = lblReID.Text; try {

Page 46: appendix - bc.msu.ac.th

239

money2 = int.Parse(txtCome.Text); } catch { } if (money2 >= int.Parse(lblAmount.Text)) { string strSql2;//8��/Pก,$+$����ก strSql2 = "INSERT INTO Receive(Receive_id, Receive_date, Mem_id,Agent_id,SumRe) Values(@Receive_id, @Receive_date, @Mem_id,@Agent_id,@SumRe)"; comSql = new SqlCommand(strSql2, objcon.conn1); comSql.Parameters.Add("Receive_id", SqlDbType.Char).Value = lblReID.Text; comSql.Parameters.Add("Receive_date", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = txtCheck.Text; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = "A0001"; comSql.Parameters.Add("SumRe", SqlDbType.Int).Value = lblAmount.Text; int numRec2 = comSql.ExecuteNonQuery();//��8(7$�:��F: if (numRec2 > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); button6.Enabled = true; } foreach (DataGridViewRow dr in dataGridView1.Rows) { if (Convert.ToBoolean(dr.Cells[0].Value) == true)//"S'44�$/0E"�92ก { string deId = dataGridView1.Rows[dr.Index].Cells[1].Value.ToString();//"2$+��!1$"ก'8�:� �,�:�%+ string strSql;//8��/Pก �,$+$�+$D�)"20D� strSql = "INSERT INTO Receive_Detail (Receive_id, MoneyRate, Death_id) Values(@Receive_id, @MoneyRate, @Death_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Receive_id", SqlDbType.Char).Value = lblReID.Text; comSql.Parameters.Add("MoneyRate", SqlDbType.Int).Value = 30;

Page 47: appendix - bc.msu.ac.th

240

comSql.Parameters.Add("Death_id", SqlDbType.Char).Value = deId; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { } } } ShowDeath(); ShowDetailReceivek(); id = getReceive(); lblReID.Text = id; lblAmount.Text = ""; txtCome.Text = ""; lblChange.Text = ""; } else { MessageBox.Show("(7$�:�"�-��1�524�)"); } } private void txtCome_TextChanged(object sender, EventArgs e) { try { int sum = 0, sumNet, sumRe; sumNet = int.Parse(lblAmount.Text); sumRe = int.Parse(txtCome.Text); sum = sumRe - sumNet; lblChange.Text = sum.ToString(); } catch { } }

Page 48: appendix - bc.msu.ac.th

241

private void txtCome_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.� e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } } private void txtCome_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtCome.Text != "") { if (int.Parse(txtCome.Text) > 0) { button2_Click(sender, e); } } } private void button6_Click(object sender, EventArgs e) { frm_prReceive fRe = new frm_prReceive(AgeID, receID,txtCheck.Text);//!�� fRe.Show(); } private void dataGridView1_Click(object sender, EventArgs e) { int i = 0, sum = 0; foreach (DataGridViewRow dr in dataGridView1.Rows) { if (Convert.ToBoolean(dr.Cells[0].Value) == true)

Page 49: appendix - bc.msu.ac.th

242

{ i = i + 1; } } numDeath = i + 1; sum = 30 * numDeath; lblAmount.Text = sum.ToString(); } private void button1_Click_2(object sender, EventArgs e) { Clear(); } } }

Form : Death.cs (FG�H�Iก���I�WO�) using System.Data.SqlClient; namespace Project_desktop { public partial class Death : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id, kumID; public Death() { InitializeComponent(); } public void Clear() { id = getDeath(); lblDetID.Text = id;

Page 50: appendix - bc.msu.ac.th

243

txtNum.Text = ""; txtOut.Text = ""; txtMemID.Text = ""; txtCheck.Text = ""; } public void ShowKum() { objcon.Conn(); string Sql = "Select Kum_id, Kum_name From Kum"; comSql = new SqlCommand(Sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); cboKum.DataSource = dt; cboKum.DisplayMember = "Kum_name"; cboKum.ValueMember = "Kum_id"; dr.Close(); } private void callOld() { int curyear2 = DateTime.Today.Year + 543; string day = DateTime.Today.Day.ToString(); string mount = DateTime.Today.Month.ToString(); int y3 = curyear2; string y4 = day + "/" + mount + "/" + y3.ToString(); int cDay, cMount; cDay = int.Parse(day); cMount = int.Parse(mount); //:��"ก-� //========="5-E1",-1 string a, b, c, strDay; int year99, yearMem; DateTime dt1 = new DateTime(); dt1 = DateTime.Parse(dtpBirth.Text); a = dt1.Day.ToString();

Page 51: appendix - bc.msu.ac.th

244

DateTime dt2 = new DateTime(); dt2 = DateTime.Parse(dtpBirth.Text); b = dt2.Month.ToString(); DateTime dt3 = new DateTime(); dt3 = DateTime.Parse(dtpBirth.Text); c = dt3.Year.ToString(); year99 = int.Parse(c); yearMem = year99 + 543; strDay = a + "/" + b + "/" + yearMem; string btd = strDay; //=========!-.�!G�"5-E1",-1 string[] x; x = strDay.Split('/'); string btdDay, btdMount, btdYear; int btDay, btMount, btYear; btdDay = x[0]; btdMount = x[1]; btdYear = x[2]; btDay = int.Parse(btdDay); btMount = int.Parse(btdMount); btYear = int.Parse(btdYear); string cNumDay = DateTime.DaysInMonth(y3, cMount).ToString(); //:��/0E!*�!G�#2�"�92���)%�%�((G8�� string NumDay = DateTime.DaysInMonth(btYear, btMount).ToString(); //:��/0E!*�!G�#2�"�92���)%�"ก-� //,+:(!28:�� int numD, numBtd = 0; numD = int.Parse(NumDay); if (cMount > btMount) { numBtd = curyear2 - btYear; } else if (cMount < btMount) { numBtd = curyear2 - btYear - 1;

Page 52: appendix - bc.msu.ac.th

245

} else { if (cDay > btDay) { numBtd = curyear2 - btYear; } else if (cDay < btDay) { numBtd = curyear2 - btYear - 1; } else { numBtd = curyear2 - btYear; } } lblOld.Text = numBtd.ToString(); } private void showMembersOut() { objcon.Conn(); string strSql = " SELECT m.M_id, m.M_tname, m.M_fname, m.M_lname, k.Kum_name FROM Member_Out m , Kum AS k WHERE m.Kum_id = k.Kum_id AND (m.Kum_id = '"+kumID+"')"; comSql = new SqlCommand(strSql,objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtMemID.Text = dr["M_id"].ToString(); lblFname.Text = dr["M_fname"].ToString(); lblLname.Text = dr["M_lname"].ToString(); } else { MessageBox.Show("�1�58#�21*�"); }

Page 53: appendix - bc.msu.ac.th

246

} private void showMembers() { objcon.Conn(); string sql = "select Mem_id from Member where Mem_status ='"%Z�!1$S-ก' and Mem_id ='"+txtMemID.Text+"'"; comSql = new SqlCommand(sql,objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Close(); objcon.Conn(); string sqlDet = "select d.Death_id,m.Mem_fname+' '+m.Mem_lname as name3 from Death d,Member m where d.Mem_id = m.Mem_id AND d.Death_id NOT IN (select rd.Death_id From Receive_Detail rd ,Receive r Where r.Receive_id = rd.Receive_id AND r.Mem_id ='" + txtMemID.Text + "')"; comSql = new SqlCommand(sqlDet, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dr.Close(); int iRow = dataGridView2.RowCount; if (iRow >= 1) { MessageBox.Show("10��0.4�$�" + iRow); return; } } else { MessageBox.Show("No mem"); } } private void ShowInformant() {

Page 54: appendix - bc.msu.ac.th

247

objcon.Conn(); string Sql = "SELECT Inf_id, Inf_fname, Inf_lname FROM Informant WHERE (Inf_id LIKE '%" + txtCheck.Text + "%') OR(Inf_fname LIKE '%" + txtCheck.Text + "%') OR(Inf_lname LIKE '%" + txtCheck.Text + "%')"; comSql = new SqlCommand(Sql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtCheck.Text = dr["Inf_id"].ToString(); lblIname.Text = dr["Inf_fname"].ToString(); lblInLname.Text = dr["Inf_lname"].ToString(); dr.Close(); groupBox2.Enabled = true; } else { groupBox2.Enabled = false; lblIname.Text = ""; lblInLname.Text = ""; } } public string getDeath() { objcon.Conn(); string sql1 = "SELECT MAX(Death_id) FROM Death"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id; last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "D";

Page 55: appendix - bc.msu.ac.th

248

string id_s; objcon.Conn(); string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Death"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString(); objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Death"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Death"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Death"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); dr.Close(); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9)

Page 56: appendix - bc.msu.ac.th

249

{ id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9) { id2 += 1; } else if (id2 == 9) { id2 = 0; } } } } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s; } private void ShowDeath()

Page 57: appendix - bc.msu.ac.th

250

{ objcon.Conn(); string sqlDet = "select Death_id,Death_date,Death_number,Death_out,Out,Mem_id,Inf_id from Death Order by Death_id DESC"; comSql = new SqlCommand(sqlDet, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!ก$+�(��"; dataGridView1.Columns[1].HeaderText = ":��/0E"!0DS0:-,"; dataGridView1.Columns[2].HeaderText = ""�#/0E 81+o)8�,+"; dataGridView1.Columns[3].HeaderText = ":��/0E22ก"; dataGridView1.Columns[4].HeaderText = "22ก3�D"; dataGridView1.Columns[5].HeaderText = "+��!�*�"!0DS0:-,"; dataGridView1.Columns[6].HeaderText = "+��!�*��(��"; dr.Close(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { objcon.Conn(); kumID = cboKum.SelectedValue.ToString(); string sqlK = "SELECT UPPER(Agent_fname)+' ' +UPPER(Agent_lname) as name FROM Agent WHERE (Kum_id = '"+kumID+"')"; comSql = new SqlCommand(sqlK, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); lblAname.Text = dr["name"].ToString(); dr.Close(); } if (cboKum.SelectedIndex == 0) { button2.Visible = true;

Page 58: appendix - bc.msu.ac.th

251

button5.Visible = false; } else { button2.Visible = false; button5.Visible = true; } } private void Death_Load(object sender, EventArgs e) { objcon.Conn(); ShowDeath(); id = getDeath(); lblDetID.Text = id; ShowKum(); btnUpdate.Enabled = false; btnDel.Enabled = false; cboKum.SelectedIndex = 0; kumID = cboKum.SelectedValue.ToString(); } private void button5_Click(object sender, EventArgs e) { objcon.Conn(); string strSql = "SELECT m.Mem_id, Mem_idcard, Mem_tname, m.Mem_fname, m.Mem_lname, Mem_gender,Mem_birthday, Mem_date, UPPER(Mem_address) + ' k2D ' + UPPER(Mem_stred) + ' F�� ' + UPPER(Mem_road) + ' ,7$8� ' + UPPER(Mem_subdistrict) + ' 27$"�2 ' + UPPER(Mem_district) + ' (���:�� ' + UPPER(Mem_province) + ' +��!�%+�o0D6 ' + UPPER(Mem_code) AS addre, Mem_tel, Mem_subscription, Kum_name FROM Member AS m, Kum AS k WHERE m.Kum_id = k.Kum_id ANd m.Kum_id <> 'K01' AND (m.Mem_status = '"%Z�!1$S-ก') AND (m.Mem_id = '" + txtMemID.Text + "') OR(m.Mem_fname = '" + txtMemID.Text + "') OR(m.Mem_lname = '" + txtMemID.Text + "') "; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read();

Page 59: appendix - bc.msu.ac.th

252

txtMemID.Text = dr["Mem_id"].ToString(); lblIdCard.Text = dr["Mem_idcard"].ToString(); cobTname.Text = dr["Mem_tname"].ToString(); lblFname.Text = dr["Mem_fname"].ToString(); lblLname.Text = dr["Mem_lname"].ToString(); dtpBirth.Text = dr["Mem_birthday"].ToString(); lblAddress.Text = dr["addre"].ToString(); dr.Close(); callOld(); btnSave.Enabled = true; } else { btnSave.Enabled = false; } } private void btnCheck_Click(object sender, EventArgs e) { ShowInformant(); } private void btnSave_Click(object sender, EventArgs e) { objcon.Conn(); //---8��/Pก#�21*� if (txtMemID.Text != "" && txtNum.Text != "") { string strSql = "INSERT INTO Death (Death_id, Date_p, Death_date, Death_number, Death_out, Out, Mem_id, Inf_id, Agent_id) Values(@Death_id, @Date_p, @Death_date, @Death_number, @Death_out, @Out,@Mem_id, @Inf_id, @Agent_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Death_id", SqlDbType.Char).Value = lblDetID.Text; comSql.Parameters.Add("Date_p", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Death_date", SqlDbType.DateTime).Value = dtpDet.Value; comSql.Parameters.Add("Death_number", SqlDbType.VarChar).Value = txtNum.Text;

Page 60: appendix - bc.msu.ac.th

253

comSql.Parameters.Add("Death_out", SqlDbType.DateTime).Value = dtpOut.Value; comSql.Parameters.Add("Out", SqlDbType.VarChar).Value = txtOut.Text; comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = txtMemID.Text; comSql.Parameters.Add("Inf_id", SqlDbType.Char).Value = txtCheck.Text; string Agent = "A0001"; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = Agent; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); string sql2 = "UPDATE Member SET Mem_status = '"!0DS0:-,' WHERE (Mem_id = '" + txtMemID.Text + "')"; comSql = new SqlCommand(sql2, objcon.conn1); int numRec2 = comSql.ExecuteNonQuery(); if (numRec2 > 0) { MessageBox.Show("�ก��##�21*�"+0D8+�2D���:", "��ก$+�ก��##�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } ShowDeath(); Clear(); } } else { MessageBox.Show("ก+Go$ก+2ก#�21*� ��4+84�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } { objcon.conn1.Close(); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {

Page 61: appendix - bc.msu.ac.th

254

if (e.RowIndex == -1) { return; } lblDetID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); dtpDet.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); txtNum.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); dtpOut.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtOut.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); txtMemID.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); txtCheck.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); groupBox2.Enabled = true; btnSave.Enabled = false; btnUpdate.Enabled = true; btnDel.Enabled = true; ShowMember2(); ShowInfDatagid(); } private void ShowInfDatagid() { string Sql = "SELECT i.Inf_fname, i.Inf_lname FROM Informant AS i CROSS JOIN Death AS d WHERE (i.Inf_id = '" + txtCheck.Text + "') AND (d.Inf_id = i.Inf_id)"; objcon.Conn(); comSql = new SqlCommand(Sql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); lblIname.Text = dr["Inf_fname"].ToString(); lblInLname.Text = dr["Inf_lname"].ToString(); dr.Close(); } } private void ShowMember2()

Page 62: appendix - bc.msu.ac.th

255

{ objcon.Conn(); string strSql = "SELECT m.Mem_id, Mem_idcard, Mem_tname, Mem_fname, Mem_lname, Mem_gender,Mem_birthday, Mem_date, UPPER(Mem_address) + ' k2D ' + UPPER(Mem_stred) + ' F�� ' + UPPER(Mem_road) + ' ,7$8� ' + UPPER(Mem_subdistrict) + ' 27$"�2 ' + UPPER(Mem_district) + ' (���:�� ' + UPPER(Mem_province) + ' +��!�%+�o0D6 ' + UPPER(Mem_code) AS addre FROM Member m, Death d WHERE d.Mem_id = m.Mem_id and d.Mem_id = '" + txtMemID.Text + "'"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtMemID.Text = dr["Mem_id"].ToString(); lblIdCard.Text = dr["Mem_idcard"].ToString(); cobTname.Text = dr["Mem_tname"].ToString(); lblFname.Text = dr["Mem_fname"].ToString(); lblLname.Text = dr["Mem_lname"].ToString(); dtpBirth.Text = dr["Mem_birthday"].ToString(); lblAddress.Text = dr["addre"].ToString(); dr.Close(); callOld(); } } private void btnDel_Click(object sender, EventArgs e) { if (lblDetID.Text == "") { return; } DialogResult dlgResult = MessageBox.Show("4Go,�2�ก$+�8#�21*��0. S��+92�1�", "D9�D��ก$+�8#�21*�", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { string strSql = "DELETE Death WHERE Death_id = '" + lblDetID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1);

Page 63: appendix - bc.msu.ac.th

256

int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("�8#�21*�"+0D8+�2D���:", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F�8#�21*����", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowDeath(); } private void txtMemID_TextChanged(object sender, EventArgs e) { if (txtMemID.Text == "") { lblIdCard.Text = ""; cobTname.Text = ""; lblFname.Text = ""; lblLname.Text = ""; dtpBirth.Text = ""; lblOld.Text = ""; lblAddress.Text = ""; } } private void txtCheck_TextChanged(object sender, EventArgs e) { if (txtCheck.Text == "") { lblIname.Text = ""; lblInLname.Text = ""; }

Page 64: appendix - bc.msu.ac.th

257

} private void button1_Click(object sender, EventArgs e) { Clear(); btnSave.Enabled = true; btnDel.Enabled = false; btnUpdate.Enabled = false; } private void button2_Click(object sender, EventArgs e) { objcon.Conn(); string sql = "select Mem_id from Member where Kum_id ='K01' AND Mem_status ='"%Z�!1$S-ก' and Mem_id ='" + txtMemID.Text + "'"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); string mId = dr["Mem_id"].ToString(); dr.Close(); objcon.Conn(); string sqlDet = "select d.Death_id,m.Mem_fname+' '+m.Mem_lname as name3 from Death d,Member m where d.Mem_id = m.Mem_id AND d.Death_id NOT IN (select rd.Death_id From Receive_Detail rd ,Receive r Where r.Receive_id = rd.Receive_id AND r.Mem_id ='" + txtMemID.Text + "')"; comSql = new SqlCommand(sqlDet, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dr.Close(); int iRow = dataGridView2.RowCount; if (iRow < 1) {

Page 65: appendix - bc.msu.ac.th

258

objcon.Conn(); string strSql = "SELECT m.Mem_id, Mem_idcard, Mem_tname, m.Mem_fname, m.Mem_lname, Mem_gender,Mem_birthday, Mem_date, UPPER(Mem_address) + ' k2D ' + UPPER(Mem_stred) + ' F�� ' + UPPER(Mem_road) + ' ,7$8� ' + UPPER(Mem_subdistrict) + ' 27$"�2 ' + UPPER(Mem_district) + ' (���:�� ' + UPPER(Mem_province) + ' +��!�%+�o0D6 ' + UPPER(Mem_code) AS addre, Mem_tel, Mem_subscription, Kum_name FROM Member AS m, Kum AS k WHERE m.Kum_id = k.Kum_id ANd m.Kum_id = 'K01' AND (m.Mem_status = '"%Z�!1$S-ก') AND (m.Mem_id = '" + txtMemID.Text + "') OR(m.Mem_fname = '" + txtMemID.Text + "') OR(m.Mem_lname = '" + txtMemID.Text + "') "; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtMemID.Text = dr["Mem_id"].ToString(); lblIdCard.Text = dr["Mem_idcard"].ToString(); cobTname.Text = dr["Mem_tname"].ToString(); lblFname.Text = dr["Mem_fname"].ToString(); lblLname.Text = dr["Mem_lname"].ToString(); dtpBirth.Text = dr["Mem_birthday"].ToString(); lblAddress.Text = dr["addre"].ToString(); dr.Close(); callOld(); btnSave.Enabled = true; } } else { MessageBox.Show("ก+Go$S7$+)"�-� ���1�ก�2�4�)", "10D2�"�-�4�$�S7$+) ", MessageBoxButtons.OK, MessageBoxIcon.Stop); btnSave.Enabled = false; return; } } else

Page 66: appendix - bc.msu.ac.th

259

{ objcon.Conn(); sql = "select Mem_id from Member where Kum_id <>'K01' AND Mem_status ='"%Z�!1$S-ก' and Mem_id ='" + txtMemID.Text + "'"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); string mId = dr["Mem_id"].ToString(); dr.Close(); MessageBox.Show(""%Z�!1$S-ก4G�129E�", "ก+Go$"�92ก#�21*�4G�1", MessageBoxButtons.OK, MessageBoxIcon.Warning); btnSave.Enabled = false; } else {MessageBox.Show("�1����"%Z�!1$S-ก���:"); btnSave.Enabled = false; } } } } }

Form : Interest_Pay.cs (FG�H�Iก��WM�\�M�� I�#�(�PO�I�Q��T�\K�])) using System.Data.SqlClient; namespace Project_desktop { public partial class Interest_Pay : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr;

Page 67: appendix - bc.msu.ac.th

260

DataTable dt; private string id, interID, AgeID; int money,netmoney; public Interest_Pay(string nID) { InitializeComponent(); AgeID = nID; } private void Clear() { id = getInt_Pay(); lblPayID.Text = id; lblIntID.Text = ""; lblIntLname.Text = ""; lblIntName.Text = ""; lblMoney.Text = ""; } public string getInt_Pay() { objcon.Conn(); string sql1 = "SELECT MAX(IntPay_id) FROM Interest_Pay"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id; last_id = comSql.ExecuteScalar().ToString(); int id3, id4, id5, id6; string id_s6; string id_s5; string id_s4; string id_s3; string id_s2 = "P"; string id_s1 = "I"; string id_s; objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Interest_Pay"; comSql = new SqlCommand(sql3, objcon.conn1);

Page 68: appendix - bc.msu.ac.th

261

dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Interest_Pay"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Interest_Pay"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); objcon.Conn(); string sql6 = "SELECT SUBSTRING('" + last_id + "',6, 1)AS id1 FROM Interest_Pay"; comSql = new SqlCommand(sql6, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s6 = dr["id1"].ToString(); dr.Close(); id6 = int.Parse(id_s6); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); if (id6 >= 0 && id6 < 9) { id6 += 1; } else if (id6 == 9) { id6 = 0; if (id5 >= 0 && id5 < 9) {

Page 69: appendix - bc.msu.ac.th

262

id5 += 1; } else if (id5 == 9) { id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; } } } } id_s = id_s1 + id_s2 + id3.ToString() + id4.ToString() + id5.ToString() + id6.ToString(); dr.Close(); return id_s; } private void ShowMember() { objcon.Conn(); if (txtCheck.Text != "") { string strSql;

Page 70: appendix - bc.msu.ac.th

263

strSql = "SELECT m.Mem_id, UPPER(m.Mem_fname)+' '+ UPPER(m.Mem_lname),k.Kum_name FROM Member AS m INNER JOIN Kum AS k ON m.Kum_id = k.Kum_id WHERE ((Mem_id LIKE '%" + txtCheck.Text + "%') OR(Mem_fname LIKE '%" + txtCheck.Text + "%') OR(Mem_lname LIKE '%" + txtCheck.Text + "%')) AND (Mem_status = '"!0DS0:-,')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!"; dataGridView1.Columns[1].HeaderText = "!1$S-ก"; dataGridView1.Columns[2].HeaderText = "4G�1"; } } private void btnCheck_Click(object sender, EventArgs e) { ShowMember(); dataGridView1.Visible = true; } private void ShowInterest() { objcon.Conn(); string sql = " SELECT Interest_id, UPPER(Interest_tname)+' '+ UPPER(Interest_fname), Interest_lname,Int_Percent FROM Interest WHERE Mem_id ='" + txtCheck.Text + "' Order by Interest_id DESC"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dataGridView2.Columns[0].HeaderText = "+��!�*�+�8��%+)3DS�6"; dataGridView2.Columns[1].HeaderText = "S9E2"; dataGridView2.Columns[2].HeaderText = "�$1!กG�"; dataGridView2.Columns[3].HeaderText = "2�,+$/0E���+�8";

Page 71: appendix - bc.msu.ac.th

264

} private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } txtCheck.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); lblName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); lblKum.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ShowInterest(); dataGridView1.Visible = false; } private void Interest_Pay_Load(object sender, EventArgs e) { id = getInt_Pay(); lblPayID.Text = id; txtCheck.Focus(); } private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblIntID.Text = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString(); interID = lblIntID.Text; lblIntName.Text = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); lblIntLname.Text = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString(); string strMoney = dataGridView2.Rows[e.RowIndex].Cells[3].Value.ToString(); money = int.Parse(strMoney); netmoney = 36100 * money /100; lblMoney.Text = netmoney.ToString(); }

Page 72: appendix - bc.msu.ac.th

265

private void btnSave_Click(object sender, EventArgs e) { objcon.Conn(); string sql1 = "select Interest_id from Interest_Pay WHERE Interest_id='" + interID + "'"; comSql = new SqlCommand(sql1, objcon.conn1);//!��47$!�E�sql �%connetก�8�$�#�21*� dr = comSql.ExecuteReader(); if (dr.HasRows == true) { MessageBox.Show("(�$D4�$,28�/����:"); dr.Close(); } else { dr.Close(); //---8��/Pก#�21*� if (txtCheck.Text != "") { string strSql = "INSERT INTO Interest_Pay (IntPay_id, Interest_id, InterP_date, Inter_money, Agent_id) Values(@IntPay_id,@Interest_id, @InterP_date, @Inter_money, @Agent_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("IntPay_id", SqlDbType.Char).Value = lblPayID.Text; comSql.Parameters.Add("Interest_id", SqlDbType.Char).Value = lblIntID.Text; comSql.Parameters.Add("InterP_date", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Inter_money", SqlDbType.Int).Value = int.Parse(lblMoney.Text); comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = AgeID; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); } dr.Close(); } else

Page 73: appendix - bc.msu.ac.th

266

{ MessageBox.Show("ก+Go$ก+2ก#�21*� ��4+84�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } objcon.conn1.Close(); } } private void btnPrint_Click(object sender, EventArgs e) { frm_prIntPaycs f =new frm_prIntPaycs(lblIntID.Text ,AgeID); f.Show(); } private void txtCheck_TextChanged(object sender, EventArgs e) { if (txtCheck.Text == "") { lblName.Text = ""; lblKum.Text = ""; dataGridView1.DataSource = ""; } } } }

Form : Agent_Pay.cs (FG�H�IWM�\�M�� I�#�(���#�)) using System.Data.SqlClient; namespace Project_desktop { public partial class Agent_Pay : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id, AgeID;//%+)ก$�,�:�%+1$+�8txt/0E%+)ก$��:� �frmMain"1�*

Page 74: appendix - bc.msu.ac.th

267

public Agent_Pay(string Aid)//%+)ก$�,�:�%+1$+�8,�:��$�8� { InitializeComponent(); AgeID = Aid;//!��4�$1$ ��,�:�%+ } public void Clear() { id = getAgent_Pay(); lblPayID.Text = id; lblMem.Text = ""; lblSum.Text = ""; lblNet.Text = ""; lblMoney.Text = ""; comboBox1.SelectedItem = ""; } private void ShowAgent() { try { objcon.Conn(); string strSql; strSql = "SELECT a.Agent_id, UPPER(a.Agent_tname)+''+ UPPER(a.Agent_fname)+' '+ UPPER(a.Agent_lname)AS name,k.Kum_name FROM Agent AS a INNER JOIN Kum AS k ON a.Kum_id = k.Kum_id WHERE (a.Agent_id = '" + txtAgenID.Text + "')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); txtAgenID.Text = dr["Agent_id"].ToString(); lblname.Text = dr["name"].ToString(); lblKum.Text = dr["Kum_name"].ToString(); ComDeate(); dr.Close();

Page 75: appendix - bc.msu.ac.th

268

} } catch { } } private void btnCheck_Click(object sender, EventArgs e) { ShowAgent(); } public string getAgent_Pay() { objcon.Conn(); string sql1 = "SELECT MAX(Agp_id) FROM Agent_Pay"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id;//M00005 last_id = comSql.ExecuteScalar().ToString(); int id3, id4, id5, id6; string id_s6; string id_s5; string id_s4; string id_s3; string id_s2 = "P"; string id_s1 = "A"; string id_s; objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Agent_Pay"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Agent_Pay"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader();

Page 76: appendix - bc.msu.ac.th

269

dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Agent_Pay"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); objcon.Conn(); string sql6 = "SELECT SUBSTRING('" + last_id + "',6, 1)AS id1 FROM Agent_Pay"; comSql = new SqlCommand(sql6, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s6 = dr["id1"].ToString(); dr.Close(); id6 = int.Parse(id_s6); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); if (id6 >= 0 && id6 < 9) { id6 += 1; } else if (id6 == 9) { id6 = 0; if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0;

Page 77: appendix - bc.msu.ac.th

270

//====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; } } } } id_s = id_s1 + id_s2 + id3.ToString() + id4.ToString() + id5.ToString() + id6.ToString(); dr.Close(); return id_s; } private void ComDeate() { try { objcon.Conn(); string strSql = "select DISTINCT d.Death_id, m.Mem_tname + + m.Mem_fname + ' ' + m.Mem_lname AS mName from Death AS de, Member AS m , Receive AS r, Receive_Detail AS d where de.Death_id=d.Death_id AND de.Mem_id = m.Mem_id AND r.Receive_id = d.Receive_id AND r.Agent_id = '" + txtAgenID.Text + "' AND d.Death_id IN (SELECT DISTINCT rd.Death_id FROM Receive AS r , Receive_Detail AS rd where r.Receive_id = rd.Receive_id AND rd.Death_id NOT IN ( select Death_id from Agent_Pay ) )";

Page 78: appendix - bc.msu.ac.th

271

comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); if (dr.HasRows == true) { dt.Load(dr); comboBox1.DataSource = dt; comboBox1.DisplayMember = "mName"; comboBox1.ValueMember = "Death_id"; } comboBox1.Items.RemoveAt(0); } catch { } dr.Close(); } private void ShowAge_Pay() { objcon.Conn(); string sql = " SELECT p.Agp_id,UPPER(a.Agent_tname)+''+ UPPER(a.Agent_fname)+' '+ UPPER(a.Agent_lname)AS name,p.Agp_net,p.Agp_money FROM Agent_Pay p,Agent a WHERE a.Agent_id ='" + txtAgenID.Text + "' Order by Agp_id DESC"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = ""�#/0Eก$+(�$D"; dataGridView1.Columns[1].HeaderText = "S9E2,�:�/�"; dataGridView1.Columns[2].HeaderText = "D2�"�-�!G/�-/0E(�$D"; dataGridView1.Columns[3].HeaderText = "(7$�:�"�-�/0E,�2�!��"; dataGridView1.Columns[0].Width = 100; dataGridView1.Columns[1].Width = 100;

Page 79: appendix - bc.msu.ac.th

272

dataGridView1.Columns[2].Width = 100; dataGridView1.Columns[3].Width = 100; } private int countMem() { objcon.Conn(); string sql = "select count(Mem_id) from Member where Mem_status ='"%Z�!1$S-ก' AND Kum_id ='K01'"; comSql = new SqlCommand(sql, objcon.conn1); string cMem; int a; cMem = comSql.ExecuteScalar().ToString(); a = int.Parse(cMem); return a; } private void Agent_Pay_Load(object sender, EventArgs e) { id = getAgent_Pay(); lblPayID.Text = id; txtAgenID.Focus(); txtAgenID.Text = "a0001"; ShowAge_Pay(); } private void btnSave_Click(object sender, EventArgs e) { int countMemData, countMemLable; countMemData = countMem(); countMemLable = int.Parse(lblMem.Text); if (countMemLable != countMemData) { MessageBox.Show("!1$S-ก(�$D"�-�D���1�4+8"); return; } objcon.Conn(); string sql1 = "select Death_id from Agent_Pay WHERE Death_id='" + AgeID + "'";

Page 80: appendix - bc.msu.ac.th

273

comSql = new SqlCommand(sql1, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { MessageBox.Show("(�$D4�$,28�/����:"); dr.Close(); } else { dr.Close(); //---8��/Pก#�21*� if (txtAgenID.Text != "") { string strSql = "INSERT INTO Agent_Pay (Agp_id, Agp_date,Death_id, Agp_amount,Agp_sum, Agp_net,Agp_money, Agent_id,Of_id) Values(@Agp_id, @Agp_date,@Death_id, @Agp_amount, @Agp_sum,@Agp_net,@Agp_money, @Agent_id,@Of_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Agp_id", SqlDbType.Char).Value = lblPayID.Text; comSql.Parameters.Add("Agp_date", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Death_id", SqlDbType.Char).Value = comboBox1.SelectedValue.ToString(); comSql.Parameters.Add("Agp_amount", SqlDbType.Int).Value = int.Parse(lblMem.Text); comSql.Parameters.Add("Agp_sum", SqlDbType.Float).Value = float.Parse(lblSum.Text); comSql.Parameters.Add("Agp_net", SqlDbType.Float).Value = float.Parse(lblNet.Text); comSql.Parameters.Add("Agp_money", SqlDbType.Float).Value = float.Parse(lblMoney.Text); comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = txtAgenID.Text; string Officer = "O0001"; comSql.Parameters.Add("Of_id", SqlDbType.Char).Value = Officer; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); ComDeate(); ShowAge_Pay();

Page 81: appendix - bc.msu.ac.th

274

Clear(); } dr.Close(); } else { MessageBox.Show("ก+Go$ก+2ก#�21*� ��4+84�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } objcon.conn1.Close(); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { int cMem = countMem(); lblDataMem.Text = cMem.ToString(); objcon.Conn(); string DeathID = comboBox1.SelectedValue.ToString(); AgeID = comboBox1.SelectedValue.ToString(); string strSql = "SELECT COUNT(r.Receive_id) AS Num FROM Receive AS r INNER JOIN Receive_Detail AS d ON r.Receive_id = d.Receive_id WHERE (d.Death_id = '" + DeathID + "') AND (r.Agent_id = '" + txtAgenID.Text + "')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); string mNum = dr["Num"].ToString(); lblMem.Text = mNum; dr.Close(); float people, sumPeplo, sum, send; people = float.Parse(mNum); sumPeplo = people * 30; sum = sumPeplo * 13 / 100;

Page 82: appendix - bc.msu.ac.th

275

lblSum.Text = sumPeplo.ToString(); lblNet.Text = sum.ToString(); send = sumPeplo - sum; lblMoney.Text = send.ToString(); } catch { } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblPayID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); lblname.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); lblNet.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); lblMoney.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); ShowAge_Pay(); } private void btnPrint_Click(object sender, EventArgs e) { frm_prAgePay f = new frm_prAgePay(lblPayID.Text, AgeID); f.Show(); } private void txtAgenID_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { btnCheck_Click(sender, e); } }

Page 83: appendix - bc.msu.ac.th

276

private void txtAgenID_TextChanged(object sender, EventArgs e) { if (txtAgenID.Text == "") { lblname.Text = ""; lblKum.Text = ""; lblMem.Text = ""; lblSum.Text = ""; lblNet.Text = ""; lblMoney.Text = ""; comboBox1.SelectedValue = ""; dataGridView1.DataSource = ""; } } } }

Form : Out.cs (FG�H�Iก��Q� ก) using System.Data.SqlClient; namespace Project_desktop { public partial class Out : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id, AgeID,OutMem; public Out(string aID) { InitializeComponent(); AgeID = aID; }

Page 84: appendix - bc.msu.ac.th

277

public void clear() { id = getResignID(); lblOutID.Text = id; txtCheck.Text = ""; lblName.Text = ""; lblKum.Text = ""; dataGridView2.DataSource = ""; } private void ShowResign() { objcon.Conn(); string strSql = "SELECT r.Out_id,m.Mem_id, UPPER(m.Mem_fname)+' '+ UPPER(m.Mem_lname) ,k.Kum_name FROM Resign AS r ,Member AS m,Kum AS k WHERE m.Kum_id = k.Kum_id AND r.Mem_id = m.Mem_id Order by Out_id DESC"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!�$22ก"; dataGridView1.Columns[1].HeaderText = "+��!"; dataGridView1.Columns[2].HeaderText = "S9E2-!กG�!1$S-ก"; dataGridView1.Columns[3].HeaderText = "4G�1"; dataGridView1.Columns[0].Width = 100; dataGridView1.Columns[1].Width = 100; dataGridView1.Columns[2].Width = 100; dataGridView1.Columns[3].Width = 120; } public string getResignID() { objcon.Conn(); string sql1 = "SELECT MAX(Out_id) FROM Resign"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id;

Page 85: appendix - bc.msu.ac.th

278

last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "R"; string id_s; objcon.Conn(); string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Resign"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString(); objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Resign"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Resign"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Resign"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3);

Page 86: appendix - bc.msu.ac.th

279

id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9) { id2 += 1; } else if (id2 == 9) { id2 = 0; } }

Page 87: appendix - bc.msu.ac.th

280

} } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s; } private void Out_Load(object sender, EventArgs e) { objcon.Conn(); id = getResignID(); lblOutID.Text = id; ShowResign(); txtCheck.Focus(); btnClear.Enabled = false; } private void ShowMember() { objcon.Conn(); string strSql; strSql = "SELECT m.Mem_id, UPPER(m.Mem_fname) + ' ' + UPPER(m.Mem_lname) AS Expr1,k.Kum_name FROM Member AS m ,Kum AS k WHERE (m.Mem_status = '"%Z�!1$S-ก') AND m.Kum_id = k.Kum_id AND (Mem_id LIKE '%" + txtCheck.Text + "%') OR(Mem_fname LIKE '%" + txtCheck.Text + "%') OR(Mem_lname LIKE '%" + txtCheck.Text + "%')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dataGridView2.Columns[0].HeaderText = "+��!"; dataGridView2.Columns[1].HeaderText = "!1$S-ก"; dataGridView2.Columns[2].HeaderText = "4G�1"; } private void btnCheck_Click_1(object sender, EventArgs e) {

Page 88: appendix - bc.msu.ac.th

281

ShowMember(); dataGridView2.Visible = true; string strSql = " SELECT Mem_id FROM Resign WHERE Mem_id='" + txtCheck.Text + "'"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); if (dr.HasRows == true) { dr.Read(); OutMem = dr["Mem_id"].ToString(); dr.Close(); } else { OutMem = ""; } } private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } txtCheck.Text = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString(); lblName.Text = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); lblKum.Text = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString(); dataGridView2.Visible = false; } private void btnSave_Click(object sender, EventArgs e) {//---8��/Pก#�21*� objcon.Conn(); if(OutMem!="" ) { MessageBox.Show("�$22ก���:4�)", "�(��",92�", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;

Page 89: appendix - bc.msu.ac.th

282

} if (lblName.Text == "") { MessageBox.Show("�1����"%Z�!1$S-ก���:4�)", "�(��",92�", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtCheck.Text != "" ) { string strSql = "INSERT INTO Resign(Out_id,Out_date,Mem_id,Agent_id) Values(@Out_id,@Out_date,@Mem_id,@Agent_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Out_id", SqlDbType.Char).Value = lblOutID.Text; comSql.Parameters.Add("Out_date", SqlDbType.DateTime).Value = DateTime.Now; comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = txtCheck.Text; string Agent = "A0001"; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = Agent; try { int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); string sql2 = "UPDATE Member SET Mem_status = '�$22ก' WHERE (Mem_id = '" + txtCheck.Text + "')"; comSql = new SqlCommand(sql2, objcon.conn1); int numRec2 = comSql.ExecuteNonQuery(); if (numRec2 > 0) { MessageBox.Show("�ก��##�21*�"+0D8+�2D���:", "��ก$+�ก��##�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } ShowResign(); clear();

Page 90: appendix - bc.msu.ac.th

283

} } catch (Exception ex) { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowResign(); } } else { MessageBox.Show("4Go�1����ก+2ก#�21*�4�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } { objcon.conn1.Close(); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblOutID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); txtCheck.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); string Mem_fname; Mem_fname = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); lblName.Text = Mem_fname; lblKum.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); btnSave.Enabled = false; btnClear.Enabled = true } private void btnClear_Click(object sender, EventArgs e) {

Page 91: appendix - bc.msu.ac.th

284

clear(); btnSave.Enabled = true; } private void btnPrint_Click(object sender, EventArgs e) { frm_prOut f = new frm_prOut(AgeID, lblOutID.Text); f.Show(); } private void txtCheck_TextChanged(object sender, EventArgs e) { if (txtCheck.Text == "") { lblName.Text = ""; lblKum.Text = ""; dataGridView2.DataSource = ""; } } } }

Form : Interest.cs (FG�H�II�#_กO �PQ�PO�I�Q��T�\K�]) using System.Data.SqlClient; namespace Project_desktop { public partial class Interest : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; int count = 0, intBlance, sumBlance = 0; int retOld, retNew, sum = 0; private string id;

Page 92: appendix - bc.msu.ac.th

285

public Interest() { InitializeComponent(); } public void clear() { id = getIntID(); lblIntID.Text = id; txtCard.Focus(); txtCard.Text = ""; cboTname.SelectedItem = ""; txtName.Text = ""; txtLname.Text = ""; dtpBirth.Text = ""; txtOld.Text = ""; txtAdd.Text = ""; txtStred.Text = ""; txtTel.Text = ""; txtRe.Text = ""; txtRate.Text = ""; ShowInter(); } public string getIntID() { objcon.Conn(); string sql1 = "SELECT MAX(Interest_id) FROM Interest"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id; last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "I";

Page 93: appendix - bc.msu.ac.th

286

string id_s; objcon.Conn(); string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Interest"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString(); objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Interest"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Interest"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString() objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Interest"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); dr.Close(); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9)

Page 94: appendix - bc.msu.ac.th

287

{ id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9) { id2 += 1; } else if (id2 == 9) { id2 = 0; } } } } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s; }

Page 95: appendix - bc.msu.ac.th

288

private void callOld() { //:��/0E%�((G8�� int curyear2 = DateTime.Today.Year + 543; string day = DateTime.Today.Day.ToString(); string mount = DateTime.Today.Month.ToString(); int y3 = curyear2; string y4 = day + "/" + mount + "/" + y3.ToString(); int cDay, cMount; cDay = int.Parse(day); cMount = int.Parse(mount); //"ก-� string a, b, c, strDay; int year99, yearMem; DateTime dt1 = new DateTime(); dt1 = DateTime.Parse(dtpBirth.Text); a = dt1.Day.ToString(); DateTime dt2 = new DateTime(); dt2 = DateTime.Parse(dtpBirth.Text); b = dt2.Month.ToString(); DateTime dt3 = new DateTime(); dt3 = DateTime.Parse(dtpBirth.Text); c = dt3.Year.ToString(); year99 = int.Parse(c); yearMem = year99 + 543; strDay = a + "/" + b + "/" + yearMem; string btd = strDay; string[] x; x = strDay.Split('/'); string btdDay, btdMount, btdYear; int btDay, btMount, btYear; btdDay = x[0]; btdMount = x[1]; btdYear = x[2]; btDay = int.Parse(btdDay);

Page 96: appendix - bc.msu.ac.th

289

btMount = int.Parse(btdMount); btYear = int.Parse(btdYear); string cNumDay = DateTime.DaysInMonth(y3, cMount).ToString();//:��/0E!*�!G�#2�"�92���)%�%�((G8�� string NumDay = DateTime.DaysInMonth(btYear, btMount).ToString();//:��/0E!*�!G�#2�"�92���)%�"ก-� //,+:(!28:�� int numD, numBtd = 0; numD = int.Parse(NumDay); if (cMount > btMount) { numBtd = curyear2 - btYear; } else if (cMount < btMount) { numBtd = curyear2 - btYear - 1; } else { if (cDay > btDay) { numBtd = curyear2 - btYear; } else if (cDay < btDay) { numBtd = curyear2 - btYear - 1; } else { numBtd = curyear2 - btYear; } } txtOld.Text = numBtd.ToString(); } public int CalInterest() //��8(7$�:��*�+�8��%+)3DS�6 { string strSQl;

Page 97: appendix - bc.msu.ac.th

290

strSQl = "SELECT Count(Mem_id) AS cont FROM Interest WHERE Mem_id =('"+txtCheck.Text+"')"; comSql = new SqlCommand(strSQl, objcon.conn1); objcon.Conn(); dr = comSql.ExecuteReader(); dr.Read(); string strcount; strcount = dr["cont"].ToString(); count = int.Parse(strcount); return count; } private void ShowMembers()//--�!��#�21*� � dataGridView2 { objcon.Conn(); string strSql; strSql = "SELECT Mem_id, UPPER(Mem_fname) + ' ' + UPPER(Mem_lname) AS name FROM Member WHERE ((Mem_id LIKE '%"+txtCheck.Text+"%') OR (Mem_fname LIKE '%"+txtCheck.Text+"%') OR (Mem_lname LIKE '%"+txtCheck.Text+"%')) AND (Mem_status = '"%Z�!1$S-ก') AND (Kum_id='K01') "; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView2.DataSource = dt; dataGridView2.Columns[0].HeaderText = "+��!"; dataGridView2.Columns[1].HeaderText = "S9E2 - !กG�"; } private void ShowInterest() { objcon.Conn(); string sql = " SELECT Interest_id,Interest_idcard, Interest_tname, Interest_fname, Interest_lname, Int_Percent, Interest_gender, Interest_birthday, Interest_address,Interest_stred, Interest_road, Interest_subdistrict, Interest_district, Interest_province, Interest_code, Interest_tel, Interest_Re FROM Interest WHERE Mem_id ='" + txtCheck.Text + "' Order by Interest_id DESC";

Page 98: appendix - bc.msu.ac.th

291

comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!�*�+�8��%+)3DS�6"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = "2�,+$��%+)3DS�6/0E���+�8"; dataGridView1.Columns[6].HeaderText = ":��"ก-�"; dataGridView1.Columns[7].HeaderText = ""5�"; dataGridView1.Columns[8].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[9].HeaderText = "k2D"; dataGridView1.Columns[10].HeaderText = "F��"; dataGridView1.Columns[11].HeaderText = ",7$8�"; dataGridView1.Columns[12].HeaderText = "27$"�2"; dataGridView1.Columns[13].HeaderText = "(���:��"; dataGridView1.Columns[14].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[15].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[16].HeaderText = "4:$1!�15���6"; dataGridView1.Columns[0].Width = 80; dataGridView1.Columns[1].Width = 80; dataGridView1.Columns[2].Width = 80; dataGridView1.Columns[3].Width = 80; dataGridView1.Columns[4].Width = 80; dataGridView1.Columns[5].Width = 80; dataGridView1.Columns[6].Width = 80; dataGridView1.Columns[7].Width = 80; dataGridView1.Columns[8].Width = 80; dataGridView1.Columns[9].Width = 80; dataGridView1.Columns[10].Width = 80; dataGridView1.Columns[11].Width = 80; dataGridView1.Columns[12].Width = 80;

Page 99: appendix - bc.msu.ac.th

292

dataGridView1.Columns[13].Width = 80; dataGridView1.Columns[14].Width = 80; dataGridView1.Columns[15].Width = 80; dataGridView1.Columns[16].Width = 80; callOld(); } private void button5_Click(object sender, EventArgs e) { ShowMembers(); dataGridView2.Visible = true; } private void button6_Click(object sender, EventArgs e) { if (intBlance <= 0)// intBlance 492 "%2+6"k'�4�"��92 { MessageBox.Show("8��/Pก�1����"); } else { //sumBlance 492 ��+:1 #2�"%2+6"k'� //sumBlance = "%2+6"k'�4�"��92 + "%2+6"k'�/0E"5-E1"#�$1$ �1� sumBlance = intBlance + int.Parse(txtRate.Text); if (sumBlance > 100) { MessageBox.Show("8��/Pก�1����"); } else { MessageBox.Show("8��/Pก���"); } } } private void ShowInter() { objcon.Conn();

Page 100: appendix - bc.msu.ac.th

293

string sql = "select Interest_id,Interest_idcard, Interest_tname, Interest_fname, Interest_lname, Int_Percent,Interest_gender,Interest_birthday,Interest_address,Interest_stred, Interest_road, Interest_subdistrict,Interest_district,Interest_province,Interest_code, Interest_tel, Interest_Re from Interest Order by Interest_id DESC"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!�*�+�8��%+)3DS�6"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = "2�,+$��%+)3DS�6/0E���+�8"; dataGridView1.Columns[6].HeaderText = ""5�"; dataGridView1.Columns[7].HeaderText = ":��"ก-�"; dataGridView1.Columns[8].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[9].HeaderText = "k2D"; dataGridView1.Columns[10].HeaderText = "F��"; dataGridView1.Columns[11].HeaderText = ",7$8�"; dataGridView1.Columns[12].HeaderText = "27$"�2"; dataGridView1.Columns[13].HeaderText = "(���:��"; dataGridView1.Columns[14].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[15].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[16].HeaderText = "4:$1!�15���6"; callOld(); } private void Interest_Load(object sender, EventArgs e) { objcon.Conn(); ShowInter(); id = getIntID(); lblIntID.Text = id; rdogenderM.Checked = true;

Page 101: appendix - bc.msu.ac.th

294

cboTname.SelectedIndex = 0; int curyear = DateTime.Today.Year + 543; int y2 = curyear; string mount = DateTime.Today.Month.ToString(); string day = DateTime.Today.Day.ToString(); string y = day + "/" + mount + "/" + y2.ToString(); dtpBirth.Value = DateTime.Parse(y); txtRoad.Text = "�4+!:++46"; txtSub.Text = ",�$�"; txtDistrict.Text = ""192�"; txtProvince.Text = "1�$!$+4$1"; txtCode.Text = "44000"; btnEdit.Enabled = false; btnDel.Enabled = false; txtOld.Text = ""; txtCheck.Focus(); } private void InsertInterest() { objcon.Conn(); string sql = "SELECT COUNT(Interest_id) as Intcount FROM Interest Where Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); string CountInt; CountInt = dr["Intcount"].ToString(); dr.Close(); int i; i = int.Parse(CountInt); if (i < 2)//4��:��*�+�8��%+)3DS�6 { if (txtName.Text != "" && txtLname.Text != "") { string strSql = "INSERT INTO Interest (Interest_id, Mem_id, Interest_idcard, Interest_tname,

Page 102: appendix - bc.msu.ac.th

295

Interest_fname, Interest_lname, Interest_gender, Interest_birthday, Interest_address,Interest_stred, Interest_road, Interest_subdistrict, Interest_district, Interest_province, Interest_code, Interest_tel, Interest_Re, Int_Percent,Agent_id)VALUES(@Interest_id,@Mem_id,@Interest_idcard,@Interest_tname,@Interest_fname,@Interest_lname,@Interest_gender,@Interest_birthday,@Interest_address,@Interest_stred,@Interest_road,@Interest_subdistrict,@Interest_district,@Interest_province,@Interest_code,@Interest_tel,@Interest_Re,@Int_Percent,@Agent_id)"; comSql = new SqlCommand(strSql, objcon.conn1); int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtOld.Text = year.ToString(); comSql.Parameters.Add("Interest_id", SqlDbType.Char).Value = lblIntID.Text; comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = txtCheck.Text; string idcard = txtCard.Text; comSql.Parameters.Add("Interest_idcard", SqlDbType.Char).Value = idcard; comSql.Parameters.Add("Interest_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem; comSql.Parameters.Add("Interest_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Interest_lname", SqlDbType.VarChar).Value = txtLname.Text; string sex; if (rdogenderM.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } comSql.Parameters.Add("Interest_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Interest_birthday", SqlDbType.DateTime).Value = dtpBirth.Value; comSql.Parameters.Add("Interest_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Interest_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Interest_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Interest_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Interest_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Interest_province", SqlDbType.VarChar).Value = txtProvince.Text;

Page 103: appendix - bc.msu.ac.th

296

comSql.Parameters.Add("Interest_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Interest_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Interest_Re", SqlDbType.VarChar).Value = txtRe.Text; comSql.Parameters.Add("Int_Percent", SqlDbType.Int).Value = txtRate.Text; string Agent = "A0001"; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = Agent; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowInterest(); objcon.conn1.Close(); clear(); } } else { MessageBox.Show("4Go�1����ก+2ก#�21*�4�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("�1�!$1$+F"5-E1�*�+�8��%+)3DS�6���4�)"); } } private void btnSAVE_Click_1(object sender, EventArgs e) { objcon.Conn(); string sql0 = "SELECT sum(Int_Percent) FROM Interest WHERE Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql0, objcon.conn1); label3.Text = comSql.ExecuteScalar().ToString(); if (label3.Text == "") {

Page 104: appendix - bc.msu.ac.th

297

label3.Text = "0"; } retOld = int.Parse(label3.Text); retNew = int.Parse(txtRate.Text); sum = retOld + retNew; if (sum > 100) { return; } if (intBlance > 100 )// intBlance 492 "%2+6"k'�4�"��92 { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����"+intBlance); } else { //sumBlance 492 ��+:1 #2�"%2+6"k'� //sumBlance = "%2+6"k'�4�"��92 + "%2+6"k'�/0E"5-E1"#�$1$ �1� sumBlance = intBlance + int.Parse(txtRate.Text); if (sumBlance <= 0) { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����"); } else { //MessageBox.Show("8��/Pก���"); InsertInterest(); } } string sql1 = "SELECT sum(Int_Percent) FROM Interest WHERE Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql1, objcon.conn1); label3.Text = comSql.ExecuteScalar().ToString(); if (label3.Text == "") { label3.Text = "0"; }

Page 105: appendix - bc.msu.ac.th

298

ShowInter(); string sql2 = "SELECT 100-SUM(Int_Percent) as Per FROM Interest Where Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); txtBalance.Text = dr["Per"].ToString(); intBlance = int.Parse(txtBalance.Text); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblIntID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); txtCard.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); cboTname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtLname.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); string sex = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); if (sex == "S$D") { rdogenderM.Checked = true; } else { rdogenderW.Checked = true; } dtpBirth.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); txtAdd.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); txtStred.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); txtRoad.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString(); txtSub.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(); txtDistrict.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();

Page 106: appendix - bc.msu.ac.th

299

txtProvince.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString(); txtCode.Text = dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString(); txtTel.Text = dataGridView1.Rows[e.RowIndex].Cells[15].Value.ToString(); txtRe.Text = dataGridView1.Rows[e.RowIndex].Cells[16].Value.ToString(); txtRateold.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); txtRateold.Visible = true; btnSAVE.Enabled = false; btnEdit.Enabled = true; btnDel.Enabled = true; } private void btnDel_Click_1(object sender, EventArgs e) { objcon.Conn(); if (lblIntID.Text == "") { return; } DialogResult dlgResult = MessageBox.Show("4Go,�2�ก$+�8#�21*��0. S��+92�1�", "D9�D��ก$+�8#�21*�", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { string strSql = "DELETE Interest WHERE Interest_id = '" + lblIntID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1); int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("�8#�21*�"+0D8+�2D���:", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F�8#�21*����", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } ShowInterest();

Page 107: appendix - bc.msu.ac.th

300

dr.Close(); } } private void btnEdit_Click_1(object sender, EventArgs e) { retOld = int.Parse(txtRateold.Text); retNew = int.Parse(txtRate.Text); if (retOld > retNew)//== %"ก�$ > % �1� { sum = retOld - retNew; MessageBox.Show("�ก��##�21*�"+0D8+�2D���:"); UpdateInterest(); } else { sum = retNew - retOld; if (intBlance > sum) { MessageBox.Show("�ก��##�21*�"+0D8+�2D���:"); UpdateInterest(); } else if (intBlance < sum) { MessageBox.Show("�1�!$1$+F�ก��##�21*����"); } else { MessageBox.Show("�ก��##�21*�"+0D8+�2D���:"); UpdateInterest(); } } objcon.Conn(); string sql0 = "SELECT sum(Int_Percent) FROM Interest WHERE Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql0, objcon.conn1); label3.Text = comSql.ExecuteScalar().ToString();

Page 108: appendix - bc.msu.ac.th

301

if (label3.Text == "") { label3.Text = "0"; } string sql2 = "SELECT 100-SUM(Int_Percent) as Per FROM Interest Where Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); txtBalance.Text = dr["Per"].ToString(); intBlance = int.Parse(txtBalance.Text); } private void UpdateInterest() { objcon.Conn(); if (lblIntID.Text != "" && txtCard.Text != "") { string strSql = "UPDATE Interest SET Interest_id=@Interest_id,Mem_id=@Mem_id,Interest_idcard=@Interest_idcard,Interest_tname=@Interest_tname,Interest_fname=@Interest_fname,Interest_lname=@Interest_lname,Interest_gender=@Interest_gender,Interest_birthday=@Interest_birthday,Interest_address=@Interest_address,Interest_stred=@Interest_stred,Interest_road=@Interest_road,Interest_subdistrict=@Interest_subdistrict, Interest_district=@Interest_district,Interest_province=@Interest_province,Interest_code=@Interest_code,Interest_tel=@Interest_tel,Interest_Re=@Interest_Re,Int_Percent=@Int_Percent WHERE Interest_id = '" + lblIntID.Text + "'"; comSql = new SqlCommand(strSql, objcon.conn1); int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtOld.Text = year.ToString(); comSql.Parameters.Add("Interest_id", SqlDbType.Char).Value = lblIntID.Text; comSql.Parameters.Add("Mem_id", SqlDbType.Char).Value = txtCheck.Text; string idcard = txtCard.Text; comSql.Parameters.Add("Interest_idcard", SqlDbType.Char).Value = idcard; comSql.Parameters.Add("Interest_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem;

Page 109: appendix - bc.msu.ac.th

302

comSql.Parameters.Add("Interest_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Interest_lname", SqlDbType.VarChar).Value = txtLname.Text; string sex; if (rdogenderM.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } comSql.Parameters.Add("Interest_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Interest_birthday", SqlDbType.DateTime).Value = dtpBirth.Value; comSql.Parameters.Add("Interest_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Interest_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Interest_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Interest_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Interest_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Interest_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Interest_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Interest_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Interest_Re", SqlDbType.VarChar).Value = txtRe.Text; comSql.Parameters.Add("Int_Percent", SqlDbType.Int).Value = txtRate.Text; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }

Page 110: appendix - bc.msu.ac.th

303

dr.Close(); ShowInterest(); id = getIntID(); lblIntID.Text = id; txtCard.Focus(); txtCard.Text = ""; cboTname.SelectedItem = ""; txtName.Text = ""; txtLname.Text = ""; dtpBirth.Text = ""; txtOld.Text = ""; txtAdd.Text = ""; txtStred.Text = ""; txtRoad.Text = ""; txtSub.Text = ""; txtDistrict.Text = ""; txtProvince.Text = ""; txtCode.Text = ""; txtTel.Text = ""; txtRe.Text = ""; txtRate.Text = ""; btnSAVE.Enabled = true; btnEdit.Enabled = false; } private void txtAdd_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) { e.KeyChar = Convert.ToChar(Keys.None); } } private void txtStred_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) {

Page 111: appendix - bc.msu.ac.th

304

e.KeyChar = Convert.ToChar(Keys.None); } } private void txtTel_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.� e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } } private void txtTel_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtTel.Text != "") { if (int.Parse(txtTel.Text) > 0) { btnSAVE_Click(sender, e); } } } private void btnSAVE_Click(object sender, KeyEventArgs e) { throw new NotImplementedException(); } private void txtCheck_TextChanged(object sender, EventArgs e) { if (txtCheck.Text == "") {

Page 112: appendix - bc.msu.ac.th

305

txtMname.Text = ""; dataGridView2.DataSource = ""; } } private void button2_Click(object sender, EventArgs e) { clear(); txtBalance.Text = ""; label3.Text = ""; txtRateold.Text = ""; txtCheck.Text = ""; txtMname.Text = ""; btnSAVE.Enabled = true; btnDel.Enabled = false; btnEdit.Enabled = false; } private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } txtCheck.Text = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString(); txtMname.Text = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); ShowInterest(); try { string sql2 = "SELECT 100-SUM(Int_Percent) as Per FROM Interest Where Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); txtBalance.Text = dr["Per"].ToString(); intBlance = int.Parse(txtBalance.Text); }

Page 113: appendix - bc.msu.ac.th

306

catch { txtBalance.Text = "0"; } try { objcon.Conn(); string sql = "SELECT sum(Int_Percent) FROM Interest WHERE Mem_id = '" + txtCheck.Text + "'"; comSql = new SqlCommand(sql, objcon.conn1); label3.Text = comSql.ExecuteScalar().ToString(); if (label3.Text == "") { label3.Text = "0"; } } catch { label3.Text = "0"; } dataGridView2.Visible = false; } private void txtRate_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.� e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } }

Page 114: appendix - bc.msu.ac.th

307

private void txtRate_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtAdd.Text != "") { if (int.Parse(txtAdd.Text) > 0) { btnSAVE_Click(sender, e); } } } } }

Form : Agent.cs (FG�H�II�#_กO �PQ���#��`O�) using System.Data.SqlClient; namespace Project_desktop { public partial class Agent : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id,KumID; public Agent() { InitializeComponent(); } public void clear() { maskedTextBox1.Focus(); id = getAgentID(); lblAgenID.Text = id; maskedTextBox1.Text = "";

Page 115: appendix - bc.msu.ac.th

308

cboTname.SelectedItem = ""; txtName.Text = ""; txtLname.Text = ""; txtOld.Text = ""; txtAdd.Text = ""; txtStred.Text = ""; txtTel.Text = ""; txtUser.Text = ""; txtPass.Text = ""; } private void ShowKum() { objcon.Conn(); string Sql = "Select Kum_id, Kum_name From Kum"; comSql = new SqlCommand(Sql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); cboKum.DataSource = dt; cboKum.DisplayMember = "Kum_name"; cboKum.ValueMember = "Kum_id"; dr.Close(); } private void ShowAgent() { objcon.Conn(); string strSql = "Select a.Agent_id,a.Agent_idcard,a.Agent_tname,a.Agent_fname,a.Agent_lname,a.Agent_gender,k.Kum_name,a.Agent_birthday,a.Agent_address,a.Agent_stred,a.Agent_road,a.Agent_subdistrict,a.Agent_district,a.Agent_province,a.Agent_code,a.Agent_tel,a.Useragent,a.Passwordagent From Agent a,Kum k WHERE a.Kum_id=k.Kum_id Order by Agent_id DESC"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr);

Page 116: appendix - bc.msu.ac.th

309

dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!,�:�/�"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = ""5�"; dataGridView1.Columns[6].HeaderText = "4G�1"; dataGridView1.Columns[7].HeaderText = ":��"ก-�"; dataGridView1.Columns[8].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[9].HeaderText = "k2D"; dataGridView1.Columns[10].HeaderText = "F��"; dataGridView1.Columns[11].HeaderText = ",7$8�"; dataGridView1.Columns[12].HeaderText = "27$"�2"; dataGridView1.Columns[13].HeaderText = "(���:��"; dataGridView1.Columns[14].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[15].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[16].HeaderText = "S9E2�*�"#�$ S�+)88"; dataGridView1.Columns[17].HeaderText = "+��!��$�"; } public string getAgentID() { objcon.Conn(); string sql1 = "SELECT MAX(Agent_id) FROM Agent"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id; last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "A"; string id_s; objcon.Conn();

Page 117: appendix - bc.msu.ac.th

310

string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Agent"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString(); objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Agent"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Agent"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Agent"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1; } else if (id5 == 9) { id5 = 0; //====id ,�:/0E 4

Page 118: appendix - bc.msu.ac.th

311

if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9) { id2 += 1; } else if (id2 == 9) { id2 = 0; } } } } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s; } private void btnSave_Click(object sender, EventArgs e) { objcon.Conn(); string sql1 = "select Kum_id from Agent WHERE Kum_id='" + KumID + "'"; comSql = new SqlCommand(sql1, objcon.conn1);

Page 119: appendix - bc.msu.ac.th

312

dr = comSql.ExecuteReader(); if (dr.HasRows == true) { MessageBox.Show("10#�21*�,�:�/�4G�1���:"); dr.Close(); } else { dr.Close(); //---8��/Pก#�21*� if (txtName.Text != "" && txtLname.Text != "") { string strSql = "INSERT INTO Agent(Agent_id,Agent_idcard,Agent_tname,Agent_fname,Agent_lname,Agent_gender,Agent_birthday,Agent_address,Agent_stred,Agent_road,Agent_subdistrict,Agent_district,Agent_province,Agent_code,Agent_tel,Useragent,Passwordagent,Kum_id) Values(@Agent_id,@Agent_idcard,@Agent_tname,@Agent_fname,@Agent_lname,@Agent_gender,@Agent_birthday,@Agent_address,@Agent_stred,@Agent_road,@Agent_subdistrict,@Agent_district,@Agent_province,@Agent_code,@Agent_tel,@Useragent,@Passwordagent,@Kum_id)"; comSql = new SqlCommand(strSql, objcon.conn1); string sex; if (radioButton1.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtOld.Text = year.ToString(); comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = lblAgenID.Text;

Page 120: appendix - bc.msu.ac.th

313

string idcard = maskedTextBox1.Text; comSql.Parameters.Add("Agent_idcard", SqlDbType.VarChar).Value = idcard; comSql.Parameters.Add("Agent_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem; comSql.Parameters.Add("Agent_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Agent_lname", SqlDbType.VarChar).Value = txtLname.Text; comSql.Parameters.Add("Agent_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Agent_birthday", SqlDbType.DateTime).Value = dtpBirth.Value; comSql.Parameters.Add("Agent_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Agent_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Agent_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Agent_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Agent_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Agent_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Agent_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Agent_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Useragent", SqlDbType.VarChar).Value = txtUser.Text; comSql.Parameters.Add("Passwordagent", SqlDbType.VarChar).Value = txtPass.Text; comSql.Parameters.Add("Kum_id", SqlDbType.Char).Value = cboKum.SelectedValue; try { int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowAgent(); clear(); } } catch (Exception ex) { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowAgent(); }

Page 121: appendix - bc.msu.ac.th

314

} else { MessageBox.Show("4Go�1����ก+2ก#�21*�4�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } private void Agent_Load(object sender, EventArgs e) { objcon.Conn(); ShowKum(); ShowAgent(); id = getAgentID(); lblAgenID.Text = id; int curyear = DateTime.Today.Year + 543; int y2 = curyear - 60; string mount = DateTime.Today.Month.ToString(); string day = DateTime.Today.Day.ToString(); string y = day + "/" + mount + "/" + y2.ToString(); dtpBirth.Value = DateTime.Parse(y); txtRoad.Text = "�4+!:++46"; txtSub.Text = ",�$�"; txtDistrict.Text = ""192�"; txtProvince.Text = "1�$!$+4$1"; txtCode.Text = "44000"; btnUpdate.Enabled = false; //SetDate(); txtCheck.Focus(); } private void CallOld() { //:��/0E%�((G8�� int curyear2 = DateTime.Today.Year + 543; string day = DateTime.Today.Day.ToString();

Page 122: appendix - bc.msu.ac.th

315

string mount = DateTime.Today.Month.ToString(); int y3 = curyear2; string y4 = day + "/" + mount + "/" + y3.ToString(); int cDay, cMount; cDay = int.Parse(day); cMount = int.Parse(mount); //"ก-� //========="5-E1",-1 string a, b, c, strDay; int year99, yearMem; DateTime dt1 = new DateTime(); dt1 = DateTime.Parse(dtpBirth.Text); a = dt1.Day.ToString(); DateTime dt2 = new DateTime(); dt2 = DateTime.Parse(dtpBirth.Text); b = dt2.Month.ToString(); DateTime dt3 = new DateTime(); dt3 = DateTime.Parse(dtpBirth.Text); c = dt3.Year.ToString(); year99 = int.Parse(c); yearMem = year99 + 543; strDay = a + "/" + b + "/" + yearMem; string btd = strDay; //=========!-.�!G�"5-E1",-1 string[] x; x = strDay.Split('/'); string btdDay, btdMount, btdYear; int btDay, btMount, btYear; btdDay = x[0]; btdMount = x[1]; btdYear = x[2]; btDay = int.Parse(btdDay); btMount = int.Parse(btdMount); btYear = int.Parse(btdYear); string cNumDay = DateTime.DaysInMonth(y3, cMount).ToString();//:��/0E!*�!G�#2�"�92���)%�%�((G8��

Page 123: appendix - bc.msu.ac.th

316

string NumDay = DateTime.DaysInMonth(btYear, btMount).ToString();//:��/0E!*�!G�#2�"�92���)%�"ก-� //,+:(!28:�� int numD, numBtd = 0; numD = int.Parse(NumDay); if (cMount > btMount) { numBtd = curyear2 - btYear; } else if (cMount < btMount) { numBtd = curyear2 - btYear - 1; } else { if (cDay > btDay) { numBtd = curyear2 - btYear; } else if (cDay < btDay) { numBtd = curyear2 - btYear - 1; } else { numBtd = curyear2 - btYear; } } txtOld.Text = numBtd.ToString(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; }

Page 124: appendix - bc.msu.ac.th

317

lblAgenID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); maskedTextBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); cboTname.SelectedItem = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtLname.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); string sex = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); if (sex == "S$D") { radioButton1.Checked = true; } else { radioButton2.Checked = true; } cboKum.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); dtpBirth.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); txtAdd.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); txtStred.Text= dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); txtRoad.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString(); txtSub.Text= dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(); txtDistrict.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString(); txtProvince.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString(); txtCode.Text= dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString(); txtTel.Text = dataGridView1.Rows[e.RowIndex].Cells[15].Value.ToString(); txtUser.Text = dataGridView1.Rows[e.RowIndex].Cells[16].Value.ToString(); txtPass.Text = dataGridView1.Rows[e.RowIndex].Cells[17].Value.ToString(); btnSave.Enabled = false; btnUpdate.Enabled = true; CallOld(); } private void btnDelete_Click(object sender, EventArgs e) { if (lblAgenID.Text == "")

Page 125: appendix - bc.msu.ac.th

318

{ return; } DialogResult dlgResult = MessageBox.Show("4Go,�2�ก$+�8#�21*��0. S��+92�1�", "D9�D��ก$+�8#�21*�", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { string strSql = "DELETE Agent WHERE Agent_id = '" + lblAgenID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1); int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("�8#�21*�"+0D8+�2D���:", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F�8#�21*����", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowAgent(); } private void btnUpdate_Click(object sender, EventArgs e) { if (lblAgenID.Text != "" && maskedTextBox1.Text != "") { string strSql = "UPDATE Agent SET Agent_id=@Agent_id,Agent_idcard=@Agent_idcard,Agent_tname=@Agent_tname,Agent_fname=@Agent_fname,Agent_lname=@Agent_lname,Agent_gender=@Agent_gender,Agent_birthday=@Agent_birthday,Agent_address=@Agent_address,Agent_stred=@Agent_stred,Agent_road=@Agent_road,Agent_subdistrict=@Agent_subdistrict,Agent_district=@Agent_district,Agent_province=@Agent_province,Agent_code=@Agent_code,Agent_tel=@Agent_tel,Useragent=@Useragent,Passwordagent=@Passwordagent,Kum_id=@Kum_id WHERE Agent_id = '" + lblAgenID.Text + "'"; comSql = new SqlCommand(strSql, objcon.conn1);

Page 126: appendix - bc.msu.ac.th

319

string sex; if (radioButton1.Checked == true) { sex = "S$D"; } else { sex = "�Q-�"; } int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtOld.Text = year.ToString(); comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = lblAgenID.Text; string idcard = maskedTextBox1.Text; comSql.Parameters.Add("Agent_idcard", SqlDbType.VarChar).Value = idcard; comSql.Parameters.Add("Agent_tname", SqlDbType.VarChar).Value = cboTname.SelectedItem; comSql.Parameters.Add("Agent_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Agent_lname", SqlDbType.VarChar).Value = txtLname.Text; comSql.Parameters.Add("Agent_gender", SqlDbType.VarChar).Value = sex; comSql.Parameters.Add("Agent_birthday", SqlDbType.DateTime).Value = dtpBirth.Value; comSql.Parameters.Add("Agent_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Agent_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Agent_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Agent_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Agent_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Agent_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Agent_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Agent_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Useragent", SqlDbType.VarChar).Value = txtUser.Text; comSql.Parameters.Add("Passwordagent", SqlDbType.VarChar).Value = txtPass.Text; comSql.Parameters.Add("Kum_id", SqlDbType.Char).Value = cboKum.SelectedValue.ToString(); int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) {

Page 127: appendix - bc.msu.ac.th

320

MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowAgent(); } private void ShowCheck() { objcon.Conn(); string strSql; strSql = "SELECT * FROM Agent WHERE (Agent_id LIKE '%" + txtCheck.Text + "%') OR(Agent_fname LIKE '%" + txtCheck.Text + "%') OR(Agent_lname LIKE '%" + txtCheck.Text + "%')"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!!1$S-ก"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "47$�7$���$"; dataGridView1.Columns[3].HeaderText = "S9E2"; dataGridView1.Columns[4].HeaderText = "�$1!กG�"; dataGridView1.Columns[5].HeaderText = ""5�"; dataGridView1.Columns[6].HeaderText = "4G�1"; dataGridView1.Columns[7].HeaderText = ":��"ก-�"; dataGridView1.Columns[8].HeaderText = ":��/0E!1�4+"; dataGridView1.Columns[9].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[10].HeaderText = "k2D"; dataGridView1.Columns[11].HeaderText = "F��"; dataGridView1.Columns[12].HeaderText = ",7$8�";

Page 128: appendix - bc.msu.ac.th

321

dataGridView1.Columns[13].HeaderText = "27$"�2"; dataGridView1.Columns[14].HeaderText = "(���:��"; dataGridView1.Columns[15].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[16].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[17].HeaderText = "4�$!1�4+"; } private void btnCheck_Click(object sender, EventArgs e) { ShowCheck(); } private void dtpBirth_ValueChanged(object sender, EventArgs e) { int x = int.Parse(dtpBirth.Value.Year.ToString()); int y = int.Parse(DateTime.Now.Year.ToString()); int year = y - x; txtOld.Text = year.ToString(); int d = 60; int f; f = int.Parse(txtOld.Text); if (d > f) { MessageBox.Show("2$DG�1�FP� 60 %� �1�!$1$+F!1�4+��� !!!", "#�2�-�5�$�", MessageBoxButtons.OK, MessageBoxIcon.Information); txtOld.Focus(); txtOld.SelectAll(); return; } } private void txtAdd_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) { e.KeyChar = Convert.ToChar(Keys.None); } }

Page 129: appendix - bc.msu.ac.th

322

private void txtStred_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 47) || (e.KeyChar > 57)) { e.KeyChar = Convert.ToChar(Keys.None); } } private void txtTel_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && txtTel.Text != "") { if (int.Parse(txtTel.Text) > 0) { btnSave_Click(sender, e); } } } private void txtTel_KeyPress(object sender, KeyPressEventArgs e) { //,+:(!28:�$ key /0Eก� "%Z�,�:"�# �+92 %GH14:84G1 �+92�1� if (char.IsNumber(e.KeyChar) == true || char.IsControl(e.KeyChar) == true) { //F�$ S� ()+�840D6��.� e.Handled = false; } else { //F�$�1� S� ()�1�+�840D6��.� e.Handled = true; } } private void cboKum_SelectedIndexChanged(object sender, EventArgs e) { KumID = cboKum.SelectedValue.ToString();

Page 130: appendix - bc.msu.ac.th

323

} } }

Form : Informant.cs (FG�H�II�#_กO �PQ�PO�WO�) using System.Data.SqlClient; namespace Project_desktop { public partial class Informant : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; private string id; public Informant() { InitializeComponent(); } public void clear() { id = getInfID(); lblInfID.Text = id; maskedTextBox1.Text = ""; txtName.Text = ""; txtLname.Text = ""; txtAdd.Text = ""; txtStred.Text = ""; txtTel.Text = ""; txtRe.Text = ""; } private void ShowInformant() { objcon.Conn();

Page 131: appendix - bc.msu.ac.th

324

string strSql = "Select Inf_id,idcard,Inf_fname,Inf_lname,Inf_address,Inf_stred,Inf_road,Inf_subdistrict,Inf_district,Inf_province,Inf_code,Inf_tel,Inf_relationship From Informant Order by Inf_id DESC"; comSql = new SqlCommand(strSql, objcon.conn1); dr = comSql.ExecuteReader(); dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Columns[0].HeaderText = "+��!�*��(��"; dataGridView1.Columns[1].HeaderText = "+��!8�,+%+)S$S�"; dataGridView1.Columns[2].HeaderText = "S9E2"; dataGridView1.Columns[3].HeaderText = "�$1!กG�"; dataGridView1.Columns[4].HeaderText = "8�$�"�#/0E"; dataGridView1.Columns[5].HeaderText = "k2D"; dataGridView1.Columns[6].HeaderText = "F��"; dataGridView1.Columns[7].HeaderText = ",7$8�"; dataGridView1.Columns[8].HeaderText = "27$"�2"; dataGridView1.Columns[9].HeaderText = "(���:��"; dataGridView1.Columns[10].HeaderText = "+��!�%+�o0D6"; dataGridView1.Columns[11].HeaderText = ""82+63/+��5/6"; dataGridView1.Columns[12].HeaderText = "4:$1!�15���6"; } public string getInfID() { objcon.Conn(); string sql1 = "SELECT MAX(Inf_id) FROM Informant"; comSql = new SqlCommand(sql1, objcon.conn1); string last_id; last_id = comSql.ExecuteScalar().ToString(); int id2, id3, id4, id5; string id_s5; string id_s4; string id_s3; string id_s2; string id_s1 = "J";

Page 132: appendix - bc.msu.ac.th

325

string id_s; objcon.Conn(); string sql2 = "SELECT SUBSTRING('" + last_id + "',2,1)AS id1 FROM Informant"; comSql = new SqlCommand(sql2, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s2 = dr["id1"].ToString(); objcon.Conn(); string sql3 = "SELECT SUBSTRING('" + last_id + "',3, 1)AS id1 FROM Informant"; comSql = new SqlCommand(sql3, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s3 = dr["id1"].ToString(); objcon.Conn(); string sql4 = "SELECT SUBSTRING('" + last_id + "',4, 1)AS id1 FROM Informant"; comSql = new SqlCommand(sql4, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s4 = dr["id1"].ToString(); objcon.Conn(); string sql5 = "SELECT SUBSTRING('" + last_id + "',5, 1)AS id1 FROM Informant"; comSql = new SqlCommand(sql5, objcon.conn1); dr = comSql.ExecuteReader(); dr.Read(); id_s5 = dr["id1"].ToString(); id5 = int.Parse(id_s5); id4 = int.Parse(id_s4); id3 = int.Parse(id_s3); id2 = int.Parse(id_s2); if (id5 >= 0 && id5 < 9) { id5 += 1;

Page 133: appendix - bc.msu.ac.th

326

} else if (id5 == 9) { id5 = 0; //====id ,�:/0E 4 if (id4 >= 0 && id4 < 9) { id4 += 1; } else if (id4 == 9) { id4 = 0; //====id ,�:/0E 3 if (id3 > 0 && id3 < 9) { id3 += 1; } else if (id3 == 9) { id3 = 0; //====id ,�:/0E 2 if (id2 > 0 && id2 < 9) { id2 += 1; } else if (id2 == 9) { id2 = 0; } } } } id_s = id_s1 + id2.ToString() + id3.ToString() + id4.ToString() + id5.ToString(); dr.Close(); return id_s;

Page 134: appendix - bc.msu.ac.th

327

} private void Informant_Load(object sender, EventArgs e) { objcon.Conn(); ShowInformant(); id = getInfID(); lblInfID.Text = id; maskedTextBox1.Focus(); txtRoad.Text = "�4+!:++46"; txtSub.Text = ",�$�"; txtDistrict.Text = ""192�"; txtProvince.Text = "1�$!$+4$1"; txtCode.Text = "44000"; btnUpdate.Enabled = false; btnDelete.Enabled = false; } private void btnSave_Click(object sender, EventArgs e) { //---8��/Pก#�21*� if (txtName.Text != "" && txtLname.Text !="") { string strSql = "INSERT INTO Informant(Inf_id,idcard,Inf_fname,Inf_lname,Inf_address,Inf_stred,Inf_road,Inf_subdistrict,Inf_district,Inf_province,Inf_code,Inf_tel,Inf_relationship,Agent_id) Values(@Inf_id,@idcard,@Inf_fname,@Inf_lname,@Inf_address,@Inf_stred,@Inf_road,@Inf_subdistrict,@Inf_district,@Inf_province,@Inf_code,@Inf_tel,@Inf_relationship,@Agent_id)"; comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Inf_id", SqlDbType.Char).Value = id; string idcard = maskedTextBox1.Text; comSql.Parameters.Add("idcard", SqlDbType.VarChar).Value = idcard; comSql.Parameters.Add("Inf_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Inf_lname", SqlDbType.VarChar).Value = txtLname.Text; comSql.Parameters.Add("Inf_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Inf_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Inf_road", SqlDbType.VarChar).Value = txtRoad.Text;

Page 135: appendix - bc.msu.ac.th

328

comSql.Parameters.Add("Inf_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Inf_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Inf_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Inf_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Inf_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Inf_relationship", SqlDbType.VarChar).Value = txtRe.Text; string Agent = "A0001"; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = Agent; try { int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowInformant(); clear(); } } catch (Exception ex) { MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); ShowInformant(); } } else { MessageBox.Show("4Go�1����ก+2ก#�21*�4�)", "ก+Go$ก+2ก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Warning); } { objcon.conn1.Close(); } }

Page 136: appendix - bc.msu.ac.th

329

private void btnUpdate_Click(object sender, EventArgs e) { if (lblInfID.Text != "" && maskedTextBox1.Text != "") { string strSql = "UPDATE Informant SET Inf_id=@Inf_id,idcard=@idcard,Inf_fname=@Inf_fname,Inf_lname=@Inf_lname,Inf_address=@Inf_address,Inf_stred=@Inf_stred,Inf_road=@Inf_road,Inf_subdistrict=@Inf_subdistrict,Inf_district=@Inf_district,Inf_province=@Inf_province,Inf_code=@Inf_code,Inf_tel=@Inf_tel,Inf_relationship=@Inf_relationship,Agent_id=@Agent_id WHERE Inf_id = '" + lblInfID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1); comSql = new SqlCommand(strSql, objcon.conn1); comSql.Parameters.Add("Inf_id", SqlDbType.Char).Value = lblInfID.Text; string idcard = maskedTextBox1.Text; comSql.Parameters.Add("idcard", SqlDbType.VarChar).Value = maskedTextBox1.Text; comSql.Parameters.Add("Inf_fname", SqlDbType.VarChar).Value = txtName.Text; comSql.Parameters.Add("Inf_lname", SqlDbType.VarChar).Value = txtLname.Text; comSql.Parameters.Add("Inf_address", SqlDbType.VarChar).Value = txtAdd.Text; comSql.Parameters.Add("Inf_stred", SqlDbType.VarChar).Value = txtStred.Text; comSql.Parameters.Add("Inf_road", SqlDbType.VarChar).Value = txtRoad.Text; comSql.Parameters.Add("Inf_subdistrict", SqlDbType.VarChar).Value = txtSub.Text; comSql.Parameters.Add("Inf_district", SqlDbType.VarChar).Value = txtDistrict.Text; comSql.Parameters.Add("Inf_province", SqlDbType.VarChar).Value = txtProvince.Text; comSql.Parameters.Add("Inf_code", SqlDbType.VarChar).Value = txtCode.Text; comSql.Parameters.Add("Inf_tel", SqlDbType.VarChar).Value = txtTel.Text; comSql.Parameters.Add("Inf_relationship", SqlDbType.VarChar).Value = txtRe.Text; string Agent = "A01"; comSql.Parameters.Add("Agent_id", SqlDbType.Char).Value = Agent; int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("8��/Pก#�21*�"+0D8+�2D���:", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else {

Page 137: appendix - bc.msu.ac.th

330

MessageBox.Show("�1�!$1$+F8��/Pก#�21*����", "��ก$+8��/Pก#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowInformant(); clear(); btnSave.Enabled = true; btnUpdate.Enabled = false; objcon.conn1.Close(); } private void btnDelete_Click(object sender, EventArgs e) { if (lblInfID.Text == "") { return; } DialogResult dlgResult = MessageBox.Show("4Go,�2�ก$+�8#�21*��0. S��+92�1�", "D9�D��ก$+�8#�21*�", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlgResult == DialogResult.Yes) { string strSql = "DELETE Informant WHERE Inf_id = '" + lblInfID.Text + "'"; SqlCommand comSql = new SqlCommand(strSql, objcon.conn1); int numRec = comSql.ExecuteNonQuery(); if (numRec > 0) { MessageBox.Show("�8#�21*�"+0D8+�2D���:", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("�1�!$1$+F�8#�21*����", "��ก$+�8#�21*�", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } ShowInformant();

Page 138: appendix - bc.msu.ac.th

331

} private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } lblInfID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); maskedTextBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtLname.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtAdd.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); txtStred.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); txtRoad.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); txtSub.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString(); txtDistrict.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); txtProvince.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString(); txtCode.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString(); txtTel.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString(); txtRe.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString(); btnSave.Enabled = false; btnUpdate.Enabled = true; btnDelete.Enabled = false; } private void btnClear_Click(object sender, EventArgs e) { clear(); btnUpdate.Enabled = false; btnSave.Enabled = true; } }

Page 139: appendix - bc.msu.ac.th

332

Form : frmMain.cs (H�O�HQก) using System.Data.SqlClient; namespace Project_desktop { public partial class frmMain : Form { ConnetDB objcon = new ConnetDB(); SqlCommand comSql; SqlDataReader dr; DataTable dt; string aID,typeLog; public frmMain(string AgeID,string AgeName,string typeL) { InitializeComponent(); aID = AgeID; txtAgeID.Text += aID; txtAgeName.Text = AgeName; typeLog = typeL; } private void menu_Load(object sender, EventArgs e) { label1.Text = DateTime.Now.ToLongDateString(); label2.Text = DateTime.Now.ToLongTimeString(); if (typeLog == "agent") { ToolStripMenuItemAgent1.Visible = false; #21�,:�/�ToolStripMenuItem1.Visible = false; ,:�/�41ToolStripMenuItem.Visible = false; 4$,28�/�,:�/�ToolStripMenuItem.Visible = false; } else { Member1.Visible = false; #21��+8��%+)3DS�ToolStripMenuItem1.Visible = false;

Page 140: appendix - bc.msu.ac.th

333

#21���(�ToolStripMenuItem1.Visible = false; ReceiveToolStripMenuItem.Visible = false; +8�(�ToolStripMenuItem.Visible = false; 4$,28�/��+8��%+)3DS�ToolStripMenuItem.Visible = false; �$22ก($ก!1$SกToolStripMenuItem.Visible = false; } } private void 22ก($กToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult ex = MessageBox.Show("4Go,�2�ก$+22ก($ก+)88 S��+92�1�", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ex == DialogResult.Yes) { Login log = new Login(); log.Show(); this.Hide(); //this.Close(); } } private void Member1_Click(object sender, EventArgs e) { Member App = new Member(txtAgeID.Text); App.MdiParent = this; App.Show(); } private void #21��+8��%+)3DS�ToolStripMenuItem1_Click(object sender, EventArgs e) { Interest inter = new Interest(); inter.MdiParent = this; inter.Show(); } private void 4$,28�/��+8��%+)3DS�ToolStripMenuItem_Click(object sender, EventArgs e) { Interest_Pay Int_pay = new Interest_Pay(txtAgeID.Text); Int_pay.MdiParent = this;

Page 141: appendix - bc.msu.ac.th

334

Int_pay.Show(); } private void #21���(�ToolStripMenuItem1_Click(object sender, EventArgs e) { Informant Infor = new Informant(); Infor.MdiParent = this; Infor.Show(); } private void #21�,:�/�ToolStripMenuItem1_Click(object sender, EventArgs e) { Agent age = new Agent(); age.MdiParent = this; age.Show(); } private void 4$,28�/�,:�/�ToolStripMenuItem_Click(object sender, EventArgs e) { Agent_Pay age_p = new Agent_Pay(txtAgeID.Text);// ��"S'44�"#�$ S�+)88/0E()22ก 8!7$4�Q ����$frmMain age_p.MdiParent = this; age_p.Show(); } private void +8�(�ToolStripMenuItem_Click(object sender, EventArgs e) { Death death_D = new Death(); death_D.MdiParent = this; death_D.Show(); } private void �$22ก($ก!1$SกToolStripMenuItem_Click(object sender, EventArgs e) { Out Resig = new Out(txtAgeID.Text); Resig.MdiParent = this; Resig.Show(); } private void ToolStripMenuItemIntersat_Click(object sender, EventArgs e) {

Page 142: appendix - bc.msu.ac.th

335

fcr_Int_Pay int_p = new fcr_Int_Pay(txtAgeID.Text,typeLog); int_p.MdiParent = this; int_p.Show(); } private void ReceiveToolStripMenuItem_Click(object sender, EventArgs e) { Receive Receive_re = new Receive(txtAgeID.Text); Receive_re.MdiParent = this; Receive_re.Show(); } private void ToolStripMenuItemAgent1_Click(object sender, EventArgs e) { Form2 Age_p = new Form2(txtAgeID.Text, typeLog); Age_p.MdiParent = this; Age_p.Show(); } private void ToolStripMenuItemOUT_Click(object sender, EventArgs e) { fcr_Out Out_u = new fcr_Out(txtAgeID.Text,typeLog); Out_u.MdiParent = this; Out_u.Show(); } private void !1$Sก%((8�ToolStripMenuItem_Click(object sender, EventArgs e) { //== typeLog "5-E1 !7$�+�8(),+:(!28 Officer fcr_Member1 fcrMem = new fcr_Member1(txtAgeID.Text, typeLog); fcrMem.MdiParent = this; fcrMem.Show(); } private void !1$Sก/�$22กToolStripMenuItem_Click(object sender, EventArgs e) { fcr_Member2 fcrMem = new fcr_Member2(txtAgeID.Text,typeLog); fcrMem.MdiParent = this; fcrMem.Show(); }

Page 143: appendix - bc.msu.ac.th

336

private void !1$Sก/"!DS:,ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_Member3 fcrMem = new fcr_Member3(txtAgeID.Text,typeLog); fcrMem.MdiParent = this; fcrMem.Show(); } private void ,:�/�41ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_Agent fcrAgent = new fcr_Agent(txtAgeID.Text); fcrAgent.MdiParent = this; fcrAgent.Show(); } private void �+8��%+)3DS�ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_Int fcrInt = new fcr_Int(txtAgeID.Text,typeLog); fcrInt.MdiParent = this; fcrInt.Show(); } private void ก$++8�(��"!DS:,ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_DeathIN fMRe = new fcr_DeathIN(txtAgeID.Text,typeLog); fMRe.MdiParent = this; fMRe.Show(); } private void ��(�ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_Informant fcrInfor = new fcr_Informant(txtAgeID.Text); fcrInfor.MdiParent = this; fcrInfor.Show(); } private void timer1_Tick(object sender, EventArgs e) { label1.Text = DateTime.Now.ToLongTimeString(); } private void +)�:$�:�/ToolStripMenuItem_Click(object sender, EventArgs e)

Page 144: appendix - bc.msu.ac.th

337

{ fcr_ReceiveDate fcrReDate = new fcr_ReceiveDate(txtAgeID.Text,typeLog); fcrReDate.MdiParent = this; fcrReDate.Show(); } private void /��1�ToolStripMenuItem_Click(object sender, EventArgs e) { fcr_ReceiveDate fcrReDate = new fcr_ReceiveDate(txtAgeID.Text,typeLog); fcrReDate.MdiParent = this; fcrReDate.Show(); } private void ,$1�"!DS:,ToolStripMenuItem_Click(object sender, EventArgs e) { frm_prMemRe fcrReDate = new frm_prMemRe(txtAgeID.Text,typeLog); fcrReDate.MdiParent = this; fcrReDate.Show(); } } }

Page 145: appendix - bc.msu.ac.th

338

������ก � I#�G�JF� �������J#����Q\$F��F�J#ab`�ก�W

Page 146: appendix - bc.msu.ac.th

339

I#�G�JF� �������J#����Q\$F��F�J#ab̀�ก�W 1

��TWG����J�$\�#$% 1/2554 ��K� : 0904402 34+��$�"/43�3�D0!$+!�"/��G+ก-( 1 (7$�:� 1 ���:Dก-, (0-2-0) KL% ������� : +)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG8�$��+0!:�!�-� ,7$8�,�$� 27$"�2"192� (���:��1�$!$+4$1 ��\KL% �POa_กd�������� :

1. S9E2-!กG� �$�!$::���$ 5+�+0!G+$S +��!%+)(7$,�: 53010972340 �W��\]#$%��_กd�������� :

2$($+D6 D�DG/� +�S,":SกG� (....................................................) ก++1ก$+/0E%+Pก�$ :��/0E ............/ ................/ ..............

(....................................................)

ก++1ก$+4�/0E 1 :��/0E ............/ ................/ ..............

(....................................................)

ก++1ก$+4�/0E 2 :��/0E ............/ ................/ ............

Page 147: appendix - bc.msu.ac.th

340

1.1 ����J�e����QT����FG��f ��gfH�

%�((G8���0."/43�3�D0���108/8$/"5-E11$ก#P.� �1�:�$()"%Z����:D�$�/�.��$4+����)�$4"2กS� !F$8��ก$+�Pก�$ ��)ก-(ก++1,�$�� ���10ก$+�7$"/43�3�D0"#�$1$ S� �ก$+27$�:D4:$1!)�:ก �ก$+%�-8�,-�$� 3�Dก$+�7$4215-:",2+6"#�$1$ S� �ก$+(��"ก'8#�21*� ก$+47$�:o ��)ก$+%+)1:���,�$� � "S�� ก$+(��"ก'8#�21*�!1$S-ก #�21*��*ก4�$ ก$+(��"ก'8#�21*�ก$+S7$+)"�-� ก$+(��"ก'8#�21*�ก$+#$D ก$+!�E�k9.2 ��� (P�"�'����:�$4215-:",2+6108/8$/"%Z�2D�$�1$ก �ก$+�7$"�-��$�,�$� � �%�((G8����)D��!$1$+F27$�:D4:$1!)�:ก ��ก�8�*�/0E��� S��$�kPE�/7$ ���$���.�10+)88+)"80D81$ก#P.� 20ก/�.�D��104:$1F*ก,�2� S�:D��#�2�-�5�$� �ก$+/7$�$���)+:�"+':1$กD-E�#P.� +)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG8�$��+0!:�!�-� ,.,�$� 2."192� (���:�� 1�$!$+4$1 "%Z�ก$+(��/7$/)"80D�!1$S-ก�$%�ก-(!�"4+$)�6/�.��1� /)"80D�ก$++�8"�-� ��)22ก 8"!+'( ��!1$S-ก/0ES7$+)4�$!1$S-ก 4�$�$%�ก-(!�"4+$)�6 (��/7$(�$D"�-��$%�ก-(!�"4+$)�6/0EFP��ก�ก++1 ��),�2�ก$+�7$4215-:",2+61$ S� �ก$+8+-�$+(��ก$+ "�9E2�($ก/$�S1+1 ���10!1$S-ก"5-E1#P.� ��)10ก$+47$�:o"�-�/0E()���+�8S�:D"��924�$�$%�ก-(!�"4+$)�6 3�D S�ก$+(�8��/Pก��:D192��)ก$+(��"ก'8"2ก!$+ ��`n1 kPE�58:�$"ก-�4:$1DG��D$ก �ก$+(��"ก'8#�21*� ก$+8��/Pก "5-E1 �8 �ก��##�21*�,�$� � /7$ ��ก$+8+-�$+(��ก$+�$%�ก-(!�"4+$)�6 S1+1�*�!*�2$DG8�$��+0!:�!�-�D��#$�%+)!-/�-�$5 �����.�+)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG8�$��+0!:�!�-� (7$"%Z�,�2�"%�0ED��%��+)88ก$+(��"ก'8#�21*� ก$+4���$ ก$+47$�:o"�-� �+)88ก$+(��"ก'8�$�#�21*�"59E2 ����$D��)!)�:ก,�2ก$+ S��$� 3�D10ก$+�7$3%+�ก+1%+)DGก,6"#�$1$5���$ ��"�1$)!1ก�8ก+)8:�ก$+/7$�$�#2��$%�ก-(!�"4+$)�6 S1+1�*�!*�2$DG8�$��+0!:�!�-���) S��$�+�:1ก�84215-:",2+6 "59E2 ��+)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG8�$��+0!:�!�-�104:$1+:�"+': F*ก,�2��1��D7$ 20ก/�.�D��S�:D27$�:D4:$1!)�:ก �ก$+4���$#�21*� /7$ ��ก$+/7$�$�10%+)!-/�-�$51$กD-E�#P.�

Page 148: appendix - bc.msu.ac.th

1.2 ��h`��TF��] �ก��a_กd�

"59E25���$+)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG

8�$��+0!:�!�-� ,.,�$� 2."192� (.1�$!$+4$1 ��10%+)!-/�-�$51$ก#P.� 1.3 IJ�ก���G�J������

3%+�ก+18+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG 8�$��+0!:�!�-� ,.,�$� 2."192� (.1�$!$+4$1 (),�2�4+284�G1ก$+�7$"�-��$����,�2�%�0. 3.1.1 +)88(��ก$+���$+�$� (Front Office) 1) +)88!1�4+!1$S-ก 1.1) !$1$+F8��/Pก#�21*�!1$S-ก��� 1.2) !$1$+F�ก��##�21*�!1$S-ก��� 1.3) !$1$+F22ก8�,+!1$S-ก��� 1.4) !$1$+F5-156 8"!+'(+�8"�-�4�$!1�4+��� 2) +)88ก$+ก$++�8S7$+)"�-� 2.1) !$1$+F,+:(!28#�21*�ก$++�8S7$+)"�-���� 2.2) !$1$+F47$�:oD2�ก$++�8S7$+)"�-���� 2.3) !$1$+F8��/Pก#�21*�ก$++�8S7$+)"�-���� 2.4) !$1$+F5-156 8"!+'(+�8"�-���� 3) +)88ก$+�$22ก 3.1) !$1$+F,+:(!28#�21*�!1$S-ก��� 3.2) !$1$+F8��/Pก#�21*�ก$+�$22ก��� 3.3) !$1$+F�ก��##�21*�ก$+�$22ก��� 3.4) !$1$+F5-156 8�$22ก��� 1.3.2 +)88(��ก$+����+�$� (Back Office) 1) +)88ก$+(�$D4�$,28�/� (�*�+�8��%+)3DS�6) 1.1) !$1$+F,+:(!28#�21*�!1$S-ก��� 1.2) !$1$+F,+:(!28#�21*��*�+�8��%+)3DS�6��� 1.3) !$1$+F"5-E1 �8 �ก��# #�21*�ก$+(�$D4�$,28�/� �*�+�8��%+)3DS�6��� 1.4) !$1$+F8��/Pก#�21*�ก$+(�$D4�$,28�/��*�+�8��%+)3DS�6��� 1.5) !$1$+F5-156 8!7$4�Q(�$D���

341

Page 149: appendix - bc.msu.ac.th

2) +)88ก$+(�$D4�$,28�/� (,�:�/�) 2.1) !$1$+F,+:(!28#�21*�!1$S-ก��� 2.2) !$1$+F,+:(!28#�21*�,�:�/���� 2.3) !$1$+F"5-E1 �8 �ก��# #�21*�ก$+(�$D4�$,28�/�,�:�/���� 2.4) !$1$+F8��/Pก#�21*�ก$+(�$D4�$,28�/�,�:�/���� 2.5) !$1$+F5-156 8!7$4�Q(�$D��� 3) +)88ก$++�8�(���*�"!0DS0:-, 3.1) !$1$+F,+:(!28#�21*��*��(����� 3.2) !$1$+F,+:(!28#�21*�!1$S-ก��� 3.3) !$1$+F"5-E1 �ก��# #�21*�ก$++�8�(���*�"!0DS0:-,��� 3.4) !$1$+F8��/Pก#�21*�ก$++�8�(���*�"!0DS0:-,��� 4) ก$+22ก+$D�$� 4.1) !$1$+F22ก+$D�$�#�21*�!1$S-ก��� 4.2) !$1$+F22ก+$D�$�#�21*�ก$++�8S7$+)"�-���� 4.3) !$1$+F22ก+$D�$�#�21*�ก$+�$22ก��� 4.4) !$1$+F22ก+$D�$�#�21*�ก$+(�$D4�$,28�/� (�*�+�8��%+)3DS�6)��� 4.5) !$1$+F22ก+$D�$�#�21*�ก$+(�$D4�$,28�/� (,�:�/�)��� 4.6) !$1$+F22ก+$D�$�#�21*�ก$++�8�(���*�"!0DS0:-,��� 4.7) !$1$+F22ก+$D�$�#�21*��*�+�8��%+)3DS�6��� 4.8) !$1$+F22ก+$D�$�#�21*��*��(�����

1.4 `�ก�i]�QTJ��L% ��L j�ก���G�J������

1.4.1 �$+6��:+6

1. "4+9E2�4215-:",2+6 (7$�:� 1 "4+9E2�

2. "4+9E2�%+-.�",2+6 (7$�:� 1 "4+9E2�

1.4.2 k2`,6�:+6

1. +)88%�-8�,-ก$+ Microsoft Windows XP S�"%Z�+)88%�-8�,-ก$+

2. 3%+�ก+1 Microsoft Visual Studio 2008 S�!7$�+�85���$+)88�$�

342

Page 150: appendix - bc.msu.ac.th

3. 3%+�ก+1 Microsoft SQL Server 2005 S�!7$�+�8(��"ก'8�$�#�21*�

4. 3%+�ก+1 Crystal Reports 2005 S�!7$�+�8ก$+�!��+$D�$�#2�+)88

5. 3%+�ก+1 Microsoft Visio 2007 S�!7$�+�8"%Z�"4+9E2�192 �ก$+22ก�88(7$�2�

#2�+)88�+92��2)�ก+1,�$� �

6. 3%+�ก+1Adobe Acrobat 9 Professional S�!7$�+�8(��+*%�88"2ก!$+

%+)ก28ก$+�7$"�-��$� ��2D*� �+*%�88 PDF

1.5 ��� �j�ก���G�J������

1.5.1 �7$"!�2��:#�2,�22$($+D6/0E%+Pก�$ 1.5.2 �Pก�$��)"ก'8+:8+:1#�21*� 1.5.3 :-"4+$)�6��)22ก�88+)88�$� 1.5.4 5���$+)88 1.5.5 /�!28+)88��)�ก��##�2�-�5�$� 1.5.6 (��/7$"2ก!$+��)�7$"!�2���$�,�24o)ก++1ก$+

1.6 �T\TJ�Q�j�ก���k�I�����

�����#$% 1-1 ,$+$��!��+)D)":�$ก$+�7$"�-��$�

ก-(ก++1 "�92� 5.�. 2554 - 2555

1-.D. ก.4. !.4. ก.D. ,.4. 5.D. �.4. 1.4. ก.5.

�7$"!�2��:#�2,�22$($+D6/0E%+Pก�$

�Pก�$��)"ก'8+:8+:1#�21*�

:-"4+$)�6��)22ก�88+)88

5���$+)88

/�!28+)88��)�ก��##�2�-�5�$�

�7$"!�2���$�,�24o)ก++1ก$+

343

Page 151: appendix - bc.msu.ac.th

1.7 �Q#$%����M�WTl�O�I

1.7.1 !$1$+F�7$+)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG�% S��$����(+-� 1.7.2 !$1$+F(��"ก'8#�21*����2D�$�10%+)!-/�-�$51$ก#P.� 1.7.3 +)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG 8�$��+0!:�!�-�10"/43�3�D0/0E/��!1�D S��$�

1.7.4 S�:D��#�.�,2� �ก$+/7$�$�

344

Page 152: appendix - bc.msu.ac.th

������ก �.

��\���ก��JO�"I �W��\]#$%��_กd�

Page 153: appendix - bc.msu.ac.th

��\���ก��"I#$%��_กd�

KL% J�L% � +)888+-�$+(��ก$+�$%�ก-(!�"4+$)�6 ก+o0�Pก�$S1+1�*�!*�2$DG8�$��+0!:�!�-� ,.,�$� 2."192� (.1�$!$+4$1

�POa_กd� �$�!$::���$ 5+�+0!G+$S +��!%+)(7$,�: 53010972340 .4�16(�83 #$%��_กd� 2$($+D6D�DG/� +�S,":SกG�

�� J�L � �m ��\��������LIH�O� / ก��jHO�G���_กd� Q�\�L KL% #$%��_กd�

15 5.D. 54 ก$+22ก�88���$`2+61 �!�:�#2�ก$+,�.�4�$ ��)ก$+�7$�$�#�21*�#P.�8� Server

13 �.4. 54 �ก��##�2%+�8%+G� ,$1/0E���+�8128�1$D

17 1.4. 55 !28F$1%�Q�$ �!�:�#2�+)88�$�/0ED���1�!$1$+F�ก��#���

7 ก.5. 55 ก$+22ก+$D�$�,�$��

21 ก.5. 55 ,+:(!284:$1F*ก,�2� ��)��)�7$ก$+#P.��7$"!�2 Project2