public void TestWrapper() { XmlDocument doc = new XmlDocument(); XmlWrapper wrapper = new XmlWrapper(doc); Assert.AreEqual(doc, wrapper.XmlDocument); }
public void GetBestMatch_MatchOnHarmonicKey_Test() { // Arrange IXmlWrapper xmlWrapper1 = new XmlWrapper(); ITempoRange tempoRange1 = new TempoRange(); IHarmonicKeyRange harmonicKeyRange1 = new HarmonicKeyRange(); IIntensityRange intensityRange1 = new IntensityRange(); ISong song1 = new Song(xmlWrapper1, tempoRange1, harmonicKeyRange1, intensityRange1) { Artist = "Song 1", PlayTime = 100, TrailingTempo = 128.000, TrailingHarmonicKey = "8A" }; IXmlWrapper xmlWrapper2 = new XmlWrapper(); ITempoRange tempoRange2 = new TempoRange(); tempoRange2.Load(128, 3); IHarmonicKeyRange harmonicKeyRange2 = new HarmonicKeyRange(); harmonicKeyRange2.Load("8A"); IIntensityRange intensityRange2 = new IntensityRange(); ISong song2 = new Song(xmlWrapper2, tempoRange2, harmonicKeyRange2, intensityRange2) { Artist = "Song 2", PlayTime = 100 }; var baseTrackList = new List <ISong> { song1 }; var playlistTracks = new List <ISong> { song2 }; var intensityStyle = "Random"; var minPlaytime = 200; var mixLength = 0; IMixDisc mixDisc = new MixDisc { BaseTrackList = baseTrackList, PlaylistTracks = playlistTracks, IntensityStyle = intensityStyle, MinPlaytime = minPlaytime, MixLength = mixLength }; // Act var result = mixDisc.GetBestMatch(); // Assert Assert.IsTrue(result.Count == 2); }
/// <summary> /// LES-WMS-005 入库数据 WL004 // <param name="logFid"></param> public static ExecuteResultConstants SendInboundOrder (Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; List <WmsTranOutInfo> vmiInboundOrderInfos = new WmsTranOutBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (vmiInboundOrderInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///发送内容 List <BFDAVmiInboundDataInfo> bFDAVmiInboundDataInfos = new List <BFDAVmiInboundDataInfo>(); foreach (var VmiInboundDataInfo in vmiInboundOrderInfos) { bFDAVmiInboundDataInfos.Add(GetBFDAVMIInfo(VmiInboundDataInfo)); } BFDAVMISendDataInfo <BFDAVmiInboundDataInfo> sendDataInfo = new BFDAVMISendDataInfo <BFDAVmiInboundDataInfo>(); sendDataInfo.List = bFDAVmiInboundDataInfos; /// WsProcessServiceClient client = new WsProcessServiceClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); ///1标识成功、0标识失败 long tenantId = 89; if (!long.TryParse(interfaceConfigInfo.Param2, out tenantId)) { errorCode = "MC:3x00000021";///接口配置错误 return(ExecuteResultConstants.Exception); } ///数据发送 msgContent = new XmlWrapper().ObjectToXml(sendDataInfo, false); Log.WriteLogToFile(msgContent, AppDomain.CurrentDomain.BaseDirectory + @"\logContent\", DateTime.Now.ToString("yyyyMMddHHmm") + interfaceConfigInfo.SysMethodName); string result = client.runProcessWithAction(interfaceConfigInfo.Param1, tenantId, interfaceConfigInfo.SysMethodName, msgContent); BFDAVMIResultInfo resultInfo = new XmlWrapper(result, LoadType.FromString).XmlToObject("/Result", typeof(BFDAVMIResultInfo)) as BFDAVMIResultInfo; // throw new Exception(resultInfo.Status); TDD: delete ///成功后更新中间表数据处理状态 if (resultInfo.Status.ToLower() == "error") { errorCode = resultInfo.ErrorCode; errorMsg = resultInfo.ErrorMsg; return(ExecuteResultConstants.Error); } Log.WriteLogToFile("END: " + ExecuteResultConstants.Success, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHHmm")); return(ExecuteResultConstants.Success); }
/// <summary> /// 转换为中间集合 /// </summary> /// <param name="sapProductOrderBomInfos"></param> /// <returns></returns> public List <SapProductOrderBomInfo> ConversionToCentreList(List <BFDASapProductOrderBomInfo> sapProductOrderBomInfos) { ///订单BOM List <SapProductOrderBomInfo> productOrderBomInfos = new List <SapProductOrderBomInfo>(); foreach (BFDASapProductOrderBomInfo sapProductOrderBomInfo in sapProductOrderBomInfos) { SapProductOrderBomInfo productOrderBomInfo = ConversionToCentreInfo(sapProductOrderBomInfo); productOrderBomInfos.Add(productOrderBomInfo); } var qProductOrderBomInfos = from u in productOrderBomInfos orderby u.Aufnr group u by new { u.Fmatnr, u.Dwerk, u.Aufnr, u.Verid, u.OnlineDate, u.OfflineDate, u.Zzdd } into g select new { g.Key }; List <SapProductOrderBomInfo> list = new List <SapProductOrderBomInfo>(); foreach (var qProductOrderBomInfo in qProductOrderBomInfos) { ///接口单车物料清单临时集合 List <SapProductOrderBomInfo> orderBomInfos = productOrderBomInfos.Where(d => d.Fmatnr == qProductOrderBomInfo.Key.Fmatnr && d.Dwerk == qProductOrderBomInfo.Key.Dwerk && d.Aufnr == qProductOrderBomInfo.Key.Aufnr && d.Verid == qProductOrderBomInfo.Key.Verid && d.Zzdd == qProductOrderBomInfo.Key.Zzdd && d.OnlineDate == qProductOrderBomInfo.Key.OnlineDate && d.OfflineDate == qProductOrderBomInfo.Key.OfflineDate).ToList(); List <BFDASapProductOrderBomMatnrdInfo> sapProductOrderBomMatnrdInfos = new List <BFDASapProductOrderBomMatnrdInfo>(); foreach (var orderBomInfo in orderBomInfos) { sapProductOrderBomMatnrdInfos.Add(ConversionToCentreDetailInfo(orderBomInfo)); } BFDASapProductOrderBomMatnrsInfo matnrsInfo = new BFDASapProductOrderBomMatnrsInfo(); matnrsInfo.MatnrsAll = sapProductOrderBomMatnrdInfos; string matnrs = new XmlWrapper().ObjectToXmlByEncoding(matnrsInfo, Encoding.UTF8, false); matnrs = matnrs.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); matnrs = matnrs.Replace("\r\n", "").Trim(); matnrs = matnrs.Replace(" ", "").Trim(); /// SapProductOrderBomInfo info = new SapProductOrderBomInfo(); info.Fmatnr = qProductOrderBomInfo.Key.Fmatnr; info.Dwerk = qProductOrderBomInfo.Key.Dwerk; info.Aufnr = qProductOrderBomInfo.Key.Aufnr; info.Verid = qProductOrderBomInfo.Key.Verid; info.Zzdd = qProductOrderBomInfo.Key.Zzdd; info.OnlineDate = qProductOrderBomInfo.Key.OnlineDate; info.OfflineDate = qProductOrderBomInfo.Key.OfflineDate; info.Matnrs = matnrs; list.Add(info); } return(list); }
public void GetBestMatch_SongAlreadyInMixableTrackCombination_Test() { // Arrange IXmlWrapper xmlWrapper1 = new XmlWrapper(); ITempoRange tempoRange1 = new TempoRange(); IHarmonicKeyRange harmonicKeyRange1 = new HarmonicKeyRange(); IIntensityRange intensityRange1 = new IntensityRange(); ISong song1 = new Song(xmlWrapper1, tempoRange1, harmonicKeyRange1, intensityRange1) { Artist = "Song 1", PlayTime = 100 }; IXmlWrapper xmlWrapper2 = new XmlWrapper(); ITempoRange tempoRange2 = new TempoRange(); IHarmonicKeyRange harmonicKeyRange2 = new HarmonicKeyRange(); IIntensityRange intensityRange2 = new IntensityRange(); ISong song2 = new Song(xmlWrapper2, tempoRange2, harmonicKeyRange2, intensityRange2) { Artist = "Song 2", PlayTime = 100 }; var baseTrackList = new List <ISong> { song2, song1 }; var playlistTracks = new List <ISong> { song2 }; var intensityStyle = "Random"; var minPlaytime = 300; var mixLength = 0; IMixDisc mixDisc = new MixDisc { BaseTrackList = baseTrackList, PlaylistTracks = playlistTracks, IntensityStyle = intensityStyle, MinPlaytime = minPlaytime, MixLength = mixLength }; // Act var result = mixDisc.GetBestMatch(); // Assert Assert.IsTrue(result.Count == 0); }
/// <summary> /// LES-SRM-004 排序拉动单 // <param name="logFid"></param> public static ExecuteResultConstants SendJisPullOrder(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; List <WmsVmiJisPullOrderInfo> vmiJisPullOrderInfos = new WmsVmiJisPullOrderBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (vmiJisPullOrderInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///发送内容 List <BFDAVmiJisPullOrderInfo> inboundOrderInfos = new List <BFDAVmiJisPullOrderInfo>(); foreach (var vmiJisPullOrderInfo in vmiJisPullOrderInfos) { inboundOrderInfos.Add(GetBFDAInfo(vmiJisPullOrderInfo)); } BFDAVMISendDataInfo <BFDAVmiJisPullOrderInfo> sendDataInfo = new BFDAVMISendDataInfo <BFDAVmiJisPullOrderInfo>(); sendDataInfo.List = inboundOrderInfos; WsProcessServiceClient client = new WsProcessServiceClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); ///1标识成功、0标识失败 long tenantId = 89; if (!long.TryParse(interfaceConfigInfo.Param2, out tenantId)) { errorCode = "MC:3x00000021";///接口配置错误 return(ExecuteResultConstants.Exception); } ///数据发送 msgContent = new XmlWrapper().ObjectToXml(sendDataInfo, false); string result = client.runProcessWithAction(interfaceConfigInfo.Param1, tenantId, interfaceConfigInfo.SysMethodName, msgContent); BFDAVMIResultInfo resultInfo = new XmlWrapper(result, LoadType.FromString).XmlToObject("/Result", typeof(BFDAVMIResultInfo)) as BFDAVMIResultInfo; ///成功后更新中间表数据处理状态 if (resultInfo.Status.ToLower() == "error") { errorCode = resultInfo.ErrorCode; errorMsg = resultInfo.ErrorMsg; return(ExecuteResultConstants.Error); } return(ExecuteResultConstants.Success); }
public InterfaceReturnInfo GetVmiPackageOutbound(List <BFDAApplianceOutputInfo> list) { /////接口代码 string interfaceCode = "WMS-LES-016"; ///回传文本 InterfaceReturnInfo retInfo = new InterfaceReturnInfo(); try { ///转报文 string msgContent = new XmlWrapper().ObjectToXml(list); ///获取传值内容,写在本地txt文本中 Log.WriteLogToFile("|WMS-LES-016 VMI.WMS.VMI器具出库 日志记录| \r\n" + msgContent.ToString() + "\r\n|Count|" + list.Count.ToString().Length + "; End|", AppDomain.CurrentDomain.BaseDirectory + @"\Log\", DateTime.Now.ToString("yyyyMMddHHmm")); /// //string keyValue = bll.GetKeyValues(list); /// ///分布式事务 执行写入数据库操作. using (TransactionScope tran = new TransactionScope()) { ///LOG日志 // string logSql = BLL.LES.CommonBLL.GetCreateInboundLogSql("SRM",, logFid, interfaceCode, keyValue, msgContent, string.Empty, string.Empty, loginUser, executeStartTime); ///添加到中间表 //dataCnt = bll.InsertListToCentreTable(list, logFid, logSql); tran.Complete(); } ///1成功、0失败 retInfo.ExecuteResult = (int)ResultsDescribed.Succeed; ///错误编码 retInfo.ErrorCode = string.Empty; ///描述信息 string successCode = "1x00000051";///传输成功 retInfo.MessageContent = GetMessage(ref successCode); } catch (Exception ex) { Log.WriteLogToFile(interfaceCode + "|" + retInfo.MessageContent + "|" + retInfo.ErrorCode, AppDomain.CurrentDomain.BaseDirectory + @"\ERROR\", DateTime.Now.ToString("yyyyMMdd")); ///1成功、0失败 retInfo.ExecuteResult = (int)ResultsDescribed.Failure;; /// string errorCode = ex.Message; ///错误消息 retInfo.MessageContent = GetMessage(ref errorCode); ///错误代码 retInfo.ErrorCode = errorCode; } return(retInfo); }
/// <summary> /// LES-MES-005 断点替换信息 /// </summary> /// <param name="logFid"></param> public static ExecuteResultConstants SendQmisAsnPullSheet(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; InterfaceReturnInfo interfaceReturnInfo = new InterfaceReturnInfo(); Log.WriteLogToFile("The logFid|" + logFid, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHHmm")); List <MesBreakpointReplacementRecordInfo> qmiInfos = new MesBreakpointReplacementRecordBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (qmiInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ReplacementRecord[] replacementRecord = new ReplacementRecord[qmiInfos.Count]; for (int i = 0; i < qmiInfos.Count; i++) { ReplacementRecord replacement = new ReplacementRecord(); replacement.ORDERNO = qmiInfos[i].Orderno; replacement.OLDPARTNO = qmiInfos[i].Oldpartno; replacement.NEWPARTNO = qmiInfos[i].Newpartno; replacement.OLDSUPPLIER = qmiInfos[i].Oldsupplier; replacement.NEWSUPPLIER = qmiInfos[i].Newsupplier; replacement.OLDSTATION = qmiInfos[i].Oldstation; replacement.NEWSTATION = qmiInfos[i].Newstation; replacement.OLDQTY = qmiInfos[i].Oldqty.GetValueOrDefault(); replacement.NEWQTY = qmiInfos[i].Newqty.GetValueOrDefault(); replacement.REPLACETIME = qmiInfos[i].Replacetime.GetValueOrDefault(); replacementRecord[i] = replacement; } ///发送内容 msgContent = new XmlWrapper().ObjectToXml(replacementRecord, false); LESMESlocal.LESWebServiceSoapClient client = new LESWebServiceSoapClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); InterfaceCallbackInfo backinfo = client.GetReplacementRecord(replacementRecord); Log.WriteLogToFile("返回结果:errorCode:" + errorCode + "; msgContent:" + errorMsg, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHHmm")); if (backinfo.RESULT == 0) { errorCode = backinfo.MSGNO; errorMsg = backinfo.MSG; return(ExecuteResultConstants.Error); } return(ExecuteResultConstants.Success); }
/// <summary> /// LES-MES-002 缺件影响订单 /// </summary> /// <param name="logFid"></param> public static ExecuteResultConstants SendQmisAsnPullSheet(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; Log.WriteLogToFile("The logFid|" + logFid, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHHmm")); List <MesMissingpartsInfluenceOrderscopeInfo> mesinfo = new MesMissingpartsInfluenceOrderscopeBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (mesinfo.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } AssemblePlanMissDetail[] missDetails = new AssemblePlanMissDetail[mesinfo.Count]; for (int i = 0; i < mesinfo.Count; i++) { AssemblePlanMissDetail missDetail = new AssemblePlanMissDetail(); missDetail.ENTERPRISE = mesinfo[i].Enterprise; ///nvarchar(8) Checked missDetail.SITE_NO = mesinfo[i].SiteNo; ///nvarchar(8) Checked missDetail.AREA_NO = mesinfo[i].AreaNo; ///nvarchar(8) Checked missDetail.DMS_NO = mesinfo[i].DmsNo; ///nvarchar(32) Checked missDetail.MATERIAL_CHECK = mesinfo[i].MaterialCheck.GetValueOrDefault() == true?1 : 0; ///bit Checked missDetail.SEND_TIME = mesinfo[i].SendTime.GetValueOrDefault(); ///datetime Checked missDetails[i] = missDetail; } // ///发送内容 msgContent = new XmlWrapper().ObjectToXml(missDetails, false); LESMESlocal.LESWebServiceSoapClient client = new LESWebServiceSoapClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); InterfaceCallbackInfo backinfo = client.GetAssemblePlanMissDetail(missDetails); ///记录结果 Log.WriteLogToFile("返回结果:errorCode:" + errorCode + "; msgContent:" + errorMsg, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHHmm")); if (backinfo.RESULT == 0) { errorCode = backinfo.MSGNO; errorMsg = backinfo.MSG; return(ExecuteResultConstants.Error); } return(ExecuteResultConstants.Success); }
/// <summary> /// LES-QMIS-002-ASN单据下发接口 /// </summary> /// <param name="logFid"></param> public static ExecuteResultConstants SendQmisAsnPullSheet(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; List <QmisAsnPullSheetInfo> qmiInfos = new QmisAsnPullSheetBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (qmiInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///转换成中间表 List <BdAsnInfo> bdAsnInfos = new List <BdAsnInfo>(); foreach (var qmiInfo in qmiInfos) { bdAsnInfos.Add(GetBdAsnInfo(qmiInfo)); } msgContent = new XmlWrapper().ObjectToXml(bdAsnInfos, false); ///接口调用 /// try { using (ILesToQmisService lesToQmisService = new BFDAQMISAsnPull.ILesToQmisService()) { lesToQmisService.Url = interfaceConfigInfo.CallUrl; lesToQmisService.AuthenticationToken = new AuthenticationToken(interfaceConfigInfo.UserName, interfaceConfigInfo.PassWord); var result = lesToQmisService.getAsninfo(bdAsnInfos.ToArray()); if (result.Count() > 0) { if (result.FirstOrDefault().status == "1") { return(ExecuteResultConstants.Success); } else { errorMsg = result.FirstOrDefault().message; } } } } catch (Exception ex) { errorMsg = ex.Message; } return(ExecuteResultConstants.Error); }
/// <summary> /// 发送 /// </summary> /// <param name="logFid"></param> /// <param name="interfaceConfigInfo"></param> /// <param name="errorCode"></param> /// <param name="errorMsg"></param> /// <param name="msgContent"></param> /// <returns></returns> public static ExecuteResultConstants Send(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { /// msgContent = string.Empty; /// List <SrmVmiSupplierPartInfo> vmiSupplierParts = new SrmVmiSupplierPartBLL().GetList("" + "[LOG_FID] = N'" + logFid + "' and " + "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (vmiSupplierParts.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///转换发送内容 List <BFDAVmiSupplierPartInfo> list = new List <BFDAVmiSupplierPartInfo>(); foreach (var vmiSupplierPartInfo in vmiSupplierParts) { list.Add(GetSrmVmiSupplierPartInfo(vmiSupplierPartInfo)); } ///准备把集合转成一个对象 BFDASRMSendDataInfo <BFDAVmiSupplierPartInfo> sendDataInfo = new BFDASRMSendDataInfo <BFDAVmiSupplierPartInfo>(); sendDataInfo.List = list; /// SupplierMaterialService_pttClient client = new SupplierMaterialService_pttClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); ///数据发送 msgContent = new XmlWrapper().ObjectToXmlByEncoding(sendDataInfo, Encoding.UTF8, false); msgContent = msgContent.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); /// string result = client.SupplierMaterialService(msgContent, out errorCode, out errorMsg); Log.WriteLogToFile(logFlag, interfaceCode + "--Return:dataCnt:" + result + "Content:" + msgContent + "\r", AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHH")); if (result == Convert.ToString((int)OutboundReturnStateConstants.FAILURE)) { return(ExecuteResultConstants.Error); } return(ExecuteResultConstants.Success); }
/// <summary> /// 发送 /// </summary> /// <param name="logFid"></param> /// <param name="interfaceConfigInfo"></param> /// <param name="errorCode"></param> /// <param name="errorMsg"></param> /// <param name="msgContent"></param> /// <returns></returns> public static ExecuteResultConstants Send(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { /// msgContent = string.Empty; /// List <SrmJisPullOrderInfo> srmJisPullOrderInfos = new SrmJisPullOrderBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (srmJisPullOrderInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///转换成BFDA集合 List <BFDAJisPullOrderInfo> list = new List <BFDAJisPullOrderInfo>(); foreach (var srmJisPullOrderInfo in srmJisPullOrderInfos) { list.Add(GetSrmJisPullOrderInfo(srmJisPullOrderInfo)); } ///准备把集合转成一个对象 BFDASRMSendDataInfo <BFDAJisPullOrderInfo> sendDataInfo = new BFDASRMSendDataInfo <BFDAJisPullOrderInfo> { List = list }; /// msgContent = new XmlWrapper().ObjectToXmlByEncoding(sendDataInfo, Encoding.UTF8, false); msgContent = msgContent.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); /// JISPullService_pttClient client = new JISPullService_pttClient(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); ///数据发送 string result = client.JISPullService(msgContent, out errorCode, out errorMsg); if (result == Convert.ToString((int)OutboundReturnStateConstants.FAILURE)) { return(ExecuteResultConstants.Error); } return(ExecuteResultConstants.Success); }
public void IsInHarmonicKeyRange_MinusOneAndOppositeCircle_Test() { // Arrange IXmlWrapper xmlWrapper = new XmlWrapper(); ITempoRange tempoRange = new TempoRange(); IHarmonicKeyRange harmonicKeyRange = new HarmonicKeyRange(); harmonicKeyRange.Load("7B"); IIntensityRange intensityRange = new IntensityRange(); ISong song = new Song(xmlWrapper, tempoRange, harmonicKeyRange, intensityRange) { Artist = "Song 1", }; var trailingHarmonicKey = "8A"; // Act var result = song.IsInHarmonicKeyRange(trailingHarmonicKey); // Assert Assert.IsFalse(result); }
public void IsInTempoRange_AboveFastestDoubleAndSlowestDoubleTempo_Test() { // Arrange IXmlWrapper xmlWrapper = new XmlWrapper(); ITempoRange tempoRange = new TempoRange(); tempoRange.Load(62.499, 3); IHarmonicKeyRange harmonicKeyRange = new HarmonicKeyRange(); IIntensityRange intensityRange = new IntensityRange(); ISong song = new Song(xmlWrapper, tempoRange, harmonicKeyRange, intensityRange) { Artist = "Song 1", }; var trailingTempo = 128; // Act var result = song.IsInTempoRange(trailingTempo); // Assert Assert.IsFalse(result); }
public void GetBestMatch_SongsAreSame_Test() { // Arrange IXmlWrapper xmlWrapper1 = new XmlWrapper(); ITempoRange tempoRange1 = new TempoRange(); IHarmonicKeyRange harmonicKeyRange1 = new HarmonicKeyRange(); IIntensityRange intensityRange1 = new IntensityRange(); ISong song1 = new Song(xmlWrapper1, tempoRange1, harmonicKeyRange1, intensityRange1); var baseTrackList = new List <ISong> { song1 }; var playlistTracks = new List <ISong> { song1 }; var intensityStyle = "Random"; var minPlaytime = 200; var mixLength = 0; IMixDisc mixDisc = new MixDisc { BaseTrackList = baseTrackList, PlaylistTracks = playlistTracks, IntensityStyle = intensityStyle, MinPlaytime = minPlaytime, MixLength = mixLength }; // Act var result = mixDisc.GetBestMatch(); // Assert Assert.IsTrue(result.Count == 0); }
public void IsInIntensityRange_AbovePlusOne_Test() { // Arrange IXmlWrapper xmlWrapper = new XmlWrapper(); ITempoRange tempoRange = new TempoRange(); IHarmonicKeyRange harmonicKeyRange = new HarmonicKeyRange(); IIntensityRange intensityRange = new IntensityRange(); intensityRange.Load(9); ISong song = new Song(xmlWrapper, tempoRange, harmonicKeyRange, intensityRange) { Artist = "Song 1", Intensity = 9 }; var trailingIntensity = 7; // Act var result = song.IsInIntensityRange(trailingIntensity); // Assert Assert.IsFalse(result); }
/// <summary> /// The read xml. /// </summary> /// <param name="reader"> The reader. </param> public void ReadXml(XmlReader reader) { this.Name = string.Empty; this.parameterValues.Clear(); if (reader.IsEmptyElement) { reader.ReadStartElement(); return; } reader.ReadStartElement(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name; if (elementName == "Name") { this.Name = reader.ReadElementString(); } else if (elementName == "Child") { XmlWrapper wrapper = new XmlWrapper(); wrapper.ReadXml(reader); this.DecoratorTask = wrapper.Task; } else if (this.taskDescription != null) { // Check if parameter. TaskParameterDescription parameterDescription = this.taskDescription.ParameterDescriptions.Find(desc => desc.ParameterName == elementName); if (parameterDescription != null) { Type type = Type.GetType(parameterDescription.Type); reader.ReadStartElement(parameterDescription.ParameterName); XmlSerializer xmlSerializer = new XmlSerializer(type); object value = xmlSerializer.Deserialize(reader); reader.ReadEndElement(); this.parameterValues[parameterDescription] = value; } else { reader.Skip(); } } else { reader.Skip(); } } else { reader.Skip(); } } reader.ReadEndElement(); }
/// <summary> /// LES-SAP-012 盘点计划报告 /// </summary> /// <param name="logFid"></param> public static ExecuteResultConstants SendInventoryCheckReportData(Guid logFid, InterfaceConfigInfo interfaceConfigInfo, ref string errorCode, ref string errorMsg, out string msgContent) { msgContent = string.Empty; List <SapInventoryCheckReportInfo> sapInventoryCheckReportInfos = new SapInventoryCheckReportBLL().GetList("[LOG_FID] = N'" + logFid + "' and [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty); if (sapInventoryCheckReportInfos.Count == 0) { errorCode = "MC:0x00000212";///经检测,传递数据为空,请确认 return(ExecuteResultConstants.Exception); } ///发送消息 Zsles008[] Itab = new Zsles008[sapInventoryCheckReportInfos.Count]; for (int i = 0; i < sapInventoryCheckReportInfos.Count; i++) { Zsles008 zfles008 = new Zsles008(); zfles008.Iblnr = sapInventoryCheckReportInfos[i].Iblnr; ///库存盘点凭证 zfles008.Matnr = sapInventoryCheckReportInfos[i].Matnr; ///物料号 ///zfles008.Werks = sapInventoryCheckReportInfos[i].; ///工厂 zfles008.Lgort = sapInventoryCheckReportInfos[i].Lgort; ///库存地点 zfles008.Menge = Convert.ToDecimal(sapInventoryCheckReportInfos[i].Menge.GetValueOrDefault()); ///数量 zfles008.Aqty = Convert.ToDecimal(sapInventoryCheckReportInfos[i].Aqty.GetValueOrDefault()); ///实盘数量 zfles008.Dqty = Convert.ToDecimal(sapInventoryCheckReportInfos[i].Dqty.GetValueOrDefault()); ///差异数量 zfles008.Gidat = sapInventoryCheckReportInfos[i].Zldat.GetValueOrDefault().ToString(sapDateFormat); ///库存盘点计划日期 Itab[i] = zfles008; } msgContent = new XmlWrapper().ObjectToXml(Itab, false); Log.WriteLogToFile("LES-SAP-012 盘点报告.return:Count:" + sapInventoryCheckReportInfos.Count + "/r" + msgContent, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHH")); ZLES008Client client = new ZLES008Client(); client.Endpoint.Address = new EndpointAddress(interfaceConfigInfo.CallUrl); ///返回对象 Zfles008[] retu008 = new Zfles008[0]; ///1标识成功、0标识失败 int result; ///返回信息提示 string msg; ///影响数据行数 string dataCnt = client.Zles008(ref Itab, ref retu008, out result, out msg); Log.WriteLogToFile("LES-SAP-012 盘点报告.return:dataCnt:" + dataCnt, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHH")); ///失败时的ERROR_CODE中是对方系统的ERROR_MSG if (result == 0) { errorMsg = msg; for (int i = 0; i < retu008.Count(); i++) { errorMsg += "; "; errorMsg += retu008[i].Msg + ":" + retu008[i].Iblnr; } Log.WriteLogToFile(errorMsg, AppDomain.CurrentDomain.BaseDirectory + @"\Error_Log\", DateTime.Now.ToString("yyyyMMddHH")); return(ExecuteResultConstants.Error); } msgContent = GetMsgContent(sapInventoryCheckReportInfos); Log.WriteLogToFile("result:" + result + " | Content:" + msgContent, AppDomain.CurrentDomain.BaseDirectory + @"\log\", DateTime.Now.ToString("yyyyMMddHH")); return(ExecuteResultConstants.Success); }
/// <summary> /// Constructor to initialise a new configuration /// </summary> /// <param name="node">The xml node</param> /// <param name="wrapper">The xml wrapper</param> public XmlDatabaseConfig(IXPathNavigable node, XmlWrapper wrapper) { _node = node; _xmlWrapper = wrapper; }
/// <summary> /// Task 90 打印文件生成函数 /// TODO:仅实现了HTML格式的打印 /// </summary> /// <param name="printConfigCode"></param> /// <returns></returns> public List <string> CreatePrintFiles(string templateFileName, string configFileName, string templateFileType, DataSet dataSet, string tempPrintFilePath, string tempPrintFilePathConfig) { StringBuilder sbTemplate = new StringBuilder(); using (StreamReader sr = new StreamReader(templateFileName, Encoding.Default)) { sbTemplate.Append(sr.ReadToEnd()); } ///字段匹配配置文件格式: XmlWrapper xmlWrapper = new XmlWrapper(configFileName, LoadType.FromFile); ///主表配置信息 PrintConfigXmlTableInfo printConfigXmlTableInfo = xmlWrapper.XmlToObject("/Table", typeof(PrintConfigXmlTableInfo)) as PrintConfigXmlTableInfo; if (string.IsNullOrEmpty(printConfigXmlTableInfo.AutoPrintFlag)) { sbTemplate = sbTemplate.Replace("$AutoPrintFlag$", string.Empty); } else { if (printConfigXmlTableInfo.AutoPrintFlag.ToLower() == "true") { sbTemplate = sbTemplate.Replace("$AutoPrintFlag$", "<script>window.onload = function () {window.print();function colseAfterPrint() {if (p = document.execCommand('print')) window.close();else setTimeout('colseAfterPrint();', 1000);}colseAfterPrint();}</script>"); } else { sbTemplate = sbTemplate.Replace("$AutoPrintFlag$", string.Empty); } } ///主表配置字段信息 List <object> printConfigXmlFieldInfos = xmlWrapper.XmlToList("/Table/Field", typeof(PrintConfigXmlFieldInfo)); ///明细行配置 PrintConfigXmlDetailsInfo printConfigXmlDetailsInfo = xmlWrapper.XmlToObject("/Table/Details", typeof(PrintConfigXmlDetailsInfo)) as PrintConfigXmlDetailsInfo; ///明细行字段 List <object> printConfigXmlDetailInfos = xmlWrapper.XmlToList("/Table/Details/Field", typeof(PrintConfigXmlFieldInfo)); DataTable dataTable = dataSet.Tables[printConfigXmlTableInfo.TableName]; if (dataTable == null && dataSet.Tables.Count > 0) { dataTable = dataSet.Tables[0]; } List <string> printFiles = new List <string>(); if (dataTable == null) { return(printFiles); } foreach (DataRow dr in dataTable.Rows) { ///主表填充 string printContent = FillPrintContent(sbTemplate.ToString(), printConfigXmlFieldInfos, dr, tempPrintFilePath, tempPrintFilePathConfig); if (printConfigXmlDetailsInfo == null) { string saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , printContent , Encoding.GetEncoding("GB2312")); printFiles.Add(tempPrintFilePathConfig + "/" + saveFileName); continue; } string[] relationFields = printConfigXmlDetailsInfo.RelationFields.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string conditions = string.Empty; for (int i = 0; i < relationFields.Length; i++) { string[] relationField = relationFields[i].Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); if (relationField.Length != 2) { continue; } conditions += "and " + relationField[0] + " = '" + dr[relationField[1]] + "'"; } DataTable dtDetail = dataSet.Tables[printConfigXmlDetailsInfo.TableName]; if (printConfigXmlDetailsInfo.TableName == printConfigXmlTableInfo.TableName) { dtDetail = dataTable; } if (dtDetail == null && dataSet.Tables.Count > 1) { dtDetail = dataSet.Tables[1]; } if (dtDetail == null) { string saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , printContent , Encoding.GetEncoding("GB2312")); printFiles.Add(tempPrintFilePathConfig + "/" + saveFileName); continue; } ///明细数据 DataRow[] detailTable; if (conditions.Length > 0) { detailTable = dtDetail.Select(conditions.Substring(4)); } else { detailTable = new DataRow[dtDetail.Rows.Count]; for (int i = 0; i < dtDetail.Rows.Count; i++) { detailTable[i] = dtDetail.Rows[i]; } } ///每页最多几行明细 int pageRowCnt = printConfigXmlDetailsInfo.MaxRow; int totalRowCnt = detailTable.Length; string detalRowTemplate = CreateHtmlDetailRowTemplate(sbTemplate.ToString()); if (string.IsNullOrEmpty(detalRowTemplate)) { string saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , printContent , Encoding.GetEncoding("GB2312")); printFiles.Add(tempPrintFilePathConfig + "/" + saveFileName); continue; } string emptyRowTemplate = CreateHtmlEmptyRowTemplate(detalRowTemplate); StringBuilder detailSb = new StringBuilder(); ///当前页码 int pageIndex = 0; while (totalRowCnt > 0) { for (int i = 0; i < pageRowCnt; i++) { if (totalRowCnt > i) { /// string detalRow = FillPrintContent(detalRowTemplate, printConfigXmlDetailInfos, detailTable[pageIndex * pageRowCnt + i], tempPrintFilePath, tempPrintFilePathConfig); detailSb.Append(detalRow); continue; } if (printConfigXmlDetailsInfo.FillEmpty) { detailSb.Append(emptyRowTemplate); } } string saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + pageIndex + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , printContent.Replace(detalRowTemplate, detailSb.ToString()) , Encoding.GetEncoding("GB2312")); printFiles.Add("../" + tempPrintFilePathConfig + "/" + saveFileName); ///页码递增 pageIndex++; /// totalRowCnt -= pageRowCnt; detailSb.Clear(); /// } } return(printFiles); }
public string CreatePrintFileByPageEntity(string templateFileName, string configFileName, string templateFileType, DataSet dataSet, string tempPrintFilePath, string tempPrintFilePathConfig) { StringBuilder sbTemplate = new StringBuilder(); StringBuilder tempBuilder = new StringBuilder(); using (StreamReader sr = new StreamReader(templateFileName, Encoding.Default)) { sbTemplate.Append(sr.ReadToEnd()); } ///字段匹配配置文件格式: XmlWrapper xmlWrapper = new XmlWrapper(configFileName, LoadType.FromFile); ///主表配置信息 PrintConfigXmlTableInfo printConfigXmlTableInfo = xmlWrapper.XmlToObject("/Table", typeof(PrintConfigXmlTableInfo)) as PrintConfigXmlTableInfo; ///主表配置字段信息 List <object> printConfigXmlFieldInfos = xmlWrapper.XmlToList("/Table/Field", typeof(PrintConfigXmlFieldInfo)); ///明细行配置 PrintConfigXmlDetailsInfo printConfigXmlDetailsInfo = xmlWrapper.XmlToObject("/Table/Details", typeof(PrintConfigXmlDetailsInfo)) as PrintConfigXmlDetailsInfo; ///明细行字段 List <object> printConfigXmlDetailInfos = xmlWrapper.XmlToList("/Table/Details/Field", typeof(PrintConfigXmlFieldInfo)); DataTable dataTable = dataSet.Tables[printConfigXmlTableInfo.TableName]; if (dataTable == null && dataSet.Tables.Count > 0) { dataTable = dataSet.Tables[0]; } string printFile = string.Empty; if (dataTable == null) { return(printFile); } if (dataTable.Rows.Count == 0) { return(printFile); } #region 变量初始化 string saveFileName = string.Empty; StringBuilder bodymainBuilder = new StringBuilder(); int IsEspecial = printConfigXmlTableInfo.IsEspecial; int MaxRow; bool FillEmpty = false; #endregion if (IsEspecial == 0) { MaxRow = printConfigXmlDetailsInfo.MaxRow; FillEmpty = printConfigXmlDetailsInfo.FillEmpty; string pagetemplate = string.Empty; foreach (DataRow dr in dataTable.Rows) { #region 获取明细数据源根据配置关联字段 string conditions = string.Empty; conditions = "1 = 1"; string[] relationFields = printConfigXmlDetailsInfo.RelationFields.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string[] valueStr1 = relationFields[0].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); string[] valueStr2 = relationFields[1].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < valueStr1.Length; i++) { conditions += "AND " + valueStr1[i] + " = '" + dr[valueStr2[i]].ToString() + "'"; } DataRow[] dtDetail = dataSet.Tables[1].Select(conditions); #endregion int allrows = dtDetail.Length; //获取总行数 int allpages = (int)Math.Ceiling(decimal.Parse(allrows.ToString()) / decimal.Parse(MaxRow.ToString())); //获取总页数 int emptycount = allpages * MaxRow - allrows; //需要补空白行数 string mainStr = CreateHtmlMaindivTemplate(sbTemplate.ToString()); pagetemplate = sbTemplate.ToString().Replace(mainStr, "<!--replacement_markers_allpages-->"); //整个页面填充标记 string detailsStr = CreateHtmlDetailsTemplate(sbTemplate.ToString()); string tabfirstStr = mainStr.Replace(detailsStr, "<!--replacement_markers_first-->"); //传入主数据填充 <!--replacement_markers_first--> => detailsStr string detailRowStr = CreateHtmlDetailTemplate(sbTemplate.ToString()); //传入明细填充数据 string printContent = FillPrintContent(tabfirstStr, printConfigXmlFieldInfos, dr, tempPrintFilePath, tempPrintFilePathConfig); ///主表填充 printContent = printContent.Replace(@"$PageCount$", allpages.ToString()); string tabsecondStr = detailsStr.Replace(detailRowStr, "<!--replacement_markers_second-->"); // <!--replacement_markers_second--> => detailRowStr if (allrows == 0) { string printContentnew = printContent.Replace(@"$PageThis$", "1"); if (FillEmpty) { for (int i = 0; i < MaxRow; i++) { string emptyRowTemplate = CreateHtmlEmptyRowTemplate(detailRowStr); tempBuilder.AppendLine(emptyRowTemplate); } } string alldetailesStr = tabsecondStr.Replace("<!--replacement_markers_second-->", tempBuilder.ToString()); string pagemiandivStr = printContentnew.Replace("<!--replacement_markers_first-->", alldetailesStr); bodymainBuilder.AppendLine(pagemiandivStr); tempBuilder.Clear(); } int sIndex = 0; int thispage = 1; foreach (DataRow drDetails in dtDetail) { string rowTemplate = detailRowStr; string detalRow = FillPrintContent(rowTemplate, printConfigXmlDetailInfos, drDetails, tempPrintFilePath, tempPrintFilePathConfig); detalRow = detalRow.Replace("$RowId$", (sIndex + 1).ToString()); tempBuilder.AppendLine(detalRow); if (allrows > 1) { if ((sIndex + 1) % MaxRow == 0) { string printContentnew = printContent.Replace(@"$PageThis$", thispage.ToString()); thispage = thispage + 1; string alldetailesStr = tabsecondStr.Replace("<!--replacement_markers_second-->", tempBuilder.ToString()); string pagemiandivStr = printContentnew.Replace("<!--replacement_markers_first-->", alldetailesStr); bodymainBuilder.AppendLine(pagemiandivStr); bodymainBuilder.AppendLine("<div class=\"PageNext\"></div>"); tempBuilder.Clear(); } } else { string printContentnew = printContent.Replace(@"$PageThis$", thispage.ToString()); if (FillEmpty) { for (int i = 0; i < emptycount; i++) { string emptyRowTemplate = CreateHtmlEmptyRowTemplate(detailRowStr); tempBuilder.AppendLine(emptyRowTemplate); } } string alldetailesStr = tabsecondStr.Replace("<!--replacement_markers_second-->", tempBuilder.ToString()); string pagemiandivStr = printContentnew.Replace("<!--replacement_markers_first-->", alldetailesStr); bodymainBuilder.AppendLine(pagemiandivStr); tempBuilder.Clear(); } sIndex++; } if (tempBuilder.Length > 0) { if (FillEmpty) { for (int i = 0; i < emptycount; i++) { string emptyRowTemplate = CreateHtmlEmptyRowTemplate(detailRowStr); tempBuilder.AppendLine(emptyRowTemplate); } } string alldetailesStr = tabsecondStr.Replace("<!--replacement_markers_second-->", tempBuilder.ToString()); printContent = printContent.Replace(@"$PageThis$", thispage.ToString()); string pagemiandivStr = printContent.Replace("<!--replacement_markers_first-->", alldetailesStr); bodymainBuilder.AppendLine(pagemiandivStr); bodymainBuilder.AppendLine("<div class=\"PageNext\"></div>"); tempBuilder.Clear(); } } pagetemplate = pagetemplate.Replace("<!--replacement_markers_allpages-->", bodymainBuilder.ToString()); saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , pagetemplate.ToString() , Encoding.GetEncoding("GB2312")); return("../" + tempPrintFilePathConfig + "/" + saveFileName); } else if (IsEspecial == 1) { #region 单Table实体支持一页打印多个 FillEmpty = printConfigXmlDetailsInfo.FillEmpty; MaxRow = printConfigXmlDetailsInfo.MaxRow; int allrows = dataTable.Rows.Count; //获取总行数 int allpages = (int)Math.Ceiling(Convert.ToDecimal((allrows / MaxRow).ToString())); //获取总页数 int i = 0; foreach (DataRow dr in dataTable.Rows) { string detalsTemplate = CreateHtmlDetailsTemplate(sbTemplate.ToString()); string detalRowTemplate = CreateHtmlDetailRowTemplate(sbTemplate.ToString()); string detalRow = FillPrintContent(detalRowTemplate, printConfigXmlDetailInfos, dataTable.Rows[i], tempPrintFilePath, tempPrintFilePathConfig); detalRow = detalRow.Replace(@"$PageCount$", allrows.ToString()); detalRow = detalRow.Replace(@"$PageThis$", (i + 1).ToString()); tempBuilder.AppendLine(detalRow); if (allrows > 1) { if ((i + 1) % MaxRow == 0) { detalsTemplate = detalsTemplate.Replace(detalRowTemplate, tempBuilder.ToString()); bodymainBuilder.AppendLine(detalsTemplate); bodymainBuilder.AppendLine("<div class=\"PageNext\"></div>"); tempBuilder.Clear(); } } else { detalsTemplate = detalsTemplate.Replace(detalRowTemplate, tempBuilder.ToString()); bodymainBuilder.AppendLine(detalsTemplate); tempBuilder.Clear(); } i++; } if (tempBuilder.Length > 0) { string detalsTemplate = CreateHtmlDetailsTemplate(sbTemplate.ToString()); string detalRowTemplate = CreateHtmlDetailRowTemplate(sbTemplate.ToString()); detalsTemplate = detalsTemplate.Replace(detalRowTemplate, tempBuilder.ToString()); bodymainBuilder.AppendLine(detalsTemplate); tempBuilder.Clear(); } sbTemplate = sbTemplate.Replace(CreateHtmlDetailsTemplate(sbTemplate.ToString()), bodymainBuilder.ToString()); saveFileName = printConfigXmlTableInfo.PrintFileName + "_" + DateTime.Now.Ticks + "." + templateFileType; FileInfo fileInfo = new FileInfo(saveFileName); File.WriteAllText(tempPrintFilePath + @"\" + saveFileName , sbTemplate.ToString() , Encoding.GetEncoding("GB2312")); return("../" + tempPrintFilePathConfig + "/" + saveFileName); #endregion } return(saveFileName); }
public void Handler() { #region 基础变量 ///最近一条的中间表数据状态 int processFlag = 0; ///本次线程已处理的中间表主键 List <long> dealedIds = new List <long>(); //数据库执行语句 StringBuilder @string = new StringBuilder(); ///物料需求提前天数 int.TryParse(materialRequireAdvanceDays, out int intMaterialRequrieAdvanceDays); intMaterialRequrieAdvanceDays = 0 - intMaterialRequrieAdvanceDays; #endregion while (processFlag != 10) { ///开始处理时间 DateTime startExecuteTime = DateTime.Now; ///获取状态⑮为10.未处理的SAP生产订单数据 ///因为后续处理过程较为复杂,所以一次获取一条ID主键最靠前的10.未处理或30.挂起或40.逆处理状态数据 ///当上一条处理数据为30.挂起状态时需要继续处理下一条,否则执行结束 ///也就意味着30.挂起的数据将优先处理且为了保障挂起数据不影响正常未处理数据而设定的逻辑 #region 获取待处理的数据 string textWhere = "[PROCESS_FLAG] in (" + (int)ProcessFlagConstants.Untreated + "," + (int)ProcessFlagConstants.Suspend + "," + (int)ProcessFlagConstants.ConverseProgress + ")"; ///集合大于0,排除 if (dealedIds.Count > 0) { textWhere += "and [ID] not in (" + string.Join(",", dealedIds.ToArray()) + ")"; } /// SapProductOrderInfo sapProductOrderInfo = new SapProductOrderBLL().GetTopOneInfo(textWhere, "[ID] asc"); if (sapProductOrderInfo == null) { throw new Exception("MC:3x00000015");///没有已启用的SAP生产订单信息 } if (sapProductOrderInfo.OnlineDate == null) { throw new Exception("MC:3x00000033");///SAP生产订单上线日期信息错误 } Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":Start " + sapProductOrderInfo.Aufnr); ///SAP生产订单上线日期 string sapProductOrderDate = sapProductOrderInfo.OnlineDate.GetValueOrDefault().ToString("yyyyMMdd"); ///处理状态 processFlag = sapProductOrderInfo.ProcessFlag.GetValueOrDefault(); /// dealedIds.Add(sapProductOrderInfo.Id); #endregion #region SAP生产订单物料清单 ///获取SAP生产订单中订单号⑤=③对应的SAP生产订单物料清单 SapProductOrderBomInfo sapProductOrderBomInfo = new SapProductOrderBomBLL().GetInfoByAufnr(sapProductOrderInfo.Aufnr); ///若此时未能获取到数据则表示该SAP生产订单的物料清单还未能从SAP成功接收到 if (sapProductOrderBomInfo == null) { ///需要终止该条生产订单的处理,并且标记为挂起状态⑮ new SapProductOrderBLL().UpdateInfo("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + ",[MODIFY_USER] = N'" + loginUser + "',[MODIFY_DATE] = GETDATE()", sapProductOrderInfo.Id); continue; } #endregion #region 订单物料清单XML解析 ///SAP生产订单物料清单中的物料信息⑦需要XML解析后并逐条以工厂③=②、物料号①=⑦.MATNR、供应商②=⑦.LIFNR XmlWrapper xmlWrapper = new XmlWrapper(sapProductOrderBomInfo.Matnrs, LoadType.FromString); List <object> objMatnrs = xmlWrapper.XmlToList("/MatnrsAll/Matnrs", typeof(Matnrs)); if (objMatnrs.Count == 0) { throw new Exception("0x00000182");///无订单物料清单 } List <string> partNos = new List <string>(); List <string> supplierNums = new List <string>(); foreach (Matnrs matnr in objMatnrs) { partNos.Add(matnr.Matnr); supplierNums.Add(matnr.Lifnr); } List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetListForInterfaceDataSync(partNos); if (maintainPartsInfos.Count == 0) { throw new Exception("0x00000182");///无订单物料清单 } List <SupplierInfo> supplierInfos = new SupplierBLL().GetListForInterfaceDataSync(supplierNums); #endregion ///需根据SAP生产订单中的上线日期⑩判定供货计划TT_ATP_SUPPLY_PLAN中的对应日期列是否存在 ///日期列的列名规则为yyyyMMdd数据类型为decimal(18,4),不存在则需要新建列 ProcessSupplyPlanDate(sapProductOrderInfo.OnlineDate.GetValueOrDefault().AddDays(intMaterialRequrieAdvanceDays)); /// string plant = new PlantBLL().GetPlantBySapPlantCode(sapProductOrderInfo.Dwerk); if (string.IsNullOrEmpty(plant)) { throw new Exception("3x00000016");///工厂不存在 } string assemblyLine = new AssemblyLineBLL().GetAssemblyLineBySapAssemblyLine(sapProductOrderInfo.Verid); if (string.IsNullOrEmpty(assemblyLine)) { throw new Exception("3x00000017");///产线不存在 } ///根据生产订单号⑤=①获取生产订单TT_BAS_PULL_ORDERS数据 PullOrdersInfo pullOrdersInfo = new PullOrdersBLL().GetInfoByOrderNo(sapProductOrderInfo.Aufnr); ///生产订单上线日期 string productOrderDate = sapProductOrderDate; ///供货日期 string materialRequireDate = sapProductOrderInfo.OnlineDate.GetValueOrDefault().AddDays(intMaterialRequrieAdvanceDays).ToString("yyyyMMdd"); #region 首次下发 ///若此时未能成功获取数据则表示该生产订单为首次下发,且不是删除的生产订单 if (pullOrdersInfo == null && string.IsNullOrEmpty(sapProductOrderInfo.Zsc)) { if (calculateSupplyPlanFlag.ToLower() == "true") { #region 供货计划 foreach (Matnrs matnr in objMatnrs) { decimal partQty = 0; decimal.TryParse(matnr.Bdmng, out partQty); MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == matnr.Matnr); string partCname = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartCname.Replace("'", "''"); string partPurchaser = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartPurchaser; SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == matnr.Lifnr); string supplierName = supplierInfo == null ? string.Empty : supplierInfo.SupplierName; ///若不存在则insert,再以工厂③、物料号①、供应商②更新其对应日期的物料数量 @string.AppendFormat(@" if not exists (select 1 from [LES].[TT_ATP_SUPPLY_PLAN] with(nolock) where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}' and [VALID_FLAG] = 1) begin insert into [LES].[TT_ATP_SUPPLY_PLAN] ([FID],[PART_NO],[PART_CNAME],[PART_PURCHASER],[SUPPLIER_NUM],[SUPPLIER_NAME],[PLANT],[VALID_FLAG],[CREATE_USER],[CREATE_DATE]) values (NEWID(),N'{0}',N'{6}',N'{7}',N'{1}',N'{8}',N'{2}',1,N'{5}',GETDATE()); end update [LES].[TT_ATP_SUPPLY_PLAN] set [PART_CNAME] = N'{6}',[PART_PURCHASER] = N'{7}',[SUPPLIER_NAME] = N'{8}',[{3}] = ISNULL([{3}] , 0) + {4},[MODIFY_USER] = N'{5}',[MODIFY_DATE] = GETDATE() where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}';" , matnr.Matnr, matnr.Lifnr, plant, materialRequireDate, partQty, loginUser, partCname, partPurchaser, supplierName); } #endregion } #region 生产订单 /// pullOrdersInfo = PullOrdersBLL.CreatePullOrdersInfo(loginUser); /// PullOrdersBLL.GetPullOrdersInfo(sapProductOrderInfo, ref pullOrdersInfo); ///WERK,接口_工厂 pullOrdersInfo.Werk = plant; ///ORDER_DATE,订单日期 pullOrdersInfo.OrderDate = BLL.LES.CommonBLL.TryParseDatetime(sapProductOrderDate); ///ASSEMBLY_LINE,工厂模型_流水线 pullOrdersInfo.AssemblyLine = assemblyLine; ///PLAN_EXECUTE_TIME,计划执行时间 pullOrdersInfo.PlanExecuteTime = BLL.LES.CommonBLL.TryParseDatetime(sapProductOrderDate); /// @string.AppendLine(PullOrdersDAL.GetInsertSql(pullOrdersInfo)); ///并批量插入生产订单物料清单(参见TT_BAS_PULL_ORDER_BOM备注中的对应关系) WmsVmiProductOrderInfo wmsVmiProductOrderInfo = WmsVmiProductOrderBLL.CreateWmsVmiProductOrderInfo(loginUser); /// WmsVmiProductOrderBLL.GetWmsVmiProductOrderInfo(pullOrdersInfo, ref wmsVmiProductOrderInfo); /// wmsVmiProductOrderInfo.DownLineTime = sapProductOrderInfo.OfflineDate; wmsVmiProductOrderInfo.OnlineTime = sapProductOrderInfo.OnlineDate; wmsVmiProductOrderInfo.LockFlag = sapProductOrderInfo.LockFlag; @string.AppendLine(WmsVmiProductOrderDAL.GetInsertSql(wmsVmiProductOrderInfo)); @string.AppendLine(BLL.LES.CommonBLL.GetCreateOutboundLogSql("VMI", wmsVmiProductOrderInfo.LogFid.GetValueOrDefault(), "LES-WMS-012", wmsVmiProductOrderInfo.OrderNo, loginUser)); foreach (Matnrs matnr in objMatnrs) { decimal partQty = 0; decimal.TryParse(matnr.Bdmng, out partQty); MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == matnr.Matnr); string partCname = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartCname; @string.AppendFormat(@"insert into [LES].[TT_BAS_PULL_ORDER_BOM] ([FID],[ORDERFID],[ZORDNO],[ZKWERK],[ZBOMID],[ZCOMNO],[ZQTY],[ZLOC],[SUPPLIER_NUM],[PLATFORM],[CREATE_USER],[CREATE_DATE],[VALID_FLAG],[ZCOMDS],[ZDATE]) values (NEWID(),N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',{5},N'{6}',N'{7}',N'{8}',N'{9}',GETDATE(),1,N'{10}',N'{11}');" , pullOrdersInfo.Fid.GetValueOrDefault(), sapProductOrderInfo.Aufnr, plant, matnr.Aennr, matnr.Matnr, partQty, matnr.Ebort, matnr.Lifnr, matnr.Platform, loginUser, partCname, sapProductOrderDate); } #endregion #region 计划拉动状态 ///获取已启用的计划零件类的零件类外键① ///并将TT_BAS_PULL_ORDERS的订单外键②写入TT_MPM_PLAN_PULL_CREATE_STATUS ///其中的状态③为10.未生成(20.已生成,在系统代码中创建CREATE_STATUS,还需修改计划拉动单生成逻辑中的对应枚举项) List <PlanPartBoxInfo> planPartBoxInfos = new PlanPartBoxBLL().GetList("[STATUS] = " + (int)BasicDataStatusConstants.Enable + "", string.Empty); /// foreach (PlanPartBoxInfo planPartBoxInfo in planPartBoxInfos) { @string.AppendFormat(@"insert into [LES].[TT_MPM_PLAN_PULL_CREATE_STATUS] (FID,PART_BOX_FID,ORDER_FID,STATUS,CREATE_USER,CREATE_DATE,VALID_FLAG) values (NEWID(),N'{0}',N'{1}',{2},'{3}',GETDATE(),1);" , planPartBoxInfo.Fid.GetValueOrDefault(), pullOrdersInfo.Fid.GetValueOrDefault(), (int)CreateStatusConstants.NotGenerated, loginUser); } #endregion ///同时更新SAP生产订单物料清单处理状态⑮为20.已处理 @string.AppendFormat(@"update [LES].[TI_IFM_SAP_PRODUCT_ORDER_BOM] set PROCESS_FLAG = {0},PROCESS_TIME = GETDATE(),[MODIFY_USER] = N'{1}',[MODIFY_DATE] = GETDATE() where [ID] = {2};" , (int)ProcessFlagConstants.Processed, loginUser, sapProductOrderBomInfo.Id); } #endregion #region 是首次下发 else { if (calculateSupplyPlanFlag.ToLower() == "true") { ///若之前成功获取了生产订单则比对上线日期⑩⑤是否较SAP生产订单有变化 #region 供货计划 ///获取生产订单物料清单 List <PullOrderBomInfo> pullOrderBomInfos = new PullOrderBomBLL().GetList("[ZORDNO] = N'" + pullOrdersInfo.OrderNo + "'", string.Empty); ///SAP订单删除,需要重新计算供货计划 if (sapProductOrderInfo.Zsc.ToUpper() == "X") { ///需要根据生产订单物料清单TT_BAS_PULL_ORDER_BOM和生产订单的订单日期⑤扣减供货计划 foreach (PullOrderBomInfo pullOrderBomInfo in pullOrderBomInfos) { @string.AppendLine("update [LES].[TT_ATP_SUPPLY_PLAN] " + "set [" + materialRequireDate + "] = ISNULL([" + materialRequireDate + "] , 0) - " + pullOrderBomInfo.Zqty.GetValueOrDefault() + "," + "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [PART_NO] = N'" + pullOrderBomInfo.Zcomno + "' and " + "[SUPPLIER_NUM] = N'" + pullOrderBomInfo.SupplierNum + "' and " + "[PLANT] = N'" + plant + "';"); } } else { ///若日期无变化⑩=⑤处理状态⑮为10.未处理或30.挂起时不需要更新供货计划 if (sapProductOrderInfo.OnlineDate.GetValueOrDefault() == pullOrdersInfo.OrderDate.GetValueOrDefault()) { ///若处理状态⑮为40.逆处理时 if (processFlag == (int)ProcessFlagConstants.ConverseProgress) { ///根据SAP生产订单上线日期⑩及物料清单扣减供货计划 foreach (Matnrs matnr in objMatnrs) { decimal partQty = 0; decimal.TryParse(matnr.Bdmng, out partQty); @string.AppendFormat(@"update [LES].[TT_ATP_SUPPLY_PLAN] set [{3}] = ISNULL([{3}] , 0) - {4},[MODIFY_USER] = N'{5}',[MODIFY_DATE] = GETDATE() where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}';" , matnr.Matnr, matnr.Lifnr, plant, materialRequireDate, partQty, loginUser); } ///再以生产订单⑤日期及物料清单累加供货计划 foreach (PullOrderBomInfo pullOrderBomInfo in pullOrderBomInfos) { MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == pullOrderBomInfo.Zcomno); string partCname = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartCname; string partPurchaser = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartPurchaser; SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == pullOrderBomInfo.SupplierNum); string supplierName = supplierInfo == null ? string.Empty : supplierInfo.SupplierName; @string.AppendFormat(@"update [LES].[TT_ATP_SUPPLY_PLAN] set [PART_CNAME] = N'{6}',[PART_PURCHASER] = N'{7}',[SUPPLIER_NAME] = N'{8}',[{3}] = ISNULL([{3}] , 0) + {4},[MODIFY_USER] = N'{5}',[MODIFY_DATE] = GETDATE() where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}';" , pullOrderBomInfo.Zcomno, pullOrderBomInfo.SupplierNum, plant, materialRequireDate, pullOrderBomInfo.Zqty.GetValueOrDefault(), loginUser, partCname, partPurchaser, supplierName); } } } ///日期有变化⑩<>⑤ else { ///SAP生产订单处理状态⑮为10.未处理或30.挂起时 if (processFlag == (int)ProcessFlagConstants.Untreated || processFlag == (int)ProcessFlagConstants.Suspend) { ///需要根据生产订单物料清单TT_BAS_PULL_ORDER_BOM和生产订单的订单日期⑤扣减供货计划 foreach (PullOrderBomInfo pullOrderBomInfo in pullOrderBomInfos) { @string.AppendFormat(@"update [LES].[TT_ATP_SUPPLY_PLAN] set [{3}] = ISNULL([{3}] , 0) - {4},[MODIFY_USER] = N'{5}',[MODIFY_DATE] = GETDATE() where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}';" , pullOrderBomInfo.Zcomno, pullOrderBomInfo.SupplierNum, plant, materialRequireDate, pullOrderBomInfo.Zqty.GetValueOrDefault(), loginUser); } ///同时根据SAP生产订单上线日期⑩及物料清单累加供货计划 foreach (Matnrs matnr in objMatnrs) { decimal partQty = 0; decimal.TryParse(matnr.Bdmng, out partQty); MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == matnr.Matnr); string partCname = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartCname; string partPurchaser = maintainPartsInfo == null ? string.Empty : maintainPartsInfo.PartPurchaser; SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == matnr.Lifnr); string supplierName = supplierInfo == null ? string.Empty : supplierInfo.SupplierName; @string.AppendFormat(@"update [LES].[TT_ATP_SUPPLY_PLAN] set [PART_CNAME] = N'{6}',[PART_PURCHASER] = N'{7}',[SUPPLIER_NAME] = N'{8}',[{3}] = ISNULL([{3}] , 0) + {4},[MODIFY_USER] = N'{5}',[MODIFY_DATE] = GETDATE() where [PART_NO] = N'{0}' and [SUPPLIER_NUM] = N'{1}' and [PLANT] = N'{2}';" , matnr.Matnr, matnr.Lifnr, plant, materialRequireDate, partQty, loginUser, partCname, partPurchaser, supplierName); } } } } #endregion } #region 更新生产订单 ///生产订单删除 if (sapProductOrderInfo.Zsc.ToUpper() == "X") { @string.AppendLine("update [LES].[TT_BAS_PULL_ORDERS] " + "set [VALID_FLAG] = 0," + "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapProductOrderInfo.Id + " and " + "[VALID_FLAG] = 1;"); @string.AppendLine("update [LES].[TT_BAS_PULL_ORDER_BOM] " + "set [VALID_FLAG] = 0," + "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ZORDNO] = N'" + pullOrdersInfo.OrderNo + "' and " + "[VALID_FLAG] = 1;"); } else { ///更新生产订单时版本号⑨累加,同时更新生产订单内容、以及SAP生产订单处理状态⑮为20.已处理 @string.AppendFormat("update [LES].[TT_BAS_PULL_ORDERS] set " + "[WERK] = N'{1}'," + "[MODEL_YEAR] = N'{2}'," + "[VEHICLE_ORDER] = N'{3}'," + "[ORDER_DATE] = N'{4}'," + "[ASSEMBLY_LINE] = N'{5}'," + "[PART_NO] = N'{6}'," + "[VERSION] = ISNULL([VERSION],0) + 1," + "[MODIFY_USER] = N'{7}'," + "[MODIFY_DATE] = GETDATE()," + "[PLAN_EXECUTE_TIME] = N'{8}' " + "where [ID] = {0};", pullOrdersInfo.Id, plant, sapProductOrderInfo.CarColor, sapProductOrderInfo.OnlineSeq, sapProductOrderDate, assemblyLine, sapProductOrderInfo.Matnr, loginUser, sapProductOrderDate); } ///TODO:在下发给WMS时也需要提供生产订单删除的逻辑标识 WmsVmiProductOrderInfo wmsVmiProductOrderInfo = WmsVmiProductOrderBLL.CreateWmsVmiProductOrderInfo(loginUser); /// PullOrdersBLL.GetPullOrdersInfo(sapProductOrderInfo, ref pullOrdersInfo); ///WERK,接口_工厂 pullOrdersInfo.Werk = plant; ///ORDER_DATE,订单日期 pullOrdersInfo.OrderDate = BLL.LES.CommonBLL.TryParseDatetime(sapProductOrderDate); ///ASSEMBLY_LINE,工厂模型_流水线 pullOrdersInfo.AssemblyLine = assemblyLine; ///PLAN_EXECUTE_TIME,计划执行时间 pullOrdersInfo.PlanExecuteTime = BLL.LES.CommonBLL.TryParseDatetime(sapProductOrderDate); ///VERSION,版本号 pullOrdersInfo.Version = pullOrdersInfo.Version.GetValueOrDefault() + 1; /// WmsVmiProductOrderBLL.GetWmsVmiProductOrderInfo(pullOrdersInfo, ref wmsVmiProductOrderInfo); /// wmsVmiProductOrderInfo.DownLineTime = sapProductOrderInfo.OfflineDate; wmsVmiProductOrderInfo.OnlineTime = sapProductOrderInfo.OnlineDate; wmsVmiProductOrderInfo.LockFlag = sapProductOrderInfo.LockFlag; @string.AppendLine(WmsVmiProductOrderDAL.GetInsertSql(wmsVmiProductOrderInfo)); @string.AppendLine(BLL.LES.CommonBLL.GetCreateOutboundLogSql("VMI", wmsVmiProductOrderInfo.LogFid.GetValueOrDefault(), "LES-WMS-012", wmsVmiProductOrderInfo.OrderNo, loginUser)); #endregion } #endregion #region 更新SAP生产订单 @string.AppendFormat(@"update [LES].[TI_IFM_SAP_PRODUCT_ORDER] set PROCESS_FLAG = {0},PROCESS_TIME = GETDATE(),[MODIFY_USER] = N'{1}',[MODIFY_DATE] = GETDATE() where [ID] = {2};" , (int)ProcessFlagConstants.Processed, loginUser, sapProductOrderInfo.Id); #endregion #region 数据库语句执行 using (TransactionScope trans = new TransactionScope()) { if (@string.Length > 0) { BLL.LES.CommonBLL.ExecuteNonQueryBySql(@string.ToString()); } trans.Complete(); } ///这个很重要 @string.Clear(); #endregion ///订单计算用时 TimeSpan ts = new TimeSpan(); ts = DateTime.Now - startExecuteTime; Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":End " + sapProductOrderInfo.Aufnr + "," + ts.TotalSeconds + "s"); } }