using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcContainer.Models.MsOpPrice; using DSWeb.MvcContainer.Models.MsOpCtnApply; using DSWeb.MvcContainer.Models.MsOpCtnBsCard; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using DSWeb.MvcShipping.DAL.MsBaseInfoDAL; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.DAL; using DSWeb.MvcShipping.Models.MsChFee; using DSWeb.MvcContainer.DAL.MsOpPrice; namespace DSWeb.MvcContainer.DAL.MsOpCtnBsCard { public class MsOpCtnBsCardDAL { #region Inquery DataList static public List GetDataList(int start, int limit, out int totel, string strCondition, string pricetype, string companyid, string userid,string username, string sort = null) { var rangstr = GetRangDAStr(pricetype, userid, username, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("DESTPORT_OVER_DAYS_AMT", "cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2))"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by INPUTTIME DESC "); } strSql.Append(@") as num , "); strSql.Append(" b.GID,b.CTNNO,b.CTNPROP,[BSNO],SEABSNO,[APPLYNO],[CUSTOMERNAME],[GOODSNAME] ,[ETD]"); strSql.Append(",PREETA,[ETA],[AGENTNAME],[CYCLE_DAY],[IS_BOOKING]"); strSql.Append(",[IS_RETURE_EMPTY],[I_CUSTNO],[I_ETD],PREI_ETA,[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN]"); strSql.Append(",[I_DESTPORT]"); strSql.Append(",[IS_DB],[D_CUSTNO],[D_ETD],PRED_ETA,[D_ETA],[D_MBLNO],[D_CUSTNAME],[D_CARRIER],[D_CONTRACT],[D_PORTLOAD_CNT_TIME]"); strSql.Append(",[D_PORTLOAD],[D_ARRIVALDATE],[D_DEST_CNT_TIME],[D_DEST_RTCNT_TIME],[D_DESTPORT_STATOIN]"); strSql.Append(",[D_DESTPORT]"); strSql.Append(",[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL],b.CURSTATOIN,[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOADDATE],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2)) DESTPORT_OVER_DAYS_AMT,[DETAIN_CTN_DAYS],[PRE_CNT_TIME],[AUDITBY]"); strSql.Append(",AUDITSTATUS,[AUDITTIME],[AUDITRESULT],b.REMARKS,b.INPUTBY,b.INPUTTIME,b.COMPANYID,PUTCTNAUDITBY,PUTCTNAUDITSTATUS,PUTCTNAUDITTIME,PUTCTNAUDITRESULT"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS,IS_POD_CLEAN,IS_PUTCTN,PUTCTNDATE,MODIFYTIME,MODIFYUSER"); strSql.Append(",(select TOP 1 ISPORTLOADDATE from op_ctnapply where BSNO=b.APPLYNO) as ISPORTLOADDATE"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.PUTCTNAUDITBY) as PUTCTNAUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NETD"); strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME '' and D_DEST_RTCNT_TIME <= GETDATE() then D_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when D_DEST_CNT_TIME <> '' and D_DEST_CNT_TIME <= GETDATE() then D_DESTPORT + '-待还箱'"); strSql.Append(" else case when D_ETA <> '' and D_ETA <= GETDATE() then D_DESTPORT + '-待提货'"); strSql.Append(" else case when D_ETD <> '' and D_ETD <= GETDATE() then D_PORTLOAD + '-已开船'"); strSql.Append(" else case when D_PORTLOAD_CNT_TIME <> '' and D_PORTLOAD_CNT_TIME <= GETDATE() then D_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" CASE WHEN IS_RETURE_EMPTY = 1 THEN"); strSql.Append(" (case when I_DEST_RTCNT_TIME <> '' and I_DEST_RTCNT_TIME <= GETDATE() then I_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when I_DEST_CNT_TIME <> '' and I_DEST_CNT_TIME <= GETDATE() then I_DESTPORT + '-待还箱'"); strSql.Append(" else case when I_ETA <> '' and I_ETA <= GETDATE() then I_DESTPORT + '-待提货'"); strSql.Append(" else case when I_ETD <> '' and I_ETD <= GETDATE() then I_PORTLOAD + '-已开船'"); strSql.Append(" else case when I_PORTLOAD_CNT_TIME <> '' and I_PORTLOAD_CNT_TIME <= GETDATE() then I_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" (case when DEST_RTCNT_TIME <> '' and DEST_RTCNT_TIME <= GETDATE() then DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when DEST_CNT_TIME <> '' and DEST_CNT_TIME <= GETDATE() then DESTPORT + '-待还箱'"); strSql.Append(" else case when ETA <> '' and ETA <= GETDATE() then DESTPORT + '-待提货'"); strSql.Append(" else case when ETD <> '' and ETD <= GETDATE() then PORTLOAD + '-已开船'"); strSql.Append(" else case when PORTLOAD_CNT_TIME <> '' and PORTLOAD_CNT_TIME <= GETDATE() then PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" END"); strSql.Append(" END "); strSql.Append(" CUR_PORT,SHENTIME"); //系统判断业务卡中“生成目的港箱使费”这个按钮有没有点过 strSql.Append(",dbo.F_CTNBSCARD_ExistsMDGXSF(b.GID) MDGXSFSTATUS"); strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称) strSql.Append(",SERVICE,isnull(NEEDBEHEATED,0)NEEDBEHEATED,AGENTINPUTBY,isnull(EMPTYCTNALLOCATION,0)EMPTYCTNALLOCATION");//运输条款 是否加热 代理维护人 strSql.Append(" from op_ctnbscard b "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // totel = getTotalCount(strCondition); return SetData(strSql); } public static int getTotalCount(string strCondition) { StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) from op_ctnbscard b"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public List GetDataAllList(string strCondition, string pricetype, string companyid, string userid, string username, string sort = null) { var rangstr = GetRangDAStr(pricetype, userid, username, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT b.GID,b.CTNNO,b.CTNPROP,[BSNO],SEABSNO,[APPLYNO],[CUSTOMERNAME],[GOODSNAME] ,[ETD]"); strSql.Append(",PREETA,[ETA],[AGENTNAME],[CYCLE_DAY],[IS_RETURE_EMPTY],[IS_BOOKING],[I_CUSTNO]"); strSql.Append(",[I_ETD],PREI_ETA,[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN],[I_DESTPORT]"); strSql.Append(",[IS_DB],[D_CUSTNO],[D_ETD],PRED_ETA,[D_ETA],[D_MBLNO],[D_CUSTNAME],[D_CARRIER],[D_CONTRACT],[D_PORTLOAD_CNT_TIME]"); strSql.Append(",[D_PORTLOAD],[D_ARRIVALDATE],[D_DEST_CNT_TIME],[D_DEST_RTCNT_TIME],[D_DESTPORT_STATOIN]"); strSql.Append(",[D_DESTPORT]"); strSql.Append(",[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL]"); strSql.Append(",b.CURSTATOIN,[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOADDATE],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2)) DESTPORT_OVER_DAYS_AMT,[DETAIN_CTN_DAYS],[PRE_CNT_TIME],[AUDITBY]"); strSql.Append(",AUDITSTATUS,[AUDITTIME],[AUDITRESULT],b.REMARKS,b.INPUTBY,b.INPUTTIME,b.COMPANYID,PUTCTNAUDITBY,PUTCTNAUDITSTATUS,PUTCTNAUDITTIME,PUTCTNAUDITRESULT"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS,IS_POD_CLEAN,IS_PUTCTN,PUTCTNDATE,MODIFYTIME,MODIFYUSER"); strSql.Append(",(select TOP 1 ISPORTLOADDATE from op_ctnapply where BSNO=b.APPLYNO) as ISPORTLOADDATE"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.PUTCTNAUDITBY) as PUTCTNAUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NETD"); strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME '' and D_DEST_RTCNT_TIME <= GETDATE() then D_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when D_DEST_CNT_TIME <> '' and D_DEST_CNT_TIME <= GETDATE() then D_DESTPORT + '-待还箱'"); strSql.Append(" else case when D_ETA <> '' and D_ETA <= GETDATE() then D_DESTPORT + '-待提货'"); strSql.Append(" else case when D_ETD <> '' and D_ETD <= GETDATE() then D_PORTLOAD + '-已开船'"); strSql.Append(" else case when D_PORTLOAD_CNT_TIME <> '' and D_PORTLOAD_CNT_TIME <= GETDATE() then D_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" CASE WHEN IS_RETURE_EMPTY = 1 THEN"); strSql.Append(" (case when I_DEST_RTCNT_TIME <> '' and I_DEST_RTCNT_TIME <= GETDATE() then I_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when I_DEST_CNT_TIME <> '' and I_DEST_CNT_TIME <= GETDATE() then I_DESTPORT + '-待还箱'"); strSql.Append(" else case when I_ETA <> '' and I_ETA <= GETDATE() then I_DESTPORT + '-待提货'"); strSql.Append(" else case when I_ETD <> '' and I_ETD <= GETDATE() then I_PORTLOAD + '-已开船'"); strSql.Append(" else case when I_PORTLOAD_CNT_TIME <> '' and I_PORTLOAD_CNT_TIME <= GETDATE() then I_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" (case when DEST_RTCNT_TIME <> '' and DEST_RTCNT_TIME <= GETDATE() then DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when DEST_CNT_TIME <> '' and DEST_CNT_TIME <= GETDATE() then DESTPORT + '-待还箱'"); strSql.Append(" else case when ETA <> '' and ETA <= GETDATE() then DESTPORT + '-待提货'"); strSql.Append(" else case when ETD <> '' and ETD <= GETDATE() then PORTLOAD + '-已开船'"); strSql.Append(" else case when PORTLOAD_CNT_TIME <> '' and PORTLOAD_CNT_TIME <= GETDATE() then PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" END"); strSql.Append(" END "); strSql.Append(" CUR_PORT,SHENTIME"); //系统判断业务卡中“生成目的港箱使费”这个按钮有没有点过 strSql.Append(",dbo.F_CTNBSCARD_ExistsMDGXSF(b.GID) MDGXSFSTATUS"); strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称) strSql.Append(",SERVICE,isnull(NEEDBEHEATED,0)NEEDBEHEATED,AGENTINPUTBY,isnull(EMPTYCTNALLOCATION,0)EMPTYCTNALLOCATION");//运输条款 是否加热 代理维护人 strSql.Append(" from op_ctnbscard b "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("DESTPORT_OVER_DAYS_AMT", "cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2))"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by INPUTTIME DESC "); } return SetData(strSql); } static public string GetDataListStr(string strCondition, string pricetype, string companyid, string userid, string username, string sort = null) { var rangstr = GetRangDAStr(pricetype, userid, userid, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("select * from v_op_ctnbscard 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 INPUTTIME DESC "); } return strSql.ToString(); } static public OpCtnBsCard GetData(string condition, string pricetype, string companyid, string userid, string username) { OpCtnBsCard data = null; var list = GetDataAllList(condition, pricetype,companyid, userid,username); if (list.Count > 0) data = list[0]; if (data == null) { data = new OpCtnBsCard(); data.COMPANYID = companyid; } return data; } static public OpCtnBsCard GetData(string condition, string userid) { var strSql = new StringBuilder(); strSql.Append("SELECT b.GID,b.CTNNO,b.CTNPROP,b.BSNO,SEABSNO,[APPLYNO],[CUSTOMERNAME],[GOODSNAME],[ETD]"); strSql.Append(",PREETA,[ETA],[AGENTNAME],[CYCLE_DAY],[IS_RETURE_EMPTY],[IS_BOOKING],[I_CUSTNO]"); strSql.Append(",[I_ETD],PREI_ETA,[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN],[I_DESTPORT]"); strSql.Append(",[IS_DB],[D_CUSTNO],[D_ETD],PRED_ETA,[D_ETA],[D_MBLNO],[D_CUSTNAME],[D_CARRIER],[D_CONTRACT],[D_PORTLOAD_CNT_TIME]"); strSql.Append(",[D_PORTLOAD],[D_ARRIVALDATE],[D_DEST_CNT_TIME],[D_DEST_RTCNT_TIME],[D_DESTPORT_STATOIN]"); strSql.Append(",[D_DESTPORT]"); strSql.Append(",[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL]"); strSql.Append(",b.CURSTATOIN,[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOADDATE],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2)) DESTPORT_OVER_DAYS_AMT,[DETAIN_CTN_DAYS],[PRE_CNT_TIME],[AUDITBY]"); strSql.Append(",AUDITSTATUS,[AUDITTIME],[AUDITRESULT],b.REMARKS,b.INPUTBY,b.INPUTTIME,b.COMPANYID,b.MODIFYTIME,b.MODIFYUSER"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS,IS_POD_CLEAN,IS_PUTCTN,PUTCTNDATE,PUTCTNAUDITBY,PUTCTNAUDITSTATUS,PUTCTNAUDITTIME,PUTCTNAUDITRESULT"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select TOP 1 ISPORTLOADDATE from op_ctnapply where BSNO=b.APPLYNO) as ISPORTLOADDATE"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.PUTCTNAUDITBY) as PUTCTNAUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME) as NETD"); strSql.Append(",(select TOP 1 GOODSNAME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME '' and D_DEST_RTCNT_TIME <= GETDATE() then D_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when D_DEST_CNT_TIME <> '' and D_DEST_CNT_TIME <= GETDATE() then D_DESTPORT + '-待还箱'"); strSql.Append(" else case when D_ETA <> '' and D_ETA <= GETDATE() then D_DESTPORT + '-待提货'"); strSql.Append(" else case when D_ETD <> '' and D_ETD <= GETDATE() then D_PORTLOAD + '-已开船'"); strSql.Append(" else case when D_PORTLOAD_CNT_TIME <> '' and D_PORTLOAD_CNT_TIME <= GETDATE() then D_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" CASE WHEN IS_RETURE_EMPTY = 1 THEN"); strSql.Append(" (case when I_DEST_RTCNT_TIME <> '' and I_DEST_RTCNT_TIME <= GETDATE() then I_DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when I_DEST_CNT_TIME <> '' and I_DEST_CNT_TIME <= GETDATE() then I_DESTPORT + '-待还箱'"); strSql.Append(" else case when I_ETA <> '' and I_ETA <= GETDATE() then I_DESTPORT + '-待提货'"); strSql.Append(" else case when I_ETD <> '' and I_ETD <= GETDATE() then I_PORTLOAD + '-已开船'"); strSql.Append(" else case when I_PORTLOAD_CNT_TIME <> '' and I_PORTLOAD_CNT_TIME <= GETDATE() then I_PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" ELSE"); strSql.Append(" (case when DEST_RTCNT_TIME <> '' and DEST_RTCNT_TIME <= GETDATE() then DESTPORT_STATOIN + '已还箱-闲置'"); strSql.Append(" else case when DEST_CNT_TIME <> '' and DEST_CNT_TIME <= GETDATE() then DESTPORT + '-待还箱'"); strSql.Append(" else case when ETA <> '' and ETA <= GETDATE() then DESTPORT + '-待提货'"); strSql.Append(" else case when ETD <> '' and ETD <= GETDATE() then PORTLOAD + '-已开船'"); strSql.Append(" else case when PORTLOAD_CNT_TIME <> '' and PORTLOAD_CNT_TIME <= GETDATE() then PORTLOAD + '-待开船' end end end end end)"); strSql.Append(" END"); strSql.Append(" END "); strSql.Append(" CUR_PORT,SHENTIME"); //系统判断业务卡中“生成目的港箱使费”这个按钮有没有点过 strSql.Append(",dbo.F_CTNBSCARD_ExistsMDGXSF(b.GID) MDGXSFSTATUS"); strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称) strSql.Append(",SERVICE,isnull(NEEDBEHEATED,0)NEEDBEHEATED,AGENTINPUTBY,isnull(EMPTYCTNALLOCATION,0)EMPTYCTNALLOCATION");//运输条款 是否加热 代理维护人 strSql.Append(" from op_ctnbscard b "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var list = SetData(strSql); if (list.Count > 0) return list[0]; return new OpCtnBsCard(); } static public List GetRptCtnStatusList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT * FROM (SELECT [GID],[CTNNO],[CTNPROP],[BSNO],SEABSNO,[APPLYNO],[CUSTOMERNAME],[GOODSNAME],[PREGOODSNAME] ,[ETD]"); strSql.Append(",PREETA,[ETA],[AGENTNAME],[CYCLE_DAY],[IS_RETURE_EMPTY],[IS_BOOKING],[I_CUSTNO]"); strSql.Append(",[I_ETD],PREI_ETA,[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN],[I_DESTPORT]"); strSql.Append(",[IS_DB],[D_CUSTNO],[D_ETD],PRED_ETA,[D_ETA],[D_MBLNO],[D_CUSTNAME],[D_CARRIER],[D_CONTRACT],[D_PORTLOAD_CNT_TIME]"); strSql.Append(",[D_PORTLOAD],[D_ARRIVALDATE],[D_DEST_CNT_TIME],[D_DEST_RTCNT_TIME],[D_DESTPORT_STATOIN]"); strSql.Append(",[D_DESTPORT]"); strSql.Append(",[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL]"); strSql.Append(",[CURSTATOIN],[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOADDATE],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2)) DESTPORT_OVER_DAYS_AMT,[DETAIN_CTN_DAYS],[PRE_CNT_TIME],[AUDITBY]"); strSql.Append(",AUDITSTATUS,[AUDITTIME],[AUDITRESULT],[REMARKS],[INPUTBY],[INPUTTIME],[COMPANYID],PUTCTNAUDITBY,PUTCTNAUDITSTATUS,PUTCTNAUDITTIME,PUTCTNAUDITRESULT"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS,IS_POD_CLEAN,IS_PUTCTN,PUTCTNDATE,INPUTTIME MODIFYTIME,'' MODIFYUSER"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select TOP 1 ISPORTLOADDATE from op_ctnapply where BSNO=b.APPLYNO) as ISPORTLOADDATE"); strSql.Append(",(select ShowName from [user] where GID=b.PUTCTNAUDITBY) as PUTCTNAUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE CTNNO=b.CTNNO and GID<>b.GID AND PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME ORDER BY PORTLOAD_CNT_TIME ) as NETD"); strSql.Append(" ,VCURSTATOIN CUR_PORT,NULL SHENTIME "); //系统判断业务卡中“生成目的港箱使费”这个按钮有没有点过 strSql.Append(",dbo.F_CTNBSCARD_ExistsMDGXSF(b.GID) MDGXSFSTATUS"); strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称) strSql.Append(",SERVICE,isnull(NEEDBEHEATED,0)NEEDBEHEATED,AGENTINPUTBY,isnull(EMPTYCTNALLOCATION,0)EMPTYCTNALLOCATION");//运输条款 是否加热 代理维护人 strSql.Append(" from v_top_opctnbscard b "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(") AS B "); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { sortstring = sortstring.Replace("DESTPORT_OVER_DAYS_AMT", "cast(round(isnull(DESTPORT_OVER_DAYS,0)*isnull(DESTPORT_OVER_DAYS_FEE,0),2) as numeric(20,2))"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by INPUTTIME 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()) { OpCtnBsCard data = new OpCtnBsCard(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CTNNO = Convert.ToString(reader["CTNNO"]); data.CTNPROP = Convert.ToString(reader["CTNPROP"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.SEABSNO = Convert.ToString(reader["SEABSNO"]); data.APPLYNO = Convert.ToString(reader["APPLYNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.GOODSNAMEREF = Convert.ToString(reader["GOODSNAMEREF"]); data.PREGOODSNAME = Convert.ToString(reader["PREGOODSNAME"]); 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["PREETA"] != DBNull.Value) data.PREETA = Convert.ToDateTime(reader["PREETA"]).ToString("yyyy-MM-dd"); data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]); if (reader["NETD"] != DBNull.Value) data.NETD = Convert.ToDateTime(reader["NETD"]).ToString("yyyy-MM-dd"); if (reader["ISPORTLOADDATE"] != DBNull.Value) data.ISPORTLOADDATE = Convert.ToBoolean(reader["ISPORTLOADDATE"]); if (reader["ISCLOSE"] != DBNull.Value) data.ISCLOSE = Convert.ToBoolean(reader["ISCLOSE"]); if (reader["CLOSEDATE"] != DBNull.Value) data.CLOSEDATE = Convert.ToDateTime(reader["CLOSEDATE"]).ToString("yyyy-MM-dd"); if (reader["IS_PUTCTN"] != DBNull.Value) data.IS_PUTCTN = Convert.ToBoolean(reader["IS_PUTCTN"]); if (reader["PUTCTNDATE"] != DBNull.Value) data.PUTCTNDATE = Convert.ToDateTime(reader["PUTCTNDATE"]).ToString("yyyy-MM-dd"); if (reader["IS_RETURE_EMPTY"] != DBNull.Value) data.IS_RETURE_EMPTY = Convert.ToBoolean(reader["IS_RETURE_EMPTY"]); if (reader["IS_DB"] != DBNull.Value) data.IS_DB = Convert.ToBoolean(reader["IS_DB"]); if (reader["IS_POD_CLEAN"] != DBNull.Value) data.IS_POD_CLEAN = Convert.ToBoolean(reader["IS_POD_CLEAN"]); if (reader["IS_BOOKING"] != DBNull.Value) data.IS_BOOKING = Convert.ToBoolean(reader["IS_BOOKING"]); data.I_CUSTNO = Convert.ToString(reader["I_CUSTNO"]); if (reader["I_ETD"] != DBNull.Value) data.I_ETD = Convert.ToDateTime(reader["I_ETD"]).ToString("yyyy-MM-dd"); if (reader["I_ETA"] != DBNull.Value) data.I_ETA = Convert.ToDateTime(reader["I_ETA"]).ToString("yyyy-MM-dd"); if (reader["PREI_ETA"] != DBNull.Value) data.PREI_ETA = Convert.ToDateTime(reader["PREI_ETA"]).ToString("yyyy-MM-dd"); data.I_MBLNO = Convert.ToString(reader["I_MBLNO"]); data.I_CUSTNAME = Convert.ToString(reader["I_CUSTNAME"]); data.I_CARRIER = Convert.ToString(reader["I_CARRIER"]); data.I_CONTRACT = Convert.ToString(reader["I_CONTRACT"]); if (reader["I_PORTLOAD_CNT_TIME"] != DBNull.Value) data.I_PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["I_PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); data.I_PORTLOAD = Convert.ToString(reader["I_PORTLOAD"]); if (reader["I_ARRIVALDATE"] != DBNull.Value) data.I_ARRIVALDATE = Convert.ToDateTime(reader["I_ARRIVALDATE"]).ToString("yyyy-MM-dd"); if (reader["I_DEST_CNT_TIME"] != DBNull.Value) data.I_DEST_CNT_TIME = Convert.ToDateTime(reader["I_DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["I_DEST_RTCNT_TIME"] != DBNull.Value) data.I_DEST_RTCNT_TIME = Convert.ToDateTime(reader["I_DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.I_DESTPORT_STATOIN = Convert.ToString(reader["I_DESTPORT_STATOIN"]); data.I_DESTPORT = Convert.ToString(reader["I_DESTPORT"]); data.D_CUSTNO = Convert.ToString(reader["D_CUSTNO"]); if (reader["D_ETD"] != DBNull.Value) data.D_ETD = Convert.ToDateTime(reader["D_ETD"]).ToString("yyyy-MM-dd"); if (reader["D_ETA"] != DBNull.Value) data.D_ETA = Convert.ToDateTime(reader["D_ETA"]).ToString("yyyy-MM-dd"); if (reader["PRED_ETA"] != DBNull.Value) data.PRED_ETA = Convert.ToDateTime(reader["PRED_ETA"]).ToString("yyyy-MM-dd"); data.D_MBLNO = Convert.ToString(reader["D_MBLNO"]); data.D_CUSTNAME = Convert.ToString(reader["D_CUSTNAME"]); data.D_CARRIER = Convert.ToString(reader["D_CARRIER"]); data.D_CONTRACT = Convert.ToString(reader["D_CONTRACT"]); if (reader["D_PORTLOAD_CNT_TIME"] != DBNull.Value) data.D_PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["D_PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); data.D_PORTLOAD = Convert.ToString(reader["D_PORTLOAD"]); if (reader["D_ARRIVALDATE"] != DBNull.Value) data.D_ARRIVALDATE = Convert.ToDateTime(reader["D_ARRIVALDATE"]).ToString("yyyy-MM-dd"); if (reader["D_DEST_CNT_TIME"] != DBNull.Value) data.D_DEST_CNT_TIME = Convert.ToDateTime(reader["D_DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["D_DEST_RTCNT_TIME"] != DBNull.Value) data.D_DEST_RTCNT_TIME = Convert.ToDateTime(reader["D_DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.D_DESTPORT_STATOIN = Convert.ToString(reader["D_DESTPORT_STATOIN"]); data.D_DESTPORT = Convert.ToString(reader["D_DESTPORT"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.OP = Convert.ToString(reader["OP"]); data.BOOKGOODNAME = Convert.ToString(reader["BOOKGOODNAME"]); data.TRUCKNAME = Convert.ToString(reader["TRUCKNAME"]); data.TRUCKLINKNAME = Convert.ToString(reader["TRUCKLINKNAME"]); data.TRUCKLINKTEL = Convert.ToString(reader["TRUCKLINKTEL"]); data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]); data.LOADADDR = Convert.ToString(reader["LOADADDR"]); data.CUSTOMGOODNAME = Convert.ToString(reader["CUSTOMGOODNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.CARRIER = Convert.ToString(reader["CARRIER"]); data.PORTLOAD_STATOIN = Convert.ToString(reader["PORTLOAD_STATOIN"]); data.LOADFACTORY = Convert.ToString(reader["LOADFACTORY"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); if (reader["PORTLOADDATE"] != DBNull.Value) data.PORTLOADDATE = Convert.ToDateTime(reader["PORTLOADDATE"]).ToString("yyyy-MM-dd"); if (reader["PORTLOAD_CNT_TIME"] != DBNull.Value) data.PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["NPORTLOAD_CNT_TIME"] != DBNull.Value) data.NPORTLOAD_CNT_TIME = Convert.ToDateTime(reader["NPORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["PORTLOAD_FREE_DAYS"] != DBNull.Value) data.PORTLOAD_FREE_DAYS = Convert.ToDecimal(reader["PORTLOAD_FREE_DAYS"]); if (reader["PORTLOAD_OVER_DAYS"] != DBNull.Value) data.PORTLOAD_OVER_DAYS = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS"]); //起运港超期天数= 开船日-起运港提箱日+1-起运港免箱天数 if (data.ISPORTLOADDATE == true) { if (data.PORTLOADDATE != "" && (data.PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.PORTLOAD_CNT_TIME) < DateTime.Now))) { //2017-04-12 SR2017041100021 var _days = Convert.ToDateTime(data.PORTLOADDATE) - Convert.ToDateTime(data.PORTLOAD_CNT_TIME); if ((_days.Days + 1 - data.PORTLOAD_FREE_DAYS) > 0) data.PORTLOAD_OVER_DAYS = _days.Days + 1 - data.PORTLOAD_FREE_DAYS; else data.PORTLOAD_OVER_DAYS = 0; } } else { if (data.ETD != "" && (data.PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.ETD) < DateTime.Now))) { var _days = Convert.ToDateTime(data.ETD) - Convert.ToDateTime(data.PORTLOAD_CNT_TIME); if ((_days.Days + 1 - data.PORTLOAD_FREE_DAYS) > 0) data.PORTLOAD_OVER_DAYS = _days.Days + 1 - data.PORTLOAD_FREE_DAYS; else data.PORTLOAD_OVER_DAYS = 0; } } if (reader["PORTLOAD_OVER_DAYS_FEE"] != DBNull.Value) data.PORTLOAD_OVER_DAYS_FEE = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS_FEE"]); if (reader["PORTLOAD_OVER_DAYS_AMT"] != DBNull.Value) data.PORTLOAD_OVER_DAYS_AMT = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS_AMT"]); data.PORTLOAD_OVER_DAYS_AMT = data.PORTLOAD_OVER_DAYS * data.PORTLOAD_OVER_DAYS_FEE; data.DESTPORT = Convert.ToString(reader["DESTPORT"]); if (reader["ARRIVALDATE"] != DBNull.Value) data.ARRIVALDATE = Convert.ToDateTime(reader["ARRIVALDATE"]).ToString("yyyy-MM-dd"); data.DESTAGENTNAME = Convert.ToString(reader["DESTAGENTNAME"]); if (reader["DEST_CNT_TIME"] != DBNull.Value) data.DEST_CNT_TIME = Convert.ToDateTime(reader["DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["DEST_RTCNT_TIME"] != DBNull.Value) data.DEST_RTCNT_TIME = Convert.ToDateTime(reader["DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.DESTPORT_STATOIN = Convert.ToString(reader["DESTPORT_STATOIN"]); if (reader["DESTPORT_FREE_DAYS"] != DBNull.Value) data.DESTPORT_FREE_DAYS = Convert.ToDecimal(reader["DESTPORT_FREE_DAYS"]); //if (reader["DESTPORT_OVER_DAYS"] != DBNull.Value) //data.DESTPORT_OVER_DAYS = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS"]); if (reader["DESTPORT_OVER_DAYS_FEE"] != DBNull.Value) data.DESTPORT_OVER_DAYS_FEE = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS_FEE"]); //目的港超期天数= 目的港提箱日期-到港日期+1-免箱天数 if (data.DEST_RTCNT_TIME != "" && (data.ETA != "" && (Convert.ToDateTime(data.ETA) < DateTime.Now))) { var _days = Convert.ToDateTime(data.DEST_RTCNT_TIME) - Convert.ToDateTime(data.ETA); if ((_days.Days + 1 - data.DESTPORT_FREE_DAYS) > 0) data.DESTPORT_OVER_DAYS = _days.Days + 1 - data.DESTPORT_FREE_DAYS; else data.DESTPORT_OVER_DAYS = 0; } else if (data.DEST_RTCNT_TIME == "" && (data.ETA != "" && (Convert.ToDateTime(data.ETA) < DateTime.Now))) { var _days = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")) - Convert.ToDateTime(data.ETA); if ((_days.Days + 1 - data.DESTPORT_FREE_DAYS) > 0) data.DESTPORT_OVER_DAYS = _days.Days + 1 - data.DESTPORT_FREE_DAYS; else data.DESTPORT_OVER_DAYS = 0; } // if (reader["DESTPORT_OVER_DAYS_AMT"] != DBNull.Value) // data.DESTPORT_OVER_DAYS_AMT = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS_AMT"]); data.DESTPORT_OVER_DAYS_AMT = data.DESTPORT_OVER_DAYS * data.DESTPORT_OVER_DAYS_FEE; if (reader["DETAIN_CTN_DAYS"] != DBNull.Value) data.DETAIN_CTN_DAYS = Convert.ToDecimal(reader["DETAIN_CTN_DAYS"]); if (reader["PRE_CNT_TIME"] != DBNull.Value) data.PRE_CNT_TIME = Convert.ToDateTime(reader["PRE_CNT_TIME"]).ToString("yyyy-MM-dd"); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]); if (reader["MODIFYTIME"] != DBNull.Value) data.MODIFYTIME = Convert.ToDateTime(reader["MODIFYTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]); data.AUDITBY = Convert.ToString(reader["AUDITBY"]); data.AUDITBYREF = Convert.ToString(reader["AUDITBYREF"]); if (reader["AUDITTIME"] != DBNull.Value) data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); if (reader["SHENTIME"] != DBNull.Value) data.SHENTIME = Convert.ToDateTime(reader["SHENTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]); data.PUTCTNAUDITSTATUS = Convert.ToString(reader["PUTCTNAUDITSTATUS"]); data.PUTCTNAUDITBY = Convert.ToString(reader["PUTCTNAUDITBY"]); data.PUTCTNAUDITBYREF = Convert.ToString(reader["PUTCTNAUDITBYREF"]); if (reader["PUTCTNAUDITTIME"] != DBNull.Value) data.PUTCTNAUDITTIME = Convert.ToDateTime(reader["PUTCTNAUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.PUTCTNAUDITRESULT = Convert.ToString(reader["PUTCTNAUDITRESULT"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); data.REPAIRSTATUS = Convert.ToString(reader["REPAIRSTATUS"]); data.CLEARINGSTATUS = Convert.ToString(reader["CLEARINGSTATUS"]); data.CUR_PORT = Convert.ToString(reader["CUR_PORT"]); if (data.IS_DB == true) { if (data.D_DEST_RTCNT_TIME != "" && (Convert.ToDateTime(data.D_DEST_RTCNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; data.CUR_DATE = data.D_DEST_RTCNT_TIME; if (data.NPORTLOAD_CNT_TIME != "") data.DETAIN_CTN_DAYS = DateDiff(data.D_DEST_RTCNT_TIME, data.NPORTLOAD_CNT_TIME); else data.DETAIN_CTN_DAYS = DateDiff(data.D_DEST_RTCNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } else if (data.D_DEST_CNT_TIME != "" && (Convert.ToDateTime(data.D_DEST_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "-待还箱"; data.CUR_DATE = data.D_DEST_CNT_TIME; } else if (data.D_ETA != "" && (Convert.ToDateTime(data.D_ETA) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "-待提货"; data.CUR_DATE = data.D_ETA; } else if (data.D_ETD != "" && (Convert.ToDateTime(data.D_ETD) < DateTime.Now)) { // data.CUR_PORT = data.I_PORTLOAD + "-" + data.I_DESTPORT; data.CUR_DATE = data.D_ETD; } else if (data.D_PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.D_PORTLOAD_CNT_TIME) < DateTime.Now)) { data.CUR_PORT = data.D_PORTLOAD + "-待开船"; data.CUR_DATE = data.D_PORTLOAD_CNT_TIME; } else { // data.CUR_PORT = data.I_PORTLOAD + "-待装货"; data.CUR_DATE = DateTime.Now.ToString("yyyy-MM-dd"); } } else { if (data.IS_RETURE_EMPTY == true) { if (data.I_DEST_RTCNT_TIME != "" && (Convert.ToDateTime(data.I_DEST_RTCNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "已还箱-闲置"; data.CUR_DATE = data.I_DEST_RTCNT_TIME; if (data.NPORTLOAD_CNT_TIME != "") data.DETAIN_CTN_DAYS = DateDiff(data.I_DEST_RTCNT_TIME, data.NPORTLOAD_CNT_TIME); else data.DETAIN_CTN_DAYS = DateDiff(data.I_DEST_RTCNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } else if (data.I_DEST_CNT_TIME != "" && (Convert.ToDateTime(data.I_DEST_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "-待还箱"; data.CUR_DATE = data.I_DEST_CNT_TIME; } else if (data.I_ETA != "" && (Convert.ToDateTime(data.I_ETA) < DateTime.Now)) { // data.CUR_PORT = data.I_DESTPORT + "-待提货"; data.CUR_DATE = data.I_ETA; } else if (data.I_ETD != "" && (Convert.ToDateTime(data.I_ETD) < DateTime.Now)) { // data.CUR_PORT = data.I_PORTLOAD + "-" + data.I_DESTPORT; data.CUR_DATE = data.I_ETD; } else if (data.I_PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.I_PORTLOAD_CNT_TIME) < DateTime.Now)) { data.CUR_PORT = data.I_PORTLOAD + "-待开船"; data.CUR_DATE = data.I_PORTLOAD_CNT_TIME; } else { // data.CUR_PORT = data.I_PORTLOAD + "-待装货"; data.CUR_DATE = DateTime.Now.ToString("yyyy-MM-dd"); } } else { if (data.DEST_RTCNT_TIME != "" && (Convert.ToDateTime(data.DEST_RTCNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.DESTPORT + "已还箱-闲置"; data.CUR_DATE = data.DEST_RTCNT_TIME; if (data.NPORTLOAD_CNT_TIME != "") data.DETAIN_CTN_DAYS = DateDiff(data.DEST_RTCNT_TIME, data.NPORTLOAD_CNT_TIME); else data.DETAIN_CTN_DAYS = DateDiff(data.DEST_RTCNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } else if (data.DEST_CNT_TIME != "" && (Convert.ToDateTime(data.DEST_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.DESTPORT + "-待还箱"; data.CUR_DATE = data.DEST_CNT_TIME; } else if (data.ETA != "" && (Convert.ToDateTime(data.ETA) < DateTime.Now)) { // data.CUR_PORT = data.DESTPORT + "-待提货"; data.CUR_DATE = data.ETA; } else if (data.ETD != "" && (Convert.ToDateTime(data.ETD) < DateTime.Now)) { // data.CUR_PORT = data.PORTLOAD + "-" + data.DESTPORT; data.CUR_DATE = data.ETD; } else if (data.PORTLOAD_CNT_TIME != "" && (Convert.ToDateTime(data.PORTLOAD_CNT_TIME) < DateTime.Now)) { // data.CUR_PORT = data.PORTLOAD + "-待开船"; data.CUR_DATE = data.PORTLOAD_CNT_TIME; } else { // data.CUR_PORT = data.PORTLOAD + "-待装货"; data.CUR_DATE = DateTime.Now.ToString("yyyy-MM-dd"); } } } if (data.ETD != "" && data.NETD != "") data.CYCLE_DAY = DateDiff(data.ETD, data.NETD); else if (data.ETD != "") data.CYCLE_DAY = DateDiff(data.ETD, DateTime.Now.ToString("yyyy-MM-dd")); data.MDGXSFSTATUS = Convert.ToString(reader["MDGXSFSTATUS"]); //是否产生了目的港箱使费 if (data.MDGXSFSTATUS == "") { if ((data.DEST_RTCNT_TIME != "") && (data.DESTPORT_OVER_DAYS_AMT != 0)) data.MDGXSFSTATUS = "已还箱,未生成"; if ((data.DEST_RTCNT_TIME == "") && (data.DESTPORT_OVER_DAYS_AMT != 0)) data.MDGXSFSTATUS = "未还箱,未生成"; } data.SERVICE = Convert.ToString(reader["SERVICE"]);//运输条款 data.NEEDBEHEATED = Convert.ToBoolean(reader["NEEDBEHEATED"]);//是否加热 data.AGENTINPUTBY = Convert.ToString(reader["AGENTINPUTBY"]);//代理维护人 data.EMPTYCTNALLOCATION = Convert.ToBoolean(reader["EMPTYCTNALLOCATION"]);//空箱调拨 #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetDataFeeList(string strCondition, string datetype, string companyid, string userid, string sort = null) { var rangstr = GetRangDAStr("", userid, userid, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT B.GID,B.CTNNO,t.CTNPROP,B.[BSNO],[APPLYNO],[CUSTOMERNAME],[GOODSNAME],[PREGOODSNAME] ,[ETD]"); strSql.Append(",[ETA],[AGENTNAME],[CUR_PORT],[CYCLE_DAY],[IS_RETURE_EMPTY],[IS_BOOKING],[I_CUSTNO]"); strSql.Append(",[I_ETD],[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN]"); strSql.Append(",[I_DESTPORT],[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL]"); strSql.Append(",B.CURSTATOIN,[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],[DESTPORT_OVER_DAYS_AMT],[DETAIN_CTN_DAYS],[PRE_CNT_TIME],B.AUDITBY"); strSql.Append(",B.AUDITSTATUS,B.AUDITTIME,B.AUDITRESULT,B.REMARKS,B.INPUTBY,B.INPUTTIME,B.COMPANYID"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE PORTLOAD_CNT_TIME IS NOT NULL AND CTNNO=b.CTNNO and GID<>b.GID AND (PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME or ETD>b.ETD) ORDER BY PORTLOAD_CNT_TIME ) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE ETD IS NOT NULL AND CTNNO=b.CTNNO and GID<>b.GID AND (ETD>b.ETD or PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME) ORDER BY ETD ) as NETD"); strSql.Append(",G.RMBDR,G.RMBCR,G.USDDR,G.USDCR,G.XSFUSDDR,G.OTUSDDR,G.XSFRMBDR,G.OTRMBDR,G.GXFUSDDR,G.HDFRMBDR,t.CTNRENT "); strSql.Append(" from v_op_ctnbscard b "); strSql.Append("LEFT JOIN v_opctn_gain_sum G ON (G.BSNO=B.GID) "); strSql.Append("LEFT JOIN code_ctntk t ON (t.CTNNO=B.CTNNO) "); 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 B.INPUTTIME DESC "); } return SetFeeData(strSql,datetype); } static public string GetDataFeeListStr(string strCondition, string datetype, string companyid, string userid, string sort = null) { var rangstr = GetRangDAStr("", userid, userid, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT B.GID,B.CTNNO,t.CTNPROP,B.[BSNO],[APPLYNO],[CUSTOMERNAME],[GOODSNAME],[PREGOODSNAME] ,[ETD]"); strSql.Append(",[ETA],[AGENTNAME],[CUR_PORT],[CYCLE_DAY],[IS_RETURE_EMPTY],[IS_BOOKING],[I_CUSTNO]"); strSql.Append(",[I_ETD],[I_ETA],[I_MBLNO],[I_CUSTNAME],[I_CARRIER],[I_CONTRACT],[I_PORTLOAD_CNT_TIME]"); strSql.Append(",[I_PORTLOAD],[I_ARRIVALDATE],[I_DEST_CNT_TIME],[I_DEST_RTCNT_TIME],[I_DESTPORT_STATOIN]"); strSql.Append(",[I_DESTPORT],[CUSTNO],[OP],[BOOKGOODNAME],[TRUCKNAME],[TRUCKLINKNAME],[TRUCKLINKTEL]"); strSql.Append(",B.CURSTATOIN,[LOADADDR],[CUSTOMGOODNAME],[MBLNO],[CARRIER],[PORTLOAD_STATOIN]"); strSql.Append(",[PORTLOAD_CNT_TIME],[LOADFACTORY],[PORTLOAD],[PORTLOAD_FREE_DAYS],[PORTLOAD_OVER_DAYS]"); strSql.Append(",[PORTLOAD_OVER_DAYS_FEE],[PORTLOAD_OVER_DAYS_AMT],[DESTPORT],[ARRIVALDATE],[DESTAGENTNAME]"); strSql.Append(",[DEST_CNT_TIME],[DEST_RTCNT_TIME],[DESTPORT_STATOIN],[DESTPORT_FREE_DAYS],[DESTPORT_OVER_DAYS]"); strSql.Append(",[DESTPORT_OVER_DAYS_FEE],[DESTPORT_OVER_DAYS_AMT],[DETAIN_CTN_DAYS],[PRE_CNT_TIME],B.AUDITBY"); strSql.Append(",B.AUDITSTATUS,B.AUDITTIME,B.AUDITRESULT,B.REMARKS,B.INPUTBY,B.INPUTTIME,B.COMPANYID"); strSql.Append(",ISCLOSE,CLOSEDATE,REPAIRSTATUS,CLEARINGSTATUS"); strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF"); strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF"); strSql.Append(",(select TOP 1 PORTLOAD_CNT_TIME FROM op_ctnbscard WHERE PORTLOAD_CNT_TIME IS NOT NULL AND CTNNO=b.CTNNO and GID<>b.GID AND (PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME or ETD>b.ETD) ORDER BY PORTLOAD_CNT_TIME ) as NPORTLOAD_CNT_TIME"); strSql.Append(",(select TOP 1 ETD FROM op_ctnbscard WHERE ETD IS NOT NULL AND CTNNO=b.CTNNO and GID<>b.GID AND (ETD>b.ETD or PORTLOAD_CNT_TIME>b.PORTLOAD_CNT_TIME) ORDER BY ETD ) as NETD"); strSql.Append(",G.RMBDR,G.RMBCR,G.USDDR,G.USDCR,G.XSFUSDDR,G.OTUSDDR,G.XSFRMBDR,G.OTRMBDR,G.GXFUSDDR,G.HDFRMBDR,t.CTNRENT "); strSql.Append(" from v_op_ctnbscard b "); strSql.Append("LEFT JOIN v_opctn_gain_sum G ON (G.BSNO=B.GID) "); strSql.Append("LEFT JOIN code_ctntk t ON (t.CTNNO=B.CTNNO) "); 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 B.INPUTTIME DESC "); } return strSql.ToString(); } private static List SetFeeData(StringBuilder strSql,string datetype) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnBsCard data = new OpCtnBsCard(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.CTNNO = Convert.ToString(reader["CTNNO"]); data.CTNPROP = Convert.ToString(reader["CTNPROP"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.APPLYNO = Convert.ToString(reader["APPLYNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.PREGOODSNAME = Convert.ToString(reader["PREGOODSNAME"]); 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.AGENTNAME = Convert.ToString(reader["AGENTNAME"]); if (reader["NETD"] != DBNull.Value) data.NETD = Convert.ToDateTime(reader["NETD"]).ToString("yyyy-MM-dd"); if (reader["ISCLOSE"] != DBNull.Value) data.ISCLOSE = Convert.ToBoolean(reader["ISCLOSE"]); if (reader["CLOSEDATE"] != DBNull.Value) data.CLOSEDATE = Convert.ToDateTime(reader["CLOSEDATE"]).ToString("yyyy-MM-dd"); if (reader["IS_RETURE_EMPTY"] != DBNull.Value) data.IS_RETURE_EMPTY = Convert.ToBoolean(reader["IS_RETURE_EMPTY"]); if (reader["IS_BOOKING"] != DBNull.Value) data.IS_BOOKING = Convert.ToBoolean(reader["IS_BOOKING"]); data.I_CUSTNO = Convert.ToString(reader["I_CUSTNO"]); if (reader["I_ETD"] != DBNull.Value) data.I_ETD = Convert.ToDateTime(reader["I_ETD"]).ToString("yyyy-MM-dd"); if (reader["I_ETA"] != DBNull.Value) data.I_ETA = Convert.ToDateTime(reader["I_ETA"]).ToString("yyyy-MM-dd"); data.I_MBLNO = Convert.ToString(reader["I_MBLNO"]); data.I_CUSTNAME = Convert.ToString(reader["I_CUSTNAME"]); data.I_CARRIER = Convert.ToString(reader["I_CARRIER"]); data.I_CONTRACT = Convert.ToString(reader["I_CONTRACT"]); if (reader["I_PORTLOAD_CNT_TIME"] != DBNull.Value) data.I_PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["I_PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); data.I_PORTLOAD = Convert.ToString(reader["I_PORTLOAD"]); if (reader["I_ARRIVALDATE"] != DBNull.Value) data.I_ARRIVALDATE = Convert.ToDateTime(reader["I_ARRIVALDATE"]).ToString("yyyy-MM-dd"); if (reader["I_DEST_CNT_TIME"] != DBNull.Value) data.I_DEST_CNT_TIME = Convert.ToDateTime(reader["I_DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["I_DEST_RTCNT_TIME"] != DBNull.Value) data.I_DEST_RTCNT_TIME = Convert.ToDateTime(reader["I_DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.I_DESTPORT_STATOIN = Convert.ToString(reader["I_DESTPORT_STATOIN"]); data.I_DESTPORT = Convert.ToString(reader["I_DESTPORT"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.OP = Convert.ToString(reader["OP"]); data.BOOKGOODNAME = Convert.ToString(reader["BOOKGOODNAME"]); data.TRUCKNAME = Convert.ToString(reader["TRUCKNAME"]); data.TRUCKLINKNAME = Convert.ToString(reader["TRUCKLINKNAME"]); data.TRUCKLINKTEL = Convert.ToString(reader["TRUCKLINKTEL"]); data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]); data.LOADADDR = Convert.ToString(reader["LOADADDR"]); data.CUSTOMGOODNAME = Convert.ToString(reader["CUSTOMGOODNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.CARRIER = Convert.ToString(reader["CARRIER"]); data.PORTLOAD_STATOIN = Convert.ToString(reader["PORTLOAD_STATOIN"]); data.LOADFACTORY = Convert.ToString(reader["LOADFACTORY"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); if (reader["PORTLOAD_CNT_TIME"] != DBNull.Value) data.PORTLOAD_CNT_TIME = Convert.ToDateTime(reader["PORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["NPORTLOAD_CNT_TIME"] != DBNull.Value) data.NPORTLOAD_CNT_TIME = Convert.ToDateTime(reader["NPORTLOAD_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["PORTLOAD_FREE_DAYS"] != DBNull.Value) data.PORTLOAD_FREE_DAYS = Convert.ToDecimal(reader["PORTLOAD_FREE_DAYS"]); if (reader["PORTLOAD_OVER_DAYS"] != DBNull.Value) data.PORTLOAD_OVER_DAYS = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS"]); if (reader["PORTLOAD_OVER_DAYS_FEE"] != DBNull.Value) data.PORTLOAD_OVER_DAYS_FEE = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS_FEE"]); if (reader["PORTLOAD_OVER_DAYS_AMT"] != DBNull.Value) data.PORTLOAD_OVER_DAYS_AMT = Convert.ToDecimal(reader["PORTLOAD_OVER_DAYS_AMT"]); data.DESTPORT = Convert.ToString(reader["DESTPORT"]); if (reader["ARRIVALDATE"] != DBNull.Value) data.ARRIVALDATE = Convert.ToDateTime(reader["ARRIVALDATE"]).ToString("yyyy-MM-dd"); data.DESTAGENTNAME = Convert.ToString(reader["DESTAGENTNAME"]); if (reader["DEST_CNT_TIME"] != DBNull.Value) data.DEST_CNT_TIME = Convert.ToDateTime(reader["DEST_CNT_TIME"]).ToString("yyyy-MM-dd"); if (reader["DEST_RTCNT_TIME"] != DBNull.Value) data.DEST_RTCNT_TIME = Convert.ToDateTime(reader["DEST_RTCNT_TIME"]).ToString("yyyy-MM-dd"); data.DESTPORT_STATOIN = Convert.ToString(reader["DESTPORT_STATOIN"]); if (reader["DESTPORT_FREE_DAYS"] != DBNull.Value) data.DESTPORT_FREE_DAYS = Convert.ToDecimal(reader["DESTPORT_FREE_DAYS"]); if (reader["DESTPORT_OVER_DAYS"] != DBNull.Value) data.DESTPORT_OVER_DAYS = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS"]); if (reader["DESTPORT_OVER_DAYS_FEE"] != DBNull.Value) data.DESTPORT_OVER_DAYS_FEE = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS_FEE"]); if (reader["DESTPORT_OVER_DAYS_AMT"] != DBNull.Value) data.DESTPORT_OVER_DAYS_AMT = Convert.ToDecimal(reader["DESTPORT_OVER_DAYS_AMT"]); if (reader["DETAIN_CTN_DAYS"] != DBNull.Value) data.DETAIN_CTN_DAYS = Convert.ToDecimal(reader["DETAIN_CTN_DAYS"]); if (reader["PRE_CNT_TIME"] != DBNull.Value) data.PRE_CNT_TIME = Convert.ToDateTime(reader["PRE_CNT_TIME"]).ToString("yyyy-MM-dd"); var usdexrate = GetUsdExrate(data.PORTLOAD_CNT_TIME, "USD"); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]); data.AUDITBY = Convert.ToString(reader["AUDITBY"]); data.AUDITBYREF = Convert.ToString(reader["AUDITBYREF"]); if (reader["AUDITTIME"] != DBNull.Value) data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); data.REPAIRSTATUS = Convert.ToString(reader["REPAIRSTATUS"]); data.CLEARINGSTATUS = Convert.ToString(reader["CLEARINGSTATUS"]); if (data.PORTLOAD_CNT_TIME == "") { data.CUR_PORT = data.PORTLOAD + "-待装货"; data.CUR_DATE = DateTime.Now.ToString("yyyy-MM-dd"); } else if (data.ETD == "" || (data.ETD != "" && (Convert.ToDateTime(data.ETD) > DateTime.Now))) { data.CUR_PORT = data.PORTLOAD + "-待开船"; data.CUR_DATE = data.PORTLOAD_CNT_TIME; } else if (data.ETA == "" || (data.ETA != "" && (Convert.ToDateTime(data.ETA) > DateTime.Now))) { data.CUR_PORT = data.PORTLOAD + "-" + data.DESTPORT; data.CUR_DATE = data.ETD; } else if (data.DEST_CNT_TIME == "" || (data.DEST_CNT_TIME != "" && (Convert.ToDateTime(data.DEST_CNT_TIME) > DateTime.Now))) { data.CUR_PORT = data.DESTPORT + "-待提货"; data.CUR_DATE = data.ETA; } else if (data.DEST_RTCNT_TIME == "" || (data.DEST_RTCNT_TIME != "" && (Convert.ToDateTime(data.DEST_RTCNT_TIME) > DateTime.Now))) { data.CUR_PORT = data.DESTPORT + "-待还箱"; data.CUR_DATE = data.DEST_CNT_TIME; } else { data.CUR_PORT = data.DESTPORT + "已还箱-闲置"; data.CUR_DATE = data.DEST_RTCNT_TIME; } if (datetype == "CNT") { if (data.PORTLOAD_CNT_TIME != "" && data.NPORTLOAD_CNT_TIME != "") data.CYCLE_DAY = DateDiff(data.PORTLOAD_CNT_TIME, data.NPORTLOAD_CNT_TIME); else if (data.PORTLOAD_CNT_TIME != "") data.CYCLE_DAY = DateDiff(data.PORTLOAD_CNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } else { if (data.ETD != "" && data.NETD != "") data.CYCLE_DAY = DateDiff(data.ETD, data.NETD); else if (data.ETD != "" ) data.CYCLE_DAY = DateDiff(data.ETD, DateTime.Now.ToString("yyyy-MM-dd")); } if (data.IS_RETURE_EMPTY) { data.LINES = data.PORTLOAD + "-" + data.DESTPORT + "-" + data.I_DESTPORT; data.RTCNT_TIME = data.I_DEST_RTCNT_TIME; if (data.NPORTLOAD_CNT_TIME != "" && data.I_DEST_RTCNT_TIME != "") data.CYCLE_CNTDAY = DateDiff(data.I_DEST_RTCNT_TIME, data.NPORTLOAD_CNT_TIME); else if (data.NPORTLOAD_CNT_TIME== "" && data.I_DEST_RTCNT_TIME != "") data.CYCLE_CNTDAY = DateDiff(data.I_DEST_RTCNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } else { data.RTCNT_TIME = data.DEST_RTCNT_TIME; data.LINES = data.PORTLOAD + "-" + data.DESTPORT; if (data.NPORTLOAD_CNT_TIME != "" && data.DEST_RTCNT_TIME != "") data.CYCLE_CNTDAY = DateDiff(data.DEST_RTCNT_TIME, data.NPORTLOAD_CNT_TIME); else if (data.NPORTLOAD_CNT_TIME == "" && data.DEST_RTCNT_TIME != "") data.CYCLE_CNTDAY = DateDiff(data.DEST_RTCNT_TIME, DateTime.Now.ToString("yyyy-MM-dd")); } if (reader["RMBDR"] != DBNull.Value) data.RMBDR = Convert.ToDecimal(reader["RMBDR"]); if (reader["RMBCR"] != DBNull.Value) data.RMBCR = Convert.ToDecimal(reader["RMBCR"]); if (reader["USDDR"] != DBNull.Value) data.USDDR = Convert.ToDecimal(reader["USDDR"]); if (reader["USDCR"] != DBNull.Value) data.USDCR = Convert.ToDecimal(reader["USDCR"]); if (reader["XSFUSDDR"] != DBNull.Value) data.XSFUSDDR = Convert.ToDecimal(reader["XSFUSDDR"]); if (reader["OTUSDDR"] != DBNull.Value) data.OTUSDDR = Convert.ToDecimal(reader["OTUSDDR"]); if (reader["XSFRMBDR"] != DBNull.Value) data.XSFRMBDR = Convert.ToDecimal(reader["XSFRMBDR"]); if (reader["HDFRMBDR"] != DBNull.Value) data.HDFDR = Convert.ToDecimal(reader["HDFRMBDR"]); if (reader["GXFUSDDR"] != DBNull.Value) data.GXFUSDDR = Convert.ToDecimal(reader["GXFUSDDR"]); if (reader["OTRMBDR"] != DBNull.Value) data.OTRMBDR = Convert.ToDecimal(reader["OTRMBDR"]); data.HDFDR = Math.Round(data.HDFDR /usdexrate, 2); data.XSFDRTTLINUSD = Math.Round(data.XSFRMBDR / usdexrate + data.XSFUSDDR,2); data.OTDRTTLINUSD = Math.Round(data.OTRMBDR / usdexrate + data.OTUSDDR, 2); data.TTLDRINUSD = Math.Round(data.RMBDR / usdexrate + data.USDDR, 2); ; data.TTLCRINUSD = Math.Round(data.RMBCR / usdexrate + data.USDCR, 2); data.PROFITINUSD = data.TTLDRINUSD - data.TTLCRINUSD; if (data.CYCLE_DAY != 0) data.DAYPROFITINUSD = data.PROFITINUSD / data.CYCLE_DAY; data.CTNRENT = Convert.ToString(reader["CTNRENT"]); if (data.CTNRENT == "") data.CTNRENT = "0"; data.RENTPROFITINUSD = Convert.ToDecimal(data.CTNRENT) * data.CYCLE_DAY; data.OPPROFITINUSD = data.PROFITINUSD - data.RENTPROFITINUSD; #endregion headList.Add(data); } reader.Close(); } return headList; } #region 东胜6数据 static public List GetBsList(string bsno) { var strSql = new StringBuilder(); //strSql.Append("SELECT 编号 GID,业务编号 BSNO,委托单位 CUSTOMERNAME,委托编号 CUSTNO,开船日期 ETD,预抵日期 ETA ,主提单号 MBLNO ,代理 AGENTNAME"); //strSql.Append(",装货港 PORTLOAD ,卸货港 DESTPORT, 保险单号 APPLYNO"); //strSql.Append(" from V_op_bscard_All where 保险单号 like '%" + bsno.Substring(0,13) + "%'"); strSql.Append("SELECT BSNO GID,BSNO,CUSTOMERNAME,CUSTNO,ETD,ETA ,MBLNO ,AGENTID AGENTNAME"); strSql.Append(",PORTLOAD ,PORTDISCHARGE DESTPORT,APPLYNO"); strSql.Append(" from op_seae where APPLYNO like '%" + bsno + "%'"); strSql.Append(" union "); strSql.Append("SELECT BSNO GID,BSNO,CUSTOMERNAME,CUSTNO,ETA ETD,ETD ETA ,MBLNO,AGENTID AGENTNAME"); strSql.Append(",PORTLOAD ,PORTDISCHARGE DESTPORT,APPLYNO"); strSql.Append(" from op_seai where APPLYNO like '%" + bsno + "%'"); return SetBSData(strSql); } private static List SetBSData(StringBuilder strSql) { var headList = new List(); // Database db = DatabaseFactory.CreateDatabase("DONGSHENG6"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnBsCard data = new OpCtnBsCard(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.APPLYNO = Convert.ToString(reader["APPLYNO"]); 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.AGENTNAME = Convert.ToString(reader["AGENTNAME"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.DESTPORT = Convert.ToString(reader["DESTPORT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion public static decimal GetUsdExrate(string currdate, string curr) { decimal result = -1; if (currdate == "") { var strSql = new StringBuilder(); strSql.Append("Select CODENAME,DEFAULTRATE "); strSql.Append(" from code_currency where CODENAME='USD'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } else { var strSql = new StringBuilder(); strSql.Append("Select CURRENCYID,VALUE "); strSql.Append(" from currency_exchange "); strSql.Append(" left join code_currency c on (c.GID=currency_exchange.CURRENCYID) "); strSql.Append(" where c.CODENAME='" + curr + "' and STARTTIME<='" + currdate + "' and ENDTIME>='" + currdate + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["VALUE"]); } reader.Close(); } if (result == -1) { var strSql2 = new StringBuilder(); strSql2.Append("Select CODENAME,DEFAULTRATE "); strSql2.Append(" from code_currency where CODENAME='USD'"); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql2.ToString())) { while (reader.Read()) { result = Convert.ToDecimal(reader["DEFAULTRATE"]); } reader.Close(); } } } return result; } public static DBResult DeleteOpCtnBsCard(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_ctnbscard where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdDelete, tran); UpOpCtnApplyCtnItems(enumValue.CTNNO, enumValue.APPLYNO); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } 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 isnull(WMSOUTBSNO,'')<>'' and 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; } public static DBResult AuditReturn(List headData,string type,string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { if (type == "1") { if (enumValue.AUDITSTATUS == "申请调拨") { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set AUDITSTATUS='批准调拨',IS_DB=1,AUDITBY='" + userid + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } else { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set AUDITSTATUS='批准返空',IS_RETURE_EMPTY=1,AUDITBY='" + userid + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } } else if (type == "0") { if (enumValue.AUDITSTATUS == "批准调拨"|| enumValue.AUDITSTATUS == "申请调拨") { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set AUDITSTATUS='驳回调拨',IS_DB=0,AUDITBY='',AUDITTIME=null where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } else { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set AUDITSTATUS='驳回返空',IS_RETURE_EMPTY=0,AUDITBY='',AUDITTIME=null where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } } } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "审批出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "审批成功"; return result; } public static DBResult SubmitAudit(string GID,string type) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set REPAIRSTATUS='提交审核' where GID='" + GID + "'"); if (type=="2") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set CLEARINGSTATUS='提交审核' where GID='" + GID + "'"); if (type == "3") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set REPAIRSTATUS='撤销提交' where GID='" + GID + "'"); if (type == "4") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set CLEARINGSTATUS='撤销提交' where GID='" + GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交审核成功"; return result; } public static DBResult Audit(string GID, string type) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set REPAIRSTATUS='审核通过' where GID='" + GID + "'"); if (type == "2") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set CLEARINGSTATUS='审核通过' where GID='" + GID + "'"); if (type == "3") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set REPAIRSTATUS='驳回提交' where GID='" + GID + "'"); if (type == "4") cmdUpdate = db.GetSqlStringCommand("update op_ctnbscard set CLEARINGSTATUS='驳回提交' where GID='" + GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交审核出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交审核成功"; return result; } public static DBResult AuditPutCtn(List bodyList, string type,string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard set PUTCTNAUDITSTATUS=@PUTCTNAUDITSTATUS,PUTCTNAUDITBY=@PUTCTNAUDITBY,PUTCTNAUDITTIME=@PUTCTNAUDITTIME where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (type == "1") { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITSTATUS", DbType.String, "审核通过"); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITBY", DbType.String, userid); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdUpdate, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITSTATUS", DbType.String, "未审核"); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITBY", DbType.String,""); db.AddInParameter(cmdUpdate, "@PUTCTNAUDITTIME", DbType.String,null); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); 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 PutCtn(List bodyList,string is_putctn,string putcntdate) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard set IS_PUTCTN=@IS_PUTCTN,PUTCTNDATE=@PUTCTNDATE where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (is_putctn == "1") { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@IS_PUTCTN", DbType.String,"1"); db.AddInParameter(cmdUpdate, "@PUTCTNDATE", DbType.String, putcntdate); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdUpdate, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@IS_PUTCTN", DbType.String, "0"); db.AddInParameter(cmdUpdate, "@PUTCTNDATE", DbType.String, null); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); 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 LockBs(List bodyList, string islock) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard set ISCLOSE=@ISCLOSE,CLOSEDATE=@CLOSEDATE where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (islock == "1") { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@ISCLOSE", DbType.String, "1"); db.AddInParameter(cmdUpdate, "@CLOSEDATE", DbType.String,DateTime.Now.ToString("yyyy-MM-dd")); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdUpdate, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@ISCLOSE", DbType.String, "0"); db.AddInParameter(cmdUpdate, "@CLOSEDATE", DbType.String, null); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); 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 #region OpCtnClearing static public List GetOpCtnClearingList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[INSTATOINTIME],[IMAGE_LINDADDR],[IMAGE1],[EIR],[EIRPATH],[CLEARINGMODE],[PREGOODSNAME]"); strSql.Append(",[ISCLEAR_CERT],[CHECKGOV],[ISCLEAR_PLAN],[CLEARTIME],[IMAGE_CLEAR],[IMAGE_CLEARPATH],[IMAGE_CHECKGOV],[IMAGE_CHECKGOVPATH]"); strSql.Append(",[ISCOMPLETE],[FEENAME],[CURRENCY],[AMOUNT],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[REMARKS]"); strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID],CURSTATOIN "); strSql.Append(",(select CTNNO from op_ctnbscard where GID=op_ctnclearing.LINKGID) CTNNO"); strSql.Append(",(select BSNO from op_ctnbscard where GID=op_ctnclearing.LINKGID) BSNO"); strSql.Append(" from op_ctnclearing "); 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 INSTATOINTIME desc,INPUTTIME desc "); } return SetOpCtnClearingData(strSql); } static public string GetOpCtnClearingListStr(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[INSTATOINTIME],[IMAGE_LINDADDR],[IMAGE1],[EIR],[EIRPATH],[CLEARINGMODE],[PREGOODSNAME]"); strSql.Append(",[ISCLEAR_CERT],[CHECKGOV],[ISCLEAR_PLAN],[CLEARTIME],[IMAGE_CLEAR],[IMAGE_CLEARPATH],[IMAGE_CHECKGOV],[IMAGE_CHECKGOVPATH]"); strSql.Append(",[ISCOMPLETE],[FEENAME],[CURRENCY],[AMOUNT],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[REMARKS]"); strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID],CURSTATOIN"); strSql.Append(",(select CTNNO from op_ctnbscard where GID=op_ctnclearing.LINKGID) CTNNO"); strSql.Append(",(select BSNO from op_ctnbscard where GID=op_ctnclearing.LINKGID) BSNO"); strSql.Append(" from op_ctnclearing "); 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 INPUTTIME "); } return strSql.ToString(); } private static List SetOpCtnClearingData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnClearing data = new OpCtnClearing(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.LINKGID = Convert.ToString(reader["LINKGID"]); data.CTNNO = Convert.ToString(reader["CTNNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]); if (reader["INSTATOINTIME"] != DBNull.Value) data.INSTATOINTIME = Convert.ToDateTime(reader["INSTATOINTIME"]).ToString("yyyy-MM-dd"); data.IMAGE_LINDADDR = Convert.ToString(reader["IMAGE_LINDADDR"]); data.IMAGE1= Convert.ToString(reader["IMAGE1"]); data.EIR = Convert.ToString(reader["EIR"]); data.EIRPATH = Convert.ToString(reader["EIRPATH"]); data.CLEARINGMODE = Convert.ToString(reader["CLEARINGMODE"]); data.PREGOODSNAME = Convert.ToString(reader["PREGOODSNAME"]); if (reader["ISCLEAR_CERT"] != DBNull.Value) data.ISCLEAR_CERT = Convert.ToBoolean(reader["ISCLEAR_CERT"]); data.CHECKGOV = Convert.ToString(reader["CHECKGOV"]); if (reader["ISCLEAR_PLAN"] != DBNull.Value) data.ISCLEAR_PLAN = Convert.ToBoolean(reader["ISCLEAR_PLAN"]); if (reader["CLEARTIME"] != DBNull.Value) data.CLEARTIME = Convert.ToDateTime(reader["CLEARTIME"]).ToString("yyyy-MM-dd"); data.IMAGE_CLEAR = Convert.ToString(reader["IMAGE_CLEAR"]); data.IMAGE_CLEARPATH = Convert.ToString(reader["IMAGE_CLEARPATH"]); data.IMAGE_CHECKGOV = Convert.ToString(reader["IMAGE_CHECKGOV"]); data.IMAGE_CHECKGOVPATH = Convert.ToString(reader["IMAGE_CHECKGOVPATH"]); if (reader["ISCOMPLETE"] != DBNull.Value) data.ISCOMPLETE = Convert.ToBoolean(reader["ISCOMPLETE"]); data.FEENAME = Convert.ToString(reader["FEENAME"]); data.CURRENCY = Convert.ToString(reader["CURRENCY"]); if (reader["AMOUNT"] != DBNull.Value) data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]); data.AUDITBY = Convert.ToString(reader["AUDITBY"]); data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]); if (reader["AUDITTIME"] != DBNull.Value) data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveOpCtnClearing(List bodyList, string PID, 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_ctnclearing (GID,LINKGID,INSTATOINTIME,CLEARINGMODE,PREGOODSNAME,ISCLEAR_CERT,CHECKGOV,ISCLEAR_PLAN,CLEARTIME,ISCOMPLETE, FEENAME,CURRENCY,AMOUNT,INPUTBY,INPUTTIME,REMARKS,AUDITSTATUS,CURSTATOIN) values (@GID,@LINKGID,@INSTATOINTIME,@CLEARINGMODE,@PREGOODSNAME,@ISCLEAR_CERT,@CHECKGOV,@ISCLEAR_PLAN,@CLEARTIME,@ISCOMPLETE,@FEENAME, @CURRENCY,@AMOUNT,@INPUTBY,@INPUTTIME,@REMARKS,@AUDITSTATUS,@CURSTATOIN ) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnclearing set INSTATOINTIME=@INSTATOINTIME,CLEARINGMODE=@CLEARINGMODE,PREGOODSNAME=@PREGOODSNAME,ISCLEAR_CERT=@ISCLEAR_CERT ,CHECKGOV=@CHECKGOV,ISCLEAR_PLAN=@ISCLEAR_PLAN,CLEARTIME=@CLEARTIME,ISCOMPLETE=@ISCOMPLETE,FEENAME=@FEENAME,CURRENCY=@CURRENCY, AMOUNT=@AMOUNT,REMARKS=@REMARKS,CURSTATOIN=@CURSTATOIN where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.INSTATOINTIME == "") enumValue.INSTATOINTIME = null; else { enumValue.INSTATOINTIME = Convert.ToDateTime(enumValue.INSTATOINTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.CLEARTIME == "") enumValue.CLEARTIME = null; else { enumValue.CLEARTIME = Convert.ToDateTime(enumValue.CLEARTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.AUDITTIME == "") enumValue.AUDITTIME = null; if (enumValue.GID == "*" || enumValue.GID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@INSTATOINTIME", DbType.String, enumValue.INSTATOINTIME); db.AddInParameter(cmdInsert, "@CLEARINGMODE", DbType.String, enumValue.CLEARINGMODE); db.AddInParameter(cmdInsert, "@PREGOODSNAME", DbType.String, enumValue.PREGOODSNAME); db.AddInParameter(cmdInsert, "@ISCLEAR_CERT", DbType.Boolean, enumValue.ISCLEAR_CERT); db.AddInParameter(cmdInsert, "@CHECKGOV", DbType.String, enumValue.CHECKGOV); db.AddInParameter(cmdInsert, "@ISCLEAR_PLAN", DbType.Boolean, enumValue.ISCLEAR_PLAN); db.AddInParameter(cmdInsert, "@CLEARTIME", DbType.String, enumValue.CLEARTIME); db.AddInParameter(cmdInsert, "@ISCOMPLETE", DbType.Boolean, enumValue.ISCOMPLETE); db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME); db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@AUDITSTATUS", DbType.String,"录入状态"); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS); db.AddInParameter(cmdInsert, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@INSTATOINTIME", DbType.String, enumValue.INSTATOINTIME); db.AddInParameter(cmdUpdate, "@CLEARINGMODE", DbType.String, enumValue.CLEARINGMODE); db.AddInParameter(cmdUpdate, "@PREGOODSNAME", DbType.String, enumValue.PREGOODSNAME); db.AddInParameter(cmdUpdate, "@ISCLEAR_CERT", DbType.Boolean, enumValue.ISCLEAR_CERT); db.AddInParameter(cmdUpdate, "@CHECKGOV", DbType.String, enumValue.CHECKGOV); db.AddInParameter(cmdUpdate, "@ISCLEAR_PLAN", DbType.Boolean, enumValue.ISCLEAR_PLAN); db.AddInParameter(cmdUpdate, "@CLEARTIME", DbType.String, enumValue.CLEARTIME); db.AddInParameter(cmdUpdate, "@ISCOMPLETE", DbType.Boolean, enumValue.ISCOMPLETE); db.AddInParameter(cmdUpdate, "@FEENAME", DbType.String, enumValue.FEENAME); db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY); db.AddInParameter(cmdUpdate, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT); db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS); db.AddInParameter(cmdUpdate, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN); 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 DeleteOpCtnClearing(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_ctnclearing where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdDelete, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult UpdateClearingFileData(string filename, string name, string BSNO, string type) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (type == "3") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnclearing set IMAGE1=@IMAGE1,IMAGE_LINDADDR=@IMAGE_LINDADDR where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE1", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_LINDADDR", DbType.String, filename); db.ExecuteNonQuery(cmdUpdate, tran); } else if (type == "4") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnclearing set EIR=@EIR,EIRPATH=@EIRPATH where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@EIR", DbType.String, name); db.AddInParameter(cmdUpdate, "@EIRPATH", DbType.String, filename); db.ExecuteNonQuery(cmdUpdate, tran); } else if (type == "5") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnclearing set IMAGE_CLEAR=@IMAGE_CLEAR,IMAGE_CLEARPATH=@IMAGE_CLEARPATH where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE_CLEAR", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_CLEARPATH", DbType.String, filename); db.ExecuteNonQuery(cmdUpdate, tran); } else if (type == "6") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnclearing set IMAGE_CHECKGOV=@IMAGE_CHECKGOV,IMAGE_CHECKGOVPATH=@IMAGE_CHECKGOVPATH where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE_CHECKGOV", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_CHECKGOVPATH", DbType.String, filename); 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 AuditOpCtnClearing(List headData,string type,string username) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdUpdate = db.GetSqlStringCommand("update op_ctnclearing set AUDITSTATUS='提交审核' where GID='" + enumValue.GID + "'"); if (type=="2") cmdUpdate = db.GetSqlStringCommand("update op_ctnclearing set AUDITSTATUS='录入状态' where GID='" + enumValue.GID + "'"); if (type == "0") cmdUpdate = db.GetSqlStringCommand("update op_ctnclearing set AUDITSTATUS='审核通过',AUDITBY='" + username + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+ "' where GID='" + enumValue.GID + "'"); if (type == "4") cmdUpdate = db.GetSqlStringCommand("update op_ctnclearing set AUDITSTATUS='驳回提交',AUDITBY='" + username + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + enumValue.GID + "'"); if (type == "6") cmdUpdate = db.GetSqlStringCommand("update op_ctnclearing set AUDITSTATUS='申请修改' where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交成功"; return result; } #endregion #region OpCtnDelivery static public List GetOpCtnDeliveryList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[CHECKITEMS],[REMARKS]"); strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID]"); strSql.Append(" from op_ctndelivery "); 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 INPUTTIME"); } return SetOpCtnDeliveryData(strSql); } private static List SetOpCtnDeliveryData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnDelivery data = new OpCtnDelivery(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.LINKGID = Convert.ToString(reader["LINKGID"]); data.CHECKITEMS = Convert.ToString(reader["CHECKITEMS"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveOpCtnDelivery(List bodyList, string PID, 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_ctndelivery (GID,LINKGID,CHECKITEMS,INPUTBY,INPUTTIME,REMARKS) values (@GID,@LINKGID,@CHECKITEMS,@INPUTBY,@INPUTTIME,@REMARKS ) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_ctndelivery set CHECKITEMS=@CHECKITEMS,REMARKS=@REMARKS where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.GID == "*" || enumValue.GID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@CHECKITEMS", DbType.String, enumValue.CHECKITEMS); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@CHECKITEMS", DbType.String, enumValue.CHECKITEMS); db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS); 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 DeleteOpCtnDelivery(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_ctndelivery where GID='" + enumValue.GID + "'"); 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 OpCtnRepair static public List GetOpCtnRepairList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[REPAIRITEMS],[REPAIRTIME]"); strSql.Append(",[FEENAME],[CURRENCY],[AMOUNT] ,[CURSTATOIN],[INPUTBY],[INPUTTIME],[COMPANYID],REMARKS,AUDITSTATUS,[AUDITBY],[AUDITTIME],[AUDITRESULT] "); strSql.Append(",(select CTNNO from op_ctnbscard where GID=op_ctnrepair.LINKGID) CTNNO"); strSql.Append(",(select BSNO from op_ctnbscard where GID=op_ctnrepair.LINKGID) BSNO"); strSql.Append(",(select top 1 IMAGE_LINDADDR1 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE_LINDADDR"); strSql.Append(",(select top 1 IMAGE_LINDADDR2 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE_LINDADDR2"); strSql.Append(",(select top 1 IMAGE1 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE1"); strSql.Append(",(select top 1 IMAGE2 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE2"); strSql.Append(" from op_ctnrepair "); 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 REPAIRTIME desc,INPUTTIME desc"); } return SetOpCtnRepairData(strSql); } static public string GetOpCtnRepairListStr(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[REPAIRITEMS],[REPAIRTIME]"); strSql.Append(",[FEENAME],[CURRENCY],[AMOUNT] ,[CURSTATOIN],[INPUTBY],[INPUTTIME],[COMPANYID],REMARKS,AUDITSTATUS,[AUDITBY],[AUDITTIME],[AUDITRESULT] "); strSql.Append(",(select CTNNO from op_ctnbscard where GID=op_ctnrepair.LINKGID) CTNNO"); strSql.Append(",(select BSNO from op_ctnbscard where GID=op_ctnrepair.LINKGID) BSNO"); strSql.Append(",(select top 1 IMAGE_LINDADDR1 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE_LINDADDR"); strSql.Append(",(select top 1 IMAGE_LINDADDR2 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE_LINDADDR2"); strSql.Append(",(select top 1 IMAGE1 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE1"); strSql.Append(",(select top 1 IMAGE2 from op_ctnbscard_img where LINKGID=op_ctnrepair.GID order by INPUTTIME) IMAGE2"); strSql.Append(" from op_ctnrepair "); 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 INPUTTIME"); } return strSql.ToString(); } private static List SetOpCtnRepairData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnRepair data = new OpCtnRepair(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.LINKGID = Convert.ToString(reader["LINKGID"]); data.CTNNO = Convert.ToString(reader["CTNNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]); data.REPAIRITEMS = Convert.ToString(reader["REPAIRITEMS"]); if (reader["REPAIRTIME"] != DBNull.Value) data.REPAIRTIME = Convert.ToDateTime(reader["REPAIRTIME"]).ToString("yyyy-MM-dd"); data.IMAGE_LINDADDR = Convert.ToString(reader["IMAGE_LINDADDR"]); data.IMAGE_LINDADDR2 = Convert.ToString(reader["IMAGE_LINDADDR2"]); data.IMAGE1 = Convert.ToString(reader["IMAGE1"]); data.IMAGE2= Convert.ToString(reader["IMAGE2"]); data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]); data.FEENAME = Convert.ToString(reader["FEENAME"]); data.CURRENCY = Convert.ToString(reader["CURRENCY"]); if (reader["AMOUNT"] != DBNull.Value) data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.AUDITBY = Convert.ToString(reader["AUDITBY"]); data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]); if (reader["AUDITTIME"] != DBNull.Value) data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveOpCtnRepair(List bodyList, string PID, 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_ctnrepair (GID,LINKGID,REPAIRITEMS,REPAIRTIME,FEENAME,CURRENCY,AMOUNT,INPUTBY,INPUTTIME,REMARKS,AUDITSTATUS,CURSTATOIN) values (@GID,@LINKGID,@REPAIRITEMS,@REPAIRTIME,@FEENAME,@CURRENCY,@AMOUNT,@INPUTBY,@INPUTTIME,@REMARKS,@AUDITSTATUS,@CURSTATOIN) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnrepair set REPAIRITEMS=@REPAIRITEMS,REPAIRTIME=@REPAIRTIME,CURRENCY=@CURRENCY,AMOUNT=@AMOUNT ,FEENAME=@FEENAME,REMARKS=@REMARKS,CURSTATOIN=@CURSTATOIN where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.REPAIRTIME == "") enumValue.REPAIRTIME = null; else { enumValue.REPAIRTIME = Convert.ToDateTime(enumValue.REPAIRTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd"); } if (enumValue.GID == "*" || enumValue.GID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@REPAIRITEMS", DbType.String, enumValue.REPAIRITEMS); db.AddInParameter(cmdInsert, "@REPAIRTIME", DbType.String, enumValue.REPAIRTIME); db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME); db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@AUDITSTATUS", DbType.String, "录入状态"); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS); db.AddInParameter(cmdInsert, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@REPAIRITEMS", DbType.String, enumValue.REPAIRITEMS); db.AddInParameter(cmdUpdate, "@REPAIRTIME", DbType.String, enumValue.REPAIRTIME); db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY); db.AddInParameter(cmdUpdate, "@FEENAME", DbType.String, enumValue.FEENAME); db.AddInParameter(cmdUpdate, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT); db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS); db.AddInParameter(cmdUpdate, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN); 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 SaveOpCtnRepairImg(List bodyList, string PID, 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_ctnbscard_img (GID,LINKGID,IMAGEDESC,INPUTBY,INPUTTIME,REMARKS) values (@GID,@LINKGID,@IMAGEDESC,@INPUTBY,@INPUTTIME,@REMARKS) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard_img set IMAGEDESC=@IMAGEDESC ,REMARKS=@REMARKS where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.GID == "*" || enumValue.GID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@IMAGEDESC", DbType.String, enumValue.IMAGEDESC); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@IMAGEDESC", DbType.String, enumValue.IMAGEDESC); db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS); 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 DeleteOpCtnRepair(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_ctnrepair where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdDelete, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult UpdateRepairFileData(string filename, string name, string BSNO, string type) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (type == "1") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard_img set IMAGE1=@IMAGE1,IMAGE_LINDADDR1=@IMAGE_LINDADDR1 where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE1", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_LINDADDR1", DbType.String, filename); db.ExecuteNonQuery(cmdUpdate, tran); } else { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard_img set IMAGE2=@IMAGE2,IMAGE_LINDADDR2=@IMAGE_LINDADDR2 where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE2", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_LINDADDR2", DbType.String, filename); 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 AuditOpCtnRepair(List headData, string type, string username) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdUpdate = db.GetSqlStringCommand("update op_ctnrepair set AUDITSTATUS='提交审核' where GID='" + enumValue.GID + "'"); if (type == "2") cmdUpdate = db.GetSqlStringCommand("update op_ctnrepair set AUDITSTATUS='录入状态' where GID='" + enumValue.GID + "'"); if (type == "0") cmdUpdate = db.GetSqlStringCommand("update op_ctnrepair set AUDITSTATUS='审核通过',AUDITBY='" + username + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + enumValue.GID + "'"); if (type == "4") cmdUpdate = db.GetSqlStringCommand("update op_ctnrepair set AUDITSTATUS='驳回提交',AUDITBY='" + username + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + enumValue.GID + "'"); if (type == "6") cmdUpdate = db.GetSqlStringCommand("update op_ctnrepair set AUDITSTATUS='申请修改' where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdUpdate, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交或审核出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交或审核成功"; return result; } public static DBResult CreateOpCtnRepairFromFee(List FeeList, string userid) { var result = new DBResult(); var headdata = GetData("GID='" + FeeList[0].BsNo + "'", userid); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); var cmdInsert = db.GetSqlStringCommand( @"insert into op_ctnclearing (GID,LINKGID,INSTATOINTIME,CLEARINGMODE,PREGOODSNAME,ISCLEAR_CERT,CHECKGOV,ISCLEAR_PLAN,CLEARTIME,ISCOMPLETE, FEENAME,CURRENCY,AMOUNT,INPUTBY,INPUTTIME,REMARKS,AUDITSTATUS,CURSTATOIN) values (@GID,@LINKGID,@INSTATOINTIME,@CLEARINGMODE,@PREGOODSNAME,@ISCLEAR_CERT,@CHECKGOV,@ISCLEAR_PLAN,@CLEARTIME,@ISCOMPLETE,@FEENAME, @CURRENCY,@AMOUNT,@INPUTBY,@INPUTTIME,@REMARKS,@AUDITSTATUS,@CURSTATOIN ) "); var cmdInsertRepaire = db.GetSqlStringCommand( @"insert into op_ctnrepair (GID,LINKGID,REPAIRITEMS,REPAIRTIME,FEENAME,CURRENCY,AMOUNT,INPUTBY,INPUTTIME,REMARKS,AUDITSTATUS,CURSTATOIN) values (@GID,@LINKGID,@REPAIRITEMS,@REPAIRTIME,@FEENAME,@CURRENCY,@AMOUNT,@INPUTBY,@INPUTTIME,@REMARKS,@AUDITSTATUS,@CURSTATOIN) "); try { if (FeeList != null) { foreach (var enumValue in FeeList) { var rtnctndate = ""; if (headdata.IS_DB && headdata.D_DEST_RTCNT_TIME != "") { rtnctndate = headdata.D_DEST_RTCNT_TIME; } else if (headdata.IS_RETURE_EMPTY && headdata.I_DEST_RTCNT_TIME != "") { rtnctndate = headdata.I_DEST_RTCNT_TIME; } else if (headdata.DEST_RTCNT_TIME != "") { rtnctndate = headdata.DEST_RTCNT_TIME; } if (enumValue.FeeName == "清洗费") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, headdata.GID); db.AddInParameter(cmdInsert, "@INSTATOINTIME", DbType.String, rtnctndate); db.AddInParameter(cmdInsert, "@CLEARINGMODE", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREGOODSNAME", DbType.String, headdata.PREGOODSNAME); db.AddInParameter(cmdInsert, "@ISCLEAR_CERT", DbType.Boolean, false); db.AddInParameter(cmdInsert, "@CHECKGOV", DbType.String, enumValue.CustomerName); db.AddInParameter(cmdInsert, "@ISCLEAR_PLAN", DbType.Boolean, false); db.AddInParameter(cmdInsert, "@CLEARTIME", DbType.String, rtnctndate); db.AddInParameter(cmdInsert, "@ISCOMPLETE", DbType.Boolean, true); db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@AUDITSTATUS", DbType.String, "录入状态"); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.Remark); db.AddInParameter(cmdInsert, "@CURSTATOIN", DbType.String, headdata.CURSTATOIN); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdInsertRepaire.Parameters.Clear(); db.AddInParameter(cmdInsertRepaire, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsertRepaire, "@LINKGID", DbType.String, headdata.GID); db.AddInParameter(cmdInsertRepaire, "@REPAIRITEMS", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsertRepaire, "@REPAIRTIME", DbType.String,rtnctndate); db.AddInParameter(cmdInsertRepaire, "@FEENAME", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsertRepaire, "@CURRENCY", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsertRepaire, "@AMOUNT", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsertRepaire, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsertRepaire, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsertRepaire, "@AUDITSTATUS", DbType.String, "录入状态"); db.AddInParameter(cmdInsertRepaire, "@REMARKS", DbType.String, enumValue.Remark); db.AddInParameter(cmdInsertRepaire, "@CURSTATOIN", DbType.String, headdata.CURSTATOIN); db.ExecuteNonQuery(cmdInsertRepaire, tran); } } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "提交或审核出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "提交或审核成功"; return result; } public static DBResult GetYardRemark(string bsno,string userid) { var result = new DBResult(); var headdata = GetData("GID='" + bsno+ "'", userid); var remark = ""; var rtnctndate = ""; var rtnyard = ""; var rtnport = ""; if (headdata.IS_DB && headdata.D_DEST_RTCNT_TIME != "") { rtnctndate = headdata.D_DEST_RTCNT_TIME; rtnport = headdata.D_DESTPORT; rtnyard = headdata.D_DESTPORT_STATOIN; } else if (headdata.IS_RETURE_EMPTY && headdata.I_DEST_RTCNT_TIME != "") { rtnctndate = headdata.I_DEST_RTCNT_TIME; rtnport = headdata.I_DESTPORT; rtnyard = headdata.I_DESTPORT_STATOIN; } else if (headdata.DEST_RTCNT_TIME != "") { rtnctndate = headdata.DEST_RTCNT_TIME; rtnport = headdata.DESTPORT; rtnyard = headdata.DESTPORT_STATOIN; } remark = rtnctndate + "-" + headdata.NPORTLOAD_CNT_TIME; var con = "FEENAME"; var pricelist = MsOpPriceDAL.GetPriceItemsList("FEENAME='堆存费' AND LINKGID IN (SELECT GID FROM op_price WHERE PORTDISCHARGE='"+rtnport+ "' and YARD='"+ rtnyard + "' and FEETYPE='堆存')", " INPUTTIME DESC"); if (pricelist.Count > 0) { remark = remark + " 清洗免堆存" + pricelist[0].FREEDAY + "天,超期" + pricelist[0].UNITPRICE + "/天"; } result.Success = true; result.Data = remark; result.Message = "提交或审核成功"; return result; } #endregion #region OpCtnRepairImg static public List GetOpCtnRepairListImg(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT [GID],[LINKGID],[IMAGEDESC],[IMAGE_LINDADDR1],[IMAGE_LINDADDR2],[IMAGE1],[IMAGE2]"); strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID],REMARKS "); strSql.Append(" from op_ctnbscard_img "); 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 INPUTTIME"); } return SetOpCtnRepairDataImg(strSql); } private static List SetOpCtnRepairDataImg(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpCtnRepairImg data = new OpCtnRepairImg(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.LINKGID = Convert.ToString(reader["LINKGID"]); data.IMAGEDESC = Convert.ToString(reader["IMAGEDESC"]); data.IMAGE_LINDADDR1 = Convert.ToString(reader["IMAGE_LINDADDR1"]); data.IMAGE_LINDADDR2 = Convert.ToString(reader["IMAGE_LINDADDR2"]); data.IMAGE1 = Convert.ToString(reader["IMAGE1"]); data.IMAGE2 = Convert.ToString(reader["IMAGE2"]); data.INPUTBY = Convert.ToString(reader["INPUTBY"]); data.REMARKS = Convert.ToString(reader["REMARKS"]); if (reader["INPUTTIME"] != DBNull.Value) data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult DeleteOpCtnRepairImg(List headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData != null) { foreach (var enumValue in headData) { var cmdDelete = db.GetSqlStringCommand("delete from op_ctnbscard_img where GID='" + enumValue.GID + "'"); db.ExecuteNonQuery(cmdDelete, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult UpdateRepairFileDataImg(string filename, string name, string BSNO, string type) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (type == "1") { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard_img set IMAGE1=@IMAGE1,IMAGE_LINDADDR1=@IMAGE_LINDADDR1 where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE1", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_LINDADDR1", DbType.String, filename); db.ExecuteNonQuery(cmdUpdate, tran); } else { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnbscard_img set IMAGE2=@IMAGE2,IMAGE_LINDADDR2=@IMAGE_LINDADDR2 where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, BSNO); db.AddInParameter(cmdUpdate, "@IMAGE2", DbType.String, name); db.AddInParameter(cmdUpdate, "@IMAGE_LINDADDR2", DbType.String, filename); 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 // public static DBResult UpOpCtnApplyCtnItems(string CNTRNO,string APPLYNO) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand( @"update op_ctnapplyctnitems set AUDITSTATUS=@AUDITSTATUS,AUDITBY=@AUDITBY,AUDITTIME=@AUDITTIME where CTNNO=@CTNNO AND LINKGID=(SELECT TOP 1 GID FROM op_ctnapply WHERE BSNO=@BSNO) "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@AUDITSTATUS", DbType.String, "录入"); db.AddInParameter(cmdUpdate, "@AUDITBY", DbType.String,""); db.AddInParameter(cmdUpdate, "@AUDITTIME", DbType.String,null); db.AddInParameter(cmdUpdate, "@CTNNO", DbType.String, CNTRNO); db.AddInParameter(cmdUpdate, "@BSNO", DbType.String, APPLYNO); db.ExecuteNonQuery(cmdUpdate, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } private static int DateDiff(string dateStart, string dateEnd) { DateTime start = Convert.ToDateTime(dateStart); DateTime end = Convert.ToDateTime(dateEnd); TimeSpan sp = end.Subtract(start); return sp.Days; } static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT Count(BSNO) AS CT from op_ctnbscard (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; } public static DBResult UpCtnStatus(string CTNNO) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdate = db.GetSqlStringCommand("update code_ctntk set CTNSTATUS='可用' where CTNNO='"+CTNNO+"'"); db.ExecuteNonQuery(cmdUpdate, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult SaveFeeDR(OpCtnBsCard headdata, string userid,string feetype) { 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 ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE) "); if (headdata.PORTLOAD_OVER_DAYS_AMT != 0 && feetype=="1") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, headdata.GID); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, "箱使费"); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, ""); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, headdata.AGENTNAME); db.AddInParameter(cmdInsert, "@unit", DbType.String, "罐"); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, headdata.PORTLOAD_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, "DEMURRAGE CHARGE"); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal,1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, headdata.PORTLOAD_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@currency", DbType.String, "USD"); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, MsChFeeDAL.GetUsdExrate("", "","")); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); var remark = headdata.CTNNO + "," + headdata.PORTLOAD_CNT_TIME + "到," + headdata.ETD + "还," + headdata.PORTLOAD_FREE_DAYS + "," + headdata.PORTLOAD_OVER_DAYS_FEE + ",超期" + headdata.PORTLOAD_OVER_DAYS + "天," + headdata.PORTLOAD_OVER_DAYS_AMT; db.AddInParameter(cmdInsert, "@remark", DbType.String, remark); // db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, headdata.PORTLOAD_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal,0); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "手工"); db.ExecuteNonQuery(cmdInsert, tran); } if (headdata.DESTPORT_OVER_DAYS_AMT != 0 && feetype == "2") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, headdata.GID); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, "箱使费"); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, ""); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, headdata.AGENTNAME); db.AddInParameter(cmdInsert, "@unit", DbType.String, "罐"); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, headdata.DESTPORT_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, "DEMURRAGE CHARGE"); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, headdata.DESTPORT_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@currency", DbType.String, "USD"); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, MsChFeeDAL.GetUsdExrate("", "","")); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); var remark = headdata.CTNNO + "," + headdata.ETA + "到," + headdata.DEST_RTCNT_TIME + "还," + headdata.DESTPORT_FREE_DAYS + "," + headdata.DESTPORT_OVER_DAYS_FEE + ",超期" + headdata.DESTPORT_OVER_DAYS + "天," + headdata.DESTPORT_OVER_DAYS_AMT; db.AddInParameter(cmdInsert, "@remark", DbType.String, remark); // db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, headdata.DESTPORT_OVER_DAYS_AMT); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "手工"); db.ExecuteNonQuery(cmdInsert, tran); } if (headdata.DESTPORT_OVER_DAYS_AMT != 0 && feetype == "3") { T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var sSQL = "SELECT CHANGERATE as inum from op_ctnapply where BSNO='" + headdata.APPLYNO + "'"; var sNum = T_ALL_DA.GetStrSQL("inum", sSQL); if (sNum != "" && sNum != "0") { var amountfee=headdata.DESTPORT_OVER_DAYS_AMT*Convert.ToDecimal(sNum)/100; cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, headdata.GID); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, "箱使代理费"); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, ""); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, headdata.AGENTNAME); db.AddInParameter(cmdInsert, "@unit", DbType.String, "罐"); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, -amountfee); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, "COMMISSION"); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, -amountfee); db.AddInParameter(cmdInsert, "@currency", DbType.String, "USD"); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, MsChFeeDAL.GetUsdExrate("", "","")); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, ""); // db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, -amountfee); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 0); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal,0); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "手工"); db.ExecuteNonQuery(cmdInsert, 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 UpdOpseaiDEST_RTCNT_TIME(OpCtnBsCard headData) { var result = new DBResult(); if (!string.IsNullOrWhiteSpace(headData.DEST_RTCNT_TIME) && !headData.DEST_RTCNT_TIME.Contains("1900-01-01")) { result.SetErrorInfo(""); } else { var _r = BasicDataRefDAL.ExecSql($" update op_seai set DEST_RTCNT_TIME='{headData.DEST_RTCNT_TIME}' where applyno='{headData.APPLYNO}' and not exists(select 1 from v_top_opctnbscard where applyno='{headData.APPLYNO}' and isnull(DEST_RTCNT_TIME,'')='')"); if (_r > 0) result.Success = true; } return result; } public static DBResult UpBsCtn(OpCtnBsCard headData,string updatetype="0") { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (updatetype == "0" || updatetype == "1") { var cmdUpdate = db.GetSqlStringCommand("update op_ctn set TIXIANGSHIJIAN='" + headData.PORTLOAD_CNT_TIME + "',FREECTNDAY=" + headData.PORTLOAD_FREE_DAYS + ",CTNDAY=" + headData.PORTLOAD_OVER_DAYS.ToString() + ",CTNPRICE="+ headData.PORTLOAD_OVER_DAYS_FEE.ToString()+ " FROM op_ctn WHERE CNTRNO='" + headData.CTNNO + "' AND EXISTS (SELECT 1 FROM OP_SEAE WHERE OP_SEAE.BSNO=op_ctn.BSNO AND OP_SEAE.APPLYNO='" + headData.APPLYNO + "') "); db.ExecuteNonQuery(cmdUpdate, tran); } if (updatetype == "0" || updatetype == "2") { var cmdUpdateSeai = db.GetSqlStringCommand("update op_ctn set TIXIANGSHIJIAN='" + headData.DEST_RTCNT_TIME + "',FREECTNDAY=" + headData.DESTPORT_FREE_DAYS + ",CTNDAY=" + headData.DESTPORT_OVER_DAYS + ",CTNPRICE=" + headData.DESTPORT_OVER_DAYS_FEE.ToString() + " FROM OP_CTN WHERE CNTRNO='" + headData.CTNNO + "' AND EXISTS (SELECT 1 FROM OP_SEAI WHERE OP_SEAI.BSNO=op_ctn.BSNO AND OP_SEAI.APPLYNO='" + headData.APPLYNO + "') "); db.ExecuteNonQuery(cmdUpdateSeai, tran); } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "更新成功"; return result; } public static DBResult InsertOpCtnRepairImg(OpCtnRepairImg imgdata, string PID, 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_ctnbscard_img (GID,LINKGID,IMAGEDESC,INPUTBY,INPUTTIME,REMARKS) values (@GID,@LINKGID,@IMAGEDESC,@INPUTBY,@INPUTTIME,@REMARKS) "); cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, imgdata.GID); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@IMAGEDESC", DbType.String, imgdata.IMAGEDESC); db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid); db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, imgdata.REMARKS); db.ExecuteNonQuery(cmdInsert, tran); tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } #region 权限范围 public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; string modustr = "modOpCtnBsCard";// modOpCtnApply var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" VISIBLERANGE,OPERATERANGE "); strSql.Append(" from VW_User_Authority "); strSql.Append(" where [NAME]='" + modustr + "' 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 = " (b.OP='" + username + "')"; } else if (visiblerange == "3") { str = " (b.OP='" + username + "')"; } else if (visiblerange == "2") { if (tb == "index") { 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 = " (b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' "; } else { str = str + " or b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' "; }; } str = str + ")"; reader.Close(); } } else { str = " b.COMPANYID='" + companyid + "'"; } } else if (visiblerange == "1") { str = " b.COMPANYID='" + companyid + "'"; } return str; } #endregion } }