private void OKButton_Click(object sender, EventArgs e) { MySqlConnection con = new MySqlConnection("host=localhost;user=admin;password=123456;database=project"); ManySet = numericUpDown1.Text; try { string receipt = "WN-" + System.DateTime.Now.ToString("yyyyMMddHHmmss"); con.Open(); //เรียกข้อมูลอาหาร string sql1 = "SELECT * FROM neworder WHERE id_order='" + SelectMenuTakeHome + "'"; //MessageBox.Show("'" + SelectMenuTakeHome + "'"); //MessageBox.Show(sql1); MySqlCommand cmd1 = new MySqlCommand(sql1, con); MySqlDataReader reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { ig_name = reader1.GetString("name_order"); ig_price = reader1.GetString("prices_order"); ig_group = reader1.GetString("group_order"); } con.Close(); con.Open(); //เซฟข้อมูลลงใบเสร็จ int a = Convert.ToInt32(ig_price); int b = Convert.ToInt32(ManySet); sum = a * b; //sum = int.Parse(ig_price) * int.Parse(Program.manypeoplebuffe); sumstring = sum.ToString(); string sql2 = "INSERT INTO receipt(name_receipt, number_receipt, prices_receipt, user_receipt, date_receipt, no_receipt, group_receipt) VALUES('" + ig_name + "', '" + ManySet + "', '" + sumstring + "', '" + Program.username + "', '" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "', '" + receipt + "', '" + ig_group + "')"; MySqlCommand cmd2 = new MySqlCommand(sql2, con); MySqlDataReader reader2 = cmd2.ExecuteReader(); while (reader2.Read()) { } con.Close(); con.Open(); //crate status_login By no_receipt การค้างบิล เช็คสถานะโดยการเอาที่เลขใบเสร็จใส่ลงไป string sql3 = "UPDATE login SET status_login='******' WHERE Username = '******';"; MySqlCommand cmd3 = new MySqlCommand(sql3, con); MySqlDataReader reader3 = cmd3.ExecuteReader(); while (reader3.Read()) { } con.Close(); MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว"); confirm ST = new confirm(); ST.ShowDialog(); } catch (Exception ex)//การเกิดข้อผิดพลาด { MessageBox.Show("เกิดข้อผิดพลาด" + ex); } }
private void button1_Click(object sender, EventArgs e) { MySqlConnection con = new MySqlConnection("host=localhost;user=admin;password=123456;database=project"); try { con.Open();//หน้า login string sql = "SELECT * FROM login WHERE Username='******' AND Password='******'"; MySqlCommand cmd = new MySqlCommand(sql, con); MySqlDataReader reader = cmd.ExecuteReader(); bool check = false; while (reader.Read()) { check = true; //เเสดงว่า username password มีข้อมูลอยู่ในดาต้าเบส Program.username = reader.GetString("Username"); //เป็นเลขาที่เก็บข้อมูล ดึงข้อมูลออกมาใช้เก็บไว้ในคอม Program.status = reader.GetString("status_login"); //ดึงข้อมูล status_login } con.Close(); if (check == false)//ตรวจสอบข้อมูล { MessageBox.Show("ไม่มี UsernameและPassword นี้"); } else//ถ้ามี check= true { if (Program.status == "")//การเช็คสถานะของผู้ใช้ว่าว่างไหม { select se = new select(); se.ShowDialog(); } else//ถ้าสถานะไม่ว่าง แสดงว่ามีเลขที่ใบเสร็จ เอาเลขที่ใบเสร็จไปตรวจสอบว่าเป็นการสังประเภทไหน { try//คำสั่งการทำงานปกติ { MySqlConnection con1 = new MySqlConnection("host=localhost;user=admin;password=123456;database=project"); con1.Open(); string sql2 = "SELECT * FROM receipt WHERE no_receipt = '" + Program.status + "'"; MySqlCommand cmd1 = new MySqlCommand(sql2, con1); MySqlDataReader reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { no_receiptfromDB = reader1.GetString("group_receipt"); } if (no_receiptfromDB == "บุพเฟ่ต์") { storetable s = new storetable(); s.ShowDialog(); } else if (no_receiptfromDB == "กลับบ้าน") { confirm s = new confirm(); s.ShowDialog(); } } catch (Exception ex) //ทำงานเกิดข้อผิดพลาด ตรวจสอบเงื่อนไข { MessageBox.Show("เกิดข้อผิดพลาดเกี่ยวกับฐานข้อมูล กรุณาลองใหม่อีกครั้ง" + ex); } } } } catch (Exception ex) { MessageBox.Show("เกิดข้อผิดพลาดในการเชื่อมต่อฐานข้อมูล" + ex); } }