diff --git a/Schnittstelle/Import/LV/Model/LVPosition.cs b/Schnittstelle/Import/LV/Model/LVPosition.cs new file mode 100644 index 0000000..4103837 --- /dev/null +++ b/Schnittstelle/Import/LV/Model/LVPosition.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Schnittstelle.Import.LV.Model +{ + public class LVPosition + { + public LVPosition((string Positionsnummer, string Title, string Einheit) m) + { + this.Positionsnummer = m.Positionsnummer; + this.Title = m.Title; + this.Einheit = m.Einheit; + } + + public LVPosition() + { + + } + + public string Positionsnummer { get; set; } = ""; + public string Title { get; set; } = ""; + public string Einheit { get; set; } = ""; + + + + public override string ToString() + { + return Positionsnummer; + } + } +} diff --git a/Schnittstelle/Import/LV/X81.cs b/Schnittstelle/Import/LV/X81.cs new file mode 100644 index 0000000..333f28a --- /dev/null +++ b/Schnittstelle/Import/LV/X81.cs @@ -0,0 +1,157 @@ +using Schnittstelle.Import.LV.Model; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Xml; + +namespace Schnittstelle.Import.LV +{ + public class X81 + { + + private List LVPositionen = new List(); + public List ExportedLVPosition = new List(); + + public X81(string filename) + { + ParseFile(filename); + } + + void ParseFile(string filename) + { + XmlDocument doc = new XmlDocument(); + doc.Load(filename); + var manager = new XmlNamespaceManager(doc.NameTable); + var l = doc.SelectSingleNode("GAEB"); + XmlNode elements = doc.LastChild.LastChild.LastChild.LastChild; + + /* + * foreach in elements where Name = BoQCtgy + */ + foreach(XmlNode s in elements.ChildNodes ) + { + if(s.Name.Equals("BoQCtgy")) + { + ParseBoQCtgy(s); + } + } + + var gx = LVPositionen.GroupBy(x => x.Positionsnummer).ToList(); + List<(string Positionsnummer, string Title, string Einheit)> sd = LVPositionen.Select(x => ( x.Positionsnummer, x.Title, x.Einheit)).Distinct().ToList(); + foreach(var m in sd) + { + ExportedLVPosition.Add(new LVPosition(m)); + } + } + + private void ParseBoQCtgy(XmlNode s) + { + foreach(XmlNode e in s.ChildNodes ) + { + switch(e.Name) + { + case "LblTx": break; + case "BoQBody": ParseBoQBody(e); break; + case "BoQCtgy": ParseBoQCtgy(e); break; + case "Remark": break; + default: throw new NotImplementedException(e.Name); + } + + } + } + + private void ParseBoQBody(XmlNode e) + { + foreach(XmlNode node in e.ChildNodes ) + { + switch(node.Name) + { + case "BoQCtgy": ParseBoQCtgy(e); break; + case "Itemlist": ParseItemList(e); break; + case "Remark": break; + default: throw new NotImplementedException(node.Name); + } + } + } + + private void ParseItemList(XmlNode e) + { + foreach(XmlNode node in e.ChildNodes) + { + switch(node.Name) + { + case "Remark": break; + case "Item": ParseItem(node); break; + case "Itemlist": ParseItemList(node); break; + default: throw new NotImplementedException(node.Name); + } + } + } + + private void ParseItem(XmlNode node) + { + LVPosition lVPosition = new LVPosition(); + foreach (XmlNode snode in node.ChildNodes) + { + + switch(snode.Name) + { + case "QU": lVPosition.Einheit = snode.InnerText; break; + case "Description": lVPosition.Title = ParseDescription(snode); break; + case "NEMETSCHEK:Codetext": lVPosition.Positionsnummer = ParseCodeText(snode.InnerText); break; + } + + } + LVPositionen.Add(lVPosition); + + } + + private string ParseCodeText(string src) + { + /* input + * 0021010010 + * should + * 002.1.01.0010 + */ + string t1 = src.Substring(0, 3); + string t2 = src.Substring(3,1); + string t3 = src.Substring(4, 2); + string pos = src.Substring(6, 4); + return string.Format("{0}.{1}.{2}.{3}",t1,t2,t3,pos); + + } + + private string ParseDescription(XmlNode snode) + { + foreach(XmlNode snode2 in snode.ChildNodes) + { + switch (snode2.Name) + { + case "CompleteText": + { + foreach(XmlNode snode3 in snode2.ChildNodes) + { + switch(snode3.Name) + { + case "DetailTxt": break; + case "OutlineText": return snode3.InnerText; + case "ComplTSA": + case "ComplTSB": + break; + + default: throw new NotImplementedException(snode3.Name); + } + } + } + break; + default: throw new NotImplementedException(snode2.Name); + } + } + throw new NotImplementedException(); + } + + + } +}