private void icoBtnThem_Click(object sender, EventArgs e) { if (txtSoLuong.Text == "" || txtSoLuong.Text == "0") { MessageBox.Show("Vui lòng điền đầy đủ thông tin và số lượng > 0", "Cảnh báo"); } else { string maDV = cboTenDV.SelectedValue.ToString(); DANH_SACH_SU_DUNG_DICH_VU ds = context.DANH_SACH_SU_DUNG_DICH_VU.FirstOrDefault(p => p.MaThuePhong == maPhieuThue && p.MaDichVu == maDV); if (ds == null) { //Them moi DANH_SACH_SU_DUNG_DICH_VU newDS = new DANH_SACH_SU_DUNG_DICH_VU() { MaThuePhong = maPhieuThue, MaDichVu = cboTenDV.SelectedValue.ToString(), SoLuong = int.Parse(txtSoLuong.Text) }; context.DANH_SACH_SU_DUNG_DICH_VU.Add(newDS); context.SaveChanges(); MessageBox.Show("Thêm thành công", "Thông tin"); loadData(); } else { MessageBox.Show("Thêm thành công", "Thông tin"); ds.SoLuong += int.Parse(txtSoLuong.Text); context.SaveChanges(); loadData(); } } }
private void icoBtnSua_Click(object sender, EventArgs e) { if (txtSoLuong.Text == "" || txtSoLuong.Text == "0") { MessageBox.Show("Vui lòng điền đầy đủ thông tin và số lượng > 0", "Cảnh báo"); } else { string maDV = cboTenDV.SelectedValue.ToString(); DANH_SACH_SU_DUNG_DICH_VU ds = context.DANH_SACH_SU_DUNG_DICH_VU.FirstOrDefault(p => p.MaThuePhong == maPhieuThue && p.MaDichVu == maDV); if (ds == null) { if (MessageBox.Show("Dịch vụ này chưa có bạn muốn thêm mới không ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //Them moi DANH_SACH_SU_DUNG_DICH_VU newDS = new DANH_SACH_SU_DUNG_DICH_VU() { MaThuePhong = maPhieuThue, MaDichVu = cboTenDV.SelectedValue.ToString(), SoLuong = int.Parse(txtSoLuong.Text) }; context.DANH_SACH_SU_DUNG_DICH_VU.Add(newDS); context.SaveChanges(); MessageBox.Show("Thêm thành công", "Thông tin"); loadData(); } } else { ds.SoLuong = int.Parse(txtSoLuong.Text); context.SaveChanges(); loadData(); MessageBox.Show("Sửa thành công", "Thông tin"); } } }