using System; using System.Data; using System.Collections.Generic; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.Dispatch.Models; using HcUtility.Comm; using System.Configuration; using DSWeb.MvcShipping.Models.MsOpSeaeEdi; using System.Data.Common; namespace DSWeb.Dispatch.DAL { public class MsOpSeaeDAL { #region 查询 static public List GetSaleDataList(string shortName, string condition = null, string sort = null, string order = null, bool hasNoFee = true) { var strSql = new StringBuilder(); strSql.AppendLine("SELECT BSNO,VESSEL,VOYNO,MBLNO,INVNO,ETD,ATD,CNTRTOTAL,KGS,YARD,CNTRSEALNO,CUSTOMNO,"); strSql.AppendLine("(SELECT dbo.Fun_JoinFactoryAddr(S.BSNO)) FACTORYADDR,"); strSql.AppendLine("ISNULL((SELECT TOP 1 CARGODATE FROM OP_LETTER_TRUCK WHERE BSNO=S.BSNO ORDER BY TRUCKDATE DESC),'') CARGODATE,"); strSql.AppendLine("(SELECT COMPTIME FROM OP_STATUS WHERE BSNO=S.BSNO AND ISCOMP=1 and [status]='重箱返场') STA_ZXFC,"); strSql.AppendLine("(SELECT COMPTIME FROM OP_STATUS WHERE BSNO=S.BSNO AND ISCOMP=1 and [status]='海关放行') STA_HGFX,"); strSql.AppendLine("(SELECT SUM(AMOUNT) FROM CH_FEE WHERE FEETYPE=1 AND FEESTATUS IN (0,8,9) AND CUSTOMERNAME=S.CUSTOMERNAME AND BSNO=S.BSNO AND CURRENCY='RMB') AMOUNT_RMB,"); strSql.AppendLine("(SELECT SUM(AMOUNT) FROM CH_FEE WHERE FEETYPE=1 AND FEESTATUS IN (0,8,9) AND CUSTOMERNAME=S.CUSTOMERNAME AND BSNO=S.BSNO AND CURRENCY='USD') AMOUNT_USD"); strSql.AppendLine("FROM OP_SEAE S"); strSql.AppendLine($"WHERE CUSTOMERNAME='{shortName}'"); if (!hasNoFee) { strSql.AppendLine("AND (SELECT COUNT(1) FROM CH_FEE WHERE FEETYPE=1 AND FEESTATUS IN (0,8,9) AND CUSTOMERNAME=S.CUSTOMERNAME AND BSNO=S.BSNO)>0"); } if (!string.IsNullOrWhiteSpace(condition)) { var obj = new { VESSEL = "", VOYNO = "", MBLNO = "", INVNO = "", BSNO = "" }; var jsonObj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(condition, obj); if (!string.IsNullOrWhiteSpace(jsonObj.VESSEL)) { strSql.Append($" and VESSEL like '%{jsonObj.VESSEL.Replace("'", "")}%'"); } if (!string.IsNullOrWhiteSpace(jsonObj.VOYNO)) { strSql.Append($" and VOYNO like '%{jsonObj.VOYNO.Replace("'", "")}%'"); } if (!string.IsNullOrWhiteSpace(jsonObj.MBLNO)) { strSql.Append($" and MBLNO='{jsonObj.MBLNO.Replace("'", "")}'"); } if (!string.IsNullOrWhiteSpace(jsonObj.INVNO)) { strSql.Append($" and INVNO='{jsonObj.INVNO.Replace("'", "")}'"); } if (!string.IsNullOrWhiteSpace(jsonObj.BSNO)) { strSql.Append($" and BSNO='{jsonObj.BSNO.Replace("'", "")}'"); } } if (!string.IsNullOrEmpty(sort)) { strSql.AppendLine($" order by {sort} {(string.IsNullOrWhiteSpace(order) ? string.Empty : order)}"); } else { strSql.AppendLine(" order by BSDATE desc"); } return SetData(strSql); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpSeaeModel data = new OpSeaeModel(); #region Set DB data to Object data.BSNO = Convert.ToString(reader["BSNO"]); data.VESSEL = Convert.ToString(reader["VESSEL"]); data.VOYNO = Convert.ToString(reader["VOYNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.INVNO = Convert.ToString(reader["INVNO"]); data.CNTRTOTAL = Convert.ToString(reader["CNTRTOTAL"]); data.KGS = Convert.ToString(reader["KGS"]); data.YARD = Convert.ToString(reader["YARD"]); data.CNTRSEALNO = Convert.ToString(reader["CNTRSEALNO"]); data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]); data.FACTORYADDR = Convert.ToString(reader["FACTORYADDR"]); data.CARGODATE = Convert.ToString(reader["CARGODATE"]); if (reader["STA_ZXFC"] != DBNull.Value) data.STA_ZXFC = Convert.ToString(reader["STA_ZXFC"]); if (reader["STA_HGFX"] != DBNull.Value) data.STA_HGFX = Convert.ToString(reader["STA_HGFX"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd"); if (reader["ATD"] != DBNull.Value) data.ATD = Convert.ToDateTime(reader["ATD"]).ToString("yyyy-MM-dd"); if (reader["AMOUNT_RMB"] != DBNull.Value) data.AMOUNT_RMB = Convert.ToDecimal(reader["AMOUNT_RMB"]); if (reader["AMOUNT_USD"] != DBNull.Value) data.AMOUNT_USD = Convert.ToDecimal(reader["AMOUNT_USD"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion public static DBResult SaveDetail(OrderImportData headData, List bodyList) { var result = new DBResult(); var GID = Guid.NewGuid().ToString(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsertMaster = db.GetSqlStringCommand( @"insert into order_import (GID,outer_orderid,order_source,province,city,district,address,name,identity_name,identity_no,phone,tel,postcode,freight,order_total,exp_code,exp_no,order_time,add_time,notify_url,remark) values (@GID,@outer_orderid,@order_source,@province,@city,@district,@address,@name,@identity_name,@identity_no,@phone, @tel,@postcode,@freight,@order_total,@exp_code,@exp_no,@order_time,@add_time,@notify_url,@remark) "); var cmdInsert = db.GetSqlStringCommand( @"insert into order_import_detail ([GID],[PGID],[outer_sku],[sku],[name],[price],[num],[unit],[total]) values (@GID,@PGID,@outer_sku,@sku,@name,@price,@num,@unit,@total) "); cmdInsertMaster.Parameters.Clear(); db.AddInParameter(cmdInsertMaster, "@GID", DbType.String, GID); db.AddInParameter(cmdInsertMaster, "@outer_orderid", DbType.String, headData.outer_orderid); db.AddInParameter(cmdInsertMaster, "@order_source", DbType.String, headData.order_source); db.AddInParameter(cmdInsertMaster, "@province", DbType.String, headData.province); db.AddInParameter(cmdInsertMaster, "@city", DbType.String, headData.city); db.AddInParameter(cmdInsertMaster, "@district", DbType.String, headData.district); db.AddInParameter(cmdInsertMaster, "@address", DbType.String, headData.address); db.AddInParameter(cmdInsertMaster, "@name", DbType.String, headData.name); db.AddInParameter(cmdInsertMaster, "@identity_name", DbType.String, headData.identity_name); db.AddInParameter(cmdInsertMaster, "@identity_no", DbType.String, headData.identity_no); db.AddInParameter(cmdInsertMaster, "@phone", DbType.String, headData.phone); db.AddInParameter(cmdInsertMaster, "@tel", DbType.String, headData.tel); db.AddInParameter(cmdInsertMaster, "@postcode", DbType.String, headData.postcode); db.AddInParameter(cmdInsertMaster, "@freight", DbType.String, headData.freight); db.AddInParameter(cmdInsertMaster, "@order_total", DbType.String, headData.order_total); db.AddInParameter(cmdInsertMaster, "@exp_code", DbType.String, headData.exp_code); db.AddInParameter(cmdInsertMaster, "@exp_no", DbType.String, headData.exp_no); db.AddInParameter(cmdInsertMaster, "@order_time", DbType.String, headData.order_time); db.AddInParameter(cmdInsertMaster, "@add_time", DbType.String, headData.add_time); db.AddInParameter(cmdInsertMaster, "@notify_url", DbType.String, headData.notify_url); db.AddInParameter(cmdInsertMaster, "@remark", DbType.String, headData.remark); db.ExecuteNonQuery(cmdInsertMaster, tran); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@PGID", DbType.String, GID); db.AddInParameter(cmdInsert, "@outer_sku", DbType.String, enumValue.outer_sku); db.AddInParameter(cmdInsert, "@sku", DbType.String, enumValue.sku); db.AddInParameter(cmdInsert, "@name", DbType.String, enumValue.name); db.AddInParameter(cmdInsert, "@price", DbType.String, enumValue.price); db.AddInParameter(cmdInsert, "@num", DbType.String, enumValue.num); db.AddInParameter(cmdInsert, "@unit", DbType.String, enumValue.unit); db.AddInParameter(cmdInsert, "@total", DbType.String, enumValue.total); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = GID; return result; } public static List GetCodectns() { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, "select [代码] CTNID,[箱型] CTNTYPE,[尺寸] CTNSIZE,[表现形式] CTNALL FROM t_code_ctn")) { while (reader.Read()) { codectn data = new codectn(); #region Set DB data to Object data.CTNID = Convert.ToString(reader["CTNID"]); data.CTNSIZE = Convert.ToString(reader["CTNSIZE"]); data.CTNTYPE = Convert.ToString(reader["CTNTYPE"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveSeaiData(MsOpSeai headData, List ctnbodyList, List feebodyList,bool isupdate,string lbsno) { var result = new DBResult(); var GID = Guid.NewGuid().ToString(); var CTNCODELIST = GetCodectns(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var bsno = Get_id(); if (isupdate) bsno = lbsno; var orderinputby = ConfigurationManager.AppSettings["orderinputby"]; var ordercompany = ConfigurationManager.AppSettings["ordercompany"]; if (!string.IsNullOrEmpty(headData.OP)) orderinputby = headData.OP; var cmdInsertMaster = db.GetSqlStringCommand( @"insert into t_op_seai (编号,主编号,业务编号,主提单号,会计期间,进口日期,财务,财务凭证,录入人,录入日期,分部名称,操作员,业务来源,装运方式,业务类型,委托单位,业务状态,费用状态,主提单标准,分提单标准,委托标准,报关标准,报检标准 ,船名,航次,发货人代码,货物名称,合同号,手册号,船公司,件数,重量,委托编号,场站,商品编码,集装箱,许可证号,揽货人,操作部门,销售部门,客服员,箱TEU,箱型1,箱型2,箱型3,箱型4,箱型5,箱型6,箱型7,箱型8,箱型9,封帐前状态) values (@BSNO,@MBSNO,@YWBSNO,@MBLNO,null,@ETA,0,'','" + orderinputby + "',GETDATE(),'"+ ordercompany + "','" + orderinputby + "','Sales','整箱','普通货',@customername,'接受委托','录入状态','" + bsno+ "','" + bsno + "','" + bsno + "','" + bsno + "','" + bsno + "',@VESSEL,@VOYNO,@SHIPPER,@DESCRIPTION,@CONTRACTNO,@BOOKNO,@CARRIER,@PKGS,@KGS,@CUSTNO,@YARD,@HSCODE,@CNTRSTR,@LICENSENO,'郑彬','销售操作组','销售部','" + orderinputby + "',@TEU,@CTN1,@CTN2,@CTN3,@CTN4,@CTN5,@CTN6,@CTN7,@CTN8,@CTN9,'接受委托') "); var cmdInsertMasterUpdate = db.GetSqlStringCommand( @"update t_op_seai SET 进口日期=@ETA,委托单位=@customername,船名=@VESSEL,航次=@VOYNO,发货人代码=@SHIPPER,货物名称=@DESCRIPTION,合同号=@CONTRACTNO,手册号=@BOOKNO,船公司=@CARRIER ,件数=@PKGS,重量=@KGS,委托编号=@CUSTNO,场站=@YARD,商品编码=@HSCODE,集装箱=@CNTRSTR,许可证号=@LICENSENO,箱TEU=@TEU,箱型1=@CTN1,箱型2=@CTN2,箱型3=@CTN3,箱型4=@CTN4,箱型5=@CTN5,箱型6=@CTN6,箱型7=@CTN7,箱型8=@CTN8,箱型9=@CTN9 WHERE 编号=@BSNO "); var cmdInsert = db.GetSqlStringCommand( @"insert into t_op_ctn ([编号],[代码],[尺寸],[箱型],[数量],[TEU],[表现形式]) values (@BSNO,@CTNID,@CTNSIZE,@CTNTYPE,@CTNNUM,@TEU,@CTNALL) "); var cmdInsertFee = db.GetSqlStringCommand( @"insert into t_ch_fee ([类型],[费用状态],[编号],[费用名称],[客户名称],[标准],[单价],[数量],[金额],[币别],[汇率],[结算金额],[开票金额],[录入人],[录入日期], [是否对帐],[冲抵金额],[机密],[是否复核],[是否垫付],[申请金额],[不开发票],[系统费用],[申请开票],[第三方金额],[不含税价],[税率],[税额],[财务对帐],结算单位,费用英文名称) values (@FEETYPE,'录入状态',@BSNO,@FEENAME,@CUSTOMERNAME,'单票',@UNITPRICE,@QUANTITY,@AMOUNT,@CURRENCY,@EXCHANGERATE,0,0,'" + orderinputby + "',GETDATE()," + "0,0,0,0,0,0,0,0,0,0,@NOTAXUNITPRICE,0,0,0,'船公司',@RATE) "); if (isupdate) { db.ExecuteNonQuery(tran,CommandType.Text, "delete from t_op_ctn where 编号='"+bsno+ "' "); } var CNTRSTR = ""; int ctnteusum = 0; int ctn1 = 0; int ctn2 = 0; int ctn3 = 0; int ctn4 = 0; int ctn5 = 0; int ctn6 = 0; int ctn7 = 0; int ctn8 = 0; int ctn9 = 0; int ctn10 = 0; if (ctnbodyList != null) { foreach (var enumValue in ctnbodyList) { CTNCODELIST.ForEach(i => { if (i.CTNALL.Replace("'","") == enumValue.CTNALL.Replace("'", "")) { var ctnteu = 1; cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, bsno); db.AddInParameter(cmdInsert, "@CTNID", DbType.String, i.CTNID); db.AddInParameter(cmdInsert, "@CTNSIZE", DbType.String, i.CTNSIZE); db.AddInParameter(cmdInsert, "@CTNTYPE", DbType.String, i.CTNTYPE); db.AddInParameter(cmdInsert, "@CTNNUM", DbType.String, enumValue.CTNNUM); if (i.CTNSIZE.IndexOf("40") >= 0 || i.CTNSIZE.IndexOf("45") >= 0 || i.CTNSIZE.IndexOf("53") >= 0) ctnteu = 2; db.AddInParameter(cmdInsert, "@TEU", DbType.String, enumValue.CTNNUM * ctnteu); db.AddInParameter(cmdInsert, "@CTNALL", DbType.String, enumValue.CTNALL); db.ExecuteNonQuery(cmdInsert, tran); if (CNTRSTR=="") CNTRSTR = enumValue.CTNALL+"*"+ enumValue.CTNNUM.ToString(); else CNTRSTR = CNTRSTR+" "+ enumValue.CTNALL + "*" + enumValue.CTNNUM.ToString(); ctnteusum = ctnteusum+ctnteu; if (i.CTNALL == "20'GP") ctn1 = ctn1 + enumValue.CTNNUM; if (i.CTNALL == "20'RF") ctn2 = ctn2 + enumValue.CTNNUM; if (i.CTNALL == "40'GP") ctn3 = ctn3 + enumValue.CTNNUM; if (i.CTNALL == "40'RF") ctn4 = ctn4+ enumValue.CTNNUM; if (i.CTNALL == "40'RH") ctn5 = ctn5 + enumValue.CTNNUM; if (i.CTNALL == "45'HC") ctn6 = ctn6 + enumValue.CTNNUM; if (i.CTNALL == "40'HC") ctn7 = ctn7 + enumValue.CTNNUM; if (i.CTNALL == "53'HQ") ctn8 = ctn8 + enumValue.CTNNUM; if (i.CTNALL == "40'FR") ctn9 = ctn9 + enumValue.CTNNUM; } }); } } if (isupdate) { cmdInsertMasterUpdate.Parameters.Clear(); db.AddInParameter(cmdInsertMasterUpdate, "@ETA", DbType.String, headData.ETA); db.AddInParameter(cmdInsertMasterUpdate, "@customername", DbType.String, headData.CUSTOMERNAME); db.AddInParameter(cmdInsertMasterUpdate, "@VESSEL", DbType.String, headData.VESSEL); db.AddInParameter(cmdInsertMasterUpdate, "@VOYNO", DbType.String, headData.VOYNO); db.AddInParameter(cmdInsertMasterUpdate, "@SHIPPER", DbType.String, headData.SHIPPER); db.AddInParameter(cmdInsertMasterUpdate, "@DESCRIPTION", DbType.String, headData.DESCRIPTION); db.AddInParameter(cmdInsertMasterUpdate, "@CONTRACTNO", DbType.String, headData.CONTRACTNO); db.AddInParameter(cmdInsertMasterUpdate, "@BOOKNO", DbType.String, headData.BOOKNO); db.AddInParameter(cmdInsertMasterUpdate, "@CARRIER", DbType.String, headData.CARRIER); db.AddInParameter(cmdInsertMasterUpdate, "@PKGS", DbType.String, headData.PKGS); db.AddInParameter(cmdInsertMasterUpdate, "@KGS", DbType.String, headData.KGS); db.AddInParameter(cmdInsertMasterUpdate, "@CUSTNO", DbType.String, headData.CUSTNO); db.AddInParameter(cmdInsertMasterUpdate, "@YARD", DbType.String, headData.YARD); db.AddInParameter(cmdInsertMasterUpdate, "@HSCODE", DbType.String, headData.HSCODE); db.AddInParameter(cmdInsertMasterUpdate, "@CNTRSTR", DbType.String, CNTRSTR); db.AddInParameter(cmdInsertMasterUpdate, "@LICENSENO", DbType.String, headData.LICENSENO); db.AddInParameter(cmdInsertMasterUpdate, "@TEU", DbType.Int32, ctnteusum); db.AddInParameter(cmdInsertMasterUpdate, "@CTN1", DbType.Int32, ctn1); db.AddInParameter(cmdInsertMasterUpdate, "@CTN2", DbType.Int32, ctn2); db.AddInParameter(cmdInsertMasterUpdate, "@CTN3", DbType.Int32, ctn3); db.AddInParameter(cmdInsertMasterUpdate, "@CTN4", DbType.Int32, ctn4); db.AddInParameter(cmdInsertMasterUpdate, "@CTN5", DbType.Int32, ctn5); db.AddInParameter(cmdInsertMasterUpdate, "@CTN6", DbType.Int32, ctn6); db.AddInParameter(cmdInsertMasterUpdate, "@CTN7", DbType.Int32, ctn7); db.AddInParameter(cmdInsertMasterUpdate, "@CTN8", DbType.Int32, ctn8); db.AddInParameter(cmdInsertMasterUpdate, "@CTN9", DbType.Int32, ctn9); db.AddInParameter(cmdInsertMasterUpdate, "@BSNO", DbType.String, bsno); db.ExecuteNonQuery(cmdInsertMasterUpdate, tran); } else { var ywno = GetBsNo(); cmdInsertMaster.Parameters.Clear(); db.AddInParameter(cmdInsertMaster, "@BSNO", DbType.String, bsno); db.AddInParameter(cmdInsertMaster, "@MBSNO", DbType.String, bsno); db.AddInParameter(cmdInsertMaster, "@YWBSNO", DbType.String, ywno); db.AddInParameter(cmdInsertMaster, "@MBLNO", DbType.String, headData.MBLNO); // db.AddInParameter(cmdInsertMaster, "@ACCDATE", DbType.String,""); db.AddInParameter(cmdInsertMaster, "@ETA", DbType.String, headData.ETA); db.AddInParameter(cmdInsertMaster, "@customername", DbType.String, headData.CUSTOMERNAME); db.AddInParameter(cmdInsertMaster, "@VESSEL", DbType.String, headData.VESSEL); db.AddInParameter(cmdInsertMaster, "@VOYNO", DbType.String, headData.VOYNO); db.AddInParameter(cmdInsertMaster, "@SHIPPER", DbType.String, headData.SHIPPER); db.AddInParameter(cmdInsertMaster, "@DESCRIPTION", DbType.String, headData.DESCRIPTION); db.AddInParameter(cmdInsertMaster, "@CONTRACTNO", DbType.String, headData.CONTRACTNO); db.AddInParameter(cmdInsertMaster, "@BOOKNO", DbType.String, headData.BOOKNO); db.AddInParameter(cmdInsertMaster, "@CARRIER", DbType.String, headData.CARRIER); db.AddInParameter(cmdInsertMaster, "@PKGS", DbType.String, headData.PKGS); db.AddInParameter(cmdInsertMaster, "@KGS", DbType.String, headData.KGS); db.AddInParameter(cmdInsertMaster, "@CUSTNO", DbType.String, headData.CUSTNO); db.AddInParameter(cmdInsertMaster, "@YARD", DbType.String, headData.YARD); db.AddInParameter(cmdInsertMaster, "@HSCODE", DbType.String, headData.HSCODE); db.AddInParameter(cmdInsertMaster, "@CNTRSTR", DbType.String, CNTRSTR); db.AddInParameter(cmdInsertMaster, "@TEU", DbType.Int32, ctnteusum); db.AddInParameter(cmdInsertMaster, "@CTN1", DbType.Int32, ctn1); db.AddInParameter(cmdInsertMaster, "@CTN2", DbType.Int32, ctn2); db.AddInParameter(cmdInsertMaster, "@CTN3", DbType.Int32, ctn3); db.AddInParameter(cmdInsertMaster, "@CTN4", DbType.Int32, ctn4); db.AddInParameter(cmdInsertMaster, "@CTN5", DbType.Int32, ctn5); db.AddInParameter(cmdInsertMaster, "@CTN6", DbType.Int32, ctn6); db.AddInParameter(cmdInsertMaster, "@CTN7", DbType.Int32, ctn7); db.AddInParameter(cmdInsertMaster, "@CTN8", DbType.Int32, ctn8); db.AddInParameter(cmdInsertMaster, "@CTN9", DbType.Int32, ctn9); db.AddInParameter(cmdInsertMaster, "@LICENSENO", DbType.String, headData.LICENSENO); db.ExecuteNonQuery(cmdInsertMaster, tran); } if (feebodyList != null) { foreach (var enumValue in feebodyList) { var rate = GetFeeRate("中文名='" + enumValue.FEENAME + "'"); cmdInsertFee.Parameters.Clear(); db.AddInParameter(cmdInsertFee, "@FEETYPE", DbType.String, enumValue.FEETYPE); db.AddInParameter(cmdInsertFee, "@BSNO", DbType.String, bsno); db.AddInParameter(cmdInsertFee, "@FEENAME", DbType.String, enumValue.FEENAME); db.AddInParameter(cmdInsertFee, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME); //db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, enumValue.UNIT); db.AddInParameter(cmdInsertFee, "@UNITPRICE", DbType.String, enumValue.UNITPRICE); db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.String, enumValue.QUANTITY); db.AddInParameter(cmdInsertFee, "@AMOUNT", DbType.String, enumValue.AMOUNT); db.AddInParameter(cmdInsertFee, "@CURRENCY", DbType.String, enumValue.CURRENCY); db.AddInParameter(cmdInsertFee, "@EXCHANGERATE", DbType.String, enumValue.EXCHANGERATE); db.AddInParameter(cmdInsertFee, "@NOTAXUNITPRICE", DbType.String, enumValue.UNITPRICE); db.AddInParameter(cmdInsertFee, "@RATE", DbType.String, rate); db.ExecuteNonQuery(cmdInsertFee, tran); } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message =e.Message; return result; } } result.Success = true; result.Message = GID; return result; } public static DBResult UpdateSeaeTraceData(List bodyList) { var result = new DBResult(); var GID = Guid.NewGuid().ToString(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); var cmdInsertTrace = db.GetSqlStringCommand( @"insert into t_op_seae_trace ([编号],[提箱],[重箱返场日期],[装船],[开航],[中转抵港1],[中转卸载1],[中转装船1],[中转开航1],[中转抵港2] ,[中转卸载2],[中转装船2],[中转开航2],[中转抵港3],[中转卸载3],[中转装船3],[中转开航3],[抵港],[卸载],[船东放货],[提货],[返空],预警提醒,[录入时间],[更新时间],ETA) values (@BSNO,@TX,@FC,@ZC,@KAIHANG,@ZZDG1,@ZZXZ1,@ZZZC1,@ZZKH1,@ZZDG2,@ZZXZ2,@ZZZC2,@ZZKH2,@ZZDG3,@ZZXZ3,@ZZZC3,@ZZKH3,@DG,@XZ,@FH,@TH,@FK,@YJXX,@INPUTDATE,@UPDATE,@ETA) "); var cmdInsertTraceCtn = db.GetSqlStringCommand( @"insert into t_op_seae_trace_ctn ([编号],[箱号],[提箱时间],[返场时间],[提货时间],[返空时间],[录入时间],[更新时间]) values (@BSNO,@CNTRNO,@TX,@FC,@TH,@FK,@INPUTDATE,@UPDATE) "); // var cmdUpdateTrace = db.GetSqlStringCommand( // @"update t_op_seae_trace SET 提箱=@TX,重箱返场日期=@FC,装船=@ZC,开航=@KAIHANG,中转抵港1=@ZZDG1,中转卸载1=@ZZXZ1,中转装船1=@ZZZC1,中转开航1=@ZZKH1, //中转抵港2=@ZZDG2,中转卸载2=@ZZXZ2,中转装船2=@ZZZC2,中转开航2=@ZZKH2,中转抵港3=@ZZDG3,中转卸载3=@ZZXZ3,中转装船3=@ZZZC3,中转开航3=@ZZKH3,[抵港]=@DG,[卸载]=@XZ,[船东放货]=@FH,[提货]=@TH,[返空]=@FK //,[更新时间]=@UPDATE WHERE TR_ID=@TRID "); try { if (bodyList != null) { foreach (var enumValue in bodyList) { var constr = ""; if (!string.IsNullOrEmpty(enumValue.TMblno)) { constr = "t_op_seae.真提单号 = '" + enumValue.TMblno + "'"; } else { constr = "t_op_seae.主提单号 = '" + enumValue.Mblno + "'"; } var optrace = GetSeaeTrace(constr, db, tran); if (!string.IsNullOrEmpty(optrace.BSNO)) { if (string.IsNullOrEmpty(optrace.TRID)) { cmdInsertTrace.Parameters.Clear(); db.AddInParameter(cmdInsertTrace, "@BSNO", DbType.String, optrace.BSNO); db.AddInParameter(cmdInsertTrace, "@TX", DbType.String, enumValue.PortloadCtnDate); db.AddInParameter(cmdInsertTrace, "@FC", DbType.String, enumValue.PortloadRtYard); db.AddInParameter(cmdInsertTrace, "@ZC", DbType.String, enumValue.PortloadShipment); db.AddInParameter(cmdInsertTrace, "@KAIHANG", DbType.String, enumValue.PortloadOnBoard); db.AddInParameter(cmdInsertTrace, "@ZZDG1", DbType.String, enumValue.Transport1Arrival); db.AddInParameter(cmdInsertTrace, "@ZZXZ1", DbType.String, enumValue.Transport1Unload); db.AddInParameter(cmdInsertTrace, "@ZZZC1", DbType.String, enumValue.Transport1Shipment); db.AddInParameter(cmdInsertTrace, "@ZZKH1", DbType.String, enumValue.Transport1OnBoard); db.AddInParameter(cmdInsertTrace, "@ZZDG2", DbType.String, enumValue.Transport2Arrival); db.AddInParameter(cmdInsertTrace, "@ZZXZ2", DbType.String, enumValue.Transport2Unload); db.AddInParameter(cmdInsertTrace, "@ZZZC2", DbType.String, enumValue.Transport2Shipment); db.AddInParameter(cmdInsertTrace, "@ZZKH2", DbType.String, enumValue.Transport2OnBoard); db.AddInParameter(cmdInsertTrace, "@ZZDG3", DbType.String, enumValue.Transport3Arrival); db.AddInParameter(cmdInsertTrace, "@ZZXZ3", DbType.String, enumValue.Transport3Unload); db.AddInParameter(cmdInsertTrace, "@ZZZC3", DbType.String, enumValue.Transport3Shipment); db.AddInParameter(cmdInsertTrace, "@ZZKH3", DbType.String, enumValue.Transport3OnBoard); db.AddInParameter(cmdInsertTrace, "@DG", DbType.String, enumValue.PortDischargeArrival); db.AddInParameter(cmdInsertTrace, "@XZ", DbType.String, enumValue.PortDischargeUnload); db.AddInParameter(cmdInsertTrace, "@FH", DbType.String, enumValue.PortDischargeCarrierRelease); db.AddInParameter(cmdInsertTrace, "@TH", DbType.String, enumValue.PortDischargeDelivery); db.AddInParameter(cmdInsertTrace, "@FK", DbType.String, enumValue.PortDischargeRtCtn); db.AddInParameter(cmdInsertTrace, "@YJXX", DbType.String, enumValue.WarningMsg); db.AddInParameter(cmdInsertTrace, "@INPUTDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.AddInParameter(cmdInsertTrace, "@UPDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.AddInParameter(cmdInsertTrace, "@ETA", DbType.String, enumValue.Eta); db.ExecuteNonQuery(cmdInsertTrace, tran); if (enumValue.CntrList != null) { foreach (var item in enumValue.CntrList) { cmdInsertTraceCtn.Parameters.Clear(); db.AddInParameter(cmdInsertTraceCtn, "@BSNO", DbType.String, optrace.BSNO); db.AddInParameter(cmdInsertTraceCtn, "@CNTRNO", DbType.String, item.CntrNo); db.AddInParameter(cmdInsertTraceCtn, "@TX", DbType.String, item.PortloadCtnDate); db.AddInParameter(cmdInsertTraceCtn, "@FC", DbType.String, item.PortloadRtYard); db.AddInParameter(cmdInsertTraceCtn, "@TH", DbType.String, item.PortDischargeDelivery); db.AddInParameter(cmdInsertTraceCtn, "@FK", DbType.String, item.PortDischargeRtCtn); db.AddInParameter(cmdInsertTraceCtn, "@INPUTDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.AddInParameter(cmdInsertTraceCtn, "@UPDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.ExecuteNonQuery(cmdInsertTraceCtn, tran); } } } else { var strSql = new StringBuilder(); strSql.Append("update t_op_seae_trace SET [更新时间]=@UPDATE "); if (!string.IsNullOrEmpty(enumValue.PortloadCtnDate)) { strSql.Append(",提箱=@TX"); } if (!string.IsNullOrEmpty(enumValue.PortloadRtYard)) { strSql.Append(",重箱返场日期=@FC"); } if (!string.IsNullOrEmpty(enumValue.PortloadShipment)) { strSql.Append(",装船=@ZC"); } if (!string.IsNullOrEmpty(enumValue.PortloadOnBoard)) { strSql.Append(",开航=@KAIHANG"); } if (!string.IsNullOrEmpty(enumValue.Transport1Arrival)) { strSql.Append(",中转抵港1=@ZZDG1"); } if (!string.IsNullOrEmpty(enumValue.Transport1Unload)) { strSql.Append(",中转卸载1=@ZZXZ1"); } if (!string.IsNullOrEmpty(enumValue.Transport1Shipment)) { strSql.Append(",中转装船1=@ZZZC1"); } if (!string.IsNullOrEmpty(enumValue.Transport1OnBoard)) { strSql.Append(",中转开航1=@ZZKH1"); } if (!string.IsNullOrEmpty(enumValue.Transport2Arrival)) { strSql.Append(",中转抵港2=@ZZDG2"); } if (!string.IsNullOrEmpty(enumValue.Transport2Unload)) { strSql.Append(",中转卸载2=@ZZXZ2"); } if (!string.IsNullOrEmpty(enumValue.Transport2Shipment)) { strSql.Append(",中转装船2=@ZZZC2"); } if (!string.IsNullOrEmpty(enumValue.Transport2OnBoard)) { strSql.Append(",中转开航2=@ZZKH2"); } if (!string.IsNullOrEmpty(enumValue.Transport3Arrival)) { strSql.Append(",中转抵港3=@ZZDG3"); } if (!string.IsNullOrEmpty(enumValue.Transport3Unload)) { strSql.Append(",中转卸载3=@ZZXZ3"); } if (!string.IsNullOrEmpty(enumValue.Transport3Shipment)) { strSql.Append(",中转装船3=@ZZZC3"); } if (!string.IsNullOrEmpty(enumValue.Transport3OnBoard)) { strSql.Append(",中转开航3=@ZZKH3"); } if (!string.IsNullOrEmpty(enumValue.PortDischargeArrival)) { strSql.Append(",[抵港]=@DG"); } if (!string.IsNullOrEmpty(enumValue.PortDischargeUnload)) { strSql.Append(",[卸载]=@XZ"); } if (!string.IsNullOrEmpty(enumValue.PortDischargeCarrierRelease)) { strSql.Append(",[船东放货]=@FH"); } if (!string.IsNullOrEmpty(enumValue.PortDischargeDelivery)) { strSql.Append(",[提货]=@TH"); } if (!string.IsNullOrEmpty(enumValue.PortDischargeRtCtn)) { strSql.Append(",[返空]=@FK"); } if (!string.IsNullOrEmpty(enumValue.WarningMsg)) { strSql.Append(",预警提醒=@YJXX"); } if (!string.IsNullOrEmpty(enumValue.Eta)) { strSql.Append(",ETA=@ETA"); } strSql.Append(" WHERE TR_ID=@TRID"); var cmdUpdateTrace = db.GetSqlStringCommand(strSql.ToString()); cmdUpdateTrace.Parameters.Clear(); db.AddInParameter(cmdUpdateTrace, "@UPDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); if (!string.IsNullOrEmpty(enumValue.PortloadCtnDate)) { db.AddInParameter(cmdUpdateTrace, "@TX", DbType.String, enumValue.PortloadCtnDate); } if (!string.IsNullOrEmpty(enumValue.PortloadRtYard)) { db.AddInParameter(cmdUpdateTrace, "@FC", DbType.String, enumValue.PortloadRtYard); } if (!string.IsNullOrEmpty(enumValue.PortloadShipment)) { db.AddInParameter(cmdUpdateTrace, "@ZC", DbType.String, enumValue.PortloadShipment); } if (!string.IsNullOrEmpty(enumValue.PortloadOnBoard)) { db.AddInParameter(cmdUpdateTrace, "@KAIHANG", DbType.String, enumValue.PortloadOnBoard); } if (!string.IsNullOrEmpty(enumValue.Transport1Arrival)) { db.AddInParameter(cmdUpdateTrace, "@ZZDG1", DbType.String, enumValue.Transport1Arrival); } if (!string.IsNullOrEmpty(enumValue.Transport1Unload)) { db.AddInParameter(cmdUpdateTrace, "@ZZXZ1", DbType.String, enumValue.Transport1Unload); } if (!string.IsNullOrEmpty(enumValue.Transport1Shipment)) { db.AddInParameter(cmdUpdateTrace, "@ZZZC1", DbType.String, enumValue.Transport1Shipment); } if (!string.IsNullOrEmpty(enumValue.Transport1OnBoard)) { db.AddInParameter(cmdUpdateTrace, "@ZZKH1", DbType.String, enumValue.Transport1OnBoard); } if (!string.IsNullOrEmpty(enumValue.Transport2Arrival)) { db.AddInParameter(cmdUpdateTrace, "@ZZDG2", DbType.String, enumValue.Transport2Arrival); } if (!string.IsNullOrEmpty(enumValue.Transport2Unload)) { db.AddInParameter(cmdUpdateTrace, "@ZZXZ2", DbType.String, enumValue.Transport2Unload); } if (!string.IsNullOrEmpty(enumValue.Transport2Shipment)) { db.AddInParameter(cmdUpdateTrace, "@ZZZC2", DbType.String, enumValue.Transport2Shipment); } if (!string.IsNullOrEmpty(enumValue.Transport2OnBoard)) { db.AddInParameter(cmdUpdateTrace, "@ZZKH2", DbType.String, enumValue.Transport2OnBoard); } if (!string.IsNullOrEmpty(enumValue.Transport3Arrival)) { db.AddInParameter(cmdUpdateTrace, "@ZZDG3", DbType.String, enumValue.Transport3Arrival); } if (!string.IsNullOrEmpty(enumValue.Transport3Unload)) { db.AddInParameter(cmdUpdateTrace, "@ZZXZ3", DbType.String, enumValue.Transport3Unload); } if (!string.IsNullOrEmpty(enumValue.Transport3Shipment)) { db.AddInParameter(cmdUpdateTrace, "@ZZZC3", DbType.String, enumValue.Transport3Shipment); } if (!string.IsNullOrEmpty(enumValue.Transport3OnBoard)) { db.AddInParameter(cmdUpdateTrace, "@ZZKH3", DbType.String, enumValue.Transport3OnBoard); } if (!string.IsNullOrEmpty(enumValue.PortDischargeArrival)) { db.AddInParameter(cmdUpdateTrace, "@DG", DbType.String, enumValue.PortDischargeArrival); } if (!string.IsNullOrEmpty(enumValue.PortDischargeUnload)) { db.AddInParameter(cmdUpdateTrace, "@XZ", DbType.String, enumValue.PortDischargeUnload); } if (!string.IsNullOrEmpty(enumValue.PortDischargeCarrierRelease)) { db.AddInParameter(cmdUpdateTrace, "@FH", DbType.String, enumValue.PortDischargeCarrierRelease); } if (!string.IsNullOrEmpty(enumValue.PortDischargeDelivery)) { db.AddInParameter(cmdUpdateTrace, "@TH", DbType.String, enumValue.PortDischargeDelivery); } if (!string.IsNullOrEmpty(enumValue.PortDischargeRtCtn)) { db.AddInParameter(cmdUpdateTrace, "@FK", DbType.String, enumValue.PortDischargeRtCtn); } if (!string.IsNullOrEmpty(enumValue.WarningMsg)) { db.AddInParameter(cmdUpdateTrace, "@YJXX", DbType.String, enumValue.WarningMsg); } if (!string.IsNullOrEmpty(enumValue.Eta)) { db.AddInParameter(cmdUpdateTrace, "@ETA", DbType.String, enumValue.Eta); } db.AddInParameter(cmdUpdateTrace, "@TRID", DbType.String, optrace.TRID); db.ExecuteNonQuery(cmdUpdateTrace, tran); if (enumValue.CntrList != null) { foreach (var item in enumValue.CntrList) { var optraceCtn = GetSeaeTraceCtn("编号='" + optrace.BSNO + "' and 箱号='" + item.CntrNo + "'", db, tran); if (string.IsNullOrEmpty(optraceCtn.TRID)) { cmdInsertTraceCtn.Parameters.Clear(); db.AddInParameter(cmdInsertTraceCtn, "@BSNO", DbType.String, optrace.BSNO); db.AddInParameter(cmdInsertTraceCtn, "@CNTRNO", DbType.String, item.CntrNo); db.AddInParameter(cmdInsertTraceCtn, "@TX", DbType.String, item.PortloadCtnDate); db.AddInParameter(cmdInsertTraceCtn, "@FC", DbType.String, item.PortloadRtYard); db.AddInParameter(cmdInsertTraceCtn, "@TH", DbType.String, item.PortDischargeDelivery); db.AddInParameter(cmdInsertTraceCtn, "@FK", DbType.String, item.PortDischargeRtCtn); db.AddInParameter(cmdInsertTraceCtn, "@INPUTDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.AddInParameter(cmdInsertTraceCtn, "@UPDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); db.ExecuteNonQuery(cmdInsertTraceCtn, tran); } else { var strSqlCtn = new StringBuilder(); strSqlCtn.Append("update t_op_seae_trace_ctn SET [更新时间]=@UPDATE "); if (!string.IsNullOrEmpty(item.PortloadCtnDate)) { strSqlCtn.Append(",提箱时间=@TX"); } if (!string.IsNullOrEmpty(item.PortloadRtYard)) { strSqlCtn.Append(",返场时间=@FC"); } if (!string.IsNullOrEmpty(item.PortDischargeDelivery)) { strSqlCtn.Append(",[提货时间]=@TH"); } if (!string.IsNullOrEmpty(item.PortDischargeRtCtn)) { strSqlCtn.Append(",[返空时间]=@FK"); } strSqlCtn.Append(" WHERE TRCTN_ID=@TRID"); var cmdUpdateTraceCtn = db.GetSqlStringCommand(strSqlCtn.ToString()); cmdUpdateTraceCtn.Parameters.Clear(); db.AddInParameter(cmdUpdateTraceCtn, "@UPDATE", DbType.String, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss")); if (!string.IsNullOrEmpty(item.PortloadCtnDate)) { db.AddInParameter(cmdUpdateTraceCtn, "@TX", DbType.String, item.PortloadCtnDate); } if (!string.IsNullOrEmpty(item.PortloadRtYard)) { db.AddInParameter(cmdUpdateTraceCtn, "@FC", DbType.String, item.PortloadRtYard); } if (!string.IsNullOrEmpty(item.PortDischargeDelivery)) { db.AddInParameter(cmdUpdateTraceCtn, "@TH", DbType.String, item.PortDischargeDelivery); } if (!string.IsNullOrEmpty(item.PortDischargeRtCtn)) { db.AddInParameter(cmdUpdateTraceCtn, "@FK", DbType.String, item.PortDischargeRtCtn); } db.AddInParameter(cmdUpdateTraceCtn, "@TRID", DbType.String, optraceCtn.TRID); db.ExecuteNonQuery(cmdUpdateTraceCtn, tran); } } } //if (!string.IsNullOrEmpty(enumValue.PortloadOnBoard)) //{ // if (!string.IsNullOrEmpty(enumValue.Eta)) // { // var cmdUpdateETD = // db.GetSqlStringCommand(" update t_op_seae set ETD='" + Convert.ToDateTime(enumValue.PortloadOnBoard).ToString("yyyy-MM-dd hh:MM:ss") + "',预抵日期='" + Convert.ToDateTime(enumValue.PortloadOnBoard).ToString("yyyy-MM-dd hh:MM:ss") + "',ETA='" + Convert.ToDateTime(enumValue.Eta).ToString("yyyy-MM-dd hh:MM:ss") + "' where 编号='" + optrace.BSNO + "'"); // db.ExecuteNonQuery(cmdUpdateETD, tran); // } // else // { // var cmdUpdateETD = // db.GetSqlStringCommand(" update t_op_seae set ETD='" + Convert.ToDateTime(enumValue.PortloadOnBoard).ToString("yyyy-MM-dd hh:MM:ss") + "',预抵日期='" + Convert.ToDateTime(enumValue.PortloadOnBoard).ToString("yyyy-MM-dd hh:MM:ss") + "' where 编号='" + optrace.BSNO + "'"); // db.ExecuteNonQuery(cmdUpdateETD, tran); // } //} //else if(!string.IsNullOrEmpty(enumValue.Eta)) { var cmdUpdateETD = db.GetSqlStringCommand(" update t_op_seae set ETA='" + Convert.ToDateTime(enumValue.Eta).ToString("yyyy-MM-dd hh:MM:ss") + "' where 编号='" + optrace.BSNO + "'"); db.ExecuteNonQuery(cmdUpdateETD, tran); } } } } } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = e.Message; return result; } } result.Success = true; result.Message = GID; return result; } static public MsOpSeaeTraceBsNo GetSeaeTrace(string strCondition,Database db, DbTransaction tran) { var strSql = new StringBuilder(); strSql.Append("SELECT top 1 t_op_seae.编号 BSNO,t_op_seae_trace.TR_ID from t_op_seae (NOLOCK) left join t_op_seae_trace on (t_op_seae_trace.编号=t_op_seae.编号) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var headData = new MsOpSeaeTraceBsNo(); using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString())) { while (reader.Read()) { headData.TRID = Convert.ToString(reader["TR_ID"]); headData.BSNO = Convert.ToString(reader["BSNO"]); } reader.Close(); } return headData; } static public MsOpSeaeTraceBsNo GetSeaeTraceCtn(string strCondition, Database db, DbTransaction tran) { var strSql = new StringBuilder(); strSql.Append("SELECT top 1 TRCTN_ID from t_op_seae_trace_ctn (NOLOCK) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var headData = new MsOpSeaeTraceBsNo(); using (IDataReader reader = db.ExecuteReader(tran, CommandType.Text, strSql.ToString())) { while (reader.Read()) { headData.TRID = Convert.ToString(reader["TRCTN_ID"]); } reader.Close(); } return headData; } public static DBResult UpdateVgmStatus(VgmStatus VgmStatus) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { //if (ctnbodyList != null) //{ // foreach (var enumValue in ctnbodyList) // { // if (string.IsNullOrEmpty(enumValue.BSNO)) // { // if (!string.IsNullOrEmpty(enumValue.MBLNO)) // { // var VGMSTATUS = "update t_op_seae SET 1=1"; // if (!string.IsNullOrEmpty(enumValue.VGMSTATUS)) VGMSTATUS = VGMSTATUS + ",VGM状态='" + enumValue.VGMSTATUS + "'"; // if (!string.IsNullOrEmpty(enumValue.VGMURL)) VGMSTATUS = VGMSTATUS + ",VGMURL='" + enumValue.VGMURL + "'"; // VGMSTATUS = VGMSTATUS + " 主提单号='" + enumValue.MBLNO + "'"; // db.ExecuteNonQuery(tran, CommandType.Text, VGMSTATUS); // } // } // else // { var VGMSTATUS = "update t_op_seae SET 业务编号=业务编号"; if (!string.IsNullOrEmpty(VgmStatus.status)) VGMSTATUS = VGMSTATUS + ",VGM状态='"+ VgmStatus.status + "'"; if (!string.IsNullOrEmpty(VgmStatus.vgmLink)) VGMSTATUS = VGMSTATUS + ",VGMURL='" + VgmStatus.vgmLink + "'"; VGMSTATUS = VGMSTATUS + " WHERE 业务编号='" + VgmStatus.bsno+ "'"; db.ExecuteNonQuery(tran, CommandType.Text, VGMSTATUS); // } // } //} tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = e.Message; return result; } } result.Success = true; result.Message =""; return result; } public static DBResult UpdateYardStatus(YardStatus VgmStatus) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var VGMSTATUS = "update t_op_seae SET 业务编号=业务编号"; if (VgmStatus.status) VGMSTATUS = VGMSTATUS + ",核对提单=1"; else VGMSTATUS = VGMSTATUS + ",核对提单=0"; VGMSTATUS = VGMSTATUS + " WHERE 业务编号='" + VgmStatus.bsno + "'"; db.ExecuteNonQuery(tran, CommandType.Text, VGMSTATUS); tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = e.Message; return result; } } result.Success = true; result.Message = ""; return result; } public static DBResult ImportCdData(MsOpSeaeEdi bill) { 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_seae_edi(编号,主编号,EDI类型,EDI状态,录入人,录入日期,业务编号,主提单号,分提单号,发货人企业代码 ,发货人名称,发货人地址1,发货人地址2,发货人国家代码,发货人电话,收货人企业代码,收货人名称,收货人地址1,收货人地址2 ,收货人国家代码,收货人电话,通知人企业代码,通知人名称,通知人地址1,通知人地址2,通知人国家代码,通知人电话 ,船名,航次,开船日期,装港代码,装货港,卸货代码,卸货港,交货代码,交货地点 ,目的代码,目的地,运输条款,唛头,货物描述,件数,包装,重量,尺码,货物标识,危险品分类 ,危险品编号,冷藏通风量,温度单位,设置温度,船舶IMO,船公司代码,装运类型,付费方式,场站,船公司,预抵日期,船代,委托发送方 ,单价,应收,备注,危险品联系人,危险品电话,是否冻代干) VALUES (@BSNO,@MASTERNO,@EDITYPE,@EDISTATUS,@INPUTBY,@INPUTDATE,@CUSTNO,@MBLNO,@HBLNO,@SHIPPERCODE ,@SHIPPERNAME,@SHIPPERADDR1,@SHIPPERADDR2,@SHIPPERCOUNTRY,@SHIPPERTEL,@CONSIGNEECODE,@CONSIGNEENAME,@CONSIGNEEADDR1,@CONSIGNEEADDR2 ,@CONSIGNEECOUNTRY,@CONSIGNEETEL,@NOTIFYPARTYCODE,@NOTIFYPARTYNAME,@NOTIFYPARTYADDR1,@NOTIFYPARTYADDR2,@NOTIFYPARTYCOUNTRY,@NOTIFYPARTYTEL ,@VESSEL,@VOYNO,@ETD,@PORTLOADID,@PORTLOAD,@PORTDISCHARGEID,@PORTDISCHARGE,@PLACEDELIVERYID,@PLACEDELIVERY ,@DESTINATIONID,@DESTINATION,@SERVICE,@MARKS,@DESCRIPTION,@PKGS,@KINDPKGS,@KGS,@CBM,@CARGOID,@DCLASS ,@DUNNO,@REEFERF,@TEMPID,@TEMPSET,@SHIPIMO,@CARRIERID,@TRANSTYPE,@BLFRT,@YARD,@CARRIER,@ETA,@FORWARDER,@CUSTOMERNAME ,@PRICE,@DRAMOUNT,@REMARK,@DATTN,@DTEL,@ISNOR) "); var orderinputby = ConfigurationManager.AppSettings["orderinputby"]; //if (MsOpSeaeEdiList != null) //{ // foreach (var bill in MsOpSeaeEdiList) // { var bsno = Get_id(); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, bsno); db.AddInParameter(cmdInsert, "@MASTERNO", DbType.String, bsno); db.AddInParameter(cmdInsert, "@EDITYPE", DbType.String, "CN"); db.AddInParameter(cmdInsert, "@EDISTATUS", DbType.String, "未发送"); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, orderinputby); db.AddInParameter(cmdInsert, "@INPUTDATE", DbType.DateTime, DateTime.Now); db.AddInParameter(cmdInsert, "@CUSTNO", DbType.String, bsno); db.AddInParameter(cmdInsert, "@MBLNO", DbType.String, bill.MBLNO); db.AddInParameter(cmdInsert, "@HBLNO", DbType.String, bill.HBLNO); db.AddInParameter(cmdInsert, "@SHIPPERCODE", DbType.String, bill.LeiXingFa+"+"+bill.SHIPPERCODE); db.AddInParameter(cmdInsert, "@SHIPPERNAME", DbType.String, bill.SHIPPERNAME); db.AddInParameter(cmdInsert, "@SHIPPERADDR1", DbType.String, bill.SHIPPERADDR1); db.AddInParameter(cmdInsert, "@SHIPPERADDR2", DbType.String, bill.SHIPPERADDR2); db.AddInParameter(cmdInsert, "@SHIPPERCOUNTRY", DbType.String, bill.SHIPPERCOUNTRY); db.AddInParameter(cmdInsert, "@SHIPPERTEL", DbType.String, bill.SHIPPERTEL); db.AddInParameter(cmdInsert, "@CONSIGNEECODE", DbType.String, bill.LeiXingShou + "+" + bill.CONSIGNEECODE); db.AddInParameter(cmdInsert, "@CONSIGNEENAME", DbType.String, bill.CONSIGNEENAME); db.AddInParameter(cmdInsert, "@CONSIGNEEADDR1", DbType.String, bill.CONSIGNEEADDR1); db.AddInParameter(cmdInsert, "@CONSIGNEEADDR2", DbType.String, bill.CONSIGNEEADDR2); db.AddInParameter(cmdInsert, "@CONSIGNEECOUNTRY", DbType.String, bill.CONSIGNEECOUNTRY); db.AddInParameter(cmdInsert, "@CONSIGNEETEL", DbType.String, bill.CONSIGNEETEL); db.AddInParameter(cmdInsert, "@NOTIFYPARTYCODE", DbType.String, bill.LeiXingShou + "+" + bill.NOTIFYPARTYCODE); db.AddInParameter(cmdInsert, "@NOTIFYPARTYNAME", DbType.String, bill.NOTIFYPARTYNAME); db.AddInParameter(cmdInsert, "@NOTIFYPARTYADDR1", DbType.String, bill.NOTIFYPARTYADDR1); db.AddInParameter(cmdInsert, "@NOTIFYPARTYADDR2", DbType.String, bill.NOTIFYPARTYADDR2); db.AddInParameter(cmdInsert, "@NOTIFYPARTYCOUNTRY", DbType.String, bill.NOTIFYPARTYCOUNTRY); db.AddInParameter(cmdInsert, "@NOTIFYPARTYTEL", DbType.String, bill.NOTIFYPARTYTEL); db.AddInParameter(cmdInsert, "@VESSEL", DbType.String, bill.VESSEL); db.AddInParameter(cmdInsert, "@VOYNO", DbType.String, bill.VOYNO); db.AddInParameter(cmdInsert, "@ETD", DbType.String, bill.ETD); db.AddInParameter(cmdInsert, "@PORTLOADID", DbType.String, bill.PORTLOADID); db.AddInParameter(cmdInsert, "@PORTLOAD", DbType.String, bill.PORTLOAD); db.AddInParameter(cmdInsert, "@PORTDISCHARGEID", DbType.String, bill.PORTDISCHARGEID); db.AddInParameter(cmdInsert, "@PORTDISCHARGE", DbType.String, bill.PORTDISCHARGE); db.AddInParameter(cmdInsert, "@PLACEDELIVERYID", DbType.String, bill.PLACEDELIVERYID); db.AddInParameter(cmdInsert, "@PLACEDELIVERY", DbType.String, bill.PLACEDELIVERY); db.AddInParameter(cmdInsert, "@DESTINATIONID", DbType.String, bill.DESTINATIONID); db.AddInParameter(cmdInsert, "@DESTINATION", DbType.String, bill.DESTINATION); db.AddInParameter(cmdInsert, "@SERVICE", DbType.String, bill.SERVICE); db.AddInParameter(cmdInsert, "@MARKS", DbType.String, bill.MARKS); db.AddInParameter(cmdInsert, "@PKGS", DbType.String, bill.PKGS); db.AddInParameter(cmdInsert, "@KINDPKGS", DbType.String, bill.KINDPKGS); db.AddInParameter(cmdInsert, "@KGS", DbType.String, bill.KGS); db.AddInParameter(cmdInsert, "@CBM", DbType.String, bill.CBM); db.AddInParameter(cmdInsert, "@CARGOID", DbType.String, bill.CARGOID); db.AddInParameter(cmdInsert, "@DCLASS", DbType.String, bill.DCLASS); db.AddInParameter(cmdInsert, "@DUNNO", DbType.String, bill.DUNNO); db.AddInParameter(cmdInsert, "@REEFERF", DbType.String, bill.REEFERF); db.AddInParameter(cmdInsert, "@TEMPID", DbType.String, bill.TEMPID); db.AddInParameter(cmdInsert, "@TEMPSET", DbType.String, bill.TEMPSET); db.AddInParameter(cmdInsert, "@SHIPIMO", DbType.String, bill.SHIPIMO); db.AddInParameter(cmdInsert, "@CARRIERID", DbType.String, bill.CARRIERID); db.AddInParameter(cmdInsert, "@TRANSTYPE", DbType.String, bill.TRANSTYPE); db.AddInParameter(cmdInsert, "@BLFRT", DbType.String, bill.BLFRT); db.AddInParameter(cmdInsert, "@YARD", DbType.String, bill.YARD); db.AddInParameter(cmdInsert, "@CARRIER", DbType.String, bill.CARRIER); db.AddInParameter(cmdInsert, "@ETA", DbType.String, bill.ETA); db.AddInParameter(cmdInsert, "@FORWARDER", DbType.String, bill.FORWARDER); db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, bill.WeiTuoFaSongFang); db.AddInParameter(cmdInsert, "@PRICE", DbType.String, bill.PRICE); db.AddInParameter(cmdInsert, "@DRAMOUNT", DbType.String, bill.DRAMOUNT); db.AddInParameter(cmdInsert, "@REMARK", DbType.String, bill.SENDREMARK); db.AddInParameter(cmdInsert, "@DATTN", DbType.String, bill.DATTN); db.AddInParameter(cmdInsert, "@DTEL", DbType.String, bill.DTEL); db.AddInParameter(cmdInsert, "@ISNOR", DbType.Boolean, bill.ISNOR); db.ExecuteNonQuery(cmdInsert, tran); if (bill.CTNLIST != null) { foreach (var ctn in bill.CTNLIST) { var cmdInsertCtn = db.GetSqlStringCommand(@"insert into t_op_ctn_edi (编号,代码,尺寸,箱型,数量,TEU,表现形式,箱号,封号,件数,重量,尺码,包装,重箱整箱标志,施封人) values ('" + bsno + "','" + ctn.CTNCODE + "','" + ctn.SIZE + "','" + ctn.CTN + "'," + ctn.CTNNUM + "," + ctn.TEU + ",'" + ctn.CTNALL.Replace("'", "''") + "','" + ctn.CNTRNO + "','" + ctn.SEALNO + "','" + ctn.PKGS + "'," + ctn.KGS + "," + ctn.CBM + ",'" + ctn.KINDPKGS + "','" + ctn.ZhongKongBiaoShi + "','" + ctn.ShiFengRen+ "')"); db.ExecuteNonQuery(cmdInsertCtn, tran); } } // } //} tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = e.Message; return result; } } result.Success = true; result.Message = ""; return result; } public static string Get_id() { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_id"); db.AddOutParameter(cmd, "@str", DbType.String, 12); db.ExecuteNonQuery(cmd); return Convert.ToString(db.GetParameterValue(cmd, "@str")); } public static string GetBsNo() { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_no_get"); db.AddInParameter(cmd, "@Code", DbType.String,"SI"+DateTime.Now.ToString("yyyyMM")); db.AddOutParameter(cmd, "@Num", DbType.String, 12); db.ExecuteNonQuery(cmd); return Convert.ToString(db.GetParameterValue(cmd, "@Num")); } static public int GetSeaiRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT Count(*) AS CT from t_op_seai (NOLOCK) "); 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; } static public string GetSeaiBSNO(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT 编号 BSNO from t_op_seai (NOLOCK) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var BSNO=""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BSNO= Convert.ToString(reader["BSNO"]); } reader.Close(); } return BSNO; } static public string GetFeeRate(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT 英文名 RATE from t_code_fee (NOLOCK) "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var BSNO = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BSNO = Convert.ToString(reader["RATE"]); } reader.Close(); } return BSNO; } public static OpSeaeModel GetOneByBSNO(string bsno) { var strSql = new StringBuilder(); strSql.AppendLine("SELECT BSNO,VESSEL,VOYNO,MBLNO,INVNO,ETD,ATD,CNTRTOTAL,KGS,YARD,CNTRSEALNO,CUSTOMNO,"); strSql.AppendLine("(SELECT dbo.Fun_JoinFactoryAddr(S.BSNO)) FACTORYADDR,"); strSql.AppendLine("ISNULL((SELECT TOP 1 CARGODATE FROM OP_LETTER_TRUCK WHERE BSNO=S.BSNO ORDER BY TRUCKDATE DESC),'') CARGODATE,"); strSql.AppendLine("(SELECT COMPTIME FROM OP_STATUS WHERE BSNO=S.BSNO AND ISCOMP=1 and [status]='重箱返场') STA_ZXFC,"); strSql.AppendLine("(SELECT COMPTIME FROM OP_STATUS WHERE BSNO=S.BSNO AND ISCOMP=1 and [status]='海关放行') STA_HGFX"); strSql.AppendLine("FROM OP_SEAE S"); strSql.AppendLine($"WHERE BSNO='{bsno}'"); var list = SetData(strSql); if (list.Count > 0) { return list[0]; } return null; } } }