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.

901 lines
55 KiB
C#

11 months ago
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Web.Mvc;
using DSWeb.MvcShipping.Models.MsOpApply;
using DSWeb.MvcShipping.Models.MsOpSeaeBill;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using System.IO;
using HcUtility.Core;
using DSWeb.MvcShipping.Models.CompanyDef;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.Models.FtpSet;
using DotNet4.Utilities;
using DSWeb.MvcShipping.DAL.MsCodeYardDataSet;
using InvokeWebService;
using DSWeb.MvcShipping.DAL.YARDCTNXML;
using System.Xml;
using System.Xml.Serialization;
using System.Linq;
using System.Text.RegularExpressions;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
using System.Web;
using System.Drawing;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL;
using DSWeb.MvcShipping.DAL.MsOpApplyDAL;
using DSWeb.Areas.Import.DAL.ReceiptDoc;
using DSWeb.Areas.Import.Models.ImportTrade;
using System.IO.Compression;
using DSWeb.MvcShipping.Helper;
using System.Collections;
namespace DSWeb.MvcShipping.DAL.MsOpApplyEdiPortDAL
{
public class MsOpApplyEdiPortDAL
{
#region EDI导出
#region 易航线 EDI //需求编号SR2017081100003
public static string IsCreateEdiELineEDI(List<MsOpApply> headData, string usercode, string path, string mblno, string filerole, CodeFtpSet ftpset, string type, int isbill, int isnotctn, string carrier, string portdischarge, string recerverop, string filetype, string strCOMPANYID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var error = "";
foreach (var bill in headData)
{
#region 3.1.1报关单业务、备案清单业务委托人信息
if (ftpset.SENDCODE == null || ftpset.SENDCODE == "")
{ error += "<br />易航线EDI的配置信息发送方EDI代码委托平台代码不能为空"; }
if (ftpset.SENDNAME == null || ftpset.SENDNAME == "")
{ error += "<br />易航线EDI的配置信息发送方名称委托平台分配名称不能为空"; }
if (ftpset.SENDSUBCOMPANYCODE == null || ftpset.SENDSUBCOMPANYCODE == "")
{ error += "<br />易航线EDI的配置信息发送方分部代码9位组织机构代码证号不能为空"; }
if (ftpset.SENDCOMPANYCODE == null || ftpset.SENDCOMPANYCODE == "")
{ error += "<br />易航线EDI的配置信息发送方公司代码委托人公司名称不能为空"; }
if (ftpset.SENDATTN == null || ftpset.SENDATTN == "")
{ error += "<br />易航线EDI的配置信息发送方联系人委托人联系人唯一标识不能为空"; }
#endregion
#region 3.1.2报关单业务、备案清单业务基本信息
if (bill.MBLNO == null || bill.MBLNO == "")
{ error += "<br />主提单号 不能为空"; }
if (bill.CUSTNO == null || bill.CUSTNO == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 委托编号(活动委托唯一标示) 不能为空"; }
if (bill.BSTYPE == null || bill.BSTYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运输类型 不能为空"; }
if (bill.EDIYWLX == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 易航线业务类型 不能为空"; }
if (bill.EDIYWLX != 0 && bill.EDIYWLX != 1)
{
if (bill.RECORDSN == null || bill.RECORDSN == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 备案号 不能为空"; }
}
if (bill.VESSEL == null || bill.VESSEL == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 船名 不能为空"; }
if (bill.VOYNO == null || bill.VOYNO == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 航次 不能为空"; }
if (bill.BSTYPE == "1")//出口
{
if (bill.PAYMENT == null || bill.PAYMENT == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 征税比例 不能为空"; }
}
if (bill.TRADETERM == null || bill.TRADETERM == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 贸易条款(成交方式) 不能为空"; }//成交方式CIF,C&F,FOB出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
if (bill.BSTYPE == "1")//出口
{
if (bill.TRADETERM == "0")//CIF
{
//必填项
if (bill.CARRIAGETYPE == null || bill.CARRIAGETYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费类型 不能为空"; }
if (bill.CARRIAGEPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 运费金额 不能为空"; }
if (bill.CARRIAGETYPE != "率")
{
if (bill.CARRIAGECURRENCY == null || bill.CARRIAGECURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费币制 不能为空"; }
}
//必填项
if (bill.PREMIUMTYPE == null || bill.PREMIUMTYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费类型 不能为空"; }
if (bill.PREMIUMPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 保费金额 不能为空"; }
if (bill.PREMIUMTYPE != "率")
{
if (bill.PREMIUMCURRENCY == null || bill.PREMIUMCURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费币制 不能为空"; }
}
}
else if (bill.TRADETERM == "1")//FOB
{
}
else if (bill.TRADETERM == "2")//C&F
{
//必填项
if (bill.CARRIAGETYPE == null || bill.CARRIAGETYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费类型 不能为空"; }
if (bill.CARRIAGEPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 运费金额 不能为空"; }
if (bill.CARRIAGETYPE != "率")
{
if (bill.CARRIAGECURRENCY == null || bill.CARRIAGECURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费币制 不能为空"; }
}
}
else
{
}
}
else if (bill.BSTYPE == "2")//进口
{
if (bill.TRADETERM == "0")//CIF
{
}
else if (bill.TRADETERM == "1")//FOB
{
//必填项
if (bill.CARRIAGETYPE == null || bill.CARRIAGETYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费类型 不能为空"; }
if (bill.CARRIAGEPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 运费金额 不能为空"; }
if (bill.CARRIAGETYPE != "率")
{
if (bill.CARRIAGECURRENCY == null || bill.CARRIAGECURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 运费币制 不能为空"; }
}
//必填项
if (bill.PREMIUMTYPE == null || bill.PREMIUMTYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费类型 不能为空"; }
if (bill.PREMIUMPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 保费金额 不能为空"; }
if (bill.PREMIUMTYPE != "率")
{
if (bill.PREMIUMCURRENCY == null || bill.PREMIUMCURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费币制 不能为空"; }
}
}
else if (bill.TRADETERM == "2")//C&F
{
//必填项
if (bill.PREMIUMTYPE == null || bill.PREMIUMTYPE == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费类型 不能为空"; }
if (bill.PREMIUMPRICE == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 保费金额 不能为空"; }
if (bill.PREMIUMTYPE != "率")
{
if (bill.PREMIUMCURRENCY == null || bill.PREMIUMCURRENCY == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 保费币制 不能为空"; }
}
}
else
{
}
}
#endregion
#region 3.1.3报关单业务商品信息(循环)
List<MsOpApplyDetail> BodyList = MsOpApplyDAL.MsOpApplyDAL.GetBodyList("bsno='" + bill.BSNO.ToString() + "'");
if (BodyList != null)
{
if (BodyList.Count > 0)
{
foreach (var opCtn in BodyList)
{
if (opCtn.SerialNo == null)
{ error += "<br />提单号:" + bill.MBLNO + "的 集装箱商品序号 不能为空"; }
}
}
}
#endregion
#region 3.1.4报关单业务、备案清单业务随附单证信息
List<ReceiptDocmb> rdList = ReceiptDocDAL.GetDocList("bsno='" + bill.BSNO.ToString() + "' and RECEIPTTYPE like '易航线_单证'");
if (BodyList != null)
{
if (BodyList.Count > 0)
{
foreach (var opFuJian in rdList)
{
if (opFuJian.DOCUMENTATTACHEDNO == null || opFuJian.DOCUMENTATTACHEDNO == "")
{ error += "<br />提单号:" + bill.MBLNO + "的 单证附件的随附单证编号 不能为空"; }
}
}
}
#endregion
}
return error;
}
public static string CreateEdiELineESI(List<MsOpApply> headData, string usercode, string path, string mblno, string filerole, CodeFtpSet ftpset, string type, int isbill, int isnotctn, string carrier, string portdischarge, string recerverop, string filetype, string strCOMPANYID)
{
string filename = path + "\\" + mblno + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
FileStream f = new FileStream(filename, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.UTF8);//.Default
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var bill in headData)
{
r.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
r.WriteLine("<message>");
#region 3.1.1报关单业务、备案清单业务委托人信息
r.WriteLine("<messageHead>");
r.WriteLine("<token>tokenCeShi</token>");//令牌必填b5ed4dc769ef2be
r.WriteLine("<clientPlatformCode>" + ftpset.SENDCODE + "</clientPlatformCode>");//委托平台代码必填发送方代码1000120000
r.WriteLine("<clientPlatformName>" + ftpset.SENDNAME + "</clientPlatformName>");//委托平台分配名称,必填,发送方名称,金科信,易航线测试
r.WriteLine("<clientCompanyCode>" + ftpset.SENDSUBCOMPANYCODE + "</clientCompanyCode>");//9位组织机构代码证号必填发送方分部代码demotest
r.WriteLine("<clientCompanyName>" + ftpset.SENDCOMPANYCODE + "</clientCompanyName>");//委托人公司名称,必填,发送方公司代码,测试账号,易航线测试
r.WriteLine("<clientUser>" + ftpset.SENDATTN + "</clientUser>");//委托人联系人唯一标识必填发送方联系人demoyhxtest
r.WriteLine("</messageHead>");
#endregion
r.WriteLine("<messageBody>");
#region 3.1.2报关单业务、备案清单业务基本信息
r.WriteLine("<taskId>" + bill.CUSTNO + "</taskId>");//活动委托唯一标示必填100
if (bill.BSTYPE == "1")
{
r.WriteLine("<importExportFlag>E</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
}
else if (bill.BSTYPE == "2")
{
r.WriteLine("<importExportFlag>I</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
}
r.WriteLine("<type>"+bill.EDIYWLX+"</type>");//业务类型 (0/1/2/3/4/5) 注:0代表一般出口业务;1代表一般进口业务;2代表出口备案手册业务;3代表进口备案手册业务;4出境清单业务;5进境清单业务必填//0
r.WriteLine("<declearLocation>" + bill.BYCUSTOM + "</declearLocation>");//申报地海关//青岛大港
r.WriteLine("<custom>" + bill.PORTLOAD + "</custom>");//出口口岸//青岛大港
if (bill.EDIYWLX == 0 || bill.EDIYWLX == 1)
{
r.WriteLine("<recordSn></recordSn>");//备案号Type=0||1时该字段不填写其他必须填写
}
else
{
r.WriteLine("<recordSn>" + bill.RECORDSN + "</recordSn>");//备案号Type=0||1时该字段不填写其他必须填写必填
}
r.WriteLine("<contract>" + bill.CONTRACTNO + "</contract>");//合同协议号//111222333444555666777
r.WriteLine("<company></company>");//10位收发货人编号//1111112222
r.WriteLine("<companySocialCode></companySocialCode>");//18位收发货人编号//111111222211111111//w
r.WriteLine("<companyName>" + bill.CUSTOMERNAME + "</companyName>");//收发货人名称//青岛公司
r.WriteLine("<company2></company2>");//10位生产销售单位编号1111112222
r.WriteLine("<company2SocialCode>" + bill.ENTERPID + "</company2SocialCode>");//18位生产销售单位编号111111222211111111
r.WriteLine("<company2Name>" + bill.ENTERP + "</company2Name>");//生产销售单位名称//青岛公司
r.WriteLine("<reportCompany></reportCompany>");//10位申报单位编号1111112222
r.WriteLine("<reportCompanySocialCode></reportCompanySocialCode>");//18位申报单位编号111111222211111111
r.WriteLine("<reportCompanyName>" + bill.CUSTOMERNAME + "</reportCompanyName>");//申报单位名称//青岛公司
r.WriteLine("<transportType>水路运输</transportType>");//运输方式,如果有填箱单,则该字段必填
r.WriteLine("<transportTool>" + bill.VESSEL + "</transportTool>");//运输工具名称,如果有填箱单,则该字段必填//EVERY LUCKY
r.WriteLine("<transportNum>" + bill.VOYNO + "</transportNum>");//航次航班编号,如果有填箱单,则该字段必填//0345W
r.WriteLine("<blno>" + bill.MBLNO + "</blno>");//提运单号,如果有填箱单,则该字段必填//BLH01011122
r.WriteLine("<jianguan>" + bill.TRADETYPE + "</jianguan>");//监管方式//一般贸易
r.WriteLine("<tax></tax>");//征免性质//一般征税
if (bill.BSTYPE == "1")//出口
{
r.WriteLine("<payment>" + bill.PAYMENT + "</payment>");//征税比例,出口方式需要必填,进口方式不填//电汇
}
else if (bill.BSTYPE == "2")//进口
{
r.WriteLine("<payment></payment>");//征税比例,出口方式需要必填,进口方式不填
}
r.WriteLine("<nsdw></nsdw>");//纳税单位
r.WriteLine("<xkzh></xkzh>");//许可证号
r.WriteLine("<country></country>");//运抵国//澳大利亚澳大利亚
r.WriteLine("<harbour>" + bill.PORTDISCHARGE + "</harbour>");//指运港//澳大利亚
r.WriteLine("<churchyard>" + bill.GOODSOURCE + "</churchyard>");//境内货源地//济南其他
if (bill.BSTYPE == "1")//出口
{
if (bill.TRADETERM == "0")//CIF
{
r.WriteLine("<dealMode>CIF</dealMode>");//成交方式CIF,C&F,FOB出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//必填项
r.WriteLine("<carriageType>" + bill.CARRIAGETYPE + "</carriageType>");//运费类型,率,单价,总价//率
r.WriteLine("<carriagePrice>" + Math.Round(bill.CARRIAGEPRICE, 7) + "</carriagePrice>");//运费金额//1.5
if (bill.CARRIAGETYPE == "率")
{
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制//
}
else
{
r.WriteLine("<carriageCurrency>" + bill.CARRIAGECURRENCY + "</carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制//
}
r.WriteLine("<premiumType>" + bill.PREMIUMTYPE + "</premiumType>");//保费类型,当类型是[率]时,不能填保费币制//率
r.WriteLine("<premiumPrice>" + Math.Round(bill.PREMIUMPRICE, 7) + "</premiumPrice>");//保费金额//20
if (bill.PREMIUMTYPE == "率")
{
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制//
}
else
{
r.WriteLine("<premiumCurrency>" + bill.PREMIUMCURRENCY + "</premiumCurrency>");//保费币制//
}
}
else if (bill.TRADETERM == "1")//FOB
{
r.WriteLine("<dealMode>FOB</dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//均不能填
r.WriteLine("<carriageType></carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice></carriagePrice>");//运费金额
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
r.WriteLine("<premiumType></premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice></premiumPrice>");//保费金额
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
else if (bill.TRADETERM == "2")//C&F
{
r.WriteLine("<dealMode>C&F</dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//必填项
r.WriteLine("<carriageType>" + bill.CARRIAGETYPE + "</carriageType>");//运费类型,率,单价,总价//率
r.WriteLine("<carriagePrice>" + Math.Round(bill.CARRIAGEPRICE, 7) + "</carriagePrice>");//运费金额//1.5
if (bill.CARRIAGETYPE == "率")
{
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
}
else
{
r.WriteLine("<carriageCurrency>" + bill.CARRIAGECURRENCY + "</carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
}
//均不能填
r.WriteLine("<premiumType></premiumType>");//保费类型,当类型是[率]时,不能填保费币制//率
r.WriteLine("<premiumPrice></premiumPrice>");//保费金额//20
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
else
{
r.WriteLine("<dealMode></dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
r.WriteLine("<carriageType></carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice></carriagePrice>");//运费金额
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
r.WriteLine("<premiumType></premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice></premiumPrice>");//保费金额
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
}
else if (bill.BSTYPE == "2")//进口
{
if (bill.TRADETERM == "0")//CIF
{
r.WriteLine("<dealMode>CIF</dealMode>");//成交方式CIF,C&F,FOB出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//均不能填
r.WriteLine("<carriageType></carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice></carriagePrice>");//运费金额
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
r.WriteLine("<premiumType></premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice></premiumPrice>");//保费金额
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
else if (bill.TRADETERM == "1")//FOB
{
r.WriteLine("<dealMode>FOB</dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//必填项
r.WriteLine("<carriageType>" + bill.CARRIAGETYPE + "</carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice>" + Math.Round(bill.CARRIAGEPRICE, 7) + "</carriagePrice>");//运费金额
if (bill.CARRIAGETYPE == "率")
{
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
}
else
{
r.WriteLine("<carriageCurrency>" + bill.CARRIAGECURRENCY + "</carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
}
r.WriteLine("<premiumType>" + bill.PREMIUMTYPE + "</premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice>" + Math.Round(bill.PREMIUMPRICE, 7) + "</premiumPrice>");//保费金额
if (bill.PREMIUMTYPE == "率")
{
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
else
{
r.WriteLine("<premiumCurrency>" + bill.PREMIUMCURRENCY + "</premiumCurrency>");//保费币制
}
}
else if (bill.TRADETERM == "2")//C&F
{
r.WriteLine("<dealMode>C&F</dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
//均不能填
r.WriteLine("<carriageType></carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice></carriagePrice>");//运费金额
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
//必填项
r.WriteLine("<premiumType>" + bill.PREMIUMTYPE + "</premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice>" + Math.Round(bill.PREMIUMPRICE, 7) + "</premiumPrice>");//保费金额
if (bill.PREMIUMTYPE == "率")
{
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
else
{
r.WriteLine("<premiumCurrency>" + bill.PREMIUMCURRENCY + "</premiumCurrency>");//保费币制
}
}
else
{
r.WriteLine("<dealMode></dealMode>");//成交方式CIF,C&F,FOB 出口业务:成交方式为CIF时运费保费均为必填项;FOB运费保费均不能填;C&F运费为必填项进口业务:成交方式为FOB时运费保费均为必填项CIF运费保费均不能填;C&F保费为必填项
r.WriteLine("<carriageType></carriageType>");//运费类型,率,单价,总价
r.WriteLine("<carriagePrice></carriagePrice>");//运费金额
r.WriteLine("<carriageCurrency></carriageCurrency>");//运费币制,当类型是[率]时,不能填运费币制
r.WriteLine("<premiumType></premiumType>");//保费类型,当类型是[率]时,不能填保费币制
r.WriteLine("<premiumPrice></premiumPrice>");//保费金额
r.WriteLine("<premiumCurrency></premiumCurrency>");//保费币制
}
}
r.WriteLine("<otherType></otherType>");//杂费类型,当类型是[率]时,不能填杂费币制
r.WriteLine("<otherPrice></otherPrice>");//杂费金额
r.WriteLine("<otherCurrency></otherCurrency>");//杂费币制
r.WriteLine("<boxNum>" + bill.PKGS + "</boxNum>");//件数//123
r.WriteLine("<boxType></boxType>");//包装种类//其他
r.WriteLine("<grossWeight>" + Math.Round(bill.KGS, 5) + "</grossWeight>");//毛重//323
r.WriteLine("<netWeight>" + Math.Round(bill.NETWEIGHT, 5) + "</netWeight>");//净重//232
r.WriteLine("<tradingCountry></tradingCountry>");//贸易国日本
r.WriteLine("<relationship></relationship>");//特殊关系确认,是||否,是
r.WriteLine("<pathmark></pathmark>");//价格影响确认,是||否,否
r.WriteLine("<useFee></useFee>");//支付特许权使用费确认,是||否,是
r.WriteLine("<formType></formType>");//报关单类型:有纸化报关||通关无纸化,有纸报关
r.WriteLine("<remark>" + bill.REMARK + "</remark>");//备注
r.WriteLine("<relativeEntryNo>" + bill.BSCUSTOMNO + "</relativeEntryNo>");//关联报关单号
r.WriteLine("<relativeEnrolNo></relativeEnrolNo>");//关联备案号
r.WriteLine("<bsjgPlace></bsjgPlace>");//保税/监管场所
r.WriteLine("<yardCode></yardCode>");//货场代码
#endregion
#region 3.1.3报关单业务商品信息(循环)
List<MsOpApplyDetail> BodyList = MsOpApplyDAL.MsOpApplyDAL.GetBodyList("bsno='" + bill.BSNO.ToString() + "'");
if (BodyList != null)
{
if (BodyList.Count > 0)
{
r.WriteLine("<productInformationList>");
foreach (var opCtn in BodyList)
{
r.WriteLine("<productInformation>");
r.WriteLine("<serialNum>" + opCtn.SerialNo + "</serialNum>");//商品序号按顺序从1递增如果有商品则该字段必填//1
r.WriteLine("<hsCode>" + opCtn.GoodsCode + "</hsCode>");//商品编码//8486203100
r.WriteLine("<productName>" + opCtn.GoodsName + "</productName>");//商品名称//制造半导体器件或集成电路用分布重复光刻机
r.WriteLine("<reportElement></reportElement>");//申报要素//对橡胶等非金属材料进行加工|激光雕刻|红帆牌|CM1490
r.WriteLine("<productNum>" + Math.Round(opCtn.Pkgs, 4) + "</productNum>");//成交数量//1
r.WriteLine("<dealUnit></dealUnit>");//成交单位//台
r.WriteLine("<productPrice>" + Math.Round(opCtn.Price, 4) + "</productPrice>");//成交价格//5420.0000
r.WriteLine("<productSum>" + Math.Round(opCtn.Total, 2) + "</productSum>");//成交总价//5420.00
r.WriteLine("<productCurrency>" + opCtn.Currency + "</productCurrency>");//币制//美元
r.WriteLine("<productLegalNum></productLegalNum>");//法定数量,法定单位不为空时,法定数量必填//1
r.WriteLine("<productLegalUnit></productLegalUnit>");//法定单位//台
if (bill.BSTYPE == "1")//出口
{
r.WriteLine("<productCity></productCity>");//出口:最终目的国,进口:原产国//日本
r.WriteLine("<originCountry>" + bill.ARCOUNTRY + "</originCountry>");//出口:原产国,进口:最终目的国//澳大利亚
}
else if (bill.BSTYPE == "2")//进口
{
r.WriteLine("<productCity>" + bill.ARCOUNTRY + "</productCity>");//出口:最终目的国,进口:原产国//日本
r.WriteLine("<originCountry></originCountry>");//出口:原产国,进口:最终目的国//澳大利亚
}
r.WriteLine("<productTax></productTax>");//征免//照章征税
r.WriteLine("<secondNum></secondNum>");//第二数量,第二单位不为空时,第二数量必填//
r.WriteLine("<secondUnit></secondUnit>");//第二单位//
if (bill.BSTYPE == "1")//出口
{
r.WriteLine("<purpose></purpose>");//用途,限进口//特区内销
}
else if (bill.BSTYPE == "2")//进口
{
r.WriteLine("<purpose></purpose>");//用途,限进口//特区内销
}
r.WriteLine("</productInformation>");
}
r.WriteLine("</productInformationList>");
}
}
#endregion
#region 其他(文档中没有解释)
//r.WriteLine("<entryContainerInformationList>");
//r.WriteLine("<entryContainerInformation>");
//r.WriteLine("<contaId>NYKU4008903</contaId>");//集装箱箱号
//r.WriteLine("<contaSize>Z</contaSize>");//集装箱规格
//r.WriteLine("<tareWeight>2300</tareWeight>");//集装箱自重
//r.WriteLine("<contaModel>20GP</contaModel>");//集装箱箱型
//r.WriteLine("</entryContainerInformation>");
//r.WriteLine("</entryContainerInformationList>");
#endregion
#region 3.1.4报关单业务、备案清单业务随附单证信息
List<ReceiptDocmb> rdList = ReceiptDocDAL.GetDocList("bsno='" + bill.BSNO.ToString() + "' and RECEIPTTYPE like '易航线%' and (([documentAttachedCode]<>'' and documentAttachedCode is not null) or ([documentAttachedNo]<>'' and documentAttachedNo is not null)) ");
if (rdList != null)
{
if (rdList.Count > 0)
{
r.WriteLine("<documentAttachedInformationList>");
foreach (var opFuJian in rdList)
{
r.WriteLine("<documentAttachedInformation>");
r.WriteLine("<documentAttachedCode>" + opFuJian.DOCUMENTATTACHEDCODE + "</documentAttachedCode>");//随附单证代码//出/入境货物通关单(毛坯钻石用)
r.WriteLine("<documentAttachedNo>" + opFuJian.DOCUMENTATTACHEDNO + "</documentAttachedNo>");//随附单证编号,如果有单证则该字段必填//370200215020824000
r.WriteLine("</documentAttachedInformation>");
}
r.WriteLine("</documentAttachedInformationList>");
}
}
#endregion
r.WriteLine("</messageBody>");
r.WriteLine("</message>");
}
r.Close();
f.Close();
return filename;
}
public static string CreateEdiELineESI2(List<MsOpApply> headData, string path, string mblno, CodeFtpSet ftpset, ReceiptDocmb opFuJian, string sDriect_URL)
{
string sURL = opFuJian.URL.ToString();
int iKZM = sURL.LastIndexOf(".");
string sKZM = sURL.Substring(iKZM+1);
string filename = path + "\\" + mblno + "_" + sURL.Substring(0, (sURL.Length - iKZM)) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
FileStream f = new FileStream(filename, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.UTF8);//.Default
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
foreach (var bill in headData)
{
r.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
r.WriteLine("<message>");
#region 3.2 报关单随附单据、单证报文节点说明1.2 随附单据验证服务及上传接口)
r.WriteLine("<token>tokenCeShi</token>");//组织机构代码证号39f1e2b0e30f8e2
r.WriteLine("<clientPlatformCode>" + ftpset.SENDCODE + "</clientPlatformCode>");//委托平台代码必填发送方代码1000120000
r.WriteLine("<clientCompanyCode>" + ftpset.SENDSUBCOMPANYCODE + "</clientCompanyCode>");//9位组织机构代码证号必填发送方分部代码323456790test
r.WriteLine("<taskId>" + bill.CUSTNO + "</taskId>");//活动委托唯一标示必填112210
if (bill.BSTYPE == "1")
{
r.WriteLine("<importExportFlag>E</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
}
else if (bill.BSTYPE == "2")
{
r.WriteLine("<importExportFlag>I</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
}
r.WriteLine("<fileType>" + opFuJian.RECEIPTTYPE.Replace("易航线_", "") + "</fileType>"); //单据类型//发票装箱单提运单合同其他1其他2其他3纸质代理报关委托协议扫描件电子代理报关委托协议编号减免税货物税款担保证明减免税货物税款担保延期证明必填
r.WriteLine("<number></number>"); //单据、单证编号//如果没有binaryData即没有附件文件则fileName必填//20154200015811840
r.WriteLine("<mimeType>" + sKZM + "</mimeType>"); //文件类型扩展名 (只支持pdf)//文件真实类型扩展名,有binaryData则必填
//
//将PDF格式文件转成base64编码
String base64String = fileToBase64(sDriect_URL);
base64String = MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatEdiStr("xml", base64String);
r.WriteLine("<binaryData>" + base64String + "</binaryData>"); //单据base64编码//文件base64编码值是否有附件的唯一标识。该数据项有记录则为有附件的随附单据则mimeType必填。无记录则number必填。
#endregion
#region 3.2 报关单随附单据、单证报文节点说明1.2.1 随附单据验证服务及上传接口)
//r.WriteLine("<token>tokenCeShi</token>");//组织机构代码证号39f1e2b0e30f8e2
//r.WriteLine("<clientPlatformCode>" + ftpset.SENDCODE + "</clientPlatformCode>");//委托平台代码必填发送方代码1000120000
//r.WriteLine("<clientCompanyCode>" + ftpset.SENDSUBCOMPANYCODE + "</clientCompanyCode>");//9位组织机构代码证号必填发送方分部代码323456790test
//r.WriteLine("<taskId>" + bill.CUSTNO + "</taskId>");//活动委托唯一标示必填112210
//if (bill.BSTYPE == "1")
//{
// //r.WriteLine("<importExportFlag>E</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
//}
//else if (bill.BSTYPE == "2")
//{
// //r.WriteLine("<importExportFlag>I</importExportFlag>");//进出口标示 (I/E)必填I进口 E出口
//}
//r.WriteLine("<mimeType>" + sKZM + "</mimeType>"); //文件类型扩展名//文件真实类型扩展名,有binaryData则必填
////将PDF格式文件转成base64编码
//String base64String = fileToBase64(sDriect_URL);
////base64String = MsOpSeaeEdiPortDAL.MsOpSeaeEdiPortDAL.formatEdiStr("xml", base64String);
//r.WriteLine("<binaryData>" + base64String + "</binaryData>"); //单据base64编码//文件base64编码值是否有附件的唯一标识。该数据项有记录则为有附件的随附单据则mimeType必填。无记录则number必填。
#endregion
r.WriteLine("</message>");
}
r.Close();
f.Close();
return filename;
}
#endregion
#region 易航线网站上传接口//需求编号SR2017081100003
public static DBResult WebFile(string filePath, CodeFtpSet ftpset, ArrayList alFile)
{
var result = new DBResult();
try
{
UnicodeEncoding unicode = new UnicodeEncoding();
#region 第一种post方法
//HttpHelper http = new HttpHelper();
//HttpItem item = new HttpItem()
//{
// //http:///test.21eline.com:8030/api/bg_simple_validate.html?delegete=1
// URL = ftpset.SERVERIP + "/api/get_token.html?clientPlatformCode=" + ftpset.USERNAME + "&key=" + ftpset.PASSWORD,//URL这里都是测试 必需项
// Referer = ftpset.SERVERIP,
// Encoding = null,//编码格式UTF-8,gb2312,gbk 可选项 默认类会自动识别
// Host = ftpset.SERVERIP.Replace("http://", ""),
// UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
// Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
// ContentType = "text/html",
// Method = "POST",//URL 可选项 默认为Get
//};
//HttpResult resulthtml = http.GetHtml(item);
//string ddd = resulthtml.Html;
//string dddf = unicode.GetString(unicode.GetBytes(Regex.Unescape(resulthtml.Html)));
#endregion
#region 第二种post方法Data传json数组
//string ff = DSWeb.Areas.Mobile.DAL.HttpHelper.HttpPost("http://test.21eline.com:8030/api/bg_simple_validate.html?delegete=1", ("clientPlatformCode=" + ftpset.USERNAME + "&key=" + ftpset.PASSWORD));
//string dfs = unicode.GetString(unicode.GetBytes(Regex.Unescape(ff)));
#endregion
#region 第三种post方法
//string postData = "clientPlatformCode=" + ftpset.USERNAME + "&key=" + ftpset.PASSWORD; // 要发放的数据
//byte[] byteArray = Encoding.UTF8.GetBytes(postData);
//HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://test.21eline.com:8030/api/get_token.html");
//objWebRequest.Method = "POST";
//objWebRequest.ContentType = "application/x-www-form-urlencoded";
//objWebRequest.ContentLength = byteArray.Length;
//Stream newStream = objWebRequest.GetRequestStream();
//newStream.Write(byteArray, 0, byteArray.Length); //写入参数
//newStream.Close();
//HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
//StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
//string resultJson = sr.ReadToEnd(); // 返回的数据
//string dfhss = unicode.GetString(unicode.GetBytes(Regex.Unescape(resultJson)));
#endregion
#region 第四种post方法
//HttpHelperX2 ShippHttp = new HttpHelperX2();
//var refurl7 = ftpset.SERVERIP + "/api/get_token.html";
//var Postdata7 = "clientPlatformCode=" + ftpset.USERNAME + "&key=" + ftpset.PASSWORD;
//var alldatahtml = ShippHttp.PostAndGetHtml(refurl7, Postdata7, "application/x-www-form-urlencoded", refurl7, true, Encoding.UTF8);
//var tokenData7 = JsonConvert.Deserialize<MsOpApplyELine>(alldatahtml);
#endregion
#region 第五种post方法传字典方式1.5 授权接口获取易航线网站的token2小时有效
var refurl = ftpset.SERVERIP + "/api/get_token.html";
MsOpApplyELine tokenData = new MsOpApplyELine();
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["clientPlatformCode"] = ftpset.USERNAME;
values["key"] = ftpset.PASSWORD;
var response = client.UploadValues(refurl, values);
var responseString = Encoding.UTF8.GetString(response);
tokenData = JsonConvert.Deserialize<MsOpApplyELine>(responseString);
}
#endregion
if (tokenData.resultCode == "1")
{
#region 第五种post方法传字典方式1.1 主报关单验证服务及上传接口
refurl = ftpset.SERVERIP + "/api/bg_simple_validate.html?delegete=1";
var fileStr = fileToString(filePath);//打开已经生成好的xml文件路径//"C:\\Users\\Administrator\\Desktop\\文件.xml"//接口xml范例1.xml
fileStr = fileStr.Replace("tokenCeShi", tokenData.resultValue);//替换为最新的口令
string gzStr = GZipCompressString(fileStr);//压缩返回Base64字符串
MsOpApplyELine headData = new MsOpApplyELine();
string resultCode = "0";
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["main_xml"] = gzStr;
var response = client.UploadValues(refurl, values);
var responseString = Encoding.UTF8.GetString(response);
if (responseString.IndexOf("\"resultCode\":1") > -1)
{
resultCode = "1";
}
else
{
headData = JsonConvert.Deserialize<MsOpApplyELine>(responseString);
}
//{\"taskId\":\"TAD17060026\",\"resultCode\":1,\"resultValue\":{\"goods\":{\"1\":\"116666\"}},\"systemNum\":\"170905150825103340\"}
}
#endregion
//if (headData.resultCode == "1")
if (resultCode == "1")
{
if (alFile.Count>0)
{
string sError = "";
for (int i = 0; i < alFile.Count; i++)
{
#region 第五种post方法传字典方式1.2.1 随附单据验证服务及上传接口
//refurl = ftpset.SERVERIP + "/api/file_validate.html";
var refurl3 = ftpset.SERVERIP + "/api/file_validate_notype.html";
var fileStr3 = fileToString(alFile[i].ToString());//打开已经生成好的xml文件路径
fileStr3 = fileStr3.Replace("tokenCeShi", tokenData.resultValue);//替换为最新的口令
string gzStr3 = GZipCompressString(fileStr3);//压缩返回Base64字符串
MsOpApplyELine headData3 = new MsOpApplyELine();
string resultCode3 = "0";
using (var client = new WebClient())
{
var values = new NameValueCollection();
values["xml"] = gzStr3;
//client.Headers.Add("Content-Type", "multipart/form-data");
var response = client.UploadValues(refurl3, values);
var responseString = Encoding.UTF8.GetString(response);
if (responseString.IndexOf("\"resultCode\":1") > -1)
{
resultCode3 = "1";
}
else
{
headData3 = JsonConvert.Deserialize<MsOpApplyELine>(responseString);
}
}
#endregion
//if (headData3.resultCode == "1")
if (resultCode3 == "1")
{ }
else
{
sError += headData3.resultValue;
continue;
}
}
if (sError != "")
{
result.Success = false;
result.Message = sError;//"提示:暂时连接不上服务器,请稍后重试!" +
return result;
}
}
}
else
{
result.Success = false;
result.Message = headData.resultValue;
return result;
}
}
else
{
result.Success = false;
result.Message = tokenData.resultValue;
return result;
}
result.Success = true;
result.Message = "上传成功" + result.Message;
return result;
}
catch (Exception)
{
result.Success = false;
//需求编号SR2017041200014
if (result.Message.ToString().IndexOf("连接尝试失败") > -1)
{
result.Message = "提示:暂时连接不上船公司服务器,请稍后重试!";
}
return result;
}
}
#endregion
#region 文件转Base64编码字符//需求编号SR2017081100003
public static string fileToBase64(string filePath)
{
FileInfo fi = new FileInfo(filePath);
byte[] buff = new byte[fi.Length];
FileStream fs = fi.OpenRead();
fs.Read(buff, 0, Convert.ToInt32(fs.Length));
fs.Close();
string str = Convert.ToBase64String(buff);
return str;
}
#endregion
#region 文件转字符//需求编号SR2017081100003
public static string fileToString(string filePath)
{
FileInfo fi = new FileInfo(filePath);
byte[] buff = new byte[fi.Length];
FileStream fs = fi.OpenRead();
fs.Read(buff, 0, Convert.ToInt32(fs.Length));
fs.Close();
//string str = System.Text.Encoding.Default.GetString(buff);
string str = System.Text.Encoding.UTF8.GetString(buff);
return str;
}
#endregion
#region 文件用GZip算法压缩后返回Base64编码字符//需求编号SR2017081100003
/// <summary>
/// 将传入字符串以GZip算法压缩后返回Base64编码字符
/// </summary>
/// <param name="rawString">需要压缩的字符串</param>
/// <returns>压缩后的Base64编码的字符串</returns>
public static string GZipCompressString(string rawString)
{
if (string.IsNullOrEmpty(rawString) || rawString.Length == 0)
{
return "";
}
else
{
byte[] rawData = System.Text.Encoding.UTF8.GetBytes(rawString.ToString());
byte[] zippedData = Compress(rawData);
return (string)(Convert.ToBase64String(zippedData));
}
}
/// <summary>
/// GZip压缩
/// </summary>
/// <param name="rawData"></param>
/// <returns></returns>
public static byte[] Compress(byte[] rawData)
{
MemoryStream ms = new MemoryStream();
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);
compressedzipStream.Write(rawData, 0, rawData.Length);
compressedzipStream.Close();
return ms.ToArray();
}
/// <summary>
/// 将传入的二进制字符串资料以GZip算法解压缩
/// </summary>
/// <param name="zippedString">经GZip压缩后的二进制字符串</param>
/// <returns>原始未压缩字符串</returns>
public static string GZipDecompressString(string zippedString)
{
if (string.IsNullOrEmpty(zippedString) || zippedString.Length == 0)
{
return "";
}
else
{
byte[] zippedData = Convert.FromBase64String(zippedString.ToString());
return (string)(System.Text.Encoding.UTF8.GetString(Decompress(zippedData)));
}
}
/// <summary>
/// ZIP解压
/// </summary>
/// <param name="zippedData"></param>
/// <returns></returns>
public static byte[] Decompress(byte[] zippedData)
{
MemoryStream ms = new MemoryStream(zippedData);
GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress);
MemoryStream outBuffer = new MemoryStream();
byte[] block = new byte[1024];
while (true)
{
int bytesRead = compressedzipStream.Read(block, 0, block.Length);
if (bytesRead <= 0)
break;
else
outBuffer.Write(block, 0, bytesRead);
}
compressedzipStream.Close();
return outBuffer.ToArray();
}
#endregion
#endregion
}
}