DS7/DSWeb/Shipping/EDIList.aspx.cs

1518 lines
85 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;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using DSWeb.DataAccess;
using System.Data.SqlClient;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Web.Script.Serialization;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Web.Mail;
using System.IO;
using System.Data.OleDb;
using JsonHelper;
using DSWeb.Log;
using System.Xml.Linq;
using System.Xml;
namespace DSWeb.Shipping
{
public partial class EDIList : System.Web.UI.Page
{
TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA();
TempOpSeaeEdiEntity TempOpSeaeEdiEntity = new TempOpSeaeEdiEntity();
TempOpSeaeEdiDA TempOpSeaeEdiDA = new TempOpSeaeEdiDA();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
TopCtnDA TopCtnDA = new TopCtnDA();
TopCtnEntity TopCtnEntity = new TopCtnEntity();
public string strHandleType = String.Empty;
//grid
private string strColumnVal;
public string strUserID;//用户GID
private string strType = "16";//Grid模块号
private string strShowName;//用户登录名
private string strCompanyID;//分公司GID
private string strDeptName;//部门名称
//gridEnd
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
//strUserID = "";
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
//
if (!IsPostBack)
{
}
if (hid_setting.Value.Trim() != "")
{
strColumnVal = hid_setting.Value.Trim();
SaveColumnSetting(strColumnVal);
hid_setting.Value = "";
}
if (hid_header.Value.Trim() != "")
{
strColumnVal = hid_header.Value.Trim();
SaveColumnSetting(strColumnVal);
hid_header.Value = "";
}
}
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "EDI" + strBSNO;
return strBSNO;
}
protected void getNULL()
{
TempOpSeaeEdiEntity.GID = getBSNO();
//TempOpSeaeEdiEntity.DOCGID = "";
TempOpSeaeEdiEntity.ISOK = false;
TempOpSeaeEdiEntity.CAUSE = "";
//
TempOpSeaeEdiEntity.BSNO = TempOpSeaeEdiEntity.GID;
TempOpSeaeEdiEntity.MASTERNO = "";
TempOpSeaeEdiEntity.BSSTATUS = false;
TempOpSeaeEdiEntity.FEESTATUS = false;
TempOpSeaeEdiEntity.ORDERTYPE = "EDI导入";
//TempOpSeaeEdiEntity.BSDATE = DateTime.Today.Date;
TempOpSeaeEdiEntity.ACCDATE = "";
TempOpSeaeEdiEntity.MBLNO = "";
TempOpSeaeEdiEntity.HBLNO = "";
TempOpSeaeEdiEntity.CUSTNO = "";
TempOpSeaeEdiEntity.TRANSNO = "";
TempOpSeaeEdiEntity.CUSTOMERNAME = "";
TempOpSeaeEdiEntity.BLTYPE = "";
TempOpSeaeEdiEntity.STLNAME = "";
TempOpSeaeEdiEntity.SHIPPERID = "";
TempOpSeaeEdiEntity.CONSIGNEEID = "";
TempOpSeaeEdiEntity.NOTIFYPARTYID = "";
TempOpSeaeEdiEntity.SHIPPER = "";
TempOpSeaeEdiEntity.CONSIGNEE = "";
TempOpSeaeEdiEntity.NOTIFYPARTY = "";
TempOpSeaeEdiEntity.AGENTID = "";
TempOpSeaeEdiEntity.AGENT = "";
TempOpSeaeEdiEntity.YARD = "";
TempOpSeaeEdiEntity.VESSEL = "";
TempOpSeaeEdiEntity.VOYNO = "";
TempOpSeaeEdiEntity.PlACERECEIPT = "";
TempOpSeaeEdiEntity.PORTLOADID = "";
TempOpSeaeEdiEntity.PORTLOAD = "";
TempOpSeaeEdiEntity.PORTDISCHARGEID = "";
TempOpSeaeEdiEntity.PORTDISCHARGE = "";
TempOpSeaeEdiEntity.PLACEDELIVERYID = "";
TempOpSeaeEdiEntity.PLACEDELIVERY = "";
TempOpSeaeEdiEntity.DESTINATIONID = "";
TempOpSeaeEdiEntity.DESTINATION = "";
TempOpSeaeEdiEntity.NOBILL = "";
TempOpSeaeEdiEntity.ISSUETYPE = "";
TempOpSeaeEdiEntity.ISSUEPLACE = "";
TempOpSeaeEdiEntity.BLFRT = "";
TempOpSeaeEdiEntity.PREPARDAT = "";
TempOpSeaeEdiEntity.PAYABLEAT = "";
TempOpSeaeEdiEntity.SERVICE = "";
TempOpSeaeEdiEntity.MARKS = "";
TempOpSeaeEdiEntity.CNTRSEALNO = "";
TempOpSeaeEdiEntity.NOPKGS = "";
TempOpSeaeEdiEntity.DESCRIPTION = "";
TempOpSeaeEdiEntity.GOODSNAME = "";
TempOpSeaeEdiEntity.GROSSWEIGHT = "";
TempOpSeaeEdiEntity.MEASUREMENT = "";
TempOpSeaeEdiEntity.PKGS = 0;
TempOpSeaeEdiEntity.KINDPKGS = "";
TempOpSeaeEdiEntity.KGS = 0;
TempOpSeaeEdiEntity.CBM = 0;
TempOpSeaeEdiEntity.TOTALNO = "";
TempOpSeaeEdiEntity.CNTRNO = "";
TempOpSeaeEdiEntity.CNTR1 = 0;
TempOpSeaeEdiEntity.CNTR2 = 0;
TempOpSeaeEdiEntity.CNTR3 = 0;
TempOpSeaeEdiEntity.CNTR4 = 0;
TempOpSeaeEdiEntity.CNTR5 = 0;
TempOpSeaeEdiEntity.CNTR6 = 0;
TempOpSeaeEdiEntity.CNTR7 = 0;
TempOpSeaeEdiEntity.CNTR8 = 0;
TempOpSeaeEdiEntity.CNTR9 = 0;
TempOpSeaeEdiEntity.CNTR10 = 0;
TempOpSeaeEdiEntity.OTCNTR = 0;
TempOpSeaeEdiEntity.TEU = 0;
TempOpSeaeEdiEntity.CNTRTOTAL = "";
TempOpSeaeEdiEntity.INPUTBY = "";
DataSet ds1 = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, "select SHOWNAME from [user] where GID ='" + strUserID.Trim() + "'");
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
TempOpSeaeEdiEntity.INPUTBY = ds1.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim();
}
}
TempOpSeaeEdiEntity.OP = T_ALL_DA.GetStrSQL("SHOWNAME", "select SHOWNAME from [user] where GID='" + strUserID.Trim() + "'");
TempOpSeaeEdiEntity.DOC = T_ALL_DA.GetStrSQL("SHOWNAME", "select SHOWNAME from [user] where GID='" + strUserID.Trim() + "'");
TempOpSeaeEdiEntity.CUSTSERVICE = "";
TempOpSeaeEdiEntity.LANE = "";
TempOpSeaeEdiEntity.SALE = "";
TempOpSeaeEdiEntity.CARRIER = "";
TempOpSeaeEdiEntity.FORWARDER = "";
TempOpSeaeEdiEntity.CUSTOMSER = "";
TempOpSeaeEdiEntity.TRUCKER = "";
TempOpSeaeEdiEntity.INVNO = "";
TempOpSeaeEdiEntity.CARGOID = "";
TempOpSeaeEdiEntity.DCLASS = "";
TempOpSeaeEdiEntity.DUNNO = "";
TempOpSeaeEdiEntity.REEFERF = "";
TempOpSeaeEdiEntity.TEMPID = "";
TempOpSeaeEdiEntity.TEMPSET = "";
TempOpSeaeEdiEntity.TEMPMAX = "";
TempOpSeaeEdiEntity.TEMPMIN = "";
TempOpSeaeEdiEntity.BSSOURCE = "";
TempOpSeaeEdiEntity.BSSOURCEDETAIL = "";
TempOpSeaeEdiEntity.CUSTOMSNUM = 0;
TempOpSeaeEdiEntity.CONTRACTNO = "";
TempOpSeaeEdiEntity.ORDTYPE = "";
TempOpSeaeEdiEntity.ORDERNO = "";
TempOpSeaeEdiEntity.INSURANCEER = "";
TempOpSeaeEdiEntity.INSURANCENO = "";
TempOpSeaeEdiEntity.INAMOUT = 0;
TempOpSeaeEdiEntity.ISVOU = false;
TempOpSeaeEdiEntity.VOUNO = "";
TempOpSeaeEdiEntity.REMARK = "";
TempOpSeaeEdiEntity.STATUS1 = false;
TempOpSeaeEdiEntity.STATUS2 = false;
TempOpSeaeEdiEntity.STATUS3 = false;
TempOpSeaeEdiEntity.STATUS4 = false;
TempOpSeaeEdiEntity.STATUS5 = false;
TempOpSeaeEdiEntity.ISFUMIGATION = false;
TempOpSeaeEdiEntity.ISSTORAGE = false;
TempOpSeaeEdiEntity.ISLAND = false;
TempOpSeaeEdiEntity.ISCUSTOMS = false;
TempOpSeaeEdiEntity.ISINSPECTION = false;
TempOpSeaeEdiEntity.ISBOOKING = false;
TempOpSeaeEdiEntity.ISAGENT = false;
TempOpSeaeEdiEntity.ISHBLNO = false;
TempOpSeaeEdiEntity.SERVICE9 = false;
TempOpSeaeEdiEntity.SERVICE10 = false;
TempOpSeaeEdiEntity.ISFUMIGATION = false;
TempOpSeaeEdiEntity.ISSTORAGE = false;
TempOpSeaeEdiEntity.ISLAND = false;
TempOpSeaeEdiEntity.ISCUSTOMS = false;
TempOpSeaeEdiEntity.ISINSPECTION = false;
TempOpSeaeEdiEntity.ISBOOKING = false;
TempOpSeaeEdiEntity.ISAGENT = false;
TempOpSeaeEdiEntity.ISHBLNO = false;
TempOpSeaeEdiEntity.PACKINGTYPE = "";
TempOpSeaeEdiEntity.WAREHOUSE = "";
TempOpSeaeEdiEntity.CORPID = "";
TempOpSeaeEdiEntity.SALEDEPT = "";
TempOpSeaeEdiEntity.MBLFRT = "";
TempOpSeaeEdiEntity.OPERATOR = "";
TempOpSeaeEdiEntity.OPERATORTEL = "";
TempOpSeaeEdiEntity.OPERATORFAX = "";
TempOpSeaeEdiEntity.OPERATOREMAIL = "";
TempOpSeaeEdiEntity.FINANCIALSTAFF = "";
TempOpSeaeEdiEntity.FINANCIALSTAFFTEL = "";
TempOpSeaeEdiEntity.FINANCIALSTAFFFAX = "";
TempOpSeaeEdiEntity.FINANCIALSTAFFEMAIL = "";
TempOpSeaeEdiEntity.OPERATORCODE = "";
TempOpSeaeEdiEntity.FINANCIALSTAFFCODE = "";
}
protected void btEDI_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)
{
this.hdDOCGID.Value = "";
Response.Write("<script>alert('请选择要导入的数据文件!');history.back();</script>");
return;
}
//
string s2 = Server.MapPath(Request.Path.ToString());
int i2 = s2.LastIndexOf("DSWeb", s2.Length);
if (FileUpload1.HasFile) //如果用户确实选择了上传控件的浏览按钮,浏览文件成功.
{
int i = FileUpload1.FileName.IndexOf(".", 0, FileUpload1.FileName.Length);
string sFileType = FileUpload1.FileName.Substring(i + 1, FileUpload1.FileName.Length - (i + 1));
if (sFileType != "txt")
{
Response.Write("<script>alert('选择的文件类型不正确,只能为*.txt');history.back();</script>");
return;
}
else
{
ArrayList alCTN = new ArrayList();
string strCTNALL = "";//表现形式
string strCTNALL2 = "";
string strDOCGID="";
string sPath = s2.Substring(0, i2 + 5).ToString() + "\\Temp\\" + FileUpload1.FileName;
this.FileUpload1.SaveAs(sPath); //保存到服务器的目录,需要根据服务器具体情况修改FileUpload1.FileName会自动获取上传文件名.
//
if (sFileType == "txt")
{
string[] strDataRow = File.ReadAllLines(sPath, Encoding.GetEncoding("GB2312"));
for (int j = 0; j < strDataRow.Length; j++)
{
try
{
strDataRow[j] = strDataRow[j].ToString().Trim().Replace("\\n", "\r\n");
strDataRow[j] = strDataRow[j].ToString().Trim().Replace("'", "");
if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("STMF"))
{
TempOpSeaeEdiEntity.DOCGID = strDataRow[j].ToString().Substring(14, 24).Trim();
this.hdDOCGID.Value = TempOpSeaeEdiEntity.DOCGID.Trim();
strDOCGID = TempOpSeaeEdiEntity.DOCGID.Trim();
bool bll = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "delete from temp_op_seae_edi where DOCGID='" + TempOpSeaeEdiEntity.DOCGID.Trim() + "'");
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("ENMF"))
{
break;
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("STBL"))
{
getNULL();
alCTN.Clear();
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("ENBL"))
{
string alt = strDataRow[j].ToString().Trim();
alt = T_ALL_DA.GetStrSQL("MBLNO", "select MBLNO from temp_op_seae_edi where MBLNO='" + TempOpSeaeEdiEntity.MBLNO.Trim() + "' and DOCGID='" + TempOpSeaeEdiEntity.DOCGID.Trim() + "'");
if (alt.Trim() == "")
{
alt = T_ALL_DA.GetStrSQL("GID", "select GID from temp_op_seae_edi where GID='" + TempOpSeaeEdiEntity.GID.Trim() + "'");
if (alt.Trim() != "")
{
TempOpSeaeEdiEntity.GID = getBSNO();
TempOpSeaeEdiEntity.BSNO = TempOpSeaeEdiEntity.GID;
}
int iResult = TempOpSeaeEdiDA.InserInfo(TempOpSeaeEdiEntity);
if (iResult > 0)
{
//减去已入库的集装箱的剩余的
for (int b = 0; b < alCTN.Count; b++)
{
string stral = alCTN[b].ToString();
strCTNALL = stral.Substring(0, 4);
string strSIZE = stral.Substring(0, 2);
string strCTN = stral.Substring(2, 2);
int ils = int.Parse(stral.Substring(5));
for (int a = 0; a < ils; a++)
{
TopCtnEntity.CNTRNO = "";//箱号
TopCtnEntity.CTNALL = strCTNALL;//表现形式
TopCtnEntity.SIZE = strSIZE;//尺寸
TopCtnEntity.CTN = strCTN;//箱型
TopCtnEntity.SEALNO = "";//封号
TopCtnEntity.CTNCODE = "";//箱型代码
TopCtnEntity.CTNNUM = 1;//箱量
TopCtnEntity.KGS = 0;//重量
TopCtnEntity.CBM = 0;//尺码
TopCtnEntity.TEU = TopCtnEntity.CTNNUM;//TEU
if (int.Parse(strSIZE) >= 40)
{
TopCtnEntity.TEU = 2;//TEU
}
TopCtnEntity.CTN_ID = Guid.NewGuid().ToString();
TopCtnEntity.BSNO = TempOpSeaeEdiEntity.BSNO;
TopCtnEntity.PKGS = 0;
TopCtnEntity.REMARK = "";
//
iResult = TopCtnDA.InserInfo(TopCtnEntity);
if (iResult > 0)
{
}
else
{
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "insert into [temp_op_seae_edi](DOCGID,ISOK,CAUSE,BSNO,MBLNO) values('" + TempOpSeaeEdiEntity.DOCGID.Trim() + "','False','数据格式不匹配,导入失败!','" + TempOpSeaeEdiEntity.BSNO.Trim() + "','" + TempOpSeaeEdiEntity.MBLNO.Trim() + "')");
}
}
}
//------
//Response.Write("<script>alert('数据导入成功!');history.back();</script>");
//return;
}
else
{
bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "insert into [temp_op_seae_edi](DOCGID,ISOK,CAUSE,BSNO,MBLNO) values('" + TempOpSeaeEdiEntity.DOCGID.Trim() + "','False','数据格式不匹配,导入失败!','" + TempOpSeaeEdiEntity.BSNO.Trim() + "','" + TempOpSeaeEdiEntity.MBLNO.Trim() + "')");
bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "delete from [op_ctn] where BSNO='" + TempOpSeaeEdiEntity.BSNO.Trim() + "'");
//Response.Write("<script>alert('数据格式不匹配,导入失败!');history.back();</script>");
//return;
}
}
else
{
bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "delete from [op_ctn] where BSNO='" + TempOpSeaeEdiEntity.BSNO.Trim() + "'");
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("BLNO"))
{
TempOpSeaeEdiEntity.MBLNO = strDataRow[j].ToString().Substring(4, 16).Trim();
if (strDataRow[j].ToString().Substring(4, 16).Trim() == "")
{
TempOpSeaeEdiEntity.ISOK = false;
TempOpSeaeEdiEntity.CAUSE = "数据库没有匹配的提单号";
}
else
{
TempOpSeaeEdiEntity.MBLNO = strDataRow[j].ToString().Substring(4, 16).Trim();
DataSet ds1 = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, "select * from [op_seae] where MBLNO ='" + TempOpSeaeEdiEntity.MBLNO.Trim() + "'");
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
if (ds1.Tables[0].Rows[0]["BSSTATUS"].ToString().Trim().Equals("True"))
{
TempOpSeaeEdiEntity.ISOK = false;
TempOpSeaeEdiEntity.CAUSE = "业务锁定状态";
}
else
{
TempOpSeaeEdiEntity.ISOK = true;
}
TempOpSeaeEdiEntity.GID = ds1.Tables[0].Rows[0]["BSNO"].ToString().Trim();
TempOpSeaeEdiEntity.BSNO = ds1.Tables[0].Rows[0]["BSNO"].ToString().Trim();
TempOpSeaeEdiEntity.ORDERTYPE = "EDI导入";
}
else
{
TempOpSeaeEdiEntity.ISOK = true;
}
}
else
{
TempOpSeaeEdiEntity.ISOK = true;
}
}
//
bool bl2 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "delete from op_ctn where BSNO='" + TempOpSeaeEdiEntity.BSNO.Trim() + "'");
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("BKNO"))
{
TempOpSeaeEdiEntity.ORDERNO = strDataRow[j].ToString().Substring(4).Trim();//订舱编号
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("SHIP"))
{
/*
TempOpSeaeEdiEntity.SHIPPERID = strDataRow[j].ToString().Substring(4, 10).Trim();//发货人
string ss = strDataRow[j].ToString().Substring(14).Trim();//发货人
ss = ss.Trim().Replace("\\n", "\r\n");
TempOpSeaeEdiEntity.SHIPPER = ss.Trim();//发货人
*/
TempOpSeaeEdiEntity.SHIPPER = strDataRow[j].ToString().Substring(14).Trim();//发货人
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("CONS"))
{
/*
TempOpSeaeEdiEntity.CONSIGNEEID = strDataRow[j].ToString().Substring(4, 10).Trim();//收货人
string ss = strDataRow[j].ToString().Substring(14).Trim();//收货人
ss = ss.Trim().Replace("\\n", "\r\n");
TempOpSeaeEdiEntity.CONSIGNEE = ss.Trim();//收货人
*/
TempOpSeaeEdiEntity.CONSIGNEE = strDataRow[j].ToString().Substring(14).Trim();//收货人
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("NOTI"))
{
/*
TempOpSeaeEdiEntity.NOTIFYPARTYID = strDataRow[j].ToString().Substring(4, 10).Trim();//通知人
string ss = strDataRow[j].ToString().Substring(14).Trim();//通知人
ss = ss.Trim().Replace("\\n", "\r\n");
TempOpSeaeEdiEntity.NOTIFYPARTY = ss.Trim();//通知人
*/
TempOpSeaeEdiEntity.NOTIFYPARTY = strDataRow[j].ToString().Substring(14).Trim();//通知人
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("VESL"))//船名航次
{
TempOpSeaeEdiEntity.VOYNO = strDataRow[j].ToString().Substring(9,11).Trim().Replace(" ","");//航次
TempOpSeaeEdiEntity.VESSEL = strDataRow[j].ToString().Substring(20).Trim();//船名
string cm = strDataRow[j].ToString().Substring(20).Trim();
if(cm.IndexOf(" ")>0)
{
TempOpSeaeEdiEntity.VESSEL = strDataRow[j].ToString().Substring(20,cm.IndexOf(" ")).Trim();//船名
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("PLRT"))//目的地
{
TempOpSeaeEdiEntity.DESTINATIONID = strDataRow[j].ToString().Substring(4, 5).Trim();//目的地
TempOpSeaeEdiEntity.DESTINATION = strDataRow[j].ToString().Substring(9).Trim();//目的地
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("POLD"))//装货港
{
TempOpSeaeEdiEntity.PORTLOADID = strDataRow[j].ToString().Substring(4, 5).Trim();//装货港代码
TempOpSeaeEdiEntity.PORTLOAD = strDataRow[j].ToString().Substring(9).Trim();//装货港
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("PODC"))//卸货港
{
TempOpSeaeEdiEntity.PORTDISCHARGEID = strDataRow[j].ToString().Substring(4, 5).Trim();//卸货港代码
TempOpSeaeEdiEntity.PORTDISCHARGE = strDataRow[j].ToString().Substring(9).Trim();//卸货港
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("PLDL"))//交货地
{
TempOpSeaeEdiEntity.PLACEDELIVERYID = strDataRow[j].ToString().Substring(4, 5).Trim();//交货地代码
TempOpSeaeEdiEntity.PLACEDELIVERY = strDataRow[j].ToString().Substring(9).Trim();//交货地
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("CRTM"))//运输条款
{
TempOpSeaeEdiEntity.SERVICE = strDataRow[j].ToString().Substring(6).Trim();//运输条款
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("FLFG"))//装运方式
{
if (strDataRow[j].ToString().Substring(4, 1).Trim().Equals("F"))
{
TempOpSeaeEdiEntity.BLTYPE = "整箱";//装运方式
}
else if (strDataRow[j].ToString().Substring(4, 1).Trim().Equals("L"))
{
TempOpSeaeEdiEntity.BLTYPE = "拼箱";//装运方式
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("SOCF"))//货物标识
{
TempOpSeaeEdiEntity.CARGOID = strDataRow[j].ToString().Substring(4, 1).Trim();//货物标识
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("DGFL"))//危险品分类/等级
{
TempOpSeaeEdiEntity.DCLASS = strDataRow[j].ToString().Substring(4, 1).Trim();//危险品分类/等级
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("MARK"))//唛头
{
TempOpSeaeEdiEntity.MARKS = strDataRow[j].ToString().Substring(4).Trim();//唛头
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("DESC"))//货物描述
{
TempOpSeaeEdiEntity.DESCRIPTION = strDataRow[j].ToString().Substring(4).Trim();//货物描述
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("GWGT"))//毛重
{
if (strDataRow[j].ToString().Substring(4).Trim() != "")
{
TempOpSeaeEdiEntity.KGS = Decimal.Parse(Decimal.Parse(strDataRow[j].ToString().Substring(4).Trim()).ToString("F2"));//毛重
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("GMSR"))//尺码
{
if (strDataRow[j].ToString().Substring(4).Trim() != "")
{
TempOpSeaeEdiEntity.CBM = Decimal.Parse(Decimal.Parse(strDataRow[j].ToString().Substring(4).Trim()).ToString("F2"));//尺码
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("SAYD"))//件数大写
{
TempOpSeaeEdiEntity.TOTALNO = strDataRow[j].ToString().Substring(4).Trim();//件数大写
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("FRTM"))//付费方式
{
TempOpSeaeEdiEntity.BLFRT = strDataRow[j].ToString().Substring(6).Trim();//付费方式
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("PKGS"))//NOPKGS 件数包装 循环
{
TempOpSeaeEdiEntity.NOPKGS += strDataRow[j].ToString().Substring(4, 5).Trim() + strDataRow[j].ToString().Substring(11).Trim() + "\r\n";//件数+包装的循环
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("REFR"))//温度
{
TempOpSeaeEdiEntity.TEMPSET = strDataRow[j].ToString().Substring(4, 5).Trim();//设置温度
TempOpSeaeEdiEntity.TEMPID = strDataRow[j].ToString().Substring(9, 1).Trim();//温度单位
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("FRPP"))//预付地点
{
TempOpSeaeEdiEntity.PREPARDAT = strDataRow[j].ToString().Substring(4).Trim();//预付地点
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("FRPY"))//到付地点
{
TempOpSeaeEdiEntity.PAYABLEAT = strDataRow[j].ToString().Substring(4).Trim();//到付地点
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("POIS"))//签单地点
{
TempOpSeaeEdiEntity.ISSUEPLACE = strDataRow[j].ToString().Substring(4).Trim();//签单地点
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("OBLN"))//提单份数
{
string strOBLN = strDataRow[j].ToString().Substring(6).Trim();//提单份数
int iOBLN = strOBLN.IndexOf("(");
if (iOBLN > -1)
{
TempOpSeaeEdiEntity.NOBILL = strOBLN.Trim().Substring(0,iOBLN).Trim();//提单份数
}
else
{
TempOpSeaeEdiEntity.NOBILL = strOBLN.Trim();//提单份数
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("DOIS"))//签单日期
{
if (strDataRow[j].ToString().Substring(4).Trim() != "")
{
TempOpSeaeEdiEntity.ISSUEDATE = DateTime.Parse(strDataRow[j].ToString().Substring(4, 4).Trim() + "-" + strDataRow[j].ToString().Substring(8, 2).Trim() + "-" + strDataRow[j].ToString().Substring(10, 2).Trim());//签单日期
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("ONBD"))//开船日期
{
if (strDataRow[j].ToString().Substring(4).Trim() != "")
{
TempOpSeaeEdiEntity.ETD = DateTime.Parse(strDataRow[j].ToString().Substring(4, 4).Trim() + "-" + strDataRow[j].ToString().Substring(8, 2).Trim() + "-" + strDataRow[j].ToString().Substring(10, 2).Trim());//开船日期
TempOpSeaeEdiEntity.ACCDATE = strDataRow[j].ToString().Substring(4, 4).Trim() + "-" + strDataRow[j].ToString().Substring(8, 2).Trim();
}
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("CQTY"))//CNTRTOTAL 集装箱全部内容 循环
{
strCTNALL = strDataRow[j].ToString().Substring(4, 4).Trim();//表现形式
strCTNALL2 = T_ALL_DA.GetStrSQL("CTN", "select CTN from [code_ctn] where EDICODE='" + strCTNALL.Trim() + "'");
if (strCTNALL2.Trim() != "")
{
strCTNALL = strCTNALL2.Trim();
}
TempOpSeaeEdiEntity.CNTRTOTAL += strCTNALL.Trim() + "*" + strDataRow[j].ToString().Substring(8).Trim() + " / ";//CNTRTOTAL 集装箱全部内容的循环
alCTN.Add(strCTNALL.Trim() + "*" + strDataRow[j].ToString().Substring(8).Trim());
}
else if (strDataRow[j].ToString().Trim().Substring(0, 4).Equals("CNTR"))//集装箱循环
{
TopCtnEntity.CNTRNO = strDataRow[j].ToString().Substring(7, 11).Trim();//箱号
//
strCTNALL =strDataRow[j].ToString().Substring(18, 4).Trim();//表现形式
strCTNALL2 = T_ALL_DA.GetStrSQL("CTN","select CTN from [code_ctn] where EDICODE='"+strCTNALL.Trim()+"'");
if(strCTNALL2.Trim()!="")
{
strCTNALL=strCTNALL2.Trim();
}
TopCtnEntity.CTNALL = strCTNALL.Trim();
TopCtnEntity.SIZE = strCTNALL.Trim().Substring(0, 2);//strDataRow[j].ToString().Substring(18, 2).Trim();//尺寸
//
TopCtnEntity.CTN = strDataRow[j].ToString().Substring(20, 2).Trim();//箱型
TopCtnEntity.SEALNO = strDataRow[j].ToString().Substring(22, 21).Trim();//封号
TopCtnEntity.CTNCODE = "";
TopCtnEntity.CTNNUM = 1;
TopCtnEntity.KGS = Decimal.Parse(Decimal.Parse(strDataRow[j].ToString().Substring(52, 10).Trim()).ToString("F2"));//重量
TopCtnEntity.CBM = Decimal.Parse(Decimal.Parse(strDataRow[j].ToString().Substring(62, 10).Trim()).ToString("F2"));//尺码
TopCtnEntity.TEU = TopCtnEntity.CTNNUM;//TEU
if (int.Parse(strDataRow[j].ToString().Substring(18, 2).Trim()) >= 40)
{
TopCtnEntity.TEU = TopCtnEntity.CTNNUM * 2;//TEU
}
TopCtnEntity.CTN_ID = Guid.NewGuid().ToString();
TopCtnEntity.BSNO = TempOpSeaeEdiEntity.BSNO;
TopCtnEntity.PKGS = int.Parse(strDataRow[j].ToString().Substring(45, 5).Trim());//件数//strDataRow[j].ToString().Substring(43, 2).Trim();//件数包装
TopCtnEntity.REMARK = "";
//
int iResult = TopCtnDA.InserInfo(TopCtnEntity);
if (iResult > 0)
{
//减去已入库的集装箱
for (int c = 0; c < alCTN.Count; c++)
{
string stral = alCTN[c].ToString();
int ils = stral.IndexOf("*");
string strls = stral.Substring(0, ils);
strCTNALL = strDataRow[j].ToString().Substring(18, 4).Trim();//表现形式
strCTNALL2 = T_ALL_DA.GetStrSQL("CTN", "select CTN from [code_ctn] where EDICODE='" + strCTNALL.Trim() + "'");
if (strCTNALL2.Trim() != "")
{
strCTNALL = strCTNALL2.Trim();
}
if (strCTNALL.Equals(strls))
{
ils = int.Parse(stral.Substring(ils+1))-1;
if (ils > 0)
{
alCTN[c] = strls + "*" + ils;
}
else
{
alCTN[c] = strls + "*0";
}
}
}
//------
}
else
{
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "insert into [temp_op_seae_edi](DOCGID,ISOK,CAUSE,BSNO,MBLNO) values('" + TempOpSeaeEdiEntity.DOCGID.Trim() + "','False','数据格式不匹配,导入失败!','" + TempOpSeaeEdiEntity.BSNO.Trim() + "','" + TempOpSeaeEdiEntity.MBLNO.Trim() + "')");
}
}
}
catch (Exception)
{
string strCAUSE = strDataRow[j].ToString().Trim();
string alt = "";
alt = T_ALL_DA.GetStrSQL("MBLNO", "select MBLNO from temp_op_seae_edi where MBLNO='" + TempOpSeaeEdiEntity.MBLNO.Trim() + "' and DOCGID='" + TempOpSeaeEdiEntity.DOCGID.Trim() + "'");
if (alt.Trim() == "")
{
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "insert into [temp_op_seae_edi](DOCGID,ISOK,CAUSE,BSNO,MBLNO) values('" + TempOpSeaeEdiEntity.DOCGID.Trim() + "','False','"+strCAUSE+"数据格式不匹配,导入失败!','" + TempOpSeaeEdiEntity.BSNO.Trim() + "','" + TempOpSeaeEdiEntity.MBLNO.Trim() + "')");
bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "delete from [op_ctn] where BSNO='" + TempOpSeaeEdiEntity.BSNO.Trim() + "'");
}
//throw execError;
}
/*
//
int iResult = TempOpSeaeEdiDA.InserInfo(TempOpSeaeEdiEntity);
if (iResult > 0)
{
Response.Write("<script>alert('数据导入成功!');history.back();</script>");
return;
}
else
{
Response.Write("<script>alert('数据格式不匹配,导入失败!');history.back();</script>");
return;
}
*/
}
}
File.Delete(sPath);
//导入op_seae委托
int iRt = 0;
IList<TopSeaeEntity> TopSeaeEntities = new List<TopSeaeEntity>();
IList<TempOpSeaeEdiEntity> TempOpSeaeEdiEntities = TempOpSeaeEdiDA.GetByGroupID(strDOCGID);
if (TempOpSeaeEdiEntities.Count <= 0)
{
Response.Write("<script>alert('数据格式不匹配,导入失败!');history.back();</script>");
return;
}
foreach (TempOpSeaeEdiEntity TempOpSeaeEdiEntity in TempOpSeaeEdiEntities)
{
if (TempOpSeaeEdiEntity.GID != null)
{
TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
//
#region
TopSeaeEntity.BSNO = "";
TopSeaeEntity.MASTERNO = "";
TopSeaeEntity.BSSTATUS = false;
TopSeaeEntity.FEESTATUS = false;
TopSeaeEntity.ORDERTYPE = "EDI导入";
//TopSeaeEntity.BSDATE = DateTime.Today.Date;
TopSeaeEntity.PlACERECEIPTID = "";//收货地
TopSeaeEntity.ACCDATE = "";
TopSeaeEntity.MBLNO = "";
TopSeaeEntity.TRANSNO = "";
TopSeaeEntity.CUSTOMERNAME = "";
TopSeaeEntity.BLTYPE = "";
TopSeaeEntity.STLNAME = "";
TopSeaeEntity.SHIPPERID = "";
TopSeaeEntity.CONSIGNEEID = "";
TopSeaeEntity.NOTIFYPARTYID = "";
TopSeaeEntity.SHIPPER = "";
TopSeaeEntity.CONSIGNEE = "";
TopSeaeEntity.NOTIFYPARTY = "";
TopSeaeEntity.AGENTID = "";
TopSeaeEntity.AGENT = "";
TopSeaeEntity.YARD = "";
TopSeaeEntity.VESSEL = "";
TopSeaeEntity.VOYNO = "";
TopSeaeEntity.PlACERECEIPT = "";
TopSeaeEntity.PORTLOADID = "";
TopSeaeEntity.PORTLOAD = "";
TopSeaeEntity.PORTDISCHARGEID = "";
TopSeaeEntity.PORTDISCHARGE = "";
TopSeaeEntity.PLACEDELIVERYID = "";
TopSeaeEntity.PLACEDELIVERY = "";
TopSeaeEntity.DESTINATIONID = "";
TopSeaeEntity.DESTINATION = "";
TopSeaeEntity.NOBILL = "";
TopSeaeEntity.ISSUETYPE = "";
TopSeaeEntity.ISSUEPLACE = "";
TopSeaeEntity.BLFRT = "";
TopSeaeEntity.PREPARDAT = "";
TopSeaeEntity.PAYABLEAT = "";
TopSeaeEntity.SERVICE = "";
TopSeaeEntity.MARKS = "";
TopSeaeEntity.CNTRSEALNO = "";
TopSeaeEntity.NOPKGS = "";
TopSeaeEntity.DESCRIPTION = "";
TopSeaeEntity.GOODSNAME = "";
TopSeaeEntity.GROSSWEIGHT = "";
TopSeaeEntity.MEASUREMENT = "";
TopSeaeEntity.PKGS = 0;
TopSeaeEntity.KINDPKGS = "";
TopSeaeEntity.KGS = 0;
TopSeaeEntity.CBM = 0;
TopSeaeEntity.TOTALNO = "";
TopSeaeEntity.CNTRNO = "";
TopSeaeEntity.CNTR1 = 0;
TopSeaeEntity.CNTR2 = 0;
TopSeaeEntity.CNTR3 = 0;
TopSeaeEntity.CNTR4 = 0;
TopSeaeEntity.CNTR5 = 0;
TopSeaeEntity.CNTR6 = 0;
TopSeaeEntity.CNTR7 = 0;
TopSeaeEntity.CNTR8 = 0;
TopSeaeEntity.CNTR9 = 0;
TopSeaeEntity.CNTR10 = 0;
TopSeaeEntity.OTCNTR = 0;
TopSeaeEntity.TEU = 0;
TopSeaeEntity.INPUTBY = "";
DataSet ds1 = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, "select SHOWNAME from [user] where GID ='" + strUserID.Trim() + "'");
if (ds1 != null)
{
if (ds1.Tables[0].Rows.Count > 0)
{
TopSeaeEntity.INPUTBY = ds1.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim();
}
}
TopSeaeEntity.OP=T_ALL_DA.GetStrSQL("SHOWNAME","select SHOWNAME from [user] where GID='"+strUserID.Trim()+"'");
TopSeaeEntity.DOC=T_ALL_DA.GetStrSQL("SHOWNAME","select SHOWNAME from [user] where GID='"+strUserID.Trim()+"'");
TopSeaeEntity.CUSTSERVICE = "";
TopSeaeEntity.LANE = "";
TopSeaeEntity.SALE = "";
TopSeaeEntity.CARRIER = "";
TopSeaeEntity.FORWARDER = "";
TopSeaeEntity.CUSTOMSER = "";
TopSeaeEntity.TRUCKER = "";
TopSeaeEntity.INVNO = "";
TopSeaeEntity.CARGOID = "";
TopSeaeEntity.DCLASS = "";
TopSeaeEntity.DUNNO = "";
TopSeaeEntity.REEFERF = "";
TopSeaeEntity.TEMPID = "";
TopSeaeEntity.TEMPSET = "";
TopSeaeEntity.TEMPMAX = "";
TopSeaeEntity.TEMPMIN = "";
TopSeaeEntity.BSSOURCE = "";
TopSeaeEntity.BSSOURCEDETAIL = "";
TopSeaeEntity.CUSTOMSNUM = 0;
TopSeaeEntity.CONTRACTNO = "";
TopSeaeEntity.ORDTYPE = "";
TopSeaeEntity.ORDERNO = "";
TopSeaeEntity.INSURANCEER = "";
TopSeaeEntity.INSURANCENO = "";
TopSeaeEntity.INAMOUT = 0;
TopSeaeEntity.ISVOU = false;
TopSeaeEntity.VOUNO = "";
TopSeaeEntity.REMARK = "";
TopSeaeEntity.STATUS1 = false;
TopSeaeEntity.STATUS2 = false;
TopSeaeEntity.STATUS3 = false;
TopSeaeEntity.STATUS4 = false;
TopSeaeEntity.STATUS5 = false;
TopSeaeEntity.ISFUMIGATION = false;
TopSeaeEntity.ISSTORAGE = false;
TopSeaeEntity.ISLAND = false;
TopSeaeEntity.ISCUSTOMS = false;
TopSeaeEntity.ISINSPECTION = false;
TopSeaeEntity.ISBOOKING = false;
TopSeaeEntity.ISAGENT = false;
TopSeaeEntity.ISHBLNO = false;
TopSeaeEntity.SERVICE9 = false;
TopSeaeEntity.SERVICE10 = false;
TopSeaeEntity.ISFUMIGATION = false;
TopSeaeEntity.ISSTORAGE = false;
TopSeaeEntity.ISLAND = false;
TopSeaeEntity.ISCUSTOMS = false;
TopSeaeEntity.ISINSPECTION = false;
TopSeaeEntity.ISBOOKING = false;
TopSeaeEntity.ISAGENT = false;
TopSeaeEntity.ISHBLNO = false;
TopSeaeEntity.PACKINGTYPE = "";
TopSeaeEntity.WAREHOUSE = "";
TopSeaeEntity.CORPID = T_ALL_DA.GetStrSQL("COMPANYID", "select COMPANYID from [user_company] where USERID='" + strUserID.Trim() + "'");
TopSeaeEntity.SALEDEPT = T_ALL_DA.GetStrSQL("DEPTNAME", "select DEPTNAME from user_baseinfo where USERID='" + strUserID.Trim() + "'");
TopSeaeEntity.MBLFRT = "";
TopSeaeEntity.OPERATOR = "";
TopSeaeEntity.OPERATORTEL = "";
TopSeaeEntity.OPERATORFAX = "";
TopSeaeEntity.OPERATOREMAIL = "";
TopSeaeEntity.FINANCIALSTAFF = "";
TopSeaeEntity.FINANCIALSTAFFTEL = "";
TopSeaeEntity.FINANCIALSTAFFFAX = "";
TopSeaeEntity.FINANCIALSTAFFEMAIL = "";
TopSeaeEntity.OPERATORCODE = "";
TopSeaeEntity.FINANCIALSTAFFCODE = "";
//
TopSeaeEntity.BSNO = TempOpSeaeEdiEntity.BSNO;
TopSeaeEntity.MASTERNO = TempOpSeaeEdiEntity.BSNO;
TopSeaeEntity.MBLNO = TempOpSeaeEdiEntity.MBLNO;//提单号
TopSeaeEntity.ORDERNO = TempOpSeaeEdiEntity.ORDERNO; //订舱编号
TopSeaeEntity.SHIPPERID = TempOpSeaeEdiEntity.SHIPPERID; //发货人
TopSeaeEntity.SHIPPER = TempOpSeaeEdiEntity.SHIPPER; //发货人
TopSeaeEntity.CONSIGNEEID = TempOpSeaeEdiEntity.CONSIGNEEID; //收货人
TopSeaeEntity.CONSIGNEE = TempOpSeaeEdiEntity.CONSIGNEE; //收货人
TopSeaeEntity.NOTIFYPARTYID = TempOpSeaeEdiEntity.NOTIFYPARTYID; //通知人
TopSeaeEntity.NOTIFYPARTY = TempOpSeaeEdiEntity.NOTIFYPARTY; //通知人
TopSeaeEntity.VOYNO = TempOpSeaeEdiEntity.VOYNO; //航次
TopSeaeEntity.VESSEL = TempOpSeaeEdiEntity.VESSEL; //船名
TopSeaeEntity.DESTINATIONID = TempOpSeaeEdiEntity.DESTINATIONID; //目的地
TopSeaeEntity.DESTINATION = TempOpSeaeEdiEntity.DESTINATION; //目的地
TopSeaeEntity.PORTLOADID = TempOpSeaeEdiEntity.PORTLOADID; //装货港代码
TopSeaeEntity.PORTLOAD = TempOpSeaeEdiEntity.PORTLOAD; //装货港
TopSeaeEntity.PORTDISCHARGEID = TempOpSeaeEdiEntity.PORTDISCHARGEID; //卸货港代码
TopSeaeEntity.PORTDISCHARGE = TempOpSeaeEdiEntity.PORTDISCHARGE; //卸货港
TopSeaeEntity.PLACEDELIVERYID = TempOpSeaeEdiEntity.PLACEDELIVERYID; //交货地代码
TopSeaeEntity.PLACEDELIVERY = TempOpSeaeEdiEntity.PLACEDELIVERY; //交货地
TopSeaeEntity.SERVICE = TempOpSeaeEdiEntity.SERVICE; //运输条款
TopSeaeEntity.BLTYPE = TempOpSeaeEdiEntity.BLTYPE; //装运方式
TopSeaeEntity.CARGOID = TempOpSeaeEdiEntity.CARGOID; //货物标识
TopSeaeEntity.DCLASS = TempOpSeaeEdiEntity.DCLASS; //危险品分类/等级
TopSeaeEntity.MARKS = TempOpSeaeEdiEntity.MARKS; //唛头
TopSeaeEntity.DESCRIPTION = TempOpSeaeEdiEntity.DESCRIPTION; //货物描述
TopSeaeEntity.KGS = TempOpSeaeEdiEntity.KGS; //毛重
TopSeaeEntity.GROSSWEIGHT = TempOpSeaeEdiEntity.KGS.ToString().Trim(); //货物毛重
TopSeaeEntity.CBM = TempOpSeaeEdiEntity.CBM; //尺码
TopSeaeEntity.MEASUREMENT = TempOpSeaeEdiEntity.CBM.ToString().Trim(); //货物尺码
TopSeaeEntity.TOTALNO = TempOpSeaeEdiEntity.TOTALNO; //件数大写
TopSeaeEntity.BLFRT = TempOpSeaeEdiEntity.BLFRT; //付费方式
TopSeaeEntity.NOPKGS = TempOpSeaeEdiEntity.NOPKGS; //件数+包装的循环
TopSeaeEntity.PKGS = getPKGS(TempOpSeaeEdiEntity.NOPKGS); //件数
TopSeaeEntity.KINDPKGS = getKINDPKGS(TempOpSeaeEdiEntity.NOPKGS);//包装
TopSeaeEntity.CNTRNO = ""; //集装箱大写
if (TempOpSeaeEdiEntity.CNTRTOTAL.ToString().Trim().Equals(""))
{
TopSeaeEntity.CNTRTOTAL = ""; //集装箱全部内容
}
else
{
TopSeaeEntity.CNTRTOTAL = TempOpSeaeEdiEntity.CNTRTOTAL.ToString().Trim().Substring(0, TempOpSeaeEdiEntity.CNTRTOTAL.ToString().Trim().Length-2); //集装箱全部内容
}
TopSeaeEntity.TEMPSET = TempOpSeaeEdiEntity.TEMPSET; //设置温度
TopSeaeEntity.TEMPID = TempOpSeaeEdiEntity.TEMPID; //温度单位
TopSeaeEntity.PREPARDAT = TempOpSeaeEdiEntity.PREPARDAT; //预付地点
TopSeaeEntity.PAYABLEAT = TempOpSeaeEdiEntity.PAYABLEAT; //到付地点
TopSeaeEntity.ISSUEPLACE = TempOpSeaeEdiEntity.ISSUEPLACE; //签单地点
TopSeaeEntity.NOBILL = TempOpSeaeEdiEntity.NOBILL; //提单份数
TopSeaeEntity.ISSUEDATE = TempOpSeaeEdiEntity.ISSUEDATE; //签单日期
TopSeaeEntity.ETD = TempOpSeaeEdiEntity.ETD; //开船日期
TopSeaeEntity.ACCDATE = TempOpSeaeEdiEntity.ACCDATE;//会计期间
//TopSeaeEntity.HBLNO = getCodeRule("分提单号", "HBLNO", TopSeaeEntity.ETD.ToString().Trim(), TopSeaeEntity.ACCDATE.ToString().Trim());//调用编码规则
//TopSeaeEntity.CUSTNO = getCodeRule("委托编号", "CUSTNO", TopSeaeEntity.ETD.ToString().Trim(), TopSeaeEntity.ACCDATE.ToString().Trim());//调用编码规则
TopSeaeEntity.HBLNO = "";
TopSeaeEntity.CUSTNO = "";
#endregion
TopSeaeEntities.Add(TopSeaeEntity);
}
}
iRt = SeaExportInfoDA.InsertTopSeaesEDI(TopSeaeEntities, strCompanyID);
if (iRt > 0)
{
foreach (TempOpSeaeEdiEntity TempOpSeaeEdiEntity in TempOpSeaeEdiEntities)
{
if (TempOpSeaeEdiEntity.GID != null)
{
string strCNTRTOTAL = "";
string strCNTRNO = "";
//
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, "update [op_seae] set CNTR1=0,CNTR2=0,CNTR3=0,CNTR4=0,CNTR5=0,CNTR6=0,CNTR7=0,CNTR8=0,CNTR9=0,CNTR10=0,OTCNTR=0,TEU=0,CNTRTOTAL='',CNTRSEALNO='' where BSNO='" + TempOpSeaeEdiEntity.BSNO.Trim() + "'");
//
IList<TopCtnEntity> TopCtnEntities = TopCtnDA.GetID(TempOpSeaeEdiEntity.BSNO);
if (TopCtnEntities.Count > 0)
{
foreach (TopCtnEntity TopCtnEntity in TopCtnEntities)
{
if (TopCtnEntity.CTN_ID != null)
{
string alt = "";
//
strCTNALL = TopCtnEntity.CTNALL.ToString().Trim();//表现形式
strCTNALL2 = T_ALL_DA.GetStrSQL("CTN", "select CTN from [code_ctn] where EDICODE='" + strCTNALL.Trim() + "'");
if (strCTNALL2.Trim() != "")
{
strCTNALL = strCTNALL2.Trim();
}
//
alt = T_ALL_DA.setEDICTN(TopCtnEntity.BSNO, strUserID.Trim(), strCTNALL.Trim(), TopCtnEntity.CTNNUM, TopCtnEntity.CTN_ID, TopCtnEntity.REMARK, TopCtnEntity.CNTRNO, TopCtnEntity.SEALNO);
strCNTRTOTAL += strCTNALL.Trim() + "*" + TopCtnEntity.CTNNUM.ToString().Trim() + " / ";
strCNTRNO += TopCtnEntity.CNTRNO.ToString().Trim() + "/" + TopCtnEntity.SEALNO.ToString().Trim() + "/" + strCTNALL.Trim() + "\r\n";//"/" + myRow["PKGS"].ToString().Trim() + "PKGS/" + myRow["KGS"].ToString().Trim() + "KGS/" + myRow["CBM"].ToString().Trim() + "CBM
}
}
//
strCNTRTOTAL = strCNTRTOTAL.Trim().Substring(0, strCNTRTOTAL.Trim().Length - 1);
CrmSeaeorderDA CrmSeaeorderDA = new CrmSeaeorderDA();
int iii = CrmSeaeorderDA.UpdateInfoCNTRTOTAL("update op_seae set CNTRTOTAL='" + strCNTRTOTAL + "',CNTRSEALNO='" + strCNTRNO + "' where BSNO='" + TempOpSeaeEdiEntity.GID.ToString().Trim() + "'", strUserID.Trim());
}
}
}
//
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>ShowDetailFresh();</script>");
//Response.Write("<script>alert('数据导入完成!');history.back();</script>");
return;
}
else
{
Response.Write("<script>alert('数据格式不匹配,导入失败!');history.back();</script>");
return;
}
}
}
//
//this.isEDI.Value = "1";
//
}
/// <summary>
/// 提取规则编号
/// </summary>
/// <param name="strRULENAME">规则项目名称</param>
/// <param name="strfield">需要加规则的字段</param>
/// <returns></returns>
protected String getCodeRule(string strRULENAME, string strfield, string strETD, string strACCDATE)
{
//调用编码规则
string strRULEYEAR = "";
string strRULECONTENT = "";
string strCODENAME = "";
string strDEPTNO = "";
string strRULENOLENGTH = "";
int iRULENOLENGTH = 0;
int inum = 0;
string strCONTENT = "";
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='" + strRULENAME.Trim() + "' and RULETYPE=1");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["ISSTARTUSING"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("业务日期"))
{
if (strETD.Trim() == "")
{
return "";
}
DateTime dETD = System.Convert.ToDateTime(strETD.Trim());
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy") + dETD.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dETD.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dETD.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("会计期间"))
{
if (strACCDATE.Trim() == "")
{
return "";
}
DateTime dACCDATE = System.Convert.ToDateTime(strACCDATE.Trim() + "-01");
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dACCDATE.ToString("yyyy") + dACCDATE.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dACCDATE.ToString("yy") + dACCDATE.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = dACCDATE.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = dACCDATE.ToString("yy");
}
}
}
else if (ds.Tables[0].Rows[0]["RULEDATE"].ToString().Trim().Equals("自然月份"))
{
DateTime fwqdate = System.Convert.ToDateTime(T_ALL_DA.GetStrSQL("fwqdate", "select fwqdate=getdate()"));
if (ds.Tables[0].Rows[0]["ISCLEAREDINEARLY"].ToString().Trim().Equals("True"))
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy") + fwqdate.ToString("MM");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy") + fwqdate.ToString("MM");
}
}
else
{
if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "4")
{
strRULEYEAR = fwqdate.ToString("yyyy");
}
else if (ds.Tables[0].Rows[0]["RULEYEAR"].ToString().Trim() == "2")
{
strRULEYEAR = fwqdate.ToString("yy");
}
}
}
//
if (ds.Tables[0].Rows[0]["ISCOMPANY"].ToString().Trim().Equals("True"))
{
strCODENAME = T_ALL_DA.GetStrSQL("CODENAME", "select CODENAME from [company] where GID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')");
}
if (ds.Tables[0].Rows[0]["ISDEPT"].ToString().Trim().Equals("True"))
{
strDEPTNO = T_ALL_DA.GetStrSQL("DEPTNO", "select DEPTNO from [sys_dept] where LINKID=(select top 1 COMPANYID from user_company where USERID='" + strUserID.Trim() + "')");
}
strRULECONTENT = ds.Tables[0].Rows[0]["RULECONTENT"].ToString().Trim();
strRULECONTENT = strRULECONTENT.Replace("《COMPANY》", strCODENAME);
strRULECONTENT = strRULECONTENT.Replace("《DEPT》", strDEPTNO);
//
iRULENOLENGTH = int.Parse(ds.Tables[0].Rows[0]["RULENOLENGTH"].ToString().Trim());
strCONTENT = strRULECONTENT + strRULEYEAR;
//获取分公司的票号头字符
string tempBANKSHEAD = T_ALL_DA.GetStrSQL("BANKSHEAD", "SELECT TOP 1 BANKSHEAD FROM company WHERE GID='" + strCompanyID.Trim() + "'");
strCONTENT = tempBANKSHEAD + strCONTENT;
//
strRULENOLENGTH = T_ALL_DA.GetStrSQL(strfield, "select top 1 " + strfield + " from [op_seae] where " + strfield + " like '" + strCONTENT.Trim() + "%' order by " + strfield + " DESC");
if (strRULENOLENGTH == "")
{
strRULENOLENGTH = "1";
}
else
{
strRULENOLENGTH = strRULENOLENGTH.Replace(strCONTENT.Trim(), "");
inum = int.Parse(strRULENOLENGTH.Trim());
inum = inum + 1;
strRULENOLENGTH = inum.ToString();
}
int j = iRULENOLENGTH - strRULENOLENGTH.Length;
for (int i = 1; i <= j; i++)
{
strRULENOLENGTH = "0" + strRULENOLENGTH;
}
//
strCONTENT = strCONTENT + strRULENOLENGTH;
return strCONTENT;
}
}
}
return "";
}
private int getPKGS(string strNOPKGS)
{
var iums = 0;
if (strNOPKGS != null && strNOPKGS != "")
{
string[] items= strNOPKGS.Split(new string[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);//这里是以换行符作为分界
string[] ii = new String[items.Length];
if (items != null && items.Length > 0)
{
for (var i = 0; i < items.Length; i++)
{
for (var j = 0; j < items[i].Length;j++ )
{
var s = items[i].Trim().Substring(0, j+1);
var tf = IsNumeric(s);
if (tf)
{
ii[i] = s;
}
else
{
break;
}
}
iums += int.Parse(ii[i]);
}
}
}
return iums;
//$("tbPKGS").value = iums.toString();
}
private String getKINDPKGS(string strNOPKGS)
{
var sums = "";
if (strNOPKGS != null && strNOPKGS != "")
{
string[] items = strNOPKGS.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);//这里是以换行符作为分界
string[] ss = new String[items.Length];
if (items != null && items.Length > 0)
{
for (var i = 0; i < items.Length; i++)
{
for (var j = 0; j < items[i].Length; j++)
{
var s = items[i].Trim().Substring(0, j + 1);
var tf = IsNumeric(s);
if (tf)
{
ss[i] = "";
}
else
{
ss[i] = items[i].Trim().Substring(j).ToUpper();
break;
}
}
}
}
for (var k = 0; k < ss.Length; k++)
{
if (ss.Length == 1)
{
sums = ss[k].ToString().Trim().ToUpper();
break;
}
if (ss[k] == ss[ss.Length - 1])
{
sums = ss[k].ToString().Trim().ToUpper();
}
else
{
sums = "PACKAGES";
break;
}
}
}
return sums;
//$("hd_comboKINDPKGS").value = sums;
}
public bool IsNumeric(string s)
{
bool bReturn = true;
try
{
int inum = int.Parse(s);
}
catch
{
//int inum = 0;
bReturn = false;
}
return bReturn;
}
#region Grid参数
private void SaveColumnSetting(string tempColumnVal)
{
JsonColumnGroupEntity jsonColumnGroupEntity = GetPostEntity(tempColumnVal);
List<JsonColumnEntity> jsonColumnEntities = new List<JsonColumnEntity>();
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = userSettingDA.GetUserSettingByUserIDType(strUserID, strType);
if (userSettingEntity.GID != null)
{
userSettingEntity.ModifiedUser = strUserID;
GridEntity gridEntity = null;
List<GridColumnEntity> gridColumnEntities = new List<GridColumnEntity>();
gridEntity = GetSettingXml(userSettingEntity.Xml);
gridEntity.PagePreCount = jsonColumnGroupEntity.ShowCount;
foreach (JsonColumnEntity jColumn in jsonColumnGroupEntity.JsonColumnEntities)
{
foreach (GridColumnEntity gColumn in gridEntity.Columns)
{
if (gColumn.Description.Equals(jColumn.col3))
{
gColumn.Description = jColumn.col3;
gColumn.Width = jColumn.col5;
gColumn.Index = jColumn.col4;
if (jColumn.col6 != -1)
{
gColumn.VisibleState = jColumn.col6;
}
//gridColumnEntities.Add(gColumn);
break;
}
}
}
//Columns
//gridEntity.Columns = gridColumnEntities;
userSettingEntity.Xml = SaveUserSetting(gridEntity).OuterXml;
int iResult = userSettingDA.UpdateUserSetting(userSettingEntity);
}
else
{
if (jsonColumnGroupEntity != null)
{
userSettingEntity = new UserSettingEntity();
userSettingEntity.GID = Guid.NewGuid().ToString();
userSettingEntity.Name = "EDIListGridSetting";
userSettingEntity.Description = "EDI批量导入Grid设置";
userSettingEntity.UserID = strUserID;
userSettingEntity.Type = 1;//type值为1表示Grid
string strRequestUrl = Request.Url.ToString();
string strUrl = strRequestUrl.Substring(0, strRequestUrl.LastIndexOf("/"));
string strPage = strRequestUrl.Substring(strRequestUrl.LastIndexOf("/") + 1, strRequestUrl.Length - strRequestUrl.LastIndexOf("/") - 1);
userSettingEntity.Url = strUrl;
userSettingEntity.Page = strPage;
userSettingEntity.CreateUser = strUserID;
GridEntity gridEntity = new GridEntity();
gridEntity.GID = userSettingEntity.GID;
gridEntity.UserID = strUserID;
gridEntity.GroupBy = "";
gridEntity.DefaultPrePageCount = 15;
gridEntity.PagePreCount = jsonColumnGroupEntity.ShowCount;
List<GridColumnEntity> gridColumnEntities = new List<GridColumnEntity>();
foreach (JsonColumnEntity column in jsonColumnGroupEntity.JsonColumnEntities)
{
GridColumnEntity gridColumnEntity = new GridColumnEntity();
if (column.col6 != -1)
{
gridColumnEntity.Name = column.col2;
gridColumnEntity.VisibleState = column.col6;
}
else
{
switch (column.col3.Trim())
{
case "导入结果":
gridColumnEntity.Name = "sISOK";
break;
case "提单号":
gridColumnEntity.Name = "MBLNO";
break;
case "船名":
gridColumnEntity.Name = "VESSEL";
break;
case "航次":
gridColumnEntity.Name = "VOYNO";
break;
case "启运港":
gridColumnEntity.Name = "PORTLOAD";
break;
case "目的港":
gridColumnEntity.Name = "PORTDISCHARGE";
break;
case "件数":
gridColumnEntity.Name = "PKGS";
break;
case "包装":
gridColumnEntity.Name = "CARRIER";
break;
case "重量":
gridColumnEntity.Name = "KGS";
break;
case "尺码":
gridColumnEntity.Name = "CBM";
break;
}
gridColumnEntity.VisibleState = 0;
}
gridColumnEntity.Description = column.col3;
gridColumnEntity.Index = column.col4;
gridColumnEntity.Width = column.col5;
gridColumnEntities.Add(gridColumnEntity);
}
//Columns
gridEntity.Columns = gridColumnEntities;
userSettingEntity.Xml = SaveUserSetting(gridEntity).OuterXml;
int iResult = userSettingDA.InsertUserSetting(userSettingEntity);
dvSaveState.InnerHtml = iResult.ToString();
}
}
}
#region 获取列信息
/// <summary>
/// 获取列信息
/// </summary>
/// <param name="tempValue"></param>
/// <returns></returns>
private JsonColumnGroupEntity GetPostEntity(string tempValue)
{
JsonColumnGroupEntity tempColumnGroupEntity = new JsonColumnGroupEntity();
try
{
tempColumnGroupEntity = (JsonColumnGroupEntity)JSON.Instance.ToObject(tempValue);
}
catch (Exception error)
{
throw error;
}
return tempColumnGroupEntity;
}
#endregion
private XmlDocument SaveUserSetting(GridEntity gridEntity)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("user-settings");
//xmlDoc.AppendChild(root);
XmlElement xGid = xmlDoc.CreateElement("gid");
xGid.InnerText = gridEntity.GID;
root.AppendChild(xGid);
XmlElement xUserID = xmlDoc.CreateElement("userid");
xUserID.InnerText = gridEntity.UserID;
root.AppendChild(xUserID);
XmlElement xCreateTime = xmlDoc.CreateElement("create-time");
xCreateTime.InnerText = gridEntity.CreateTime.ToString();
root.AppendChild(xCreateTime);
XmlElement xColumns = xmlDoc.CreateElement("columns");
foreach (GridColumnEntity column in gridEntity.Columns)
{
XmlElement xColumn = xmlDoc.CreateElement("column");
XmlElement nName = xmlDoc.CreateElement("name");
nName.InnerText = column.Name;
xColumn.AppendChild(nName);
XmlElement nDescription = xmlDoc.CreateElement("description");
nDescription.InnerText = column.Description;
xColumn.AppendChild(nDescription);
XmlElement nIndex = xmlDoc.CreateElement("index");
nIndex.InnerText = column.Index.ToString();
xColumn.AppendChild(nIndex);
XmlElement nWidth = xmlDoc.CreateElement("width");
nWidth.InnerText = column.Width.ToString();
xColumn.AppendChild(nWidth);
XmlElement nVisible = xmlDoc.CreateElement("visible");
nVisible.InnerText = column.VisibleState.ToString();
xColumn.AppendChild(nVisible);
xColumns.AppendChild(xColumn);
}
root.AppendChild(xColumns);
XmlElement xGroupBy = xmlDoc.CreateElement("group-by");
xGroupBy.InnerText = gridEntity.GroupBy;
root.AppendChild(xGroupBy);
XmlElement xPage = xmlDoc.CreateElement("page");
XmlElement nPageDefault = xmlDoc.CreateElement("page-default");
nPageDefault.InnerText = gridEntity.DefaultPrePageCount.ToString();
xPage.AppendChild(nPageDefault);
XmlElement nPagePre = xmlDoc.CreateElement("page-pre");
nPagePre.InnerText = gridEntity.PagePreCount.ToString();
xPage.AppendChild(nPagePre);
root.AppendChild(xPage);
xmlDoc.AppendChild(root);
return xmlDoc;
}
private GridEntity GetSettingXml(string strXml)
{
XmlDocument xmlSettingDoc = new XmlDocument();
GridEntity gridEntity = new GridEntity();
try
{
xmlSettingDoc.LoadXml(strXml);
gridEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[0].InnerText.Trim();
gridEntity.UserID = xmlSettingDoc.ChildNodes[0].ChildNodes[1].InnerText.Trim();
gridEntity.CreateTime = DateTime.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[2].InnerText.Trim());
IList<GridColumnEntity> columnsEntities = new List<GridColumnEntity>();
int iColCount = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes.Count;
for (int i = 0; i < iColCount; i++)
{
GridColumnEntity columnEntity = new GridColumnEntity();
//columnEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[0].ToString();
columnEntity.Name = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[0].InnerText.Trim();
columnEntity.Description = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[1].InnerText.Trim();
columnEntity.Index = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[2].InnerText.Trim());
columnEntity.Width = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[3].InnerText.Trim());
columnsEntities.Add(columnEntity);
}
gridEntity.Columns = columnsEntities;
gridEntity.GroupBy = xmlSettingDoc.ChildNodes[0].ChildNodes[4].InnerText.Trim();
gridEntity.DefaultPrePageCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[0].InnerText.Trim());
gridEntity.PagePreCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[1].InnerText.Trim());
}
catch (Exception error)
{
throw (error);
}
return gridEntity;
}
public enum SqlName
{
NAME = 0,
LOGTYPE = 1,
LOGTIME = 2,
LOGCONTENT = 3,
USERNAME = 4
}
#endregion
}
}