private void AddPaymentSB_Click(object sender, EventArgs e) { int? documentId = null; if (DataGV.SelectedRows.Count > 0) { documentId = Convert.ToInt32(DataGV.SelectedRows[0].Cells["ID"].Value); } if (documentId != null) { DocumentPaymentData form = new DocumentPaymentData(Convert.ToInt32(documentId), cashRegister); form.WindowState = FormWindowState.Normal; form.ShowDialog(); manager.Save(); manager.CloseContext(); manager = new ContextManager(); Fill(); } }
private void AddPaymentSB_Click(object sender, EventArgs e) { int?documentId = null; if (DataGV.SelectedRows.Count > 0) { documentId = Convert.ToInt32(DataGV.SelectedRows[0].Cells["ID"].Value); } if (documentId != null) { DocumentPaymentData form = new DocumentPaymentData(Convert.ToInt32(documentId), cashRegister); form.WindowState = FormWindowState.Normal; form.ShowDialog(); manager.Save(); manager.CloseContext(); manager = new ContextManager(); Fill(); } }
/// <summary> /// Збереження даних документу /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveBt_Click(object sender, EventArgs e) { if (dxValidationProvider1.Validate() == true) { if (ContractorLUE.EditValue != null) document.ContractorID = Convert.ToInt32(ContractorLUE.EditValue); if (CurrencyLUE.EditValue != null) document.CurrencyID = Convert.ToInt32(CurrencyLUE.EditValue); if (DateDE.EditValue != null) document.Date = Convert.ToDateTime(DateDE.EditValue); document.Description = DescriptionTE.Text; document.Address = AddressTE.Text; document.Number = NumberTE.Text; if (DocumentTypeLUE.EditValue != null) document.DocumentTypeID = Convert.ToInt32(DocumentTypeLUE.EditValue); if (FromObjectLUE.EditValue != null) document.FromStructureObjectID = Convert.ToInt32(FromObjectLUE.EditValue); if (ToObjectLUE.EditValue != null) document.ToStructureObjectD = Convert.ToInt32(ToObjectLUE.EditValue); int enterpriseId = Convert.ToInt32(EnterprisesCB.SelectedValue); int? teamId = null; if (TeamsLUE.EditValue != null) teamId = Convert.ToInt32(TeamsLUE.EditValue); //перезаписуємо дані працівників documentsLogic.DeleteDocumentEmployees(document, employeesDetailsView); foreach (StaffEmployeeView item in employeesDetailsView) { documentsLogic.SaveDocumentWithEmployees(document, item.Employee, teamId, mode); } if (cardId != null) document.CardID = cardId; document.DocumentSum = documentSum; document.EnterpriseID = enterpriseId; if (mode == "new") { document.CreatedDate = DateTime.Now; document.CreatedUserID = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; Logic.Staff.StaffEmployeeLogic staffLogic = new Logic.Staff.StaffEmployeeLogic(manager); StaffEmployee employee = staffLogic.GetByUserID(userId); if (employee != null) document.CreatedEmployeeID = employee.ID; //foreach (WareDocumentDetail detail in documentDetailsNew) //{ // documentDetailsLogic.SaveDocumentDetail(detail); //} documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "new"); } if (mode == "edit") { documentDetailsLogic.DeleteAllForDocument(document.ID); documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "edit"); //documentsLogic. } //якщо вказані дані про авто до перевіряємо чи дані вже існують string carNumber = CarNumberTE.Text; if (carNumber.Trim().Length > 0) { CWCarsLogic carsLogic = new CWCarsLogic(manager); CWCar car = null; categoryId = null; if (CarCategoriesCB.SelectedItem != null) { if (Convert.ToInt32(CarCategoriesCB.SelectedValue) > 0) categoryId = Convert.ToInt32(CarCategoriesCB.SelectedValue); } List<CWCar> cars = carsLogic.GetAll(CarNumberTE.Text, modelId, brandId); if (cars.Count > 0) { car = cars.FirstOrDefault(); } else { car = carsLogic.Create(brandId, modelId, carNumber, categoryId); } if (ContractorLUE.EditValue != null) { CWContractorCarsLogic contractorCars = new CWContractorCarsLogic(manager); contractorCars.Create(Convert.ToInt32(document.ContractorID), car); } DocumentCarsLogic documentCarsLogic = new DocumentCarsLogic(manager); documentCarsLogic.Create(document, car); } //Зберігаємо зміни manager.Save(); //Здійснюємо перерахунок залишків Compas.Logic.Wares.WareRemainsLogic remainsLogic = new Compas.Logic.Wares.WareRemainsLogic(manager); foreach (WareDocumentDetail detail in documentDetailsView) { if (document.FromStructureObjectID != null) remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.FromStructureObjectID, null); if (document.ToStructureObjectD != null) remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.ToStructureObjectD, null); } manager.Save(); int documentId = document.ID; if (AddPaymentCB.Checked == true) { DocumentPaymentData paymentForm = new DocumentPaymentData(documentId, document, cashRegister); paymentForm.ShowDialog(); } if (CloseAfterPayment == true) this.Close(); else { //після збереження даного документу - позиції документа очищаються і форма готова для створення нового документа CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info); manager = new ContextManager(); DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //FillPayments(); documentDetailsNew = new List<WareDocumentDetail>(); documentDetailsOld = new List<WareDocumentDetail>(); documentDetailsDeleted = new List<WareDocumentDetail>(); documentDetailsView = new List<WareDocumentDetail>(); employeesDetailsView = new List<StaffEmployeeView>(); documentsLogic = new DocumentsLogic(manager); documentDetailsLogic = new DocumentDetailsLogic(manager); if (mode == "new") { //створюємо документ в памяті document = documentsLogic.CreateEmpty(); } documentDetailsViewer.Clear(); FillDetails(); } } }
/// <summary> /// Збереження даних документу /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveBt_Click(object sender, EventArgs e) { if (dxValidationProvider1.Validate() == true) { if (ContractorLUE.EditValue != null) { document.ContractorID = Convert.ToInt32(ContractorLUE.EditValue); } if (CurrencyLUE.EditValue != null) { document.CurrencyID = Convert.ToInt32(CurrencyLUE.EditValue); } if (DateDE.EditValue != null) { document.Date = Convert.ToDateTime(DateDE.EditValue); } document.Description = DescriptionTE.Text; document.Address = AddressTE.Text; document.Number = NumberTE.Text; if (DocumentTypeLUE.EditValue != null) { document.DocumentTypeID = Convert.ToInt32(DocumentTypeLUE.EditValue); } if (FromObjectLUE.EditValue != null) { document.FromStructureObjectID = Convert.ToInt32(FromObjectLUE.EditValue); } if (ToObjectLUE.EditValue != null) { document.ToStructureObjectD = Convert.ToInt32(ToObjectLUE.EditValue); } int enterpriseId = Convert.ToInt32(EnterprisesCB.SelectedValue); int?teamId = null; if (TeamsLUE.EditValue != null) { teamId = Convert.ToInt32(TeamsLUE.EditValue); } //перезаписуємо дані працівників documentsLogic.DeleteDocumentEmployees(document, employeesDetailsView); foreach (StaffEmployeeView item in employeesDetailsView) { documentsLogic.SaveDocumentWithEmployees(document, item.Employee, teamId, mode); } if (cardId != null) { document.CardID = cardId; } document.DocumentSum = documentSum; document.EnterpriseID = enterpriseId; if (mode == "new") { document.CreatedDate = DateTime.Now; document.CreatedUserID = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; int userId = Compas.Logic.Security.CurrentSecurityContext.Identity.ID; Logic.Staff.StaffEmployeeLogic staffLogic = new Logic.Staff.StaffEmployeeLogic(manager); StaffEmployee employee = staffLogic.GetByUserID(userId); if (employee != null) { document.CreatedEmployeeID = employee.ID; } //foreach (WareDocumentDetail detail in documentDetailsNew) //{ // documentDetailsLogic.SaveDocumentDetail(detail); //} documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "new"); } if (mode == "edit") { documentDetailsLogic.DeleteAllForDocument(document.ID); documentsLogic.SaveDocumentWithDetails(document, documentDetailsView, "edit"); //documentsLogic. } //якщо вказані дані про авто до перевіряємо чи дані вже існують string carNumber = CarNumberTE.Text; if (carNumber.Trim().Length > 0) { CWCarsLogic carsLogic = new CWCarsLogic(manager); CWCar car = null; categoryId = null; if (CarCategoriesCB.SelectedItem != null) { if (Convert.ToInt32(CarCategoriesCB.SelectedValue) > 0) { categoryId = Convert.ToInt32(CarCategoriesCB.SelectedValue); } } List <CWCar> cars = carsLogic.GetAll(CarNumberTE.Text, modelId, brandId); if (cars.Count > 0) { car = cars.FirstOrDefault(); } else { car = carsLogic.Create(brandId, modelId, carNumber, categoryId); } if (ContractorLUE.EditValue != null) { CWContractorCarsLogic contractorCars = new CWContractorCarsLogic(manager); contractorCars.Create(Convert.ToInt32(document.ContractorID), car); } DocumentCarsLogic documentCarsLogic = new DocumentCarsLogic(manager); documentCarsLogic.Create(document, car); } //Зберігаємо зміни manager.Save(); //Здійснюємо перерахунок залишків Compas.Logic.Wares.WareRemainsLogic remainsLogic = new Compas.Logic.Wares.WareRemainsLogic(manager); foreach (WareDocumentDetail detail in documentDetailsView) { if (document.FromStructureObjectID != null) { remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.FromStructureObjectID, null); } if (document.ToStructureObjectD != null) { remainsLogic.UpdateCurrentRemainByDocumentDetail(document.Date, detail.WareID, document.ToStructureObjectD, null); } } manager.Save(); int documentId = document.ID; if (AddPaymentCB.Checked == true) { DocumentPaymentData paymentForm = new DocumentPaymentData(documentId, document, cashRegister); paymentForm.ShowDialog(); } if (CloseAfterPayment == true) { this.Close(); } else { //після збереження даного документу - позиції документа очищаються і форма готова для створення нового документа CompasLogger.Add(String.Format("Start opening doc form"), CompasLogger.Level.Info); manager = new ContextManager(); DetailsGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; //FillPayments(); documentDetailsNew = new List <WareDocumentDetail>(); documentDetailsOld = new List <WareDocumentDetail>(); documentDetailsDeleted = new List <WareDocumentDetail>(); documentDetailsView = new List <WareDocumentDetail>(); employeesDetailsView = new List <StaffEmployeeView>(); documentsLogic = new DocumentsLogic(manager); documentDetailsLogic = new DocumentDetailsLogic(manager); if (mode == "new") { //створюємо документ в памяті document = documentsLogic.CreateEmpty(); } documentDetailsViewer.Clear(); FillDetails(); } } }