private void Btn_suaDCNC_Click(object sender, EventArgs e) { if (tbNoiNhapCanh.Text == "") { lb_thongBao.ForeColor = Color.Red; lb_thongBao.Text = "Có trường dữ liệu còn trống! Vui lòng điền đầy đủ!"; return; } DiaChiNCDTO dcnc = new DiaChiNCDTO(); dcnc.MaDCNC = tempList[selectRow].MaDCNC; dcnc.DiaChiNC = tbNoiNhapCanh.Text; bool kq = dcbus.sua(dcnc); if (kq == false) { lb_thongBao.ForeColor = Color.Red; lb_thongBao.Text = "Sửa địa chỉ nhập cảnh thất bại! Kiểm tra lại dữ liệu!"; } else { FrmDanhMucDiaChiNhapCanh_Load(sender, e); lb_thongBao.ForeColor = Color.Green; lb_thongBao.Text = "Sửa địa chỉ nhập cảnh thành công!"; btn_suaDCNC.Hide(); btnThem.Show(); } }
void Xoa(object sender, ToolStripItemClickedEventArgs e) { DialogResult drl = MessageBox.Show("Bạn có chắc chắn muốn xóa!", "Thông báo!", MessageBoxButtons.YesNo); if (drl == DialogResult.No) { return; } DiaChiNCDTO dcnc = new DiaChiNCDTO(); dcnc.MaDCNC = tempList[selectRow].MaDCNC; bool kq = dcbus.xoa(dcnc); if (kq == false) { lb_thongBao.ForeColor = Color.Red; lb_thongBao.Text = "Xóa địa chỉ nhập cảnh thất bại! Có thể còn dữ liệu phụ thuộc liên quan!"; } else { FrmDanhMucDiaChiNhapCanh_Load(sender, e); lb_thongBao.ForeColor = Color.Green; lb_thongBao.Text = "Xóa địa chỉ nhập cảnh thành công!"; } }
private void btnThem_Click(object sender, EventArgs e) { DiaChiNCDTO dcnc = new DiaChiNCDTO(); string maDCNC; string numZeroStr = ""; // String chứa có bao nhiêu số 0 trong mã if (tbNoiNhapCanh.Text == "") { lb_thongBao.ForeColor = Color.Red; lb_thongBao.Text = "Có trường dữ liệu còn trống! Vui lòng điền đầy đủ!"; return; } dcnc.DiaChiNC = tbNoiNhapCanh.Text; for (int i = 0; i < tempList.Count; i++) { if (int.Parse(tempList[i].MaDCNC.Substring(2)) != i + 1) // Căt pahàn số sau chữ "DC" { i++; // Cộng giá trị lên 1 để tránh số 0 maDCNC = i.ToString(); int numZero = sizeMaDCNC - i.ToString().Length - 2; // tính số số 0 trong chuõi for (int j = 0; j < numZero; j++) { numZeroStr = numZeroStr + "0"; } dcnc.MaDCNC = "DC" + numZeroStr + i.ToString(); // Mã = DC + Số 0 + mã số break; } } if (dcnc.MaDCNC == null) // tra hết list nếu ko có thêm phần tử mnói { int numZero = sizeMaDCNC - (tempList.Count + 1).ToString().Length - 2; for (int j = 0; j < numZero; j++) { numZeroStr = numZeroStr + "0"; } dcnc.MaDCNC = "DC" + numZeroStr + (tempList.Count + 1).ToString(); } bool kq = dcbus.them(dcnc); if (kq == false) { lb_thongBao.ForeColor = Color.Red; lb_thongBao.Text = "Thêm địa chỉ nhập cảnh thất bại! Dữ liệu có thể còn liên hệ với các bảng dữ liệu khác!"; } else { FrmDanhMucDiaChiNhapCanh_Load(sender, e); lb_thongBao.ForeColor = Color.Green; lb_thongBao.Text = "Thêm địa chỉ nhập cảnh mới thành công!"; } }
public bool xoa(DiaChiNCDTO dc) { bool re = dcDAL.xoa(dc); return(re); }
public bool them(DiaChiNCDTO dc) { bool re = dcDAL.them(dc); return(re); }