示例#1
0
        public static XElement ConvertToXml(SpecificationItem item)
        {
            double?  mass;
            XElement xElement = new XElement("SpecificationItem");

            xElement.SetAttributeValue("InputType", item.InputType.ToString());
            xElement.SetAttributeValue("Position", item.Position);
            xElement.SetAttributeValue("AfterName", item.AfterName);
            xElement.SetAttributeValue("BeforeName", item.BeforeName);
            xElement.SetAttributeValue("Count", item.Count);
            xElement.SetAttributeValue("DbIndex", item.DbIndex);
            xElement.SetAttributeValue("Designation", item.Designation);
            xElement.SetAttributeValue("Dimension", item.Dimension);
            xElement.SetAttributeValue("HasSteel", item.HasSteel);
            if (item.Mass.HasValue)
            {
                XName xName = "Mass";
                mass = item.Mass;
                xElement.SetAttributeValue(xName, mass.Value);
            }

            xElement.SetAttributeValue("Note", item.Note);
            xElement.SetAttributeValue("TopName", item.TopName);
            xElement.SetAttributeValue("SteelDoc", item.SteelDoc);
            xElement.SetAttributeValue("SteelType", item.SteelType);
            xElement.SetAttributeValue("SteelVisibility", item.SteelVisibility);
            if (item.Product != null)
            {
                XElement xElement1 = new XElement("Product");
                xElement1.SetAttributeValue("BaseDocument.Id", item.Product.BaseDocument.Id);
                xElement1.SetAttributeValue("BaseDocument.DataBaseName", item.Product.BaseDocument.DataBaseName);
                if (item.Product.Length.HasValue)
                {
                    XName xName1 = "Length";
                    mass = item.Product.Length;
                    xElement1.SetAttributeValue(xName1, mass.Value);
                }

                if (item.Product.Diameter.HasValue)
                {
                    XName xName2 = "Diameter";
                    mass = item.Product.Diameter;
                    xElement1.SetAttributeValue(xName2, mass.Value);
                }

                if (item.Product.Width.HasValue)
                {
                    XName xName3 = "Width";
                    mass = item.Product.Width;
                    xElement1.SetAttributeValue(xName3, mass.Value);
                }

                if (item.Product.Height.HasValue)
                {
                    XName xName4 = "Height";
                    mass = item.Product.Height;
                    xElement1.SetAttributeValue(xName4, mass.Value);
                }

                xElement1.SetAttributeValue("SteelDoc", item.Product.SteelDoc);
                xElement1.SetAttributeValue("SteelType", item.Product.SteelType);
                xElement1.SetAttributeValue("Position", item.Product.Position);
                xElement1.SetAttributeValue("Mass", item.Product.Mass);
                xElement1.SetAttributeValue("WMass", item.Product.WMass);
                xElement1.SetAttributeValue("CMass", item.Product.CMass);
                xElement1.SetAttributeValue("SMass", item.Product.SMass);
                if (!item.Product.BaseDocument.Items?.Elements("Item").Any() ?? true)
                {
                    xElement1.SetAttributeValue("IndexOfItem", -1);
                }
                else
                {
                    xElement1.SetAttributeValue("IndexOfItem", item.Product.BaseDocument.Items.Elements("Item").ToList().IndexOf(item.Product.Item));
                }

                if (item.Product.ItemTypes == null)
                {
                    xElement1.SetAttributeValue("ItemTypesValues", string.Empty);
                }
                else
                {
                    string str = item.Product.ItemTypes.Aggregate(string.Empty, (current, itemType) => string.Concat(current, itemType.SelectedItem, "$"));
                    xElement1.SetAttributeValue("ItemTypesValues", str.TrimEnd('$'));
                }

                xElement.Add(xElement1);
            }

            return(xElement);
        }
示例#2
0
        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);
        }
示例#3
0
        /// <summary>
        /// Конвертирование продукта в класс SpecificationItem для заполнения спецификации
        /// </summary>
        /// <returns></returns>
        public SpecificationItem GetSpecificationItem(double?count)
        {
            SpecificationItem str;
            SpecificationItem specificationItem;
            int    num          = 0;
            string dataBaseName = BaseDocument.DataBaseName;

            if (dataBaseName == "DbMetall")
            {
                num = 0;
            }
            else if (dataBaseName == "DbConcrete")
            {
                num = 1;
            }
            else if (dataBaseName == "DbWood")
            {
                num = 2;
            }
            else if (dataBaseName == "DbMaterial")
            {
                num = 3;
            }
            else if (dataBaseName == "DbOther")
            {
                num = 4;
            }

            var dimension = string.Empty;

            if (Length.HasValue)
            {
                var dimensionAttribute = BaseDocument.XmlDocument.Attribute("DimType");
                if (dimensionAttribute != null)
                {
                    if (dimensionAttribute.Value.Contains("Длина"))
                    {
                        dimension = "Длина";
                    }
                }
            }

            if (!BaseDocument.HasSteel)
            {
                specificationItem = new SpecificationItem(
                    this, string.Empty, string.Empty, dimension, string.Empty,
                    SpecificationItemInputType.DataBase, string.Empty, string.Empty, string.Empty, GetProductMass())
                {
                    DbIndex = num
                };
                str = specificationItem;
            }
            else
            {
                specificationItem = new SpecificationItem(
                    this, SteelDoc, SteelType, dimension, string.Empty,
                    SpecificationItemInputType.DataBase, string.Empty, string.Empty, string.Empty, GetProductMass())
                {
                    DbIndex = num
                };
                str = specificationItem;
            }

            if (count.HasValue)
            {
                str.Count = count.ToString();
            }

            str.Position = Position;
            return(str);
        }