public int Insert(Services aServices) { try { aDatabaseDA.Services.Add(aServices); aDatabaseDA.SaveChanges(); return aServices.ID; } catch (Exception ex) { throw new Exception(string.Format("ServicesBO.Insert :" + ex.Message)); } }
private void bnAdd_Click(object sender, EventArgs e) { try { if (this.ValidateData() == true) { Services aService = new Services(); aService.Name = txtName.Text; aService.CostRef = string.IsNullOrEmpty(txtCost.Text) == true ? 0 : Convert.ToDecimal(txtCost.Text); aService.Unit = txtUnit.Text; aService.Status = cboStatus.SelectedIndex + 1; if (cboType.Text == "Tiệc") { aService.Type = 1; } else { aService.Type = 2; } aService.Disable = bool.Parse(cboDisable.Text); aService.IDServiceGroups = Convert.ToInt32(lueIDServiceGroup.EditValue); aServiceBO.Insert(aService); MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (this.afrmLst_Services != null) { this.afrmLst_Services.ReloadData(); } else if (this.afrmIns_BookingHalls_Services != null) { this.afrmIns_BookingHalls_Services.Reload(); } this.Close(); } } catch (Exception ex) { MessageBox.Show("frmIns_Services.bnAdd_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void bnAdd_Click(object sender, EventArgs e) { try { if(this.CheckData()==true) { ServicesBO aServiceBO = new ServicesBO(); Services aService = new Services(); aService.Name = txtName.Text; aService.CostRef = string.IsNullOrEmpty(txtCost.Text) == true ? 0 : Convert.ToDecimal(txtCost.Text); aService.Unit = txtUnit.Text; aService.Status = 1; aService.Type = cboType.SelectedIndex + 1; aService.Disable = false; aService.IDServiceGroups = Convert.ToInt32(lueIDServiceGroup.EditValue); aServiceBO.Insert(aService); MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (this.afrmLst_Services != null) { this.afrmLst_Services.ReloadData(); } if (this.afrmTsk_BookingHall_Customer_New != null) { this.afrmTsk_BookingHall_Customer_New.CallBackService(aService); } if (this.afrmTsk_UseServices != null) { this.afrmTsk_UseServices.Reload(); } this.Close(); } } catch (Exception ex) { MessageBox.Show("frmIns_Services.bnAdd_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// truyền lại Service vừa thêm vào 2 List public void CallBackService(Services aServices) { try { this.LoadService(); ServicesBO aServicesBO = new ServicesBO(); ServiceUsedEN aServiceUsedEN = new ServiceUsedEN(); aServiceUsedEN.IDService = aServices.ID; aServiceUsedEN.NameService = aServices.Name; aServiceUsedEN.Cost = aServices.CostRef; aServiceUsedEN.CostRef_Service = aServices.CostRef; aServiceUsedEN.Unit = aServices.Unit; aServiceUsedEN.Quantity = 1; aServiceUsedEN.Tax = 10; aServiceUsedEN.DateUsed = dtpFrom.DateTime; if (this.aNewBookingHEN.aListBookingHallUsed.Where(a => a.CodeHall == CurrentCodeHall).ToList().Count > 0) { this.aNewBookingHEN.aListBookingHallUsed.Where(a => a.CodeHall == CurrentCodeHall).ToList()[0].InsertService(aServiceUsedEN); dgvServiceInHall.DataSource = this.aNewBookingHEN.aListBookingHallUsed.Where(a => a.CodeHall == CurrentCodeHall).ToList()[0].aListServiceUsed; dgvServiceInHall.RefreshDataSource(); } } catch (Exception ex) { MessageBox.Show("frmTsk_BookingHall_Customer_New.btnSelectService_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int Update(Services aServices) { aDatabaseDA.Services.AddOrUpdate(aServices); int ret = aDatabaseDA.SaveChanges(); return ret; }