using Myshipping.Application.EDI.ESL; using MySqlX.XDevAPI.Common; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace Myshipping.Application.EDI.PIL { public class PILEdiHelper { public PILEdiHelper() { } #region 基本函数 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 #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 + "超出部分”)"; } } 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 + "超出部分”)"; } } 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 public static string GetmpStr(string str, int len) { var strhead = ""; if (str.IndexOf("-") >= 0) { strhead = "-"; str.Replace("-", ""); } string result = str; for (var i = 0; i <= len - str.Length - 2; i++) { result = "0" + result; } return result; } public static string GetSpaceStr(string str, int len, string substr = " ") { if (substr == "0") { if (str.IndexOf(".") >= 0) str = str.Substring(0, str.IndexOf(".")); } string result = str; if (str.Length >= len) { result = str.Substring(0, len); } else { for (var i = 0; i <= len - str.Length - 1; i++) { if (substr == "0") result = "0" + result; else result = result + substr; } } return result; } public static string GetPILServiceStr(string str) { string result = "Y"; str = str.ToUpper(); char splitstr = '-'; if (str.IndexOf("-") > 0) { splitstr = '-'; } else if (str.IndexOf("/") > 0) { splitstr = '/'; } var strList = str.Split(splitstr); var i = 1; var strhead = ""; var strbotton = ""; foreach (var substr in strList) { if (i == 1) { if (substr == "CY") strhead = "Y"; else if (substr == "CFS") strhead = "F"; else if (substr == "FO") strhead = "O"; else if (substr == "DOOR") strhead = "O"; else if (substr == "HOOK") strhead = "K"; else if (substr == "TACKLE") strhead = "L"; } if (i == 2) { if (substr == "CY") strbotton = "Y"; else if (substr == "CFS") strbotton = "F"; else if (substr == "FO") strbotton = "O"; else if (substr == "DOOR") strbotton = "O"; else if (substr == "HOOK") strbotton = "K"; else if (substr == "TACKLE") strbotton = "L"; } i = i + 1; } if (strhead == "") strhead = "Y"; if (strbotton == "") strbotton = "Y"; result = strhead + strbotton; return result; } #endregion #region 检查 public static string IsCreatePILEDI(EDIBaseModel 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 bill in InttrEdi.BSLIST) { if (string.IsNullOrEmpty(bill.ORDERNO)) { error = error + "|订舱单号不能为空"; } if (bill.PORTLOADID == "CNTAO") { if (string.IsNullOrEmpty(bill.YARD) || string.IsNullOrEmpty(bill.YARDEDICODE)) { error = error + "|场站和场站EDI代码不能为空"; } } if (string.IsNullOrEmpty(bill.MBLNO)) { error = error + "|主提单号不能为空"; } if (string.IsNullOrEmpty(bill.BLFRT)) { error = error + "
提单号:" + bill.MBLNO + "付费方式不能为空"; } if (string.IsNullOrEmpty(bill.PORTLOADID)) { error = error + "
提单号:" + bill.MBLNO + "装货港代码不能为空"; } if (string.IsNullOrEmpty(bill.PORTLOAD)) { error = error + "
提单号:" + bill.MBLNO + "装货港不能为空"; } if (string.IsNullOrEmpty(bill.ETD)) { error = error + "
提单号:" + bill.MBLNO + "开船日期不能为空"; return error; } if (string.IsNullOrEmpty(bill.ETA)) { error = error + "
提单号:" + bill.MBLNO + "预抵日期不能为空"; return error; } if (string.IsNullOrEmpty(bill.GOODSNAME)) { error = error + "
提单号:" + bill.MBLNO + "货物品名不能为空"; return error; } if (string.IsNullOrEmpty(bill.PORTDISCHARGEID)) { error = error + "
提单号:" + bill.MBLNO + "卸货港代码不能为空"; } if (string.IsNullOrEmpty(bill.PLACEDELIVERYID)) { error = error + "
提单号:" + bill.MBLNO + "交货代码不能为空"; } if (bill.PLACEDELIVERY == null || bill.PLACEDELIVERY == "") { error = error + "
提单号:" + bill.MBLNO + "交货地不能为空"; } if (bill.DESTINATION == null || bill.DESTINATION == "") { error = error + "
提单号:" + bill.MBLNO + "目的地不能为空"; } if (bill.ISSUEPLACE == null || bill.ISSUEPLACE == "") { error = error + "
提单号:" + bill.ISSUEPLACE + "签单地点不能为空"; } if (bill.PKGS == 0) { error = error + "
提单号:" + bill.MBLNO + "货物件数不能为空"; } if (bill.KGS == 0) { error = error + "
提单号:" + bill.MBLNO + "货物毛重不能为空"; } if (bill.CBM == 0) { error = error + "
提单号:" + bill.CBM + "货物尺码不能为空"; } if (bill.CARGOID == null || bill.CARGOID == "") { error = error + "
提单号:" + bill.MBLNO + "货物标示不能为空"; } if (bill.CARGOID == "D") { if (bill.DCLASS == null || bill.DCLASS == "") { error = error + "
提单号:" + bill.MBLNO + "危险品分类不能为空"; } if (bill.DUNNO == null || bill.DUNNO == "") { error = error + "
提单号:" + bill.MBLNO + "危险品编号不能为空"; } if (bill.DUNNO.Length != 4) { error = error + "
提单号:" + bill.MBLNO + "危险品编号必须是4位数字"; } } if (bill.CARGOID == "R") { if (bill.TEMPSET == null || bill.TEMPSET == "") { error = error + "
提单号:" + bill.MBLNO + "设置温度不能为空"; } else { if (bill.TEMPSET.IndexOf("+") < 0 && bill.TEMPSET.IndexOf("-") < 0 && bill.TEMPSET.IndexOf(".") < 0) { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } } if (bill.TEMPMAX == null || bill.TEMPMAX == "") { error = error + "
提单号:" + bill.MBLNO + "最高温度不能为空"; } else { if (bill.TEMPMAX.IndexOf("+") < 0 && bill.TEMPMAX.IndexOf("-") < 0 && bill.TEMPMAX.IndexOf(".") < 0) { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } } if (bill.TEMPMIN == null || bill.TEMPMIN == "") { error = error + "
提单号:" + bill.MBLNO + "最低温度不能为空"; } else { if (bill.TEMPMIN.IndexOf("+") < 0 && bill.TEMPMIN.IndexOf("-") < 0 && bill.TEMPMIN.IndexOf(".") < 0) { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } } } if (string.IsNullOrEmpty(bill.MARKS)) { error = error + "
提单号:" + bill.MBLNO + " 唛头不能为空"; } else { if (StringIsChinese(bill.MARKS)) { error = error + "
提单号:" + bill.MBLNO + " 唛头含有中文或双字节字符"; } else { error += formatlengthError("txt", bill.MARKS, 35, bill.MBLNO, "唛头", 0, "", false); } } if (string.IsNullOrEmpty(bill.DESCRIPTION)) { error = error + "
提单号:" + bill.MBLNO + " 货物描述不能为空"; } else { if (StringIsChinese(bill.DESCRIPTION)) { error = error + "
提单号:" + bill.MBLNO + " 货物描述含有中文或双字节字符"; } else { //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); } } if (string.IsNullOrEmpty(bill.SHIPPER)) { error = error + "
提单号:" + bill.MBLNO + " 发货人不能为空"; } else { if (StringIsChinese(bill.SHIPPER)) { error = error + "
提单号:" + bill.MBLNO + " 发货人含有中文或双字节字符"; } else error += formatlengthError("txt", bill.SHIPPER, 35, bill.MBLNO, "发货人", 6, "*", false); } //} if (string.IsNullOrEmpty(bill.CONSIGNEE)) { error = error + "
提单号:" + bill.MBLNO + " 收货人不能为空"; } else { if (StringIsChinese(bill.CONSIGNEE)) { error = error + "
提单号:" + bill.MBLNO + " 收货人含有中文或双字节字符"; } else error += formatlengthError("txt", bill.CONSIGNEE, 35, bill.MBLNO, "收货人", 6, "*", false); } if (string.IsNullOrEmpty(bill.NOTIFYPARTY)) { error = error + "
提单号:" + bill.MBLNO + " 通知人不能为空"; } else { if (StringIsChinese(bill.NOTIFYPARTY)) { error = error + "
提单号:" + bill.MBLNO + " 通知人含有中文或双字节字符"; } else error += formatlengthError("txt", bill.NOTIFYPARTY, 35, bill.MBLNO, "通知人", 6, "*", false); } var ctnlist = bill.CTNLIST; if (ctnlist.Count == 0) { error = error + "
提单号:" + bill.MBLNO + " 集装箱信息不能为空"; }; 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 + "
提单号:" + bill.MBLNO + " 集装箱箱型EDI代码不能为空"; } if (string.IsNullOrEmpty(ctn.KINDPKGS_EDI_CODE)) { error = error + "
提单号:" + bill.MBLNO + " 集装箱包装EDI代码不能为空"; } if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (bill.CARGOID != "R")) { { error = error + "
提单号:" + bill.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } } if (InttrEdi.filetype == "E") { //if (string.IsNullOrEmpty(ctn.CNTRNO)) //{ error = error + "
提单号:" + bill.MBLNO + " 箱号不能为空"; } //if (string.IsNullOrEmpty(ctn.SEALNO)) //{ error = error + "
提单号:" + bill.MBLNO + " 封号不能为空"; } if (ctn.KINDPKGS != bill.KINDPKGS) { error = error + "
提单号:" + bill.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } dlPKGS += Convert.ToDecimal(ctn.PKGS); dlKGS += Convert.ToDecimal(ctn.KGS); dlCBM += Convert.ToDecimal(ctn.CBM); } } if (InttrEdi.filetype == "E") { if (dlPKGS != Convert.ToDecimal(bill.PKGS)) { error = error + "
提单号:" + bill.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } if (dlKGS != Convert.ToDecimal(bill.KGS)) { error = error + "
提单号:" + bill.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } if (dlCBM != Convert.ToDecimal(bill.CBM)) { error = error + "
提单号:" + bill.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } } } //太平新Edi接口判断 if (bill.HSCODE == null || bill.HSCODE == "") { error = error + "
提单号:" + bill.MBLNO + "HS编码 不能为空"; } if (bill.MasterBOLIndicator == null || bill.MasterBOLIndicator == "") { error = error + "
提单号:" + bill.MBLNO + "Master BOL Indicator 不能为空"; } if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 { if (bill.ConsigneeEdiCode == null || bill.ConsigneeEdiCode == "") { error = error + "
提单号:" + bill.MBLNO + "收货人Edi代码 不能为空"; } } else { if (bill.ShipperEdiCode == null || bill.ShipperEdiCode == "") { error = error + "
提单号:" + bill.MBLNO + "发货人Edi代码 不能为空"; } } if (bill.SalesRepCode == null || bill.SalesRepCode == "") { error = error + "
提单号:" + bill.MBLNO + "太平销售的Edi代码 不能为空"; } if (bill.BYCOUNTRY == "CANADA") { if (bill.ACIHBL == null || bill.ACIHBL == "") { error = error + "
提单号:" + bill.MBLNO + "ACI HBL 不能为空"; } if (bill.S0CC0C == null || bill.S0CC0C == "") { error = error + "
提单号:" + bill.MBLNO + "S0C C0C 不能为空"; } } if (InttrEdi.filetype == "E") { if (bill.BYCOUNTRY == "USA") { if (bill.CONTRACTNO == null || bill.CONTRACTNO.ToString().Trim() == "") { error = error + "
提单号:" + bill.MBLNO + "运费协议号 不能为空"; } } } } return error; } #endregion #region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) public static CommonWebApiResult CreateEdiPIL(EDIBaseModel InttrEdi) { CommonWebApiResult result = new CommonWebApiResult { succ = false }; var estr = ""; if (InttrEdi.filetype == "E") { estr = "ESI"; } else { estr = "EDI"; } var SENDCODE = ""; SENDCODE = InttrEdi.SENDCODE; // string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + estr + ".pms"; //如果是部署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 tempstr = ""; #region 00 //tempstr = "00DOC" + GetSpaceStr("", 22) + GetSpaceStr(SENDCODE, 8) + GetSpaceStr("", 6) + DateTime.Now.ToString("yyyyMMddHHmm") + GetSpaceStr("", 1) // + portload + portload; //if (filetype == "E") // tempstr = tempstr + "4.01"; //else // tempstr = tempstr + "PBK"; //r.WriteLine(GetSpaceStr(tempstr, 250)); tempstr = "00";//1//RECORD-ID//M//9(2)//1//2//00 tempstr += "DOC";//2//Data-type ID//M//X(3)//3//5//DOC=BL, BKG=Booking tempstr += GetSpaceStr("", 20);//3//File Description//O//X(20)//6//25// tempstr += GetSpaceStr("", 2);//4//Filler//M//X(2)//26//27//Spaces tempstr += GetSpaceStr(SENDCODE, 8);//5//Sender-Code//M//X(8)//28//35//Sender/Receiver Code List tempstr += GetSpaceStr("", 6);//6//Filler//M//X(6)//36//41// tempstr += DateTime.Now.ToString("yyyyMMddHHmm");//7//File Send time//M//9(12)//42//53//YYYYMMDDHHMM tempstr += GetSpaceStr("", 1);//8//Filler//M//X(1)//54//54//Spaces tempstr += InttrEdi.BSLIST[0].PORTLOADID;//9//Sender Port Code//M//X(5)//55//59// tempstr += InttrEdi.BSLIST[0].PORTLOADID;//10//Receiver Port Code//M//X(5)//60//64// if (InttrEdi.filetype == "E") { tempstr += "4.02";//11//EDI Version//M//X(4) //65//68//Default to "PBK" / esi:4.01 } else { tempstr += "PBK";//11//EDI Version//M//X(4) //65//68//Default to "PBK" / esi:4.01 } tempstr += GetSpaceStr("", 15);//12//Sender Ver Control ID//C//X(15)//69//83//Sender's ASFS/AFMS software version; blank if not applicable tempstr += GetSpaceStr("", 167);//13//Filler//M//X(167)//84//250//Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion foreach (var bill in InttrEdi.BSLIST) { icount = icount + 1; #region 11 var eta = ""; if (bill.ETA == "" || bill.ETA == null) { eta = DateTime.Now.ToString("yyyyMMdd"); } else { eta = bill.ETA.Replace("-", ""); } var etd = ""; if (bill.ETD == "" || bill.ETD == null) { etd = GetSpaceStr("", 8); } else { etd = bill.ETD.Replace("-", ""); } //tempstr = "11" + GetSpaceStr("", 1) + GetSpaceStr(bill.VESSELID, 10) + GetSpaceStr(bill.VESSEL, 20) + GetSpaceStr(bill.VOYNO, 8) + eta + etd // + GetSpaceStr(bill.VESSELID + bill.VOYNO, 12) + eta; //r.WriteLine(GetSpaceStr(tempstr, 250)); tempstr = "11";//1//RECORD-ID//M//9(2)//1//2//11// tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces// if (bill.VOYNO.ToString().Trim().Length < 4) { tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim(), 10);//3//Vessel Code//M//X(10)//4//13//和vessel有关的,即field 4和 field 3 都必填 } else { tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim().Substring(0, 4), 10);//3//Vessel Code//M//X(10)//4//13//和vessel有关的,即field 4和 field 3 都必填 } tempstr += GetSpaceStr(bill.VESSEL, 20);//4//Vessel Name//M//X(20)//14//33//和vessel有关的,即field 4和 field 3 都必填 tempstr += GetSpaceStr("", 8);//5//Voyage No.//M//X(8)//34//41//Alternate Voyage Reference (Commercial voyage)//但是和voyage有关的,即field 5和field 8不用填//不用填 //tempstr += GetSpaceStr("", 8);//5//Voyage No.//M//X(8)//34//41//Alternate Voyage Reference (Commercial voyage)//不用填 tempstr += eta;//6//Arrival Date//M//9(8)//42//49//YYYYMMDD (ATA or ETA if ATA not available)// tempstr += etd;//7//Sailing Date//M//9(8)//50//57//YYYYMMDD (ATD or ETD if ATD not available)// tempstr += GetSpaceStr("", 12);//8//webCSM Voyage No.//O//X(12)//58//69//webCSM System Voyage Reference//但是和voyage有关的,即field 5和field 8不用填//不要填 tempstr += eta;//9//Berthing Date//O//9(8)//70//77//YYYYMMDD (ATB or ETB if ATB not available)// if (bill.VOYNO.ToString().Trim().Length < 5) { tempstr += GetSpaceStr("", 12);//10//Export Local Voyage Reference//O//X(12)//78//89//Export Local Voyage in relation to Sender Port(customs/port reporting)//ENHANCEMENT,填写原field 8的内容,报关用 } else { tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim().Substring(4), 12);//10//Export Local Voyage Reference//O//X(12)//78//89//Export Local Voyage in relation to Sender Port(customs/port reporting)//ENHANCEMENT,填写原field 8的内容,报关用 } tempstr += GetSpaceStr("", 12);//11//Import Local Voyage Reference//O//X(12)//90//101//Import Local Voyage in relation to Sender Port(customs/port reporting)//内部航次 tempstr += GetSpaceStr("", 149);//12//Filler//M//X(149)//102//250//Spaces// r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 12 tempstr = "12";//1 //RECORD-ID//M//9(2)//1 //2 //12 if (InttrEdi.filetype == "E") { tempstr += GetSpaceStr(bill.MBLNO, 20);//2 //webCSM Booking Reference//M//X(20)//3 //22 //webCSM System Job Reference如果需要,填写原field 3的custom ref//bill.ORDERNO } else { tempstr += GetSpaceStr("+", 20);//2 //webCSM Booking Reference//M//X(20)//3 //22 //webCSM System Job Reference如果需要,填写原field 3的custom ref } tempstr += GetSpaceStr(bill.MBLNO, 20);//3 //webCSM BL Number//C//X(20)//23 //42 //Pre-assigned BKG Refmandtory (PIL's bkg ref nbr),预放提单号 if (bill.PORTLOADID == "CNTAO") { tempstr += GetSpaceStr(bill.MBLNO, 20);//4 //Original Bill of Lading//C//X(20)//43 //62 //webCSM External B/L Reference, only if external BL is used } else { tempstr += GetSpaceStr("", 20);//4 //Original Bill of Lading//C//X(20)//43 //62 //webCSM External B/L Reference, only if external BL is used } tempstr += GetSpaceStr("", 5);//5 //Filler//M//X(5)//63 //67 //Spaces tempstr += GetSpaceStr(bill.PORTDISCHARGEID, 5);//6 //Port of Discharge//M//X(5)//68 //72 //Next Discharge Port for the voyage generated tempstr += GetSpaceStr(bill.PORTLOADID, 5);//7 //Port of Loading//M//X(5)//73 //77 //Load Port for the voyage generated tempstr += "FF";//8 //BL Movement Type//M//X(2)//78 //79 //F:FCL, L:LCL, M:MTY, T:TFCL, Y:TMTY, eg. FF=FCL/FCL tempstr += "PP";//9 //Movement Terms//O//X(2)//80 //81 //D:Door, P:Port, R:Ramp, eg. DD=Door/Door tempstr += GetSpaceStr(GetPILServiceStr(bill.SERVICE), 2);//10 //Freight Terms//M//X(2)//82 //83 //Y:CY, F:CFS, I:FI, O:FO, D:Door, K:Hook, L:Tackle eg. YY=CY/CY tempstr += GetSpaceStr("", 3);//11 //Filler//M//X(3)//84 //86 //Spaces if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1) { tempstr += "C";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C } else if (bill.BLFRT.IndexOf("PREPAID") > -1)//预付 { tempstr += "P";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C } else { tempstr += "C";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C } tempstr += "N";//13 //BL Tranship Flag//M//X(1)//88 //88 //Y or N tempstr += "N";//14 //BL All Empty CTN Flag//M//X(1)//89 //89 //Y or N if (bill.CLOSINGDATE == "") { tempstr += GetSpaceStr("", 8);//15 //Loading Date//C//X(8)//90 //97 //YYYYMMDD, mandatory if record submitted is BL } else { tempstr += Convert.ToDateTime(bill.CLOSINGDATE).ToString("yyyyMMdd");//15 //Loading Date//C//X(8)//90 //97 //YYYYMMDD, mandatory if record submitted is BL } if (bill.PORTLOADID == "CNSHA" && InttrEdi.filetype != "E") { tempstr += GetSpaceStr("", 20);//16 //Original_reference//C//X(20)//98 //117 //webCSM Alternate Booking Reference, only if alt booking ref is used } else { tempstr += GetSpaceStr(bill.MBLNO, 20);//16 //Original_reference//C//X(20)//98 //117 //webCSM Alternate Booking Reference, only if alt booking ref is used } tempstr += GetSpaceStr("", 20);//17 //Bkg Pty Reference//O//X(20)//118 //137 //webCSM Bkg Party Reference tempstr += "F";//18 //Booking_Party_indicator//M//X(1)//138 //138 //D-Deciding Pty, N-Notify Pty, C-Consignee, S-Shipper, F-Forwarder tempstr += GetSpaceStr("", 20);//19 //Part MBL//C//X(20)//139 //158 //Not for part BL purpose tempstr += GetSpaceStr("", 20);//20 //BL Paid By//C//X(20)//159 //178 //Freight Absorbed by BL Reference, only if BL's frt is paid by other BL tempstr += GetSpaceStr("", 12);//21 //Customs Bill of Lading//C//X(12)//179 //190 //Customs BL Reference (12 char) - only for US/CA Customs requirement if (bill.ETD == "") { tempstr += GetSpaceStr("", 8);//22 //Booking Date//M//X(8)//191 //198 //YYYYMMDD } else { tempstr += Convert.ToDateTime(bill.ETD).ToString("yyyyMMdd");//22 //Booking Date//M//X(8)//191 //198 //YYYYMMDD } //tempstr += eta;//23 //Slot Owner//M//X(3)//199 //201 // tempstr += GetSpaceStr("PI", 3);//24 //Cntr Operator//M//X(3)//202 //204 // tempstr += GetSpaceStr("PI", 3);//25 //Filler//M//X(46)//205 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 13 tempstr = "13";//1 //RECORD-ID//M//9(2)//1 //2 //13 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(bill.PORTLOADID, 5);//3 //Port of Origin//M//X(5)//6 //10 //refer Port Code (Place of receipt) tempstr += GetSpaceStr(bill.PORTDISCHARGEID, 5);//4 //Port of Discharge//M//X(5)//11 //15 //refer Port code (Port of Discharge - final) tempstr += GetSpaceStr("", 5);//5 //Port of Trans//C//X(5)//16 //20 //refer Port code (1st T/S port), only if Transshipment involved tempstr += GetSpaceStr(bill.PLACEDELIVERYID, 5);//6 //Final Destination//M//X(5)//21 //25 //refer Port Code (Place of delivery) tempstr += GetSpaceStr("", 20);//7 //Final Destination (Name)//M//X(20)//26 //45 // tempstr += GetSpaceStr("", 10);//8 //Route Code//O//X(10)//46 //55 //webCSM Route Code (out from webCSM only) tempstr += GetSpaceStr("", 45);//9 //Filler//M//X(45)//56 //100 //Spaces tempstr += GetSpaceStr("", 5);//10 //Transhipment Port 1//C//X(5)//101 //105 //1st Transhipment Port, only if Transshipment involved tempstr += GetSpaceStr("", 5);//11 //Transhipment Port 2//C//X(5)//106 //110 //2nd Transhipment Port, only if 2nd Transshipment involved tempstr += GetSpaceStr("", 5);//12 //Transhipment Port 3//C//X(5)//111 //115 //3rd Transhipment Port, only if 3rd Transshipment involved //eta = GetPortEDICode(bill.PORTDISCHARGEID, "PIL").Substring(2, 3); //if (eta == "SSZ" || eta == "BUE" || eta == "MVD" || eta == "PNG" || eta == "NVT" || eta == "RIO") //{ // tempstr += "U";//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 //} //else //{ // tempstr += "N";//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 //} tempstr += bill.MasterBOLIndicator;//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 tempstr += GetSpaceStr("", 3);//14 //Job Status //O//X(3)//117 //119 //webCSM Job Status (out from webCSM only) tempstr += GetSpaceStr("", 3);//15 //B/L Status//O//X(3)//120 //122 //webCSM B/L Status (out from webCSM only) tempstr += GetSpaceStr("", 1);//16 //Export Haulage//O//X(1)//123 //123 //M:Merchant Haulage, C:Carrier Haulage tempstr += GetSpaceStr("", 1);//17 //Import Haulage//O//X(1)//124 //124 //M:Merchant Haulage, C:Carrier Haulage tempstr += GetSpaceStr("", 35);//18 //EDI301 Reference//C//X(35)//125 //159 //Shipping Portal's booking reference (eg. GT Nexus, INTTRA) tempstr += GetSpaceStr("", 91);//19 //Filler//M//X(91)//160 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion if (InttrEdi.filetype == "E") { #region 15 tempstr = "15";//1//RECORD-ID//M//9(2)//1//2//15 tempstr += GetSpaceStr(bill.PLACERECEIPT, 50);//2//Origin Freeform//O//X(50)//3//52//BL location text for Port of Origin//收货地 tempstr += GetSpaceStr(bill.PORTLOAD, 50);//3//Load Port Freeform//O//X(50)//53//102//BL location text for Port of Load//装货港 tempstr += GetSpaceStr(bill.PORTDISCHARGE, 50);//4//Discharge Port Freeform//O//X(50)//103//152//BL location text for Port of Discharge//卸货港 tempstr += GetSpaceStr(bill.PLACEDELIVERY, 50);//5//Destination Freeform//O//X(50)//153//202//BL location text for Port of Delivery//交货地点 tempstr += GetSpaceStr(bill.VOYNO, 30);//6//Freeform Voyage//O//X(30)//203//232//BL voyage freeform/ tempstr += GetSpaceStr(bill.VOYNO, 30);//6//Freeform Voyage//O//X(30)//203//232//BL voyage freeform//航次 tempstr += GetSpaceStr("", 18);//7//Filler//M//X(18)//233//250//Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } #region 16 tempstr = "16";//1//RECORD-ID//M//9(2)//1//2//16 tempstr += GetSpaceStr("", 3);//2//Filler//M//X(3)//3//5//Spaces //if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 //{ // tempstr += GetSpaceStr("", 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 //} //else //{ tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 //} tempstr += GetSpaceStr("", 3);//4//Shipper Code//O//X(3)//16//18//webcsm Partner Subcode tempstr += GetSpaceStr("", 4);//5//Filler//M//X(4)//19//22//Spaces var Shipping = ""; Shipping = bill.SHIPPER; List ShippingList = formatlengthStr(Shipping, 35); for (var i = 0; i < ShippingList.Count; i++) { if (i <= 6) { tempstr += GetSpaceStr(ShippingList[i], 35);//6//Shipper-Item (1)//M//X(35)//23//57//Shipper Name, Address line 1 } } //6//Shipper-Item (1)//M//X(35)//23//57//Shipper Name, Address line 1 //7//Shipper-item (2)//M//X(35)//58//92//Shipper Name, Address line 2 //8//Shipper-item (3)//M//X(35)//93//127//Shipper Name, Address line 3 //9//Shipper-item (4)//M//X(35)//128//162//Shipper Name, Address line 4 //10//Shipper-item (5)//M//X(35)//163//197//Shipper Name, Address line 5 //11//Shipper-item (6)//M//X(35)//198//232//Shipper Name, Address line 6 //12//SCAC Code//O//X(4)//233//236// //13//Filler//M//X(14)//237//250//Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 17 tempstr = "17";//1 //RECORD-ID//M//9(2)//1 //2 //17 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces //if (bill.BLFRT == "FREIGHT PREPAID") //{ // tempstr += GetSpaceStr(agent, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code //} //else //{ // tempstr += GetSpaceStr(cagent, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code //} if (bill.BLFRT.IndexOf("FREIGHT PREPAID") > -1)//运费预付 { tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code } else { tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 } if (bill.PORTLOADID == "CNTAO" && InttrEdi.filetype != "E") { tempstr += GetSpaceStr("", 3);//4 //Booking Party Code//O//X(3)//16 //18 //webcsm Partner Subcode//mandtory,订舱单位代码(customer code) } else { tempstr += GetSpaceStr("001", 3);//4 //Booking Party Code//O//X(3)//16 //18 //webcsm Partner Subcode//mandtory,订舱单位代码(customer code) } tempstr += GetSpaceStr("", 4);//5 //Filler//M//X(4)//19 //22 //Spaces int iLs = InttrEdi.ForWarderName.Length / 35; int iLs2 = InttrEdi.ForWarderName.Length % 35; int n = 0; for (int i = 0; i < iLs; i++) { tempstr += GetSpaceStr(InttrEdi.ForWarderName.Substring(i * 35, 35), 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 1; n = i + 1; } if (iLs < 6) { if (iLs2 > 0) { tempstr += GetSpaceStr(InttrEdi.ForWarderName.Substring(n * 35), 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 1-6; } if ((iLs + 1) < 6) { for (int i = 0; i < (6 - iLs - 1); i++) { tempstr += GetSpaceStr("", 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 6; } } } tempstr += GetSpaceStr("", 4);//12 //SCAC Code//O//X(4)//233 //236 // tempstr += GetSpaceStr("", 14);//13 //Filler//M//X(14)//237 //250 //Spaces tempstr = GetSpaceStr(tempstr, 236); if (bill.BLFRT.IndexOf("FREIGHT PREPAID") > -1)//运费预付 { tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code } else { tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 } r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 18 var contractno = bill.CONTRACTNO; tempstr = "18";//1 //RECORD-ID//M//9(2)//1 //2 //18 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces //if (bill.CONTRACTNO == "") //{ // if (bill.BLFRT == "FREIGHT PREPAID") // { // tempstr += GetSpaceStr(agent, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 // } // else // { // tempstr += GetSpaceStr(cagent, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 // } //} //else //{ // tempstr += GetSpaceStr(bill.CONTRACTNO, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code //} if (bill.BYCOUNTRY == "USA") { tempstr += GetSpaceStr("", 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 } else { if (contractno == "") { tempstr += GetSpaceStr("DUM000001", 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 } else { tempstr += GetSpaceStr(contractno, 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code } } if (bill.PORTLOADID == "CNTAO" && InttrEdi.filetype != "E") { tempstr += GetSpaceStr("", 2);//4 //Deciding Party Code//O//X(3)//16 //18 //webcsm Partner Subcode } else { tempstr += GetSpaceStr("01", 2);//4 //Deciding Party Code//O//X(3)//16 //18 //webcsm Partner Subcode } tempstr += GetSpaceStr("", 1);//5 //Special Rate Indicator//C//X(1)//19 //19 //Denote special account with fixed exchange rates (out from webCSM only) tempstr += GetSpaceStr("", 3);//6 //Filler//M//X(3)//20 //22 //Spaces Shipping = ""; if (bill.BLFRT == "FREIGHT PREPAID") { Shipping = bill.SHIPPER; } else { Shipping = bill.CONSIGNEE; } ShippingList = formatlengthStr(Shipping, 35); for (var i = 0; i < ShippingList.Count; i++) { if (i <= 6) { tempstr += GetSpaceStr(ShippingList[i], 35);//7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 } } //var iLS = ShippingList.Count - 6; //if (iLS > 0) //{ // for (var i = 0; i < iLS; i++) // { // tempstr += GetSpaceStr("", 35);//7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 // } //} //7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 //8 //Deciding-item (2)//M//X(35)//58 //92 //Deciding Party Name, Address line 2 //9 //Deciding-item (3)//M//X(35)//93 //127 //Deciding Party Name, Address line 3 //10 //Deciding-Item (4)//M//X(35)//128 //162 //Deciding Party Name, Address line 4 //11 //Deciding-item (5)//M//X(35)//163 //197 //Deciding Party Name, Address line 5 //12 //Deciding-item (6)//M//X(35)//198 //232 //Deciding Party Name, Address line 6 tempstr = GetSpaceStr(tempstr, 232); tempstr += GetSpaceStr("", 4);//12 //SCAC Code//O//X(4)//233 //236 // tempstr += GetSpaceStr(bill.SalesRepCode, 14);//13 //Filler//M//X(14)//237 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 21 tempstr = "21";//1 //RECORD-ID//M//9(2)//1 //2 //21 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 { tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3 //Consignee Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory for FOB shpts,收货人代码,到付必填。跟客服要 } else { tempstr += GetSpaceStr("", 10);//3 //Consignee Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory for FOB shpts,收货人代码,到付必填 } tempstr += GetSpaceStr("", 3);//4 //Consignee Code//O//X(3)//16 //18 //webcsm Partner Subcode tempstr += GetSpaceStr("", 4);//5 //Filler//M//X(4)//19 //22 //Spaces Shipping = ""; Shipping = bill.CONSIGNEE; ShippingList = formatlengthStr(Shipping, 35); for (var i = 0; i < ShippingList.Count; i++) { if (i <= 6) { tempstr += GetSpaceStr(ShippingList[i], 35);//6 //Consignee item - (1)//M//X(35)//23 //57 //Consignee Name, Address line 1 } } //6 //Consignee item - (1)//M//X(35)//23 //57 //Consignee Name, Address line 1 //7 //Consignee item - (2)//M//X(35)//58 //92 //Consignee Name, Address line 2 //8 //Consignee item - (3)//M//X(35)//93 //127 //Consignee Name, Address line 3 //9 //Consignee item - (4)//M//X(35)//128 //162 //Consignee Name, Address line 4 //10 //Consignee item - (5)//M//X(35)//163 //197 //Consignee Name, Address line 5 //11 //Consignee item - (6)//M//X(35)//198 //232 //Consignee Name, Address line 6 //12 //SCAC Code//O//X(4)//233 //236 // //13 //Filler//M//X(14)//237 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 26 tempstr = "26";//1 //RECORD-ID//M//9(2)//1 //2 //26 tempstr += GetSpaceStr("", 2);//2 //Filler//M//X(2)//3 //4 //Spaces tempstr += "1";//3 //Notify Party Count//M//9(1)//5 //5 //I = 1 to 3 notify party tempstr += GetSpaceStr("", 10);//4 //Notify Code//O//X(10)//6 //15 //webcsm Partner Code tempstr += GetSpaceStr("", 3);//5 //Notify Code//O//X(3)//16 //18 //webcsm Partner Subcode tempstr += GetSpaceStr("", 4);//6 //Filler//M//X(4)//19 //22 //Spaces Shipping = ""; Shipping = bill.NOTIFYPARTY; ShippingList = formatlengthStr(Shipping, 35); for (var i = 0; i < ShippingList.Count; i++) { if (i <= 6) { tempstr += GetSpaceStr(ShippingList[i], 35);//7 //Notify Field-(1)//M//X(35)//23 //57 //Notify Party Name, Address line 1 } } //7 //Notify Field-(1)//M//X(35)//23 //57 //Notify Party Name, Address line 1 //8 //Notify Field-(2)//M//X(35)//58 //92 //Notify Party Name, Address line 2 //9 //Notify Field-(3)//M//X(35)//93 //127 //Notify Party Name, Address line 3 //10 //Notify Field-(4)//M//X(35)//128 //162 //Notify Party Name, Address line 4 //11 //Notify Field-(5)//M//X(35)//163 //197 //Notify Party Name, Address line 5 //12 //Notify Field-(6)//M//X(35)//198 //232 //Notify Party Name, Address line 6 //12 //SCAC Code//O//X(4)//233 //236 // //13 //Filler//M//X(14)//237 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion var soc = "N"; if (bill.ISCONTAINERSOC) { soc = "S"; } List ctnsumlist = new List(); foreach (var ctn in bill.CTNLIST) { var isfind = false; ctnsumlist.ForEach(i => { if (i.CTNALLCODE == ctn.CTNALLCODE) { i.CTNNUM = i.CTNNUM + ctn.CTNNUM; i.KGS = i.KGS + ctn.KGS; if (ctn.CTNALLCODE.IndexOf("40") > 0) i.TEU = i.TEU + ctn.CTNNUM * 2; else i.TEU = i.TEU + ctn.CTNNUM * 1; i.PKGS = i.PKGS + ctn.PKGS; i.CBM = i.CBM + ctn.CBM; i.CTNNUM = i.CTNNUM + ctn.CTNNUM; isfind = true; } }); if (!isfind) { var ctnnum = new MsOpSeaeCtnEDIBaseModel(); ctnnum.CTNALLCODE = ctn.CTNALLCODE; ctnnum.KGS = ctn.KGS; if (ctn.CTNALLCODE.IndexOf("40") > 0) ctnnum.TEU = ctn.CTNNUM * 2; else ctnnum.TEU = ctn.CTNNUM * 1; ctnnum.PKGS = ctn.PKGS; ctnnum.CBM = ctn.CBM; ctnnum.CTNNUM = ctn.CTNNUM; ctnsumlist.Add(ctnnum); } } var ctnline = 1; foreach (var ctn in ctnsumlist) { if (InttrEdi.filetype == "E") { #region ESI #region 41 tempstr = "41";//1 //RECORD-ID//M//9(2)//1 //2 //41 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence#//M//9(3)//6 //8 //001 to 999 (line-items) if (bill.HSCODE.ToString().Length > 6) { tempstr += GetSpaceStr(bill.HSCODE.ToString().Substring(0, 6), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE//mandtory,Hscode,必填,商品编码前6位 } else { tempstr += GetSpaceStr(bill.HSCODE.ToString(), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE//mandtory,Hscode,必填,商品编码前6位 } tempstr += "Y";//5 //BL Override//M//X(1)//18 //18 //Y or N, Y=lumpsum weights used, (out from webCSM only) tempstr += GetSpaceStr(ctn.CTNNUM.ToString(), 6, "0");//6 //No of packages/Containers//M//9(6)//19 //24 //Number of Containers for the cargo line tempstr += GetSpaceStr(ctn.TEU.ToString(), 4, "0");//7 //TEU Utilisation//C//9(4)//25 //28 //Actual TEU utilised, eg. OOG's slot kill or Flatrack bundled units tempstr += GetSpaceStr((ctn.KGS * 1000).ToString(), 11, "0");//8 //Cargo Gross Weight//C//9(8)v999//29 //39 //Mandatory, except for Empties tempstr += GetSpaceStr("", 11, "0");//9 //Cargo Nett Weight//C//9(8)v999//40 //50 //Mandatory, except for Empties tempstr += GetSpaceStr((ctn.CBM * 1000).ToString(), 10, "0");//10 //Cargo Gross Measurement//C//9(7)v999//51 //60 //Mandatory, except for Empties tempstr += GetSpaceStr("", 10, "0");//11 //Cargo Nett Measurement//C//9(7)v999//61 //70 //Mandatory, except for Empties tempstr += GetSpaceStr(bill.GOODSNAME, 48);//12 //Commodity Name//O//X(48)//71 //118 // //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code tempstr += GetSpaceStr("", 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code tempstr += GetSpaceStr(ctn.CTNALLCODE, 4);//14 //webcsm Package Code//M//X(4)//123 //126 //eg 20GP, 40GP etc. tempstr += "KGM";//15 //UOM Weight//M//X(3)//127 //129 //Default to METRIC = KGM tempstr += "MTQ";//16 //UOM Measurement//M//X(3)//130 //132 //Default to METRIC = MTQ tempstr += soc;//17 //Equipment Flag //M//X(1)//133 //133 //Y:COC cntr required, N:cntr not required, S:SOC//mandtory,只要有SOC箱子就要填S tempstr += GetSpaceStr("", 117);//18 //Filler//M//X(117)//134 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 44 if (ctnline == 1) { Shipping = bill.MARKS; ShippingList = formatlengthStr(Shipping, 20); for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(12))); i++) { tempstr = "44";//1 //RECORD-ID//M//9(2)//1 //2 //44 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) for (var z = 0; z < 12; z++) { if ((i * 12 + z) < ShippingList.Count) { tempstr += GetSpaceStr(ShippingList[i * 12 + z], 20);//4 //Mark-no-(1)//O//X(20)//9 //28 } } //4 //Mark-no-(1)//O//X(20)//9 //28 // //5 //Mark-no-(2)//O//X(20)//29 //48 // //6 //Mark-no-(3)//O//X(20)//49 //68 // //7 //Mark-no-(4)//O//X(20)//69 //88 // //8 //Mark-no-(5)//O//X(20)//89 //108 // //9 //Mark-no-(6)//O//X(20)//109 //128 // //10 //Mark-no-(7)//O//X(20)//129 //148 // //11 //Mark-no-(8)//O//X(20)//149 //168 // //12 //Mark-no-(9)//O//X(20)//169 //188 // //13 //Mark-no-(10)//O//X(20)//189 //208 // //14 //Mark-no-(11)//O//X(20)//209 //228 // //15 //Mark-no-(12)//O//X(20)//229 //248 // //16 //Filler//M//X(2)//249 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } } #endregion #region 47 if (ctnline == 1) { Shipping = bill.DESCRIPTION; ShippingList = formatlengthStr(Shipping, 30); for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(8))); i++) { tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) for (var z = 0; z < 8; z++) { if ((i * 8 + z) < ShippingList.Count) { tempstr += GetSpaceStr(ShippingList[i * 8 + z], 30);//4 //Cargo Description- (1)//O//X(30)//9 //38 // } } //4 //Cargo Description- (1)//O//X(30)//9 //38 // //5 //Cargo Description- (2)//O//X(30)//39 //68 // //6 //Cargo Description- (3)//O//X(30)//69 //98 // //7 //Cargo Description- (4)//O//X(30)//99 //128 // //8 //Cargo Description- (5)//O//X(30)//129 //158 // //9 //Cargo Description- (6)//O//X(30)//159 //188 // //10 //Cargo Description- (7)//O//X(30)//189 //218 // //11 //Cargo Description- (8)//O//X(30)//219 //248 // //12 //Filler//M//X(2)//249 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } } #endregion var m = 1; foreach (var ctndetail in bill.CTNLIST) { if (ctndetail.CTNALLCODE == ctn.CTNALLCODE) { if (ctndetail.CTNSTATUS == "") ctndetail.CTNSTATUS = "F"; if (ctndetail.CNTRNO != "") { #region 51 tempstr = "51";//1//RECORD-ID//M//9(2)//1//2//51 tempstr += GetSpaceStr("", 3);//2//Filler//M//X(3)//3//5//Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items) tempstr += GetSpaceStr(m.ToString(), 3, "0");//4//Equipment Sequence No//M//9(3)//9//11//001 to 999 tempstr += GetSpaceStr(ctndetail.CNTRNO, 11);//5//Container No//M//X(11)//12//22//Container Number if (bill.ISCONTAINERSOC) { tempstr += "Y";//6//Container SOC//M//X(1)//23//23//Y or N } else { tempstr += "N";//6//Container SOC//M//X(1)//23//23//Y or N } tempstr += ctn.CTNALLCODE;//7//Cntr Size/type code//M//X(4)//24//27//ISO Size/type eg 2200 tempstr += ctndetail.CTNSTATUS;//8//Cntr Loading Status//M//X(1)//28//28//F-Full, P-Part, E-Empty tempstr += GetSpaceStr("", 3);//9//Cntr Operator//O//X(3)//29//31// tempstr += GetSpaceStr("", 3);//10//UOM Weight//M//X(3)//32//34//Default to METRIC = KGM tempstr += GetSpaceStr("", 3);//11//UOM Measurement//M//X(3)//35//37//Default to METRIC = MTQ tempstr += GetSpaceStr("", 9);//12//Filler//M//X(9)//38//46//Spaces tempstr += GetSpaceStr(ctndetail.PKGS.ToString(), 6, "0");//13//Cntr No of Packages//O//9(6)//47//52//Number of Packages in the Container //tempstr += GetSpaceStr(ctndetail.KINDPKGS, 8);//14//Cntr Kind of Packages//O//X(8)//53//60//Package Description (limited to 8 characters) tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 8);//14//Cntr Kind of Packages//O//X(8)//53//60//Package Description (limited to 8 characters) tempstr += GetSpaceStr((ctndetail.KGS * 1000).ToString(), 9, "0");//15//Cntr Cargo Gross Weight//O//9(6)v999//61//69//Cargo Gross Weight per the container unit tempstr += GetSpaceStr("", 9, "0");//16//Cntr Tare Weight//O//9(6)v999//70//78//Container Tare Weight tempstr += GetSpaceStr((ctndetail.CBM * 1000).ToString(), 9, "0");//17//Cntr Cargo Measurement//O//9(6)v999//79//87//Measurement per the container unit tempstr += GetSpaceStr("", 9, "0");//18//Cntr Cargo Net Weight//O//9(6)v999//88//96//Cargo Net Weight per the container unit tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 5);//19//webCSM Package Code//O//X(5)//97//101//Package code within the container eg BX (boxes) tempstr += GetSpaceStr("", 20);//20//Seal No (Shipper)//O//X(20)//102//121//Shipper's Seal Number tempstr += GetSpaceStr(ctndetail.SEALNO, 20);//21//Seal No (Carrier)//O//X(20)//122//141//Carrier's Seal Number tempstr += GetSpaceStr("", 20);//22//Seal No (Customs)//O//X(20)//142//161//Customs' Seal Number tempstr += GetSpaceStr("", 20);//23//Seal No (Others)//O//X(20)//162//181//4th Seal Number tempstr += GetSpaceStr("", 1);//24//Shortship Flag//C//X(1)//182//182//Y:Shortship, S:Shortland, O:Overland, else leave blank tempstr += GetSpaceStr("", 20);//25//Part BL Cross-reference (Their Ref)//C//X(20)//183//202//Cross-ref to Main/Sub OBL of Part containers, only applicable to Part BLs tempstr += GetSpaceStr("", 48);//26//Filler//M//X(48)//203//250//Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } if (bill.CARGOID == "R") { #region 54 冻柜 var tmpset = ""; if (bill.TEMPSET.IndexOf("-") >= 0) { tmpset = "-"; } else { tmpset = "0"; } bill.TEMPSET = bill.TEMPSET.Replace("+", "").Replace("-", ""); tempstr = "54";//1 //RECORD-ID//M//9(2)//1 //2 //54 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//货物的序列号//M//9(3)//6 //8 //001 to 999 (line-items) tempstr += GetSpaceStr(m.ToString(), 3, "0");//4 //Equipment Sequence No设备序列号//M//9(3)//9 //11 //001 to 999 tempstr += "C";//5 //Reefer Temperature UOM冷藏温度计量单位//M//X(1)//12 //12 //C or F (C=Celsius, F=Fahrenheit) tempstr += GetSpaceStr("", 5);//6 //Reefer Min Temperature//C//9(3)v99//13 //17 //If MAX exists, MIN should exists tempstr += GetSpaceStr("", 5);//7 //Reefer Max Temperature//C//9(3)v99//18 //22 //If MIN exists, MAX should exists tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//8 //Reefer Preset Temperature冷藏温度设定//C//9(3)v99//23 //27 //Blank if no Preset required tempstr += "N";//9 //Reefer Gensets Required冷藏机组的要求//M//X(1)//28 //28 //Y or N if (bill.REEFERF != "") { tempstr += GetSpaceStr((Convert.ToDecimal(bill.REEFERF) * 100).ToString(), 5, "0");//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 } else { tempstr += GetSpaceStr("", 5);//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 } tempstr += "Y";//11 //Pretrip Flag//M//X(1)//34 //34 //Y or N tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//12 //Carriage Temperature运输温度//C//9(3)v99//35 //39 //For operating reefers, at least one temperature field must not be blank if (bill.REEFERF != "") { tempstr += "H";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open } else { tempstr += "C";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open } tempstr += GetSpaceStr("", 210);//14 //Filler//M//X(210)//41 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } else if (bill.CARGOID == "D") { #region 55 危险品紧急联系信息 tempstr = "55";//1//RECORD-ID//M//9(2)//1//2//55//record-id tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces//填料 tempstr += "01";//3//DG Sequence No//M//9(2)//4//5//Default to "01", Rec 55 is needed only once for each equipment seq//DG的序列号 tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items)//货物没有#序列 tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No//M//9(3)//9//11//001 to 999//设备序列号 tempstr += GetSpaceStr(bill.EDIATTN, 35);//6//Emergency Contact//O//X(35)//12//46////急救联系 tempstr += GetSpaceStr("", 35);//7//Emergency Tel//O//X(35)//47//81////急救电话 tempstr += GetSpaceStr("", 100);//8//Emergency Email//O//X(100)//82//181////急救的电子邮件 tempstr += GetSpaceStr("", 20);//9//Emergency Reference//O//X(20)//182//201////急救参考 tempstr += GetSpaceStr("", 49);//10//Filler//M//X(49)//202//250//Spaces//填料 r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 56 危险品//56 01001001//2556//a//4.1 //2 //KGM//008220000//009516000//N tempstr = "56";//1//RECORD-ID M 9(2) 1//2//56 tempstr += GetSpaceStr("", 1);//2//Filler M X(1) 3//3//Spaces 填料 tempstr += GetSpaceStr("01", 2);//3//DG Sequence No M 9(2) 4//5//01 to 99, to denote multiple DG items in each equipment seq (cntr) DG的序列号 tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No# M 9(3) 6//8//001 to 999 (line-items)//货物没有#序列 tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No M 9(3) 9//11//001 to 999 设备序列号 tempstr += GetSpaceStr(bill.DUNNO, 4);//6//UN Number M X(4) 12//15// 联合国编号 tempstr += GetSpaceStr("", 1);//7//UN Variant M X(1) 16//16// 联合国的变体 tempstr += GetSpaceStr(bill.DCLASS, 4);//8//IMO Class M X(4) 17//20// 国际海事组织类 tempstr += GetSpaceStr("", 3);//9//PSA Class O X(3) 21//23// PSA类 tempstr += "KGM";//10//UOM M X(3) 24//26//Default to METRIC, eg. KGM 计量单位 tempstr += GetSpaceStr(((ctn.KGS - ctn.TAREWEIGHT) * 1000).ToString(), 9, "0");//11//Net Weight C 9(6)v999 27//35//Weight of DG item 净重量 tempstr += GetSpaceStr((ctn.KGS * 1000).ToString(), 9, "0");//12//Gross Weight C 9(6)v999 36//44//Weight of DG item 总重量 tempstr += "N";//13//Marine Pollutant M X(1) 45//45//Y or N 海洋污染物 tempstr += GetSpaceStr(bill.DPAGE, 10);//14//IMDG Page O X(10) 46//55// 危规页码 tempstr += GetSpaceStr("", 4);//15//DOT Packaging Group O X(4) 56//59// 点包装集团 tempstr += GetSpaceStr("", 10);//16//Filler M X(10) 60//69//Spaces 填料 tempstr += GetSpaceStr("", 25);//17//Flashpoint O X(25) 70//94// 闪点 tempstr += GetSpaceStr("", 3);//18//Packing Group O X(3) 95//97// 包装组 tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 5);//19//Outer Package Code O X(5) 98//102//webCSM Package Code 外包装编码 tempstr += GetSpaceStr(ctndetail.PKGS.ToString(), 9, "0");//20//Outer Quantity O 9(9) 103//111// 外量 tempstr += GetSpaceStr("", 5);//21//Inner Package Code O X(5) 112//116//webCSM Package Code 内包装代码 tempstr += GetSpaceStr("", 9);//22//Inner Quantity O 9(9) 117//125// 内部变量 tempstr += GetSpaceStr("", 5);//23//Next Inner Package Code O X(5) 126//130//webCSM Package Code 下一个内部包代码 tempstr += GetSpaceStr("", 9);//24//Next Inner Quantity O 9(9) 131//139// 下一个内部变量 tempstr += GetSpaceStr("", 50);//25//Chemical Name O X(50) 140//189// 化学名称 tempstr += GetSpaceStr("", 20);//26//Our Reference O X(20) 190//209// 我们的参考 tempstr += GetSpaceStr("", 21);//28//Filler M X(21) 230//250//Spaces 填料 r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } m = m + 1; } } #endregion } else { #region EDI #region 41 tempstr = "41";//1 //RECORD-ID//M//9(2)//1 //2 //41 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence#//M//9(3)//6 //8 //001 to 999 (line-items) //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE if (bill.HSCODE.ToString().Length > 6) { tempstr += GetSpaceStr(bill.HSCODE.ToString().Substring(0, 6), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE } else { tempstr += GetSpaceStr(bill.HSCODE.ToString(), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE } tempstr += "Y";//5 //BL Override//M//X(1)//18 //18 //Y or N, Y=lumpsum weights used, (out from webCSM only) tempstr += GetSpaceStr(ctn.CTNNUM.ToString(), 6, "0");//6 //No of packages/Containers//M//9(6)//19 //24 //Number of Containers for the cargo line tempstr += GetSpaceStr(ctn.TEU.ToString(), 4, "0");//7 //TEU Utilisation//C//9(4)//25 //28 //Actual TEU utilised, eg. OOG's slot kill or Flatrack bundled units tempstr += GetSpaceStr((ctn.KGS * 1000).ToString(), 11, "0");//8 //Cargo Gross Weight//C//9(8)v999//29 //39 //Mandatory, except for Empties tempstr += GetSpaceStr("", 11, "0");//9 //Cargo Nett Weight//C//9(8)v999//40 //50 //Mandatory, except for Empties tempstr += GetSpaceStr((ctn.CBM * 1000).ToString(), 10, "0");//10 //Cargo Gross Measurement//C//9(7)v999//51 //60 //Mandatory, except for Empties tempstr += GetSpaceStr("", 10, "0");//11 //Cargo Nett Measurement//C//9(7)v999//61 //70 //Mandatory, except for Empties tempstr += GetSpaceStr(bill.GOODSNAME, 48);//12 //Commodity Name//O//X(48)//71 //118 // //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code tempstr += GetSpaceStr("", 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code tempstr += GetSpaceStr(ctn.CTNALLCODE, 4);//14 //webcsm Package Code//M//X(4)//123 //126 //eg 20GP, 40GP etc. tempstr += "MTQ";//15 //UOM Weight//M//X(3)//127 //129 //Default to METRIC = KGM tempstr += "MTQ";//16 //UOM Measurement//M//X(3)//130 //132 //Default to METRIC = MTQ tempstr += soc;//17 //Equipment Flag //M//X(1)//133 //133 //Y:COC cntr required, N:cntr not required, S:SOC tempstr += GetSpaceStr("", 117);//18 //Filler//M//X(117)//134 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 44 Shipping = bill.MARKS; ShippingList = formatlengthStr(Shipping, 20); for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(12))); i++) { tempstr = "44";//1 //RECORD-ID//M//9(2)//1 //2 //44 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) for (var z = 0; z < 12; z++) { if ((i * 12 + z) < ShippingList.Count) { tempstr += GetSpaceStr(ShippingList[i * 12 + z], 20);//4 //Mark-no-(1)//O//X(20)//9 //28 } } //4 //Mark-no-(1)//O//X(20)//9 //28 // //5 //Mark-no-(2)//O//X(20)//29 //48 // //6 //Mark-no-(3)//O//X(20)//49 //68 // //7 //Mark-no-(4)//O//X(20)//69 //88 // //8 //Mark-no-(5)//O//X(20)//89 //108 // //9 //Mark-no-(6)//O//X(20)//109 //128 // //10 //Mark-no-(7)//O//X(20)//129 //148 // //11 //Mark-no-(8)//O//X(20)//149 //168 // //12 //Mark-no-(9)//O//X(20)//169 //188 // //13 //Mark-no-(10)//O//X(20)//189 //208 // //14 //Mark-no-(11)//O//X(20)//209 //228 // //15 //Mark-no-(12)//O//X(20)//229 //248 // //16 //Filler//M//X(2)//249 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } #endregion if (ctnline == 1) { #region 47 tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) tempstr += bill.PKGS.ToString() + bill.KINDPKGS;//4 //Cargo Description- (1)//O//X(30)//9 //38 // //5 //Cargo Description- (2)//O//X(30)//39 //68 // //6 //Cargo Description- (3)//O//X(30)//69 //98 // //7 //Cargo Description- (4)//O//X(30)//99 //128 // //8 //Cargo Description- (5)//O//X(30)//129 //158 // //9 //Cargo Description- (6)//O//X(30)//159 //188 // //10 //Cargo Description- (7)//O//X(30)//189 //218 // //11 //Cargo Description- (8)//O//X(30)//219 //248 // //12 //Filler//M//X(2)//249 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } #region 47 description Shipping = bill.DESCRIPTION; ShippingList = formatlengthStr(Shipping, 30); for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(8))); i++) { tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) for (var z = 0; z < 8; z++) { if ((i * 8 + z) < ShippingList.Count) { tempstr += GetSpaceStr(ShippingList[i * 8 + z], 30);//4 //Cargo Description- (1)//O//X(30)//9 //38 // } } //4 //Cargo Description- (1)//O//X(30)//9 //38 // //5 //Cargo Description- (2)//O//X(30)//39 //68 // //6 //Cargo Description- (3)//O//X(30)//69 //98 // //7 //Cargo Description- (4)//O//X(30)//99 //128 // //8 //Cargo Description- (5)//O//X(30)//129 //158 // //9 //Cargo Description- (6)//O//X(30)//159 //188 // //10 //Cargo Description- (7)//O//X(30)//189 //218 // //11 //Cargo Description- (8)//O//X(30)//219 //248 // //12 //Filler//M//X(2)//249 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } #endregion for (var m = 1; m <= ctn.CTNNUM; ++m) { if (bill.CARGOID == "R") { #region 54 冻柜 var tmpset = ""; if (bill.TEMPSET.IndexOf("-") >= 0) tmpset = "-"; else tmpset = "0"; bill.TEMPSET = bill.TEMPSET.Replace("+", "").Replace("-", ""); tempstr = "54";//1 //RECORD-ID//M//9(2)//1 //2 //54 tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//货物的序列号//M//9(3)//6 //8 //001 to 999 (line-items) tempstr += GetSpaceStr(m.ToString(), 3, "0");//4 //Equipment Sequence No设备序列号//M//9(3)//9 //11 //001 to 999 tempstr += "C";//5 //Reefer Temperature UOM冷藏温度计量单位//M//X(1)//12 //12 //C or F (C=Celsius, F=Fahrenheit) tempstr += GetSpaceStr("", 5);//6 //Reefer Min Temperature//C//9(3)v99//13 //17 //If MAX exists, MIN should exists tempstr += GetSpaceStr("", 5);//7 //Reefer Max Temperature//C//9(3)v99//18 //22 //If MIN exists, MAX should exists tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//8 //Reefer Preset Temperature冷藏温度设定//C//9(3)v99//23 //27 //Blank if no Preset required tempstr += "N";//9 //Reefer Gensets Required冷藏机组的要求//M//X(1)//28 //28 //Y or N if (bill.REEFERF != "") { tempstr += GetSpaceStr((Convert.ToDecimal(bill.REEFERF) * 100).ToString(), 5, "0");//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 } else { tempstr += GetSpaceStr("", 5);//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 } tempstr += "Y";//11 //Pretrip Flag//M//X(1)//34 //34 //Y or N tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//12 //Carriage Temperature运输温度//C//9(3)v99//35 //39 //For operating reefers, at least one temperature field must not be blank if (bill.REEFERF != "") { tempstr += "H";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open } else { tempstr += "C";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open } tempstr += GetSpaceStr("", 210);//14 //Filler//M//X(210)//41 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } else if (bill.CARGOID == "D") { #region 55 危险品紧急联系信息 tempstr = "55";//1//RECORD-ID//M//9(2)//1//2//55//record-id tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces//填料 tempstr += "01";//3//DG Sequence No//M//9(2)//4//5//Default to "01", Rec 55 is needed only once for each equipment seq//DG的序列号 tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items)//货物没有#序列 tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No//M//9(3)//9//11//001 to 999//设备序列号 tempstr += GetSpaceStr(bill.EDIATTN, 35);//6//Emergency Contact//O//X(35)//12//46////急救联系 tempstr += GetSpaceStr("", 35);//7//Emergency Tel//O//X(35)//47//81////急救电话 tempstr += GetSpaceStr("", 100);//8//Emergency Email//O//X(100)//82//181////急救的电子邮件 tempstr += GetSpaceStr("", 20);//9//Emergency Reference//O//X(20)//182//201////急救参考 tempstr += GetSpaceStr("", 49);//10//Filler//M//X(49)//202//250//Spaces//填料 r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion #region 56 危险品//56 01001001//2556//a//4.1 //2 //KGM//008220000//009516000//N tempstr = "56";//1//RECORD-ID M 9(2) 1//2//56 tempstr += GetSpaceStr("", 1);//2//Filler M X(1) 3//3//Spaces 填料 tempstr += GetSpaceStr("01", 2);//3//DG Sequence No M 9(2) 4//5//01 to 99, to denote multiple DG items in each equipment seq (cntr) DG的序列号 tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No# M 9(3) 6//8//001 to 999 (line-items)//货物没有#序列 tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No M 9(3) 9//11//001 to 999 设备序列号 tempstr += GetSpaceStr(bill.DUNNO, 4);//6//UN Number M X(4) 12//15// 联合国编号 tempstr += GetSpaceStr("", 1);//7//UN Variant M X(1) 16//16// 联合国的变体 tempstr += GetSpaceStr(bill.DCLASS, 4);//8//IMO Class M X(4) 17//20// 国际海事组织类 tempstr += GetSpaceStr("", 3);//9//PSA Class O X(3) 21//23// PSA类 tempstr += "KGM";//10//UOM M X(3) 24//26//Default to METRIC, eg. KGM 计量单位 tempstr += GetSpaceStr(((ctn.KGS - ctn.TAREWEIGHT) * 1000).ToString(), 9, "0");//11//Net Weight C 9(6)v999 27//35//Weight of DG item 净重量 tempstr += GetSpaceStr((ctn.KGS * 1000).ToString(), 9, "0");//12//Gross Weight C 9(6)v999 36//44//Weight of DG item 总重量 tempstr += "N";//13//Marine Pollutant M X(1) 45//45//Y or N 海洋污染物 tempstr += GetSpaceStr(bill.DPAGE, 10);//14//IMDG Page O X(10) 46//55// 危规页码 tempstr += GetSpaceStr("", 4);//15//DOT Packaging Group O X(4) 56//59// 点包装集团 tempstr += GetSpaceStr("", 10);//16//Filler M X(10) 60//69//Spaces 填料 tempstr += GetSpaceStr("", 25);//17//Flashpoint O X(25) 70//94// 闪点 tempstr += GetSpaceStr("", 3);//18//Packing Group O X(3) 95//97// 包装组 tempstr += GetSpaceStr(ctn.KINDPKGS_EDI_CODE, 5);//19//Outer Package Code O X(5) 98//102//webCSM Package Code 外包装编码 tempstr += GetSpaceStr(ctn.PKGS.ToString(), 9, "0");//20//Outer Quantity O 9(9) 103//111// 外量 tempstr += GetSpaceStr("", 5);//21//Inner Package Code O X(5) 112//116//webCSM Package Code 内包装代码 tempstr += GetSpaceStr("", 9);//22//Inner Quantity O 9(9) 117//125// 内部变量 tempstr += GetSpaceStr("", 5);//23//Next Inner Package Code O X(5) 126//130//webCSM Package Code 下一个内部包代码 tempstr += GetSpaceStr("", 9);//24//Next Inner Quantity O 9(9) 131//139// 下一个内部变量 tempstr += GetSpaceStr("", 50);//25//Chemical Name O X(50) 140//189// 化学名称 tempstr += GetSpaceStr("", 20);//26//Our Reference O X(20) 190//209// 我们的参考 tempstr += GetSpaceStr("", 21);//28//Filler M X(21) 230//250//Spaces 填料 r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } } #endregion } ctnline = ctnline + 1; } #region 73 tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 //3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); if (!string.IsNullOrWhiteSpace(bill.ACIHBL)) { tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 tempstr += GetSpaceStr(bill.ACIHBL, 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } if (!string.IsNullOrWhiteSpace(bill.S0CC0C)) { tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 tempstr += GetSpaceStr(bill.S0CC0C, 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } if (InttrEdi.filetype == "E") { //欧盟港口、伊朗港口、KHI if (bill.cKHI != "") { Shipping = bill.cKHI; List ShippingListLs = formatlengthStr(Shipping, 120); for (var i = 0; i < ShippingListLs.Count; i++) { tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "C";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } } //南美东 if (bill.cNCM != "") { Shipping = bill.cNCM; List ShippingListLs = formatlengthStr(Shipping, 120); for (var i = 0; i < ShippingListLs.Count; i++) { tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "C";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } } //巴西线的木质包装情况 if (bill.wNCM != "") { Shipping = bill.wNCM; List ShippingListLs = formatlengthStr(Shipping, 120); for (var i = 0; i < ShippingListLs.Count; i++) { tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 tempstr += "W";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); } } } #endregion #region 74 tempstr = "74";//1//RECORD-ID//M//9(2)//1//2//74// tempstr += GetSpaceStr("", 3);//2//Filler//O//X(3)//3//5//Spaces// tempstr += GetSpaceStr(bill.ISSUEPLACEID, 5);//3//Place of BL issue//M//X(5)//6//10//webCSM Port code (Port of BL Issuance)//提单签发地//webcsm港口代码(BL发行端口) if (string.IsNullOrWhiteSpace(bill.ISSUEDATE)) { tempstr += GetSpaceStr("", 8);//4//Date of BL issue//M//X(8)//11//18//YYYYMMDD//提单签发日期//年月日 } else { tempstr += GetDateStr(bill.ISSUEDATE, "yyyyMMdd");//4//Date of BL issue//M//X(8)//11//18//YYYYMMDD//提单签发日期//年月日 } tempstr += GetSpaceStr("", 4);//5//Department Code//M//X(4)//19//22//webCSM Department Code (eg SG00) (out from webCSM only)//部门代码//webcsm部门代码(如sg00)(从webcsm只) tempstr += GetSpaceStr("", 3);//6//Booking Agent Code//M//X(3)//23//25//webCSM Booking Agent Code (eg SIN)//订舱代理代码//webcsm订舱代理代码(如犯罪) if (bill.ISSUETYPE.ToString().Trim().ToUpper() == "WAYBILL") { tempstr += GetSpaceStr("W", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominal,g-negotiable,S-开关,w-waybill,m-memo } else { tempstr += GetSpaceStr("N", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominal,g-negotiable,S-开关,w-waybill,m-memo } //tempstr += GetSpaceStr(GetBillNum(bill.NOBILL.ToString().Trim()), 2, "0");//8//No. of Original BLs//O//9(2)//27//28//号原BLS// //tempstr += GetSpaceStr(GetBillNum(bill.COPYNOBILL.ToString().Trim()), 2, "0");//9//No. of Copy BLs//O//9(2)//29//30//不复制BLS// tempstr += GetSpaceStr("", 2);//8//No. of Original BLs//O//9(2)//27//28//号原BLS//太平要求去掉 tempstr += GetSpaceStr("", 2);//9//No. of Copy BLs//O//9(2)//29//30//不复制BLS//太平要求去掉 if (bill.BYCOUNTRY == "USA") { tempstr += GetSpaceStr(bill.CONTRACTNO, 10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运 } else { tempstr += GetSpaceStr("", 10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运 } tempstr += GetSpaceStr("", 5);//11//Prepaid at (Port code)//M//X(5)//41//45//Ocean Freight Payment Location//预付(港码)//海运付款地点 tempstr += GetSpaceStr("", 5);//12//Payable at (Port Code)//M//X(5)//46//50//1st Collect Charge Payment Location//按(港口代码)支付//第一收取缴费地点 tempstr += GetSpaceStr(bill.PKGS.ToString().Trim(), 8, "0");//13//BL's total No of Packages//O//9(8)//51//58//提单总包数// tempstr += GetSpaceStr(bill.KINDPKGS_EDI_CODE, 8);//14//BL's Packages_type in total//O//X(8)//59//66//Default as 'PACKAGE'//BL的packages_type总//默认为“包” tempstr += GetSpaceStr("", 12);//15//Filler//M//X(12)//67//78//Spaces//填料//空间 tempstr += GetSpaceStr("", 1);//16//Roundtrip Indicator//O//X(1)//79//79//Y:Round trip, else leave Blank//往返指示器//往返,否则留下空白 tempstr += GetSpaceStr("", 1);//17//Received for Shipment//O//X(1)//80//80//Y:Received for Shipment, else leave Blank//收到的货物//收到装运,否则留空 tempstr += GetSpaceStr("", 8);//18//Shipped on Board Date//O//X(8)//81//88//YYYYMMDD (SOB Date)//装船日期//YYYYMMDD(SOB日期) tempstr += GetSpaceStr("", 8);//19//Date of Surrender//O//X(8)//89//96//YYYYMMDD (Surrender Date)//日投降//YYYYMMDD(投降日) tempstr += GetSpaceStr("", 5);//20//Point of BL Surrender//O//X(5)//97//101//webCSM Port code (Point of BL Surrender)//提单退保点//webcsm港口代码(BL屈服点) tempstr += GetSpaceStr("", 5);//21//Point of BL Switch//O//X(5)//102//106//webCSM Port code (Point of BL Switch)//BL开关点//webcsm港口代码(BL开关点) tempstr += GetSpaceStr("", 8);//22//Date of Switch Issuance//O//X(8)//107//114//YYYYMMDD (Switch Issuance Date)//开关签发日期//YYYYMMDD(开关发行日期) tempstr += GetSpaceStr("", 5);//23//Point of BL Switch Issuance//O//X(5)//115//119//webCSM Port code (Point of BL Switch Issuance)//提单开关点//webcsm港口代码(BL开关发行点) tempstr += GetSpaceStr("", 5);//24//Final Delivered Point//O//X(5)//120//124//webCSM Port code (Final Released Point of cargo)//最后交付点//webcsm港口代码(最终发布点的货物) tempstr += GetSpaceStr("", 126);//25//Filler//M//X(126)//125//250//Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion } #region 99 tempstr = "99";//1 RECORD-ID M 9(2) 1 2 99 tempstr += GetSpaceStr("", 3);//2 Filler M X(3) 3 5 Spaces tempstr += GetSpaceStr(icount.ToString(), 6, "0");//3 Total No of B/Ls M 9(6) 6 11 Total number of b/ls generated in EDI file //4 Filler M X(239) 12 250 Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); #endregion r.Close(); f.Close(); result.succ = true; result.extra = filename; return result; } #endregion } }