You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4396 lines
172 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 判断是否符合保存的要求
/// </summary>
/// <param name="bsnos"></param>
/// <param name="isETA"></param>
/// <param name="type"></param>
/// <returns></returns>
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 + "<br />舱单已直发,不允许再次新增";
}
if (type == "修改" && bill.EDISTATUS == "已录入")
{
error = error + "<br />未查到发送记录,类型请选择新增。";
}
if (type == "删除" && bill.EDISTATUS == "已录入")
{
error = error + "<br />未查到发送记录,类型请选择新增。";
}
if (bill.MBLNO == null || bill.MBLNO == "")
{
error = error + "<br />主提单号不能为空";
}
if (bill.FORWARDER == null || bill.FORWARDER == "")
{
error = error + "<br />提单号:" + alertNo + " 船代不能为空";
}
else
{
//if (MsOpSeaeDAL.MsOpSeaeDAL.GetCustEdi(bill.SHIPAGENCY) == "")
//{
// error = error + "<br />提单号:" + alertNo + " 船代EDI代码不能为空";
//}
}
//if (bill.CARRIER == null || bill.CARRIER == "")
//{
// error = error + "<br />提单号:" + alertNo + " 船公司不能为空";
//}
//else
//{
// if (MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetCustEdi(bill.CARRIER) == "")
// {
// error = error + "<br />提单号:" + alertNo + " 船公司EDI代码不能为空";
// }
//}
if ((string.IsNullOrWhiteSpace(bill.BLFRT)))
{ error = error + "<br />提单号:" + alertNo + " 付费方式不能为空"; }
if (string.IsNullOrWhiteSpace(bill.VESSEL))
{ error = error + "<br />提单号:" + alertNo + " 船名不能为空"; }
if (string.IsNullOrWhiteSpace(bill.VOYNO ))
{ error = error + "<br />提单号:" + alertNo + " 航次不能为空"; }
#endregion
#region 装货港、卸货港、开船日期、预付地点、到付地点、签单地点
if (string.IsNullOrWhiteSpace(bill.PORTLOADID))
{ error = error + "<br />提单号:" + alertNo + " 装货港代码不能为空"; }
if (string.IsNullOrWhiteSpace(bill.PORTLOAD))
{ error = error + "<br />提单号:" + alertNo + " 装货港不能为空"; }
if (bill.ETD == null)
{
error = error + "<br />提单号:" + alertNo + " 开船日期不能为空";
}
if (isETA)
{
if (bill.ETA == null)
{
error = error + "<br />提单号:" + alertNo + " 预抵日期不能为空";
}
}
if (string.IsNullOrWhiteSpace(bill.PORTDISCHARGEID))
{ error = error + "<br />提单号:" + alertNo + " 卸货港代码不能为空"; }
if (string.IsNullOrWhiteSpace(bill.PORTDISCHARGE))
{ error = error + "<br />提单号:" + alertNo + " 卸货港不能为空"; }
//if (bill.BLFRT.IndexOf("PREPAID") >= 0)
//{
// if (bill.PREPARDAT == "" || MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPortEDICode(bill.PREPARDAT) == "")
// { error = error + "<br />提单号:" + alertNo + " 预付地点或预付地点EDI代码不能为空"; }
//}
//if (bill.SHIPPERCODE.Trim() == "")
//{
// error = error + "<br />提单号:" + alertNo + " 发货人企业代码不能为空";
//}
if (string.IsNullOrWhiteSpace(bill.SHIPPERTEL) && string.IsNullOrWhiteSpace(bill.SHIPPEREMAIL))
{
error = error + "<br />提单号:" + alertNo + " 发货人电话和邮箱不能都为空";
}
//var consigneestr = bill.CONSIGNEE.ToUpper().Replace(" ", "");
if (string.IsNullOrWhiteSpace(bill.CONSIGNEE))
{
error = error + "<br />提单号:" + alertNo + "收货人不能为空";
}
if (string.IsNullOrWhiteSpace(bill.CONSIGNEENAME))
{
error = error + "<br />提单号:" + alertNo + "收货人不能为空";
}
else
{
//if (!bill.CONSIGNEENAME.Contains("ORDER"))
//{
//}
}
//if (bill.BLFRT.IndexOf("COLLECT") >= 0)
//{
// if (bill.PAYABLEAT == "" || MsOpSeaeDAL.MsOpSeaeDAL.GetPortEDICode(bill.PAYABLEAT) == "")
// { error = error + "<br />提单号:" + alertNo + " 到付地点或到付地点EDI代码不能为空"; }
//}
//if (bill.ISSUEPLACE == "" || MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPortEDICode(bill.ISSUEPLACE) == "")
//{ error = error + "<br />提单号:" + alertNo + " 签单地点或到签单地点EDI代码不能为空"; }
#endregion
#region 件数包装、件重尺
//if (MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPackageEDICode(bill.KINDPKGS, "") == "")
//{
// error = error + "<br />提单号:" + alertNo + " 包装EDI代码不能为空";
//}
//if (bill.PKGS == "0")
//{ error = error + "<br />提单号:" + alertNo + " 货物件数不能为空"; }
//if (bill.KGS == "0")
//{ error = error + "<br />提单号:" + alertNo + " 货物重量不能为空"; }
//if (bill.CBM == "0")
//{ error = error + "<br />提单号:" + alertNo + " 货物尺码不能为空"; }
#endregion
#region 货物描述
if (string.IsNullOrWhiteSpace(bill.DESCRIPTION))
{
error = error + "<br />提单号:" + alertNo + " 货物描述不能为空";
}
else
{
if (StringIsChinese(bill.DESCRIPTION))
{
error = error + "<br />提单号:" + alertNo + " 货物描述含有中文或双字节字符";
}
//else
//{
// error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.DESCRIPTION, 70, alertNo, "货物描述", 0, "", true);
//}
}
#endregion
#region 唛头
if (string.IsNullOrWhiteSpace(bill.MARKS))
{
error = error + "<br />提单号:" + alertNo + " 唛头不能为空";
}
else
{
if (StringIsChinese(bill.MARKS))
{
error = error + "<br />提单号:" + alertNo + " 唛头含有中文或双字节字符";
}
//else
//{
// error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.MARKS, 35, alertNo, "唛头", 0, "", false);
//}
}
#endregion
#region 货物标识信息
if (string.IsNullOrWhiteSpace(bill.CARGOID ))
{ error = error + "<br />提单号:" + alertNo + " 货物标示不能为空"; }
if (bill.CARGOID == "D")
{
if (string.IsNullOrWhiteSpace(bill.DCLASS))
{ error = error + "<br />提单号:" + alertNo + " 危险品分类不能为空"; }
if (string.IsNullOrWhiteSpace(bill.DUNNO))
{ error = error + "<br />提单号:" + alertNo + " 危险品编号不能为空"; }
}
if (bill.CARGOID == "R")
{
if (string.IsNullOrWhiteSpace(bill.TEMPSET ))
{ error = error + "<br />提单号:" + alertNo + " 设置温度不能为空"; }
}
#endregion
#region 发货人
if (string.IsNullOrWhiteSpace(bill.SHIPPER))
{
error = error + "<br />提单号:" + alertNo + " 发货人不能为空";
}
else
{
if (StringIsChinese(bill.SHIPPER))
{
error = error + "<br />提单号:" + alertNo + " 发货人含有中文或双字节字符";
}
else
{
//error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.SHIPPER, 35, alertNo, "发货人", 5, "*", false);
}
}
#endregion
#region 收货人
if (string.IsNullOrWhiteSpace(bill.CONSIGNEE))
{
error = error + "<br />提单号:" + alertNo + " 收货人不能为空";
}
else
{
if (StringIsChinese(bill.CONSIGNEE))
{
error = error + "<br />提单号:" + alertNo + " 收货人含有中文或双字节字符";
}
else
{
//error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.CONSIGNEE, 35, alertNo, "收货人", 5, "**", false);
}
}
#endregion
#region 通知人
if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTY))
{
error = error + "<br />提单号:" + alertNo + " 通知人不能为空";
}
else
{
if (StringIsChinese(bill.NOTIFYPARTY))
{
error = error + "<br />提单号:" + alertNo + " 通知人含有中文或双字节字符";
}
else
{
//error += MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatlengthError("txt", bill.NOTIFYPARTY, 35, alertNo, "通知人", 5, "***", false);
}
}
#endregion
#region 代理
/*
if (bill.AGENT == "")
{
error = error + "<br />提单号:" + alertNo + " 代理不能为空";
}
else
{
if (MsOpSeaeDAL.MsOpSeaeDAL.StringIsChinese(bill.AGENT))
{
error = error + "<br />提单号:" + alertNo + " 代理含有中文或双字节字符";
}
else
{
error += MsOpSeaeDAL.MsOpSeaeDAL.formatlengthError("txt", bill.AGENT, 35, alertNo, "代理", 5, "****");
}
}
*/
#endregion
#region 运输条款、运费协议号
if (string.IsNullOrWhiteSpace(bill.SERVICE))
{ error = error + "<br />提单号:" + alertNo + " 运输条款不能为空"; }
//string sSERVICE = MsOpSeaeDAL.MsOpSeaeDAL.GetSERVICEEDICode(bill.SERVICE.ToUpper(), "");
//if (sSERVICE == "")
//{ error = error + "<br />提单号:" + alertNo + " 运输条款EDI代码不能为空"; }
//if ((bill.CONTRACTNO == null || bill.CONTRACTNO == ""))
//{ error = error + "<br />提单号:" + alertNo + " 运费协议号不能为空"; }
#endregion
#region 集装箱判断检查
var ctnlist = db.EdiCtns.Where(x => x.MFNO == bill.MFNO).ToList();
if (ctnlist.Count == 0) { error = error + "<br />提单号:" + alertNo + " 集装箱信息不能为空"; };
foreach (var ctn in ctnlist)
{
//if (MsOpSeaeDAL.MsOpSeaeDAL.GetCtnEDICode(ctn.CTNALL, "") == "")
//{ error = error + "<br />提单号:" + alertNo + " 集装箱箱型EDI代码不能为空"; }
if (checkCtnNum && !EdiDataContext.VerifyContainerCode(ctn.CNTRNO))
{
{ error = error + "<br />提单号:" + alertNo + " 箱号:" + ctn.CNTRNO + " 不符合规范"; }
}
if (string.IsNullOrWhiteSpace(ctn.CNTRNO))
{ error = error + "<br />提单号:" + alertNo + " 箱号不能为空"; }
if (string.IsNullOrWhiteSpace(ctn.SEALNO ))
{ error = error + "<br />提单号:" + alertNo + " 封号不能为空"; }
if (string.IsNullOrWhiteSpace(ctn.KINDPKGS ))
{ error = error + "<br />提单号:" + alertNo + " 包装不能为空"; }
//if (ctn.CBM == 0)
//{ error = error + "<br />提单号:" + alertNo + " 尺码不能为零"; }
}
#endregion
}
return error;
}
/// <summary>
/// 判断主单的件重尺是否符合总分合计
/// </summary>
/// <param name="bsnos"></param>
/// <param name="isETA"></param>
/// <param name="type"></param>
/// <returns></returns>
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 "<br />分单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 += "<br /> 分票件数合计:" + + " 与总票件数:" + .PKGS + " 不一致。";
if (.KGS != ) error += " <br />分票毛重合计:" + .ToString("0.####") + " 与总票毛重:" + ((decimal).KGS).ToString("0.####") + " 不一致。";
//if (主单.CBM != 尺码合计) errormsg += "<br /> 分票件数合计:" + 件数合计 + " 与总票件数:" + 主单.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 += $"<br/>箱号为{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 += $"<br/>箱号为{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 += $"<br/>箱号为{obj.CNTRNO}的尺码,分单合计值与主单不一致";
//}
}
}
}
return error;
}
/// <summary>
/// 是否同一业务 是否同一主单
/// </summary>
/// <param name="bsnos"></param>
/// <returns></returns>
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 += "必须发送同一主单下的业务<br />";
}
}
else
{
if (item.BSNO != _bsno)
{
result += "必须发送同一主单下的业务<br />";
}
}
}
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 += "<br />所有业务均未填写船代信息";
}
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<OpSeaeEdiCtn>();
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 + "<br />舱单已直发,不允许再次新增";
}
if (sendtype == "修改" && bill.EDISTATUS == "已录入")
{
result = result + "<br />未查到发送记录,类型请选择新增。";
}
if (sendtype == "删除" && bill.EDISTATUS == "已录入")
{
result = result + "<br />未查到发送记录,类型请选择新增。";
}
}
//20211022 增加发送判断 收发通信息的人 地址 国家 电话 不可为空
foreach (var bill in List)
{
var alertNo = "【" + bill.MBLNO + bill.HBLNO == null ? "" : ";" + bill.HBLNO + "】";
#region 发货人
if (string.IsNullOrWhiteSpace(bill.SHIPPERNAME.Trim()))
{
result += "<br />提单号:" + alertNo + " 发货人企业代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.SHIPPERADDR1))
{
result += "<br />提单号:" + alertNo + " 发货人地址不能为空";
}
if (string.IsNullOrWhiteSpace(bill.SHIPPERCOUNTRY))
{
result += "<br />提单号:" + alertNo + " 发货人国家代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.SHIPPERTEL))
{
result += "<br />提单号:" + alertNo + " 发货人电话不能为空";
}
#endregion
#region 收货人
if (string.IsNullOrWhiteSpace(bill.CONSIGNEENAME.Trim()))
{
result += "<br />提单号:" + alertNo + " 收货人企业代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.CONSIGNEEADDR1))
{
result += "<br />提单号:" + alertNo + " 收货人地址不能为空";
}
if (string.IsNullOrWhiteSpace(bill.CONSIGNEECOUNTRY))
{
result += "<br />提单号:" + alertNo + " 收货人国家代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.CONSIGNEETEL))
{
result += "<br />提单号:" + alertNo + " 收货人电话不能为空";
}
#endregion
#region 通知人
if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYNAME.Trim()))
{
result += "<br />提单号:" + alertNo + " 通知人企业代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYADDR1))
{
result += "<br />提单号:" + alertNo + " 通知人地址不能为空";
}
if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYCOUNTRY))
{
result += "<br />提单号:" + alertNo + " 通知人国家代码不能为空";
}
if (string.IsNullOrWhiteSpace(bill.NOTIFYPARTYTEL))
{
result += "<br />提单号:" + 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<CTNNULL> 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<CTNNULL>();
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<OpSeaeEdiCtn> ) {
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;
}
/// <summary>
/// 看这个船代是否能直发
/// </summary>
/// <param name="dcarrier"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 该用户是否具备直发权限
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
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<string> GetBSNOsList(string bsnos)
{
var result = bsnos.Replace("'", "").Split(',').ToList();
return result;
}
/// <summary>
/// 20210816 改为判断他们是同一主单的分单 不再关心他们是否是全部分单
/// </summary>
/// <param name="bsnos"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 主单缺少所需信息则会返回ture 令前台弹出是否选项
/// 如不缺少则返回否,前台将会自动进行后续的发送逻辑
/// </summary>
/// <param name="bsnos"></param>
/// <param name="USERID"></param>
/// <returns></returns>
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<StatusZDXX_HeadModel>(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<ZDXXModel, StatusZDXXModel>(zddata);
ZDXXLocal.message.xh_info= AutoMapperHelper.MapToList<ZDXXDetailModel, ZDXXDetailModel_jiekou>(zdctninfo);
//ZDXXLocal.message.xh_info.
return ZDXXChanged(headdata, ZDXXLocal);
}
/// <summary>
/// 箱信息按箱号封号合计
/// </summary>
//private static List<OpSeaeEdiCtn> 箱信息按箱号封号合计(List<OpSeaeEdiCtn> 箱信息List){
// var 用于比较的箱信息List = new List<OpSeaeEdiCtn>();
// 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<OpSeaeEdiCtn, OpSeaeEdiCtn>(item);
// 用于比较的箱信息List.Add(newctn);
// }
// }
// return 用于比较的箱信息List;
//}
private static bool (List<OpSeaeEdiCtn> List, List<ZDXXDetailModel_jiekou> 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;
}
/// <summary>
/// 即主单状态为 接受申报 或 主单状态包括放行二字
/// </summary>
/// <returns></returns>
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; }
/// <summary>
/// 该客户使用自己的网站用户名和密码登陆船代网站
/// </summary>
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);
}
/// <summary>
/// 用于组织读取主单信息的参数组织
/// </summary>
/// data = {
///'yardid': 'WLCD', 必须
///'mblno': 'AAST013610', 必须
///'isweb': 2, 暂时默认为2
///'webusername': '', 客户用来登录的账号密码, 没有就不传
///'webuserpass': '',
///'wltype': 'WLXXSX' 必须
///}
/// <param name="dcarrier"></param>
/// <param name="userid"></param>
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<OpSeaeEdi> SetNewStatus(OpSeaeEdi billhead,string status,string newtips = "", bool isFenDan = false)
//{
// var result = new List<OpSeaeEdi>();
// 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 = "<!--";
if (newtips.Contains(markword))
{
//var _ar= Regex.Split(content, "<!--", RegexOptions.IgnoreCase);
//content = _ar[0];
newtips = newtips.Substring(0, newtips.IndexOf(markword));
}
tips.OPERATOR = showname;
tips.FORWARDER = dcarrier;
tips.TIPS = newtips;
tips.OPTYPE = status;
edc.OP_SEAE_EDI_TIPS.Add(tips);
edc.SaveChanges();
}
public static string GetEdiStatus(string MFNO) {
var result = "";
EdiDataContext edc = new EdiDataContext();
var tips = edc.OP_SEAE_EDI_TIPS.Where(x=>x.MFNO==MFNO && "新增修改删除".Contains(x.OPTYPE) ).OrderByDescending(o => o.TIPSTIME).ToList();
if (tips == null || tips.Count == 0) return "新增";
else return tips[0].OPTYPE;
return result;
}
public static void SetEdiStatus(string MFNO,string type,string showname,string dcarrier, EdiSendStatus ediSendStatus, string msg="") {
EdiDataContext edc = new EdiDataContext();
string text = "";
string headname = "";
string typename = EdiSendStatusName.Gettypename(type);
string newstatus = EdiSendStatusName.Getname(ediSendStatus);
headname = $"[{newstatus}]";
if (!(ediSendStatus==EdiSendStatus.Fail && ediSendStatus == EdiSendStatus.Overtime))
{
text = $"{headname}";//[提交时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][提交人:" + showname + "][船代:" + dcarrier + "]
}
if ((ediSendStatus == EdiSendStatus.Fail))
{
text = $"{headname}";//[错误信息:{msg}][提交时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][提交人:" + showname + "][船代:" + dcarrier + "]
if (!string.IsNullOrWhiteSpace(msg)) text += $"[错误信息:{msg}]";
}
if (ediSendStatus == EdiSendStatus.Overtime)
{
text = $"{headname}";//[错误信息:{msg}][提交时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][提交人:" + showname + "][船代:" + dcarrier + "]
if (!string.IsNullOrWhiteSpace(msg)) text += $"[发送超时,请联系平台业务人员!]";
}
if (ediSendStatus == EdiSendStatus.ISdelete)
{
text = "[已作废][提交时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "][提交人:" + showname + "]";
}
var billhead = edc.Edis.First(x => x.MFNO == MFNO);
billhead.EDISTATUS = newstatus;
if (ediSendStatus == EdiSendStatus.Success)
{
billhead.SENDTIME = DateTime.Now;
}
EdiChangeStatus(edc,billhead, newstatus, text, showname, dcarrier);
}
public static void SetEdiStatus(List<OpSeaeEdi> billList, string type, string showname, string dcarrier, EdiSendStatus ediSendStatus, string msg = "") {
foreach (var item in billList) {
SetEdiStatus(item.MFNO, type, showname, dcarrier, ediSendStatus, msg);
}
}
/// <summary>
/// 产生变动费用
/// </summary>
/// <param name="showname"></param>
/// <param name="loginComname"></param>
/// <param name="model"></param>
/// <param name="userid"></param>
/// <param name="stype"></param>
/// <param name="f"></param>
/// <param name="newctnlist"></param>
/// <param name="sendtype"></param>
public static Cust_Fee_md MakeChange(EdiDataContext edc, string showname,string companyid, string loginComname, OpSeaeEdi model
, string userid, int sendtype,ref string beizhu,bool withZhifa)
{
//sendtype 新增0 删除5 修改9 直发新增4
string XG = "";//备注字段
var f = new Cust_Fee_md(model, sendtype, userid, showname, companyid,loginComname, edc);
bool = false;//有成本修改
bool = false;//无成本修改
if (sendtype == 5 || sendtype == 0) {
= true;
}
#region 对比两个model获取修改类型
if (sendtype == 9)
{
//对比计算扣费额
//获取同票业务最近一次的消费记录
var oldfeelist = edc.Cust_Fee.Where(x => x.BSNO == model.MFNO).OrderByDescending(o => o.CREATETIME).ToList();
Cust_Fee_md fOld = new Cust_Fee_md();
if (oldfeelist != null && oldfeelist.Count > 0) fOld = oldfeelist[0];
///
//有成本字段
if (fOld.MBLNO != f.MBLNO)
{
= true;
XG += "主提单号,";
}
if (fOld.HBLNO != f.HBLNO)
{
= true;
XG += "分提单号,";
}
if (fOld.FORWARDER != f.FORWARDER)
{
= true;
XG += "船代,";
}
if (fOld.VESSEL != f.VESSEL)
{
if (fOld.VESSEL != null)
{
fOld.VESSEL = fOld.VESSEL.ToString().Trim();
}
if (f.VESSEL != null)
{
f.VESSEL = f.VESSEL.ToString().Trim();
}
= true;
XG += "船名,";
}
if (fOld.VOYNO != f.VOYNO)
{
if (fOld.VOYNO != null)
{
fOld.VOYNO = fOld.VOYNO.ToString().Trim();
}
if (f.VOYNO != null)
{
f.VOYNO = f.VOYNO.ToString().Trim();
}
= true;
XG += "航次,";
}
//无成本字段
if (fOld.ETD != null && f.ETD != null)
{
DateTime oldEtd = (DateTime)fOld.ETD;
DateTime newEtd = (DateTime)f.ETD;
TimeSpan ts = oldEtd - newEtd;
int differenceInDays = ts.Days;
if (differenceInDays != 0)
{
= true;
XG += "开船日,";
}
if (Convert.ToDecimal(fOld.PKGS) - Convert.ToDecimal(f.PKGS) != 0)
{
= true;
XG += "件数,";
}
}
if (fOld.KINDPKGS != f.KINDPKGS)
{
= true;
XG += "包装,";
}
if (fOld.KGS != f.KGS)
{
= true;
XG += "重量,";
}
if (fOld.CBM != f.CBM)
{
= true;
XG += "尺码,";
}
if (fOld.CARRIER != f.CARRIER)
{
= true;
XG += "船公司,";
}
if (fOld.PORTDISCHARGE != f.PORTDISCHARGE)
{
= true;
XG += "卸货港,";
}
if (fOld.DESTINATION != f.DESTINATION)
{
= true;
XG += "目的地,";
}
if (fOld.DESCRIPTION != f.DESCRIPTION)
{
= true;
XG += "货物描述,";
}
if (fOld.MARKS != f.MARKS)
{
= true;
XG += "唛头,";
}
//如果主要信息没有修改,则判断明细差别
var ctnlistOld = edc.Cust_Fee_Ctn.Where(x => x.FeeID == fOld.GID).ToList();// ("feeid = (select top 1 gid from Cust_Fee where bsno = '" + model.MFNO + "' order by CREATETIME desc)");
var newctnlist = new List<Cust_Fee_Ctn_md>();
string MXXG = "";
int = CompareCTN(f, ctnlistOld, out newctnlist, out MXXG);
//明细变化1有成本 2无成本
XG += MXXG;
if (XG.Length > 0)
{
XG = XG.Substring(0, XG.Length - 1);
XG = "修改:" + XG;
}
//只有修改记录备注
f.BEIZHU = XG;
beizhu = XG;
if (!)
{
if ( == 1)
{
= true;
}
else
{
= true;
}
}
}
#endregion
var custFeeType = getCustFeeType(sendtype, withZhifa, );
//if (sendtype == 9)
//{
// if (有成本修改)
// {
// FeeSendtype = 1;
// }
// else
// {
// FeeSendtype = 2;
// }
//}
//else {
// FeeSendtype = sendtype;
//}
var price = GetPrice(edc, loginComname, custFeeType, model,withZhifa);
f.PRICE = price;
f.SENDTYPE = custFeeType;
return f;
}
public static List<Cust_Fee_md> MakeChangeList(EdiDataContext edc, string showname,string companyid, string loginComname, List<OpSeaeEdi> billList, string userid, int sendtype, ref string beizhu,bool withZhifa)
{
var result = new List<Cust_Fee_md>();
foreach (var model in billList) {
var _r = MakeChange(edc, showname, companyid, loginComname, model, userid, sendtype, ref beizhu, withZhifa);
result.Add(_r);
}
return result;
}
public static Result_md (EdiDataContext edc1, Cust_Fee_md CustFee, ref Cust_Price_md pricehead, string COMPANYNAME)
{
//var result = new Result_md();
if (pricehead.GiftBalance >= CustFee.PRICE)
{
pricehead.GiftBalance -= CustFee.PRICE;
}
else
{
var price = CustFee.PRICE;
if (pricehead.GiftBalance > 0)
{
price = price - pricehead.GiftBalance;
pricehead.GiftBalance = 0;
}
var balance = edc1.Cust_Balance.FirstOrDefault(x => x.COMNAME == COMPANYNAME);
if (balance.Balance < price)
{
var jr_1 = new Result_md ( false, $"剩余余额已不足以发送完成此次业务,请及时充值!");
return jr_1;
}
balance.Balance -= price;
}
edc1.Cust_Fee.Add(CustFee);
var ctnlist = edc1.EdiCtns.Where(x => x.MFNO == CustFee.BSNO).ToList();
if (ctnlist.Count > 0)
{
foreach (var ctn in ctnlist) {
var CustFeeCtn = new Cust_Fee_Ctn_md(ctn,CustFee.GID);
edc1.Cust_Fee_Ctn.Add(CustFeeCtn);
}
}
return new Result_md ( true, "");
}
/// <summary>
/// 判断集装箱信息是否修改 是有成本还是无成本
/// 返回1 代表有成本
/// 返回2 代表无成本
/// </summary>
/// <param name="model"></param>
/// <param name="oldList"></param>
/// <param name="newList"></param>
/// <param name="xg"></param>
/// <returns></returns>
static private int CompareCTN(Cust_Fee_md model, List<Cust_Fee_Ctn_md> oldList, out List<Cust_Fee_Ctn_md> newList, out string xg)
{
xg = "";
EdiDataContext edc = new EdiDataContext();
//当前的集装箱明细
var ctnlistNew = edc.EdiCtns.Where(x => x.MFNO == model.BSNO).ToList();// GetBodyList("MFNO='" + model.BSNO + "'");
//根据箱号排序
oldList = oldList.OrderBy(a => a.XiangHao).ToList();
ctnlistNew = ctnlistNew.OrderBy(a => a.CNTRNO).ToList();
//判断不同,并返回收费类型
int index = 0;
//int sendtype = 2;
bool = false;
List<Cust_Fee_Ctn_md> list = new List<Cust_Fee_Ctn_md>();
if (oldList.Count != ctnlistNew.Count)
{
= || true;
xg = "箱量,";
}
foreach (var item in ctnlistNew)
{
if (index < oldList.Count)
{
Cust_Fee_Ctn_md old = oldList[index];
if (old.XiangHao != item.CNTRNO)
{
= || true;
xg += "箱号,";
}
if (old.XiangXing != item.CTNALL)
{
= || true;
xg += "箱型,";
}
if (old.FengHao != item.SEALNO)
{
= || false;
xg += "封号,";
}
}
else
{
= || true;
//sendtype = 1;
}
index++;
}
int idx = 0;
foreach (var item in ctnlistNew)
{
Cust_Fee_Ctn_md ctn = new Cust_Fee_Ctn_md(item, model.GID);
list.Add(ctn);
idx++;
}
newList = list;
//return sendtype;
if () return 1; else return 2;
}
public static decimal GetPrice(EdiDataContext edc ,string loginComname,int sendtype, OpSeaeEdi model,bool withZhifa) {
decimal price = doGetprice(edc,loginComname, sendtype, model);
return price;
}
private static decimal doGetprice(EdiDataContext edc,string companyname, int sendtype, OpSeaeEdi model)
{
//EdiDataContext edc = new EdiDataContext();
var priceObjList = edc.Cust_Price.Where(x => x.COMNAME == companyname && x.SENDTYPE == sendtype && x.BSTYPE == 0).ToList();
decimal result = -1;
if (priceObjList == null || priceObjList.Count == 0) {
return result;
}
var priceObj = priceObjList[0];
if (priceObj != null)
{
var priceDetail = edc.Cust_Price_detail.Where(x => x.LINKGID == priceObj.GID); //MsOpSeaeCustPriceDAL.GetBodyList(" LINKGID='" + priceObj.GID + "'");
if (model.FORWARDER == "青港")
{
//主分单
if (string.IsNullOrWhiteSpace(model.HBLNO))
{
//主单(分单号为空)
result = (decimal)priceObj.PRICEQG;
}
else
{
//分单
result = (decimal)priceObj.PRICEFQG;
}
}
else
{
var detailpriceList = edc.Cust_Price_detail.Where(x => x.LINKGID == priceObj.GID && x.FORWARDER == model.FORWARDER).ToList(); //MsOpSeaeCustPriceDAL.getPriceDetail(priceDetail, model.FORWARDER);
if (detailpriceList != null && detailpriceList.Count > 0)
{
var detailprice = detailpriceList[0];
if (string.IsNullOrWhiteSpace(model.HBLNO))
{
result = (decimal)detailprice.PRICE;
}
else
{
result = (decimal)detailprice.PRICEF;
}
}
else
//主分单
if (string.IsNullOrWhiteSpace(model.HBLNO))
{
result = (decimal)priceObj.PRICE;
}
else
{
result = (decimal)priceObj.PRICEF;
}
}
}
return result;
}
/// <summary>
///
/// </summary>
/// <param name="stype"></param>
/// <returns></returns>
public static int getSendType(string stype) {
var sendtype = 9;
//创建计费实体
if (stype == "新增")
{
sendtype = 0;
}
if (stype == "删除")
{
sendtype = 5;
}
if (stype == "修改")
{
sendtype = 9;
}
return sendtype;
}
public static int getCustFeeType(int sendtype, bool withZhifa,bool =true)
{
/// StoreFSLX.add({ "VALUE": "0", "TEXT": "新增" });
/// StoreFSLX.add({ "VALUE": "1", "TEXT": "有成本修改" });
/// StoreFSLX.add({ "VALUE": "2", "TEXT": "无成本修改" });
/// StoreFSLX.add({ "VALUE": "3", "TEXT": "导出" });
/// StoreFSLX.add({ "VALUE": "4", "TEXT": "船代直发" });
/// StoreFSLX.add({ "VALUE": "5", "TEXT": "删除" });
var FeeSendtype = 9;
if (sendtype == 0 && withZhifa)
{
FeeSendtype = 4;
}
else
if (sendtype == 9)
{
if ()
{
FeeSendtype = 1;
}
else
{
FeeSendtype = 2;
}
}
else
{
FeeSendtype = sendtype;
}
return FeeSendtype;
}
public static string DelOtherWord(string str) {
//var result = Regex.Replace(str, @"[^0-9a-zA-Z \s~!@#\$%\^&\*\(\)\+=\|\{\}\[:;<,.>\]]", "");
var result = Regex.Replace(str, @"[^0-9a-zA-Z ~!@#\$%\^&\*\(\)\+=_\-?\|\{\}\[:;<,.>\]/'""\r\n]", "");
//\u4e00-\u9fa5
return result;
}
/// <summary>
/// 各种文本转义字符
/// </summary>
/// <param name="fileType">文件类型例如txt、xml</param>
/// <param name="str">文本字符串</param>
/// <returns></returns>
public static string formatEdiStr(string fileType, string str)
{
var result = "";
if (fileType == "txt")
{
result= str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'");
}
else if (fileType == "xml")
{
result = str.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
}
else if (fileType == "both")
{
result = DelOtherWord(str);
result = result.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;").Replace("\"", "&quot;").Replace("'", "&apos;");
}
else
{
result = str;
}
//Encoding ec = Encoding.GetEncoding("iso-8859-1");
//byte[] btArr = ec.GetBytes(result);
//result = Encoding.Default.GetString(btArr);
return result;
}
public static List<System.String> formatlengthStr(string str, int length)
{
str = str.Replace("\r\n", "\\");
str = str.Replace("\n", "\\");
str = str.Replace("\r", " ");
string[] StrList = str.Split('\\');
var strtemp = "";
var strnewline = "";
var strtempnewline = "";
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
List<System.String> DestList = new List<System.String>();
for (var i = 0; i <= StrList.Length - 1; i++)
{
if (StrList[i].Length <= length) 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
{
DestList.Add(strnewline);
strnewline = strtempnewline;
}
strtempnewline = "";
}
}
if (strnewline.Trim() != "")
DestList.Add(strnewline);
}
}
return DestList;
}
public static List<System.String> formatlengthStr(string[] str, int length, int start)
{
var strtemp = "";
var strnewline = "";
var strtempnewline = "";
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
List<System.String> DestList = new List<System.String>();
for (var i = 1; i <= str.Length - 1; i++)
{
if (str[i].Length <= length) DestList.Add(str[i]);
else
{
strtemp = str[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
{
DestList.Add(strnewline);
strnewline = strtempnewline;
}
strtempnewline = "";
}
}
if (strnewline.Trim() != "")
DestList.Add(strnewline);
}
}
return DestList;
}
static public string GetPackageEDICode(string Package, string EDINAME)
{
string EDICODE = "";
Package = Package.Replace("'", "''");
//var strSql = new StringBuilder();
//strSql.Append("select EDICODE from code_pkgs_edi where PKGS='" + Package + "' AND EDINAME='" + EDINAME + "'");
//Database db = DatabaseFactory.CreateDatabase();
//using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
//{
// while (reader.Read())
// {
// EDICODE = Convert.ToString(reader["EDICODE"]).Trim();
// }
// reader.Close();
//}
EdiDataContext edc = new EdiDataContext();
var ediitem = edc.code_pkgs_edi.FirstOrDefault(x => x.PKGS == Package && x.EDINAME == EDINAME);
if (ediitem != null)
{
EDICODE = ediitem.EDICODE;
}
else {
var ediitembase = edc.CODE_PACKAGE.FirstOrDefault(x => x.PKGS == Package);
if (ediitembase != null)
EDICODE = ediitembase.EDICODE;
}
return EDICODE;
}
public static string CheckCTNALL(string CTNALL) {
EdiDataContext edc = new EdiDataContext();
var cc = edc.Code_Ctn.Where(x => x.CTN == CTNALL).ToList();
if (cc == null || cc.Count == 0) return "";
else
return cc[0].CTN;
}
}
public class DoSend {
#region 导出分票舱单EDIXML格式海关一点通
public static string MakeFenDanFile(List<OpSeaeEdi> headList, int FILEROLE, string SENDCODE, string path, string USERID)
{
//var opBill = headList[0];
//string filename = path + "\\" + opalertNo + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
//if (System.IO.File.Exists(filename))
//{
// System.IO.File.Delete(filename);
//}
var filename = GetFenDanFileName(headList, path);
return MakeFenDanFile_WithFileName( headList, FILEROLE, SENDCODE, filename, USERID);
}
public static string GetFenDanFileName(List<OpSeaeEdi> headList, string path) {
var opBill = headList [0];
//20210331 从主单信息表里获取船名航次
var = "";
var edc = new EdiDataContext();
var List = edc.op_seae_edi_mainstatus.Where(x => x.mfno == opBill.BSNO).ToList();
if (List.Count > 0)
{
var _head = List[0];
= "%" + _head.means_transport + "%" + _head.voyage_number + "%";
}
//else
//{
// //20220613 对于不明原因的主单信息mfno填入了分单MFNO的情况 采用如下逻辑
// 主单信息List = edc.op_seae_edi_mainstatus.Where(x => headList.Select(s => s.MFNO).Contains(x.mfno)).ToList();
// if (主单信息List.Count > 0)
// {
// var _head = 主单信息List[0];
// 船名航次文本 = "%" + _head.means_transport + "%" + _head.voyage_number + "%";
// }
//}
string filename = path + opBill.MBLNO + + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
return filename;
}
/// <summary>
/// 根据已指定的文件名生成待发分单的报文
/// </summary>
/// <param name="headList"></param>
/// <param name="FILEROLE"></param>
/// <param name="SENDCODE"></param>
/// <param name="FileName"></param>
/// <param name="USERID"></param>
/// <returns></returns>
public static string MakeFenDanFile_WithFileName(List<OpSeaeEdi> headList, int FILEROLE, string SENDCODE, string FileName, string USERID)
{
var opBill = headList[0];
//string filename = path + "\\" + opalertNo + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
if (System.IO.File.Exists(FileName))
{
System.IO.File.Delete(FileName);
}
var filename = Path.GetFileName(FileName);
var filepath = FileName.Replace(filename,"");
var newfilename = GetFenDanFileName(headList, filepath);
FileName = newfilename;
FileStream f = new FileStream(FileName, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.Default);
EdiDataContext edc = new EdiDataContext();
var userData = edc.UserBases.FirstOrDefault(x => x.USERID == USERID);
if (string.IsNullOrWhiteSpace(userData.FaSongFangDaiMa) || string.IsNullOrWhiteSpace(userData.JieShouFangDaiMa)) {
userData = edc.UserBases.FirstOrDefault(x => x.USERID == "d85fd590-d9f6-4410-93a1-f6fac77b606e");
}
var mainhead = edc.Edis.FirstOrDefault(x => x.MBLNO == opBill.MBLNO && !(x.HBLNO.Trim() == "" || x.HBLNO == null));
var zdxxHead = edc.op_seae_edi_mainstatus.FirstOrDefault(x => x.mblno == opBill.MBLNO);
var zdxxBodyList = edc.op_seae_edi_mainstatus_xhinfo.Where(x => x.mblno == opBill.MBLNO).ToList();
var loadportedicode = CheckData.GetLoadPortEdiCode(zdxxHead.customs_code);
//20220727 将部分信息改为固定值
var SENDID = "4200MA3P5JHB2";
var RECEIVEID = "4200";
//20220902 根据该客户是用大简云直发还是自己发 来判断SENDID的取值
//如客户自发 则取 company_new.CangdanCode
var userinfo = edc.Users.FirstOrDefault(x => x.GID == USERID);
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"))
{
//已配置该参数 使用公司自己的company_new.CangdanCode
var company = cdc.CompanyNew.FirstOrDefault(x => x.CompId == userinfo.CompId);
if (company != null && !string.IsNullOrWhiteSpace(company.CangdanCode) && company.CangdanCode.Trim().Length>=4) {
SENDID = company.CangdanCode;
RECEIVEID = SENDID.Substring(0, 4);
}
}
else
{
//未配置该参数 仍使用原有SENDID直发
}
#region xml按回车显示
r.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
r.WriteLine("<Manifest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:Declaration:datamodel:standard:CN:MT2101:1\">");
#region Head
r.WriteLine("<Head>");
//报文编号循环次数1
//r.WriteLine("<MessageID>" + SENDCODE + opBill.MBLNO +"_"+ DateTime.Now.ToString("yyyyMMddHHmmssfff") + "</MessageID>");
r.WriteLine("<MessageID>" + SENDID + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "</MessageID>");
//报文功能代码循环次数1
r.WriteLine("<FunctionCode>" + FILEROLE + "</FunctionCode>");
//报文类型代码循环次数1
r.WriteLine("<MessageType>MT2101</MessageType>");
//发送方代码循环次数1
//r.WriteLine("<SenderID>" + userData.FaSongFangDaiMa + "</SenderID>");
r.WriteLine("<SenderID>" + SENDID + "</SenderID>");
//接受方代码循环次数1
//r.WriteLine("<ReceiverID>" + userData.JieShouFangDaiMa + "</ReceiverID>");
r.WriteLine("<ReceiverID>" + RECEIVEID + "</ReceiverID>");
//发送时间循环次数1采用精确到毫秒的时间格式格式为CCYYMMDDHHmmssfff
r.WriteLine("<SendTime>" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "</SendTime>");
//报文版本号循环次数1
r.WriteLine("<Version>1.0</Version>");
r.WriteLine("</Head>");
#endregion
//报文体循环次数1
r.WriteLine("<Declaration>");
#region 承运人
//舱单传输人数据段循环次数1
r.WriteLine("<RepresentativePerson>");
// 256 Representative person name 舱单传输人名称循环次数1
//r.WriteLine("<Name>" + userData.FaSongFangDaiMa + "</Name>");
r.WriteLine("<Name>" + RECEIVEID + "</Name>");
r.WriteLine("</RepresentativePerson>");
// 运输工具离境地海关数据段循环次数1
r.WriteLine("<ExitCustomsOffice>");
// 运输工具离境地海关代码循环次数1
///20210209 原逻辑为固定
///现改为根据接口返回值填入。
//r.WriteLine("<ID>CNQWG/4258</ID>");///////////////////////20210218 改为从已经读取的主单信息中提取
r.WriteLine("<ID>" + loadportedicode + "</ID>");
r.WriteLine("</ExitCustomsOffice>");
// 运输工具代理企业数据段循环次数0-1
r.WriteLine("<Agent>");
// 运输工具代理企业代码循环次数1
//r.WriteLine("<ID>" + userData.FaSongFangDaiMa + "</ID>");
r.WriteLine("<ID>" + SENDID + "</ID>");
r.WriteLine("</Agent>");
// 承运人数据段循环次数1
r.WriteLine("<Carrier>");
// 承运人代码循环次数1
// r.WriteLine("<ID>" + MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetCustEdi(opBill.CARRIER) + "</ID>");
//r.WriteLine("<ID>" + opBill.CARRIER + "</ID>");//20210218 分单的船公司字段固定写成DAJIANYUN
r.WriteLine("<ID>"+ SENDID + "</ID>");
r.WriteLine("</Carrier>");
#endregion
#region 运输工具
// 运输工具数据段循环次数1
r.WriteLine("<BorderTransportMeans>");
//航次航班编号循环次数1//20210218 改为从已经读取的主单信息中提取
//r.WriteLine("<JourneyID>" + opBill.VOYNO + "</JourneyID>");//20210218 改为从已经读取的主单信息中提取
r.WriteLine("<JourneyID>" + zdxxHead.voyage_number + "</JourneyID>");
//运输方式代码循环次数1
r.WriteLine("<TypeCode>1</TypeCode>");
// 运输工具代码循环次数0-1
//string shipimo = mainhead.SHIPIMO;//改为使用读取主单信息接口时返回的IMO字段值
string shipimo = zdxxHead.IMO;
r.WriteLine("<ID>"+ shipimo + "</ID>");//船舶IMO
// 运输工具名称循环次数0-1//20210218 改为从已经读取的主单信息中提取
//r.WriteLine("<Name>" + opBill.VESSEL + "</Name>");//20210218 改为从已经读取的主单信息中提取
r.WriteLine("<Name>" + zdxxHead.means_transport + "</Name>");
//运输工具抵达关境内第一个目的港代码循环次数0-1
//r.WriteLine("<FirstArrivalLocationID>" + MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.GetPortEDICode(opBill.PORTDISCHARGEID, "HGYDT") + "</FirstArrivalLocationID>");
////运输工具抵达关境内第一个目的港的日期和时间CCYYMMDDhhmmss循环次数0-1
//DateTime dtetd = DateTime.Parse(opBill.ETD).AddDays(5);
//r.WriteLine("<ArrivalDateTime>" + dtetd.ToString("yyyyMMdd") + "0000086" + "</ArrivalDateTime>");
////运输工具启运日期和时间CCYYMMDDhhmmss循环次数1
//DateTime dteta = DateTime.Parse(opBill.ETA).AddDays(5);
//r.WriteLine("<DepartureDateTime>" + dteta.ToString("yyyyMMdd") + "0000086" + "</DepartureDateTime>");
r.WriteLine("</BorderTransportMeans>");
#endregion
#region 更改原因代码循环次数0-3暂时无此功能
if (FILEROLE == 3)
{
//for( i:=0 to bsSkinCheckListBox1.Items.Count-1 )
//{
//if bsSkinCheckListBox1.Checked[i] then
// {
// str.Add('<ChangeReasonCode>'+COPY(bsSkinCheckListBox1.Items[i],1,Pos(':',bsSkinCheckListBox1.Items[i])-1)+'</ChangeReasonCode>');
// }
//}
}
#endregion
//已分单为最小单位,合计语句
// T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
// string sSQL = @"SELECT [MFNO],[MBLNO],[HBLNO],sum([PKGS]) as [PKGS],sum([KGS]) as [KGS],sum([CBM]) as [CBM],REMARKS,KINDPKGS
//from op_seae_edi where MBLNO='" + opalertNo + "' and HBLNO<> '' group by [MFNO],[MBLNO],[HBLNO],REMARKS,KINDPKGS order by MBLNO";//,[CNTRNO],[SEALNO],[DESCRIPTION]
// DataSet dsFenDan = T_ALL_DA.GetAllSQL(sSQL);
//decimal 重量合计 = (decimal)分单List.Sum(s => s.KGS);
var dsFenDan = edc.Edis.Where(x => x.MBLNO == opBill.MBLNO && !(x.HBLNO.Trim() == "" || x.HBLNO == null)).ToList();
//var PKGS = (decimal)dsFenDan.Sum(s => s.PKGS);
//var KGS = (decimal)dsFenDan.Sum(s => s.KGS);
//var CBM = (decimal)dsFenDan.Sum(s => s.CBM);
if (dsFenDan != null)
{
foreach (var FenDan in dsFenDan)
{
if (!headList.Exists(x => x.MFNO == FenDan.MFNO)) { continue; }
//提单数据段循环次数1-9999
r.WriteLine("<Consignment>");
#region 付费方式、运输条款
var xtype = "PP";
if (FenDan.BLFRT.IndexOf("FREIGHT COLLECT") >= 0)
xtype = "CC";
string sSERVICE = "";
if (FenDan.SERVICE.ToUpper() == "DOOR-DOOR")//Door-to-door
{
sSERVICE = "27";
}
else if (FenDan.SERVICE.ToUpper() == "DOOR-CY")//Door-to-pier
{
sSERVICE = "28";
}
else if (FenDan.SERVICE.ToUpper() == "CY-DOOR")//Pier-to-door
{
sSERVICE = "29";
}
else if (FenDan.SERVICE.ToUpper() == "CY-CY")//Pier-to-pier
{
sSERVICE = "10";
}
else
{
sSERVICE = "10";
}
//运输合同信息循环次数1
r.WriteLine("<TransportContractDocument>");
//总提单号循环次数1
r.WriteLine("<ID>" + FenDan.MBLNO + "</ID>");
//运输条款代码循环次数0-1
r.WriteLine("<ConditionCode>" + sSERVICE + "</ConditionCode>");
r.WriteLine("</TransportContractDocument>");
//运输合同附加信息循环次数0-1
r.WriteLine("<AssociatedTransportDocument>");
//分提单号循环次数1
r.WriteLine("<ID>" + FenDan.HBLNO + "</ID>");
r.WriteLine("</AssociatedTransportDocument>");
#endregion
#region 货物信息
//货物体积循环次数0-1
// r.WriteLine("<GrossVolumeMeasure>" + Math.Round(Decimal.Parse(dsFenDan.Tables[0].Rows[i]["CBM"].ToString()), 0).ToString() + "</GrossVolumeMeasure>");
//装货地信息循环次数0-1
r.WriteLine("<LoadingLocation>");
//装货地代码循环次数0-1
r.WriteLine("<ID>" + loadportedicode + "</ID>");
//货物装载运输工具时间循环次数0-1
//20220727 改为ETD+15天
DateTime loadingdate = ((DateTime)opBill.ETD).AddDays(15);
r.WriteLine("<LoadingDate>" + loadingdate.ToString("yyyyMMdd") + "120000" + "</LoadingDate>");
//r.WriteLine("<LoadingDate></LoadingDate>");
r.WriteLine("</LoadingLocation>");
//卸货地信息循环次数1
r.WriteLine("<UnloadingLocation>");
//卸货地代码循环次数1
r.WriteLine("<ID>" + FenDan.PORTDISCHARGEID + "</ID>");
//到达卸货地日期(CCYYMMDD)循环次数0-1
//20200222 ArrivalDate改为开船日期+3天
//r.WriteLine("<ArrivalDate></ArrivalDate>");
r.WriteLine("</UnloadingLocation>");
//收货地信息循环次数0-1
r.WriteLine("<GoodsReceiptPlace>");
//收货地点代码循环次数0-1
r.WriteLine("<ID>" + ChangeInfo.formatEdiStr("both", FenDan.DESTINATIONID) + "</ID>");
//收货地点名称循环次数0-1
r.WriteLine("<Name>" + ChangeInfo.formatEdiStr("both", FenDan.DESTINATION) + "</Name>");
r.WriteLine("</GoodsReceiptPlace>");
r.WriteLine("<GoodsConsignedPlace>");
// <!--收货地点代码循环次数0-1-->
r.WriteLine("<ID>CN37</ID>");
r.WriteLine("</GoodsConsignedPlace>");
r.WriteLine("<CustomsStatusCode>001</CustomsStatusCode>");
//运费支付信息循环次数1
r.WriteLine("<FreightPayment>");
//运费支付方法代码循环次数1
r.WriteLine("<MethodCode>" + xtype + "</MethodCode>");
r.WriteLine("</FreightPayment>");
//货物总件数/包装种类代码循环次数1
r.WriteLine("<ConsignmentPackaging>");
//货物总件数循环次数1
r.WriteLine("<QuantityQuantity>" + FenDan.PKGS.ToString() + "</QuantityQuantity>");
// 包装种类代码循环次数0-1
r.WriteLine("<TypeCode>" + ChangeInfo.GetPackageEDICode(FenDan.KINDPKGS.ToString(), "HGYDT").Trim() + "</TypeCode>");
r.WriteLine("</ConsignmentPackaging>");
//货物总毛重循环次数1
r.WriteLine("<TotalGrossMassMeasure>" + FenDan.KGS.ToString() + "</TotalGrossMassMeasure>");
#endregion
#region 收货人
//收货人信息循环次数0-1
r.WriteLine("<Consignee>");
//收货人代码循环次数0-1
// r.WriteLine("<ID>" + FenDan.LeiXingShou + "+" + FenDan.CONSIGNEECODE + "</ID>");
//r.WriteLine("<ID></ID>");
//收货人名称循环次数0-1
var Shipping = ChangeInfo.formatEdiStr("both", FenDan.CONSIGNEE);
List<System.String> ShippingList = ChangeInfo.formatlengthStr(Shipping, 35);
if (ShippingList.Count >= 1)
r.WriteLine("<Name>" + ShippingList[0].ToString() + "</Name>");
else r.WriteLine("<Name></Name>");
//收货人地址信息循环次数0-1
r.WriteLine("<Address>");
//详细地址(街道,邮箱循环次数0-1
r.WriteLine("<Line>" + ChangeInfo.formatEdiStr("both", FenDan.CONSIGNEEADDR1) + "</Line>");
r.WriteLine("<CountryCode>" + FenDan.CONSIGNEECOUNTRY + "</CountryCode>");
r.WriteLine("</Address>");
r.WriteLine("<Communication>");
if (!string.IsNullOrWhiteSpace(FenDan.SHIPPERTEL))
{
r.WriteLine("<ID>" + FenDan.CONSIGNEETEL + "</ID>");
r.WriteLine("<TypeID>TE</TypeID>");
}
else
{
r.WriteLine("<ID>" + FenDan.CONSIGNEEEMAIL + "</ID>");
r.WriteLine("<TypeID>EM</TypeID>");
}
r.WriteLine("</Communication>");
r.WriteLine("</Consignee>");
#endregion
#region 发货人
//发货人信息循环次数1
r.WriteLine("<Consignor>");
//发货人代码循环次数0-1
// r.WriteLine("<ID>" + FenDan.LeiXingFa + "+" + FenDan.SHIPPERCODE + "</ID>");
//r.WriteLine("<ID></ID>");
//发货人名称循环次数1
Shipping = ChangeInfo.formatEdiStr("both", FenDan.SHIPPER);
List<System.String> ShippingList2 = ChangeInfo.formatlengthStr(Shipping, 35);
if (ShippingList2.Count >= 1)
r.WriteLine("<Name>" + ShippingList2[0].ToString() + "</Name>");
else r.WriteLine("<Name></Name>");
//发货人地址信息循环次数0-1
r.WriteLine("<Address>");
//详细地址(街道,邮箱循环次数0-1
r.WriteLine("<Line>" + ChangeInfo.formatEdiStr("both", FenDan.SHIPPERADDR1) + "</Line>");
r.WriteLine("<CountryCode>" + FenDan.SHIPPERCOUNTRY + "</CountryCode>");
r.WriteLine("</Address>");
r.WriteLine("<Communication>");
if (!string.IsNullOrWhiteSpace(FenDan.SHIPPERTEL))
{
r.WriteLine("<ID>" + FenDan.SHIPPERTEL + "</ID>");
r.WriteLine("<TypeID>TE</TypeID>");
}
else
{
r.WriteLine("<ID>" + FenDan.SHIPPEREMAIL + "</ID>");
r.WriteLine("<TypeID>EM</TypeID>");
}
r.WriteLine("</Communication>");
r.WriteLine("</Consignor>");
#endregion
#region 通知人
//通知人信息循环次数0-1
r.WriteLine("<NotifyParty>");
//通知人代码循环次数0-1
// r.WriteLine("<ID>" + FenDan.LeiXingTong + "+" + FenDan.NOTIFYPARTYCODE + "</ID>");
//r.WriteLine("<ID></ID>");
//通知人名称循环次数0-1
Shipping = ChangeInfo.formatEdiStr("both", FenDan.NOTIFYPARTY);
List<System.String> ShippingList3 = ChangeInfo.formatlengthStr(Shipping, 35);
if (ShippingList3.Count >= 1)
r.WriteLine("<Name>" + ShippingList3[0].ToString() + "</Name>");
else r.WriteLine("<Name></Name>");
//通知人地址信息循环次数0-1
r.WriteLine("<Address>");
//详细地址(街道,邮箱循环次数1
r.WriteLine("<Line>" + ChangeInfo.formatEdiStr("both", FenDan.NOTIFYPARTYADDR1) + "</Line>");
r.WriteLine("<CountryCode>" + FenDan.NOTIFYPARTYCOUNTRY + "</CountryCode>");
r.WriteLine("</Address>");
//20220725 收货人电话 TE
r.WriteLine("<Communication>");
//详细地址(街道,邮箱循环次数1
r.WriteLine("<ID>" + FenDan.CONSIGNEETEL + "</ID>");
r.WriteLine("<TypeID>TE</TypeID>");
r.WriteLine("</Communication>");
//if (!string.IsNullOrWhiteSpace( FenDan.NOTIFYPARTYTEL) || !string.IsNullOrWhiteSpace(FenDan.NOTIFYPARTYEMAIL))
//{
// r.WriteLine("<Communication>");
// if (!string.IsNullOrWhiteSpace(FenDan.NOTIFYPARTYTEL))
// {
// r.WriteLine("<ID>" + FenDan.NOTIFYPARTYTEL + "</ID>");
// r.WriteLine("<TypeID>TE</TypeID>");
// }
// else
// {
// r.WriteLine("<ID>" + FenDan.NOTIFYPARTYEMAIL + "</ID>");
// r.WriteLine("<TypeID>EM</TypeID>");
// }
// r.WriteLine("</Communication>");
//}
r.WriteLine("</NotifyParty>");
#endregion
#region 危险品信息
if (FenDan.CARGOID.Trim() == "D")
{
r.WriteLine("<UNDGContact>");
r.WriteLine("<Name>" + FenDan.DATTN + "</Name>");
r.WriteLine("<Communication>");
r.WriteLine("<ID>" + FenDan.DTEL + "</ID>");
r.WriteLine("<TypeID>TE</TypeID>");
r.WriteLine("</Communication>");
r.WriteLine("</UNDGContact>");
}
#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("<TransportEquipment>");
//集装箱编号信息循环次数1)
r.WriteLine("<EquipmentIdentification>");
// 集装箱编号循环次数1
r.WriteLine("<ID>" + ctn.CNTRNO + "</ID>");
r.WriteLine("</EquipmentIdentification>");
//集装箱尺寸和类型循环次数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("<CharacteristicCode>" + sCTNALL + "</CharacteristicCode>");
}
else
{
r.WriteLine("<CharacteristicCode></CharacteristicCode>");
}
//集装箱来源代码循环次数0-1
r.WriteLine("<SupplierPartyTypeCode>2</SupplierPartyTypeCode>");
//重箱或者空箱标识代码循环次数1
//if (opBill.FORWARDER == "振华" || opBill.FORWARDER == "外代")
//{
// r.WriteLine("<FullnessCode>" + "8" + "</FullnessCode>");
//}
//else
//{
// r.WriteLine("<FullnessCode>" + ctn.ZhongKongBiaoShi + "</FullnessCode>");
//}
r.WriteLine("<FullnessCode>" + zdxxctninfo.getZKBS() + "</FullnessCode>");
//SealID的值是封志类型/号码,AgencyCode的值是施加封志人类型循环次数0-9
r.WriteLine("<SealID AgencyCode=\"" + zdxxctninfo.ShiFengRen + "\">M/" + ctn.SEALNO + "</SealID>");
r.WriteLine("</TransportEquipment>");
#endregion
}
#region 集装箱_内容
//商品项信息循环次数1-999
r.WriteLine("<ConsignmentItem>");
//商品项序号循环次数1
r.WriteLine("<SequenceNumeric>1</SequenceNumeric>");
//商品项包装信息循环次数1
r.WriteLine("<ConsignmentItemPackaging>");
//商品项货物件数循环次数1
r.WriteLine("<QuantityQuantity>" + FenDan.PKGS.ToString() + "</QuantityQuantity>");
//包装种类代码循环次数0-1
r.WriteLine("<TypeCode>" + ChangeInfo.GetPackageEDICode(FenDan.KINDPKGS.ToString(), "HGYDT").Trim() + "</TypeCode>");
//唛头循环次数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("<MarksNumbers>" + ChangeInfo.formatEdiStr("both", FenDan.MARKS) + "</MarksNumbers>");
r.WriteLine("</ConsignmentItemPackaging>");
//商品项简要描述循环次数1
r.WriteLine("<Commodity>");
//商品项简要描述循环次数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("<CargoDescription>" + ChangeInfo.formatEdiStr("both", FenDan.DESCRIPTION) + "</CargoDescription>");
//危险品编号循环次数0-1
if (opBill.CARGOID.Trim() == "D")
{
r.WriteLine("<UNDGCode>" + FenDan.DUNNO + "</UNDGCode>");
}
//海关税则编号循环次数0-1//20220727去掉
//r.WriteLine("<TariffClassificationCode></TariffClassificationCode>");
r.WriteLine("</Commodity>");
//商品项货物毛重循环次数1
r.WriteLine("<GoodsMeasure>");
//商品项货物毛重循环次数1
r.WriteLine("<GrossMassMeasure>" + FenDan.KGS.ToString() + "</GrossMassMeasure>");
r.WriteLine("</GoodsMeasure>");
#endregion
foreach (var ctn in ctnList)
{
#region 集装箱_封号
//集装箱编号信息循环次数0-9999
r.WriteLine("<EquipmentIdentification>");
// 集装箱编号循环次数1
r.WriteLine("<ID>" + ctn.CNTRNO + "</ID>");
r.WriteLine("</EquipmentIdentification>");
#endregion
}
r.WriteLine("</ConsignmentItem>");
r.WriteLine("</Consignment>");
}
}
r.WriteLine("</Declaration>");
r.WriteLine("</Manifest>");
#endregion
r.Close();
f.Close();
return FileName;
}
private static string SetXMLStr(string str) {
var result = str;
//Result:= Trim(str);
//Result:= StringReplace(Result, '&', '&amp;',[rfReplaceAll]);
//Result:= StringReplace(Result, '<', '&lt;',[rfReplaceAll]);
//Result:= StringReplace(Result, '"', '&quot;',[rfReplaceAll]);
//Result:= StringReplace(Result, '>', '&gt;',[rfReplaceAll]);
//Result:= StringReplace(Result, '''', '&apos;',[rfReplaceAll]);
result = result.Replace("&", "&amp;");
result = result.Replace("<", "&lt;");
result = result.Replace("\"", "&quot");
result = result.Replace(">", "&gt;");
result = result.Replace("'", "&apos;");
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
/// <summary>
/// 发送舱单 发送主单
/// </summary>
/// <param name="EdiList"></param>
/// <param name="dcarrier"></param>
/// <param name="filepath"></param>
/// <param name="userid"></param>
/// <param name="showname"></param>
/// <param name="type"></param>
/// <returns></returns>
public static Result_md SendEdiDirect(List<OpSeaeEdi> 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<PortResult>(str);
//stats = PortResult.stats;
status = PortResult.status;
message= PortResult.message;
}
}
public Result_md SendFendanDirect(List<OpSeaeEdi> 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;
}
}
/// <summary>
/// 获得分单号的
/// </summary>
/// <param name="hblno"></param>
/// <returns></returns>
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("<br />"));
}
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<OpSeaeEdi> 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<OpSeaeEdi> 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<byte> 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<byte>();
}
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<byte> 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<WLXX_MBLNO_DELAY_md>();
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";
/// <summary>
/// 通过接口读取回执状态
/// 如果状态值中包括(接收申报/放行则返回true 否则返回false
/// </summary>
/// <param name="MBLNO"></param>
/// <param name="MFNO"></param>
/// <param name="needtype">临时读取/正常读取;如临时读取则在返回值中包括“接收申报”时</param>
/// <returns></returns>
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<RepWLXXModel>(rtn);
//if(PortResult.status=="0") DoSend.主单设为发送异常(MBLNO);
//var falseresult = Newtonsoft.Json.JsonConvert.DeserializeObject<RepZDXXfalseModel>(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;
}
/// <summary>
/// 读取主单信息方法
/// </summary>
/// <param name="MBLNO"></param>
/// <param name="MFNO"></param>
/// 请求参数
/// <returns></returns>
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<ZDXXModel_jiekou>(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<RepZDXXfalseModel>(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<StatusZDXX_HeadModel>(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<RepZDXXfalseModel>(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();
}
}
}