using ITnet2.Server.BusinessLogic.Core.Documents;
using ITnet2.Server.BusinessLogic.Core.Documents.DataLayer;
using ITnet2.Server.Data;
using ITnet2.Server.Runtime.Methods;
using System.Collections.Generic;
using ITnet2.Server.Session;
using ITnet2.Common.Tools;
using System.Xml.Serialization;
public class RrtMethodLogic : UserRequestMethodBusinessLogic
private const string KOBJDB = "00001";
private const int ORG2 = 1;
private const string kdmt = "TMSAPP";
public override void Call()
private static string importDirectory = @"C:\Users\boev\Downloads\";
private static string importFileName = "Z-0000680748.xml";
public void ImportXmlFiles()
XmlDocument doc = new XmlDocument();
var file = OSDialogs.OpenFile(new OpenFileOptions
Filter = new DialogFilterCollection("XML") { AllFilesFilter = false },
Title = "Файл шаблону імпорту даних"
var tempServerDir = Path.Combine(Settings.Environment.VfpServerDir, Text.GetRandomString() + ".xml");
var tempklient = file.ClientPath;
FileManager.LoadFile(tempklient, tempServerDir);
var mappedModel = MapXmlToModel(tempServerDir);
public static OrderHeadUpload MapXmlToModel(string tempServerDir)
XmlDocument doc = new XmlDocument();
XmlSerializer deserializer = new XmlSerializer(typeof(OrderHeadUpload));
TextReader textReader = new StreamReader(tempServerDir);
var mappedResult = (OrderHeadUpload)deserializer.Deserialize(textReader);
private int FindOrgByClientId(int oldorg)
return SqlClient.Main.CreateCommand("select ORG from ORG where OLDORG = CONVERT(NVARCHAR,@id)", new SqlParam("id", oldorg)).ExecScalar<int>();
private int FindDepartment(int departmentId, bool findSender = true)
return SqlClient.Main.CreateCommand("select CEH from POD where ZEX = @id", new SqlParam("id", departmentId)).ExecScalar<int>();
return SqlClient.Main.CreateCommand("select CEH from POD where ZEX = @id", new SqlParam("id", departmentId)).ExecScalar<int>();
private int Currency(int Undog)
return SqlClient.Main.CreateCommand("select KVAL from DOG where UNDOG = @id", new SqlParam("id", Undog)).ExecScalar<int>();
public void CreateDocs(OrderHeadUpload item)
var headerRepository = new HeadersRepository();
SelfSideContractorCode = ORG2
doc.Number = item.Number_1C;
doc.AdditionalNumber = item.Number_confirm_1C;
doc.SetValue("NDM_Z", item.Number_order_client);
doc.Comment = item.Doc_name;
doc.Comment2 = item.Comment;
doc.ExtractDate = item.Upload_date;
doc.Date = item.Order_date;
doc.ContractorCode = FindOrgByClientId(item.Client_id);
doc.DepartSender = FindDepartment(item.Wrh_id);
doc.DepartRecipient = FindDepartment(item.Transit_wrh_id, false);
doc.Sign1 = item.Delivery_type;
doc.Sign2 = item.Route_id;
doc.SetValue("D_SHIP", item.Shipment_date);
doc.SetValue("D_DELIV", item.Delivery_date);
doc.SetValue("POINT_ID", item.Point_id);
doc.SetValue("POINT_NO", item.Point_no);
doc.SetValue("GLN", item.Point_GLN);
doc.SetValue("DATE_FROM_", item.Arrival_time_from);
doc.SetValue("DATE_TO_", item.Arrival_time_to);
var positions = new List<Positions>();
foreach (var pos in positions)
headerRepository.Add(doc);
#region Модель сущности считываемой с XML
[XmlRoot(ElementName = "OrderHeadUpload", Namespace = "http://www.sample-package.org")]
public class OrderHeadUpload
[XmlElement(ElementName = "Client_id", Namespace = "http://www.sample-package.org")]
public int Client_id { get; set; }
[XmlElement(ElementName = "Comment", Namespace = "http://www.sample-package.org")]
public string Comment { get; set; }
[XmlElement(ElementName = "Delivery_date", Namespace = "http://www.sample-package.org")]
public DateTime Delivery_date { get; set; }
[XmlElement(ElementName = "Delivery_type", Namespace = "http://www.sample-package.org")]
public string Delivery_type { get; set; }
[XmlElement(ElementName = "Doc_name", Namespace = "http://www.sample-package.org")]
public string Doc_name { get; set; }
[XmlElement(ElementName = "Dog_id", Namespace = "http://www.sample-package.org")]
public int Dog_id { get; set; }
[XmlElement(ElementName = "Number_1C", Namespace = "http://www.sample-package.org")]
public string Number_1C { get; set; }
[XmlElement(ElementName = "Number_confirm_1C", Namespace = "http://www.sample-package.org")]
public string Number_confirm_1C { get; set; }
[XmlElement(ElementName = "Number_order_client", Namespace = "http://www.sample-package.org")]
public int Number_order_client { get; set; }
[XmlElement(ElementName = "Order_date", Namespace = "http://www.sample-package.org")]
public DateTime Order_date { get; set; }
[XmlElement(ElementName = "Point_GLN", Namespace = "http://www.sample-package.org")]
public string Point_GLN { get; set; }
[XmlElement(ElementName = "Point_id", Namespace = "http://www.sample-package.org")]
public int Point_id { get; set; }
[XmlElement(ElementName = "Point_no", Namespace = "http://www.sample-package.org")]
public string Point_no { get; set; }
[XmlElement(ElementName = "Positions", Namespace = "http://www.sample-package.org")]
public List<Positions> Positions { get; set; }
[XmlElement(ElementName = "Route_id", Namespace = "http://www.sample-package.org")]
public string Route_id { get; set; }
[XmlElement(ElementName = "Arrival_time_from", Namespace = "http://www.sample-package.org")]
public DateTime Arrival_time_from { get; set; }
[XmlElement(ElementName = "Arrival_time_to", Namespace = "http://www.sample-package.org")]
public DateTime Arrival_time_to { get; set; }
[XmlElement(ElementName = "Shipment_date", Namespace = "http://www.sample-package.org")]
public DateTime Shipment_date { get; set; }
[XmlElement(ElementName = "Transit_wrh_id", Namespace = "http://www.sample-package.org")]
public int Transit_wrh_id { get; set; }
[XmlElement(ElementName = "Upload_date", Namespace = "http://www.sample-package.org")]
public DateTime Upload_date { get; set; }
[XmlElement(ElementName = "Wrh_id", Namespace = "http://www.sample-package.org")]
public int Wrh_id { get; set; }
[XmlAttribute(AttributeName = "xmlns")]
public string Xmlns { get; set; }
[XmlAttribute(AttributeName = "xs", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xs { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlRoot(ElementName = "Positions", Namespace = "http://www.sample-package.org")]
[XmlElement(ElementName = "Barcode_id", Namespace = "http://www.sample-package.org")]
public string Barcode_id { get; set; }
[XmlElement(ElementName = "Count", Namespace = "http://www.sample-package.org")]
public string Count { get; set; }
[XmlElement(ElementName = "Count_pack", Namespace = "http://www.sample-package.org")]
public string Count_pack { get; set; }
[XmlElement(ElementName = "Count_pce", Namespace = "http://www.sample-package.org")]
public string Count_pce { get; set; }
[XmlElement(ElementName = "Number_in_order", Namespace = "http://www.sample-package.org")]
public string Number_in_order { get; set; }
[XmlElement(ElementName = "Product_art", Namespace = "http://www.sample-package.org")]
public string Product_art { get; set; }
[XmlElement(ElementName = "Product_date", Namespace = "http://www.sample-package.org")]
public string Product_date { get; set; }
[XmlElement(ElementName = "Product_id", Namespace = "http://www.sample-package.org")]
public string Product_id { get; set; }
[XmlElement(ElementName = "Tare_id", Namespace = "http://www.sample-package.org")]
public string Tare_id { get; set; }
[XmlElement(ElementName = "Tare_type", Namespace = "http://www.sample-package.org")]
public string Tare_type { get; set; }