using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity; using DSWeb.Common.DB; using System.Collections.Specialized; using System.IO; using System.Net; using Newtonsoft.Json.Linq; using DSWeb.Common.Helper; using System.Reflection; using Newtonsoft.Json; using System.Text.RegularExpressions; using System.Collections.Generic; namespace DSWeb.DLL.SendEdiToYard { public class CheckData { /// /// 判断是否符合保存的要求 /// /// /// /// /// public static string CheckCanSave(string bsnos, bool isETA = false, string type = "", bool checkCtnNum = true) { var bsnoList = GetBSNOsList(bsnos); EdiDataContext db = new EdiDataContext(); var billList = db.Edis.Where(x => bsnoList.Contains(x.MFNO)).ToList(); var error = ""; foreach (var bill in billList) { //var billams = db.OP_SEAE_AMS.Where(x=>x.BSNO=) var alertNo = bill.MBLNO; if (!string.IsNullOrWhiteSpace(bill.HBLNO)) alertNo = bill.HBLNO; #region 提单号、船名航次、HSCODE、付费方式、船公司、船代 if (type == "新增" && bill.EDISTATUS == "已直发") { error = error + "
舱单已直发,不允许再次新增"; } if (type == "修改" && bill.EDISTATUS == "已录入") { error = error + "
未查到发送记录,类型请选择新增。"; } if (type == "删除" && bill.EDISTATUS == "已录入") { error = error + "
未查到发送记录,类型请选择新增。"; } if (bill.MBLNO == null || bill.MBLNO == "") { error = error + "
主提单号不能为空"; } if (bill.FORWARDER == null || bill.FORWARDER == "") { error = error + "
提单号:" + alertNo + " 船代不能为空"; } else { //if (MsOpSeaeDAL.MsOpSeaeDAL.GetCustEdi(bill.SHIPAGENCY) == "") //{ // error = error + "
提单号:" + alertNo + " 船代EDI代码不能为空"; //} } //if (bill.CARRIER == null || bill.CARRIER == "") //{ // error = error + "
提单号:" + alertNo + " 船公司不能为空"; //} //else //{ // if (MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetCustEdi(bill.CARRIER) == "") // { // error = error + "
提单号:" + alertNo + " 船公司EDI代码不能为空"; // } //} if ((string.IsNullOrWhiteSpace(bill.BLFRT))) { error = error + "
提单号:" + alertNo + " 付费方式不能为空"; } if (string.IsNullOrWhiteSpace(bill.VESSEL)) { error = error + "
提单号:" + alertNo + " 船名不能为空"; } if (string.IsNullOrWhiteSpace(bill.VOYNO )) { error = error + "
提单号:" + alertNo + " 航次不能为空"; } #endregion #region 装货港、卸货港、开船日期、预付地点、到付地点、签单地点 if (string.IsNullOrWhiteSpace(bill.PORTLOADID)) { error = error + "
提单号:" + alertNo + " 装货港代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.PORTLOAD)) { error = error + "
提单号:" + alertNo + " 装货港不能为空"; } if (bill.ETD == null) { error = error + "
提单号:" + alertNo + " 开船日期不能为空"; } if (isETA) { if (bill.ETA == null) { error = error + "
提单号:" + alertNo + " 预抵日期不能为空"; } } if (string.IsNullOrWhiteSpace(bill.PORTDISCHARGEID)) { error = error + "
提单号:" + alertNo + " 卸货港代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.PORTDISCHARGE)) { error = error + "
提单号:" + alertNo + " 卸货港不能为空"; } //if (bill.BLFRT.IndexOf("PREPAID") >= 0) //{ // if (bill.PREPARDAT == "" || MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPortEDICode(bill.PREPARDAT) == "") // { error = error + "
提单号:" + alertNo + " 预付地点或预付地点EDI代码不能为空"; } //} //if (bill.SHIPPERCODE.Trim() == "") //{ // error = error + "
提单号:" + alertNo + " 发货人企业代码不能为空"; //} if (string.IsNullOrWhiteSpace(bill.SHIPPERTEL) && string.IsNullOrWhiteSpace(bill.SHIPPEREMAIL)) { error = error + "
提单号:" + alertNo + " 发货人电话和邮箱不能都为空"; } //var consigneestr = bill.CONSIGNEE.ToUpper().Replace(" ", ""); if (string.IsNullOrWhiteSpace(bill.CONSIGNEE)) { error = error + "
提单号:" + alertNo + "收货人不能为空"; } if (string.IsNullOrWhiteSpace(bill.CONSIGNEENAME)) { error = error + "
提单号:" + alertNo + "收货人不能为空"; } else { //if (!bill.CONSIGNEENAME.Contains("ORDER")) //{ //} } //if (bill.BLFRT.IndexOf("COLLECT") >= 0) //{ // if (bill.PAYABLEAT == "" || MsOpSeaeDAL.MsOpSeaeDAL.GetPortEDICode(bill.PAYABLEAT) == "") // { error = error + "
提单号:" + alertNo + " 到付地点或到付地点EDI代码不能为空"; } //} //if (bill.ISSUEPLACE == "" || MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPortEDICode(bill.ISSUEPLACE) == "") //{ error = error + "
提单号:" + alertNo + " 签单地点或到签单地点EDI代码不能为空"; } #endregion #region 件数包装、件重尺 //if (MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPackageEDICode(bill.KINDPKGS, "") == "") //{ // error = error + "
提单号:" + alertNo + " 包装EDI代码不能为空"; //} //if (bill.PKGS == "0") //{ error = error + "
提单号:" + alertNo + " 货物件数不能为空"; } //if (bill.KGS == "0") //{ error = error + "
提单号:" + alertNo + " 货物重量不能为空"; } //if (bill.CBM == "0") //{ error = error + "
提单号:" + alertNo + " 货物尺码不能为空"; } #endregion #region 货物描述 if (string.IsNullOrWhiteSpace(bill.DESCRIPTION)) { error = error + "
提单号:" + alertNo + " 货物描述不能为空"; } else { if (StringIsChinese(bill.DESCRIPTION)) { error = error + "
提单号:" + alertNo + " 货物描述含有中文或双字节字符"; } //else //{ // error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.DESCRIPTION, 70, alertNo, "货物描述", 0, "", true); //} } #endregion #region 唛头 if (string.IsNullOrWhiteSpace(bill.MARKS)) { error = error + "
提单号:" + alertNo + " 唛头不能为空"; } else { if (StringIsChinese(bill.MARKS)) { error = error + "
提单号:" + alertNo + " 唛头含有中文或双字节字符"; } //else //{ // error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.MARKS, 35, alertNo, "唛头", 0, "", false); //} } #endregion #region 货物标识信息 if (string.IsNullOrWhiteSpace(bill.CARGOID )) { error = error + "
提单号:" + alertNo + " 货物标示不能为空"; } if (bill.CARGOID == "D") { if (string.IsNullOrWhiteSpace(bill.DCLASS)) { error = error + "
提单号:" + alertNo + " 危险品分类不能为空"; } if (string.IsNullOrWhiteSpace(bill.DUNNO)) { error = error + "
提单号:" + alertNo + " 危险品编号不能为空"; } } if (bill.CARGOID == "R") { if (string.IsNullOrWhiteSpace(bill.TEMPSET )) { error = error + "
提单号:" + alertNo + " 设置温度不能为空"; } } #endregion #region 发货人 if (string.IsNullOrWhiteSpace(bill.SHIPPER)) { error = error + "
提单号:" + alertNo + " 发货人不能为空"; } else { if (StringIsChinese(bill.SHIPPER)) { error = error + "
提单号:" + alertNo + " 发货人含有中文或双字节字符"; } else { //error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.SHIPPER, 35, alertNo, "发货人", 5, "*", false); } } #endregion #region 收货人 if (string.IsNullOrWhiteSpace(bill.CONSIGNEE)) { error = error + "
提单号:" + alertNo + " 收货人不能为空"; } else { if (StringIsChinese(bill.CONSIGNEE)) { error = error + "
提单号:" + alertNo + " 收货人含有中文或双字节字符"; } else { //error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.CONSIGNEE, 35, alertNo, "收货人", 5, "**", false); } } #endregion #region 通知人 if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTY)) { error = error + "
提单号:" + alertNo + " 通知人不能为空"; } else { if (StringIsChinese(bill.NOTIFYPARTY)) { error = error + "
提单号:" + alertNo + " 通知人含有中文或双字节字符"; } else { //error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.NOTIFYPARTY, 35, alertNo, "通知人", 5, "***", false); } } #endregion #region 代理 /* if (bill.AGENT == "") { error = error + "
提单号:" + alertNo + " 代理不能为空"; } else { if (MsOpSeaeDAL.MsOpSeaeDAL.StringIsChinese(bill.AGENT)) { error = error + "
提单号:" + alertNo + " 代理含有中文或双字节字符"; } else { error += MsOpSeaeDAL.MsOpSeaeDAL.formatlengthError("txt", bill.AGENT, 35, alertNo, "代理", 5, "****"); } } */ #endregion #region 运输条款、运费协议号 if (string.IsNullOrWhiteSpace(bill.SERVICE)) { error = error + "
提单号:" + alertNo + " 运输条款不能为空"; } //string sSERVICE = MsOpSeaeDAL.MsOpSeaeDAL.GetSERVICEEDICode(bill.SERVICE.ToUpper(), ""); //if (sSERVICE == "") //{ error = error + "
提单号:" + alertNo + " 运输条款EDI代码不能为空"; } //if ((bill.CONTRACTNO == null || bill.CONTRACTNO == "")) //{ error = error + "
提单号:" + alertNo + " 运费协议号不能为空"; } #endregion #region 集装箱判断检查 var ctnlist = db.EdiCtns.Where(x => x.MFNO == bill.MFNO).ToList(); if (ctnlist.Count == 0) { error = error + "
提单号:" + alertNo + " 集装箱信息不能为空"; }; foreach (var ctn in ctnlist) { //if (MsOpSeaeDAL.MsOpSeaeDAL.GetCtnEDICode(ctn.CTNALL, "") == "") //{ error = error + "
提单号:" + alertNo + " 集装箱箱型EDI代码不能为空"; } if (checkCtnNum && !EdiDataContext.VerifyContainerCode(ctn.CNTRNO)) { { error = error + "
提单号:" + alertNo + " 箱号:" + ctn.CNTRNO + " 不符合规范"; } } if (string.IsNullOrWhiteSpace(ctn.CNTRNO)) { error = error + "
提单号:" + alertNo + " 箱号不能为空"; } if (string.IsNullOrWhiteSpace(ctn.SEALNO )) { error = error + "
提单号:" + alertNo + " 封号不能为空"; } if (string.IsNullOrWhiteSpace(ctn.KINDPKGS )) { error = error + "
提单号:" + alertNo + " 包装不能为空"; } //if (ctn.CBM == 0) //{ error = error + "
提单号:" + alertNo + " 尺码不能为零"; } } #endregion } return error; } /// /// 判断主单的件重尺是否符合总分合计 /// /// /// /// /// public static string CheckSum(string bsnos) { var bsnoList = GetBSNOsList(bsnos); EdiDataContext db = new EdiDataContext(); var billList = db.Edis.Where(x => bsnoList.Contains(x.MFNO) && (x.ISdelete==null?false:(bool)x.ISdelete)==false).ToList(); //增加判断 如不属于同一个主单 即存在BSNO不为空且不相同 则返回错误 var _bsno = ""; if (billList.Count > 0) { foreach (var item in billList) { if (string.IsNullOrWhiteSpace(_bsno)) { if (!string.IsNullOrWhiteSpace(item.BSNO)) _bsno = item.BSNO; } else { if (!string.IsNullOrWhiteSpace(item.BSNO) && item.BSNO != _bsno) { return "必须选择同一主单的分单!"; } } } } var error = ""; foreach (var item in billList) { if (string.IsNullOrWhiteSpace(item.BSNO)) { _bsno = item.MFNO; } else { _bsno = item.BSNO; } var 分单List = db.Edis.Where(x => x.BSNO == _bsno && (x.ISdelete == null ? false : (bool)x.ISdelete) == false).ToList(); if (分单List != null && 分单List.Count > 0) { var 主单 = db.Edis.FirstOrDefault(x => x.MFNO == _bsno); if (主单 == null) { return "
分单BSNO与主单MFNO不一致"; } var 件数合计 = 分单List.Sum(s => s.PKGS); decimal 重量合计 = (decimal)分单List.Sum(s => s.KGS); decimal 尺码合计 = (decimal)分单List.Sum(s => s.CBM); if (主单.PKGS != 件数合计) error += "
分票件数合计:" + 件数合计 + " 与总票件数:" + 主单.PKGS + " 不一致。"; if (主单.KGS != 重量合计) error += "
分票毛重合计:" + 重量合计.ToString("0.####") + " 与总票毛重:" + ((decimal)主单.KGS).ToString("0.####") + " 不一致。"; //if (主单.CBM != 尺码合计) errormsg += "
分票件数合计:" + 件数合计 + " 与总票件数:" + 主单.PKGS + " 不一致。"; //2020-10-27,加校验:舱单分单没有按集装箱加件重尺校验 EdiDataContext ediContext = new EdiDataContext(); var query = from edi in ediContext.Edis.AsNoTracking() join ctn in ediContext.EdiCtns.AsNoTracking() on edi.MFNO equals ctn.MFNO where edi.MBLNO == item.MBLNO select new { edi.HBLNO, ctn.CNTRNO, ctn.PKGS, ctn.KGS, ctn.CBM }; var listCheck = query.ToList(); foreach (var obj in listCheck.Where(i => i.HBLNO == null || i.HBLNO == "")) { var sumPKGS = listCheck.Where(x => x.HBLNO != null && x.HBLNO != "" && x.CNTRNO == obj.CNTRNO).Sum(x => x.PKGS); if (sumPKGS != obj.PKGS) { error += $"
箱号为{obj.CNTRNO}的件数,分单合计值与主单不一致"; } var sumKGS = listCheck.Where(x => x.HBLNO != null && x.HBLNO != "" && x.CNTRNO == obj.CNTRNO).Sum(x => x.KGS); if (sumKGS != obj.KGS) { error += $"
箱号为{obj.CNTRNO}的重量,分单合计值与主单不一致"; } //20210806 去除尺码的主分单合计数校验 //var sumCBM = listCheck.Where(x => x.HBLNO != null && x.HBLNO != "" && x.CNTRNO == obj.CNTRNO).Sum(x => x.CBM); //if (sumCBM != obj.CBM) //{ // error += $"
箱号为{obj.CNTRNO}的尺码,分单合计值与主单不一致"; //} } } } return error; } /// /// 是否同一业务 是否同一主单 /// /// /// public static string CheckCanSend(string bsnos) { var result = ""; var bsnoList = GetBSNOsList(bsnos); EdiDataContext edc = new EdiDataContext(); var 直发List = edc.Edis.Where(x => bsnoList.Contains(x.MFNO)).ToList(); var 主单List = 直发List.Where(x => x.HBLNO == null || x.HBLNO == "").ToList(); var 分单List = 直发List.Where(x => !(x.HBLNO == null || x.HBLNO.Trim() == "")).ToList(); var mblno = ""; var _bsno = ""; foreach (var item in 直发List) { if (string.IsNullOrWhiteSpace(item.BSNO)) { _bsno = item.MFNO; break; } else { _bsno = item.BSNO; break; } } foreach (var item in 直发List) { if (string.IsNullOrWhiteSpace(item.BSNO)) { if (item.MFNO != _bsno) { result += "必须发送同一主单下的业务
"; } } else { if (item.BSNO != _bsno) { result += "必须发送同一主单下的业务
"; } } } return result; } public static string CheckCanSend(string bsnos, string sendtype,string userid) { var result = ""; result = CheckCanSend(bsnos); EdiDataContext edc = new EdiDataContext(); var bsnoList = GetBSNOsList(bsnos); var 直发List = edc.Edis.Where(x => bsnoList.Contains(x.MFNO)).ToList(); var 全部为分单 = !直发List.Exists(x => x.HBLNO == "" || x.HBLNO == null); var FORWARDER = ""; if (直发List.FirstOrDefault(x => x.FORWARDER != null && x.FORWARDER != "") == null) { result += "
所有业务均未填写船代信息"; } else { FORWARDER = 直发List.FirstOrDefault(x => x.FORWARDER != null && x.FORWARDER != "").FORWARDER; } var 主单MFNO = 直发List[0].MFNO; if (!string.IsNullOrWhiteSpace(直发List[0].BSNO)) 主单MFNO = 直发List[0].BSNO; //20210419 遍历所有相关的箱信息 防止出现 件数 重量 尺码 为空或为0的数据 var 主单箱信息 = edc.EdiCtns.Where(x => x.MFNO == 主单MFNO).ToList(); var 分单箱信息 = new List(); result += checkCtnNull(主单箱信息); result += checkCtnNull(分单箱信息); var 可以单发新增分单 = UserActionHelper.取消分单发送限制(userid); //如果没有直发权限 就不限制必须分单必须同时发出 if (sendtype == "新增") { bool HasZhifaPower = CheckData.CheckHasZhiFaPower(直发List[0].INPUTBYID); var 直发 = false; if (HasZhifaPower && CheckData.CarrierCanSend(FORWARDER)) 直发 = true; if (HasZhifaPower && 全部为分单) 直发 = true; //如果具有直发权限 且没有允许分单单独直发权限 则进行如下限制 if (直发 && !可以单发新增分单) { var 这些分单所关联的所有分单List = edc.Edis.Where(x => x.BSNO == 主单MFNO).ToList(); //20210611 2、有船代直发权限的用户,如果分单下存在任意一个分单的状态是已直发,则剩下的分单允许单独发送,不走直发通道,走原来的通道。 if (这些分单所关联的所有分单List.Exists(x => x.EDISTATUS == "已直发")) { //!bsnoList.Contains(x.MFNO) && } else { var 此次发送的分单List = 直发List.Where(x => x.BSNO != "").ToList(); if (此次发送的分单List != null && 此次发送的分单List.Count > 0) { var fendan_0 = 此次发送的分单List[0]; //bool HasZhifaPower = CheckData.CheckHasZhiFaPower(fendan_0.INPUTBYID); if (此次发送的分单List.Count() != 这些分单所关联的所有分单List.Count()) result += "发送分单信息时,必须选择同一主单下的所有分单;"; var 分单MfnoList = 此次发送的分单List.Select(s => s.MFNO).ToList(); 分单箱信息 = edc.EdiCtns.Where(x => 分单MfnoList.Contains(x.MFNO)).ToList(); } } } } foreach (var bill in 直发List) { if (sendtype == "新增" && bill.EDISTATUS == "已直发") { result = result + "
舱单已直发,不允许再次新增"; } if (sendtype == "修改" && bill.EDISTATUS == "已录入") { result = result + "
未查到发送记录,类型请选择新增。"; } if (sendtype == "删除" && bill.EDISTATUS == "已录入") { result = result + "
未查到发送记录,类型请选择新增。"; } } //20211022 增加发送判断 收发通信息的人 地址 国家 电话 不可为空 foreach (var bill in 直发List) { var alertNo = "【" + bill.MBLNO + bill.HBLNO == null ? "" : ";" + bill.HBLNO + "】"; #region 发货人 if (string.IsNullOrWhiteSpace(bill.SHIPPERNAME.Trim())) { result += "
提单号:" + alertNo + " 发货人企业代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.SHIPPERADDR1)) { result += "
提单号:" + alertNo + " 发货人地址不能为空"; } if (string.IsNullOrWhiteSpace(bill.SHIPPERCOUNTRY)) { result += "
提单号:" + alertNo + " 发货人国家代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.SHIPPERTEL)) { result += "
提单号:" + alertNo + " 发货人电话不能为空"; } #endregion #region 收货人 if (string.IsNullOrWhiteSpace(bill.CONSIGNEENAME.Trim())) { result += "
提单号:" + alertNo + " 收货人企业代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.CONSIGNEEADDR1)) { result += "
提单号:" + alertNo + " 收货人地址不能为空"; } if (string.IsNullOrWhiteSpace(bill.CONSIGNEECOUNTRY)) { result += "
提单号:" + alertNo + " 收货人国家代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.CONSIGNEETEL)) { result += "
提单号:" + alertNo + " 收货人电话不能为空"; } #endregion #region 通知人 if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYNAME.Trim())) { result += "
提单号:" + alertNo + " 通知人企业代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYADDR1)) { result += "
提单号:" + alertNo + " 通知人地址不能为空"; } if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYCOUNTRY)) { result += "
提单号:" + alertNo + " 通知人国家代码不能为空"; } if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYTEL)) { result += "
提单号:" + alertNo + " 通知人电话不能为空"; } #endregion } return result; } private class CTNNULL { public string CNTRNO { get; set; } public string NULLFIELD { get; set; } public CTNNULL(string _cntrno, string _nullfield) { CNTRNO = _cntrno; NULLFIELD = _nullfield; } } private class CTNNULLList { public List List { get; set; } public void add(string CNTRNO, string NULLFIELD) { if (List != null && List.Count > 0) { if (List.Exists(x => x.CNTRNO == CNTRNO)) { foreach (var item in List) { if (item.CNTRNO == CNTRNO && !item.NULLFIELD.Contains(NULLFIELD)) { item.NULLFIELD += " " + NULLFIELD; } } } } else { List = new List(); var newrec = new CTNNULL(CNTRNO, NULLFIELD); List.Add(newrec); } } public string getErrorStr() { if (List != null && List.Count > 0) { var result = ""; foreach (var item in List) { if (result != "") result += ","; result += item.CNTRNO + ":" + item.NULLFIELD; } return result; } else { return ""; } } } private static string checkCtnNull(List 箱信息列表) { var result = ""; var CTNNULLList = new CTNNULLList(); foreach (var item in 箱信息列表) { if (item.PKGS == null || item.PKGS == 0) { CTNNULLList.add(item.CNTRNO, "件数"); } if (item.KGS == null || item.KGS == 0) { CTNNULLList.add(item.CNTRNO, "重量"); } //if (item.CBM == null || item.CBM == 0) { CTNNULLList.add(item.CNTRNO, "尺码"); } } return CTNNULLList.getErrorStr(); } 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; } } return result; } /// /// 看这个船代是否能直发 /// /// /// public static bool CarrierCanSend(string dcarrier) { //目前能进行直发的有 /* | 网站代号 | 网站名 | | -------- | ------------------------------------------------------ | | ZWY | 中外运 | | YGT | 云港通(青港) | | ZYHY | 中远海运 | | WLXX | 物流分单(FTP, 注意,如果是客户的需要上传compid,comname) | | CDCS | 舱单传输 | | WLXX | 物流分单, FTP上传 | */ var dc = dcarrier.Trim(); if (dc == "青港") return true; if (dc == "外运") return true; if (dc == "中远") return true; if (dc == "联代") return true; if (dc == "振华") return true; //if (dc == "中联运通") return true; return false; } public static string getYardidByCarriername(string dcarrier) { var yardid = ""; var dc = dcarrier.Trim(); if (dc == "青港") yardid = "CDCS"; if (dc == "外运") yardid = "ZWY"; if (dc == "中远") yardid = "ZYHY"; if (dc == "联代") yardid = "LHCD"; if (dc == "振华") yardid = "YLW"; //if (dc == "中联运通") yardid = "ZYHY"; return yardid; } /// /// 该用户是否具备直发权限 /// /// /// public static bool CheckHasZhiFaPower(string userid) { var result = false; EdiDataContext edc = new EdiDataContext(); var quanxian = edc.user_action.Where(x => x.USERID == userid && x.ACTIONID == "04B61145-C3A8-46D4-9FE4-746A80524C88").ToList(); if (quanxian != null && quanxian.Count > 0) result = true; return result; } public static string GetBSNOsInSql(string bsnos) { var result = bsnos.Replace("'", "").Replace(",", "','"); return result; } public static List GetBSNOsList(string bsnos) { var result = bsnos.Replace("'", "").Split(',').ToList(); return result; } /// /// 20210816 改为判断他们是同一主单的分单 不再关心他们是否是全部分单 /// /// /// public static Result_md 是同一主单的分单(string bsnos) { var result = new Result_md(true, ""); var bsnolist = GetBSNOsList(bsnos); EdiDataContext edc = new EdiDataContext(); var edilist = edc.Edis.Where(x => bsnolist.Contains(x.MFNO)).ToList(); //如果包含主单 返回false if (edilist.Exists(x => x.HBLNO == "" || x.HBLNO == null)) return returnfalse(result); var mblno = ""; var _bsno = "";//主单MFNO foreach (var item in edilist) { if (string.IsNullOrWhiteSpace(item.BSNO)) { _bsno = item.MFNO; break; } else { _bsno = item.BSNO; break; } } foreach (var item in edilist) { if (string.IsNullOrWhiteSpace(item.BSNO)) { if (item.MFNO != _bsno) { result.Success = false; return result; } } else { if (item.BSNO != _bsno) { result.Success = false; return result; } } } //var allbilllist = edc.Edis.Where(x => x.BSNO == _bsno).ToList(); //if (allbilllist == null || allbilllist.Count == 0) returnfalse(result);//说明没有分单 //if (allbilllist.Count != edilist.Count) returnfalse(result); return result; } public static Result_md 是一个主单或是一个主单下的全部主分单或是一个主单下的全部分单(string bsnos) { var mblno = ""; var result = new Result_md(true, ""); var bsnolist = GetBSNOsList(bsnos); EdiDataContext edc = new EdiDataContext(); var edilist = edc.Edis.Where(x => bsnolist.Contains(x.MFNO)).ToList(); if (edilist == null || edilist.Count == 0) returnfalse(result, "没有找到业务"); //如果是一个主单 返回true if (edilist.Count == 1 && (edilist[0].HBLNO == "" || edilist[0].HBLNO == null)) return result; mblno = edilist[0].MBLNO; var _bsno = ""; foreach (var item in edilist) { if (string.IsNullOrWhiteSpace(item.BSNO)) { _bsno = item.MFNO; break; } else { _bsno = item.BSNO; break; } } foreach (var item in edilist) { if (string.IsNullOrWhiteSpace(item.BSNO)) { if (item.MFNO != _bsno) { result.Success = false; return result; } } else { if (item.BSNO != _bsno) { result.Success = false; return result; } } } //如果包含主单 if (edilist.Exists(x => x.HBLNO == "" || x.HBLNO == null)) { var allbill = edc.Edis.Where(x => x.MBLNO == mblno).ToList(); if (allbill.Count == edilist.Count) return result; else returnfalse(result, "发送分单时需要选择该票的全部分单!"); } else { //只有分单 var allFendan = edc.Edis.Where(x => x.MBLNO == mblno && !(x.HBLNO.Trim() == "" || x.HBLNO == null)).ToList(); if (allFendan.Count == edilist.Count) return result; else returnfalse(result, "发送分单时需要选择该票的全部分单!"); } return result; } /// /// 主单缺少所需信息则会返回ture 令前台弹出是否选项 /// 如不缺少则返回否,前台将会自动进行后续的发送逻辑 /// /// /// /// public static Result_md 主单无回执(string bsnos, string USERID) { var result = new Result_md(true, "主单尚未获取到成功回执,建议主单申报成功后再发送分单,是否确定发送?"); var bsnolist = GetBSNOsList(bsnos); EdiDataContext edc = new EdiDataContext(); var edilist = edc.Edis.Where(x => bsnolist.Contains(x.MFNO)).ToList(); //如果包含主单 返回false //if (edilist.Exists(x => x.HBLNO == "" || x.HBLNO == null)) return returnfalse(result); //如果对应主单状态正确 返回false var MBLNO = edilist[0].MBLNO; var BSNO = edilist[0].BSNO; var headdataList = edc.Edis.Where(x => x.MFNO == BSNO).ToList(); if (headdataList == null || headdataList.Count == 0) { returnfalse(result, "主单与分单关联错误,请联系系统服务人员"); } var headdata = headdataList[0]; //查询主单状态,如回执状态正确则返回false if (主单状态为接受申报且不包括报关单放行(headdata) && 主单有主单详细信息(headdata.MBLNO)) return returnfalse(result); //如当前回执不正确则调用接口读取主单状态,如回执状态正确则返回false //var _r = WLXX.ReadWLXX(mblno, headdata.MFNO,"临时读取"); var _r = WLXX.Read_StatusZDXX(MBLNO, USERID, headdata.MFNO); CommonDataContext cdc = new CommonDataContext(); var senduser = cdc.Users.FirstOrDefault(x => x.GID == USERID); var showname = "系统管理员"; if (senduser != null) { showname = senduser.SHOWNAME; } if (_r.Success) { WLXX.删除待读主单(headdata.MFNO); //由于此处一定是在录入完成之后某次操作之后进行读取 //因此,在此时寻找现有tips中最新一条的内容,如有 则取其type使用,如无则使用新增 var rtn = _r.Data.ToString(); var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); var portstatus = PortResult.message; if (主单状态为接受申报且不包括报关单放行(headdata) && 主单有主单详细信息(headdata.MBLNO)) return returnfalse(result, "主单尚未获取到成功回执,建议主单申报成功后再发送分单,是否确定发送?"); if (portstatus.报关单放行晚于接受申报()) { return returnfalse(result, "主单报关单已放行,分单发送可能无效,是否确定发送?"); } //20210602 增加判断 如果读回的主单信息件数重量和现存主单的所有分单的件数重量合计不一致 或者本地分单箱号封号与读回的箱号封号不一致 或者删除标志为删除 var 本地分单与读回主单一致 = ZDXXChanged(headdata, PortResult); if (!本地分单与读回主单一致.Success) return 本地分单与读回主单一致; } return result; } //发送分单时,分单的件数,重量,箱号,封号,箱量,需要与总单校验,如果不一致,给出提示:XXXX与总单不符,请检查。 public static Result_md ZDXXChanged(OpSeaeEdi headdata, StatusZDXX_HeadModel ZDXX) { var result = new Result_md(); result.Success = true; var ZDXXHead = ZDXX.message; if (ZDXXHead.delete_flag == "删除") { result.Success = false; result.Message = "主单信息已删除"; return result; } EdiDataContext edc = new EdiDataContext(); var 主单的分单MfnoList = edc.Edis.Where(x => x.BSNO == headdata.MFNO).Select(s=>s.MFNO).ToList(); //寻找该主单在本地的所有分单的箱信息 var 分单箱信息List = edc.EdiCtns.Where(x => 主单的分单MfnoList.Contains(x.MFNO)).ToList(); var 读回的主单信息的箱信息List = ZDXXHead.xh_info; var errormsg = ""; var 箱号封号与读回的主单信息不对应 = 是否有箱号封号不对应(分单箱信息List, 读回的主单信息的箱信息List,out errormsg); //if (箱号封号与读回的主单信息不对应) { // result.Success = false; // result.Message = errormsg; //} var sumPKGS = 分单箱信息List.Sum(s => s.PKGS); var sumKGS = 分单箱信息List.Sum(s => s.KGS); if ((decimal)sumPKGS != ZDXXHead.goods_num) { errormsg += $"本地分单总件数{sumPKGS}和网站总件数{ZDXXHead.goods_num}不符;"; } if ((decimal)sumKGS != ZDXXHead.goods_weight) { errormsg += $"本地分单总毛重{sumKGS}和网站毛重{ZDXXHead.goods_weight}不符;"; } if (errormsg != "") { result.Success = false; result.Message = errormsg; } return result; } public static Result_md ZDXXChanged(string 主单MFNO) { EdiDataContext edc = new EdiDataContext(); var headdata = edc.Edis.FirstOrDefault(x => x.MFNO == 主单MFNO); var zddata = edc.op_seae_edi_mainstatus.FirstOrDefault(x => x.mfno == 主单MFNO); var zdctninfo = edc.op_seae_edi_mainstatus_xhinfo.Where(x=> x.mfno == 主单MFNO).ToList(); var ZDXXLocal = new StatusZDXX_HeadModel(); ZDXXLocal.message = AutoMapperHelper.MapTo(zddata); ZDXXLocal.message.xh_info= AutoMapperHelper.MapToList(zdctninfo); //ZDXXLocal.message.xh_info. return ZDXXChanged(headdata, ZDXXLocal); } /// /// 箱信息按箱号封号合计 /// //private static List 箱信息按箱号封号合计(List 箱信息List){ // var 用于比较的箱信息List = new List(); // foreach (var item in 箱信息List) // { // if (用于比较的箱信息List.Exists(x => x.CNTRNO == item.CNTRNO && x.SEALNO == item.SEALNO)) // { // 用于比较的箱信息List.First(x => x.CNTRNO == item.CNTRNO && x.SEALNO == item.SEALNO).PKGS += item.PKGS; // 用于比较的箱信息List.First(x => x.CNTRNO == item.CNTRNO && x.SEALNO == item.SEALNO).KGS += item.KGS; // } // else // { // var newctn = AutoMapperHelper.MapTo(item); // 用于比较的箱信息List.Add(newctn); // } // } // return 用于比较的箱信息List; //} private static bool 是否有箱号封号不对应(List 箱信息List, List 读回的箱信息List,out string msg) { var result = false; msg = ""; foreach (var item in 箱信息List) { if (!读回的箱信息List.Exists(x => x.xh == item.CNTRNO && x.QianFengHao == item.SEALNO)) { msg = $"本地箱信息[{item.CNTRNO},{item.SEALNO}] 在网站上不存在;"; result = true; } } foreach (var item in 读回的箱信息List) { if (!箱信息List.Exists(x => x.CNTRNO == item.xh && x.SEALNO == item. QianFengHao)) { msg += $"网站箱信息[{item.xh},{item.QianFengHao}] 在本地不存在;"; result = true; return result; } } return result; } public static Result_md returnfalse(Result_md _r,string msg="") { _r.Success = false; if (!string.IsNullOrWhiteSpace(msg)) _r.Message = msg; return _r; } public static bool 报关单放行晚于接收申报(OpSeaeEdi head) { //如果没有接受申报 返回true //如果没有报关单放行 返回false //如果 EdiDataContext edc = new EdiDataContext(); var statuslist = edc.op_seae_edi_status.Where(x => x.mfno == head.MFNO).OrderByDescending(o => o.statustime).ToList(); var result = false; if (statuslist != null && statuslist.Count > 0) { var 接受申报时间 = new DateTime(1900, 1, 1); foreach (var item in statuslist) { if (item.statustext == "接受申报" && item.ShenBaoXiangShu > 0) { 接受申报时间 = item.statustime; result = true; } } } return result; } /// /// 即主单状态为 接受申报 或 主单状态包括放行二字 /// /// public static bool 主单状态为接受申报且不包括报关单放行(OpSeaeEdi head) { EdiDataContext edc = new EdiDataContext(); var statuslist = edc.op_seae_edi_status.Where(x=>x.mfno==head.MFNO).OrderByDescending(o=>o.statustime).ToList(); var result = false; if (statuslist!=null && statuslist.Count > 0) { var 接受申报时间 = new DateTime(1900,1,1); foreach (var item in statuslist) { if (item.statustext == "接受申报" && item.ShenBaoXiangShu>0 ) { 接受申报时间 = item.statustime; result = true; } } if (!result) return result; foreach (var item in statuslist) { if (item.statustext.Contains("报关单") && item.statustime> 接受申报时间) { result = false; break; } } } return result; } public static bool 主单有主单详细信息(string MBLNO) { EdiDataContext edc = new EdiDataContext(); var zdxxHeadlist = edc.op_seae_edi_mainstatus.Where(x => x.mblno == MBLNO).ToList(); var zdxxBodylist = edc.op_seae_edi_mainstatus_xhinfo.Where(x => x.mblno == MBLNO).ToList(); if ((zdxxHeadlist != null && zdxxHeadlist.Count > 0) && (zdxxBodylist != null && zdxxBodylist.Count > 0)) { return true; } else { return false; } } public static string GetLoadPortEdiCode(string loadportcode) { var result = ""; EdiDataContext edc = new EdiDataContext(); var ld = edc.CodeLoadport.Where(x => x.EDICODE.Contains(loadportcode)).ToList(); if (ld != null && ld.Count > 0) { var lditem = ld[0]; result = lditem.EDICODE; } return result; } //public static string 中远包装代码(string code) { // var result = ""; // return result; //} //public static string 特殊包装代码(string oldcode, string codecolumnname) { //} } public class SendInfo { public string yardid { get; set; } //public string whlURL { get { return "http://47.104.90.170:8000/sub"; } } //public string whlURL { get { return "http://47.104.90.170:8000/sub"; } } public string whlURL { get; set; } public int timeOut { get; set; } public string fileKeyName { get; set; } public NameValueCollection nv { get; set; } public string filename { get; set; } public string filepath { get; set; } /// /// 该客户使用自己的网站用户名和密码登陆船代网站 /// public bool useOwnPwd { get; set; } public string webusername { get; set; } public string webpassword { get; set; } public string defaultusername { get { return "qdds"; } } public string defaultpwd { get { return "ds20040201"; } } public SendInfo() { } public SendInfo(string dcarrier, string filepath,string userid,bool isFendan=false) { whlURL = "http://47.104.90.170:8000/sub"; yardid = CheckData.getYardidByCarriername(dcarrier); nv = new NameValueCollection(); useOwnPwd = false; //nv.Add("custname", "qdds"); //nv.Add("custpsw", "ds20040201"); timeOut = 15000; fileKeyName = "file"; filename = Path.GetFileName(filepath); this.filepath = filepath; //如果维护了相应船代的用户名和密码 则使用之 setPwd(userid, dcarrier, isFendan); } /// /// 用于组织读取主单信息的参数组织 /// /// data = { ///'yardid': 'WLCD', 必须 ///'mblno': 'AAST013610', 必须 ///'isweb': 2, 暂时默认为2 ///'webusername': '', 客户用来登录的账号密码, 没有就不传 ///'webuserpass': '', ///'wltype': 'WLXXSX' 必须 ///} /// /// public static SendInfo ZDXXHelper(string dcarrier, string userid,string MBLNO) { var result = new SendInfo(); result.nv = new NameValueCollection(); result.useOwnPwd = false; EdiDataContext edc = new EdiDataContext(); var useraccount = edc.USER_ACCOUNT.Where(x => x.userid == userid).ToList(); if (useraccount != null && useraccount.Count > 0) { var _ua = useraccount[0]; //如果维护了相应船代的用户名和密码 则使用之 if (!string.IsNullOrWhiteSpace(_ua.DZKAUserName) && !string.IsNullOrWhiteSpace(_ua.DZKAPassword)) { result.useOwnPwd = true; result.addWebpwd(_ua.DZKAUserName, _ua.DZKAPassword); } else { result.useOwnPwd = false; var DSUserAccount = edc.USER_ACCOUNT.First(x => x.userid == "d85fd590-d9f6-4410-93a1-f6fac77b606e"); result.addWebpwd(DSUserAccount.DZKAUserName, DSUserAccount.DZKAPassword); } } result.timeOut = 15000; result.whlURL = "http://47.104.90.170:5000/query"; return result; } public static SendInfo StatusZDXXHelper(string dcarrier, string userid, string MBLNO) { var result = new SendInfo(); result.nv = new NameValueCollection(); result.useOwnPwd = false; EdiDataContext edc = new EdiDataContext(); var useraccount = edc.USER_ACCOUNT.Where(x => x.userid == userid).ToList(); if (useraccount != null && useraccount.Count > 0) { var _ua = useraccount[0]; //如果维护了相应船代的用户名和密码 则使用之 if (!string.IsNullOrWhiteSpace(_ua.DZKAUserName) && !string.IsNullOrWhiteSpace(_ua.DZKAPassword)) { result.useOwnPwd = true; result.addWebpwd(_ua.DZKAUserName, _ua.DZKAPassword); } else { result.useOwnPwd = false; var DSUserAccount = edc.USER_ACCOUNT.First(x => x.userid == "d85fd590-d9f6-4410-93a1-f6fac77b606e"); result.addWebpwd(DSUserAccount.DZKAUserName, DSUserAccount.DZKAPassword); } } result.timeOut = 20000; result.whlURL = "http://47.104.90.170:5000/query"; return result; } public void setPwd(string userid,string dcarrier,bool isFendan=false) { EdiDataContext edc = new EdiDataContext(); var useraccount = edc.USER_ACCOUNT.Where(x => x.userid == userid).ToList(); if (useraccount != null && useraccount.Count > 0) { var _ua = useraccount[0]; if (isFendan) { nv.Add("yardid", "WLXX"); if (!string.IsNullOrWhiteSpace(_ua.DZKAUserName) && !string.IsNullOrWhiteSpace(_ua.DZKAPassword)) { useOwnPwd = true; addWebpwd(_ua.DZKAUserName, _ua.DZKAPassword); } else { useOwnPwd = false; var DSUserAccount = edc.USER_ACCOUNT.First(x => x.userid == "d85fd590-d9f6-4410-93a1-f6fac77b606e"); addWebpwd(DSUserAccount.DZKAUserName, DSUserAccount.DZKAPassword); } addDsportpwd(_ua.DSPORTUserName, _ua.DSPORTPassword); #region 客户自发分单 20220822 增加逻辑 // 20220822 增加逻辑 //select v.ItemCode from company_new_param_value v join company_new c on c.CompId = v.CompId where v.ParaCode = 'AUTO_DRAFT_SEND' and c.CompId = '9f3b3526-4dd4-4997-b974-1f2adb2793c7' //如果系统配置参数中包含CANGDAN_SEND_PASSAGEWAY=CUSTOMER的话 增加corpid和corpname参数 //如否则增加这两个空参数 var userinfo = edc.Users.FirstOrDefault(x => x.GID == userid); if (string.IsNullOrWhiteSpace(userinfo.CompId)) { //未认证客户 走正常流程 增加这两个空参数 addCompInfo("", ""); } else { //认证的客户 具有compid 查看他是否有配置系统参数AUTO_DRAFT_SEND var cdc = new CommonDataContext(); var 公司参数 = cdc.ParamValues.Where(x => x.CompId == userinfo.CompId ).ToList(); if (公司参数 != null && 公司参数.Count() > 0 && 公司参数.Exists(x=> x.ParaCode == "CANGDAN_SEND_PASSAGEWAY" && x.ItemCode == "CUSTOMER")) { //已配置该参数 增加公司名称和公司id addCompInfo(userinfo.CompId, userinfo.COMNAME); } else { //未配置该参数 传空值 addCompInfo("", ""); } } #endregion whlURL = "http://47.104.90.170:8000/customer/sub"; //whlURL = "http://test"; } else { nv.Add("yardid", yardid); if (dcarrier == "青港") { if (!string.IsNullOrWhiteSpace(_ua.ZHUserName) && !string.IsNullOrWhiteSpace(_ua.ZHPassword)) { useOwnPwd = true; addWebpwd(_ua.ZHUserName, _ua.ZHPassword); } } if (dcarrier == "外运") { if (!string.IsNullOrWhiteSpace(_ua.WYUserName) && !string.IsNullOrWhiteSpace(_ua.WYPassword)) { useOwnPwd = true; addWebpwd(_ua.WYUserName, _ua.WYPassword); } } if (dcarrier == "中创") { if (!string.IsNullOrWhiteSpace(_ua.ZCUserName) && !string.IsNullOrWhiteSpace(_ua.ZCPassword)) { useOwnPwd = true; addWebpwd(_ua.ZCUserName, _ua.ZCPassword); } } if (dcarrier == "中远") { if (!string.IsNullOrWhiteSpace(_ua.ZYUserName) && !string.IsNullOrWhiteSpace(_ua.ZYPassword)) { useOwnPwd = true; addWebpwd(_ua.ZYUserName, _ua.ZYPassword); } } if (dcarrier == "振华") { if (!string.IsNullOrWhiteSpace(_ua.ZHUAUserName) && !string.IsNullOrWhiteSpace(_ua.ZHUAPassword)) { useOwnPwd = true; addWebpwd(_ua.ZHUAUserName, _ua.ZHUAPassword); } } if (dcarrier == "联代") { if (!string.IsNullOrWhiteSpace(_ua.LDUserName) && !string.IsNullOrWhiteSpace(_ua.LDPassword)) { useOwnPwd = true; addWebpwd(_ua.LDUserName, _ua.LDPassword); } } if (useOwnPwd == true) { addDsportpwd(_ua.DSPORTUserName, _ua.DSPORTPassword); whlURL = "http://47.104.90.170:8000/customer/sub"; } } } else { useraccount = edc.USER_ACCOUNT.Where(x => x.userid == "d85fd590-d9f6-4410-93a1-f6fac77b606e").ToList(); var _ua = useraccount[0]; if (isFendan) { nv.Add("yardid", "WLXX"); if (!string.IsNullOrWhiteSpace(_ua.DZKAUserName) && !string.IsNullOrWhiteSpace(_ua.DZKAPassword)) { useOwnPwd = true; addWebpwd(_ua.DZKAUserName, _ua.DZKAPassword); } else { useOwnPwd = false; var DSUserAccount = edc.USER_ACCOUNT.First(x => x.userid == "d85fd590-d9f6-4410-93a1-f6fac77b606e"); addWebpwd(DSUserAccount.DZKAUserName, DSUserAccount.DZKAPassword); } addDsportpwd(_ua.DSPORTUserName, _ua.DSPORTPassword); whlURL = "http://47.104.90.170:8000/customer/sub"; } else { nv.Add("yardid", yardid); if (dcarrier == "青港") { if (!string.IsNullOrWhiteSpace(_ua.ZHUserName) && !string.IsNullOrWhiteSpace(_ua.ZHPassword)) { useOwnPwd = true; addWebpwd(_ua.ZHUserName, _ua.ZHPassword); } } if (dcarrier == "外运") { if (!string.IsNullOrWhiteSpace(_ua.WYUserName) && !string.IsNullOrWhiteSpace(_ua.WYPassword)) { useOwnPwd = true; addWebpwd(_ua.WYUserName, _ua.WYPassword); } } if (dcarrier == "中创") { if (!string.IsNullOrWhiteSpace(_ua.ZCUserName) && !string.IsNullOrWhiteSpace(_ua.ZCPassword)) { useOwnPwd = true; addWebpwd(_ua.ZCUserName, _ua.ZCPassword); } } if (dcarrier == "中远") { if (!string.IsNullOrWhiteSpace(_ua.ZYUserName) && !string.IsNullOrWhiteSpace(_ua.ZYPassword)) { useOwnPwd = true; addWebpwd(_ua.ZYUserName, _ua.ZYPassword); } } if (dcarrier == "振华") { if (!string.IsNullOrWhiteSpace(_ua.ZHUAUserName) && !string.IsNullOrWhiteSpace(_ua.ZHUAPassword)) { useOwnPwd = true; addWebpwd(_ua.ZHUAUserName, _ua.ZHUAPassword); } } if (dcarrier == "联代") { if (!string.IsNullOrWhiteSpace(_ua.LDUserName) && !string.IsNullOrWhiteSpace(_ua.LDPassword)) { useOwnPwd = true; addWebpwd(_ua.LDUserName, _ua.LDPassword); } } if (useOwnPwd == true) { addDsportpwd(_ua.DSPORTUserName, _ua.DSPORTPassword); whlURL = "http://47.104.90.170:8000/customer/sub"; } } } } private void addWebpwd(string username,string pwd) { nv.Add("webusername", username); nv.Add("webpassword", pwd); webusername = username; webpassword = pwd; } private void addDsportpwd(string username, string pwd) { nv.Add("custname", username); nv.Add("custpsw", pwd); } private void addCompInfo(string compid, string comname) { nv.Add("compid", compid); nv.Add("comname", comname); } public string getUsername() { if (useOwnPwd) { return nv.Get("webusername"); } return defaultusername; } public string getPwd() { if (useOwnPwd) { return nv.Get("webpassword"); } return defaultpwd; } } public class ChangeInfo { //public static List SetNewStatus(OpSeaeEdi billhead,string status,string newtips = "", bool isFenDan = false) //{ // var result = new List(); // result.Add(EdiSetStatus(billhead, status, newtips)); // if (isFenDan) { // var edc = new EdiDataContext(); // var fenlist = edc.Edis.Where(x => x.MFNO == billhead.MFNO && !string.IsNullOrEmpty(x.HBLNO)).ToList(); // foreach (var item in fenlist) { // result.Add(EdiSetStatus(item,status,newtips)); // } // } // return result; //} //public static OpSeaeEdi EdiSetStatus(OpSeaeEdi billhead, string status, string newtips = "") { // if (billhead.ZhiFaText == "") billhead.ZhiFaText = newtips; // else // billhead.ZhiFaText += "\n" + newtips; // billhead.EDISTATUS = status; // return billhead; //} public static void EdiChangeStatus(OpSeaeEdi billhead, string status, string newtips, string showname, string dcarrier) { EdiDataContext edc = new EdiDataContext(); EdiChangeStatus(edc, billhead, status, newtips, showname, dcarrier); } public static void EdiChangeStatus(EdiDataContext edc, OpSeaeEdi billhead, string status, string newtips, string showname, string dcarrier) { //20210113 改为写入OP_SEAE_EDI_TIPS表 OP_SEAE_EDI_TIPS_md tips = new OP_SEAE_EDI_TIPS_md(billhead); var markword = " r.WriteLine("CN37"); r.WriteLine(""); r.WriteLine("001"); //运费支付信息(循环次数:1) r.WriteLine(""); //运费支付方法代码(循环次数:1) r.WriteLine("" + xtype + ""); r.WriteLine(""); //货物总件数/包装种类代码(循环次数:1) r.WriteLine(""); //货物总件数(循环次数:1) r.WriteLine("" + FenDan.PKGS.ToString() + ""); // 包装种类代码(循环次数:0-1) r.WriteLine("" + ChangeInfo.GetPackageEDICode(FenDan.KINDPKGS.ToString(), "HGYDT").Trim() + ""); r.WriteLine(""); //货物总毛重(循环次数:1) r.WriteLine("" + FenDan.KGS.ToString() + ""); #endregion #region 收货人 //收货人信息(循环次数:0-1) r.WriteLine(""); //收货人代码(循环次数:0-1) // r.WriteLine("" + FenDan.LeiXingShou + "+" + FenDan.CONSIGNEECODE + ""); //r.WriteLine(""); //收货人名称(循环次数:0-1) var Shipping = ChangeInfo.formatEdiStr("both", FenDan.CONSIGNEE); List ShippingList = ChangeInfo.formatlengthStr(Shipping, 35); if (ShippingList.Count >= 1) r.WriteLine("" + ShippingList[0].ToString() + ""); else r.WriteLine(""); //收货人地址信息(循环次数:0-1) r.WriteLine("
"); //详细地址(街道,邮箱)(循环次数:0-1) r.WriteLine("" + ChangeInfo.formatEdiStr("both", FenDan.CONSIGNEEADDR1) + ""); r.WriteLine("" + FenDan.CONSIGNEECOUNTRY + ""); r.WriteLine("
"); r.WriteLine(""); if (!string.IsNullOrWhiteSpace(FenDan.SHIPPERTEL)) { r.WriteLine("" + FenDan.CONSIGNEETEL + ""); r.WriteLine("TE"); } else { r.WriteLine("" + FenDan.CONSIGNEEEMAIL + ""); r.WriteLine("EM"); } r.WriteLine(""); r.WriteLine("
"); #endregion #region 发货人 //发货人信息(循环次数:1) r.WriteLine(""); //发货人代码(循环次数:0-1) // r.WriteLine("" + FenDan.LeiXingFa + "+" + FenDan.SHIPPERCODE + ""); //r.WriteLine(""); //发货人名称(循环次数:1) Shipping = ChangeInfo.formatEdiStr("both", FenDan.SHIPPER); List ShippingList2 = ChangeInfo.formatlengthStr(Shipping, 35); if (ShippingList2.Count >= 1) r.WriteLine("" + ShippingList2[0].ToString() + ""); else r.WriteLine(""); //发货人地址信息(循环次数:0-1) r.WriteLine("
"); //详细地址(街道,邮箱)(循环次数:0-1) r.WriteLine("" + ChangeInfo.formatEdiStr("both", FenDan.SHIPPERADDR1) + ""); r.WriteLine("" + FenDan.SHIPPERCOUNTRY + ""); r.WriteLine("
"); r.WriteLine(""); if (!string.IsNullOrWhiteSpace(FenDan.SHIPPERTEL)) { r.WriteLine("" + FenDan.SHIPPERTEL + ""); r.WriteLine("TE"); } else { r.WriteLine("" + FenDan.SHIPPEREMAIL + ""); r.WriteLine("EM"); } r.WriteLine(""); r.WriteLine("
"); #endregion #region 通知人 //通知人信息(循环次数:0-1) r.WriteLine(""); //通知人代码(循环次数:0-1) // r.WriteLine("" + FenDan.LeiXingTong + "+" + FenDan.NOTIFYPARTYCODE + ""); //r.WriteLine(""); //通知人名称(循环次数:0-1) Shipping = ChangeInfo.formatEdiStr("both", FenDan.NOTIFYPARTY); List ShippingList3 = ChangeInfo.formatlengthStr(Shipping, 35); if (ShippingList3.Count >= 1) r.WriteLine("" + ShippingList3[0].ToString() + ""); else r.WriteLine(""); //通知人地址信息(循环次数:0-1) r.WriteLine("
"); //详细地址(街道,邮箱)(循环次数:1) r.WriteLine("" + ChangeInfo.formatEdiStr("both", FenDan.NOTIFYPARTYADDR1) + ""); r.WriteLine("" + FenDan.NOTIFYPARTYCOUNTRY + ""); r.WriteLine("
"); //20220725 收货人电话 TE r.WriteLine(""); //详细地址(街道,邮箱)(循环次数:1) r.WriteLine("" + FenDan.CONSIGNEETEL + ""); r.WriteLine("TE"); r.WriteLine(""); //if (!string.IsNullOrWhiteSpace( FenDan.NOTIFYPARTYTEL) || !string.IsNullOrWhiteSpace(FenDan.NOTIFYPARTYEMAIL)) //{ // r.WriteLine(""); // if (!string.IsNullOrWhiteSpace(FenDan.NOTIFYPARTYTEL)) // { // r.WriteLine("" + FenDan.NOTIFYPARTYTEL + ""); // r.WriteLine("TE"); // } // else // { // r.WriteLine("" + FenDan.NOTIFYPARTYEMAIL + ""); // r.WriteLine("EM"); // } // r.WriteLine(""); //} r.WriteLine("
"); #endregion #region 危险品信息 if (FenDan.CARGOID.Trim() == "D") { r.WriteLine(""); r.WriteLine("" + FenDan.DATTN + ""); r.WriteLine(""); r.WriteLine("" + FenDan.DTEL + ""); r.WriteLine("TE"); r.WriteLine(""); r.WriteLine(""); } #endregion //var ctnList = MsOpSeaeEdiDAL.GetBodyList("MFNO = '" + FenDan.MFNO + "'"); var ctnList = edc.EdiCtns.Where(x => x.MFNO == FenDan.MFNO).ToList(); foreach (var ctn in ctnList) { if (!zdxxBodyList.Exists(x => x.xh == ctn.CNTRNO)) { var _msg = "未对应的箱号【" + ctn.CNTRNO + "】"; throw new Exception(_msg); } var zdxxctninfo = zdxxBodyList.First(x => x.xh == ctn.CNTRNO); #region 集装箱_箱号 // 集装箱(器)信息(循环次数:0-9999) r.WriteLine(""); //集装箱(器)编号信息(循环次数:1) r.WriteLine(""); // 集装箱(器)编号(循环次数:1) r.WriteLine("" + ctn.CNTRNO + ""); r.WriteLine(""); //集装箱(器)尺寸和类型(循环次数:1) string sCTNALL = zdxxctninfo.xx; //if (opBill.FORWARDER == "中远" && ctn.CTNALL == "20GP") //{ // sCTNALL = "22G0"; //} //else if (opBill.FORWARDER == "中远" && (ctn.CTNALL == "40HC" || ctn.CTNALL == "40HQ")) //{ // sCTNALL = "45G0"; //} //else if (opBill.FORWARDER == "中远" && ctn.CTNALL == "40GP") //{ // sCTNALL = "42G0"; //} //else //{ // sCTNALL = GetCtnNameForFenDan(ctn.CTNALL); //} //改为从(保存下来的【读取主单信息】的结果中取 if (!string.IsNullOrWhiteSpace(sCTNALL)) { r.WriteLine("" + sCTNALL + ""); } else { r.WriteLine(""); } //集装箱(器)来源代码(循环次数:0-1) r.WriteLine("2"); //重箱或者空箱标识代码(循环次数:1) //if (opBill.FORWARDER == "振华" || opBill.FORWARDER == "外代") //{ // r.WriteLine("" + "8" + ""); //} //else //{ // r.WriteLine("" + ctn.ZhongKongBiaoShi + ""); //} r.WriteLine("" + zdxxctninfo.getZKBS() + ""); //SealID的值是封志类型/号码,AgencyCode的值是施加封志人类型(循环次数:0-9) r.WriteLine("M/" + ctn.SEALNO + ""); r.WriteLine(""); #endregion } #region 集装箱_内容 //商品项信息(循环次数:1-999) r.WriteLine(""); //商品项序号(循环次数:1) r.WriteLine("1"); //商品项包装信息(循环次数:1) r.WriteLine(""); //商品项货物件数(循环次数:1) r.WriteLine("" + FenDan.PKGS.ToString() + ""); //包装种类代码(循环次数:0-1) r.WriteLine("" + ChangeInfo.GetPackageEDICode(FenDan.KINDPKGS.ToString(), "HGYDT").Trim() + ""); //唛头(循环次数:0-1) //Shipping = MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatEdiStr("txt", opBill.MARKS); //if (Shipping.Length > 256) //{ // Shipping = Shipping.Substring(0, 250); //} //Shipping = Shipping.Replace("\n", "\\"); //Shipping = Shipping.Replace("\r", " "); r.WriteLine("" + ChangeInfo.formatEdiStr("both", FenDan.MARKS) + ""); r.WriteLine(""); //商品项简要描述(循环次数:1) r.WriteLine(""); //商品项简要描述(循环次数:1) //string sDESCRIPTION = ""; //sSQL = "SELECT * from op_manifest where bsno='" + opBill.BSNO.ToString() + "' AND MBLNO='" + dsFenDan.Tables[0].Rows[i]["MBLNO"].ToString() + "' order by MBLNO"; //DataSet dsDESCRIPTION = T_ALL_DA.GetAllSQL(sSQL);//如果是“一分单多箱号”,则需要循环合并货描内容 //if (dsDESCRIPTION != null) //{ // if (dsDESCRIPTION.Tables[0].Rows.Count > 0) // { // for (int j = 0; j < dsDESCRIPTION.Tables[0].Rows.Count; j++) // { // sDESCRIPTION += dsDESCRIPTION.Tables[0].Rows[j]["DESCRIPTION"].ToString(); // } // } //} //Shipping = MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatEdiStr("txt", sDESCRIPTION); //if (Shipping.Length > 256) //{ // Shipping = Shipping.Substring(0, 250); //} //Shipping = Shipping.Replace("\n", "\\"); //Shipping = Shipping.Replace("\r", " "); r.WriteLine("" + ChangeInfo.formatEdiStr("both", FenDan.DESCRIPTION) + ""); //危险品编号(循环次数:0-1) if (opBill.CARGOID.Trim() == "D") { r.WriteLine("" + FenDan.DUNNO + ""); } //海关税则编号(循环次数:0-1)//20220727去掉 //r.WriteLine(""); r.WriteLine(""); //商品项货物毛重(循环次数:1) r.WriteLine(""); //商品项货物毛重(循环次数:1) r.WriteLine("" + FenDan.KGS.ToString() + ""); r.WriteLine(""); #endregion foreach (var ctn in ctnList) { #region 集装箱_封号 //集装箱(器)编号信息(循环次数:0-9999) r.WriteLine(""); // 集装箱(器)编号(循环次数:1) r.WriteLine("" + ctn.CNTRNO + ""); r.WriteLine(""); #endregion } r.WriteLine(""); r.WriteLine(""); } } r.WriteLine(""); r.WriteLine(""); #endregion r.Close(); f.Close(); return FileName; } private static string SetXMLStr(string str) { var result = str; //Result:= Trim(str); //Result:= StringReplace(Result, '&', '&',[rfReplaceAll]); //Result:= StringReplace(Result, '<', '<',[rfReplaceAll]); //Result:= StringReplace(Result, '"', '"',[rfReplaceAll]); //Result:= StringReplace(Result, '>', '>',[rfReplaceAll]); //Result:= StringReplace(Result, '''', ''',[rfReplaceAll]); result = result.Replace("&", "&"); result = result.Replace("<", "<"); result = result.Replace("\"", """); result = result.Replace(">", ">"); result = result.Replace("'", "'"); return result; } private static string GetCtnNameForFenDan(string ctn) { CommonDataContext cdc = new CommonDataContext(); //string sql = "select EDICODE from code_ctn where ctn = '" + ctn + "'"; //Database db = DatabaseFactory.CreateDatabase(); var codectn = cdc.Ctns.FirstOrDefault(x => x.CTN == ctn); string ctnname = ctn; try { //var rst = db.ExecuteScalar(CommandType.Text, sql); //if (rst != DBNull.Value && rst != null) //{ // ctnname = rst.ToString(); //} //else //{ // ctnname = ctn; //} //return ctnname; if (codectn != null) { ctnname = codectn.EDICODE; } } catch (Exception) { return ctn; } return ctnname; } #endregion /// /// 发送舱单 发送主单 /// /// /// /// /// /// /// /// public static Result_md SendEdiDirect(List EdiList, string dcarrier, string filepath,string userid, string showname, string type) { var result = new Result_md(); var sendinfo = new SendInfo(dcarrier, filepath, userid); if (sendinfo.yardid == "") return new Result_md(false, $"船公司{dcarrier}不符合要求"); if (dcarrier == "青港") { foreach (var item in EdiList) { if (string.IsNullOrWhiteSpace(item.CARRIER)) { result.Success = false; result.Message = "船公司不能为空"; return result; } } } var msg = ""; //var beizhu = ""; //var edc = new EdiDataContext(); try { if (filepath != "") { //var qduname = MsSysParamSetDAL.GetData("PARAMNAME='QDPORTUSER'").PARAMVALUE; //var qdpwd = MsSysParamSetDAL.GetData("PARAMNAME='QDPORTPASS'").PARAMVALUE; //string whlURL = "http://47.104.90.170:8000/sub"; //NameValueCollection nv = new NameValueCollection(); //nv.Add("yardid", yardid); //nv.Add("custname", "qdds"); //nv.Add("custpsw", "ds20040201"); ////nv.Add("webusername", qduname); ////nv.Add("webpassword", qdpwd); //string content = HttpPostData(whlURL, 10000, "file", filepath, filename, nv); ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Sending); string content = HttpPost_Port(sendinfo); //string content = "{\"status\":\"1\", \"message\":\"上传成功\"}"; EdiDataContext.SaveLog("舱单直发", "发送主单", "[" + EdiList[0].MBLNO + "]" + content, userid); if (content.Contains("远程服务器返回错误")) { ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Fail, content); result.Success = false; result.Message = content; return result; } var objRtn2 = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(content, new { status = "", message = "" }); //var objRtn2 = new { status = "1", message = "" }; if (objRtn2.status == "1") { ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Success); result.Success = true; result.Message = "舱单发送成功!"; } else { ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Fail, objRtn2.message); result.Success = false; result.Message = objRtn2.message; } } else { ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Fail); result.Success = false; result.Message = "直发舱单错误!" + msg; } return result; } catch (Exception e) { ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Fail); EdiDataContext.SaveLog("舱单直发", "发送主单", "错误[" + EdiList[0].MBLNO + "]" + e.Message, userid); result.Success = false; result.Message = "直发舱单错误!" ; return result; } } public class PortResult { //public string stats { get; set; } public string status { get; set; } public string message { get; set; } public PortResult() { } public PortResult(string str) { var PortResult = JsonConvert.DeserializeObject(str); //stats = PortResult.stats; status = PortResult.status; message= PortResult.message; } } public Result_md SendFendanDirect(List EdiList, string dcarrier, string filepath, string userid, string showname, string type) { //http://47.104.73.97:8111/cdpost.ashx //action=dzka //username password //encode =1 /* * /customer/sub yardid="WLXX" custname = 东胜用户名 custpsw webusername = 客户自己的网站用户名 webpassword file */ var result = new Result_md(); var errorMFNO = ""; try { var sendinfo = new SendInfo(dcarrier, filepath, userid, true); ChangeInfo.SetEdiStatus(EdiList, type, showname, dcarrier, EdiSendStatus.Sending); string content = HttpPost_DZKA(sendinfo); EdiDataContext.SaveLog("舱单直发", "发送分单_返回值", "[" + EdiList[0].MBLNO + "]" + content, userid); //string content = "{\"status\":\"1\", \"message\":\"上传成功\"}"; var contentStr = UnicodeToString(content); //EdiDataContext.SaveLog("舱单直发", "发送分单_返回值", "[" + EdiList[0].MBLNO + "]" + contentStr, userid); //发送正确的分单 应该在返回文本中针对每一个分单都包括一个 [分单:N240230148B]申报成功 的文本 。 //因此判断是否发送成功应该据此判断 if (分单发送成功(content)) { foreach (var item in EdiList) { errorMFNO = item.MFNO; //20220727 改为发送后直接扣费 //var hblnoSuccess = getSuccessStr(item.HBLNO); //if (contentStr.Contains(hblnoSuccess)) ChangeInfo.SetEdiStatus(item.MFNO, type, showname, dcarrier, EdiSendStatus.Success, "分单发送成功"); //else { // //ChangeInfo.SetEdiStatus(item.MFNO, type, showname, dcarrier, EdiSendStatus.Unusual, ); // ChangeInfo.SetEdiStatus(item.MFNO, type, showname, dcarrier, EdiSendStatus.Fail, getFailStr(item.HBLNO, contentStr)); // //DoSend.分单设为发送异常(item.MFNO, "分单发送异常,请联系管理人员"); //} } result.Success = true; result.Message = "舱单发送成功!"; result.Data = contentStr; } else { if (!string.IsNullOrWhiteSpace(contentStr)) { foreach (var item in EdiList) { ChangeInfo.SetEdiStatus(item.MFNO, type, showname, dcarrier, EdiSendStatus.Fail, getFailStr(item.HBLNO, contentStr)); } } result.Success = false; result.Message = contentStr; } } catch (Exception e) { EdiDataContext.SaveLog("舱单直发", "发送分单错误", "[" + EdiList[0].MBLNO + ","+ errorMFNO + "]" + e.Message+";"+e.InnerException.InnerException.Message, userid); } return result; } public static string UnicodeToString(string str) { string outStr = ""; if (!string.IsNullOrEmpty(str)) { string[] strlist = str.Replace("\\", "").Split('u'); try { for (int i = 0; i < strlist.Length; i++) { try { //将unicode字符转为10进制整数,然后转为char中文字符 var _s = strlist[i]; outStr += (char)int.Parse(_s.Substring(0, 4), System.Globalization.NumberStyles.HexNumber); if (_s.Length > 4) { var tail = _s.Substring(4, _s.Length - 4); outStr += tail; } } catch (Exception e) { var _s = strlist[i]; outStr += strlist[i]; } } } catch (FormatException ex) { outStr = ex.Message; } } return outStr; } private static bool 分单发送成功( string content) { //foreach(var item in EdiList) { // var successstr = getSuccessStr(item.HBLNO); // if (!content.Contains(successstr)) return false; //} var portresult = new PortResult(content); if ( portresult.status == "1")//portresult.stats=="1"|| //if (content.Contains("申报成功")|| content.Contains("上传成功")) { return true; } else { return false; } } /// /// 获得分单号的 /// /// /// public static string getSuccessStr(string hblno) { return $"[分单:{hblno}]申报成功"; } private static string getFailStr(string hblno,string contentStr) { var 分单失败文本头= $"[分单:{hblno}]申报失败:"; var result = ""; if (contentStr.Contains(分单失败文本头)) { var 文本剩余部分 = contentStr.Substring(contentStr.IndexOf(分单失败文本头)+ 分单失败文本头.Length, contentStr.Length- contentStr.IndexOf(分单失败文本头)- 分单失败文本头.Length); result = 文本剩余部分.Substring(0, 文本剩余部分.IndexOf("
")); } return result; } private static string HttpPost_Port(SendInfo sendinfo) { if (sendinfo.useOwnPwd == true) { return HttpPostData(sendinfo.whlURL, sendinfo.timeOut, sendinfo.fileKeyName, sendinfo.filepath, sendinfo.filename, sendinfo.nv); } else { return HttpPostData_headfield(sendinfo); } } private static string HttpPost_DZKA(SendInfo sendinfo) { var nvStr = ""; foreach (string s in sendinfo.nv) foreach (string v in sendinfo.nv.GetValues(s)) nvStr+= s+"/" +v+"//"; if (nvStr == "") { EdiDataContext.SaveLog("舱单直发", "发送分单失败", $" nv=null ; filename={sendinfo.filename}", ""); } EdiDataContext.SaveLog("舱单直发", "发送分单信息", $" nv={nvStr } filename={sendinfo.filename}", ""); return HttpPostData(sendinfo.whlURL, sendinfo.timeOut, sendinfo.fileKeyName, sendinfo.filepath, sendinfo.filename, sendinfo.nv); //return ""; } private static string HttpPostData(string url, int timeOut, string fileKeyName, string filePath, string filename, NameValueCollection stringDict) { try { string responseContent; var request = (HttpWebRequest)WebRequest.Create(url); MsMultiPartFormData form = new MsMultiPartFormData(); foreach (string key in stringDict.Keys) { form.AddFormField(key, stringDict[key]); } FileStream file = new FileStream(filePath, FileMode.Open); byte[] bb = new byte[file.Length]; file.Read(bb, 0, (int)file.Length); file.Close(); form.AddStreamFile(fileKeyName, filename, bb); form.PrepareFormData(); request.ContentType = "multipart/form-data; boundary=" + form.Boundary; request.Method = "POST"; Stream stream = request.GetRequestStream(); foreach (var b in form.GetFormData()) { stream.WriteByte(b); } stream.Close(); WebResponse response = request.GetResponse(); using (var httpStreamReader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) { responseContent = httpStreamReader.ReadToEnd(); } return responseContent; } catch(Exception e) { return e.Message; } } private static string HttpPostData_headfield(SendInfo sendinfo)// string url, int timeOut, string fileKeyName, //string filePath, string filename, NameValueCollection stringDict) { string url = sendinfo.whlURL; int timeOut = sendinfo.timeOut; string fileKeyName = sendinfo.fileKeyName; string filePath = sendinfo.filepath; string filename = sendinfo.filename; NameValueCollection stringDict = sendinfo.nv; var yardid = sendinfo.yardid; string responseContent; var request = (HttpWebRequest)WebRequest.Create(url); MsMultiPartFormData form = new MsMultiPartFormData(); foreach (string key in stringDict.Keys) { form.AddFormField(key, stringDict[key]); } FileStream file = new FileStream(filePath, FileMode.Open); byte[] bb = new byte[file.Length]; file.Read(bb, 0, (int)file.Length); file.Close(); form.AddStreamFile(fileKeyName, filename, bb); form.PrepareFormData(); request.ContentType = "multipart/form-data; boundary=" + form.Boundary; request.Method = "POST"; request.Headers.Add("yardid", sendinfo.yardid); request.Headers.Add("custname", sendinfo.defaultusername); request.Headers.Add("custpsw", sendinfo.defaultpwd); Stream stream = request.GetRequestStream(); foreach (var b in form.GetFormData()) { stream.WriteByte(b); } stream.Close(); WebResponse response = request.GetResponse(); using (var httpStreamReader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"))) { responseContent = httpStreamReader.ReadToEnd(); } return responseContent; } private static void SetHeaderValue(WebHeaderCollection header, string name, string value) { var property = typeof(WebHeaderCollection).GetProperty("InnerCollection", BindingFlags.Instance | BindingFlags.NonPublic); if (property != null) { var collection = property.GetValue(header, null) as NameValueCollection; collection[name] = value; } } public static void 记录待读状态主单(List billList, string showname, string userid, int DelayMinutes=15) { var edc = new EdiDataContext(); foreach (var bill in billList) { var 现存待读主单List = edc.WLXX_MBLNO_DELAY.Where(x=>x.MFNO==bill.MFNO).ToList(); if (现存待读主单List == null || 现存待读主单List.Count == 0) { //(string MFNO, string DCARRIER, string TYPE, string MARKS, string USERID, string USERCODE, string SHOWNAME, string COMPANYID, string COMPANYNAME,string MBLNO,int DelayMinutes) if (bill.FORWARDER == "中远") { DelayMinutes = 25; } var zhudanneedread = new WLXX_MBLNO_DELAY_md(bill, showname, userid, DelayMinutes); edc.WLXX_MBLNO_DELAY.Add(zhudanneedread); } else { 现存待读主单List[0].NEEDREAD = true; } } edc.SaveChanges(); } public static void 记录待发分单(List billList, string dcarrier, string type, string remarks, string userid, string usercode, string showname, string companyid, string companyname,string FendanFilename,string SENDCODE) { var mblno = billList[0].MBLNO; var bsno = billList[0].BSNO; ChangeInfo.SetEdiStatus(billList, "新增", showname, dcarrier, EdiSendStatus.Sending, ""); var edc = new EdiDataContext(); var MFNOs = ""; var 现有待发分单 = edc.OP_SEAE_EDI_FENDANSEND.FirstOrDefault(x => x.BSNO == bsno ); //foreach (var bill in billList) //{ // if (现有待发分单 != null) // { // if (!现有待发分单.MFNO.Contains(bill.MFNO)) // { // if (MFNOs != "") MFNOs += ","; // MFNOs += bill.MFNO; // } // } // else { // if (MFNOs != "") MFNOs += ","; // MFNOs += bill.MFNO; // } //} if (现有待发分单 == null) { var newfendan = OP_SEAE_EDI_FENDANSEND_md.getNew(dcarrier, type, remarks, userid, usercode, showname, companyid, companyname, mblno,bsno, FendanFilename, SENDCODE); newfendan.CANSEND = false; edc.OP_SEAE_EDI_FENDANSEND.Add(newfendan); edc.SaveChanges(); } else { //现有待发分单.CANSEND = false; //edc.SaveChanges(); } } public static void 待发分单列表设为可发送(WLXX_MBLNO_DELAY_md headdata) { EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x=>x.BSNO== headdata.MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { var 待发分单 = fendanneedsendlist[0]; var 实际分单列表 = edc.Edis.Where(x => x.BSNO== 待发分单.BSNO ).ToList(); //根据已记录的文件名重新生成一次待发分单的报文 var FendanFilename = DoSend.MakeFenDanFile_WithFileName(实际分单列表, 9, 待发分单.SENDCODE, 待发分单.FILENAME, 待发分单.USERID); 待发分单.FILENAME = FendanFilename; 待发分单.CANSEND = true; edc.SaveChanges(); } } //public static void 待发分单设为发送失败(string MBLNO) //{ // EdiDataContext edc = new EdiDataContext(); // var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.MBLNO == MBLNO).ToList(); // if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) // { // var fendanneedsend = fendanneedsendlist[0]; // fendanneedsend.CANSEND = false; // var EdiList = edc.Edis.Where(x => x.MBLNO== MBLNO && (x.HBLNO!="" && x.HBLNO != null)).ToList(); // ChangeInfo.SetEdiStatus(EdiList, "新增", fendanneedsend.SHOWNAME, fendanneedsend.DCARRIER, EdiSendStatus.Fail); // edc.SaveChanges(); // } //} public static void 直发主单设为发送异常(WLXX_MBLNO_DELAY_md readhead, string msg="") { EdiDataContext edc = new EdiDataContext(); var headdata = edc.Edis.First(x => x.MFNO == readhead.MFNO); if (headdata != null) { //20210304 改为INPUTBYID具备直发权限且这个船代FORWARDER能直发的时候 才标记发送异常 bool HasZhifaPower = CheckData.CheckHasZhiFaPower(headdata.INPUTBYID); bool canZhifa = CheckData.CarrierCanSend(headdata.FORWARDER); bool is危化品 = (headdata.CARGOID == "D"); //20221206 危化品分单也正常直发 //其中:非中远 或者中远非危化品 可以直发 bool 危化品直发 = (headdata.FORWARDER != "中远" || (headdata.FORWARDER == "中远" && !is危化品)); //if (HasZhifaPower && canZhifa && !is危化品) if (HasZhifaPower && canZhifa && 危化品直发)//&& !is危化品 { if (!舱单回执已接收申报(headdata.MFNO)) { ChangeInfo.SetEdiStatus(headdata.MFNO, "新增", headdata.INPUTBY, headdata.FORWARDER, EdiSendStatus.Unusual, msg); } } } } public static bool 舱单回执已接收申报(string MFNO) { EdiDataContext edc = new EdiDataContext(); var SuccessStatus = edc.op_seae_edi_status.FirstOrDefault(x => x.mfno == MFNO && x.statustext == "接收申报"); if (SuccessStatus != null ) { return true; } else return false; } //public static void 分单设为发送异常(string MFNO, string msg = "") //{ // EdiDataContext edc = new EdiDataContext(); // var Fendan = edc.Edis.First(x => x.MFNO == MFNO); // if (Fendan != null && !舱单目前已为已直发状态(MFNO)) // { // ChangeInfo.SetEdiStatus(Fendan.MFNO, "新增", Fendan.INPUTBY, Fendan.FORWARDER, EdiSendStatus.Unusual, msg); // } //} public static void 待发分单删除(string MFNO) { EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.BSNO == MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { var fendanneedsend = fendanneedsendlist[0]; var EdiList = edc.Edis.Where(x => x.BSNO == MFNO).ToList(); //ChangeInfo.SetEdiStatus(EdiList, "新增", fendanneedsend.SHOWNAME, fendanneedsend.DCARRIER, EdiSendStatus.Fail); fendanneedsend.CANSEND = false; edc.SaveChanges(); } } public static void 待发分单重置(string MFNO) { EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.BSNO == MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { var fendanneedsend = fendanneedsendlist[0]; var EdiList = edc.Edis.Where(x => x.BSNO == MFNO).ToList(); //ChangeInfo.SetEdiStatus(EdiList, "新增", fendanneedsend.SHOWNAME, fendanneedsend.DCARRIER, EdiSendStatus.Fail); fendanneedsend.CANSEND = true; edc.SaveChanges(); } } public static void 待发分单设为超时(string MFNO) { EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.BSNO == MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { var fendanneedsend = fendanneedsendlist[0]; var 分单列表List = edc.Edis.Where(x => x.BSNO == MFNO && (x.EDISTATUS=="发送中")).ToList(); ChangeInfo.SetEdiStatus(分单列表List, "新增", fendanneedsend.SHOWNAME, fendanneedsend.DCARRIER, EdiSendStatus.Overtime); fendanneedsend.CANSEND = false; edc.SaveChanges(); } } public static bool 待发分单存在(WLXX_MBLNO_DELAY_md headdata) { if (headdata.MBLNO == null) return false; EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.BSNO == headdata.MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { return true ; } else return false; } public static bool 存在可发分单(WLXX_MBLNO_DELAY_md headdata) { try { EdiDataContext edc = new EdiDataContext(); var fendanneedsendlist = edc.OP_SEAE_EDI_FENDANSEND.Where(x => x.BSNO == headdata.MFNO).ToList(); if (fendanneedsendlist != null && fendanneedsendlist.Count > 0) { var _bsno = fendanneedsendlist[0].BSNO; //查找具备这些bsno的分单 如无 则代表当初是主分单发的 但现在没有分单了 var fendanList = edc.Edis.Where(x => x.BSNO == _bsno).ToList(); if (fendanList.Count > 0) { return true; } else { return false; } } else return false; } catch (Exception e) { EdiDataContext.SaveLog("舱单直发", "存在可发分单", $" nv={e.Message}", ""); return false; } } public static bool 主单信息已存在(WLXX_MBLNO_DELAY_md readhead) { EdiDataContext edc = new EdiDataContext(); var 主单信息 = edc.op_seae_edi_mainstatus.Where(x => x.mfno == readhead.MFNO).ToList(); if (主单信息 != null && 主单信息.Count > 0) { return true; } else return false; } public static bool 分单已直发(WLXX_MBLNO_DELAY_md readhead) { EdiDataContext edc = new EdiDataContext(); var 分单信息List = edc.Edis.Where(x => x.BSNO == readhead.MFNO).ToList(); foreach (var item in 分单信息List) { if (item.EDISTATUS == "已直发") { return true; } } return false; } public static void 待读主单Edi状态_成功(string MFNO) { 待读主单Edi状态(MFNO, EdiSendStatus.Success); } public static void 待读主单Edi状态_超时(string MFNO) { 待读主单Edi状态(MFNO, EdiSendStatus.Overtime); //增加一条tips } private static void 待读主单Edi状态(string MFNO, EdiSendStatus success) { EdiDataContext edc = new EdiDataContext(); var headList = edc.Edis.Where(x => x.MFNO == MFNO).ToList(); if (headList != null && headList.Count > 0) { var head = headList[0]; var 待读主单信息list = edc.WLXX_MBLNO_DELAY.Where(x => x.MFNO == MFNO).ToList(); if (待读主单信息list != null && 待读主单信息list.Count > 0) { var 待读主单信息 = 待读主单信息list[0]; ChangeInfo.SetEdiStatus(headList, "新增", 待读主单信息.SHOWNAME, head.DCARRIER, success); } } } public class MsMultiPartFormData { private List formData; public String Boundary = "---------------------------7db1851cd1158"; private String fieldName = "Content-Disposition: form-data; name=\"{0}\""; private String fileContentType = "Content-Type: {0}"; private String fileField = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\""; private Encoding encode = Encoding.GetEncoding("UTF-8"); public MsMultiPartFormData() { formData = new List(); } public void AddFormField(String FieldName, String FieldValue) { String newFieldName = fieldName; newFieldName = string.Format(newFieldName, FieldName); formData.AddRange(encode.GetBytes("--" + Boundary + "\r\n")); formData.AddRange(encode.GetBytes(newFieldName + "\r\n\r\n")); formData.AddRange(encode.GetBytes(FieldValue + "\r\n")); } public void AddFile(String FieldName, String FileName, byte[] FileContent, String ContentType) { String newFileField = fileField; String newFileContentType = fileContentType; newFileField = string.Format(newFileField, FieldName, FileName); newFileContentType = string.Format(newFileContentType, ContentType); formData.AddRange(encode.GetBytes("--" + Boundary + "\r\n")); formData.AddRange(encode.GetBytes(newFileField + "\r\n")); formData.AddRange(encode.GetBytes(newFileContentType + "\r\n\r\n")); formData.AddRange(FileContent); formData.AddRange(encode.GetBytes("\r\n")); } public void AddStreamFile(String FieldName, String FileName, byte[] FileContent) { AddFile(FieldName, FileName, FileContent, "application/octet-stream"); } public void PrepareFormData() { formData.AddRange(encode.GetBytes("--" + Boundary + "--")); } public List GetFormData() { return formData; } } } public class WLXX { public static WLXX_MBLNO_DELAY_md 获取待读主单(EdiDataContext readdb ,int delaytime=3) { //20220810增加逻辑 只取有分单的业务 var result = new WLXX_MBLNO_DELAY_md(); var resultlist = new List(); result.NEEDREAD = false; var _resultlist = readdb.WLXX_MBLNO_DELAY .Where(x => x.READTIME <= DateTime.Now && x.NEEDREAD==true ) //.Where(x => x.MBLNO == "TAYH2G083600") .OrderBy(x=>x.READTIME).ToList(); var needsave = false; if (_resultlist != null && _resultlist.Count > 0) { foreach (var item in _resultlist) { if (DoSend.待发分单存在(item)) { resultlist.Add(item); } else { item.NEEDREAD = false; needsave = true; } } } if (resultlist != null && resultlist.Count > 0) { result = resultlist[0]; } else { var _newtimeline = DateTime.Now.AddMinutes(delaytime); _resultlist = readdb.WLXX_MBLNO_DELAY.Where(x => x.READTIME <= _newtimeline && x.NEEDREAD == true).OrderBy(x => x.READTIME).ToList(); if (_resultlist != null && _resultlist.Count > 0) { foreach (var item in _resultlist) { if (DoSend.待发分单存在(item)) { resultlist.Add(item); } } } //20220809 在延迟时间后有比较多的业务(大于10)才提前做执行 if (resultlist != null && resultlist.Count > 10 ) //如果 result = resultlist[0]; } //将无直发权限客户的主分单发送所产生的待读主单去掉; if (needsave) readdb.SaveChanges(); return result; } //const string 实时读取回执接口= "http://47.104.90.170:5000/query"; const string 实时读取回执接口 = "http://118.190.106.151:5678/v1/real/query"; //const string 实时读取主单信息接口 = "http://47.104.90.170:5000/query"; /// /// 通过接口读取回执状态 /// 如果状态值中包括(接收申报/放行)则返回true 否则返回false /// /// /// /// 临时读取/正常读取;如临时读取则在返回值中包括“接收申报”时 /// public static Result_md ReadWLXX(string MBLNO,string MFNO,string needtype= "正常读取") { var result = new Result_md(false,""); if (string.IsNullOrWhiteSpace(MBLNO)) { result.Message = "无提单号"; result.Success = false; return result; } EdiDataContext edc = new EdiDataContext(); EdiDataContext edc_do = new EdiDataContext(); JObject reqObj = new JObject(); //reqObj.Add("yardid", "WLXX"); //reqObj.Add("mblno", new JValue(MBLNO)); //reqObj.Add("isweb", "2"); //reqObj.Add("wltype", "WLXX"); reqObj.Add("user_key", "QDDJY"); reqObj.Add("user_secret", "YGH2020"); //下方此处无关权限 只用于区分调用来源 reqObj.Add("customer_id", "DY_ReadZDXX"); reqObj.Add("customer_name", "大简云自动延迟发送分单"); reqObj.Add("web_code", "HLW_CD"); reqObj.Add("bno", new JValue(MBLNO)); reqObj.Add("vessel_name", ""); reqObj.Add("voyage_no", ""); reqObj.Add("wharf_name", ""); reqObj.Add("req_type", "0"); reqObj.Add("web_user", ""); reqObj.Add("web_psw", ""); reqObj.Add("wltype", "WLXX"); //HLW_CD //var reqUrl = "http://47.104.90.170:5000/query"; //var reqUrl = "http://118.190.106.151:5678/v1/real/query"; var t = Newtonsoft.Json.Formatting.None; try { var rtn = WebRequestHelper.DoPost(实时读取回执接口, reqObj.ToString(Newtonsoft.Json.Formatting.None),20000); result.Data = rtn; EdiDataContext.SaveLog("舱单直发", "读取主单回执",$"{MBLNO}//"+ rtn, ""); if (rtn.Contains("单号信息不存在")) { result.Message = ""; } else if (rtn.Contains("验证码") || rtn.Contains("无可用账号") || rtn.Contains("当前单号无信息")) { //DelayMblno(connStr, id); } else { var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); //if(PortResult.status=="0") DoSend.主单设为发送异常(MBLNO); //var falseresult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); var portstatus = PortResult.data[0]; portstatus.SaveStatus(MFNO,MBLNO); if (needtype == "临时读取") { //如果有接受申报或装载放行 则删除WLXX_MBLNO_DELAY当中的该提单号数据 if (portstatus.临时读取完成()) { result.Success = true; } } if (needtype == "正常读取") { //如果有接受申报或装载放行 则删除WLXX_MBLNO_DELAY当中的该提单号数据 if (portstatus.已放行()) { result.Success = true; } } } } catch (Exception e) { //log.Debug($"saveerror1: {e.Message}"); //DoSend.待读主单Edi状态_超时(MFNO); } return result; } /// /// 读取主单信息方法 /// /// /// /// 请求参数 /// public static Result_md ReadZDXX(string MBLNO,string USERID, string MFNO) { var result = new Result_md(false, ""); EdiDataContext edc = new EdiDataContext(); var mainhead = edc.Edis.FirstOrDefault(x => x.MBLNO == MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "")); var sendinfo = SendInfo.ZDXXHelper(mainhead.FORWARDER,USERID, MBLNO); JObject reqObj = new JObject(); sendinfo.useOwnPwd = false;//测试用数据 if (!sendinfo.useOwnPwd) {//使用东胜账号密码 reqObj.Add("yardid", "WLCD"); reqObj.Add("mblno", MBLNO); reqObj.Add("isweb", "2"); reqObj.Add("webusername", ""); reqObj.Add("webuserpass", ""); reqObj.Add("wltype", "WLXXSX"); } else { //客户使用自己的账号密码 reqObj.Add("yardid", "WLCDKY"); reqObj.Add("mblno", MBLNO); reqObj.Add("isweb", "2"); reqObj.Add("webusername", sendinfo.webusername); reqObj.Add("webuserpass", sendinfo.webpassword); //reqObj.Add("webusername", ""); //reqObj.Add("webuserpass", ""); reqObj.Add("wltype", "WLXXSX"); } EdiDataContext edc_do = new EdiDataContext(); try { var rtn = WebRequestHelper.DoPost(sendinfo.whlURL, reqObj.ToString(Newtonsoft.Json.Formatting.None), 20000); result.Data = rtn; EdiDataContext.SaveLog("舱单直发", "读取主单信息", $"{MBLNO}//" + rtn, ""); if (rtn.Contains("单号信息不存在")) { result.Message = ""; } else if (rtn.Contains("验证码") || rtn.Contains("无可用账号") || rtn.Contains("当前单号无信息")) { //DelayMblno(connStr, id); } else { if (rtn.Contains("\"status\": \"1\"")) { var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); //if (PortResult.status == "0") DoSend.主单设为发送异常(MBLNO, PortResult.message); var statushead = PortResult.message.gethead(MFNO, MBLNO); var statusbody = PortResult.message.getbody(MFNO, MBLNO); 删除主单状态(MFNO); edc_do.op_seae_edi_mainstatus.Add(statushead); foreach(var item in statusbody) edc_do.op_seae_edi_mainstatus_xhinfo.Add(item); edc_do.SaveChanges(); result.Success = true; return result; } else { var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); //DoSend.待读主单Edi状态_超时(MFNO); } } } catch (Exception e) { //log.Debug($"saveerror1: {e.Message}"); //DoSend.待读主单Edi状态_超时(MFNO); } return result; } public static Result_md Read_StatusZDXX(string MBLNO, string USERID, string MFNO) { var result = new Result_md(false, ""); EdiDataContext edc = new EdiDataContext(); var mainhead = edc.Edis.FirstOrDefault(x => x.MBLNO == MBLNO && (x.HBLNO == null || x.HBLNO.Trim() == "")); if (MFNO == "") MFNO = mainhead.MFNO; var sendinfo = SendInfo.StatusZDXXHelper(mainhead.FORWARDER, USERID, MBLNO); JObject reqObj = new JObject(); //sendinfo.useOwnPwd = false;//测试用数据 var lognamepwd = ""; if (!sendinfo.useOwnPwd) {//使用东胜账号密码 reqObj.Add("yardid", "WLXXZH"); reqObj.Add("mblno", MBLNO.Trim()); reqObj.Add("isweb", "2"); reqObj.Add("webusername", ""); reqObj.Add("webuserpass", ""); reqObj.Add("wltype", "WLXXSX"); lognamepwd = "空用户名和密码"; } else { //客户使用自己的账号密码 reqObj.Add("yardid", "WLXXZH"); reqObj.Add("mblno", MBLNO.Trim()); reqObj.Add("isweb", "2"); reqObj.Add("webusername", sendinfo.webusername); reqObj.Add("webuserpass", sendinfo.webpassword); //reqObj.Add("webusername", ""); //reqObj.Add("webuserpass", ""); reqObj.Add("wltype", "WLXXSX"); lognamepwd = sendinfo.webusername + "/" + sendinfo.webpassword; } EdiDataContext edc_do = new EdiDataContext(); try { EdiDataContext.SaveLog("舱单直发", "读主单信息", $"{MBLNO}/{lognamepwd}/" , ""); var rtn = WebRequestHelper.DoPost(sendinfo.whlURL, reqObj.ToString(Newtonsoft.Json.Formatting.None), 20000); result.Data = rtn; EdiDataContext.SaveLog("舱单直发", "主单信息与回执", $"{MBLNO}/{lognamepwd}/" + rtn, ""); if (rtn.Contains("单号信息不存在")) { result.Message = ""; } else if (rtn.Contains("验证码") || rtn.Contains("无可用账号") || rtn.Contains("当前单号无信息")) { //DelayMblno(connStr, id); } else { if (rtn.Contains("\"status\": \"1\"")) { var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); var portstatus = PortResult.message; portstatus.SaveStatus(MFNO, MBLNO); var statushead = PortResult.message.gethead(MFNO, MBLNO); var statusbody = PortResult.message.getbody(MFNO, MBLNO); 删除主单状态(MFNO); edc_do.op_seae_edi_mainstatus.Add(statushead); foreach (var item in statusbody) edc_do.op_seae_edi_mainstatus_xhinfo.Add(item); edc_do.SaveChanges(); result.Success = true; return result; } else { //var PortResult = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); //DoSend.待读主单Edi状态_超时(MFNO); } } } catch (Exception e) { //log.Debug($"saveerror1: {e.Message}"); //DoSend.待读主单Edi状态_超时(MFNO); } return result; } public static void 删除主单状态(string MFNO) { EdiDataContext edc = new EdiDataContext(); var oldhead = edc.op_seae_edi_mainstatus.FirstOrDefault(x => x.mfno == MFNO); if (oldhead != null) { edc.op_seae_edi_mainstatus.Remove(oldhead); var oldbody = edc.op_seae_edi_mainstatus_xhinfo.Where(x => x.mfno == MFNO).ToList(); if (oldbody != null && oldbody.Count() > 0) { foreach (var item in oldbody) edc.op_seae_edi_mainstatus_xhinfo.Remove(item); } } edc.SaveChanges(); } public static void 删除待读主单(string MFNO) { EdiDataContext edc = new EdiDataContext(); var Delayitem = edc.WLXX_MBLNO_DELAY.Where(x => x.MFNO == MFNO && x.NEEDREAD==true).ToList(); if (Delayitem.Count > 0) { //edc.WLXX_MBLNO_DELAY.Remove(Delayitem[0]); Delayitem[0].NEEDREAD = false; } edc.SaveChanges(); } } }