private void FillDuLieu(DTO.DonViTinh dvt) { txtMaDVTinh.Text = dvt.MaDVTinh; txtMaDVTinh.ReadOnly = true; txtTenDVTinh.Text = dvt.TenDVTinh; txtGhiChu.Text = dvt.GhiChu; cbConQuanLy.Checked = dvt.ConQuanLy; }
//dùng để sửa public frmThemDonViTinh(DTO.DonViTinh dvt) { InitializeComponent(); isInsert = false; this.Text = "Cập nhật Đơn Vị Tính"; // button btnLuu.Click += BtnLuu_Click; btnDong.Click += BtnDong_Click; FillDuLieu(dvt); }
private void btnXoaDvt_Click(object sender, EventArgs e) { if (dgvDonViTinh.SelectedRows.Count > 0) { DialogResult rs = MessageBox.Show("Bạn có muốn xóa đơn vị tính " + dgvDonViTinh.SelectedRows[0].Cells[1].Value.ToString() + "?", "Cảnh báo", MessageBoxButtons.YesNo); if (rs == DialogResult.Yes) { string maDonVi = dgvDonViTinh.SelectedRows[0].Cells[0].Value.ToString(); string tenDonVi = dgvDonViTinh.SelectedRows[0].Cells[1].Value.ToString(); DTO.DonViTinh dv = new DTO.DonViTinh(); dv.MaDonVi = maDonVi; dv.TenDonVi = tenDonVi; dvtBUS.deleteDonViTinh(dv); MessageBox.Show("Đã xóa món ăn", "Thành công", MessageBoxButtons.OK); this.parseDataDonViTinh(dvtBUS.getDonViTinhList()); } else return; } }
private void BtnLuu_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtTenDVTinh.Text)) { MessageBox.Show("Không được bỏ trống Tên Đơn Vị Tính"); } else { DTO.DonViTinh dvt = new DTO.DonViTinh(); dvt.MaDVTinh = txtMaDVTinh.Text; dvt.TenDVTinh = txtTenDVTinh.Text; dvt.GhiChu = txtGhiChu.Text; dvt.ConQuanLy = cbConQuanLy.Checked; if (isInsert == true) { int kq = nv_dvt.ThemDVTinh(dvt); if (kq >= 1) { ThemThanhCong(); MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Thất Bại"); } } else { int kq = nv_dvt.CapNhatDVTinh(dvt); if (kq >= 1) { CapNhatThanhCong(); MessageBox.Show("Cập nhật thành công"); } else { MessageBox.Show("Thất Bại"); } } } }