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.
DS7/DSWeb/Areas/MvcShipping/DAL/MsOpSubSeaOrder/MsOpSubSeaOrderDAL.cs

3350 lines
147 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.Data;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using DSWeb.MvcShipping.Models.MsOpSubSeaOrder;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using WebSqlHelper;
using DSWeb.MvcShipping.Models.MsOpSeae;
using System.IO;
using DSWeb.MvcShipping.Models.FtpSet;
using System.Text.RegularExpressions;
namespace DSWeb.MvcShipping.DAL.MsOpSubSeaOrderDAL
{
public class MsOpSubSeaOrderDAL
{
#region 查询
static public List<MsOpSubSeaOrder> GetDataList(string strCondition, string billtype,int ortype, string userid, string usercode, string companyid, string sort = null)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and (Companyid='" + companyid + "' or Agentid='"+companyid+"') and BILLTYPE="+billtype;
}
else
{
strCondition = " (Companyid='" + companyid + "' or Agentid='"+companyid+"') and BILLTYPE=" + billtype;
}
//
var strSql = new StringBuilder();
strSql.Append("SELECT ORDNO,BSNO,ORSTATUS,ORTYPE,ORREASON,BSDATE,MBLNO,HBLNO,CUSTOMERNAME");
strSql.Append(",SHIPPER,CONSIGNEE,NOTIFYPARTY,VESSEL,VOYNO,ETD,ETA,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE");
strSql.Append(",PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT");
strSql.Append(",PREPARDAT,PAYABLEAT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS");
strSql.Append(",KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN");
strSql.Append(",REMARK,AUDITOPERATOR,AUDITDATE,DPAGE,DLABEL,LINKMAN,BILLTYPE,COMPANYID,AGENTID,SPCHARGE");
strSql.Append(",SHIPPERCODE,SHIPPERCOUNTRY,SHIPPERTEL,CONSIGNEECODE,CONSIGNEECOUNTRY,CONSIGNEETEL,NOTIFYPARTYCODE,NOTIFYPARTYCOUNTRY,NOTIFYPARTYTEL");
if (ortype == 1)
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN 'RECEIVE' WHEN '1' THEN 'POSTED' WHEN '2' THEN 'REJECTED' else 'ENTRY' end) as ORSTATUSREF ");
}
else {
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN '确认' WHEN '1' THEN '提交' WHEN '2' THEN '驳回' else '录入' end) as ORSTATUSREF ");
}
strSql.Append(",(SELECT [NAME] from company where GID=B.COMPANYID) as COMPANY ");
strSql.Append(",(SELECT [NAME] from company where GID=B.AGENTID) as AGENT ");
strSql.Append(",dbo.F_GetBillDrFeeStatus(B.ORDNO) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(B.ORDNO) CRFEESTATUS");
strSql.Append(" from op_sub_seaorder B");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BSDATE desc");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string billtype, int ortype, string userid, string usercode, string companyid, string sort = null)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and (Companyid='" + companyid + "' or Agentid='" + companyid + "') and BILLTYPE=" + billtype;
}
else
{
strCondition = " (Companyid='" + companyid + "' or Agentid='" + companyid + "') and BILLTYPE=" + billtype;
}
//
var strSql = new StringBuilder();
strSql.Append("SELECT ORDNO,BSNO,ORSTATUS,ORTYPE,ORREASON,BSDATE,MBLNO,HBLNO,CUSTOMERNAME");
strSql.Append(",SHIPPER,CONSIGNEE,NOTIFYPARTY,VESSEL,VOYNO,ETD,ETA,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE");
strSql.Append(",PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT");
strSql.Append(",PREPARDAT,PAYABLEAT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS");
strSql.Append(",KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN");
strSql.Append(",REMARK,AUDITOPERATOR,AUDITDATE,DPAGE,DLABEL,LINKMAN,BILLTYPE,COMPANYID,AGENTID,SPCHARGE");
strSql.Append(",SHIPPERCODE,SHIPPERCOUNTRY,SHIPPERTEL,CONSIGNEECODE,CONSIGNEECOUNTRY,CONSIGNEETEL,NOTIFYPARTYCODE,NOTIFYPARTYCOUNTRY,NOTIFYPARTYTEL");
if (ortype == 1)
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN 'RECEIVE' WHEN '1' THEN 'POSTED' WHEN '2' THEN 'REJECTED' else 'ENTRY' end) as ORSTATUSREF ");
}
else
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN '确认' WHEN '1' THEN '提交' WHEN '2' THEN '驳回' else '录入' end) as ORSTATUSREF ");
}
strSql.Append(",(SELECT [NAME] from company where GID=B.COMPANYID) as COMPANY ");
strSql.Append(",(SELECT [NAME] from company where GID=B.AGENTID) as AGENT ");
strSql.Append(",dbo.F_GetBillDrFeeStatus(B.ORDNO) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(B.ORDNO) CRFEESTATUS");
strSql.Append(" from op_sub_seaorder B");
strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=B.ORDNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BSDATE desc");
}
return strSql.ToString();
}
static public MsOpSubSeaOrder GetData(string condition,int ortype)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ORDNO,BSNO,ORSTATUS,ORTYPE,ORREASON,BSDATE,MBLNO,HBLNO,CUSTOMERNAME");
strSql.Append(",SHIPPER,CONSIGNEE,NOTIFYPARTY,VESSEL,VOYNO,ETD,ETA,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE");
strSql.Append(",PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT");
strSql.Append(",PREPARDAT,PAYABLEAT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS");
strSql.Append(",KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN");
strSql.Append(",REMARK,AUDITOPERATOR,AUDITDATE,DPAGE,DLABEL,LINKMAN,BILLTYPE,COMPANYID,AGENTID,SPCHARGE");
strSql.Append(",SHIPPERCODE,SHIPPERCOUNTRY,SHIPPERTEL,CONSIGNEECODE,CONSIGNEECOUNTRY,CONSIGNEETEL,NOTIFYPARTYCODE,NOTIFYPARTYCOUNTRY,NOTIFYPARTYTEL");
if (ortype == 1)
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN 'RECEIVE' WHEN '1' THEN 'POSTED' WHEN '2' THEN 'REJECTED' else 'ENTRY' end) as ORSTATUSREF ");
}
else
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN '确认' WHEN '1' THEN '提交' WHEN '2' THEN '驳回' else '录入' end) as ORSTATUSREF ");
}
strSql.Append(",(SELECT [NAME] from company where GID=B.COMPANYID ) as COMPANY ");
strSql.Append(",(SELECT [NAME] from company where GID=B.AGENTID ) as AGENT ");
strSql.Append(",dbo.F_GetBillDrFeeStatus(B.ORDNO) DRFEESTATUS");
strSql.Append(",dbo.F_GetBillCrFeeStatus(B.ORDNO) CRFEESTATUS");
strSql.Append(" from op_sub_seaorder B");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsOpSubSeaOrder();
}
private static List<MsOpSubSeaOrder> SetData(StringBuilder strSql)
{
var headList = new List<MsOpSubSeaOrder>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaOrder data = new MsOpSubSeaOrder();
#region Set DB data to Object
data.ORDNO = Convert.ToString(reader["ORDNO"]);//委托
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.ORSTATUS = Convert.ToString(reader["ORSTATUS"]);//主编号
data.ORSTATUSREF = Convert.ToString(reader["ORSTATUSREF"]);//委托编号
data.ORREASON = Convert.ToString(reader["ORREASON"]);//分提单号
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]);//接单日期
data.MBLNO = Convert.ToString(reader["MBLNO"]);//主提单号
data.HBLNO = Convert.ToString(reader["HBLNO"]);//分提单号
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);//委托单位
data.SHIPPER = Convert.ToString(reader["SHIPPER"]);//收货人内容
data.CONSIGNEE = Convert.ToString(reader["CONSIGNEE"]);//收货人内容
data.NOTIFYPARTY = Convert.ToString(reader["NOTIFYPARTY"]);//通知人内容
data.VESSEL = Convert.ToString(reader["VESSEL"]);//船名
data.VOYNO = Convert.ToString(reader["VOYNO"]);//航次
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");//到港日期
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");//预抵日期
data.PORTLOADID = Convert.ToString(reader["PORTLOADID"]);//装货港代码
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);//装货港
data.PORTDISCHARGEID = Convert.ToString(reader["PORTDISCHARGEID"]);//卸货港代码
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);//卸货港
data.PlACERECEIPT = Convert.ToString(reader["PlACERECEIPT"]);//收货地
data.PLACEDELIVERYID = Convert.ToString(reader["PLACEDELIVERYID"]);//交货地代码
data.PLACEDELIVERY = Convert.ToString(reader["PLACEDELIVERY"]);//交货地
data.DESTINATIONID = Convert.ToString(reader["DESTINATIONID"]);//目的地代码
data.DESTINATION = Convert.ToString(reader["DESTINATION"]);//目的地
data.NOBILL = Convert.ToString(reader["NOBILL"]);//提单份数
data.ISSUETYPE = Convert.ToString(reader["ISSUETYPE"]);//签单方式
if (reader["ISSUEDATE"] != DBNull.Value)
data.ISSUEDATE = Convert.ToDateTime(reader["ISSUEDATE"]).ToString("yyyy-MM-dd");//到港日期
data.ISSUEPLACE = Convert.ToString(reader["ISSUEPLACE"]);//签单地点
data.BLFRT = Convert.ToString(reader["BLFRT"]);//付费方式
data.PREPARDAT = Convert.ToString(reader["PREPARDAT"]);//预付地点
data.PAYABLEAT = Convert.ToString(reader["PAYABLEAT"]);//到付地点
data.SERVICE = Convert.ToString(reader["SERVICE"]);//运输条款
data.MARKS = Convert.ToString(reader["MARKS"]);//唛头
data.NOPKGS = Convert.ToString(reader["NOPKGS"]);//件数包装
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);//货物描述
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);//品名
data.GROSSWEIGHT = Convert.ToString(reader["GROSSWEIGHT"]);//货物毛重
data.MEASUREMENT = Convert.ToString(reader["MEASUREMENT"]);//货物尺码
data.PKGS = Convert.ToInt32(reader["PKGS"]);//件数
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);//件数包装
data.KGS = Convert.ToDecimal(reader["KGS"]);//毛重
data.CBM = Convert.ToDecimal(reader["CBM"]);//立方数/尺码
data.TOTALNO = Convert.ToString(reader["TOTALNO"]);//件数大写
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);//集装箱全部内容
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);//录入人
data.CARGOID = Convert.ToString(reader["CARGOID"]);//货物标识
data.DCLASS = Convert.ToString(reader["DCLASS"]);//危险品分类/等级
data.DUNNO = Convert.ToString(reader["DUNNO"]);//危险品编号
data.DPAGE = Convert.ToString(reader["DPAGE"]);//危险品页号
data.DLABEL = Convert.ToString(reader["DLABEL"]);//危险品标签
data.LINKMAN = Convert.ToString(reader["LINKMAN"]);//危险品联系人
data.REEFERF = Convert.ToString(reader["REEFERF"]);//冷藏通风量
data.TEMPID = Convert.ToString(reader["TEMPID"]);//温度单位
data.TEMPSET = Convert.ToString(reader["TEMPSET"]);//设置温度
data.TEMPMAX = Convert.ToString(reader["TEMPMAX"]);//最高温度
data.TEMPMIN = Convert.ToString(reader["TEMPMIN"]);//最低温度
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
data.BILLTYPE = Convert.ToInt16(reader["BILLTYPE"]);//装运方式
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);//装运方式
data.AGENTID = Convert.ToString(reader["AGENTID"]);//卸货代理
data.AGENT = Convert.ToString(reader["AGENT"]);//卸货代理
data.AUDITOPERATOR = Convert.ToString(reader["AUDITOPERATOR"]);//审核人
data.AUDITDATE = Convert.ToString(reader["AUDITDATE"]);//审核日期
data.COMPANY = Convert.ToString(reader["COMPANY"]);//卸货代理
data.SHIPPERCODE = Convert.ToString(reader["SHIPPERCODE"]);//卸货代理
data.SHIPPERCOUNTRY = Convert.ToString(reader["SHIPPERCOUNTRY"]);//卸货代理
data.SHIPPERTEL = Convert.ToString(reader["SHIPPERTEL"]);//卸货代理
data.CONSIGNEECODE = Convert.ToString(reader["CONSIGNEECODE"]);//卸货代理
data.CONSIGNEECOUNTRY = Convert.ToString(reader["CONSIGNEECOUNTRY"]);//卸货代理
data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]);//卸货代理
data.NOTIFYPARTYCODE = Convert.ToString(reader["NOTIFYPARTYCODE"]);//卸货代理
data.NOTIFYPARTYCOUNTRY = Convert.ToString(reader["NOTIFYPARTYCOUNTRY"]);//卸货代理
data.NOTIFYPARTYTEL = Convert.ToString(reader["NOTIFYPARTYTEL"]);//卸货代理
data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"]));
data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"]));
if (reader["SPCHARGE"] != DBNull.Value)
data.SPCHARGE = Convert.ToBoolean(reader["SPCHARGE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static string getfeestatus(string feestatusint)
{
var result = "";
if (feestatusint == "0:")
{
return "审核通过";
}
else if (feestatusint == "1:")
{
return "录入状态";
}
else if (feestatusint == "2:")
{
return "提交审核";
}
else if (feestatusint == "8:")
{
return "部分结算";
}
else if (feestatusint == "9:")
{
return "结算完毕";
}
else if (feestatusint == "")
{
return "未录入";
}
else if (feestatusint == "3:")
{
return "申请修改";
}
else if (feestatusint == "4:")
{
return "申请删除";
}
else if (feestatusint.IndexOf("6:") > -1)
{
return "驳回提交";
}
else if (feestatusint.IndexOf("7:") > -1)
{
return "驳回申请";
}
else if (feestatusint.IndexOf("1:") > -1)
{
return "部分录入";
}
else if (feestatusint.IndexOf("2:") > -1)
{
return "部分提交";
}
else if (feestatusint.IndexOf("9:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("8:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("0:") > -1)
{
return "部分审核";
}
else if (feestatusint.IndexOf("2:") > -1)
{
return "部分提交";
}
return result;
}
#endregion
#region 集装箱
static public List<MsOpSubSeaOrderCtn> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [CTN_ID],[BSNO],[CTNCODE],[CTNALL],[CNTRNO],[SEALNO],[PKGS],[KGS],[CBM],[REMARK],[CTNSOURCE],[STATUS] from op_seaorder_ctn");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by BSNO,cast (ISNULL(CTNCODE,0) as int),CTNALL");
return SetBodyData(strSql);
}
private static List<MsOpSubSeaOrderCtn> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsOpSubSeaOrderCtn>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaOrderCtn data = new MsOpSubSeaOrderCtn();
#region Set DB data to Object
data.CTN_ID = Convert.ToString(reader["CTN_ID"]);//编号
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.CTNCODE = Convert.ToString(reader["CTNCODE"]);//表现形式
data.CTNALL = Convert.ToString(reader["CTNALL"]);//表现形式
data.CNTRNO = Convert.ToString(reader["CNTRNO"]);//箱号
data.SEALNO = Convert.ToString(reader["SEALNO"]);//封号
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);//件数
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);//重量(货重)
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);//尺码
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
data.CTNSOURCE = Convert.ToString(reader["CTNSOURCE"]);//备注
data.STATUS = Convert.ToString(reader["STATUS"]);//备注
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 保存集装箱
public static DBResult SaveDetail(MsOpSubSeaOrder headData, List<MsOpSubSeaOrderCtn> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
int SIZE = int.Parse(enumValue.CTNALL.ToString().Trim().Substring(0, 2));
string CTN = enumValue.CTNALL.ToString().Trim().Substring(2);
int iTEU = int.Parse(enumValue.CTNALL.ToString().Trim().Substring(0, 1));
//
if (enumValue.BSNO == "*")
{
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + headData.BSNO + "','" + enumValue.CTNCODE + "','" + enumValue.CTNALL + "','" + enumValue.CNTRNO + "','" + enumValue.SEALNO + "','" + enumValue.PKGS + "'," + enumValue.KGS + "," + enumValue.CBM + ",'" + enumValue.REMARK + "','" + enumValue.CTNSOURCE + "','" + enumValue.STATUS + "')");
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(@"update op_seaorder_ctn set CTNCODE='" + enumValue.CTNCODE + "',CTNALL='" + enumValue.CTNALL + "',CNTRNO='" + enumValue.CNTRNO + "',SEALNO='" + enumValue.SEALNO + "',PKGS='" + enumValue.PKGS + "',KGS=" + enumValue.KGS + ",CBM=" + enumValue.CBM + ",REMARK='" + enumValue.REMARK + "',CTNSOURCE='" + enumValue.CTNSOURCE + "',STATUS='" + enumValue.STATUS + "' where BSNO='" + enumValue.BSNO + "' AND CTN_ID='" + enumValue.CTN_ID + "'");
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
//
getCNTRTOTAL(headData.BSNO, "op_sub_seaorder");
//
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static void getCNTRTOTAL(string strBSNO, string bstype)
{
string strCNTRTOTAL = "";
string str = "";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
DataSet dsDisp = T_ALL_DA.GetAllSQL("select * from code_ctn_disp");// where CORPID = '" + strCORPID + "'";
DataSet ds = T_ALL_DA.GetAllSQL("select * from op_seaorder_ctn where BSNO='" + strBSNO.Trim() + "'");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
str = "select CTNALL,count(*) as hj from op_seaorder_ctn where BSNO='" + strBSNO.Trim() + "' group by CTNALL order by CTNALL";
ds = T_ALL_DA.GetAllSQL(str);
foreach (DataTable myTable in ds.Tables)
{
foreach (DataRow myRow in myTable.Rows)//遍历表
{
strCNTRTOTAL += myRow["CTNALL"].ToString().Trim() + "*" + myRow["hj"].ToString().Trim() + " / ";
}
}
strCNTRTOTAL = strCNTRTOTAL.Trim().Substring(0, strCNTRTOTAL.Trim().Length - 1);
}
}
str = "update op_sub_seaorder set CNTRTOTAL='" + strCNTRTOTAL + "' where BSNO='" + strBSNO.Trim() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(str);
}
#region 费用
static public List<MsOpSubSeaOrderFee> GetFeeList(string strCondition,int agentfee)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [FEEID],[BSNO],[FEENAME],[UNITPRICE],[QUANTITY],[AMOUNT],[CURRENCY],[EXCHANGERATE],[REMARK],[FEEFRT] ,[SORT],UNIT,AGENTFEE from op_sub_seaorder_fee");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where AGENTFEE="+agentfee.ToString()+" AND " + strCondition);
}
else {
strSql.Append(" where AGENTFEE=" + agentfee.ToString());
}
strSql.Append(" order by BSNO,SORT");
return SetFeeData(strSql);
}
private static List<MsOpSubSeaOrderFee> SetFeeData(StringBuilder strSql)
{
var bodyList = new List<MsOpSubSeaOrderFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaOrderFee data = new MsOpSubSeaOrderFee();
#region Set DB data to Object
data.FEEID = Convert.ToString(reader["FEEID"]);//编号
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.FeeName = Convert.ToString(reader["FEENAME"]);//费用名称
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);//单价
data.Unit = Convert.ToString(reader["UNIT"]);//单价
if (reader["QUANTITY"] != DBNull.Value)
data.Quantity = Convert.ToDecimal(reader["QUANTITY"]);//数量
if (reader["AMOUNT"] != DBNull.Value)
data.Amount = Convert.ToDecimal(reader["AMOUNT"]);//金额
data.Currency = Convert.ToString(reader["CURRENCY"]);//币别
data.FeeFrt = Convert.ToString(reader["FEEFRT"]);//FRT
if (reader["EXCHANGERATE"] != DBNull.Value)
data.ExChangerate = Convert.ToDecimal(reader["EXCHANGERATE"]);//汇率
data.REMARK = Convert.ToString(reader["REMARK"]);//备
if (reader["AGENTFEE"] != DBNull.Value)
data.AGENTFEE = Convert.ToInt16(reader["AGENTFEE"]);
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);//排序
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
static public List<MsOpSubSeaOrderFee> GetDefFeeList(string Companyid, int agentfee)
{
var strSql = new StringBuilder();
strSql.Append("SELECT FEENAME,CURRENCY,EXCHANGERATE,[UNITPRICE],1 AS QUANTITY,SORT,AGENTFEE,UNIT");
strSql.Append(" FROM company_orderfee WHERE COMPANYID='" + Companyid + "' and AGENTFEE="+agentfee.ToString());
strSql.Append(" order by SORT");
return SetDefFeeData(strSql);
}
private static List<MsOpSubSeaOrderFee> SetDefFeeData(StringBuilder strSql)
{
var bodyList = new List<MsOpSubSeaOrderFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaOrderFee data = new MsOpSubSeaOrderFee();
#region Set DB data to Object
data.FEEID = Guid.NewGuid().ToString();//编号
data.BSNO = "*";//业务编号
data.FeeName = Convert.ToString(reader["FEENAME"]);//费用名称
data.Unit = Convert.ToString(reader["UNIT"]);//费用名称
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);//单价
data.Quantity =1;//数量
if (reader["UNITPRICE"] != DBNull.Value)
data.Amount = Convert.ToDecimal(reader["UNITPRICE"]); //金额
data.Currency = Convert.ToString(reader["CURRENCY"]);//币别
if (reader["EXCHANGERATE"] != DBNull.Value)
data.ExChangerate = Convert.ToDecimal(reader["EXCHANGERATE"]);//汇率
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);//排序
if (reader["AGENTFEE"] != DBNull.Value)
data.AGENTFEE = Convert.ToInt16(reader["AGENTFEE"]);//
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
static public List<MsCompanyOrderFee> GetCompanyFeeList(string strCondition, string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,COMPANYID,FEENAME,CURRENCY,EXCHANGERATE,SORT,AGENTFEE,UNIT,UNITPRICE from company_orderfee");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where COMPANYID='" + companyid + "' AND " + strCondition);
}
else
{
strSql.Append(" where COMPANYID='" + companyid + "'");
}
strSql.Append(" order by SORT");
return SetCompanyFeeData(strSql);
}
private static List<MsCompanyOrderFee> SetCompanyFeeData(StringBuilder strSql)
{
var bodyList = new List<MsCompanyOrderFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCompanyOrderFee data = new MsCompanyOrderFee();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//编号
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);//
data.FEENAME = Convert.ToString(reader["FEENAME"]);//
data.UNIT = Convert.ToString(reader["UNIT"]);//
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);//
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);//
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);//
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);//
if (reader["AGENTFEE"] != DBNull.Value)
data.AGENTFEE = Convert.ToInt16(reader["AGENTFEE"]);//
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);//排序
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 保存费用
public static DBResult SaveFee(MsOpSubSeaOrder headData, List<MsOpSubSeaOrderFee> bodyList, string userid,string agentfee)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.BSNO == "*")
{
var cmdInsert = db.GetSqlStringCommand(@"insert into op_sub_seaorder_fee (FEEID,BSNO,FEENAME,UNITPRICE,QUANTITY,AMOUNT,CURRENCY,EXCHANGERATE,FEEFRT,REMARK,SORT,Agentfee) values (newid(),'" + headData.BSNO + "','" + enumValue.FeeName + "'," + enumValue.UnitPrice + "," + enumValue.Quantity + "," + enumValue.Amount + ",'" + enumValue.Currency + "'," + enumValue.ExChangerate + ",'" + enumValue.FeeFrt + "','" + enumValue.REMARK + "'," + enumValue.SORT + "," +agentfee+ ")");
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(@"update op_sub_seaorder_fee set FEENAME='" + enumValue.FeeName + "',QUANTITY=" + enumValue.Quantity + ",UNITPRICE=" + enumValue.UnitPrice + ",AMOUNT=" + enumValue.Amount + ",CURRENCY='" + enumValue.Currency + "',EXCHANGERATE=" + enumValue.ExChangerate + ",SORT=" + enumValue.SORT + ",REMARK='" + enumValue.REMARK + "',FEEFRT='" + enumValue.FeeFrt + "',agentfee="+agentfee+" where BSNO='" + enumValue.BSNO + "' AND FEEID='" + enumValue.FEEID + "'");
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult SaveCompanyOrderFee(List<MsCompanyOrderFee> bodyList, string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from company_orderfee where COMPANYID='" + companyid + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdInsert =
db.GetSqlStringCommand(
@"insert into company_orderfee (GID,COMPANYID,FEENAME,UNIT,CURRENCY,UNITPRICE,SORT,EXCHANGERATE,AGENTFEE)
values (@GID,@COMPANYID,@FEENAME,@UNIT,@CURRENCY,@UNITPRICE,@SORT,@EXCHANGERATE,@AGENTFEE) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String,companyid);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@SORT", DbType.Int32, enumValue.SORT);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.EXCHANGERATE);
db.AddInParameter(cmdInsert, "@AGENTFEE", DbType.Int32, enumValue.AGENTFEE);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
public static DBResult SaveArrivalFee(MsOpSubSeaArrival headData, List<MsOpSubSeaArrivalFee> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.ORDNO == "*")
{
var cmdInsert = db.GetSqlStringCommand(@"insert into op_sub_seaorder_arrivalfee (GID,ORDNO,FEENAME,UNITPRICE,QUANTITY,UNIT,AMOUNTJPY,AMOUNTUSD,CURRENCY,REMARK,SORT,EXCHANGERATE) values (newid(),'" + headData.ORDNO + "','" + enumValue.FeeName + "'," + enumValue.UnitPrice + "," + enumValue.Quantity + ",'" + enumValue.Unit + "'," + enumValue.AmountJpy + "," + enumValue.AmountUsd + ",'" + enumValue.Currency + "','" + enumValue.REMARK + "'," + enumValue.SORT + "," + enumValue.EXCHANGERATE + ")");
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
var cmdUpdate = db.GetSqlStringCommand(@"update op_sub_seaorder_arrivalfee set FEENAME='" + enumValue.FeeName + "',QUANTITY=" + enumValue.Quantity + ",UNITPRICE=" + enumValue.UnitPrice + ",UNIT='" + enumValue.Unit + "',AMOUNTJPY=" + enumValue.AmountJpy + ",AMOUNTUSD=" + enumValue.AmountUsd + ",CURRENCY='" + enumValue.Currency + "',SORT=" + enumValue.SORT + ",EXCHANGERATE="+enumValue.EXCHANGERATE+",REMARK='" + enumValue.REMARK + "' where ORDNO='" + enumValue.ORDNO + "' AND GID='" + enumValue.FEEID + "'");
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
//
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
//判断单号是否重复
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(BSNO) AS CT from op_sub_seaorder");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct=0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
#endregion
#region 删除
public static DBResult DeleteDetail(MsOpSubSeaOrder headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from op_seaorder_ctn where BSNO='" + headData.BSNO + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdDeleteFee = db.GetSqlStringCommand("delete from op_sub_seaorder_fee where BSNO='" + headData.BSNO + "'");
db.ExecuteNonQuery(cmdDeleteFee, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
public static DBResult DeleteDetail2(MsOpSubSeaOrderCtn headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from op_seaorder_ctn where CTN_ID='" + headData.CTN_ID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
getCNTRTOTAL(headData.BSNO,"");
result.Success = true;
result.Message = "操作成功";
return result;
}
public static DBResult DeleteFeeDetail(MsOpSubSeaOrderFee headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from op_sub_seaorder_fee where CTN_ID='" + headData.FEEID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
#endregion
#region 到货通知
static public List<MsOpSubSeaOrder> GetArrivalDataList(string strCondition, string billtype, int ortype, string userid, string usercode, string companyid, string sort = null)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and (Companyid='" + companyid + "' or Agentid='" + companyid + "') and BILLTYPE=" + billtype;
}
else
{
strCondition = " (Companyid='" + companyid + "' or Agentid='" + companyid + "') and BILLTYPE=" + billtype;
}
//
var strSql = new StringBuilder();
strSql.Append("SELECT ORDNO,BSNO,ORSTATUS,ORTYPE,ORREASON,BSDATE,MBLNO,HBLNO,CUSTOMERNAME");
strSql.Append(",SHIPPER,CONSIGNEE,NOTIFYPARTY,VESSEL,VOYNO,ETD,ETA,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE");
strSql.Append(",PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT");
strSql.Append(",PREPARDAT,PAYABLEAT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS");
strSql.Append(",KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN");
strSql.Append(",REMARK,AUDITOPERATOR,AUDITDATE,DPAGE,DLABEL,LINKMAN,BILLTYPE,COMPANYID,AGENTID,SPCHARGE");
strSql.Append(",SHIPPERCODE,SHIPPERCOUNTRY,SHIPPERTEL,CONSIGNEECODE,CONSIGNEECOUNTRY,CONSIGNEETEL,NOTIFYPARTYCODE,NOTIFYPARTYCOUNTRY,NOTIFYPARTYTEL");
if (ortype == 1)
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN 'RECEIVE' WHEN '1' THEN 'POSTED' WHEN '2' THEN 'REJECTED' else 'ENTRY' end) as ORSTATUSREF ");
}
else
{
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN '确认' WHEN '1' THEN '提交' WHEN '2' THEN '驳回' else '录入' end) as ORSTATUSREF ");
}
strSql.Append(",(SELECT [NAME] from company where GID=B.COMPANYID) as COMPANY ");
strSql.Append(",(SELECT [NAME] from company where GID=B.AGENTID) as AGENT ");
strSql.Append(" from op_sub_seaorder B");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BSDATE desc");
}
return SetData(strSql);
}
static public List<MsOpSubSeaArrival> GetArrivalData(string condition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,ORDNO,INPUTBY,BSDATE,REFNO,MBLNO,HBLNO,MESSRS,");
strSql.Append("VESSEL,VOYNO,ETD,ETA,FREETIME,PlACERECEIPT,PORTLOADID,PORTLOAD,");
strSql.Append("PORTDISCHARGEID,PORTDISCHARGE,PLACEDELIVERYID,PLACEDELIVERY,ISSUETYPE,OFFICEADDR,DOADDR,");
strSql.Append("BLFRT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GROSSWEIGHT,MEASUREMENT,");
strSql.Append("PKGS,KINDPKGS,KGS,CBM,TOTALNO,CNTRTOTAL,REMARK,AMOUNTUSD,AMOUNTJPY,MARKCOUNT,EXCHANGERATE ");
strSql.Append(" from op_sub_seaorder_arrival");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by REFNO ");
}
return SetArrivalData(strSql);
}
static public string GetArrivalDataStr(string condition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,ORDNO,INPUTBY,BSDATE,REFNO,MBLNO,HBLNO,MESSRS,");
strSql.Append("VESSEL,VOYNO,ETD,ETA,FREETIME,PlACERECEIPT,PORTLOADID,PORTLOAD,");
strSql.Append("PORTDISCHARGEID,PORTDISCHARGE,PLACEDELIVERYID,PLACEDELIVERY,ISSUETYPE,OFFICEADDR,DOADDR,");
strSql.Append("BLFRT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GROSSWEIGHT,MEASUREMENT,");
strSql.Append("PKGS,KINDPKGS,KGS,CBM,TOTALNO,CNTRTOTAL,REMARK,AMOUNTUSD,AMOUNTJPY");
strSql.Append(" from op_sub_seaorder_arrival");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
// var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sort))
{
strSql.Append(" order by " + sort);
}
else
{
strSql.Append(" order by REFNO ");
}
return strSql.ToString();
}
private static List<MsOpSubSeaArrival> SetArrivalData(StringBuilder strSql)
{
var headList = new List<MsOpSubSeaArrival>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaArrival data = new MsOpSubSeaArrival();
#region Set DB data to Object
data.ORDNO = Convert.ToString(reader["ORDNO"]);//委托
data.GID = Convert.ToString(reader["GID"]);//业务编号
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]);//接单日期
data.MBLNO = Convert.ToString(reader["MBLNO"]);//主提单号
data.HBLNO = Convert.ToString(reader["HBLNO"]);//分提单号
data.REFNO = Convert.ToString(reader["REFNO"]);//分提单号
data.MESSRS = Convert.ToString(reader["MESSRS"]);//收货人内容
data.VESSEL = Convert.ToString(reader["VESSEL"]);//船名
data.VOYNO = Convert.ToString(reader["VOYNO"]);//航次
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");//到港日期
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToString("yyyy-MM-dd");//预抵日期
if (reader["FREETIME"] != DBNull.Value)
data.FREETIME = Convert.ToDateTime(reader["FREETIME"]).ToString("yyyy-MM-dd");//预抵日期
data.PORTLOADID = Convert.ToString(reader["PORTLOADID"]);//装货港代码
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);//装货港
data.PORTDISCHARGEID = Convert.ToString(reader["PORTDISCHARGEID"]);//卸货港代码
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);//卸货港
data.PlACERECEIPT = Convert.ToString(reader["PlACERECEIPT"]);//收货地
data.PLACEDELIVERYID = Convert.ToString(reader["PLACEDELIVERYID"]);//交货地代码
data.PLACEDELIVERY = Convert.ToString(reader["PLACEDELIVERY"]);//交货地
data.OFFICEADDR = Convert.ToString(reader["OFFICEADDR"]);//交货地
data.DOADDR = Convert.ToString(reader["DOADDR"]);//交货地
data.ISSUETYPE = Convert.ToString(reader["ISSUETYPE"]);//签单方式
data.BLFRT = Convert.ToString(reader["BLFRT"]);//付费方式
data.SERVICE = Convert.ToString(reader["SERVICE"]);//运输条款
data.MARKS = Convert.ToString(reader["MARKS"]);//唛头
data.NOPKGS = Convert.ToString(reader["NOPKGS"]);//件数包装
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);//货物描述
data.GROSSWEIGHT = Convert.ToString(reader["GROSSWEIGHT"]);//货物毛重
data.MEASUREMENT = Convert.ToString(reader["MEASUREMENT"]);//货物尺码
data.PKGS = Convert.ToInt32(reader["PKGS"]);//件数
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);//件数包装
data.KGS =string.Format("{0:0.00}",Convert.ToDecimal(reader["KGS"]));//毛重
data.CBM =string.Format("{0:0.000}", Convert.ToDecimal(reader["CBM"]));//立方数/尺码
data.TOTALNO = Convert.ToString(reader["TOTALNO"]);//件数大写
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);//集装箱全部内容
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);//录入人
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
if (reader["AMOUNTUSD"] != DBNull.Value)
data.AMOUNTUSD = Convert.ToDecimal(reader["AMOUNTUSD"]);
if (reader["AMOUNTJPY"] != DBNull.Value)
data.AMOUNTJPY = Convert.ToDecimal(reader["AMOUNTJPY"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static MsOpSubSeaArrival SetDefArrivalData(MsOpSubSeaOrder bill, string username)
{
var ctnlist=GetBodyList("BSNO='"+bill.BSNO+"'");
var ctnliststr="";
var ctnnum=0;
if (ctnlist != null)
{
foreach (var enumValue in ctnlist)
{
ctnliststr=ctnliststr+enumValue.CNTRNO+"("+enumValue.CTNALL+")\r\n";
ctnnum = ctnnum + 1;
}
}
var headList = new MsOpSubSeaArrival();
headList.ORDNO = bill.ORDNO;//委托
headList.GID ="*";//业务编号
headList.BSDATE = DateTime.Now;//接单日期
headList.MBLNO ="32ES"+bill.MBLNO;//主提单号
headList.HBLNO =bill.MBLNO;//分提单号
headList.MESSRS =bill.CONSIGNEE;//收货人内容
headList.VESSEL =bill.VESSEL;//船名
headList.VOYNO =bill.VOYNO;//航次
headList.ETD = bill.ETD;
headList.ETA = bill.ETA;
headList.REFNO ="";
headList.PlACERECEIPT = bill.PlACERECEIPT;
headList.PORTLOAD = bill.PORTLOAD;
headList.PORTDISCHARGE = bill.PORTDISCHARGE;
headList.PLACEDELIVERY = bill.PLACEDELIVERY;
headList.ISSUETYPE = bill.ISSUETYPE;
headList.BLFRT = bill.BLFRT;
headList.SERVICE = bill.SERVICE;
headList.MARKS = bill.MARKS + "\r\n" + ctnliststr;
headList.NOPKGS = bill.NOPKGS;
headList.TOTALNO = ctnnum.ToString() + " CONTAINERS (" + bill.PKGS.ToString() + " " + bill.KINDPKGS + ")";
var str = bill.DESCRIPTION;
str = str.Replace("\n", "\\");
str = str.Replace("\r", " ");
string[] StrList = str.Split('\\');
headList.DESCRIPTION = ctnnum.ToString() + " CONTAINERS (" + bill.PKGS.ToString() + " " + bill.KINDPKGS + ")" +
"\r\n\r\n ";
for (var i = 0; i <= StrList.Length - 1; i++)
{
headList.DESCRIPTION = headList.DESCRIPTION + "\r\n " + StrList[i];
}
headList.DESCRIPTION=headList.DESCRIPTION + "\r\n\r\n " + bill.BLFRT;
headList.GROSSWEIGHT = bill.GROSSWEIGHT;
headList.MEASUREMENT = bill.MEASUREMENT;
headList.KGS = string.Format("{0:0.00}",bill.KGS);
headList.CBM = string.Format("{0:0.000}",bill.CBM);
headList.INPUTBY = username;
return headList;
}
static public List<MsOpSubSeaArrivalFee> GetArrivalFeeList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[ORDNO],[FEENAME],[UNITPRICE],[QUANTITY],EXCHANGERATE,[AMOUNTJPY],[AMOUNTUSD],[CURRENCY],[REMARK],[SORT],UNIT from op_sub_seaorder_arrivalfee");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by ORDNO,SORT");
return SetArrivalFeeData(strSql);
}
private static List<MsOpSubSeaArrivalFee> SetArrivalFeeData(StringBuilder strSql)
{
var bodyList = new List<MsOpSubSeaArrivalFee>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaArrivalFee data = new MsOpSubSeaArrivalFee();
#region Set DB data to Object
data.FEEID = Convert.ToString(reader["GID"]);//编号
data.ORDNO = Convert.ToString(reader["ORDNO"]);//业务编号
data.FeeName = Convert.ToString(reader["FEENAME"]);//费用名称
if (reader["UNITPRICE"] != DBNull.Value)
data.UnitPrice = Convert.ToDecimal(reader["UNITPRICE"]);//单价
data.Unit = Convert.ToString(reader["UNIT"]);//单价
if (reader["QUANTITY"] != DBNull.Value)
data.Quantity = Convert.ToDecimal(reader["QUANTITY"]);//数量
if (reader["AMOUNTJPY"] != DBNull.Value)
data.AmountJpy = Convert.ToDecimal(reader["AMOUNTJPY"]);//金额
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);//金额
if (reader["AMOUNTUSD"] != DBNull.Value)
data.AmountUsd = Convert.ToDecimal(reader["AMOUNTUSD"]);//金额
data.Currency = Convert.ToString(reader["CURRENCY"]);//币别
if (reader["SORT"] != DBNull.Value)
data.SORT = Convert.ToInt16(reader["SORT"]);//排序
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static int p_update_ARRIVEL(string bsno)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_arrival");
db.AddInParameter(cmd, "@con_no", DbType.String, bsno);
db.ExecuteNonQuery(cmd);
return 0;
}
static public List<MsOpSubSeaArrivalYard> GetArrivalYardList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[YARDCODE],[DESCRIP] from op_sub_seaorder_arrival_yard");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by YARDCODE");
return SetArrivalYardData(strSql);
}
private static List<MsOpSubSeaArrivalYard> SetArrivalYardData(StringBuilder strSql)
{
var bodyList = new List<MsOpSubSeaArrivalYard>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSubSeaArrivalYard data = new MsOpSubSeaArrivalYard();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);//编号
data.YARDCODE = Convert.ToString(reader["YARDCODE"]);//
data.DESCRIP = Convert.ToString(reader["DESCRIP"]);//
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
public static DBResult DeleteArrivalFeeDetail(MsOpSubSeaArrivalFee headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from op_sub_seaorder_arrivalfee where GID='" + headData.FEEID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
#endregion
#region 集装箱动态
static public List<MsOpOrderCtnStatus> GetCtnStatusList(string strCondition,string billtype,string companyid)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and (b.Companyid='" + companyid + "' or Agentid='"+companyid+"') and b.BILLTYPE=" + billtype;
}
else
{
strCondition = " (b.Companyid='" + companyid + "' or Agentid='"+companyid+"') and b.BILLTYPE=" + billtype;
}
var strSql = new StringBuilder();
strSql.Append("SELECT c.[CTN_ID],c.[BSNO],c.[CTNCODE],c.[CTNALL],c.[CNTRNO],c.[SEALNO],c.[PKGS],c.[KGS],c.[CBM],c.[REMARK],c.[STATUS], ");
strSql.Append(" c.[CTNSTATUS],c.[CTNSTATUSDATE],b.[ORSTATUS],b.[BSDATE],b.[MBLNO],b.[VESSEL],b.[VOYNO],b.[ETD],b.[ETA],b.[PORTLOADID],b.[PORTLOAD], ");
strSql.Append(" b.[PORTDISCHARGEID],b.[PORTDISCHARGE],b.[PLACEDELIVERYID],b.[PLACEDELIVERY],b.[DESTINATIONID],b.[DESTINATION],b.[SERVICE],b.[CNTRTOTAL],b.[CARGOID] ");
strSql.Append(" from op_seaorder_ctn c left join op_sub_seaorder b on (b.BSNO=c.BSNO)");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by b.BSDATE DESC");
return SetCtnStatusData(strSql);
}
private static List<MsOpOrderCtnStatus> SetCtnStatusData(StringBuilder strSql)
{
var bodyList = new List<MsOpOrderCtnStatus>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpOrderCtnStatus data = new MsOpOrderCtnStatus();
#region Set DB data to Object
data.CTN_ID = Convert.ToString(reader["CTN_ID"]);//编号
data.BSNO = Convert.ToString(reader["BSNO"]);//业务编号
data.CTNCODE = Convert.ToString(reader["CTNCODE"]);//表现形式
data.CTNALL = Convert.ToString(reader["CTNALL"]);//表现形式
data.CNTRNO = Convert.ToString(reader["CNTRNO"]);//箱号
data.SEALNO = Convert.ToString(reader["SEALNO"]);//封号
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToInt32(reader["PKGS"]);//件数
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);//重量(货重)
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);//尺码
data.STATUS = Convert.ToString(reader["STATUS"]);
data.REMARK = Convert.ToString(reader["REMARK"]);//备注
data.CTNSTATUS = Convert.ToString(reader["CTNSTATUS"]);
data.CTNSTATUSDATE = Convert.ToString(reader["CTNSTATUSDATE"]);
data.ORSTATUS = Convert.ToString(reader["ORSTATUS"]);//
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]);//
data.MBLNO = Convert.ToString(reader["MBLNO"]);//
data.VESSEL = Convert.ToString(reader["VESSEL"]);//船名
data.VOYNO = Convert.ToString(reader["VOYNO"]);//航次
if (reader["ETD"] != DBNull.Value)
data.ETD = Convert.ToDateTime(reader["ETD"]).ToShortDateString();//到港日期
if (reader["ETA"] != DBNull.Value)
data.ETA = Convert.ToDateTime(reader["ETA"]).ToShortDateString();//到港日期
data.PORTLOADID = Convert.ToString(reader["PORTLOADID"]);//装货港代码
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);//装货港
data.PORTDISCHARGEID = Convert.ToString(reader["PORTDISCHARGEID"]);//卸货港代码
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);//卸货港
data.PLACEDELIVERYID = Convert.ToString(reader["PLACEDELIVERYID"]);//交货地代码
data.PLACEDELIVERY = Convert.ToString(reader["PLACEDELIVERY"]);//交货地
data.DESTINATIONID = Convert.ToString(reader["DESTINATIONID"]);//目的地代码
data.DESTINATION = Convert.ToString(reader["DESTINATION"]);//目的地
data.SERVICE = Convert.ToString(reader["SERVICE"]);//运输条款
data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]);//集装箱全部内容
data.CARGOID = Convert.ToString(reader["CARGOID"]);//货物标识
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 集装箱动态维护
public static DBResult UpdateCtnStatus(List<MsOpOrderCtnStatus> bodylist, string type, string opdatetime,string opname)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (var OrderData in bodylist)
{
if (type == "1")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Shipper ON "+opdatetime+"' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "2")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Receipt ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "3")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Loading ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "4")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' OnBorad ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "5")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Discharging ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "6")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Delivery ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "7")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Consignee ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
else if (type == "8")
{
var cmdupdateModify = db.GetSqlStringCommand("update V_ORDER_CTNSTATUS set ctnstatus=' Return Ctn ON " + opdatetime + "' where CTN_ID=@ID");
cmdupdateModify.Parameters.Clear();
db.AddInParameter(cmdupdateModify, "@ID", DbType.String, OrderData.CTN_ID);
db.ExecuteNonQuery(cmdupdateModify, tran);
}
if (type == "4" || type == "5")
{
importBox(OrderData, opname);
}
}
result = new DBResult();
result.Success = true;
result.Message = "提交成功";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
#region 查询当前登录用户
static public string getuser(string userid)
{
string sql = "select showname from [user] where gid='" + userid + "'";
return SetUser(sql);
}
private static string SetUser(string sb)
{
string s = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sb.ToString()))
{
while (reader.Read())
{
#region Set DB data to Object
s = Convert.ToString(reader["showname"]);
#endregion
}
reader.Close();
}
return s;
}
#endregion
public static DBResult UpdateOpCtnStatus(List<MsOpOrderCtnStatus> bodylist, string time, string remarks,string type,string userid)
{
var result = new DBResult();
string opdatetime = DateTime.Now.ToShortDateString();
StringBuilder sb = new StringBuilder("");
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
string msg = "";
string insertsql = string.Empty;
try
{
if (bodylist!=null)
{
foreach (var enumValue in bodylist)
{
string sql = " update container_info set cntype='" + enumValue.CTNALL + "' where cntrno='" + enumValue.CNTRNO + "'";
var cmd = db.GetSqlStringCommand(sql);
int a = db.ExecuteNonQuery(cmd, tran);
if (a == 0)
{
sb.Append(enumValue.CNTRNO+",");
}
else
{
if (type == "1")
{
insertsql = string.Format("insert into container_business(jcyy,box_no,vessel,voyage,blno,etd,"
+ "fobportname,operman,opertime,Remarks,jctime) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
"装船", enumValue.CNTRNO, enumValue.VESSEL, enumValue.VOYNO, enumValue.MBLNO, Convert.ToDateTime(time).ToString("yyyy-MM-dd HH:mm:ss"), enumValue.PORTLOAD, getuser(userid), opdatetime, remarks, Convert.ToDateTime(time).ToString("yyyy-MM-dd HH:mm:ss"));
}
else
{
insertsql = string.Format("insert into container_business(jcyy,box_no,vessel,voyage,blno,reachtime,"
+ "positionname,operman,opertime,Remarks,jctime) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
"卸船", enumValue.CNTRNO, enumValue.VESSEL, enumValue.VOYNO, enumValue.MBLNO, Convert.ToDateTime(time).ToString("yyyy-MM-dd HH:mm:ss"), enumValue.PORTDISCHARGE, getuser(userid), opdatetime, remarks, Convert.ToDateTime(time).ToString("yyyy-MM-dd HH:mm:ss"));
}
var cmdmx = db.GetSqlStringCommand(insertsql);
db.ExecuteNonQuery(cmdmx, tran);
}
}
}
msg = sb.ToString();
result.Success = true;
if (msg!="")
{
result.Message = "更新成功,以下箱号不存在,故未能更新:</br>" + msg;
}
else
{
result.Message = "更新成功";
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static string importBox(MsOpOrderCtnStatus headdata, string username)
{
string str = "";
if (isCntrNO(headdata.CNTRNO))
{
try
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
DataSet ds = T_ALL_DA.GetAllSQL("select * from container_business where vessel='" + headdata.VESSEL + "' and Voyage='" + headdata.VOYNO + "' and Box_No='" + headdata.CNTRNO + "'");
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdupdate = db.GetSqlStringCommand("update container_business set BLNO=@BLNO,Etd=@Etd,State=@State,Position=@Position,ReachTime=@ReachTime,fobport=@fobport,operman=@operman ,opertime=@opertime,Remarks=@Remarks where Vessel=@Vessel and Voyage=@Voyage and Box_No=@Box_No");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BLNO", DbType.String, headdata.MBLNO);
db.AddInParameter(cmdupdate, "@Vessel", DbType.String, headdata.VESSEL);
db.AddInParameter(cmdupdate, "@Voyage", DbType.String, headdata.VOYNO);
db.AddInParameter(cmdupdate, "@Box_No", DbType.String, headdata.CNTRNO);
db.AddInParameter(cmdupdate, "@Etd", DbType.String, headdata.ETD);
db.AddInParameter(cmdupdate, "@State", DbType.String, setFE(headdata.STATUS));
db.AddInParameter(cmdupdate, "@Position", DbType.String, GetPortID(headdata.PORTDISCHARGE));
db.AddInParameter(cmdupdate, "@ReachTime", DbType.String, headdata.ETA);
db.AddInParameter(cmdupdate, "@fobport", DbType.String, GetPortID(headdata.PORTLOAD));
db.AddInParameter(cmdupdate, "@operman", DbType.String, username);
db.AddInParameter(cmdupdate, "@opertime", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdupdate, "@Remarks", DbType.String,"");
db.ExecuteNonQuery(cmdupdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
}
else
{
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdupdate = db.GetSqlStringCommand("insert into container_business (BLNO,Vessel,Voyage,Box_No,Etd,State,Position,ReachTime,fobport,operman,opertime)values(@BLNO,@Vessel,@Voyage,@Box_No,@Etd,@State,@Position,@ReachTime,@fobport,@operman,@opertime)");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BLNO", DbType.String, headdata.MBLNO);
db.AddInParameter(cmdupdate, "@Vessel", DbType.String, headdata.VESSEL);
db.AddInParameter(cmdupdate, "@Voyage", DbType.String, headdata.VOYNO);
db.AddInParameter(cmdupdate, "@Box_No", DbType.String, headdata.CNTRNO);
db.AddInParameter(cmdupdate, "@Etd", DbType.String, headdata.ETD);
db.AddInParameter(cmdupdate, "@State", DbType.String, setFE(headdata.STATUS));
db.AddInParameter(cmdupdate, "@Position", DbType.String, GetPortID(headdata.PORTDISCHARGE));
db.AddInParameter(cmdupdate, "@ReachTime", DbType.String, headdata.ETA);
db.AddInParameter(cmdupdate, "@fobport", DbType.String, GetPortID(headdata.PORTLOAD));
db.AddInParameter(cmdupdate, "@operman", DbType.String, username);
db.AddInParameter(cmdupdate, "@opertime", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdupdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
}
}
}
// BaseClass.db.SetSqlStrNonQuery("update container_info set status=" + setFE(dr["ISFULL"].ToString()) + ",Position='" + posi + "',positionname='" + posiname + "',Vessel='" + vsl + "',Voyage='" + val + "' where CntrNo='" + dr["CNTR NO"].ToString().Trim() + "'");
}
catch { }
}
else
{
str += headdata.CNTRNO + ",";
}
if (!string.IsNullOrEmpty(str.TrimEnd(',')))
{
str = "已导入,以下箱号不合法未能导入:\\n" + str.TrimEnd(',');
}
else
str += "导入成功";
return str;
}
//public static string getPosition(string position)
//{
// string str = "";
// try
// {
// str = BaseClass.db.GetSqlStrScalar("select portid from code_disport where cname='" + position + "'").ToString();
// }
// catch { }
// return str;
//}
public static string getDate(string date)
{
string str = null;
try
{
str = DateTime.Parse(date).ToString("yyyy-MM-dd");
}
catch { }
return str;
}
public static string getStatus(string s)
{
string str = null;
switch (s)
{
case "可用":
str = "1";
break;
case "已用":
str = "2";
break;
case "维修":
str = "3";
break;
case "停用":
str = "4";
break;
case "退租":
str = "5";
break;
case "灭失":
str = "6";
break;
case "卖出":
str = "7";
break;
}
return str;
}
public static string setFE(string s)
{
string str = null;
if (s.ToUpper() == "F")
str = "2";
else if (s.ToUpper() == "E")
str = "1";
return str;
}
public static bool isCntrNO(string no)
{
String regex = @"^[a-zA-Z]{4}\d{7}$";
if (Regex.IsMatch(no, regex))
{
return true;
}
else
{
return false;
}
}
static public string GetPortID(string PORT)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select PORTID from code_disport where PORT like '%" + PORT + "%'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["PORTID"]);
}
reader.Close();
}
return EDICODE;
}
#endregion
#region 引入集装箱和费用明细
static public string GetCustName(string GID)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select [NAME] from company where GID='" + GID + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["NAME"]);
}
reader.Close();
}
return EDICODE;
}
static public string GetCustID(string NAME)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select GID from company where [NAME]='" +NAME+ "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["GID"]);
}
reader.Close();
}
return EDICODE;
}
public static DBResult AddOrderDetail(string bsno, MsOpSubSeaOrder orderdata,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_ctn (CTN_ID,BSNO,CTNCODE,[SIZE],CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS)
values (@CTN_ID,@BSNO,@CTNCODE,@SIZE,@CTN,@CTNNUM,@TEU,@CTNALL,@CNTRNO,@SEALNO,@PKGS,@KGS,@CBM,@REMARK,@KINDPKGS) ");
var cmdInsertfee =
db.GetSqlStringCommand(
@"INSERT into ch_fee (GID, BSNO, FEETYPE, FEENAME, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,
EXCHANGERATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,TAXUNITPRICE)
values (@GID, @BSNO, @FEETYPE, @FEENAME, @CUSTOMERNAME,@UNIT,@UNITPRICE,@QUANTITY,@AMOUNT, @CURRENCY,
@EXCHANGERATE,@ENTEROPERATOR, @ENTERDATE,@ISOPEN, @ISADVANCEDPAY, @SORT, @FEESTATUS, @FEEFRT, @TAXRATE,@NOTAXAMOUNT,@ACCTAXRATE,@TAXUNITPRICE)");
var cmdUpdateOrder =
db.GetSqlStringCommand(
@"update op_sub_seaorder set ORSTATUS='0' where BSNO=@BSNO");
var bodyList = GetBodyList("BSNO='" + orderdata.BSNO + "'");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
int SIZE = int.Parse(enumValue.CTNALL.ToString().Trim().Substring(0, 2));
string CTN = enumValue.CTNALL.ToString().Trim().Substring(2);
int TEU = 1;
int iTEU = int.Parse(enumValue.CTNALL.ToString().Trim().Substring(0, 1));
if (iTEU == 4)
{
TEU = TEU * 2;
}
var feedoid = Guid.NewGuid().ToString();
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, feedoid);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@CTNCODE", DbType.String,enumValue.CTNCODE);
db.AddInParameter(cmdInsert, "@SIZE", DbType.Int16, SIZE);
db.AddInParameter(cmdInsert, "@CTN", DbType.String, CTN);
db.AddInParameter(cmdInsert, "@CTNNUM", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@TEU", DbType.Int16, TEU);
db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL);
db.AddInParameter(cmdInsert, "@CNTRNO", DbType.String, enumValue.CNTRNO);
db.AddInParameter(cmdInsert, "@SEALNO", DbType.String, enumValue.SEALNO);
db.AddInParameter(cmdInsert, "@PKGS", DbType.Int16, enumValue.PKGS);
db.AddInParameter(cmdInsert, "@KGS", DbType.Decimal, enumValue.KGS);
db.AddInParameter(cmdInsert, "@CBM", DbType.Decimal, enumValue.CBM);
db.AddInParameter(cmdInsert, "@TAREWEIGHT", DbType.Decimal, null);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.AddInParameter(cmdInsert, "@KINDPKGS", DbType.String,"");
db.ExecuteNonQuery(cmdInsert, tran);
}
}
var AfeeList = GetFeeList("BSNO='" + orderdata .BSNO+ "'", 1);
if (AfeeList != null)
{
foreach (var enumValue in AfeeList)
{
var feedoid = Guid.NewGuid().ToString();
cmdInsertfee.Parameters.Clear();
db.AddInParameter(cmdInsertfee, "@GID", DbType.String, feedoid);
db.AddInParameter(cmdInsertfee, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdInsertfee, "@FEETYPE", DbType.Int16, 1);
db.AddInParameter(cmdInsertfee, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsertfee, "@CUSTOMERNAME", DbType.String, GetCustName(orderdata.AGENTID));
db.AddInParameter(cmdInsertfee, "@UNIT", DbType.String,enumValue.Unit);
db.AddInParameter(cmdInsertfee, "@UNITPRICE", DbType.Decimal, enumValue.UnitPrice);
db.AddInParameter(cmdInsertfee, "@QUANTITY", DbType.Decimal, enumValue.Quantity);
db.AddInParameter(cmdInsertfee, "@AMOUNT", DbType.Decimal, enumValue.Amount);
db.AddInParameter(cmdInsertfee, "@CURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsertfee, "@EXCHANGERATE", DbType.Decimal, enumValue.ExChangerate);
db.AddInParameter(cmdInsertfee, "@ENTEROPERATOR", DbType.String, userid);
db.AddInParameter(cmdInsertfee, "@ENTERDATE", DbType.Date,DateTime.Now);
db.AddInParameter(cmdInsertfee, "@ISOPEN", DbType.String,"0");
db.AddInParameter(cmdInsertfee, "@ISADVANCEDPAY", DbType.String, "0");
db.AddInParameter(cmdInsertfee, "@SORT", DbType.Int16, enumValue.SORT);
db.AddInParameter(cmdInsertfee, "@FEESTATUS", DbType.Int16, 0);
db.AddInParameter(cmdInsertfee, "@FEEFRT", DbType.String, enumValue.FeeFrt);
db.AddInParameter(cmdInsertfee, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertfee, "@NOTAXAMOUNT", DbType.Decimal, enumValue.Amount);
db.AddInParameter(cmdInsertfee, "@ACCTAXRATE", DbType.Decimal,0);
db.AddInParameter(cmdInsertfee, "@TAXUNITPRICE", DbType.Decimal, enumValue.UnitPrice);
db.ExecuteNonQuery(cmdInsertfee, tran);
}
}
var feeList = GetFeeList("BSNO='" + orderdata.BSNO + "'", 0);
if (feeList != null)
{
foreach (var enumValue in feeList)
{
var feedoid = Guid.NewGuid().ToString();
cmdInsertfee.Parameters.Clear();
db.AddInParameter(cmdInsertfee, "@GID", DbType.String, feedoid);
db.AddInParameter(cmdInsertfee, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdInsertfee, "@FEETYPE", DbType.Int16, 1);
db.AddInParameter(cmdInsertfee, "@FEENAME", DbType.String, enumValue.FeeName);
db.AddInParameter(cmdInsertfee, "@CUSTOMERNAME", DbType.String, GetCustName(orderdata.COMPANYID));
db.AddInParameter(cmdInsertfee, "@UNIT", DbType.String, enumValue.Unit);
db.AddInParameter(cmdInsertfee, "@UNITPRICE", DbType.Decimal, enumValue.UnitPrice);
db.AddInParameter(cmdInsertfee, "@QUANTITY", DbType.Decimal, enumValue.Quantity);
db.AddInParameter(cmdInsertfee, "@AMOUNT", DbType.Decimal, enumValue.Amount);
db.AddInParameter(cmdInsertfee, "@CURRENCY", DbType.String, enumValue.Currency);
db.AddInParameter(cmdInsertfee, "@EXCHANGERATE", DbType.Decimal, enumValue.ExChangerate);
db.AddInParameter(cmdInsertfee, "@ENTEROPERATOR", DbType.String, userid);
db.AddInParameter(cmdInsertfee, "@ENTERDATE", DbType.Date, DateTime.Now);
db.AddInParameter(cmdInsertfee, "@ISOPEN", DbType.String, "0");
db.AddInParameter(cmdInsertfee, "@ISADVANCEDPAY", DbType.String, "0");
db.AddInParameter(cmdInsertfee, "@SORT", DbType.Int16, enumValue.SORT);
db.AddInParameter(cmdInsertfee, "@FEESTATUS", DbType.Int16, 0);
db.AddInParameter(cmdInsertfee, "@FEEFRT", DbType.String, enumValue.FeeFrt);
db.AddInParameter(cmdInsertfee, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertfee, "@NOTAXAMOUNT", DbType.Decimal, enumValue.Amount);
db.AddInParameter(cmdInsertfee, "@ACCTAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertfee, "@TAXUNITPRICE", DbType.Decimal, enumValue.UnitPrice);
db.ExecuteNonQuery(cmdInsertfee, tran);
}
}
cmdUpdateOrder.Parameters.Clear();
db.AddInParameter(cmdUpdateOrder, "@BSNO", DbType.String, bsno);
db.ExecuteNonQuery(cmdUpdateOrder, tran);
tran.Commit();
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult ImportSeaeDetail(string bsno, List<MsOpSeaeDetail> ctnbodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK)
values (@CTN_ID,@BSNO,@CTNCODE,@CTNALL,@CNTRNO,@SEALNO,@PKGS,@KGS,@CBM,@REMARK) ");
if (ctnbodyList != null)
{
foreach (var enumValue in ctnbodyList)
{
var feedoid = Guid.NewGuid().ToString();
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@CTN_ID", DbType.String, feedoid);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@CTNCODE", DbType.String, enumValue.CTNCODE);
db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL);
db.AddInParameter(cmdInsert, "@CNTRNO", DbType.String, enumValue.CNTRNO);
db.AddInParameter(cmdInsert, "@SEALNO", DbType.String, enumValue.SEALNO);
db.AddInParameter(cmdInsert, "@PKGS", DbType.Int16, enumValue.PKGS);
db.AddInParameter(cmdInsert, "@KGS", DbType.Decimal, enumValue.KGS);
db.AddInParameter(cmdInsert, "@CBM", DbType.Decimal, enumValue.CBM);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.REMARK);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
result.Success = true;
result.Message = "生成成功" + result.Message;
return result;
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "生成过程出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "生成成功" + result.Message;
return result;
}
#endregion
#region 判断是否有费用
public static bool GetFeeCount(string BSNO)
{
var isfee = false;
var strSql = new StringBuilder();
strSql.Append("Select count(*) as count ");
strSql.Append(" from ch_fee ");
strSql.Append(" where BSNO='" + BSNO+"'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = Convert.ToInt32(reader["count"]);
if (evData > 0) { isfee = true; };
}
reader.Close();
}
return isfee;
}
#endregion
#region 审核通过处理
static public List<MsOpSubSeaOrder> GetAuditDataList(string strCondition, string billtype, string userid, string usercode, string companyid, string sort = null)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and BILLTYPE=" + billtype;
}
else
{
strCondition = " BILLTYPE=" + billtype;
}
var strSql = new StringBuilder();
strSql.Append("SELECT ORDNO,BSNO,ORSTATUS,ORTYPE,ORREASON,BSDATE,MBLNO,HBLNO,CUSTOMERNAME");
strSql.Append(",SHIPPER,CONSIGNEE,NOTIFYPARTY,VESSEL,VOYNO,ETD,ETA,PlACERECEIPT,PORTLOADID,PORTLOAD,PORTDISCHARGEID,PORTDISCHARGE");
strSql.Append(",PLACEDELIVERYID,PLACEDELIVERY,DESTINATIONID,DESTINATION,NOBILL,ISSUETYPE,ISSUEDATE,ISSUEPLACE,BLFRT");
strSql.Append(",PREPARDAT,PAYABLEAT,[SERVICE],MARKS,NOPKGS,[DESCRIPTION],GOODSNAME,GROSSWEIGHT,MEASUREMENT,PKGS,KINDPKGS");
strSql.Append(",KGS,CBM,TOTALNO,CNTRTOTAL,INPUTBY,CARGOID,DCLASS,DUNNO,REEFERF,TEMPID,TEMPSET,TEMPMAX,TEMPMIN");
strSql.Append(",REMARK,AUDITOPERATOR,AUDITDATE,DPAGE,DLABEL,LINKMAN,BILLTYPE,COMPANYID,AGENTID,SPCHARGE");
strSql.Append(",SHIPPERCODE,SHIPPERCOUNTRY,SHIPPERTEL,CONSIGNEECODE,CONSIGNEECOUNTRY,CONSIGNEETEL,NOTIFYPARTYCODE,NOTIFYPARTYCOUNTRY,NOTIFYPARTYTEL");
strSql.Append(",(CASE ORSTATUS WHEN '0' THEN '引入' WHEN '1' THEN '提交' WHEN '2' THEN '驳回' else '录入' end) as ORSTATUSREF ");
strSql.Append(",(SELECT [NAME] from company where GID=B.COMPANYID ) as COMPANY ");
strSql.Append(",(SELECT [NAME] from company where GID=B.AGENTID) as AGENT ");
strSql.Append(",'' DRFEESTATUS");
strSql.Append(",'' CRFEESTATUS");
strSql.Append(" from op_sub_seaorder B");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BSDATE desc");
}
return SetData(strSql);
}
#endregion
#region 外代EDI
static public string GetVesselEdi(string Vessel)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select EDICODE from code_vessel where Vessel='" + Vessel + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["EDICODE"]);
}
reader.Close();
}
return EDICODE;
}
static public string GetPackageEDICode(string Package)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select EDICODE from CODE_PACKAGE where PKGS='" + Package + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["EDICODE"]);
}
reader.Close();
}
return EDICODE;
}
static public string GetCtnEDICode(string Ctn)
{
string EDICODE = "";
Ctn = Ctn.Replace("'", "''");
var strSql = new StringBuilder();
strSql.Append("select EDICODE from code_ctn where CTN='" + Ctn + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["EDICODE"]);
}
reader.Close();
}
return EDICODE;
}
static public decimal GetCtnWeight(string Ctn)
{
decimal CTNWEIGHT = 0;
Ctn = Ctn.Replace("'", "''");
var strSql = new StringBuilder();
strSql.Append("select CTNWEIGHT from code_ctn where CTN='" + Ctn + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CTNWEIGHT = Convert.ToDecimal(reader["CTNWEIGHT"]);
}
reader.Close();
}
return CTNWEIGHT;
}
static public string GetFrtEDICode(string FRT)
{
string EDICODE = "P";
var strSql = new StringBuilder();
strSql.Append("select EDICODE from code_frt where FRT='" + FRT + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["EDICODE"]);
}
reader.Close();
}
return EDICODE;
}
static public string GetLaneEDICode(string lane)
{
string EDICODE = "";
var strSql = new StringBuilder();
strSql.Append("select EDICODE from code_lanes where lane='" + lane + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
EDICODE = Convert.ToString(reader["EDICODE"]);
}
reader.Close();
}
return EDICODE;
}
public static string formatEdiStr(string str)
{
return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace(";", "?;");
}
public static List<System.String> formatlengthStr(string str, int length)
{
str = str.Replace("\n", "\\");
str = str.Replace("\r", " ");
string[] StrList = str.Split('\\');
var strtemp = "";
var strnewline = "";
var strtempnewline = "";
char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' };
List<System.String> DestList = new List<System.String>();
for (var i = 0; i <= StrList.Length - 1; i++)
{
if (StrList[i].Length <= length) DestList.Add(StrList[i]);
else
{
strtemp = StrList[i];
for (var j = 0; j < strtemp.Length; j++)
{
strtempnewline = strtempnewline + strtemp[j];
if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/'
|| strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-')
{
if ((strnewline.Length + strtempnewline.Length) <= length)
strnewline = strnewline + strtempnewline;
else
{
DestList.Add(strnewline);
strnewline = "";
}
strtempnewline = "";
}
}
}
}
return DestList;
}
public static string formatListStr(List<System.String> DestList, int lineCount)
{
var result = "";
for (var i = 0; i < lineCount; i++)
{
if (DestList.Count > i)
{
result = result + DestList[i] + ":";
}
else result = result + ":";
}
return result;
}
public static string BreakLongString(string SubjectString, int lineLength)
{
StringBuilder sb = new StringBuilder(SubjectString);
int offset = 0;
ArrayList indexList = buildInsertIndexList(SubjectString, lineLength);
for (int i = 0; i < indexList.Count; i++)
{
sb.Insert((int)indexList[i] + offset, '\n');
offset++;
}
return sb.ToString();
}
public static bool IsChinese(char c)
{
return (int)c > 0x80;
}
public static bool StringIsChinese(string str)
{
var result = false;
for (int i = 1; i < str.Length; i++)
{
if (IsChinese(str[i]))
{
result = true;
return result;
}
}
return result;
}
private static ArrayList buildInsertIndexList(string str, int maxLen)
{
int nowLen = 0;
ArrayList list = new ArrayList();
for (int i = 1; i < str.Length; i++)
{
if (IsChinese(str[i]))
{
nowLen += 2;
}
else
{
nowLen++;
}
if (nowLen > maxLen)
{
nowLen = 0;
list.Add(i);
}
}
return list;
}
public static string GetDateStr(string datestr, string dateformat)
{
var result = "";
if (datestr == null || datestr == "")
{
result = "";
}
else
{
result = Convert.ToDateTime(datestr).ToString(dateformat);
}
return result;
}
public static string IsCreateEdiWD(List<MsOpSubSeaOrder> headData)
{
var error = "";
foreach (var bill in headData)
{
if (bill.MBLNO == null || bill.MBLNO == "")
{ error = error + "|MBLNO Can't Empty"; }
if (bill.BLFRT == null || bill.BLFRT == "")
{ error = error + "|MBLNO" + bill.MBLNO + "PREPAID OR COLLECT Can't Empty"; }
if (bill.VESSEL == null || bill.VESSEL == "")
{ error = error + "|MBLNO" + bill.MBLNO + "Vessel Can't Empty"; }
if (bill.SHIPPERCODE == null || bill.SHIPPERCODE == "")
{ error = error + "|MBLNO" + bill.MBLNO + "Shipper Code Can't Empty"; }
if (bill.SHIPPERTEL == null || bill.SHIPPERTEL == "")
{ error = error + "|MBLNO" + bill.MBLNO + "Shipper Tel Can't Empty"; }
if (bill.CONSIGNEECODE == null || bill.CONSIGNEECODE == "")
{ error = error + "|MBLNO" + bill.MBLNO + "Consignee Code Can't Empty"; }
if (bill.CONSIGNEETEL == null || bill.CONSIGNEETEL == "")
{ error = error + "|MBLNO" + bill.MBLNO + "Consignee Tel Can't Empty"; }
if (bill.VOYNO == null || bill.VOYNO == "")
{ error = error + "|MBLNO" + bill.MBLNO + "VoyNo Can't Empty"; }
if (bill.PORTLOADID == null || bill.PORTLOADID == "")
{ error = error + "|MBLNO" + bill.MBLNO + "PORTLOAD CODE Can't Empty"; }
if (bill.PORTLOAD == null || bill.PORTLOAD == "")
{ error = error + "|MBLNO" + bill.MBLNO + "PORTLOAD Can't Empty"; }
if (bill.ETD == null || bill.ETD == "")
{
error = error + "|MBLNO" + bill.MBLNO + "ETD Can't Empty";
return error;
}
if (bill.PORTDISCHARGEID == null || bill.PORTDISCHARGEID == "")
{ error = error + "|MBLNO" + bill.MBLNO + "PORTDISCHARGE CODE Can't Empty"; }
if (bill.DESTINATION == null || bill.DESTINATION == "")
{ error = error + "|MBLNO" + bill.MBLNO + "PORTDISCHARGE Can't Empty"; }
//if (GetPackageEDICode(bill.KINDPKGS) == "")
//{ error = error + "|提单号:" + bill.MBLNO + "包装EDI代码不能为空"; }
if (bill.DESCRIPTION == null || bill.DESCRIPTION == "")
{ error = error + "|MBLNO" + bill.MBLNO + "DESCRIPTION Can't Empty"; }
if (bill.MARKS == null || bill.MARKS == "")
{ error = error + "|MBLNO" + bill.MBLNO + "MARKS Can't Empty"; }
//if (bill.PKGS == 0)
//{ error = error + "|MBLNO" + bill.MBLNO + "PKGS Can't Empty"; }
if (bill.CARGOID == null || bill.CARGOID == "")
{ error = error + "|MBLNO" + bill.MBLNO + "CARGO CODE Can't Empty"; }
if (bill.CARGOID == "D")
{
if (bill.DCLASS == null || bill.DCLASS == "")
{ error = error + "|MBLNO" + bill.MBLNO + " DANGEROUS CLASS Can't Empty"; }
if (bill.DUNNO == null || bill.DUNNO == "")
{ error = error + "|MBLNO" + bill.MBLNO + "UNDG NO. Can't Empty"; }
}
if (bill.CARGOID == "R")
{
if (bill.TEMPSET == null || bill.TEMPSET == "")
{ error = error + "|MBLNO" + bill.MBLNO + "设置温度不能为空"; }
}
var ctnlist = GetBodyList("BSNO='" + bill.BSNO + "'");
if (ctnlist.Count == 0) { error = error + "|MBLNO" + bill.MBLNO + "CTN DETTAIL Can't Empty"; };
foreach (var ctn in ctnlist)
{
if (ctn.CNTRNO == null || ctn.CNTRNO == "")
{ error = error + "|MBLNO" + bill.MBLNO + "CNTRNO Can't Empty"; }
}
if (StringIsChinese(bill.SHIPPER))
{
error = error + "|MBLNO" + bill.MBLNO + "SHIPPER Can't Contains Special Word";
}
if (StringIsChinese(bill.CONSIGNEE))
{
error = error + "|MBLNO" + bill.MBLNO + "CONSIGNEE Can't Contains Special Word";
}
if (StringIsChinese(bill.NOTIFYPARTY))
{
error = error + "|MBLNO" + bill.MBLNO + "NOTIFYPARTY Can't Contains Special Word";
}
if (StringIsChinese(bill.MARKS))
{
error = error + "|MBLNO" + bill.MBLNO + "MARKS Can't Contains Special Word";
}
if (StringIsChinese(bill.DESCRIPTION))
{
error = error + "|MBLNO" + bill.MBLNO + "DESCRIPTION Can't Contains Special Word";
}
}
return error;
}
public static string CreateEdiWD(List<MsOpSubSeaOrder> headData, string usercode, string path, string mblno, CodeFtpSet ftpset)
{
string filename = path + "\\" + mblno + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
FileStream f = new FileStream(filename, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.Default);
var icount = 0;
var filerole = "9";
var isfirst = true;
foreach (var bill in headData)
{
if (isfirst)
{
r.WriteLine("00:PENSUM:MANIFEST:" + filerole + ":" + ftpset.SENDCODE + ":" + ftpset.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":" + bill.PORTLOADID+"::2.0'");
icount = icount + 1;
r.WriteLine("10:" + GetVesselEdi(bill.VESSEL) + ":" + bill.VESSEL + "::" + bill.VOYNO + "::::" + GetDateStr(bill.ETD, "yyyyMMddHHmmss") + ":" + bill.PORTLOADID + ":" + bill.PORTLOAD+":::1'");
// r.WriteLine("10:" + GetVesselEdi(bill.VESSEL) + ":" + bill.VESSEL + "::" + bill.VOYNO + ":::" + GetDateStr(bill.ETA, "yyyyMMdd") + ":" + GetDateStr(bill.ETD, "yyyyMMdd") + "::::::1'");
isfirst = false;
r.WriteLine("11:" + ftpset.SENDCODE + ":" + ftpset.SENDNAME + ":::" + GetDateStr(bill.ETD, "yyyyMMddHHmmss") + "::'");
icount = icount + 2;
}
// r.WriteLine("11:" + ftpset.SENDCODE + ":SOFAST SHIPPING LIMITED::4227163583837::'");
//var xtype = "PO";
// if (bill.BLFRT.IndexOf("FREIGHT COLLECT") >= 0)
// xtype = "CC";
// r.WriteLine("12:" + bill.MBLNO.Trim() + "::::::" + bill.PORTLOADID + ":" + bill.PORTLOAD
// + ":10:" + xtype + ":" + GetDateStr(bill.ETD, "yyyyMMdd") + "::::::" + bill.PKGS.ToString() +":"+
// GetPackageEDICode(bill.KINDPKGS) + ":" + string.Format("{0:0.0000}", bill.KGS) + ":" + bill.CBM.ToString() + ":0.00:::::001'");
// r.WriteLine("13:" + bill.PORTDISCHARGEID + ":" + bill.PORTDISCHARGE
// + ":" + bill.DESTINATIONID + ":" + bill.DESTINATION + "::::" + bill.ISSUEPLACE + "::'");
var xtype = "P";
if (bill.BLFRT.IndexOf("FREIGHT COLLECT") >= 0)
xtype = "C";
r.WriteLine("12:" + bill.MBLNO.Trim() + "::::" + bill.PORTLOADID + ":" + bill.PORTLOAD
+ ":" + bill.PORTLOADID + ":" + bill.PORTLOAD
+ ":" + bill.SERVICE + ":" + xtype + ":" + GetDateStr(bill.ETD, "yyyyMMddHHmmss") + "::::::::::'");
r.WriteLine("13:" + bill.PORTDISCHARGEID + ":" + bill.PORTDISCHARGE
+ ":" + bill.PORTDISCHARGEID + ":" + bill.PORTDISCHARGE + "::::" + bill.ISSUEPLACE + "::::'");
var Shipping = "";
Shipping = formatEdiStr(bill.SHIPPER);
List<System.String> ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("16:" + formatEdiStr(bill.SHIPPERCODE) + ":" + formatListStr(ShippingList, 2) + formatEdiStr(bill.SHIPPERTEL)+ ":::::::" + bill.SHIPPERCOUNTRY + ":" + ":'");
// r.WriteLine("\"16::" + ShippingList[0] + "\r:" + ShippingList[0] + "::::::::'\"");
}
Shipping = formatEdiStr(bill.CONSIGNEE);
ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("17:" + formatEdiStr(bill.CONSIGNEECODE) + ":" + formatListStr(ShippingList, 2) + formatEdiStr(bill.CONSIGNEETEL)+ ":::::::" + bill.CONSIGNEECOUNTRY + ":" + ":'");
}
Shipping = formatEdiStr(bill.NOTIFYPARTY);
ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("18:" + formatEdiStr(bill.NOTIFYPARTYCODE) + ":" + formatListStr(ShippingList, 2) + formatEdiStr(bill.NOTIFYPARTYTEL)+ ":::::::" + bill.NOTIFYPARTYCOUNTRY + ":" + ":'");
// r.WriteLine("\"18::" + ShippingList[0] + "\r:" + ShippingList[0] + "::::::::'\"");
}
var cargoid = bill.CARGOID;
if (cargoid == "") cargoid = "S";
r.WriteLine("41:1::" + bill.PKGS.ToString() + ":" + GetPackageEDICode(bill.KINDPKGS) + ":" + bill.KINDPKGS + ":"
+ bill.KGS.ToString() + "::" + bill.CBM.ToString() + "::::'");
icount = icount + 6;
if (cargoid=="D"){
r.WriteLine("43::" + bill.DCLASS + ":none:" + bill.DUNNO + ":none:::::::::'");
icount = icount + 1;
}
Shipping = formatEdiStr(bill.MARKS);
ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("44::" + formatListStr(ShippingList, 5) + "'");
icount = icount + 1;
}
Shipping = formatEdiStr(bill.DESCRIPTION);
ShippingList = formatlengthStr(Shipping, 35);
var strtemp = "";
var m = 0;
if (ShippingList.Count != 0)
{
for (var i = 0; i < ShippingList.Count; i++)
{
if (m <= 4)
{
if (m == 0) strtemp = "47:" + ShippingList[i] + ":";
else
{
if (m == 4)
strtemp = strtemp + ShippingList[i];
else
strtemp = strtemp + ShippingList[i] + ":";
}
}
else
{
m =0;
r.WriteLine(strtemp + "'");
strtemp = "47:" + ShippingList[i] + ":";
icount = icount + 1;
}
m = m + 1;
}
}
if (strtemp != "")
{
r.WriteLine(strtemp + "'");
icount = icount + 1;
};
var ctnlist = GetBodyList("BSNO='" + bill.BSNO + "'");
foreach (var ctn in ctnlist)
{
var ctnpkg ="0";
if (ctn.STATUS == "E")
{
ctnpkg ="1";
}
else ctnpkg = ctn.PKGS.ToString();
r.WriteLine("51:1:" + ctn.CNTRNO + ":" + ctn.SEALNO + ":" + ctn.CTNALL + ":" + ctn.STATUS + ":" + ctnpkg
+ ":" + ctn.KGS.ToString() + "::"+ctn.CBM.ToString()+":::::::2'");
if (ctn.STATUS=="F")
r.WriteLine("52:M:SH:"+ ctn.SEALNO + "'");
icount = icount + 2;
}
}
icount = icount + 1;
r.WriteLine("99:" + icount.ToString() + "'");
r.Close();
f.Close();
return filename;
}
public static string CreateEdiWD2(List<MsOpSubSeaOrder> headData, string usercode, string path, string mblno, CodeFtpSet ftpset)
{
string filename = path + "\\" + mblno + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt";
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
FileStream f = new FileStream(filename, FileMode.Create);
StreamWriter r = new StreamWriter(f, Encoding.Default);
var icount = 1;
// filerole = "9C";
r.WriteLine("00:CN1101::9:" + ftpset.SENDCODE + ":" + ftpset.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ":1.0'");
var isfirst = true;
foreach (var bill in headData)
{
if (isfirst) {
r.WriteLine("10:" + GetVesselEdi(bill.VESSEL) + ":" + bill.VESSEL + "::" + bill.VOYNO + "::::" + GetDateStr(bill.ETD, "yyyyMMddHHmm") + "086:" + bill.PORTLOADID + ":" + bill.PORTLOAD + "::::1'");
r.WriteLine("11:SOF::" + ftpset.SENDCODE + "::" + bill.PORTDISCHARGEID + ":" + GetDateStr(bill.ETA, "yyyyMMddHHmm") + "086'");
isfirst = false;
}
var xtype = "";
var TransType = "";
if (bill.BLFRT.IndexOf("FREIGHT PREPAID") > 0)
xtype = "PO";
else if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > 0)
xtype = "CC";
else
xtype = "PO";
if (bill.SERVICE.ToUpper() == "PORT TO PORT")
TransType = "10";
else if (bill.SERVICE.ToUpper() == "DOOR TO DOOR")
TransType = "27";
else if (bill.SERVICE.ToUpper() == "DOOR TO PIER")
TransType = "28";
else if (bill.SERVICE.ToUpper() == "PIER TO DOOR")
TransType = "29";
else
TransType = "10";
r.WriteLine("12:" + bill.MBLNO.Trim() + "::::" + bill.PLACEDELIVERYID + ":" + bill.PLACEDELIVERY + ":" + bill.PORTLOADID + ":" + bill.PORTLOAD
+ ":" + TransType + ":" + xtype + ":" + GetDateStr(bill.ETD, "yyyyMMddHHmm") + "086:::::" + bill.HBLNO + ":"
+ bill.PKGS.ToString() + ":" + GetPackageEDICode(bill.KINDPKGS).Trim() + ":" + bill.KGS.ToString() + ":::::::001'");
r.WriteLine("13:" + bill.PORTDISCHARGEID + ":" + bill.PORTDISCHARGE + ":" + bill.DESTINATIONID + ":" + bill.DESTINATION + ":::JP:::'"
+ GetDateStr(bill.ETA, "yyyyMMdd") + "::'");
r.WriteLine("14:JP'");
r.WriteLine("14:CN'");
var Shipping = "";
Shipping = formatEdiStr(bill.SHIPPER);
List<System.String> ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("16::" + formatListStr(ShippingList, 2) + "::::::::'");
}
Shipping = formatEdiStr(bill.CONSIGNEE);
ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("17::" + formatListStr(ShippingList, 2) + "::::::::'");
}
Shipping = formatEdiStr(bill.NOTIFYPARTY);
ShippingList = formatlengthStr(Shipping, 35);
if (ShippingList.Count != 0)
{
r.WriteLine("18::" + formatListStr(ShippingList, 2) + "::::::::'");
}
//Shipping = formatEdiStr(bill.AGENT);
//ShippingList = formatlengthStr(Shipping, 35);
//if (ShippingList.Count != 0)
//{
// r.WriteLine("19::" + formatListStr(ShippingList, 6) + "'");
//}
var cargoid = bill.CARGOID;
if (cargoid == "") cargoid = "S";
r.WriteLine("41:1::" + bill.PKGS.ToString() + ":" + GetPackageEDICode(bill.KINDPKGS).Trim() + ":" + bill.KINDPKGS + ":"
+ bill.KGS.ToString() + ":" + bill.KGS.ToString() + ":" + bill.CBM.ToString() + ":::'");
icount = icount + 10;
var ctnlist = GetBodyList("BSNO='" + bill.BSNO + "'");
foreach (var ctn in ctnlist)
{
r.WriteLine("42:" + ctn.CNTRNO + "'");
icount = icount + 1;
}
if (bill.CARGOID == "D")
{
r.WriteLine("43:" + bill.DCLASS + ":none:" + bill.DUNNO + ":none::::::::::::'");
icount = icount + 1;
}
else if (bill.CARGOID == "R")
{
r.WriteLine("43:::::::::C:" + bill.TEMPSET + "::::::'");
icount = icount + 1;
}
r.WriteLine("44:" + formatEdiStr(bill.MARKS).Replace("//r//n", " ") + "'");
r.WriteLine("47:" + formatEdiStr(bill.DESCRIPTION).Replace("//r//n", " ") + "'");
icount = icount + 2;
foreach (var ctn in ctnlist)
{
var ctnstatus = "5";
if (ctn.STATUS == "E") ctnstatus = "4";
if (ctn.STATUS == "F") ctnstatus = "5";
r.WriteLine("51:1:" + ctn.CNTRNO + ":" + ctn.SEALNO + ":" + GetCtnEDICode(ctn.CTNALL) + ":" + ctnstatus + ":" + ctn.PKGS.ToString()
+ ":" + ctn.KGS.ToString() + ":0:" + ctn.CBM + ":::::::2'");
r.WriteLine("52:" + ctn.SEALNO + ":M:CA'");
icount = icount + 2;
}
}
r.WriteLine("99:" + icount.ToString() + "'");
r.Close();
f.Close();
return filename;
}
#endregion
#region 权限范围
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
if (tb == "audit")
{
strSql.Append(" where [NAME]='modSeaeOrderAudit' and USERID='" + userid + "' and ISDELETE=0");
}
else
{
strSql.Append(" where [NAME]='modSeaeOrderList' and USERID='" + userid + "' and ISDELETE=0");
}
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " (OP='" + username + "' OR SALE='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
};
}
str = str + ")";
reader.Close();
}
}
else if (visiblerange == "1")
{
var rangeDa = new RangeDA();
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') ");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
return str;
}
#endregion
#region 到货通知编码生成
public static string getREFNo(string strETD)
{
DateTime dETD = System.Convert.ToDateTime(strETD.Trim());
var strRULEYEAR = dETD.ToString("yy") + dETD.ToString("MM");
int iRULENOLENGTH =4;
int inum = 0;
var strCONTENT = "CWJIS" + strRULEYEAR;
string strRULENOLENGTH = "";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
strRULENOLENGTH = T_ALL_DA.GetStrSQL("REFNO", "select top 1 REFNO from [op_sub_seaorder_arrival] where REFNO like '" + strCONTENT.Trim() + "%' order by REFNO 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;
}
#endregion
public static bool ImportCtnData(string bsno, DataTable table, out string msg, out List<MsOpSubSeaOrderCtn> headList)
{
var isSucess = false;
msg = "";
headList = new List<MsOpSubSeaOrderCtn>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
var i = 1;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var custName = Convert.ToString(row["CONTAINER NO"]);
if (custName != "")
{
#region 托单数据生成
//
var size = Convert.ToString(row["SIZE"]);
var type = Convert.ToString(row["TYPE"]);
var ctnall="";
if (type == "DR" && size == "22")
ctnall = "20GP";
else if (type == "DR" && (size == "42"||size == "40"))
ctnall = "40GP";
else if (type == "HC" && (size == "42"||size == "40"))
ctnall = "40HC";
else if (type == "HR" && (size == "42"||size=="40"))
ctnall = "40HR";
else ctnall = size + type;
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + bsno + "','" + i.ToString() + "','" + ctnall + "','" + Convert.ToString(row["CONTAINER NO"]) + "','','',0,0,'','','" + Convert.ToString(row["STATUS"]) + "')");
db.ExecuteNonQuery(cmdInsert, tran);
#endregion
}
i = i + 1;
}
tran.Commit();
getCNTRTOTAL(bsno, "op_sub_seaorder");
isSucess = true;
}
catch (Exception exception)
{
tran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
public static bool ImportCtnDataTOKYO(string bsno, DataTable table, out string msg, out List<MsOpSubSeaOrderCtn> headList)
{
var isSucess = false;
msg = "";
headList = new List<MsOpSubSeaOrderCtn>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
var i = 1;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var custName = Convert.ToString(row["AECTNO"]);
if (custName != "")
{
#region 托单数据生成
//
var size = Convert.ToString(row["AESIZE"]);
var type = Convert.ToString(row["AETYPE"]);
var ctnall = "";
if (type == "DR" && size == "22")
ctnall = "20GP";
else if (type == "DR" && (size == "42" || size == "40" || size == "44"))
ctnall = "40GP";
else if (type == "HC" && (size == "42" || size == "40" || size == "44"))
ctnall = "40HC";
else if (type == "HR" && (size == "42" || size == "40" || size == "44"))
ctnall = "40HR";
else ctnall = size + type;
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + bsno + "','" + i.ToString() + "','" + ctnall + "','" + Convert.ToString(row["AECTNO"]) + "','','',0,0,'','','')");
db.ExecuteNonQuery(cmdInsert, tran);
#endregion
}
i = i + 1;
}
tran.Commit();
getCNTRTOTAL(bsno, "op_sub_seaorder");
isSucess = true;
}
catch (Exception exception)
{
tran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
public static bool ImportCtnDataOSAKA(string bsno, DataTable table, out string msg, out List<MsOpSubSeaOrderCtn> headList)
{
var isSucess = false;
msg = "";
headList = new List<MsOpSubSeaOrderCtn>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
var i = 1;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var custName = Convert.ToString(row["EACTNO"]);
if (custName != "")
{
#region 托单数据生成
//
var size = Convert.ToString(row["EASIZE"]);
var type = Convert.ToString(row["EATYPE"]);
var ctnall = "";
if (type == "DR" && (size == "22"||size == "20"))
ctnall = "20GP";
else if (type == "RF" && (size == "22"||size == "20"))
ctnall = "20RF";
else if (type == "DR" && (size == "42" || size == "40"))
ctnall = "40GP";
else if (type == "DR" && (size == "40HC"))
ctnall = "40HC";
else if (type == "RF" && (size == "40HC"))
ctnall = "40HR";
else if (type == "RF" && (size == "40" || size == "42"))
ctnall = "40RF";
else ctnall = size + type;
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + bsno + "','" + i.ToString() + "','" + ctnall + "','" + Convert.ToString(row["EACTNO"]) + "','','',0,0,'','','')");
db.ExecuteNonQuery(cmdInsert, tran);
#endregion
}
i = i + 1;
}
tran.Commit();
getCNTRTOTAL(bsno, "op_sub_seaorder");
isSucess = true;
}
catch (Exception exception)
{
tran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
public static bool ImportCtnDataMOJI(string bsno, DataTable table, out string msg, out List<MsOpSubSeaOrderCtn> headList)
{
var isSucess = false;
msg = "";
headList = new List<MsOpSubSeaOrderCtn>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
var i = 1;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var custName = Convert.ToString(row["コンテナ番号"]);
if (custName != "")
{
#region 托单数据生成
//
var size = Convert.ToString(row["サイズ"]);
var type = Convert.ToString(row["タイプ"]);
var ctnall = "";
if (type == "DRY" && (size == "22" || size == "20"))
ctnall = "20GP";
else if ((type == "RF" || type == "CR" || type == "HCR") && (size == "22" || size == "20"))
ctnall = "20RF";
else if (type == "DRY" && (size == "42" || size == "40"))
ctnall = "40GP";
else if (type == "HCD" && (size == "40"))
ctnall = "40HC";
else if (type == "HCR" && (size == "40"))
ctnall = "40HR";
else if ((type == "RF" || type == "CR") && (size == "40" || size == "42"))
ctnall = "40RF";
else ctnall = size + type;
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + bsno + "','" + i.ToString() + "','" + ctnall + "','" + Convert.ToString(row["コンテナ番号"]) + "','','',0,0,'','','')");
db.ExecuteNonQuery(cmdInsert, tran);
#endregion
}
i = i + 1;
}
tran.Commit();
getCNTRTOTAL(bsno, "op_sub_seaorder");
isSucess = true;
}
catch (Exception exception)
{
tran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
public static bool ImportCtnDataYOKOHAMA(string bsno, DataTable table, out string msg, out List<MsOpSubSeaOrderCtn> headList)
{
var isSucess = false;
msg = "";
headList = new List<MsOpSubSeaOrderCtn>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
var i = 1;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
foreach (DataRow row in table.Rows)
{
var custName = Convert.ToString(row["Container No#"]);
if (custName != "")
{
#region 托单数据生成
//
var size = Convert.ToString(row["Size/Type"]);
var type = Convert.ToString(row["F4"]);
var ctnall = "";
if (type == "DRY" && (size == "22" || size == "20"))
ctnall = "20GP";
else if ((type == "RF" || type == "CR" || type == "F/R") && (size == "22" || size == "20"))
ctnall = "20RF";
else if ((type == "O/T") && (size == "22" || size == "20"))
ctnall = "20OT";
else if (type == "DRY" && (size == "42" || size == "40"))
ctnall = "40GP";
else if (type == "HCD" && (size == "40"))
ctnall = "40HC";
else if (type == "HCR" && (size == "40"))
ctnall = "40HR";
else if ((type == "RF" || type == "F/R") && (size == "40" || size == "42"))
ctnall = "40RF";
else if ((type == "O/T") && (size == "42" || size == "40"))
ctnall = "40OT";
else ctnall = size + type;
var cmdInsert = db.GetSqlStringCommand(@"insert into op_seaorder_ctn (CTN_ID,BSNO,CTNCODE,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,CTNSOURCE,STATUS) values (newid(),'" + bsno + "','" + i.ToString() + "','" + ctnall + "','" + Convert.ToString(row["Container No#"]) + "','','',0,0,'','','')");
db.ExecuteNonQuery(cmdInsert, tran);
#endregion
}
i = i + 1;
}
tran.Commit();
getCNTRTOTAL(bsno, "op_sub_seaorder");
isSucess = true;
}
catch (Exception exception)
{
tran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
return isSucess;
}
}
}