From c45017ff70d94d55ae4623108024b81bf488bea4 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 28 Dec 2022 09:09:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9EDI=E7=9A=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5null=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/YTEdiHelper.cs | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Myshipping.Application/EDI/YTEdiHelper.cs b/Myshipping.Application/EDI/YTEdiHelper.cs index af50800d..36b3b84b 100644 --- a/Myshipping.Application/EDI/YTEdiHelper.cs +++ b/Myshipping.Application/EDI/YTEdiHelper.cs @@ -217,6 +217,10 @@ namespace Myshipping.Application.EDI.YT #region 格式化每行 public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) { + //2022-12-28 JHQ 传的字段是null会导致报错,这里改为如果是NULL则默认赋空字符串。 + if (str == null) + str = ""; + str = str.Replace("\r\n", "\\"); str = str.Replace("\n", "\\"); str = str.Replace("\r", " "); @@ -708,7 +712,7 @@ namespace Myshipping.Application.EDI.YT + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + ":" + bill.SERVICE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M - + ":" + formatEdiStr("txt", InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "))//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + formatEdiStr("txt", !string.IsNullOrWhiteSpace(InttrEdi.ForWarderName)?InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "):"")//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C @@ -735,7 +739,7 @@ namespace Myshipping.Application.EDI.YT + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + ":" + bill.SERVICE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M - + ":" + formatEdiStr("txt", InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "))//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + formatEdiStr("txt", !string.IsNullOrWhiteSpace(InttrEdi.ForWarderName)?InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "):"")//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C @@ -818,7 +822,7 @@ namespace Myshipping.Application.EDI.YT List ShippingList = formatlengthStr(Shipping, 70); - if (Shipping != "") + if (!string.IsNullOrWhiteSpace(Shipping)) { r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'"); icount++; @@ -865,10 +869,10 @@ namespace Myshipping.Application.EDI.YT } - Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + Shipping = formatEdiStr("txt", !string.IsNullOrWhiteSpace(bill.NOTIFYPARTY2) ? bill.NOTIFYPARTY2 : ""); ShippingList = formatlengthStr(Shipping, 35); - if (Shipping != "") + if (!string.IsNullOrWhiteSpace(Shipping)) { r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); @@ -881,7 +885,7 @@ namespace Myshipping.Application.EDI.YT Shipping = bill.AMSCONSIGNEE; ShippingList = formatlengthStr(Shipping, 35); - if (Shipping != "") + if (!string.IsNullOrWhiteSpace(Shipping)) { r.WriteLine("24::" + formatListStr(ShippingList, 6, true) + "'"); icount = icount + 1; @@ -892,7 +896,7 @@ namespace Myshipping.Application.EDI.YT Shipping = bill.AMSNOTIFYPARTY; ShippingList = formatlengthStr(Shipping, 35); - if (Shipping != "") + if (!string.IsNullOrWhiteSpace(Shipping)) { r.WriteLine("25::" + formatListStr(ShippingList, 6, true) + "'"); icount = icount + 1; @@ -973,7 +977,7 @@ namespace Myshipping.Application.EDI.YT } } } - if (strtemp != "") + if (!string.IsNullOrWhiteSpace(strtemp)) { r.WriteLine(strtemp + "'"); icount = icount + 1; @@ -1069,7 +1073,7 @@ namespace Myshipping.Application.EDI.YT for (var i = 0; i < ShippingList.Count; i++) { - if (ShippingList[i] != "") + if (!string.IsNullOrWhiteSpace(ShippingList[i])) { if (m <= 5) { @@ -1093,7 +1097,7 @@ namespace Myshipping.Application.EDI.YT } } } - if (strtemp != "") + if (!string.IsNullOrWhiteSpace(strtemp)) { r.WriteLine(strtemp + "'"); icount = icount + 1;