private void Delete_Click(object sender, RoutedEventArgs e) { if (cusID == ("")) { MessageBox.Show("กรุณาเลือกข้อมูลที่ต้องการลบ !!!", "คำเตือน"); return; } else { MessageBoxResult result = MessageBox.Show("คุณต้องการลบข้อมูลนี้หรือไม่", "แจ้งเตือน", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { string sql = "delete from customer where cusID='" + cusID + "'"; MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); this.Close(); InfoEmployee go = new InfoEmployee(); go.Show(); go.Close(); } } }
private void MenuItem_Click(object sender, RoutedEventArgs e) { InfoEmployee go = new InfoEmployee(); go.Show(); }
private void EditButton_Click(object sender, RoutedEventArgs e) { con.Open(); string showidprovince = "SELECT PROVINCE_ID FROM provinces WHERE PROVINCE_NAME='" + cbProvince.SelectedItem + "'"; MySqlCommand cmd1 = new MySqlCommand(showidprovince, con); MySqlDataReader reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { Getidprovice = reader1.GetString(reader1.GetOrdinal("PROVINCE_ID")); } con.Close(); con.Open(); string showidamphur = "SELECT AMPHUR_ID FROM amphures WHERE AMPHUR_NAME='" + cbAmphur.SelectedItem + "'"; MySqlCommand cmd2 = new MySqlCommand(showidamphur, con); MySqlDataReader reader2 = cmd2.ExecuteReader(); while (reader2.Read()) { Getidamphur = reader2.GetString(reader2.GetOrdinal("AMPHUR_ID")); } con.Close(); con.Open(); string showiddistrict = "SELECT DISTRICT_ID FROM districts WHERE DISTRICT_NAME='" + cbDistrict.SelectedItem + "'"; MySqlCommand cmd3 = new MySqlCommand(showiddistrict, con); MySqlDataReader reader3 = cmd3.ExecuteReader(); while (reader3.Read()) { Getiddistricts = reader3.GetString(reader3.GetOrdinal("DISTRICT_ID")); } con.Close(); if (Showname == ("") | Showlastname == ("") | !txtTel.IsMaskCompleted | !txtCard.IsMaskCompleted | Showaddress == ("") | Showzipcode == ("")) { MessageBox.Show("กรุณากรอกข้อมูลให้ครบ (ถนน และ หมู่ ไม่จำเป็น)!!!"); return; } else { string sql = "update employee set nameEmp='" + this.txtName.Text + "',lastnameEmp='" + this.txtLastname.Text + "',telEmp='" + this.txtTel.Text + "',idcardEmp='" + this.txtCard.Text + "',sexEmp='" + Sex + "',addressEmp='" + this.txtAddress.Text + "',roadEmp='" + this.txtRoad.Text + "',mooEmp='" + this.txtMoo.Text + "',PROVINCE_ID='" + Getidprovice + "',AMPHUR_ID='" + Getidamphur + "',DISTRICT_ID='" + Getiddistricts + "',zipcodeEmp='" + this.txtZipcode.Text + "',picEmp=@IMG where idEmp='" + this.ShowidEmp + "'"; MySqlCommand cmdDataBase = new MySqlCommand(sql, con); MySqlDataReader myReader; try { byte[] imageBt = null; FileStream fstream = new FileStream(ShowpicUrl.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fstream); imageBt = br.ReadBytes((int)fstream.Length); cmdDataBase.Parameters.Add(new MySqlParameter("@IMG", imageBt)); cmdDataBase.Connection.Open(); myReader = cmdDataBase.ExecuteReader(); System.Windows.Forms.MessageBox.Show("แก้ไขสำเร็จ!!!", "สำเร็จ"); con.Close(); this.Close(); InfoEmployee go = new InfoEmployee(); go.Show(); } catch (Exception ex) { string sql2 = "update employee set nameEmp='" + this.txtName.Text + "',lastnameEmp='" + this.txtLastname.Text + "',telEmp='" + this.txtTel.Text + "',idcardEmp='" + this.txtCard.Text + "',sexEmp='" + Sex + "',addressEmp='" + this.txtAddress.Text + "',roadEmp='" + this.txtRoad.Text + "',mooEmp='" + this.txtMoo.Text + "',PROVINCE_ID='" + Getidprovice + "',AMPHUR_ID='" + Getidamphur + "',DISTRICT_ID='" + Getiddistricts + "',zipcodeEmp='" + this.txtZipcode.Text + "' where idEmp='" + this.ShowidEmp + "'"; MySqlCommand cmdDataBase2 = new MySqlCommand(sql2, con); cmdDataBase2.Connection.Open(); cmdDataBase2.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("แก้ไขสำเร็จ!!!", "สำเร็จ"); con.Close(); this.Close(); InfoEmployee go = new InfoEmployee(); go.Show(); } } }