using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
Console.WriteLine("Hello World");
public class ElectronicDocument
public string DocumentNumber { get; set; }
public string DocumentType { get; set; }
public string DocumentCode { get; set; }
public DateTime DocumentDate { get; set; }
public string DocReason_DocumentNumber { get; set; }
public string DocReason_DocumentType { get; set; }
public string DocReason_DocumentCode { get; set; }
public DateTime DocReason_DocumentDate { get; set; }
public string Buyer_TypeOfPerson { get; set; }
public string Buyer_ContractorName { get; set; }
public string Buyer_ContractorCode { get; set; }
public string Buyer_IPN { get; set; }
public string Buyer_PDVCertificate { get; set; }
public string Buyer_GLN { get; set; }
public string Seller_TypeOfPerson { get; set; }
public string Seller_ContractorName { get; set; }
public string Seller_ContractorCode { get; set; }
public string Seller_IPN { get; set; }
public string Seller_PDVCertificate { get; set; }
public string Seller_GLN { get; set; }
public string AmountWithoutVAT { get; set; }
public string VAT { get; set; }
public string Amount { get; set; }
public string FileName { get; set; }
public string Status { get; set; } = "Новий";
public List<dynamic> Table { get; set; } = null;
public ElectronicDocument(XDocument xDocument, string filename)
List<string> vs = new List<string>();
XElement ElectronicDocument = xDocument.Element("ЕлектроннийДокумент");
XElement Header = ElectronicDocument.Element("Заголовок");
XElement DocReason = ElectronicDocument.Element("Заголовок").Element("ДокПідстава");
XElement Buyer = ElectronicDocument.Elements("Сторони").Elements("Контрагент").Where(x => x.Element("СтатусКонтрагента").Value == "Покупець").First();
XElement Seller = ElectronicDocument.Element("Сторони").Elements("Контрагент").Where(x => x.Element("СтатусКонтрагента").Value == "Продавець").First();
XElement AmountXML = ElectronicDocument.Element("ВсьогоПоДокументу");
IEnumerable<XElement> xmlTable = ElectronicDocument.Element("Таблиця").Elements("Рядок");
DocumentNumber = Header.Element("НомерДокументу").Value;
DocumentType = Header.Element("ТипДокументу").Value;
DocumentCode = Header.Element("КодТипуДокументу").Value;
DocumentDate = Convert.ToDateTime(Header.Element("ДатаДокументу").Value);
DocReason_DocumentNumber = DocReason.Element("НомерДокументу").Value;
DocReason_DocumentType = DocReason.Element("ТипДокументу").Value;
DocReason_DocumentCode = DocReason.Element("КодТипуДокументу").Value;
DocReason_DocumentDate = Convert.ToDateTime(DocReason.Element("ДатаДокументу").Value);
Buyer_TypeOfPerson = Buyer.Element("ВидОсоби")?.Value;
Buyer_ContractorName = Buyer.Element("НазваКонтрагента")?.Value;
Buyer_ContractorCode = Buyer.Element("КодКонтрагента")?.Value;
Buyer_IPN = Buyer.Element("ІПН")?.Value;
Buyer_PDVCertificate = Buyer.Element("СвідоцтвоПДВ")?.Value ?? "";
Buyer_GLN = Buyer.Element("GLN")?.Value;
Seller_TypeOfPerson = Seller.Element("ВидОсоби")?.Value;
Seller_ContractorName = Seller.Element("НазваКонтрагента")?.Value;
Seller_ContractorCode = Seller.Element("КодКонтрагента")?.Value;
Seller_IPN = Seller.Element("ІПН")?.Value;
Seller_PDVCertificate = Seller.Element("СвідоцтвоПДВ")?.Value ?? "";
Seller_GLN = Seller.Element("GLN")?.Value;
AmountWithoutVAT = AmountXML.Element("СумаБезПДВ")?.Value??"";
VAT = AmountXML.Element("ПДВ")?.Value ?? "";
Amount = AmountXML.Element("Сума")?.Value ?? "";
if(Path.GetFileNameWithoutExtension(filename).EndsWith("005"))
Table = xmlTable.Select(x =>
).Cast<dynamic>().ToList(); ;
if (Path.GetFileNameWithoutExtension(filename).EndsWith("007"))
Table = xmlTable.Select(x =>
).Cast<dynamic>().ToList(); ;
if (Path.GetFileNameWithoutExtension(filename).EndsWith("012"))
Table = xmlTable.Select(x =>
).Cast<dynamic>().ToList(); ;
public class ED_Table_005
public ED_Table_005(XElement Row)
PositionNumber = Row.Element("НомПоз").Value;
BarcodeID = Row.Element("Штрихкод").Value;
BuyerArticle = Row.Element("АртикулПокупця").Value;
Name = Row.Element("Найменування").Value;
AcceptedNumber = Row.Element("ПрийнятаКількість").Value;
UnitMeasurement = Row.Element("ОдиницяВиміру").Value;
BasePrice = Row.Element("БазоваЦіна").Value;
VAT = Row.Element("ПДВ").Value;
Price = Row.Element("Ціна").Value;
Summary_PriceWithoutVAT = Row.Element("ВсьогоПоРядку").Element("СумаБезПДВ").Value;
Summary_VAT = Row.Element("ВсьогоПоРядку").Element("СумаПДВ").Value;
Summary_Price = Row.Element("ВсьогоПоРядку").Element("Сума").Value;
Reason_Code = Row.Element("Причина").Element("Код").Value;
Reason_Description = Row.Element("Причина").Element("Опис").Value;
Reason_Quantity = Row.Element("Причина").Element("Кількість").Value;
Reason_UnitMeasurement = Row.Element("Причина").Element("ОдиницяВиміру").Value;
Reason_Amount = Row.Element("Причина")?.Element("НаСуму")?.Value ?? "";
public string PositionNumber { get; set; }
public string BarcodeID { get; set; }
public string BuyerArticle { get; set; }
public string Name { get; set; }
public string AcceptedNumber { get; set; }
public string UnitMeasurement { get; set; }
public string BasePrice { get; set; }
public string VAT { get; set; }
public string Price { get; set; }
public string Summary_PriceWithoutVAT { get; set; }
public string Summary_VAT { get; set; }
public string Summary_Price { get; set; }
public string Reason_Code { get; set; }
public string Reason_Description { get; set; }
public string Reason_Quantity { get; set; }
public string Reason_UnitMeasurement { get; set; }
public string Reason_Amount { get; set; }
public class ED_Table_007
public ED_Table_007(XElement Row)
PositionNumber = Row.Element("НомПоз").Value;
BarcodeID = Row.Element("Штрихкод").Value;
BuyerArticle = Row.Element("АртикулПокупця").Value;
Name = Row.Element("Найменування").Value;
AcceptedNumber = Row.Element("ПрийнятаКількість").Value;
UnitMeasurement = Row.Element("ОдиницяВиміру").Value;
BasePrice = Row.Element("БазоваЦіна").Value;
VAT = Row.Element("ПДВ").Value;
Price = Row.Element("Ціна").Value;
Summary_PriceWithoutVAT = Row.Element("ВсьогоПоРядку").Element("СумаБезПДВ").Value;
Summary_VAT = Row.Element("ВсьогоПоРядку").Element("СумаПДВ").Value;
Summary_Price = Row.Element("ВсьогоПоРядку").Element("Сума").Value;
Reason_Code = Row.Element("Причина").Element("Код").Value;
Reason_Description = Row.Element("Причина").Element("Опис").Value;
Reason_Quantity = Row.Element("Причина").Element("Кількість").Value;
Reason_UnitMeasurement = Row.Element("Причина").Element("ОдиницяВиміру").Value;
Reason_Amount = Row.Element("Причина")?.Element("НаСуму")?.Value ?? "";
public string PositionNumber { get; set; }
public string BarcodeID { get; set; }
public string BuyerArticle { get; set; }
public string Name { get; set; }
public string AcceptedNumber { get; set; }
public string UnitMeasurement { get; set; }
public string BasePrice { get; set; }
public string VAT { get; set; }
public string Price { get; set; }
public string Summary_PriceWithoutVAT { get; set; }
public string Summary_VAT { get; set; }
public string Summary_Price { get; set; }
public string Reason_Code { get; set; }
public string Reason_Description { get; set; }
public string Reason_Quantity { get; set; }
public string Reason_UnitMeasurement { get; set; }
public string Reason_Amount { get; set; }
public class ED_Table_012
public ED_Table_012(XElement Row)
PositionNumber = Row.Element("НомПоз").Value;
BarcodeID = Row.Element("Штрихкод").Value;
BuyerArticle = Row.Element("АртикулПокупця").Value;
Name = Row.Element("Найменування").Value;
UnitMeasurement = Row.Element("ОдиницяВиміру").Value;
BasePrice = Row.Element("БазоваЦіна").Value;
VAT = Row.Element("ПДВ").Value;
Price = Row.Element("Ціна").Value;
Summary_PriceWithoutVAT = Row.Element("ВсьогоПоРядку").Element("СумаБезПДВ").Value;
Summary_VAT = Row.Element("ВсьогоПоРядку").Element("СумаПДВ").Value;
Summary_Price = Row.Element("ВсьогоПоРядку").Element("Сума").Value;
public string ED_ID { get; set; }
public string PositionNumber { get; set; }
public string BarcodeID { get; set; }
public string BuyerArticle { get; set; }
public string Name { get; set; }
public string UnitMeasurement { get; set; }
public string BasePrice { get; set; }
public string VAT { get; set; }
public string Price { get; set; }
public string Summary_PriceWithoutVAT { get; set; }
public string Summary_VAT { get; set; }
public string Summary_Price { get; set; }
public string Reurtn_Quantity { get; set; }