修改EDI的生成方法,增加字段null报错问题

optimize
jianghaiqing 2 years ago
parent 958fc4f440
commit c45017ff70

@ -217,6 +217,10 @@ namespace Myshipping.Application.EDI.YT
#region 格式化每行
public static List<System.String> 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<System.String> 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;

Loading…
Cancel
Save