/// <summary> /// Получить обновленный документ /// </summary> /// <param name="num_doc"></param> /// <returns></returns> public UZ_DOC GetDocumentOfDB_NumDoc(string num_doc) { try { UZ_Convert convert = new UZ_Convert(this.servece_owner); UZ_DOC doc = null; EFUZ_Data ef_data = new EFUZ_Data(new EFSMSDbContext()); UZ_Data uzd = ef_data.Context.Where(d => d.doc_Id == num_doc).FirstOrDefault(); if (uzd != null) { string xml_final = convert.XMLToFinalXML(uzd.raw_xml); OTPR otpr = convert.FinalXMLToOTPR(xml_final); // Документ найден doc = new UZ_DOC(); doc.id_doc = uzd.doc_Id; doc.revision = uzd.doc_Revision; doc.status = GetStatus(uzd.doc_Status); doc.sender_code = uzd.depart_code; doc.recipient_code = uzd.arrived_code; doc.dt = uzd.dt; doc.xml = uzd.raw_xml; doc.xml_final = xml_final; doc.otpr = otpr; } return(doc); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetDocumentOfDB_NumDoc(num_doc={0})", num_doc), this.servece_owner, eventID); return(null); } }
/// <summary> /// Получить UZ_DOC документ из UZ_Data (Промежуточной базы) /// </summary> /// <param name="uz_doc"></param> /// <returns></returns> public UZ_DOC Convert_UZ_Data_To_UZ_DOC(UZ_Data uz_doc) { try { UZ_Convert convert = new UZ_Convert(this.servece_owner); string xml_final = convert.XMLToFinalXML(uz_doc.raw_xml); OTPR otpr = convert.FinalXMLToOTPR(xml_final); // Документ найден UZ_DOC doc = new UZ_DOC() { id_doc = uz_doc.doc_Id, revision = uz_doc.doc_Revision, status = GetStatus(uz_doc.doc_Status), sender_code = uz_doc.depart_code, recipient_code = uz_doc.arrived_code, dt = uz_doc.dt, xml = uz_doc.raw_xml, xml_final = xml_final, otpr = otpr, }; return(doc); } catch (Exception e) { e.ExceptionMethodLog(String.Format("Convert_UZ_Data_To_UZ_DOC(doc={0})", uz_doc), this.servece_owner, eventID); return(null); } }
/// <summary> /// Получить XML перевозочного документа из промежуточной базой KRR-PA-VIZ-Other_DATA по номеру вагона отправленыйх по перечню кодов грузоотправителей начиная с указаной даты, со статусом Accepted /// </summary> /// <param name="num"></param> /// <param name="shipper"></param> /// <param name="start_date"></param> /// <returns></returns> public UZ_DOC GetDocumentOfDB_NumShipper(int num, int[] shipper, DateTime?start_date) { try { UZ_Convert convert = new UZ_Convert(this.servece_owner); UZ_DOC doc = null; EFUZ_Data ef_data = new EFUZ_Data(new EFSMSDbContext()); DateTime new_dt = ((DateTime)start_date).AddHours(0); string sql = @"SELECT * FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_Data] " + "where [doc_Id] in (SELECT [nom_doc] FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_VagonData] where [nomer] = " + num.ToString() + ") and [depart_code] in (0," + IntsToString(shipper, ',') + ",'none') and [doc_Status] in (N'Accepted', N'Delivered', N'Recieved', N'Uncredited') and update_dt >= convert(datetime,'" + new_dt.ToString("yyyy-MM-dd HH:mm:ss") + "',120)" + //" and CONVERT(nvarchar(max), raw_xml) like(N'%" + num.ToString() + "%') " + " order by [dt]"; //UZ_Data uzd = ef_data.Database.SqlQuery<UZ_Data>(sql).FirstOrDefault(); List <UZ_Data> list_uzd = ef_data.Database.SqlQuery <UZ_Data>(sql).ToList(); foreach (UZ_Data uzd in list_uzd) { if (uzd != null) { string xml_final = convert.XMLToFinalXML(uzd.raw_xml); OTPR otpr = convert.FinalXMLToOTPR(xml_final); if (otpr != null && otpr.vagon != null && otpr.vagon.Count() > 0) { // Проверим вагон пренадлежит документу UZ.VAGON vagon = otpr.vagon.ToList().Find(v => v.nomer == num.ToString()); if (vagon != null) { // Документ найден doc = new UZ_DOC(); doc.id_doc = uzd.doc_Id; doc.revision = uzd.doc_Revision; doc.status = GetStatus(uzd.doc_Status); doc.sender_code = uzd.depart_code; doc.recipient_code = uzd.arrived_code; doc.dt = uzd.dt; doc.xml = uzd.raw_xml; doc.xml_final = xml_final; doc.otpr = otpr; break; } else { } } } } return(doc); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetDocumentOfDB_NumShipper(num={0}, shipper={1}, start_date={2})", num, shipper, start_date), this.servece_owner, eventID); return(null); } }
/// <summary> /// Получить документы по вагону по указаным грузополучателям за указаный интервал /// </summary> /// <param name="num"></param> /// <param name="consignees"></param> /// <param name="days"></param> /// <returns></returns> public List <UZ_DOC> GetDocumentOfDB_NumConsignees(int num, int[] consignees, int days) { try { EFUZ_Data ef_data = new EFUZ_Data(new EFSMSDbContext()); string sql = "SELECT * FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_Data] " + "where [doc_Id] in (SELECT [nom_doc] FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_VagonData] where [nomer] = " + num.ToString() + ") and [arrived_code] in (0," + IntsToString(consignees, ',') + ",'none') order by[dt] desc"; List <UZ_Data> list_uz_data = ef_data.Database.SqlQuery <UZ_Data>(sql).ToList(); // Выберем все документы за указаный период List <UZ_DOC> result = new List <UZ_DOC>(); DateTime start = DateTime.Now.AddDays(-1 * days); foreach (UZ_Data uz_doc in list_uz_data) { if (uz_doc.update_dt != null) { if (uz_doc.update_dt >= start) { UZ_DOC doc = Convert_UZ_Data_To_UZ_DOC(uz_doc); if (doc != null) { result.Add(doc); } } } else { if (uz_doc.dt >= start) { UZ_DOC doc = Convert_UZ_Data_To_UZ_DOC(uz_doc); if (doc != null) { result.Add(doc); } } } } return(result); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetDocumentOfDB_NumConsignees(num={0}, consignees={1}, days={2})", num, consignees, days), this.servece_owner, eventID); return(null); } }
/// <summary> /// Получитм документ УЗ по номеру документа /// </summary> /// <param name="DocumentNumber"></param> /// <returns></returns> public List <UZ_DOC> GetUZ_DOC_Of_NumDoc(string DocumentNumber) { try { List <UZ_DOC> list = new List <UZ_DOC>(); List <GohubDocument> docs = GetEPD_UZ_Of_NumDoc(DocumentNumber); if (docs == null) { return(null); } foreach (GohubDocument doc in docs) { UZ_Convert convert = new UZ_Convert(this.servece_owner); string xml_final = convert.XMLToFinalXML(doc.GetXmlText()); OTPR otpr = convert.FinalXMLToOTPR(xml_final); string sender_code = null; string recipient_code = null; if (otpr != null && otpr.client.Count() == 2) { sender_code = otpr.client[0].kod; recipient_code = otpr.client[1].kod; } UZ_DOC uz_doc = new UZ_DOC() { id_doc = doc.Id, revision = doc.Revision, status = GetStatus(doc.Status.ToString()), sender_code = sender_code, recipient_code = recipient_code, //dt = doc.TimeStamp, xml = doc.GetXmlText(), xml_final = xml_final, otpr = otpr }; list.Add(uz_doc); } return(list); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetUZ_DOC_Of_NumDoc(DocumentNumber={0})", DocumentNumber), servece_owner, eventID); return(null); } }
/// <summary> /// Получить XML перевозочного документа из промежуточной базой KRR-PA-VIZ-Other_DATA по номеру вагона /// </summary> /// <param name="num"></param> /// <returns></returns> public UZ_DOC GetDocumentOfDB_Num(int num) { try { UZ_DOC doc = null; EFUZ_VagonData ef_vagon = new EFUZ_VagonData(new EFSMSDbContext()); EFUZ_Data ef_data = new EFUZ_Data(new EFSMSDbContext()); UZ_VagonData vagon = ef_vagon.Context.Where(v => v.nomer == num.ToString()).OrderByDescending(c => c.dt).FirstOrDefault(); if (vagon != null) { // вагон найден. найдем документ UZ_Data data = ef_data.Context.Where(d => d.doc_Id == vagon.nom_doc).FirstOrDefault(); if (data != null) { UZ_Convert convert = new UZ_Convert(this.servece_owner); string xml_final = convert.XMLToFinalXML(data.raw_xml); OTPR otpr = convert.FinalXMLToOTPR(xml_final); // Документ найден doc = new UZ_DOC(); doc.id_doc = data.doc_Id; doc.revision = data.doc_Revision; doc.status = GetStatus(data.doc_Status); doc.sender_code = data.depart_code; doc.recipient_code = data.arrived_code; doc.dt = data.dt; doc.xml = data.raw_xml; doc.xml_final = xml_final; doc.otpr = otpr; } } return(doc); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetDocumentOfDB_Num(num={0})", num), this.servece_owner, eventID); return(null); } }
/// <summary> /// Получить XML перевозочного документа из промежуточной базой KRR-PA-VIZ-Other_DATA по номеру вагона отправленый в адрес перечня (кодов грузополучателей 7932, 6302, 659) на перечень станций УЗ Кривого Рога /// </summary> /// <param name="num"></param> /// <param name="consignees"></param> /// <param name="stations"></param> /// <param name="dt_arrival"></param> /// <returns></returns> public UZ_DOC GetDocumentOfDB_NumConsigneesStations(int num, int[] consignees, int[] stations, DateTime?dt_arrival) { try { UZ_DOC doc = null; EFUZ_Data ef_data = new EFUZ_Data(new EFSMSDbContext()); string sql = "SELECT * FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_Data] " + "where [doc_Id] in (SELECT [nom_doc] FROM [KRR-PA-VIZ-Other_DATA].[dbo].[UZ_VagonData] where [nomer] = " + num.ToString() + ") and [arrived_code] in (0," + IntsToString(consignees, ',') + ",'none') order by[dt] desc"; List <UZ_Data> list_uz_data = ef_data.Database.SqlQuery <UZ_Data>(sql).ToList(); if (list_uz_data != null && list_uz_data.Count() > 0) { UZ_Convert convert = new UZ_Convert(this.servece_owner); foreach (UZ_Data uzd in list_uz_data) { DateTime new_dt = ((DateTime)dt_arrival).AddHours(-36); int period = -36; //!!! Проверка на старый документ на 36 часов годен затем только вручную //if ((dt_arrival != null && uzd.update_dt != null && ((DateTime)dt_arrival).AddHours(period) <= uzd.update_dt) || (dt_arrival != null && uzd.update_dt == null && uzd.dt != null && ((DateTime)dt_arrival).AddHours(period) <= uzd.dt)) string xml_final = convert.XMLToFinalXML(uzd.raw_xml); OTPR otpr = convert.FinalXMLToOTPR(xml_final); DateTime?end_date = otpr != null ? otpr.srok_end : null; if ((dt_arrival != null && end_date != null && dt_arrival <= end_date) || (dt_arrival != null && uzd.update_dt != null && ((DateTime)dt_arrival).AddHours(period) <= uzd.update_dt) || (dt_arrival != null && uzd.update_dt == null && uzd.dt != null && ((DateTime)dt_arrival).AddHours(period) <= uzd.dt)) { // Проверим есть вагон в этом документе if (otpr != null && otpr.vagon != null && otpr.vagon.Count() > 0) { int searsh_vag = otpr.vagon.Where(v => v.nomer == num.ToString()).Count(); if (searsh_vag > 0 && otpr != null && otpr.route != null && otpr.route.Count() > 0) { if (!String.IsNullOrWhiteSpace(otpr.route[0].stn_to)) { int res = (stations != null && stations.Count() > 0 ? stations.Where(s => s.ToString() == otpr.route[0].stn_to.ToString()).Count() : 0); if (res > 0) { // Документ найден doc = new UZ_DOC(); doc.id_doc = uzd.doc_Id; doc.revision = uzd.doc_Revision; doc.status = GetStatus(uzd.doc_Status); doc.sender_code = uzd.depart_code; doc.recipient_code = uzd.arrived_code; doc.dt = uzd.dt; doc.xml = uzd.raw_xml; doc.xml_final = xml_final; doc.otpr = otpr; break; } } } } } } } return(doc); } catch (Exception e) { e.ExceptionMethodLog(String.Format("GetDocumentOfDB_NumConsigneesStations(num={0}, consignees={1}, stations={2}, dt_arrival={3})", num, consignees, stations, dt_arrival), this.servece_owner, eventID); return(null); } }