/// <summary> /// /// </summary> /// <param name="product">MpProduct, связанный с элементом спецификации</param> /// <param name="steelDoc">Документ на сталь</param> /// <param name="steelType">Марка стали</param> /// <param name="dimension">Вариант измерения</param> /// <param name="subsection">Название подраздела. product должен быть null</param> /// <param name="inputType">Вид элемента спецификации: из БД, подраздел или ручной ввод</param> /// <param name="handBeforeName"></param> /// <param name="handTopName"></param> /// <param name="handAfterName"></param> /// <param name="handMass"></param> public SpecificationItem( MpProduct product, string steelDoc, string steelType, string dimension, string subsection, SpecificationItemInputType inputType, string handBeforeName, string handTopName, string handAfterName, double?handMass) { if (product != null) { Product = product; Dimension = dimension; InputType = SpecificationItemInputType.DataBase; InitSpecificationItem(steelDoc, steelType); } else { if (inputType == SpecificationItemInputType.SubSection) { Product = null; InputType = SpecificationItemInputType.SubSection; BeforeName = subsection; AfterName = TopName = SteelDoc = SteelType = Dimension = Note = string.Empty; Mass = null; HasSteel = false; SteelVisibility = Visibility.Collapsed; } else if (inputType == SpecificationItemInputType.HandInput) { Product = null; InputType = SpecificationItemInputType.HandInput; BeforeName = handBeforeName; AfterName = handAfterName; TopName = handTopName; Mass = handMass; Dimension = string.Empty; if (!string.IsNullOrEmpty(steelDoc) && !string.IsNullOrEmpty(steelType)) { SteelDoc = steelDoc; SteelType = steelType; HasSteel = true; SteelVisibility = Visibility.Visible; } else { HasSteel = false; SteelVisibility = Visibility.Collapsed; } } } }
public static SpecificationItem ConvertFromXml(XElement specificationItemXel) { MpProduct mpProduct = null; var productXel = specificationItemXel.Element("Product"); // Если есть элемент, описывающий Изделие из БД if (productXel != null) { mpProduct = new MpProduct() { BaseDocument = GetBaseDocumentById( productXel.Attribute("BaseDocument.DataBaseName")?.Value, int.TryParse(productXel.Attribute("BaseDocument.Id")?.Value, out int inum) ? inum : -1) }; mpProduct.SteelType = productXel.Attribute("SteelType")?.Value; mpProduct.Position = productXel.Attribute("Position")?.Value; mpProduct.Position = productXel.Attribute("Position")?.Value; mpProduct.Length = TryParseInvariant(productXel.Attribute("Length")?.Value, out double dnum) ? dnum : 0; mpProduct.Diameter = TryParseInvariant(productXel.Attribute("Diameter")?.Value, out dnum) ? dnum : 0; mpProduct.Width = TryParseInvariant(productXel.Attribute("Width")?.Value, out dnum) ? dnum : 0; mpProduct.Height = TryParseInvariant(productXel.Attribute("Height")?.Value, out dnum) ? dnum : 0; mpProduct.Mass = TryParseInvariant(productXel.Attribute("Mass")?.Value, out dnum) ? dnum : 0; mpProduct.WMass = TryParseInvariant(productXel.Attribute("WMass")?.Value, out dnum) ? dnum : 0; mpProduct.CMass = TryParseInvariant(productXel.Attribute("CMass")?.Value, out dnum) ? dnum : 0; mpProduct.SMass = TryParseInvariant(productXel.Attribute("SMass")?.Value, out dnum) ? dnum : 0; mpProduct.ItemTypes = mpProduct.BaseDocument.ItemTypes; var indexOfItem = int.TryParse(productXel.Attribute("IndexOfItem")?.Value, out inum) ? inum : -1; var productItemXel = indexOfItem != -1 ? mpProduct.BaseDocument.Items.Elements("Item").ElementAt(indexOfItem) : null; mpProduct.Item = productItemXel; if (!string.IsNullOrEmpty(productXel.Attribute("ItemTypesValues")?.Value)) { var list = productXel.Attribute("ItemTypesValues")?.Value.Split('$').ToList(); for (var i = 0; i < list?.Count; i++) { mpProduct.ItemTypes[i].SelectedItem = list[i]; } } } // Остальные значения var steelDoc = specificationItemXel.Attribute("SteelDoc")?.Value; var steelType = specificationItemXel.Attribute("SteelType")?.Value; var dimension = specificationItemXel.Attribute("Dimension")?.Value; double?handMass = null; if (TryParseInvariant(specificationItemXel.Attribute("Mass")?.Value, out double d)) { handMass = d; } var specificationItem = new SpecificationItem( mpProduct, steelDoc, steelType, dimension, string.Empty, GetInputType(specificationItemXel.Attribute("InputType")?.Value), specificationItemXel.Attribute("BeforeName")?.Value, specificationItemXel.Attribute("TopName")?.Value, specificationItemXel.Attribute("AfterName")?.Value, handMass); specificationItem.Position = specificationItemXel.Attribute("Position")?.Value; specificationItem.AfterName = specificationItemXel.Attribute("AfterName")?.Value; specificationItem.BeforeName = specificationItemXel.Attribute("BeforeName")?.Value; specificationItem.Count = specificationItemXel.Attribute("Count")?.Value; specificationItem.DbIndex = int.TryParse(specificationItemXel.Attribute("DbIndex")?.Value, out int integer) ? integer : -1; specificationItem.Designation = specificationItemXel.Attribute("Designation")?.Value; specificationItem.HasSteel = bool.TryParse(specificationItemXel.Attribute("HasSteel")?.Value, out bool flag) & flag; if (TryParseInvariant(specificationItemXel.Attribute("Mass")?.Value, out double dnumber)) { specificationItem.Mass = dnumber; } else { specificationItem.Mass = null; } specificationItem.Note = specificationItemXel.Attribute("Note")?.Value; specificationItem.TopName = specificationItemXel.Attribute("TopName")?.Value; specificationItem.SteelDoc = steelDoc; specificationItem.SteelType = steelType; specificationItem.AfterName = specificationItemXel.Attribute("AfterName")?.Value; specificationItem.SteelVisibility = Enum.TryParse(specificationItemXel.Attribute("SteelVisibility")?.Value, out Visibility visibility) ? visibility : Visibility.Collapsed; return(specificationItem); }