public void import(data_order order) { document = new XDocument(new XDeclaration("1.0", "windows-1251", null), new XElement("data")); XElement u = new XElement("data_order", new XAttribute("name", order.name), new XAttribute("note", order.note)); // XDeclaration xDeclaration = new XDeclaration("1.0", "windows-1251", "yes"); XElement X_list_mat = new XElement("list_materials"); foreach (Material mat in order.materials) { XElement XMat = new XElement("material", new XAttribute("name", mat.name)); XElement X_list_parts = new XElement("list_parts"); XElement X_list_sheet = new XElement("list_sheets"); foreach (part part in mat.parts) { XElement XPart = new XElement("part", new XAttribute("number", part.number), new XAttribute("length", part.Length), new XAttribute("width", part.width), new XAttribute("thick", part.thick), new XAttribute("quantity", part.quantitu), new XAttribute("rotate", part.rotate)); X_list_parts.Add(XPart); } XMat.Add(X_list_parts); foreach (Sheet sheet in mat.sheets) { XElement XSheet = new XElement("sheet", new XAttribute("length", sheet.length), new XAttribute("width", sheet.width), new XAttribute("thick", sheet.thick), new XAttribute("quantity", sheet.quantity)); X_list_sheet.Add(XSheet); } XMat.Add(X_list_sheet); X_list_mat.Add(XMat); } // xE.Add(X_list_mat); u.Add(X_list_mat); document.Root.Add(u); document.Save(@"D:\import.xml"); return; }
public void Atr(IEnumerable <XAttribute> elements, string t) { // Отображаем атрибуты элемента foreach (XAttribute attr in elements) { // Console.WriteLine("Атрибут: {0} : значение = {1}", attr.Name, attr.Value); switch (t) { case "data_order": m_data_order = new data_order(); break; case "material": //string e; // int q; if (attr.Name == "name") { m.name = attr.Value; } else if (attr.Name == "index") { m.index = Convert.ToInt32(attr.Value); } // l_m.Add(m); break; case "part": if (attr.Name == "number") { part_z.number = Convert.ToInt32(attr.Value); } else if (attr.Name == "rotate") { part_z.rotate = Convert.ToInt32(attr.Value); } else if (attr.Name == "quantitu") { part_z.quantitu = Convert.ToInt32(attr.Value); } else if (attr.Name == "thick") { part_z.thick = Convert.ToInt32(attr.Value); } else if (attr.Name == "width") { part_z.width = Convert.ToInt32(attr.Value); } else if (attr.Name == "length") { part_z.Length = Convert.ToInt32(attr.Value); } break; case "nesting_plan": if (attr.Name == "number") { np.number = Convert.ToInt32(attr.Value); } else if (attr.Name == "code") { np.code = attr.Value; } else if (attr.Name == "cut_legth") { np.cut_length = Convert.ToDouble(attr.Value); } else if (attr.Name == "length") { np.length = Convert.ToInt32(attr.Value); } else if (attr.Name == "quantitu") { np.quantitu = Convert.ToInt32(attr.Value); } else if (attr.Name == "width") { np.width = Convert.ToInt32(attr.Value); } else if (attr.Name == "thick") { np.thick = Convert.ToInt32(attr.Value); } break; case "part_n": if (attr.Name == "number") { pnest.Number = Convert.ToInt32(attr.Value); } else if (attr.Name == "rotate") { pnest.rotate = Convert.ToInt32(attr.Value); } else if (attr.Name == "note") { pnest.note = attr.Value; } else if (attr.Name == "width") { pnest.width = Convert.ToInt32(attr.Value); } else if (attr.Name == "length") { pnest.Length = Convert.ToInt32(attr.Value); } else if (attr.Name == "x") { pnest.x = Convert.ToInt32(attr.Value); } else if (attr.Name == "y") { pnest.y = Convert.ToInt32(attr.Value); } break; } } }