private void Fill() { CWCarsLogic cars = new CWCarsLogic(manager); CWCategoriesLogic categories = new CWCategoriesLogic(manager); CategoriesCB.DisplayMember = "Name"; CategoriesCB.ValueMember = "ID"; CategoriesCB.DataSource = categories.GetAll(); FillBrands(); if (mode == "edit") { CWCar car = cars.Get(Convert.ToInt32(id)); if (car != null) { foreach (object category in CategoriesCB.Items) { if (((CWCategory)category).ID == car.CategoryID) { CategoriesCB.SelectedItem = category; } } } } }
public int Create(WareDocument Document, CWCar Car) { int result = 1; WareDocumentCar documentCar = new WareDocumentCar(); Document.WareDocumentCars.Add(documentCar); Car.WareDocumentCars.Add(documentCar); return(result); }
/// <summary> /// Заповнення полів про прикріплену машину до документу /// </summary> private void FillCarInfo() { //CWContractorCarsLogic contractorCarsLogic = new CWContractorCarsLogic(manager); //List<CWContractorCar> contractorCars = contractorCarsLogic.GetAll(ContractorID); //CWContractorCar contractorCar = contractorCars.FirstOrDefault(); if (id != null) { DocumentCarsLogic documentCars = new DocumentCarsLogic(manager); List <WareDocumentCar> cars = documentCars.GetByDocumentID(Convert.ToInt32(id)); if (cars.Count > 0) { CWCar car = cars.FirstOrDefault().CWCar; CarNumberTE.Text = car.Number; CarBrandNameL.Text = car.CWCarBrand.Name; CarModelNameL.Text = car.CWCarModel.Name; CarBrandPB.Image = Helpers.ImageOperations.ByteArrayToImage(car.CWCarBrand.Image); CarModelPB.Image = Helpers.ImageOperations.ByteArrayToImage(car.CWCarModel.Image); } } }
public int Create(int ContractorID, CWCar Car) { int result = 1; Contractors.ContractorsLogic contractorsLogic = new Contractors.ContractorsLogic(manager); var carExists = from a in context.CWContractorCars where a.ContractorID == ContractorID & a.CWCar.Number == Car.Number & a.CWCar.ModelID == Car.ModelID & a.CWCar.BrandID == Car.BrandID select a; if (carExists.Count() == 0) { Contractor contractor = contractorsLogic.Get(ContractorID); if (contractor != null) { CWContractorCar cc = new CWContractorCar(); cc.ContractorID = ContractorID; Car.CWContractorCars.Add(cc); context.AddToCWContractorCars(cc); } } return(result); }
/// <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(); } } }
public CWCarView(CWCar Car) { car = Car; }