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.
D7QUANTAI/DSWeb/EDI/NpsesaEDIExport.aspx.cs

544 lines
26 KiB
C#

10 months ago
using System;
using System.Collections;
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.Xml.Linq;
using System.IO;
using System.Xml;
using DSWeb.EntityDA;
using DSWeb.Models;
using JsonHelper;
namespace DSWeb.EDI
{
public partial class NpsesaEDIExport : System.Web.UI.Page
{
public string strGIDS;//
public string strBSNO;//
public string strUserID;//登录用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (this.hdExport.Value != "")
{
setXML();
setExcelReport();
return;
}
//
if (!IsPostBack)
{
if (Request.QueryString["id"] != null && Request.QueryString["id"].ToString().Trim() != "") //if (Request.QueryString["id"] != null)
{
strBSNO = Request.QueryString["id"].ToString().Trim();
this.hdBSNO.Value = strBSNO;
}
//
if (Request.QueryString["ids"] != null && Request.QueryString["ids"].ToString().Trim() != "") //if (Request.QueryString["id"] != null)
{
strGIDS = Request.QueryString["ids"].ToString().Trim();
this.hdGIDS.Value = strGIDS;
}
//
if (Request.QueryString["ishbl"] != null && Request.QueryString["ishbl"].ToString().Trim() != "") //if (Request.QueryString["id"] != null)
{
this.hdISHBL.Value = Request.QueryString["ishbl"].ToString().Trim();
}
//
if (this.hdISHBL.Value.Trim() == "0")
{
rblTYPE.Items[2].Enabled = false;
}
else
{
rblTYPE.Items[2].Selected = true;
}
//
getXML();
}
}
protected void getXML()
{
string OppPath = "xml";
string xmlPath = Server.MapPath(OppPath);
string xmlName = "Npsesa.xml";
//
if (File.Exists(xmlPath + "//" + xmlName)) //判断文件是否寸在
{
//存在的情况下
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlPath + "//" + xmlName);
//更新文件
XmlNode roots = xmldoc.SelectSingleNode("History");//获取History节点的所有子节点
foreach (XmlNode root in roots)//遍历所有子节点
{
XmlElement xe = (XmlElement)root;//将子节点类型转换为XmlElement类型
if (xe.GetAttribute("companyid").ToString().Trim() == strCompanyID.Trim())//如果id属性值为“strCompanyID.Trim()”
{
XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode baks in bakss)//遍历
{
XmlElement bak = (XmlElement)baks;//转换类型
if (bak.Name == "SENDERCODE")//如果找到
{
tbSENDERCODE.Text = bak.InnerText.Trim();//发送方代码
}
else if (bak.Name == "RECEIVERCODE")//接收方代码
{
tbRECEIVERCODE.Text = bak.InnerText.Trim();
}
else if (bak.Name == "ISSUEPARTYCODE")//订舱人代码
{
tbISSUEPARTYCODE.Text = bak.InnerText.Trim();
}
else if (bak.Name == "FILEFUNCTION")//文件功能
{
rblFILEFUNCTION.SelectedValue = bak.InnerText.ToString().Trim();
}
//else if (bak.Name == "BOOKINGNOID")//订舱号标识
//{
// rblBOOKINGNOID.SelectedValue = bak.InnerText.ToString().Trim();
//}
//else if (bak.Name == "TEMPERATUREID")//温度计量单位
//{
// rblTEMPERATUREID.SelectedValue = bak.InnerText.ToString().Trim();
//}
//else if (bak.Name == "EquipmentSupplierTypeCode")//集装箱(器)来源代码
//{
// rblEquipmentSupplierTypeCode.SelectedValue = bak.InnerText.ToString().Trim();
//}
}
break;
}
}
}
}
protected void setXML()
{
string OppPath = "xml";
string xmlPath = Server.MapPath(OppPath);
string xmlName = "Npsesa.xml";
//
if (File.Exists(xmlPath + "//" + xmlName)) //判断文件是否寸在
{
//更新文件
updateXML(xmlPath,xmlName);
}
else
{
//创建文件
createXML(xmlPath, xmlName);
}
}
protected void updateXML(string xmlPath,string xmlName)
{
int bz = 0;
//插入
//存在的情况下
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlPath + "//" + xmlName);
//更新文件
XmlNode roots = xmldoc.SelectSingleNode("History");//获取History节点的所有子节点
foreach (XmlNode root in roots)//遍历所有子节点
{
XmlElement xe = (XmlElement)root;//将子节点类型转换为XmlElement类型
if (xe.GetAttribute("companyid").ToString().Trim() == strCompanyID.Trim())//如果id属性值为“strCompanyID.Trim()”
{
bz = 1;
XmlNodeList bakss = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode baks in bakss)//遍历
{
XmlElement bak = (XmlElement)baks;//转换类型
if (bak.Name == "SENDERCODE")//如果找到
{
bak.InnerText = tbSENDERCODE.Text.Trim();//发送方代码
}
else if (bak.Name == "RECEIVERCODE")//接收方代码
{
bak.InnerText = tbRECEIVERCODE.Text.Trim();
}
else if (bak.Name == "ISSUEPARTYCODE")//订舱人代码
{
bak.InnerText = tbISSUEPARTYCODE.Text.Trim();
}
else if (bak.Name == "FILEFUNCTION")//文件功能
{
bak.InnerText = rblFILEFUNCTION.SelectedValue.ToString().Trim();
}
//else if (bak.Name == "BOOKINGNOID")//订舱号标识
//{
// bak.InnerText = rblBOOKINGNOID.SelectedValue.ToString().Trim();
//}
//else if (bak.Name == "TEMPERATUREID")//温度计量单位
//{
// bak.InnerText = rblTEMPERATUREID.SelectedValue.ToString().Trim();
//}
//else if (bak.Name == "EquipmentSupplierTypeCode")//集装箱(器)来源代码
//{
// bak.InnerText = rblEquipmentSupplierTypeCode.SelectedValue.ToString().Trim();
//}
}
break;
}
}
//
if (bz == 0)
{
insertXML(xmlPath, xmlName);
}
else
{
xmldoc.Save(xmlPath + "//" + xmlName);
}
}
protected void createXML(string xmlPath, string xmlName)
{
Directory.CreateDirectory(xmlPath);//创建该文件
XmlDocument xmldoc = new XmlDocument();
XmlNode xmlnode = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.AppendChild(xmlnode);
XmlElement root = xmldoc.CreateElement("History");
xmldoc.AppendChild(root);
XmlElement bak = xmldoc.CreateElement("Bak");
bak.SetAttribute("companyid", strCompanyID.Trim());
root.AppendChild(bak);
XmlElement SENDERCODE = xmldoc.CreateElement("SENDERCODE");
SENDERCODE.InnerText = tbSENDERCODE.Text.Trim();
bak.AppendChild(SENDERCODE); //发送方代码
XmlElement RECEIVERCODE = xmldoc.CreateElement("RECEIVERCODE");
RECEIVERCODE.InnerText = tbRECEIVERCODE.Text.Trim();
bak.AppendChild(RECEIVERCODE); //接收方代码
XmlElement ISSUEPARTYCODE = xmldoc.CreateElement("ISSUEPARTYCODE");
ISSUEPARTYCODE.InnerText = tbISSUEPARTYCODE.Text.Trim();
bak.AppendChild(ISSUEPARTYCODE); //订舱人代码
XmlElement FILEFUNCTION = xmldoc.CreateElement("FILEFUNCTION");
FILEFUNCTION.InnerText = rblFILEFUNCTION.SelectedValue.ToString().Trim();
bak.AppendChild(FILEFUNCTION); // 文件功能
//XmlElement BOOKINGNOID = xmldoc.CreateElement("BOOKINGNOID");
//BOOKINGNOID.InnerText = rblBOOKINGNOID.SelectedValue.ToString().Trim();
//bak.AppendChild(BOOKINGNOID); //订舱号标识
//XmlElement TEMPERATUREID = xmldoc.CreateElement("TEMPERATUREID");
//TEMPERATUREID.InnerText = rblTEMPERATUREID.SelectedValue.ToString().Trim();
//bak.AppendChild(TEMPERATUREID); //温度计量单位
//XmlElement EquipmentSupplierTypeCode = xmldoc.CreateElement("EquipmentSupplierTypeCode");
//EquipmentSupplierTypeCode.InnerText = rblEquipmentSupplierTypeCode.SelectedValue.ToString().Trim();
//bak.AppendChild(EquipmentSupplierTypeCode); //集装箱(器)来源代码
xmldoc.Save(xmlPath + "//" + xmlName);
}
protected void insertXML(string xmlPath, string xmlName)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlPath + "\\" + xmlName);
//存在文件
XmlNode root = xmldoc.SelectSingleNode("History");
XmlElement bak = xmldoc.CreateElement("Bak");
bak.SetAttribute("companyid", strCompanyID.Trim());
root.AppendChild(bak);
XmlElement SENDERCODE = xmldoc.CreateElement("SENDERCODE");
SENDERCODE.InnerText = tbSENDERCODE.Text.Trim();
bak.AppendChild(SENDERCODE); //发送方代码
XmlElement RECEIVERCODE = xmldoc.CreateElement("RECEIVERCODE");
RECEIVERCODE.InnerText = tbRECEIVERCODE.Text.Trim();
bak.AppendChild(RECEIVERCODE); //接收方代码
XmlElement ISSUEPARTYCODE = xmldoc.CreateElement("ISSUEPARTYCODE");
ISSUEPARTYCODE.InnerText = tbISSUEPARTYCODE.Text.Trim();
bak.AppendChild(ISSUEPARTYCODE); //订舱人代码
XmlElement FILEFUNCTION = xmldoc.CreateElement("FILEFUNCTION");
FILEFUNCTION.InnerText = rblFILEFUNCTION.SelectedValue.ToString().Trim();
bak.AppendChild(FILEFUNCTION); // 文件功能
//XmlElement BOOKINGNOID = xmldoc.CreateElement("BOOKINGNOID");
//BOOKINGNOID.InnerText = rblBOOKINGNOID.SelectedValue.ToString().Trim();
//bak.AppendChild(BOOKINGNOID); //订舱号标识
//XmlElement TEMPERATUREID = xmldoc.CreateElement("TEMPERATUREID");
//TEMPERATUREID.InnerText = rblTEMPERATUREID.SelectedValue.ToString().Trim();
//bak.AppendChild(TEMPERATUREID); //温度计量单位
//XmlElement EquipmentSupplierTypeCode = xmldoc.CreateElement("EquipmentSupplierTypeCode");
//EquipmentSupplierTypeCode.InnerText = rblEquipmentSupplierTypeCode.SelectedValue.ToString().Trim();
//bak.AppendChild(EquipmentSupplierTypeCode); //集装箱(器)来源代码
xmldoc.Save(xmlPath + "//" + xmlName);
}
protected void setExcelReport()
{
EDIExportDA EDIExportDA = new EDIExportDA();
//
string alt = "";
string sMBLNO = "";
string[] itmGIDS = this.hdGIDS.Value.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (this.hdISHBL.Value.Trim() == "0")//整箱
{
for (int i = 0; i < itmGIDS.Length; i++)
{
SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA();
TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
TopSeaeEntity = SeaExportInfoDA.GetID(itmGIDS[i].ToString().Trim());
sMBLNO = TopSeaeEntity.VESSEL.ToString().Trim()+"_"+TopSeaeEntity.VOYNO.ToString().Trim();
if (i == 0)
{
//00头记录
alt += EDIExportDA.GetNpsesa00(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbSENDERCODE.Text.Trim(), tbRECEIVERCODE.Text.Trim());
//10船舶信息
alt += EDIExportDA.GetNpsesa10(TopSeaeEntity);
}
//12港口信息
alt += EDIExportDA.GetNpsesa12(TopSeaeEntity);
//14订舱号
alt += EDIExportDA.GetNpsesa14(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbISSUEPARTYCODE.Text.Trim());
//20发货人
alt += EDIExportDA.GetNpsesa20(TopSeaeEntity);
//21收货人
alt += EDIExportDA.GetNpsesa21(TopSeaeEntity);
//22通知人
alt += EDIExportDA.GetNpsesa22(TopSeaeEntity);
//40订舱预配箱
alt += EDIExportDA.GetNpsesa40(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), rblTYPE.SelectedValue.ToString().Trim());
//41订舱货物
alt += EDIExportDA.GetNpsesa41(TopSeaeEntity);
string sdk = TopSeaeEntity.CARGOID.ToString().Trim();
if (TopSeaeEntity.CARGOID.ToString().Trim() != "S")
{
//43危险品,冷藏和超标信息
alt += EDIExportDA.GetNpsesa43(TopSeaeEntity);
}
//44唛头
alt += EDIExportDA.GetNpsesa44(TopSeaeEntity);
//47货物描述
alt += EDIExportDA.GetNpsesa47(TopSeaeEntity);
//
if (rblFILEFUNCTION.SelectedValue.ToString().Trim() == "3")//订舱号标识//货代向船公司订舱时即标记3订舱号标识R1404为F货代向船代订舱时标记9、标记5/4订舱号标识R1404为B
{
}
else
{
//48集装箱细目
alt += EDIExportDA.GetNpsesa48(TopSeaeEntity);
}
//60运费条款
alt += EDIExportDA.GetNpsesa60(TopSeaeEntity);
//71运费条款
alt += EDIExportDA.GetNpsesa71(TopSeaeEntity);
//99尾记录
if (i == itmGIDS.Length-1)
{
string[] itms = alt.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int i99 = itms.Length+1;
alt += EDIExportDA.GetNpsesa99(i99);
}
//
}
}
else
{
if (rblTYPE.SelectedValue.ToString().Trim() == "2")
{
for (int i = 0; i < itmGIDS.Length; i++)
{
TopSeaeBillmanageDA TopSeaeBillmanageDA = new TopSeaeBillmanageDA();
TopSeaeBillmanageEntity TopSeaeBillmanageEntity = new TopSeaeBillmanageEntity();
TopSeaeBillmanageEntity = TopSeaeBillmanageDA.GetID(itmGIDS[i].ToString().Trim());
SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA();
TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
TopSeaeEntity = SeaExportInfoDA.GetID(this.hdBSNO.Value.ToString().Trim());
sMBLNO = TopSeaeEntity.MBLNO.ToString().Trim();
if (i == 0)
{
//00头记录
alt += EDIExportDA.GetNpsesa00(TopSeaeBillmanageEntity, TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbSENDERCODE.Text.Trim(), tbRECEIVERCODE.Text.Trim());
//10船舶信息
alt += EDIExportDA.GetNpsesa10(TopSeaeBillmanageEntity, TopSeaeEntity);
}
//12港口信息
alt += EDIExportDA.GetNpsesa12(TopSeaeEntity);
//14订舱号
alt += EDIExportDA.GetNpsesa14(TopSeaeBillmanageEntity, TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbISSUEPARTYCODE.Text.Trim());
//20发货人
alt += EDIExportDA.GetNpsesa20(TopSeaeBillmanageEntity);
//21收货人
alt += EDIExportDA.GetNpsesa21(TopSeaeBillmanageEntity);
//22通知人
alt += EDIExportDA.GetNpsesa22(TopSeaeBillmanageEntity);
//40订舱预配箱
alt += EDIExportDA.GetNpsesa40(TopSeaeBillmanageEntity, TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), rblTYPE.SelectedValue.ToString().Trim());
//41订舱货物
alt += EDIExportDA.GetNpsesa41(TopSeaeEntity);
string sdk = TopSeaeEntity.CARGOID.ToString().Trim();
if (TopSeaeEntity.CARGOID.ToString().Trim() != "S")
{
//43危险品,冷藏和超标信息
alt += EDIExportDA.GetNpsesa43(TopSeaeEntity);
}
//44唛头
alt += EDIExportDA.GetNpsesa44(TopSeaeBillmanageEntity);
//47货物描述
alt += EDIExportDA.GetNpsesa47(TopSeaeBillmanageEntity);
//
if (rblFILEFUNCTION.SelectedValue.ToString().Trim() == "3")//订舱号标识//货代向船公司订舱时即标记3订舱号标识R1404为F货代向船代订舱时标记9、标记5/4订舱号标识R1404为B
{
}
else
{
//48集装箱细目
alt += EDIExportDA.GetNpsesa48(TopSeaeEntity);
}
//60运费条款
alt += EDIExportDA.GetNpsesa60(TopSeaeEntity);
//71运费条款
alt += EDIExportDA.GetNpsesa71(TopSeaeBillmanageEntity, TopSeaeEntity);
//99尾记录
if (i == itmGIDS.Length-1)
{
string[] itms = alt.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int i99 = itms.Length+1;
alt += EDIExportDA.GetNpsesa99(i99);
}
//
}
}
else
{
SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA();
TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
TopSeaeEntity = SeaExportInfoDA.GetID(this.hdBSNO.Value.ToString().Trim());
sMBLNO = TopSeaeEntity.MBLNO.ToString().Trim();
//00头记录
alt += EDIExportDA.GetNpsesa00(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbSENDERCODE.Text.Trim(), tbRECEIVERCODE.Text.Trim());
//10船舶信息
alt += EDIExportDA.GetNpsesa10(TopSeaeEntity);
//12港口信息
alt += EDIExportDA.GetNpsesa12(TopSeaeEntity);
//14订舱号
alt += EDIExportDA.GetNpsesa14(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), tbISSUEPARTYCODE.Text.Trim());
//20发货人
alt += EDIExportDA.GetNpsesa20(TopSeaeEntity);
//21收货人
alt += EDIExportDA.GetNpsesa21(TopSeaeEntity);
//22通知人
alt += EDIExportDA.GetNpsesa22(TopSeaeEntity);
//40订舱预配箱
alt += EDIExportDA.GetNpsesa40(TopSeaeEntity, rblFILEFUNCTION.SelectedValue.ToString().Trim(), rblTYPE.SelectedValue.ToString().Trim());
//41订舱货物
alt += EDIExportDA.GetNpsesa41(TopSeaeEntity);
string sdk = TopSeaeEntity.CARGOID.ToString().Trim();
if (TopSeaeEntity.CARGOID.ToString().Trim() != "S")
{
//43危险品,冷藏和超标信息
alt += EDIExportDA.GetNpsesa43(TopSeaeEntity);
}
//44唛头
alt += EDIExportDA.GetNpsesa44(TopSeaeEntity);
//47货物描述
alt += EDIExportDA.GetNpsesa47(TopSeaeEntity);
//
if (rblFILEFUNCTION.SelectedValue.ToString().Trim() == "3")//订舱号标识//货代向船公司订舱时即标记3订舱号标识R1404为F货代向船代订舱时标记9、标记5/4订舱号标识R1404为B
{
}
else
{
//48集装箱细目
alt += EDIExportDA.GetNpsesa48(TopSeaeEntity);
}
//60运费条款
alt += EDIExportDA.GetNpsesa60(TopSeaeEntity);
//71运费条款
alt += EDIExportDA.GetNpsesa71(TopSeaeEntity);
//99尾记录
string[] itms = alt.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int i99 = itms.Length+1;
alt += EDIExportDA.GetNpsesa99(i99);
//
}
}
//
StringWriter sw = new StringWriter();
sw.WriteLine(alt);
//
sw.Close();
switch ("MUTEXT")
{
case "MUTEXT":
Response.AddHeader("Content-Disposition", "attachment; filename="+sMBLNO+".txt");
Response.ContentType = "application/txt";
break;
case "MUEXCEL":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xls");
Response.ContentType = "application/ms-excel";
break;
case "MUWORD":
Response.AddHeader("Content-Disposition", "attachment; filename=report.doc");
Response.ContentType = "application/ms-word";
break;
case "MUPDF":
Response.AddHeader("Content-Disposition", "attachment; filename=report.pdf");
Response.ContentType = "application/pdf";
break;
case "MUXML":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xml");
Response.ContentType = "application/xml";
break;
}
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
}
//
}
}