using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Myshipping.Application.EDI.YML { public class YMLEdiHelper { public YMLEdiHelper() { } #region 基本函数 public static string GetBillNum(string str) { if (str == "ZERO") return "0"; if (str == "ONE") return "1"; if (str == "TWO") return "2"; if (str == "THREE") return "3"; if (str == "FOUR") return "4"; if (str == "FIVE") return "5"; if (str == "SIX") return "6"; if (str == "SERVEN") return "7"; if (str == "EIGHT") return "8"; if (str == "NINE") return "9"; if (str == "TEN") return "10"; else return ""; } 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 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 文本字段判断每行是否符合 /// /// edi 文本格式处理判断(例如:1行35个字符不超过5行) /// /// 文件类型(例如:txt、xml) /// 要处理的数据 /// 每行长度 /// 主提单号 /// 数据类型(例如:发货人内容、货描等) /// 限制录入的行数(“0”代表不限制) /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) /// 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 + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; } else { error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; } } for (int j = 0; j < argAGENT.Length; j++) { //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); if (argAGENT[j].ToString().Length > length) { error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; } } } } else { if (argAGENT.Length > rowNum && rowNum != 0) { if (isHuoMiao) { error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; } else { error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; } } for (int j = 0; j < argAGENT.Length; j++) { //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); if (argAGENT[j].ToString().Length > length) { error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; } } } } return error; } #endregion #region 字符转义 /// /// 各种文本转义字符 /// /// 文件类型(例如:txt、xml) /// 文本字符串 /// public static string formatEdiStr(string fileType, string str) { 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 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 DestList = new List(); 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 IsCreateYMLEDI(MsYMLEdiModel InttrEdi) { var error = ""; if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) { error = error + "
发送方代码不能为空"; } if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) { error = error + "
发送方名称不能为空"; } if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) { error = error + "
接收方代码不能为空"; } //if (InttrEdi.filetype == "B") //{ // if (InttrEdi.UseForWarderCode) // { // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) // { error = error + "
货代代码不能为空"; } // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) // { error = error + "
货代称呼不能为空"; } // } //} foreach (var headData in InttrEdi.BSLIST) { if (InttrEdi.filetype != "B") if (string.IsNullOrEmpty(headData.MBLNO)) { error = error + "
主提单号不能为空"; } if (string.IsNullOrEmpty(headData.BLFRT)) { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } if (string.IsNullOrEmpty(headData.EDIATTN)) { error = error + "
提单号:" + headData.MBLNO + " EDI联系人不能为空"; } if (string.IsNullOrEmpty(headData.EDIATTNTEL)) { error = error + "
提单号:" + headData.MBLNO + " EDI联系人电话不能为空"; } if (string.IsNullOrEmpty(headData.EDIATTNEMAIL)) { error = error + "
提单号:" + headData.MBLNO + " EDI联系人邮编不能为空"; } if (InttrEdi.filetype == "E") { if (string.IsNullOrEmpty(headData.VESSELID)) { error = error + "
提单号:" + headData.MBLNO + " 船舶呼号不能为空"; } if (InttrEdi.filetype != "B" || headData.CARRIEREDICODE == "YML") { if (string.IsNullOrEmpty(headData.ETD)) { error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; return error; } } } if (string.IsNullOrEmpty(headData.PLACERECEIPTID) || headData.PLACERECEIPTID.Length != 5) { error = error + "
提单号:" + headData.MBLNO + " 收货地代码不能为空或录入不正确(必须是5位代码)"; } if (string.IsNullOrEmpty(headData.PLACERECEIPT)) { error = error + "
提单号:" + headData.MBLNO + " 收货地不能为空"; } if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } if (string.IsNullOrEmpty(headData.PORTLOAD)) { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5) { error = error + "
提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; } if (string.IsNullOrEmpty(headData.PLACEDELIVERY)) { error = error + "
提单号:" + headData.MBLNO + " 交货地不能为空"; } if (string.IsNullOrEmpty(headData.DESTINATION)) { if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } } if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } if (headData.PKGS == 0) { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } if (headData.KGS == 0) { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } if (headData.CBM == 0) { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } if (string.IsNullOrEmpty(headData.CARGOID)) { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } if (headData.CARGOID == "D") { if (string.IsNullOrEmpty(headData.DCLASS)) { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } if (string.IsNullOrEmpty(headData.DUNNO)) { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } } if (headData.CARGOID == "R") { if (headData.TEMPSET == null || headData.TEMPSET == "") { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } if (headData.REEFERF == null || headData.REEFERF == "") { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } } if (headData.ISSUEPLACE == null || headData.ISSUEPLACE == "") { error = error + "
提单号:" + headData.MBLNO + "签单地点不能为空"; } if (headData.CARRIEREDICODE == "APL") if (headData.ISSUETYPE == null || headData.ISSUETYPE == "") { error = error + "
提单号:" + headData.MBLNO + "签单方式不能为空"; } if (headData.SERVICE == "" || headData.SERVICE == null) { error = error + "
提单号:" + headData.MBLNO + "运输条款不能为空"; } if (string.IsNullOrEmpty(headData.MARKS)) { error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; } else { if (StringIsChinese(headData.MARKS)) { error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; } else { error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); } } if (string.IsNullOrEmpty(headData.DESCRIPTION)) { error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; } else { if (StringIsChinese(headData.DESCRIPTION)) { error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; } else { //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); } } if (string.IsNullOrEmpty(headData.SHIPPER)) { error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; } else { if (StringIsChinese(headData.SHIPPER)) { error = error + "
提单号:" + 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 + "
提单号:" + headData.MBLNO + " 收货人不能为空"; } else { if (StringIsChinese(headData.CONSIGNEE)) { error = error + "
提单号:" + 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 + "
提单号:" + headData.MBLNO + " 通知人不能为空"; } else { if (StringIsChinese(headData.NOTIFYPARTY)) { error = error + "
提单号:" + 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 + "
提单号:" + 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 + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R")) { { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } } if (InttrEdi.filetype == "E") { if (string.IsNullOrEmpty(ctn.CNTRNO)) { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } if (string.IsNullOrEmpty(ctn.SEALNO)) { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } if (ctn.KINDPKGS != headData.KINDPKGS) { error = error + "
提单号:" + 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 + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } if (dlKGS != Convert.ToDecimal(headData.KGS)) { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } if (dlCBM != Convert.ToDecimal(headData.CBM)) { error = error + "
提单号:" + 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 + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; } else { if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } } } foreach (var ctngood in headData.CTNGOODSLIST) { if (string.IsNullOrEmpty(ctngood.KINDPKGS)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } else { error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); } //if (string.IsNullOrEmpty(ctngood.HSCODE)) //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } } } #endregion } } return error; } #endregion #region 生成报文(订舱) public static string CreateEdiYML(MsYMLEdiModel InttrEdi) { var filetype = "IFTMBF"; string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; 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) { r.WriteLine("00:IFTMBF:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); isfirst = false; icount++; } r.WriteLine("02" + ":" + 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 + ":" + InttrEdi.SENDNAME//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 + "'"); icount++; var ISSUETYPE = ""; if (bill.ISSUETYPE == "正本") { ISSUETYPE = "ORI"; } else if (bill.ISSUETYPE == "电放") { 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 + ":::::" + GetDateStr(bill.ETD, "yyyyMMdd") + ":::::'"); icount++; var DESTINATIONID = bill.DESTINATIONID; var DESTINATION = bill.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 + "'"); 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 = ""; Shipping = formatEdiStr("txt", bill.EDIREMARK); List 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) { if (!string.IsNullOrEmpty(bill.ERNCODE) || !string.IsNullOrEmpty(bill.VAECODE) || !string.IsNullOrEmpty(bill.FECCODE)) { r.WriteLine("20::" + formatListStr(ShippingList, 9) + ":" + bill.ERNCODE + ":" + bill.VAECODE + ":" + bill.FECCODE + "'"); } else r.WriteLine("20::" + formatListStr(ShippingList, 9) + "'"); icount = icount + 1; } Shipping = formatEdiStr("txt", bill.CONSIGNEE); ShippingList = formatlengthStr(Shipping, 35); if (ShippingList.Count != 0 && Shipping.Length > 0) { if (!string.IsNullOrEmpty(bill.TACCODE)) { r.WriteLine("21::" + formatListStr(ShippingList, 9) + ":" + bill.TACCODE + "'"); } else r.WriteLine("21::" + formatListStr(ShippingList, 9) + "'"); icount = icount + 1; } Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); ShippingList = formatlengthStr(Shipping, 35); if (ShippingList.Count != 0 && Shipping.Length > 0) { r.WriteLine("22::" + formatListStr(ShippingList, 6) + "'"); icount = icount + 1; } Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); ShippingList = formatlengthStr(Shipping, 35); if (Shipping != "") { r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); icount = icount + 1; } r.WriteLine("24" + ":" + bill.EDIATTN// 2 BOOKING ISSUER 訂艙聯絡人 X(60) C + ":" + bill.EDIATTNEMAIL//3 EMAIL ADDRESS 訂艙聯絡人e-mail X(80) 若有給e-mail address, 在收到客戶 EDI 後, 系統會發回擲信給該 e-mail 做為確認. C + ":" + bill.EDIATTNTEL//4 TEL NO 訂艙聯絡人電話 X(80) C + "'"); 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() + ":" + bill.CBM.ToString() + "::::::" + bill.KGS.ToString() + ":::'"); 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"; var ctnsumlist = new List(); foreach (var ctn in bill.CTNLIST) { var newctnsum = ctnsumlist.Find(x => x.CTNALLCODE == ctn.CTNALLCODE); if (newctnsum == null) { var ctnsum = new MsOpSeaeCtnEdiModel(); ctnsum.CTNALLCODE = ctn.CTNALLCODE; ctnsum.CTNNUM = ctn.CTNNUM; if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) { if (!string.IsNullOrEmpty(ctnsum.CNTRNO)) { ctnsum.CNTRNO = ctn.CNTRNO; } else { ctnsum.CNTRNO = ctnsum.CNTRNO + "," + ctn.CNTRNO; } } ctnsumlist.Add(ctnsum); } else { newctnsum.CTNNUM = newctnsum.CTNNUM + ctn.CTNNUM; if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) { if (!string.IsNullOrEmpty(newctnsum.CNTRNO)) { newctnsum.CNTRNO = ctn.CNTRNO; } else { newctnsum.CNTRNO = newctnsum.CNTRNO + "," + ctn.CNTRNO; } } } } foreach (var ctnsum in ctnsumlist) { if (InttrEdi.filetype == "E") { r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + "'"); icount = icount + 1; } else { var cntrnostr = ""; var isrstr = "N"; if (cargoid == "R") isrstr = "Y"; r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + ":" + cntrnostr + ":::" + isrstr + "'"); icount = icount + 1; } } } icount = icount + 1; r.WriteLine("99:" + icount.ToString() + "'"); r.Close(); f.Close(); return filename; } #endregion #region 生成报文(确认) public static string CreateEdiYMLSI(MsYMLEdiModel InttrEdi) { string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; 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 = ""; foreach (var bill in InttrEdi.BSLIST) { bsno = bill.ORDERNO; r.WriteLine("UNB+UNOA:1+" + InttrEdi.SENDCODE + ":ZZZ+" + InttrEdi.RECEIVECODE + ":ZZZ+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMIN:D:99B:UN'"); var BGMSTR = ""; if (bill.ISSUETYPE == "正本") { BGMSTR = "705"; } else { BGMSTR = "712"; } if (InttrEdi.filerole == "9") r.WriteLine("BGM+" + BGMSTR + "+" + bill.MBLNO + "+9'"); else r.WriteLine("BGM+" + BGMSTR + "+" + bill.MBLNO + "+5'"); if (bill.SERVICE.ToUpper() == "DOOR-DOOR") { r.WriteLine("TSR+27+2'"); } else if (bill.SERVICE.ToUpper() == "DOOR-CY") { r.WriteLine("TSR+28+2'"); } else if (bill.SERVICE.ToUpper() == "CY-DOOR") { r.WriteLine("TSR+29+2'"); } else { r.WriteLine("TSR+30+2'"); } var str_pay = ""; if (bill.BLFRT.IndexOf("PREPAID") >= 0) str_pay = bill.PREPARDAT; if (bill.BLFRT.IndexOf("COLLECT") >= 0) str_pay = bill.PAYABLEAT; //r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " // + bill.PKGS.ToString() + bill.KINDPKGS + "'"); icount = icount + 4; var Shipping = ""; Shipping = formatEdiStr("txt", bill.SIREMARK); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] EdiRemarkList = Shipping.Split('\\'); if (EdiRemarkList.Length != 0) { for (var i = 0; i < EdiRemarkList.Length; i++) { r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); icount = icount + 1; } } if (bill.BYCOUNTRY == "USA") { if (bill.SCACCODE != "") r.WriteLine("FTX+CCI++MFS+1:US:" + bill.SCACCODE + "'"); else r.WriteLine("FTX+CCI++MFS+5:US'"); icount = icount + 1; } else if (bill.BYCOUNTRY == "CANADA") { if (bill.SCACCODE != "") r.WriteLine("FTX+CCI++MFS+1:CA:" + bill.SCACCODE + "'"); else r.WriteLine("FTX+CCI++MFS+5:CA'"); icount = icount + 1; } r.WriteLine("CNT+7:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + ":KGM'"); r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); r.WriteLine("CNT+15:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + ":MTQ'"); icount = icount + 3; if (bill.CARRIEREDICODE == "UASC") { if (bill.CTNLIST.Count > 0) { var ctnnum = 0; foreach (var ctn in bill.CTNLIST) { ctnnum = ctnnum + ctn.CTNNUM; } r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); icount = icount + 1; } } if (bill.BLFRT == "FREIGHT COLLECT") { if (bill.PAYABLEAT != "") { r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); icount = icount + 1; } } else { r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); icount = icount + 1; } r.WriteLine("LOC+73+" + bill.ISSUEPLACEID + "::6:" + bill.ISSUEPLACE + "'"); icount = icount + 1; r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); icount = icount + 1; r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); r.WriteLine("RFF+CT:" + bill.CONTRACTNO + "'"); icount = icount + 2; if (bill.CARRIEREDICODE == "UASC") { r.WriteLine("RFF+SI:" + bill.ORDERNO + "'"); icount = icount + 1; } if (bill.BYCOUNTRY == "USA") { r.WriteLine("REF+TN:" + bill.ITNCODE + "'"); icount = icount + 1; } if (bill.BLFRT.IndexOf("PREPAID") >= 0) r.WriteLine("CPI+4++P'"); else if (bill.BLFRT.IndexOf("COLLECT") >= 0) r.WriteLine("CPI+4++C'"); else r.WriteLine("CPI+4++B'"); icount = icount + 1; var voyno = ""; if (bill.VOYNO.IndexOf(".") >= 0) { voyno = bill.VOYNO.Substring(bill.VOYNO.IndexOf(".") + 1, bill.VOYNO.Length - bill.VOYNO.IndexOf(".") - 1); } else { voyno = bill.VOYNO; } r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + "+++:::" + bill.VESSEL + "'"); r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); icount = icount + 4; if (bill.DESTINATION != "") { r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); icount = icount + 1; } var DescriptionShipper = ""; Shipping = formatEdiStr("txt", bill.SHIPPER); List ShippingList = formatlengthStr(Shipping, 35); if (ShippingList.Count != 0 && Shipping.Length > 0) { for (var i = 0; i < ShippingList.Count; i++) { if (i == 0) Shipping = "NAD+CZ+++" + ShippingList[0] + "+"; if (i == 1) Shipping = Shipping + ShippingList[i]; if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; if (i >= 4 && ShippingList.Count > 5) { if (i == 4) { if (ShippingList[i].Length > 34) { Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); DescriptionShipper = ShippingList[i].Substring(34); } else Shipping = Shipping + ":" + ShippingList[i]; if (bill.CARRIEREDICODE == "HLCU") { Shipping = Shipping + "-"; DescriptionShipper = "-" + DescriptionShipper; } else { Shipping = Shipping + "*"; DescriptionShipper = "*" + DescriptionShipper; } } else if (i > 4) { DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; } } else if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; } } r.WriteLine(Shipping + "'"); icount = icount + 1; Shipping = formatEdiStr("txt", bill.CONSIGNEE); ShippingList = formatlengthStr(Shipping, 35); var DescriptionConsignee = ""; if (ShippingList.Count != 0 && Shipping.Length > 0) { for (var i = 0; i < ShippingList.Count; i++) { if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; if (i == 1) Shipping = Shipping + ShippingList[i]; if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; if (i >= 4 && ShippingList.Count > 5) { if (i == 4) { if (ShippingList[i].Length > 33) { Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); DescriptionConsignee = ShippingList[i].Substring(33); } else Shipping = Shipping + ":" + ShippingList[i]; if (bill.CARRIEREDICODE == "HLCU") { Shipping = Shipping + "--"; DescriptionConsignee = "--" + DescriptionConsignee; } else { Shipping = Shipping + "**"; DescriptionConsignee = "**" + DescriptionConsignee; } } else if (i > 4) { DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; } } else if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; } } if (bill.BYCOUNTRY == "USA") { Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE; r.WriteLine(Shipping + "'"); } else if (bill.BYCOUNTRY == "CANADA") { Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE + "+CA"; r.WriteLine(Shipping + "'"); } else if (bill.BYCOUNTRY == "BRAZIL") { Shipping = Shipping + "++++" + bill.CONSIGNEECOUNTRY; r.WriteLine(Shipping + "'"); r.WriteLine("RFF+GN:" + bill.CONSIGNEETAXNO + "'"); icount = icount + 1; } else r.WriteLine(Shipping + "'"); icount = icount + 1; if (bill.WEITUO != "") { if (bill.WEITUO.Length > 35) r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO.Substring(0, 35)) + "+" + formatEdiStr("txt", bill.WEITUO.Substring(35)) + "'"); else r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); } else { if (InttrEdi.UseForWarderCode) { r.WriteLine("NAD+FW+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); icount++; } else { if (InttrEdi.SENDNAME.Length > 35) r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); else r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); } } icount++; Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); ShippingList = formatlengthStr(Shipping, 35); var DescriptionNotifyparty = ""; if (ShippingList.Count != 0 && Shipping.Length > 0) { for (var i = 0; i < ShippingList.Count; i++) { if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; if (i == 1) Shipping = Shipping + ShippingList[i]; if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; if (i >= 4 && ShippingList.Count > 5) { if (i == 4) { if (ShippingList[i].Length > 32) { Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); DescriptionNotifyparty = ShippingList[i].Substring(32); } else Shipping = Shipping + ":" + ShippingList[i]; if (bill.CARRIEREDICODE == "HLCU") { Shipping = Shipping + "---"; DescriptionNotifyparty = "---" + DescriptionNotifyparty; } else { Shipping = Shipping + "***"; DescriptionNotifyparty = "***" + DescriptionNotifyparty; } } else if (i > 4) { DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; } } else if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; } } if (bill.BYCOUNTRY == "USA") { Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; r.WriteLine(Shipping + "'"); } else if (bill.BYCOUNTRY == "BRAZIL") { if (bill.NOTIFYPARTYCOUNTRY != "") Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; r.WriteLine(Shipping + "'"); if (bill.NOTIFYPARTYTAXNO != "") { r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); icount = icount + 1; } } else r.WriteLine(Shipping + "'"); icount = icount + 1; Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); ShippingList = formatlengthStr(Shipping, 35); if (ShippingList.Count != 0 && Shipping.Length > 0) { for (var i = 0; i < ShippingList.Count; i++) { if (i == 0) Shipping = "NAD+N1+++" + ShippingList[0] + "+"; if (i == 1) Shipping = Shipping + ShippingList[i]; if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; } r.WriteLine(Shipping + "'"); } r.WriteLine("NAD+CA+YMLU:160:86++YML'"); if (InttrEdi.SENDNAME.Length > 35) r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); else r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); icount = icount + 5; var copynum = GetBillNum(bill.COPYNOBILL); if (bill.ISSUETYPE == "正本") { r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); icount = icount + 1; if (copynum != "") { r.WriteLine("DOC+707+++" + copynum + "'"); icount = icount + 1; } } else if (bill.ISSUETYPE == "海运单" || bill.ISSUETYPE.ToUpper() == "SEAWAY" || bill.ISSUETYPE.ToUpper() == "SEAWAY BILL" || bill.ISSUETYPE.ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToUpper() == "SWB正本" || bill.ISSUETYPE.ToUpper() == "SWB无正本") { r.WriteLine("DOC+710+++" + GetBillNum(bill.NOBILL) + "'"); icount = icount + 1; } else if (bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "电放") { r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); icount = icount + 1; if (copynum != "") { r.WriteLine("DOC+707+++" + copynum + "'"); icount = icount + 1; } } else if (bill.ISSUETYPE == "正副本") { r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); icount = icount + 1; if (copynum != "") { r.WriteLine("DOC+707+++" + copynum + "'"); icount = icount + 1; } } else if (bill.ISSUETYPE.ToUpper() == "HOUSE BILL") { r.WriteLine("DOC+714+++" + GetBillNum(bill.NOBILL) + "'"); icount = icount + 1; } //判断集装箱是否包含分箱明细 if (bill.CTNGOODSLIST == null || bill.CTNGOODSLIST.Count == 0) { #region 取委托单货描、唛头信息 r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); icount = icount + 1; if (bill.HSCODE != "") { r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); icount = icount + 1; } Shipping = formatEdiStr("txt", bill.DESCRIPTION); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] DescriptionList = Shipping.Split('\\'); if (DescriptionList.Length != 0) { for (var i = 0; i < DescriptionList.Length; i++) { //if (DescriptionList[i] != "") //{ r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); icount = icount + 1; //} } } if (DescriptionShipper != "") { r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); icount = icount + 1; } if (DescriptionConsignee != "") { r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); icount = icount + 1; } if (DescriptionNotifyparty != "") { r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); icount = icount + 1; } r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + "'"); r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + "'"); icount = icount + 2; if (!string.IsNullOrEmpty(bill.GOODSNCM)) { r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); icount = icount + 1; } Shipping = formatEdiStr("txt", bill.MARKS); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] MarksList = Shipping.Split('\\'); if (MarksList.Length != 0) { for (var i = 0; i < MarksList.Length; i++) { //if (MarksList[i] != "") //{ r.WriteLine("PCI++" + MarksList[i] + "'"); icount = icount + 1; //} } } foreach (var ctn in bill.CTNLIST) { r.WriteLine("SGP+" + ctn.CNTRNO + "+" + ctn.PKGS.ToString() + "'"); r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); icount = icount + 3; } #endregion } else { if (bill.CARRIEREDICODE == "UASC" || bill.CARRIEREDICODE == "HLCU" || bill.CARRIEREDICODE == "CMDU") { #region 取集装箱分箱_货描、唛头信息 if (bill.CTNGOODSLIST != null) { if (bill.CTNGOODSLIST.Count > 0) { var i = 0; foreach (var ctngood in bill.CTNGOODSLIST) { //GID+1+400:CT::6:CARTONS' r.WriteLine("GID+" + (i + 1) + "+" + ctngood.PKGS.ToString() + ":" + ctngood.KINDPKGS_EDI_CODE + "::6:" + ctngood.KINDPKGS + "'"); icount++; //PIA+5+HS_CODE1:HS' r.WriteLine("PIA+5+" + ctngood.HSCODE + ":HS'"); icount++; //FTX+AAA+++MATERIAL 1' //FTX+AAA+++HS-NO 39023012' Shipping = formatEdiStr("txt", ctngood.DESCRIPTION); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] DescriptionList = Shipping.Split('\\'); if (DescriptionList.Length != 0) { for (var j = 0; j < DescriptionList.Length; j++) { r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); icount++; } } //MEA+AAE+WT+KGM:3000' //MEA+AAE+AAW+MTQ:110.11' r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); icount++; r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); icount++; //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' //if (isbill != 1) //{ // Shipping = formatEdiStr("txt", bill.MARKS); //} //else //{ Shipping = formatEdiStr("txt", ctngood.MARKS); //} if (string.IsNullOrEmpty(ctngood.MARKS)) Shipping = formatEdiStr("txt", bill.MARKS); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] MarksList = Shipping.Split('\\'); if (MarksList.Length != 0) { for (var j = 0; j < MarksList.Length; j++) { r.WriteLine("PCI++" + MarksList[j] + "'"); icount++; } } if (!string.IsNullOrEmpty(bill.GOODSNCM)) { r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); icount++; } // //SGP+MSCU1234567+100' r.WriteLine("SGP+" + ctngood.CNTRNO + "+" + ctngood.PKGS.ToString() + "'"); //MEA+AAE+WT+KGM:1000' r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); //MEA+AAE+AAW+MTQ:50.11' r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); icount = icount + 3; i = i + 1; } } } #endregion } else { #region 取集装箱分箱_货描、唛头信息 var ctngoodssumlist = new List(); foreach (var ctn in bill.CTNGOODSLIST) { var isfind = false; ctngoodssumlist.ForEach(i => { if (i.HSCODE == ctn.HSCODE && i.KINDPKGS == ctn.KINDPKGS && i.DESCRIPTION == ctn.DESCRIPTION && i.MARKS == ctn.MARKS) { i.PKGS = i.PKGS + ctn.PKGS; i.KGS = i.KGS + ctn.KGS; i.CBM = i.CBM + ctn.CBM; isfind = true; } }); if (!isfind) { var ctnnum = new MsOpSeaeCtnDetailEdiModel(); ctnnum.HSCODE = ctn.HSCODE; ctnnum.KINDPKGS = ctn.KINDPKGS; ctnnum.KINDPKGS_EDI_CODE = ctn.KINDPKGS_EDI_CODE; ctnnum.DESCRIPTION = ctn.DESCRIPTION; ctnnum.MARKS = ctn.MARKS; ctnnum.PKGS = ctn.PKGS; ctnnum.KGS = ctn.KGS; ctnnum.CBM = ctn.CBM; ctngoodssumlist.Add(ctnnum); } } if (ctngoodssumlist != null) { if (ctngoodssumlist.Count > 0) { var goodct = 0; foreach (var ctngoodsum in ctngoodssumlist) { //GID+1+400:CT::6:CARTONS' r.WriteLine("GID+" + (goodct + 1) + "+" + ctngoodsum.PKGS.ToString() + ":" + ctngoodsum.KINDPKGS_EDI_CODE + "::6:" + ctngoodsum.KINDPKGS + "'"); icount++; //PIA+5+HS_CODE1:HS' r.WriteLine("PIA+5+" + ctngoodsum.HSCODE + ":HS'"); icount++; //FTX+AAA+++MATERIAL 1' //FTX+AAA+++HS-NO 39023012' Shipping = formatEdiStr("txt", ctngoodsum.DESCRIPTION); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] DescriptionList = Shipping.Split('\\'); if (DescriptionList.Length != 0) { for (var j = 0; j < DescriptionList.Length; j++) { r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); icount++; } } //MEA+AAE+WT+KGM:3000' //MEA+AAE+AAW+MTQ:110.11' r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngoodsum.KGS), 3) + "'"); icount++; r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngoodsum.CBM), 3) + "'"); icount++; //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' //if (isbill != 1) //{ // Shipping = formatEdiStr("txt", bill.MARKS); //} //else //{ Shipping = formatEdiStr("txt", ctngoodsum.MARKS); //} if (ctngoodsum.MARKS == "") Shipping = formatEdiStr("txt", bill.MARKS); Shipping = Shipping.Replace("\n", "\\"); Shipping = Shipping.Replace("\r", " "); string[] MarksList = Shipping.Split('\\'); if (MarksList.Length != 0) { for (var j = 0; j < MarksList.Length; j++) { r.WriteLine("PCI++" + MarksList[j] + "'"); icount++; } } if (!string.IsNullOrEmpty(bill.GOODSNCM)) { r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); icount++; } goodct = goodct + 1; bill.CTNGOODSLIST.ForEach(i => { if (i.HSCODE == ctngoodsum.HSCODE && i.KINDPKGS == ctngoodsum.KINDPKGS && i.DESCRIPTION == ctngoodsum.DESCRIPTION && i.MARKS == ctngoodsum.MARKS) { //SGP+MSCU1234567+100' r.WriteLine("SGP+" + i.CNTRNO + "+" + i.PKGS.ToString() + "'"); //MEA+AAE+WT+KGM:1000' r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(i.KGS), 3) + "'"); //MEA+AAE+AAW+MTQ:50.11' r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(i.CBM), 3) + "'"); icount = icount + 3; } }); } } } #endregion } } if (bill.CARGOID == "D") { r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); icount = icount + 3; } #region 集装箱 主箱循环 foreach (var ctn in bill.CTNLIST) { if (bill.ISCONTAINERSOC) r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+1'"); else r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+2'"); r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); icount = icount + 3; if (bill.CARGOID == "R") { if (bill.REEFERF != "") { r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); icount = icount + 1; } } r.WriteLine("SEL+" + ctn.SEALNO + "+CA'"); icount = icount + 1; if (bill.CARGOID == "R") { r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); icount = icount + 1; } } #endregion } r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); r.Close(); f.Close(); return filename; } #endregion } public class MsYMLEdiModel { /// /// 发送方代码 M /// public string SENDCODE { get; set; } /// /// 发送方名称 M /// public string SENDNAME { get; set; } /// /// 接收方代码 M /// public string RECEIVECODE { get; set; } /// /// 文件类型 (B订舱,E SI确认)M /// public string filetype { get; set; } /// /// 文件功能 (9原始,1 更新,5 退舱 )M /// public string filerole { get; set; } /// /// 文件路径 M /// public string filerpath { get; set; } /// /// 是否使用货代代码。 M /// public bool UseForWarderCode { get; set; } /// /// 货代代码。 O /// public string ForWarderCode { get; set; } /// /// 货代名称 O /// public string ForWarderName { get; set; } /// /// 业务信息列表 M /// public List BSLIST { get; set; } } public class MsOpSeaeEdiModel { /// /// 委托方 /// public string WEITUO { get; set; } /// /// 操作英文名称 M /// public string OpEName { get; set; } /// /// 操作电话 M /// public string OpTel { get; set; } /// /// 操作邮箱 M /// public string OpEmail { get; set; } /// /// EDI联系人名称 O /// public string EDIATTN { get; set; } /// /// EDI联系人电话 O /// public string EDIATTNTEL { get; set; } /// /// EDI联系人邮箱 O /// public string EDIATTNEMAIL { get; set; } /// /// 订舱编号 O /// public string ORDERNO { get; set; } /// /// 主提单号 M /// public string MBLNO { get; set; } /// /// 付费方式代码 M /// public string BLFRTEDICODE { get; set; } /// /// 付费方式 M /// public string BLFRT { get; set; } /// /// 船名 O /// public string VESSEL { get; set; } /// /// 船舶呼号 O /// public string VESSELID { get; set; } /// /// 航次 O /// public string VOYNO { get; set; } /// /// 内部航次 O /// public string NVOYNO { get; set; } /// /// 开船日期 M /// public string ETD { get; set; } /// /// EDI备注 /// public string EDIREMARK { get; set; } /// /// SI备注 /// public string SIREMARK { get; set; } /// /// NVO NO /// public string NVONO { get; set; } /// /// ERN CODE /// public string ERNCODE { get; set; } /// /// TAC CODE /// public string TACCODE { get; set; } /// /// VAE CODE /// public string VAECODE { get; set; } /// /// FEC CODE /// public string FECCODE { get; set; } /// /// 船公司名称 M /// public string CARRIER { get; set; } /// /// 船公司EDI代码 M /// public string CARRIEREDICODE { get; set; } /// /// 发货人 M /// public string SHIPPER { get; set; } /// /// 收货人 M /// public string CONSIGNEE { get; set; } /// /// 通知人 M /// public string NOTIFYPARTY { get; set; } /// /// 第二通知人 /// public string NOTIFYPARTY2 { get; set; } /// /// AMS收货人 /// public string AMSCONSIGNEE { get; set; } /// /// AMS通知人 /// public string AMSNOTIFYPARTY { get; set; } /// /// 收货地所在国家 O /// public string BYCOUNTRY { get; set; } ///// ///// AMS发货人 O ///// //public string AMSSHIPPER { get; set; } ///// ///// AMS收货人 O ///// //public string AMSCONSIGNEE { get; set; } ///// ///// AMS通知人 O ///// //public string AMSNOTIFYPARTY { get; set; } /// /// HS编码 /// public string HSCODE { get; set; } /// /// 唛头 M /// public string MARKS { get; set; } /// /// 货物描述 M /// public string DESCRIPTION { get; set; } /// /// 收货地代码(每船公司可能不同) /// public string PLACERECEIPTID { get; set; } /// /// 收货地 /// public string PLACERECEIPT { get; set; } /// /// 起运港代码(每船公司可能不同) M /// public string PORTLOADID { get; set; } /// /// 起运港 M /// public string PORTLOAD { get; set; } /// ///卸货港代码(每船公司可能不同) M /// public string PORTDISCHARGEID { get; set; } /// /// 卸货港 M /// public string PORTDISCHARGE { get; set; } /// ///中转港代码 /// public string TRANSPORTID { get; set; } /// /// 中转港 /// public string TRANSPORT { get; set; } /// ///交货地代码M /// public string PLACEDELIVERYID { get; set; } /// /// 交货地 M /// public string PLACEDELIVERY { get; set; } /// ///目的地代码(每船公司可能不同) /// public string DESTINATIONID { get; set; } /// /// 目的地 /// public string DESTINATION { get; set; } /// /// 件数 M /// public Int32 PKGS { get; set; } /// /// 包装 M /// public string KINDPKGS { get; set; } /// /// 包装代码 M /// public string KINDPKGS_EDI_CODE { get; set; } /// /// 重量 M /// public decimal KGS { get; set; } /// /// 体积 M /// public decimal CBM { get; set; } /// /// 货物标识 M /// public string CARGOID { get; set; } /// /// 第一层包装皮重 O /// public decimal KINGTAREWEIGHT { get; set; } /// /// 危险品类别 O /// public string DCLASS { get; set; } /// /// 危险品编号 O /// public string DUNNO { get; set; } /// /// 危险品页号 C /// public string DPAGE { get; set; } /// /// 危险品标签 C /// public string DLABEL { get; set; } /// /// 设置温度 O /// public string TEMPSET { get; set; } /// /// 设置最低温度 C /// public string TEMPMIN { get; set; } /// /// 设置最高温度 C /// public string TEMPMAX { get; set; } /// /// 通风度 O /// public string REEFERF { get; set; } /// /// 湿度 /// public string HUMIDITY { get; set; } /// /// 预付地点 O /// public string PREPARDAT { get; set; } /// /// 到付地点 O /// public string PAYABLEAT { get; set; } /// /// 预付地点EDI代码 O /// public string PREPARDATID { get; set; } /// /// 到付地点EDI代码 O /// public string PAYABLEATID { get; set; } /// /// 签单方式 M(SI) /// public string ISSUETYPE { get; set; } /// /// 提单份数 M(SI) /// public string NOBILL { get; set; } /// /// 签单地点 M(SI) /// public string ISSUEPLACE { get; set; } /// /// 签单地点 /// public string ISSUEDATE { get; set; } /// /// 提单副本份数 M(SI) /// public string COPYNOBILL { get; set; } /// /// 签单地点EDI代码 M(SI) /// public string ISSUEPLACEID { get; set; } /// /// 运输条款 M /// public string SERVICE { get; set; } /// /// 运费协议号 M /// public string CONTRACTNO { get; set; } /// /// 服务合同号 /// public string SERVICECONTRACTNO { get; set; } /// /// ESL航线代码 M /// public string ESLLINECODE { get; set; } /// /// 收货人邮编 O /// public string CONSIGNEEPOSTCODE { get; set; } /// /// 收货人国家 O /// public string CONSIGNEECOUNTRY { get; set; } /// /// 收货人税号 O /// public string CONSIGNEETAXNO { get; set; } /// /// 通知人邮编 O /// public string NOTIFYPARTYPOSTCODE { get; set; } /// /// 通知人国家 O /// public string NOTIFYPARTYCOUNTRY { get; set; } /// /// 通知人税号 O /// public string NOTIFYPARTYTAXNO { get; set; } /// /// 货物NCM编号 O /// public string GOODSNCM { get; set; } /// /// 收货人DOOR地址 O /// public string CONSIGNEEDOORADDR { get; set; } /// /// 发货人DOOR地址 O /// public string SHIPPERDOORADDR { get; set; } /// /// SCAC代码 O /// public string SCACCODE { get; set; } /// /// ITN编号 O /// public string ITNCODE { get; set; } /// /// 付费方 O /// public string FREIGHTPAYER { get; set; } /// /// AMS代码 O /// public string AMSCODE { get; set; } /// /// 是否SOC箱 O /// public bool ISCONTAINERSOC { get; set; } /// /// 拆并单列表 O /// public string BSNOLIST { get; set; } /// /// 集装箱明细 M /// public List CTNLIST { get; set; } /// /// 集装箱多品名明细 M /// public List CTNGOODSLIST { get; set; } } public class MsOpSeaeCtnEdiModel { /// /// 箱型EDI代码 M /// public string CTNALLCODE { get; set; } public Int32 CTNNUM { get; set; } /// /// 箱号 M /// public string CNTRNO { get; set; } /// /// 封号 M /// public string SEALNO { get; set; } /// /// 件数 M /// public Int32 PKGS { get; set; } /// /// 包装 M /// public string KINDPKGS { get; set; } /// /// 包装代码 M /// public string KINDPKGS_EDI_CODE { get; set; } /// /// 重量 M /// public decimal KGS { get; set; } /// /// 体积 M /// public decimal CBM { get; set; } /// /// 箱皮重 /// public string TAREWEIGHT { get; set; } /// /// 称重重量 /// public string WEIGHKGS { get; set; } /// /// 称重方式 (累加、总重) /// public string WEIGHTYPE { get; set; } /// /// 称重签名 /// public string WEIGHSIGN { get; set; } } public class MsOpSeaeCtnDetailEdiModel { /// /// 箱号 M /// public string CNTRNO { get; set; } /// /// HS编码 M /// public string HSCODE { get; set; } /// /// 唛头 M /// public string MARKS { get; set; } /// /// 货物描述 M /// public string DESCRIPTION { get; set; } /// /// 件数 M /// public Int32 PKGS { get; set; } /// /// 包装 M /// public string KINDPKGS { get; set; } /// /// 包装代码 M /// public string KINDPKGS_EDI_CODE { get; set; } /// /// 重量 M /// public decimal KGS { get; set; } /// /// 体积 M /// public decimal CBM { get; set; } } }