/// <summary> /// Конструктор создает объект с привязкой родительского объекта /// </summary> public Product(Product toCopy) : this() { if (toCopy == null) return; _batchNumber = toCopy.BatchNumber; _costNew = toCopy.CostNew; _costOvehaul = toCopy.CostOverhaul; _costServiceable = toCopy.CostServiceable; _description = toCopy.Description; _manufacturer = toCopy.Manufacturer; _measure = toCopy.Measure; _partNumber = toCopy.PartNumber; _remarks = toCopy.Remarks; _serialNumber = toCopy.SerialNumber; _standart = toCopy.Standart; if (_suppliers == null) _suppliers = new SupplierCollection(); _suppliers.Clear(); foreach (Supplier supplier in toCopy.Suppliers) { _suppliers.Add(supplier); } if (_supplierRelations == null) _supplierRelations = new CommonCollection<KitSuppliersRelation>(); _supplierRelations.Clear(); foreach (KitSuppliersRelation ksr in toCopy.SupplierRelations) { _supplierRelations.Add(new KitSuppliersRelation(ksr) {KitId = ItemId}); } }
/// <summary> /// Конструктор создает объект с параметрами по умолчанию /// </summary> public Product() { ItemId = -1; _description = ""; _partNumber = ""; _standart = null; _remarks = ""; _manufacturer = ""; _measure = Measure.Unit; SmartCoreObjectType = SmartCoreType.Product; }
public static GoodStandartDTO Convert(this GoodStandart standart) { return(new GoodStandartDTO { ItemId = standart.ItemId, IsDeleted = standart.IsDeleted, Updated = standart.Updated, CorrectorId = standart.CorrectorId, Name = standart.FullName, PartNumber = standart.PartNumber, Description = standart.Description, Remarks = standart.Remarks, DefaultProductId = standart.DefaultProductId, ComponentType = standart.GoodsClass?.ItemId }); }
protected override void Save() { try { GoodStandart standart = comboBoxAccessoryStandard.SelectedItem as GoodStandart; string partNumber = textBoxPartNumber.Text.Replace(" ", "").ToLower(); string standartName = comboBoxAccessoryStandard.Text; //string description = textBoxDescription.Text.Replace(" ", "").ToLower(); List <Product> products = null; //List<GoodStandart> goodStandarts = null; //GoodStandart goodStandart = null; //try //{ // //goodStandarts = new List<GoodStandart>(GlobalObjects.CasEnvironment.NewLoader.GetObjectList<GoodStandartDTO, GoodStandart>()); //} //catch (Exception ex) //{ // Program.Provider.Logger.Log("Not Find dictionary of type " + typeof(GoodStandart).Name, ex); //} //if (goodStandarts != null) //{ // goodStandart = goodStandarts // .FirstOrDefault(gs => gs.PartNumber.Replace(" ", "").ToLower() == partNumber // && standart != null && gs.FullName.Replace(" ", "").ToLower() == standart.FullName.Replace(" ", "").ToLower()); // if (goodStandart == null) // { // goodStandart = new GoodStandart(); // goodStandart.GoodsClass = comboBoxDetailClass.SelectedItem as GoodsClass; // goodStandart.PartNumber = textBoxPartNumber.Text; // goodStandart.Description = textBoxDescription.Text; // goodStandart.FullName = standartName.ToLower() == "select item" || standartName.ToLower() == "n/a" ? "N/A" : standartName; // //goodStandart.CostNew = (double)numericCostNew.Value; // //goodStandart.CostServiceable = (double)numericCostServiceable.Value; // //goodStandart.CostOverhaul = (double)numericCostOverhaul.Value; // goodStandart.Remarks = textBoxRemarks.Text; // //goodStandart.Measure = comboBoxMeasure.SelectedItem as Measure; // GlobalObjects.CasEnvironment.Manipulator.Save(goodStandart); // } // _currentItem.Standart = goodStandart; //} _currentItem.GoodsClass = comboBoxDetailClass.SelectedItem as GoodsClass; _currentItem.PartNumber = textBoxPartNumber.Text; _currentItem.AltPartNumber = textBoxAltPartNum.Text; _currentItem.Description = textBoxDescription.Text; _currentItem.Manufacturer = textBoxManufacturer.Text; //_currentItem.Standart = goodStandart; _currentItem.Standart = standart; _currentItem.Name = textBoxName.Text; _currentItem.Reference = textBoxReference.Text; _currentItem.EngineRef = textBoxEngineRef.Text; _currentItem.Remarks = textBoxRemarks.Text; _currentItem.IsEffectivity = textBoxIsEffectivity.Text; _currentItem.Measure = comboBoxMeasure.SelectedItem as Measure; _currentItem.ATAChapter = comboBoxAtaChapter.ATAChapter; _currentItem.IsForbidden = checkBoxIsForbidden.Checked; _currentItem.IsDangerous = checkBoxDangerous.Checked; GlobalObjects.CasEnvironment.Manipulator.Save(_currentItem); foreach (KitSuppliersRelation ksr in _currentItem.SupplierRelations) { //if (ksr.ItemId <= 0) //{ // if (ksr.CostNew == 0) // ksr.CostNew = _currentItem.CostNew; // if (ksr.CostServiceable == 0) // ksr.CostServiceable = _currentItem.CostServiceable; // if (ksr.CostOverhaul == 0) // ksr.CostOverhaul = _currentItem.CostOverhaul; //} if (ksr.SupplierId != 0) { //_currentKit.SupplierRelations.Add(ksr); ksr.KitId = _currentItem.ItemId; ksr.ParentTypeId = _currentItem.SmartCoreObjectType.ItemId; try { GlobalObjects.CasEnvironment.NewKeeper.Save(ksr); } catch (Exception ex) { Program.Provider.Logger.Log("Error while saving data", ex); return; } } } } catch (Exception ex) { Program.Provider.Logger.Log("Error while saving data", ex); } }
/// <summary> /// Создает форму для редактирования переданного элемента /// </summary> /// <param name="currentKit"></param> public GoodStandardForm(GoodStandart currentKit) : this() { _currentKit = currentKit; UpdateInformation(); }
private void UpdateInformation() { comboBoxStandart.SelectedIndexChanged -= ComboBoxStandartSelectedIndexChanged; textBoxRemarks.Text = string.Empty; comboBoxStandart.Type = typeof(GoodStandart); Program.MainDispatcher.ProcessControl(comboBoxStandart); FormControlAttribute fca = (FormControlAttribute) typeof(Product) .GetProperty("GoodsClass") .GetCustomAttributes(typeof(FormControlAttribute), false) .FirstOrDefault(); if (fca != null) { comboBoxDetailClass.RootNodesNames = fca.TreeDictRootNodes; } comboBoxDetailClass.Type = typeof(GoodsClass); comboBoxMeasure.Items.Clear(); comboBoxMeasure.Items.AddRange(Measure.GetByCategories(new[] { MeasureCategory.Mass, MeasureCategory.EconomicEntity })); comboBoxMeasure.Items.Add(Measure.Liter); comboBoxMeasure.Items.Add(Measure.Gallon); comboBoxMeasure.Items.Add(Measure.Quart); comboBoxMeasure.Items.Add(Measure.SquareMeter); comboBoxMeasure.Items.Add(Measure.Foot); comboBoxMeasure.Items.Add(Measure.Miles); comboBoxMeasure.Items.Add(Measure.SquareFoot); comboBoxMeasure.Items.Add(Measure.Metres); comboBoxMeasure.Items.Add(Measure.Centimeters); if (_currentKit == null) { return; } comboBoxDetailClass.SelectedItem = GoodsClass.KIT; comboBoxMeasure.SelectedItem = Measure.Unit; UpdateByProduct(_currentKit.Product); Product accessoryDescription; if ((accessoryDescription = _currentKit.Product) != null) { comboBoxDetailClass.SelectedItem = accessoryDescription.GoodsClass; comboBoxDetailClass.Enabled = false; comboBoxMeasure.Enabled = false; textBoxPartNumber.ReadOnly = true; comboBoxStandart.Enabled = false; textBoxDescription.ReadOnly = true; //linkLabelEditSupplier.Enabled = true; comboBoxMeasure.SelectedItem = accessoryDescription.Measure; comboBoxStandart.SelectedItem = accessoryDescription.Standart; textBoxPartNumber.Text = accessoryDescription.PartNumber; textBoxDescription.Text = accessoryDescription.Description; textBoxReference.Text = accessoryDescription.Reference; //textBoxSuppliers.Text = accessoryDescription.Suppliers.ToString(); } else if (_currentKit.Standart != null) { GoodStandart accessoryStandart = _currentKit.Standart; comboBoxDetailClass.SelectedItem = accessoryStandart.GoodsClass; comboBoxDetailClass.Enabled = false; //comboBoxMeasure.Enabled = false; textBoxPartNumber.ReadOnly = true; textBoxDescription.ReadOnly = true; //linkLabelEditSupplier.Enabled = true; //comboBoxMeasure.SelectedItem = accessoryStandart.Measure; comboBoxStandart.SelectedItem = accessoryStandart; textBoxPartNumber.Text = accessoryStandart.PartNumber; textBoxDescription.Text = accessoryStandart.Description; textBoxReference.Text = ""; } else { if (_currentKit is Component) { comboBoxDetailClass.SelectedItem = _currentKit.GoodsClass; comboBoxDetailClass.Enabled = false; comboBoxMeasure.Enabled = false; textBoxPartNumber.ReadOnly = true; comboBoxStandart.Enabled = false; textBoxDescription.ReadOnly = true; //linkLabelEditSupplier.Enabled = true; comboBoxMeasure.SelectedItem = _currentKit.Measure; comboBoxStandart.SelectedItem = _currentKit.Standart; textBoxPartNumber.Text = _currentKit.PartNumber; textBoxDescription.Text = _currentKit.Description; textBoxReference.Text = _currentKit.Product?.Reference; //textBoxSuppliers.Text = _currentKit.Suppliers.ToString(); } } textBoxRemarks.Text = _currentKit.Remarks; numericCount.Value = (decimal)_currentKit.Quantity; comboBoxStandart.SelectedIndexChanged += ComboBoxStandartSelectedIndexChanged; }
///<summary> /// Проставляет товар и стандарт для комплектующего ///</summary> ///<returns>true - если удалось определеить и проставить продукт и стандарт для комплектующего</returns> public bool SetStandartAndProduct(AbstractAccessory accessory, string standartName, string partialNumber, string description, string remarks, string manufacturer, GoodsClass goodsClass, Measure measure, double costNew, double costOverhaul, double costServiceable, IEnumerable <Supplier> suppliers) { if (accessory == null) { throw new ArgumentException("must be not null", "accessory"); } if (accessory.Product != null && accessory.Product.ItemId > 0) { return(true); } string standart = standartName.Replace(" ", "").ToLower(); string partNumber = partialNumber.Replace(" ", "").ToLower(); bool needToSaveAccessory = false; bool result = true; GoodStandart goodStandart = null; List <GoodStandart> goodStandarts = _loader.GetObjectList <GoodStandart>(); List <Product> products; if (accessory is Entities.General.Accessory.Component) { products = new List <Product>(_loader.GetObjectList <ComponentModel>(loadChild: true).ToArray()); } else { products = _loader.GetObjectList <Product>(loadChild: true); } if (goodStandarts != null && !string.IsNullOrEmpty(standart)) { goodStandart = goodStandarts .FirstOrDefault(ad => ad.PartNumber.Replace(" ", "").ToLower() == partNumber && ad.FullName.Replace(" ", "").ToLower() == standart); if (goodStandart == null) { goodStandart = new GoodStandart { GoodsClass = goodsClass, PartNumber = partialNumber, Description = description, FullName = standartName, //CostNew = costNew, //CostServiceable = costServiceable, //CostOverhaul = costOverhaul, Remarks = remarks, //Measure = measure }; _newKeeper.Save(goodStandart); } accessory.Standart = goodStandart; needToSaveAccessory = true; } if ((manufacturer != "" || suppliers != null && suppliers.Any()) && products != null) { Product product = products .FirstOrDefault(p => p.PartNumber.Replace(" ", "").ToLower() == partNumber && p.Standart != null && p.Standart.FullName.Replace(" ", "").ToLower() == standart); if (product == null) { if (accessory is Entities.General.Accessory.Component) { ComponentModel dm = new ComponentModel { BatchNumber = "", CostNew = costNew, CostOverhaul = costOverhaul, CostServiceable = costServiceable, Description = description, GoodsClass = goodsClass, Manufacturer = manufacturer, Measure = measure, PartNumber = partNumber, Remarks = remarks, }; product = dm; } else { product = new Product { GoodsClass = goodsClass, PartNumber = partialNumber, Description = description, Manufacturer = manufacturer, Standart = goodStandart, CostNew = costNew, CostServiceable = costServiceable, CostOverhaul = costOverhaul, Remarks = remarks, Measure = measure }; } _newKeeper.Save(product); if (goodStandart != null && goodStandart.DefaultProductId <= 0) { goodStandart.DefaultProductId = product.ItemId; _newKeeper.Save(goodStandart); } product.SupplierRelations.Clear(); foreach (KitSuppliersRelation ksr in accessory.SupplierRelations) { if (ksr.SupplierId != 0) { product.SupplierRelations.Add(ksr); ksr.KitId = product.ItemId; ksr.ParentTypeId = product.SmartCoreObjectType.ItemId; _newKeeper.Save(ksr); } } } Entities.General.Accessory.Component component = accessory as Entities.General.Accessory.Component; if (component != null) { component.Model = product as ComponentModel; } else { accessory.Product = product; } needToSaveAccessory = true; } else { accessory.Product = null; result = false; } if (needToSaveAccessory) { _newKeeper.Save(accessory); } return(result); }