|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
namespace Myshipping.Application.EDI.WY
|
|
|
{
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
public class WYEdiHelper
|
|
|
{
|
|
|
|
|
|
public WYEdiHelper()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
#region 基本函数
|
|
|
|
|
|
public static string GetBillNum2(string str)
|
|
|
{
|
|
|
if (str == "ZERO") return "00";
|
|
|
if (str == "ONE") return "01";
|
|
|
if (str == "TWO") return "02";
|
|
|
if (str == "THREE") return "03";
|
|
|
if (str == "FOUR") return "04";
|
|
|
if (str == "FIVE") return "05";
|
|
|
if (str == "SIX") return "06";
|
|
|
if (str == "SERVEN") return "07";
|
|
|
if (str == "EIGHT") return "08";
|
|
|
if (str == "NINE") return "09";
|
|
|
if (str == "TEN") return "10";
|
|
|
else return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
public static string GetDateStr(string datestr, string dateformat)
|
|
|
{
|
|
|
var result = "";
|
|
|
|
|
|
if (datestr == null || datestr == "")
|
|
|
{
|
|
|
result = "";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result = Convert.ToDateTime(datestr).ToString(dateformat);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
#region 判断中文字符
|
|
|
public static bool IsChinese(char c)
|
|
|
{
|
|
|
return (int)c > 0x80;
|
|
|
}
|
|
|
public static bool StringIsChinese(string str)
|
|
|
{
|
|
|
var result = false;
|
|
|
for (int i = 1; i < str.Length; i++)
|
|
|
{
|
|
|
if (IsChinese(str[i]))
|
|
|
{
|
|
|
result = true;
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
for (int i = 0; i < str.Length; i++)
|
|
|
{
|
|
|
string stemp = str.Substring(i, 1);
|
|
|
int ilen = System.Text.Encoding.Default.GetByteCount(stemp);
|
|
|
if (ilen == 2)
|
|
|
{
|
|
|
result = true;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
public static string formatListStr(List<System.String> DestList, int lineCount, bool isformat = false)
|
|
|
{
|
|
|
var result = "";
|
|
|
for (var i = 0; i < lineCount; i++)
|
|
|
{
|
|
|
if (DestList.Count > i)
|
|
|
{
|
|
|
if (isformat)
|
|
|
result = result + formatEdiStr("txt", DestList[i]);
|
|
|
else
|
|
|
result = result + DestList[i];
|
|
|
}
|
|
|
if (i != (lineCount - 1))
|
|
|
result = result + ":";
|
|
|
|
|
|
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 文本字段判断每行是否符合
|
|
|
/// <summary>
|
|
|
/// edi 文本格式处理判断(例如:1行35个字符不超过5行)
|
|
|
/// </summary>
|
|
|
/// <param name="fileType">文件类型(例如:txt、xml)</param>
|
|
|
/// <param name="str">要处理的数据</param>
|
|
|
/// <param name="length">每行长度</param>
|
|
|
/// <param name="sMBLNO">主提单号</param>
|
|
|
/// <param name="sType">数据类型(例如:发货人内容、货描等)</param>
|
|
|
/// <param name="rowNum">限制录入的行数(“0”代表不限制)</param>
|
|
|
/// <param name="sSymbol">限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等)</param>
|
|
|
/// <returns></returns>
|
|
|
public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao)
|
|
|
{
|
|
|
string error = "";
|
|
|
string Shipping = str;
|
|
|
if (fileType == "txt")
|
|
|
{
|
|
|
Shipping = formatEdiStr("txt", str);
|
|
|
}
|
|
|
else if (fileType == "xml")
|
|
|
{
|
|
|
Shipping = formatEdiStr("txt", str);
|
|
|
}
|
|
|
string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None);
|
|
|
if (argAGENT.Length > 0)
|
|
|
{
|
|
|
if (argAGENT.Length == 1)
|
|
|
{
|
|
|
argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None);
|
|
|
if (argAGENT.Length > 0)
|
|
|
{
|
|
|
if (argAGENT.Length > rowNum && rowNum != 0)
|
|
|
{
|
|
|
if (isHuoMiao)
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)";
|
|
|
}
|
|
|
}
|
|
|
for (int j = 0; j < argAGENT.Length; j++)
|
|
|
{
|
|
|
//List<System.String> AgentList = formatlengthStr(argAGENT[j].ToString(), 35);
|
|
|
if (argAGENT[j].ToString().Length > length)
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (argAGENT.Length > rowNum && rowNum != 0)
|
|
|
{
|
|
|
if (isHuoMiao)
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)";
|
|
|
}
|
|
|
}
|
|
|
for (int j = 0; j < argAGENT.Length; j++)
|
|
|
{
|
|
|
//List<System.String> AgentList = formatlengthStr(argAGENT[j].ToString(), 35);
|
|
|
if (argAGENT[j].ToString().Length > length)
|
|
|
{
|
|
|
error = error + "<br />提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return error;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 字符转义
|
|
|
/// <summary>
|
|
|
/// 各种文本转义字符
|
|
|
/// </summary>
|
|
|
/// <param name="fileType">文件类型(例如:txt、xml)</param>
|
|
|
/// <param name="str">文本字符串</param>
|
|
|
/// <returns></returns>
|
|
|
public static string formatEdiStr(string fileType, string str)
|
|
|
{
|
|
|
if (str == null)
|
|
|
str = string.Empty;
|
|
|
|
|
|
if (fileType == "txt")
|
|
|
{
|
|
|
return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'");
|
|
|
}
|
|
|
else if (fileType == "xml")
|
|
|
{
|
|
|
return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'");
|
|
|
}
|
|
|
else if (fileType == "sitc")
|
|
|
{
|
|
|
return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return str;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
#region 格式化每行
|
|
|
public static List<System.String> formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false)
|
|
|
{
|
|
|
str = str.Replace("\r\n", "\\");
|
|
|
str = str.Replace("\n", "\\");
|
|
|
str = str.Replace("\r", " ");
|
|
|
string[] StrList = str.Split('\\');
|
|
|
var strtemp = "";
|
|
|
var strnewline = "";
|
|
|
var strtempnewline = "";
|
|
|
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
|
|
|
List<System.String> DestList = new List<System.String>();
|
|
|
for (var i = 0; i <= StrList.Length - 1; i++)
|
|
|
{
|
|
|
if (StrList[i].Length <= length)
|
|
|
{
|
|
|
if (formatstr)
|
|
|
DestList.Add(formatEdiStr("txt", StrList[i]));
|
|
|
else
|
|
|
DestList.Add(StrList[i]);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strtemp = StrList[i] + " ";
|
|
|
strtempnewline = "";
|
|
|
strnewline = "";
|
|
|
for (var j = 0; j < strtemp.Length; j++)
|
|
|
{
|
|
|
strtempnewline = strtempnewline + strtemp[j];
|
|
|
if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/'
|
|
|
|| strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-')
|
|
|
{
|
|
|
if ((strnewline.Length + strtempnewline.Length) <= length)
|
|
|
strnewline = strnewline + strtempnewline;
|
|
|
else
|
|
|
{
|
|
|
if (formatstr)
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
else
|
|
|
DestList.Add(strnewline);
|
|
|
strnewline = strtempnewline;
|
|
|
|
|
|
}
|
|
|
strtempnewline = "";
|
|
|
}
|
|
|
}
|
|
|
if (nodelsp)
|
|
|
{
|
|
|
if (formatstr)
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
else DestList.Add(strnewline);
|
|
|
}
|
|
|
else if (strnewline.Trim() != "")
|
|
|
{
|
|
|
if (formatstr)
|
|
|
DestList.Add(formatEdiStr("txt", strnewline));
|
|
|
else DestList.Add(strnewline);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return DestList;
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
#region 检查
|
|
|
public static string IsCreateWYEDI(EDIBaseModel InttrEdi)
|
|
|
{
|
|
|
var error = "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(InttrEdi.SENDCODE))
|
|
|
{ error = error + "<br />发送方代码不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(InttrEdi.SENDNAME))
|
|
|
{ error = error + "<br />发送方名称不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE))
|
|
|
{ error = error + "<br />接收方代码不能为空"; }
|
|
|
|
|
|
//2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写
|
|
|
if (string.IsNullOrEmpty(InttrEdi.ForWarderName))
|
|
|
{ error = error + "<br />货代称呼不能为空"; }
|
|
|
|
|
|
//if (InttrEdi.filetype == "B")
|
|
|
//{
|
|
|
// if (InttrEdi.UseForWarderCode)
|
|
|
// {
|
|
|
// if (string.IsNullOrEmpty(InttrEdi.ForWarderCode))
|
|
|
// { error = error + "<br />货代代码不能为空"; }
|
|
|
|
|
|
// if (string.IsNullOrEmpty(InttrEdi.ForWarderName))
|
|
|
// { error = error + "<br />货代称呼不能为空"; }
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
|
|
|
foreach (var headData in InttrEdi.BSLIST)
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.MBLNO))
|
|
|
{ error = error + "<br />主提单号不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.BLFRT))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 付费方式不能为空"; }
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.ETD))
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(headData.VESSEL))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 船名不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.VOYNO))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 航次不能为空"; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.PORTLOAD))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 装货港不能为空"; }
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; }
|
|
|
if (string.IsNullOrEmpty(headData.PORTDISCHARGE))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 卸货港不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; }
|
|
|
if (string.IsNullOrEmpty(headData.PLACEDELIVERY))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 交货地不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.DESTINATION))
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; }
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; }
|
|
|
if (headData.PKGS == 0)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 件数不能为0"; }
|
|
|
if (headData.KGS == 0)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 毛重不能为0"; }
|
|
|
if (headData.CBM == 0)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 尺码不能为0"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.CARGOID))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 货物标识不能为空"; }
|
|
|
|
|
|
if (headData.CARGOID == "D")
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(headData.DCLASS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 危险品分类不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.DUNNO))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 危险品编号不能为空"; }
|
|
|
}
|
|
|
if (headData.CARGOID == "R")
|
|
|
{
|
|
|
if (headData.TEMPSET == null || headData.TEMPSET == "")
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 设置温度不能为空"; }
|
|
|
if (headData.REEFERF == null || headData.REEFERF == "")
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 通风度不能为空"; }
|
|
|
}
|
|
|
if (headData.ISSUEPLACE == null || headData.ISSUEPLACE == "")
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + "签单地点不能为空"; }
|
|
|
|
|
|
if (headData.CARRIEREDICODE == "APL")
|
|
|
if (headData.ISSUETYPE == null || headData.ISSUETYPE == "")
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + "签单方式不能为空"; }
|
|
|
if (headData.SERVICE == "" || headData.SERVICE == null)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + "运输条款不能为空"; }
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.MARKS))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 唛头不能为空";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (StringIsChinese(headData.MARKS))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.DESCRIPTION))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 货物描述不能为空";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (StringIsChinese(headData.DESCRIPTION))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, "");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.SHIPPER))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 发货人不能为空";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (StringIsChinese(headData.SHIPPER))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (headData.CARRIEREDICODE == "HLCU")
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "*", false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.CONSIGNEE))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 收货人不能为空";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (StringIsChinese(headData.CONSIGNEE))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (headData.CARRIEREDICODE == "HLCU")
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "**", false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(headData.NOTIFYPARTY))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 通知人不能为空";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (StringIsChinese(headData.NOTIFYPARTY))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (headData.CARRIEREDICODE == "HLCU")
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "***", false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2))
|
|
|
{
|
|
|
error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false);
|
|
|
}
|
|
|
|
|
|
var ctnlist = headData.CTNLIST;
|
|
|
if (ctnlist.Count == 0) { error = error + "<br />提单号:" + headData.MBLNO + " 集装箱信息不能为空"; };
|
|
|
|
|
|
#region 集装箱判断检查
|
|
|
if (ctnlist.Count != 0)
|
|
|
{
|
|
|
Decimal dlPKGS = 0;
|
|
|
Decimal dlKGS = 0;
|
|
|
Decimal dlCBM = 0;
|
|
|
foreach (var ctn in ctnlist)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(ctn.CTNALLCODE))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; }
|
|
|
if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R"))
|
|
|
{
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; }
|
|
|
}
|
|
|
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(ctn.CNTRNO))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 箱号不能为空"; }
|
|
|
if (string.IsNullOrEmpty(ctn.SEALNO))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 封号不能为空"; }
|
|
|
|
|
|
if (ctn.KINDPKGS != headData.KINDPKGS)
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; }
|
|
|
dlPKGS += Convert.ToDecimal(ctn.PKGS);
|
|
|
dlKGS += Convert.ToDecimal(ctn.KGS);
|
|
|
dlCBM += Convert.ToDecimal(ctn.CBM);
|
|
|
}
|
|
|
}
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
{
|
|
|
if (dlPKGS != Convert.ToDecimal(headData.PKGS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; }
|
|
|
if (dlKGS != Convert.ToDecimal(headData.KGS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; }
|
|
|
if (dlCBM != Convert.ToDecimal(headData.CBM))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
{
|
|
|
if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0)
|
|
|
{
|
|
|
foreach (var ctn in ctnlist)
|
|
|
{
|
|
|
var isfind = false;
|
|
|
Int32 ctngoodssumpkgs = 0;
|
|
|
decimal ctngoodssumkgs = 0;
|
|
|
decimal ctngoodssumcbm = 0;
|
|
|
headData.CTNGOODSLIST.ForEach(i =>
|
|
|
{
|
|
|
if (i.CNTRNO == ctn.CNTRNO)
|
|
|
{
|
|
|
isfind = true;
|
|
|
ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS;
|
|
|
ctngoodssumkgs = ctngoodssumkgs + i.KGS;
|
|
|
ctngoodssumcbm = ctngoodssumcbm + i.CBM;
|
|
|
}
|
|
|
});
|
|
|
if (!isfind)
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; }
|
|
|
if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; }
|
|
|
if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var ctngood in headData.CTNGOODSLIST)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(ctngood.KINDPKGS))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; }
|
|
|
if (string.IsNullOrEmpty(ctngood.DESCRIPTION))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; }
|
|
|
else
|
|
|
{
|
|
|
error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false);
|
|
|
}
|
|
|
//if (string.IsNullOrEmpty(ctngood.HSCODE))
|
|
|
//{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; }
|
|
|
if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE))
|
|
|
{ error = error + "<br />提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点
|
|
|
//跟韩工确认增加判断
|
|
|
if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(headData.PREPARDAT))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空";
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写";
|
|
|
}
|
|
|
}
|
|
|
else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(headData.PAYABLEAT))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空";
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(headData.PREPARDAT))
|
|
|
{
|
|
|
error = error + "<br />提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return error;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 生成报文(订舱(filetype=="B"),截单(filetype=="E"))
|
|
|
public static CommonWebApiResult CreateEdiWY(EDIBaseModel InttrEdi)
|
|
|
{
|
|
|
CommonWebApiResult result = new CommonWebApiResult { succ = false };
|
|
|
|
|
|
var filetype = "IFTMBF";
|
|
|
|
|
|
string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
|
|
|
|
|
|
//如果是部署linux需要修改路径
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
filename = filename.Replace("\\", "/");
|
|
|
|
|
|
//if (System.IO.File.Exists(filename))
|
|
|
//{
|
|
|
// System.IO.File.Delete(filename);
|
|
|
//}
|
|
|
FileStream f = new FileStream(filename, FileMode.Create);
|
|
|
StreamWriter r = new StreamWriter(f, Encoding.Default);
|
|
|
var icount = 0;
|
|
|
var bsno = "";
|
|
|
var isfirst = true;
|
|
|
foreach (var bill in InttrEdi.BSLIST)
|
|
|
{
|
|
|
if (isfirst)
|
|
|
{
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
r.WriteLine("00:IFTMBF:SI:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'");
|
|
|
else
|
|
|
r.WriteLine("00:IFTMBF:BK:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'");
|
|
|
isfirst = false;
|
|
|
icount++;
|
|
|
|
|
|
}
|
|
|
//2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认
|
|
|
r.WriteLine("02"
|
|
|
+ ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M
|
|
|
+ ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C
|
|
|
+ ":" + bill.SERVICEEDICODE//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
|
|
|
+ ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M
|
|
|
+ ":"//7 ISSUE PARTY 签单人说明 X(35) C
|
|
|
+ ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C
|
|
|
+ ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C
|
|
|
+ ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C
|
|
|
+ ":"//11 BATCH ID 分批 X(1) Y/N C
|
|
|
+ ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C
|
|
|
+ ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C
|
|
|
+ ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C
|
|
|
+ ":"//15 CHARGE TYPE 费率本代码 X(1) C
|
|
|
+ ":" //16 S/C NO. 合约号 X(30) C
|
|
|
+ "'");
|
|
|
|
|
|
icount++;
|
|
|
|
|
|
var ISSUETYPE = "";
|
|
|
|
|
|
//2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX
|
|
|
//if (bill.ISSUETYPE == "正本")
|
|
|
if (bill.ISSUETYPE == "ORIGINAL")
|
|
|
{
|
|
|
ISSUETYPE = "ORI";
|
|
|
}
|
|
|
else if (bill.ISSUETYPE == "TELEX")
|
|
|
{
|
|
|
ISSUETYPE = "TER";
|
|
|
}
|
|
|
else ISSUETYPE = "EXP";
|
|
|
|
|
|
|
|
|
|
|
|
r.WriteLine("03:" + ISSUETYPE + ":" + bill.ISSUEPLACEID.Trim() + ":" + bill.ISSUEPLACE.Trim() + ":" + GetDateStr(bill.ISSUEDATE, "yyyyMMdd") + ":" + GetBillNum2(bill.NOBILL) + ":" + bill.PREPARDAT + ":" + bill.PAYABLEAT + "'");
|
|
|
icount++;
|
|
|
|
|
|
|
|
|
r.WriteLine("11:" + bill.VESSELID + ":" + bill.VESSEL + ":" + bill.VOYNO + "::" + bill.CARRIEREDICODE + ":" + bill.CARRIER + ":::::::'");
|
|
|
icount++;
|
|
|
|
|
|
var DESTINATIONID = bill.DESTINATIONID;
|
|
|
var DESTINATION = bill.DESTINATION;
|
|
|
if (bill.CARRIEREDICODE == "ONEY" || bill.CARRIEREDICODE == "ZIM")
|
|
|
{
|
|
|
DESTINATIONID = "";
|
|
|
DESTINATION = "";
|
|
|
}
|
|
|
|
|
|
r.WriteLine("12"
|
|
|
+ ":" + bill.PLACERECEIPTID//2 PLACE CODE OF RECEIPT 收货地代码 X(5) OOCL、HLC的订舱要求必选 O
|
|
|
+ ":" + bill.PLACERECEIPT//3 PLACE OF RECEIPT 收货地 X(35) C
|
|
|
+ ":" + bill.PORTLOADID//4 LOAD PORT CODE 装货港代码 X(5) OOCL的订舱要求必选 O
|
|
|
+ ":" + bill.PORTLOAD//5 LOAD PORT 装货港 X(35) C
|
|
|
+ ":" + bill.PORTDISCHARGEID//6 DISCHARGE PORT CODE 卸货港代码 X(5) OOCL的订舱要求必选 M
|
|
|
+ ":" + bill.PORTDISCHARGE//7 DISCHARGE PORT 卸货港 X(35) C
|
|
|
+ ":" + bill.TRANSPORTID //8 TRANSFER PORT CODE 中转港代码 X(5) C
|
|
|
+ ":" + bill.TRANSPORT//9 TRANSFER PORT 中转港 X(35) C
|
|
|
+ ":" + bill.PLACEDELIVERYID//10 PLACE OF DELIVERY CODE 交货地代码 X(5) OOCL的订舱要求必选 O
|
|
|
+ ":" + bill.PLACEDELIVERY//11 PLACE OF DELIVERY 交货地 X(35) C
|
|
|
+ ":" + DESTINATIONID//12 FINAL DESTINATION CODE 目的地代码 X(5) C
|
|
|
+ ":" + DESTINATION//13 FINAL DESTINATION CODE 目的地 X(35) C
|
|
|
+ ":" + bill.YARDEDICODE//14 FINAL DESTINATION CODE 目的地 X(35) C
|
|
|
+ "'");
|
|
|
|
|
|
icount = icount + 1;
|
|
|
|
|
|
r.WriteLine("14:" + bill.BLFRTEDICODE + ":" + bill.BLFRT + "'");
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
r.WriteLine("15:::" + bill.BLFRTEDICODE + ":" + bill.PAYABLEATID + ":::::'");
|
|
|
else
|
|
|
r.WriteLine("15:::" + bill.BLFRTEDICODE + "::::::'");
|
|
|
icount = icount + 2;
|
|
|
|
|
|
|
|
|
var Shipping = "";
|
|
|
if (InttrEdi.filetype == "E")
|
|
|
Shipping = formatEdiStr("txt", bill.SIREMARK);
|
|
|
else
|
|
|
Shipping = formatEdiStr("txt", bill.EDIREMARK);
|
|
|
|
|
|
List<System.String> ShippingList = formatlengthStr(Shipping, 70);
|
|
|
|
|
|
if (Shipping != "")
|
|
|
{
|
|
|
r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'");
|
|
|
icount++;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Shipping = formatEdiStr("txt", bill.SHIPPER);
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
{
|
|
|
r.WriteLine("18::" + formatListStr(ShippingList, 6) + "'");
|
|
|
icount = icount + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Shipping = formatEdiStr("txt", bill.CONSIGNEE);
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
{
|
|
|
r.WriteLine("19::" + formatListStr(ShippingList, 6) + "'");
|
|
|
icount = icount + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Shipping = formatEdiStr("txt", bill.NOTIFYPARTY);
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
{
|
|
|
r.WriteLine("20::" + formatListStr(ShippingList, 6) + "'");
|
|
|
icount = icount + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Shipping = formatEdiStr("txt", InttrEdi.ForWarderName);
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
|
if (Shipping != "")
|
|
|
{
|
|
|
|
|
|
r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'");
|
|
|
icount = icount + 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
var ctnsumlist = new List<MsOpSeaeCtnEDIBaseModel>();
|
|
|
foreach (var ctn in bill.CTNLIST)
|
|
|
{
|
|
|
var isfind = false;
|
|
|
ctnsumlist.ForEach(i =>
|
|
|
{
|
|
|
if (i.CTNALLCODE == ctn.CTNALLCODE)
|
|
|
{
|
|
|
i.CTNNUM = i.CTNNUM + ctn.CTNNUM;
|
|
|
isfind = true;
|
|
|
}
|
|
|
});
|
|
|
if (!isfind)
|
|
|
{
|
|
|
var ctnnum = new MsOpSeaeCtnEDIBaseModel();
|
|
|
ctnnum.CTNALLCODE = ctn.CTNALLCODE;
|
|
|
ctnnum.CTNNUM = ctn.CTNNUM;
|
|
|
ctnsumlist.Add(ctnnum);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (var ctnsum in ctnsumlist)
|
|
|
{
|
|
|
r.WriteLine("40:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::N'");
|
|
|
icount++;
|
|
|
}
|
|
|
|
|
|
|
|
|
var cargoid = bill.CARGOID;
|
|
|
if (cargoid == "" || cargoid == " ") cargoid = "S";
|
|
|
|
|
|
var kingweight = bill.KINGTAREWEIGHT;
|
|
|
if (kingweight == 0)
|
|
|
kingweight = 100;
|
|
|
|
|
|
r.WriteLine("41:1:" + bill.HSCODE + ":" + cargoid + ":" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + ":" + bill.KINDPKGS + ":" + kingweight.ToString("0.###") + ":"
|
|
|
+ bill.CBM.ToString("0.###") + "::::::" + bill.KGS.ToString("0.###") + ":::'");
|
|
|
|
|
|
icount = icount + 1;
|
|
|
if (cargoid == "R")
|
|
|
r.WriteLine("43::::::::::" + bill.REEFERF + ":C:" + bill.TEMPSET + ":" + bill.TEMPMIN + ":" + bill.TEMPMAX + ":::::'");
|
|
|
else if (cargoid == "D")
|
|
|
r.WriteLine("43:" + bill.DCLASS + ":" + bill.DPAGE + ":" + bill.DUNNO + ":" + bill.DLABEL + "::::::::::::'");
|
|
|
|
|
|
icount = icount + 1;
|
|
|
|
|
|
|
|
|
Shipping = formatEdiStr("txt", bill.MARKS);
|
|
|
ShippingList = formatlengthStr(Shipping, 35);
|
|
|
|
|
|
for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(10))); i++)
|
|
|
{
|
|
|
var tempstr = "44:";
|
|
|
for (var z = 0; z < 10; z++)
|
|
|
{
|
|
|
if ((i * 10 + z) < ShippingList.Count)
|
|
|
tempstr = tempstr + ShippingList[i * 10 + z];
|
|
|
if (z < 9) tempstr = tempstr + ":";
|
|
|
}
|
|
|
if (tempstr != "44:")
|
|
|
{
|
|
|
r.WriteLine(tempstr + "'");
|
|
|
icount++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Shipping = formatEdiStr("txt", bill.DESCRIPTION);
|
|
|
ShippingList = formatlengthStr(Shipping, 70);
|
|
|
|
|
|
var m = 1;
|
|
|
var strtemp = "";
|
|
|
if (ShippingList.Count != 0 && Shipping.Length > 0)
|
|
|
{
|
|
|
|
|
|
for (var i = 0; i < ShippingList.Count; i++)
|
|
|
{
|
|
|
if (ShippingList[i] != "")
|
|
|
{
|
|
|
if (m <= 5)
|
|
|
{
|
|
|
if (m == 1) strtemp = "47:" + ShippingList[i] + ":";
|
|
|
else
|
|
|
{
|
|
|
if (m == 5)
|
|
|
strtemp = strtemp + ShippingList[i];
|
|
|
else
|
|
|
strtemp = strtemp + ShippingList[i] + ":";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m = 1;
|
|
|
r.WriteLine(strtemp + "'");
|
|
|
strtemp = "47:" + ShippingList[i] + ":";
|
|
|
icount = icount + 1;
|
|
|
}
|
|
|
m = m + 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (strtemp != "")
|
|
|
{
|
|
|
r.WriteLine(strtemp + "'");
|
|
|
icount = icount + 1;
|
|
|
}
|
|
|
|
|
|
var ISSOC = "N";
|
|
|
if (bill.ISCONTAINERSOC) ISSOC = "Y";
|
|
|
foreach (var ctn in bill.CTNLIST)
|
|
|
{
|
|
|
r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + ctn.SEALNO + ":::" + ctn.CTNSTATUS + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + ":" + ctn.TAREWEIGHT.ToString("0.###") + ":" + ctn.CBM.ToString("0.###") + "'");
|
|
|
icount = icount + 1;
|
|
|
}
|
|
|
}
|
|
|
icount = icount + 1;
|
|
|
r.WriteLine("99:" + icount.ToString() + "'");
|
|
|
r.Close();
|
|
|
f.Close();
|
|
|
|
|
|
result.succ = true;
|
|
|
result.extra = filename;
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|