private void btnSave_Click(object sender, EventArgs e) { eCustomer cus = new eCustomer(); cus.CustomerID = txtCusID.Text; cus.CustomerName = txtCusName.Text; cus.Address = txtAddress.Text; cus.Phone = txtPhone.Text; if (btnSave.Text.Equals("LƯU THÊM")) { //try // { int result = bCus.insertCustomer(cus); if (result == 1) { clearTextbox(); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnNew.Text = "Thêm"; btnNew.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); MessageBox.Show("Thêm nhân viên mới thành công !", "Thêm thuốc", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCusList.DataSource = bCus.getAllCustomer(); } else { MessageBox.Show("Mã nhân viên bị trùng ! Vui lòng thử lại !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } //} // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } } }
private void btnSave_Click(object sender, EventArgs e) { if (txtCusID.Text.Length == 0 || txtCusName.Text.Length == 0 || txtPhone.Text.Length == 0 || txtAddress.Text.Length == 0) { MessageBox.Show("Không chừa trống dữ liệu nhập !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtCusID.Text.KiemTraMaKhachHang() == false) { MessageBox.Show("Mã nhân viên có định dạng:KHXXX với X là số !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } eCustomer cus = new eCustomer(); cus.CustomerID = txtCusID.Text; cus.CustomerName = txtCusName.Text; cus.Address = txtAddress.Text; cus.Phone = txtPhone.Text; if (btnSave.Text.Equals("Lưu thêm")) { try { int result = bCus.insertCustomer(cus); if (result == 1) { clearTextbox(); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnNew.Text = "Thêm"; btnNew.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnNew.ForeColor = Color.Black; btnUpdate.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Thêm khách hàng mới thành công !", "Thêm thuốc", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCusList.DataSource = bCus.getAllCustomer(); } else { MessageBox.Show("Mã khách hàng bị trùng ! Vui lòng thử lại !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { bCus.updateCustomer(cus); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnUpdate.Text = "Sửa"; btnUpdate.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnUpdate.ForeColor = Color.Black; btnNew.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Cập nhập khách hàng thành công !", "Cập nhập", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvCusList.DataSource = bCus.getAllCustomer(); } }