using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.TruckMng.Models.MsOpTruckBulkPc; using DSWeb.TruckMng.Models.MsOpTruckBulk; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; using System.Data.SqlClient; using DSWeb.DataAccess; using DSWeb.TruckMng.DAL.MsOpTruckBulkDAL; using DSWeb.Areas.CommMng.DAL; using DSWeb.TruckMng.DAL.MsCustTruckFeeTemplate; using DSWeb.Areas.SysMng.DAL.SysUser; namespace DSWeb.TruckMng.DAL.MsOpTruckBulkPcDAL { public class MsOpTruckBulkPcDAL { #region Inquery DataList static public List GetDataList(int start, int limit, string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, 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)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME desc"); } strSql.Append(@") as num ,* from ( "); // strSql.Append("select op_truck_bulk_pc.BSNO, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF"); strSql.Append(" ,TRANSSTATUS,[CUSTNO],[TRUCKER],TRUCKNO,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]"); strSql.Append(" ,[BSSOURCEDETAIL],[OP],DDOP,[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[KGS],[PKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK],DRIVER,DRIVERTEL"); strSql.Append(",[CONTRACTNO],TEMPLATENAME,UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,[NETWEIGHT],ORUNITPRICE,ORFREIGHT,SALE,CUSTSERVICE,CTNALL,CTNNUM"); strSql.Append(",TRANSTYPE,MBLNO,YARD,CLOSINGDATE,TRADETYPE,GOODSNAME,TAXRATE,TTLFREIGHT,ARRIVEDATE,RETURNDOCDATE,ARRIVEREMARK"); strSql.Append(" ,(select top 1 showname from [user] where GID=op_truck_bulk_pc.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk_pc.MODIFIEDUSER) as MODIFIEDUSER, "); strSql.Append(" MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk_pc.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk_pc.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLCR,I.TTLINVCR,I.TTLYFCR,I.TTLOTCR "); strSql.Append(",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.CUSTOMERNAME) AS CUSTOMERNAMEREF "); strSql.Append(",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.TRUCKER) AS TRUCKERREF "); strSql.Append(",ORDERNO = stuff ((SELECT distinct ORDERNO+',' FROM op_truck_bulk AS t left join op_truck_bulk_pc_detail d on (d.LINKBSNO=t.BSNO) WHERE d.BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "); strSql.Append(",INVOICEBILLNO = stuff ((SELECT distinct t.BILLNO+',' FROM CH_FEE_DO AS t WHERE t.CATEGORY=6 and t .BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "); strSql.Append(",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk_pc.SALECORPID) as SALECORP,op_truck_bulk_pc.BillFeeStatus FROM op_truck_bulk_pc"); strSql.Append(" LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk_pc.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append( " ) v "); strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // return SetData(strSql.ToString()); } public static int getTotalCount(string strCondition, string userid, string usercode, string companyid) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) "); strSql.Append(" from op_truck_bulk_pc "); strSql.Append(" LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk_pc.BSNO) "); 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 string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } // String strSql = "SELECT op_truck_bulk_pc.BSNO, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF"; strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[TRUCKER],TRUCKNO,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]"; strSql = strSql + " ,[BSSOURCEDETAIL],[OP],DDOP,[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[KGS],[PKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK],DRIVER,DRIVERTEL"; strSql = strSql + ",[CONTRACTNO],TEMPLATENAME,UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,[NETWEIGHT],ORUNITPRICE,ORFREIGHT,SALE,CUSTSERVICE,CTNALL,CTNNUM"; strSql = strSql + ",TRANSTYPE,MBLNO,YARD,CLOSINGDATE,TRADETYPE,GOODSNAME,TAXRATE,TTLFREIGHT,ARRIVEDATE,RETURNDOCDATE,ARRIVEREMARK"; strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk_pc.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk_pc.MODIFIEDUSER) as MODIFIEDUSER, "; strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk_pc.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk_pc.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLCR,I.TTLINVCR,I.TTLYFCR,I.TTLOTCR "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.CUSTOMERNAME) AS CUSTOMERNAMEREF "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.TRUCKER) AS TRUCKERREF "; strSql = strSql + ",ORDERNO = stuff ((SELECT distinct ORDERNO+',' FROM op_truck_bulk AS t left join op_truck_bulk_pc_detail d on (d.LINKBSNO=t.BSNO) WHERE d.BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",INVOICEBILLNO = stuff ((SELECT distinct t.BILLNO+',' FROM CH_FEE_DO AS t WHERE t.CATEGORY=6 and t .BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk_pc.SALECORPID) as SALECORP,op_truck_bulk_pc.BillFeeStatus FROM op_truck_bulk_pc"; strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk_pc.BSNO) "; if (!string.IsNullOrEmpty(strCondition)) { strSql += " where " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by BSDATE desc"; } return strSql.ToString(); } static public MsOpTruckBulkPc GetData(string condition) { String strSql = "SELECT op_truck_bulk_pc.BSNO, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF"; strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[TRUCKER],TRUCKNO,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]"; strSql = strSql + " ,[BSSOURCEDETAIL],[OP],DDOP,[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[KGS],[PKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK],DRIVER,DRIVERTEL"; strSql = strSql + ",TRANSTYPE,MBLNO,YARD,CLOSINGDATE,TRADETYPE,GOODSNAME,TAXRATE,TTLFREIGHT,ARRIVEDATE,RETURNDOCDATE,ARRIVEREMARK"; strSql = strSql + ",[CONTRACTNO],TEMPLATENAME,UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,[NETWEIGHT],ORUNITPRICE,ORFREIGHT,SALE,CUSTSERVICE,CTNALL,CTNNUM"; strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk_pc.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk_pc.MODIFIEDUSER) as MODIFIEDUSER, "; strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk_pc.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk_pc.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLCR,I.TTLINVCR,I.TTLYFCR,I.TTLOTCR "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.CUSTOMERNAME) AS CUSTOMERNAMEREF "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.TRUCKER) AS TRUCKERREF "; strSql = strSql + ",ORDERNO = stuff ((SELECT distinct ORDERNO+',' FROM op_truck_bulk AS t left join op_truck_bulk_pc_detail d on (d.LINKBSNO=t.BSNO) WHERE d.BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",INVOICEBILLNO = stuff ((SELECT distinct t.BILLNO+',' FROM CH_FEE_DO AS t WHERE t.CATEGORY=6 and t .BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk_pc.SALECORPID) as SALECORP,op_truck_bulk_pc.BillFeeStatus FROM op_truck_bulk_pc"; strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk_pc.BSNO) "; if (!string.IsNullOrEmpty(condition)) { strSql += " where " + condition; } var list=SetData(strSql); if (list.Count > 0) { return list[0]; } return new MsOpTruckBulkPc(); } static public List GetAuditDataList(string strCondition, string isaudit, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); //if (!string.IsNullOrEmpty(rangstr)) //{ // if (!string.IsNullOrEmpty(strCondition)) // { // strCondition = strCondition + " and " + rangstr; // } // else // { // strCondition = rangstr; // } //} // String strSql = "SELECT op_truck_bulk_pc.BSNO, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF"; strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[TRUCKER],TRUCKNO,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]"; strSql = strSql + " ,[BSSOURCEDETAIL],op_truck_bulk_pc.OP,DDOP,[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[KGS],[PKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK],DRIVER,DRIVERTEL"; strSql = strSql + ",[CONTRACTNO],TEMPLATENAME,UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,[NETWEIGHT],ORUNITPRICE,ORFREIGHT,SALE,CUSTSERVICE,CTNALL,CTNNUM"; strSql = strSql + ",TRANSTYPE,MBLNO,YARD,CLOSINGDATE,TRADETYPE,GOODSNAME,TAXRATE,TTLFREIGHT,ARRIVEDATE,RETURNDOCDATE,ARRIVEREMARK"; strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk_pc.CREATEUSER) as CREATEUSER, op_truck_bulk_pc.CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk_pc.MODIFIEDUSER) as MODIFIEDUSER, "; strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk_pc.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk_pc.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLCR,I.TTLINVCR,I.TTLYFCR,I.TTLOTCR "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.CUSTOMERNAME) AS CUSTOMERNAMEREF "; strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk_pc.TRUCKER) AS TRUCKERREF "; strSql = strSql + ",ORDERNO = stuff ((SELECT distinct ORDERNO+',' FROM op_truck_bulk AS t left join op_truck_bulk_pc_detail d on (d.LINKBSNO=t.BSNO) WHERE d.BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",INVOICEBILLNO = stuff ((SELECT distinct t.BILLNO+',' FROM CH_FEE_DO AS t WHERE t.CATEGORY=6 and t .BSNO = op_truck_bulk_pc.BSNO FOR xml path('')), 1, 0, '') "; strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk_pc.SALECORPID) as SALECORP,op_truck_bulk_pc.BillFeeStatus FROM op_truck_bulk_pc"; strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk_pc.BSNO) "; strSql = strSql + " left join workflow_using wu on wu.bsno=op_truck_bulk_pc.bsno where 1=1 "; if (isaudit == "3") strSql = strSql + " and op_truck_bulk_pc.TRANSSTATUS<>'审核通过' and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 "; else if (isaudit == "2") { strSql = strSql + " and op_truck_bulk_pc.TRANSSTATUS='审核通过' ";// AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) "); if (!string.IsNullOrEmpty(rangstr)) { strSql = strSql + " and " + rangstr; } } else if (isaudit == "1") { strSql = strSql + " and op_truck_bulk_pc.TRANSSTATUS='提交审核' ";// AND I.BILLNO IN (select distinct billno from workflow_do where auditor='" + userid + "' ) "); if (!string.IsNullOrEmpty(rangstr)) { strSql = strSql + " and " + rangstr; } } else if (isaudit == "") { if (!string.IsNullOrEmpty(rangstr)) { strSql = strSql + " and " + rangstr; } } if (!string.IsNullOrEmpty(strCondition)) { strSql += " and " + strCondition; } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql += " order by " + sortstring; } else { strSql += " order by BSDATE desc"; } return SetData(strSql); } private static List SetData(String strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpTruckBulkPc data = new MsOpTruckBulkPc(); #region Set DB data to Object if (reader["BillFeeStatus"] != DBNull.Value) data.BillFeeStatus = Convert.ToString(reader["BillFeeStatus"]); else data.BillFeeStatus ="0"; data.BSNO = Convert.ToString(reader["BSNO"]); data.BSSTATUS = Convert.ToBoolean(reader["BSSTATUS"]); data.FEESTATUS = Convert.ToBoolean(reader["FEESTATUS"]); data.BSSTATUSREF = Convert.ToString(reader["BSSTATUSREF"]); data.FEESTATUSREF = Convert.ToString(reader["FEESTATUSREF"]); data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"])); data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"])); data.TRANSSTATUS = Convert.ToString(reader["TRANSSTATUS"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.TRUCKER = Convert.ToString(reader["TRUCKER"]); data.DRIVER = Convert.ToString(reader["DRIVER"]); data.DRIVERTEL = Convert.ToString(reader["DRIVERTEL"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CUSTOMERNAMEREF = Convert.ToString(reader["CUSTOMERNAMEREF"]); data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]); data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]); if (reader["BSDATE"] != DBNull.Value) data.BSDATE = Convert.ToDateTime(reader["BSDATE"]).ToString("yyyy-MM-dd"); //if (reader["BSDATE"] != DBNull.Value) // data.BSDATE = Convert.ToDateTime(reader["BSDATE"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.OP = Convert.ToString(reader["OP"]); data.DDOP = Convert.ToString(reader["DDOP"]); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.SALE = Convert.ToString(reader["SALE"]); data.CORPID = Convert.ToString(reader["CORPID"]); 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.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]); data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]); data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]); data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]); data.TRANSTYPE = Convert.ToString(reader["TRANSTYPE"]); data.TRADETYPE= Convert.ToString(reader["TRADETYPE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.MBLNO= Convert.ToString(reader["MBLNO"]); data.YARD = Convert.ToString(reader["YARD"]); if (reader["CLOSINGDATE"] != DBNull.Value) data.CLOSINGDATE = Convert.ToDateTime(reader["CLOSINGDATE"]).ToString("yyyy-MM-dd HH:mm:ss"); //if (reader["ETD"] != DBNull.Value) // data.ETD = Convert.ToDateTime(reader["ETD"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); if (reader["KGS"] != DBNull.Value) data.KGS = Convert.ToDecimal(reader["KGS"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); if (reader["PKGS"] != DBNull.Value) data.PKGS = Convert.ToInt32(reader["PKGS"]); if (reader["CBM"] != DBNull.Value) data.CBM = Convert.ToDecimal(reader["CBM"]); if (reader["TRUCKNUM"] != DBNull.Value) data.TRUCKNUM = Convert.ToDecimal(reader["TRUCKNUM"]); if (reader["ISVOU"] != DBNull.Value) data.ISVOU = Convert.ToBoolean(reader["ISVOU"]); data.VOUNO = Convert.ToString(reader["VOUNO"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]); if (reader["MODIFIEDTIME"] != DBNull.Value) data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]); data.STLNAME = Convert.ToString(reader["STLNAME"]); data.STLDATE = Convert.ToString(reader["STLDATE"]); data.ISPRINTPR = Convert.ToString(reader["ISPRINTPR"]); decimal ttldr = 0; if (reader["TTLCR"] != DBNull.Value) ttldr = Convert.ToDecimal(reader["TTLCR"]); decimal ttlinvdr = 0; if (reader["TTLCR"] != DBNull.Value) ttlinvdr = Convert.ToDecimal(reader["TTLINVCR"]); if (ttlinvdr == 0) data.DRINVSTATUS = "未开票"; else if (ttlinvdr == ttldr) data.DRINVSTATUS = "已开票"; else if (ttlinvdr != ttldr) data.DRINVSTATUS = "部分开票"; data.SALECORPID = Convert.ToString(reader["SALECORPID"]);//分公司代码 data.SALECORP = Convert.ToString(reader["SALECORP"]);//分公司代码 if (reader["TTLCR"] != DBNull.Value) data.TTLDR = Math.Round(Convert.ToDecimal(Convert.ToString(reader["TTLCR"])), 2).ToString(); if (reader["TTLYFCR"] != DBNull.Value) data.TTLYFDR = Math.Round(Convert.ToDecimal(Convert.ToString(reader["TTLYFCR"])), 2).ToString(); if (reader["TTLOTCR"] != DBNull.Value) data.TTLOTDR = Math.Round(Convert.ToDecimal(Convert.ToString(reader["TTLOTCR"])), 2).ToString(); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.TEMPLATENAME = Convert.ToString(reader["TEMPLATENAME"]); data.FEEUNIT = Convert.ToString(reader["FEEUNIT"]); data.PRICEUNIT = Convert.ToString(reader["PRICEUNIT"]); data.UNITTYPE = Convert.ToString(reader["UNITTYPE"]); data.UNIT = Convert.ToString(reader["UNIT"]); if (reader["UNITPRICE"] != DBNull.Value) data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]); if (reader["FREIGHT"] != DBNull.Value) data.FREIGHT = Convert.ToDecimal(reader["FREIGHT"]); data.ISFEE = Convert.ToString(reader["ISFEE"]); if (reader["ORUNITPRICE"] != DBNull.Value) data.ORUNITPRICE = Convert.ToDecimal(reader["ORUNITPRICE"]); if (reader["ORFREIGHT"] != DBNull.Value) data.ORFREIGHT = Convert.ToDecimal(reader["ORFREIGHT"]); if (reader["TAXRATE"] != DBNull.Value) data.TAXRATE = Convert.ToDecimal(reader["TAXRATE"]); if (reader["TTLFREIGHT"] != DBNull.Value) data.TTLFREIGHT = Convert.ToDecimal(reader["TTLFREIGHT"]); if (reader["ARRIVEDATE"] != DBNull.Value) data.ARRIVEDATE = Convert.ToDateTime(reader["ARRIVEDATE"]).ToString("yyyy-MM-dd"); data.ARRIVEREMARK = Convert.ToString(reader["ARRIVEREMARK"]); if (reader["RETURNDOCDATE"] != DBNull.Value) data.RETURNDOCDATE = Convert.ToDateTime(reader["RETURNDOCDATE"]).ToString("yyyy-MM-dd"); if (data.CONTRACTNO != "" && data.TEMPLATENAME != "" && data.UNITPRICE == data.ORUNITPRICE && data.FREIGHT == data.ORFREIGHT) data.ISAUTOFEE = "否"; if (data.TTLDR == "") data.TTLDR = "0"; if (data.TTLYFDR == "") data.TTLYFDR = "0"; if (data.TTLOTDR == "") data.TTLOTDR = "0"; if (data.TTLDR == data.TTLOTDR) { data.TTLDR = Math.Round((Convert.ToDecimal(data.TTLFREIGHT) + Convert.ToDecimal(data.TTLOTDR)), 2).ToString(); } data.CUSTOMERNAMEREF= Convert.ToString(reader["CUSTOMERNAMEREF"]); data.TRUCKERREF = Convert.ToString(reader["TRUCKERREF"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.CTNALL = Convert.ToString(reader["CTNALL"]); if (reader["CTNNUM"] != DBNull.Value) data.CTNNUM = Convert.ToInt32(reader["CTNNUM"]); data.INVOICEBILLNO = Convert.ToString(reader["INVOICEBILLNO"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static string getfeestatus(string feestatusint) { var result = ""; if (feestatusint == "0:") { return "审核通过"; } else if (feestatusint == "1:") { return "录入状态"; } else if (feestatusint == "2:") { return "提交审核"; } else if (feestatusint == "8:") { return "部分结算"; } else if (feestatusint == "9:") { return "结算完毕"; } else if (feestatusint == "") { return "未录入"; } else if (feestatusint == "3:") { return "申请修改"; } else if (feestatusint == "4:") { return "申请删除"; } else if (feestatusint == "6:") { return "驳回提交"; } else if (feestatusint == "7:") { return "驳回申请"; } else if (feestatusint.IndexOf("9:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("8:") > -1) { return "部分结算"; } else if (feestatusint.IndexOf("0:") > -1) { return "部分审核"; } else if (feestatusint.IndexOf("2:") > -1) { return "部分提交"; } else if (feestatusint.IndexOf("6:") > -1) { return "驳回提交"; } else if (feestatusint.IndexOf("7:") > -1) { return "驳回申请"; } return result; } #endregion #region 明细表 static public List GetBodyList(string strCondition, string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT * "); strSql.Append(",CASE WHEN TRANSTYPE='集装箱' THEN (case when ISNULL(BCTNNUM,0)=0 THEN 0 ELSE cast(round(GTTLDR/BCTNNUM*CTNNUM,2) as numeric(20,2)) END) ELSE (case when ISNULL(BKGS,0)=0 THEN 0 ELSE cast(round(GTTLDR/BKGS*KGS,2) as numeric(20,2)) END) END TTLDR "); strSql.Append(" from (SELECT "); strSql.Append("d.GID,d.BSNO,d.LINKGID,d.LINKBSNO,d.PKGS,d.KGS,d.CBM,d.TRUCKNUM,d.CTNNUM,d.NETWEIGHT"); strSql.Append(",d.CREATEUSER,d.CREATETIME "); strSql.Append(",b.TRANSSTATUS,b.CUSTNO,b.CONTRACTNO,b.ORDERNO,b.TEMPLATENAME,b.CUSTOMERNAME,b.CUSTTEL,b.CUSTATTN,b.CONSIGNEENAME,b.CONSIGNEETEL,b.CONSIGNEEATTN,b.CONSIGNEEADDR "); strSql.Append(",b.BSDATE,b.CUSTSERVICE,b.SALE,b.OP,b.ETD,b.ETA,b.PORTLOAD,b.PORTDISCHARGE,b.YARD,b.TRADETYPE,b.TRANSTYPE,b.KGS BKGS "); strSql.Append(",g.GOODSNAME,g.PKGS GPKGS,g.UNITKGS,g.NETWEIGHT GNETWEIGHT,g.KGS GKGS,g.CBM GCBM,g.UNITTYPE,g.TRUCKNUM GTRUCKNUM,g.CTNALL,g.CTNNUM GCTNNUM "); strSql.Append(",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=b.CUSTOMERNAME) AS CUSTOMERNAMEREF,b.UNITPRICE,(select TTLDR FROM v_op_gain_dr_INV_truck where BSNO=b.BSNO) GTTLDR "); strSql.Append(",(select sum(CTNNUM) from op_truck_bulk_detail where BSNO=b.BSNO) BCTNNUM "); strSql.Append(" from op_truck_bulk_pc_detail d "); strSql.Append(" left join op_truck_bulk b on (b.BSNO=d.LINKBSNO)"); strSql.Append(" left join op_truck_bulk_detail g on (g.GID=d.LINKGID)"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(") B "); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by CREATETIME "); } return SetBodyData(strSql); } private static List SetBodyData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsOpTruckBulkPcDetail data = new MsOpTruckBulkPcDetail(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.LINKGID = Convert.ToString(reader["LINKGID"]); data.LINKBSNO = Convert.ToString(reader["LINKBSNO"]); if (reader["PKGS"] != DBNull.Value) data.PKGS = Convert.ToDecimal(reader["PKGS"]); if (reader["KGS"] != DBNull.Value) data.KGS = Convert.ToDecimal(reader["KGS"]); if (reader["CBM"] != DBNull.Value) data.CBM = Convert.ToDecimal(reader["CBM"]); if (reader["TRUCKNUM"] != DBNull.Value) data.TRUCKNUM = Convert.ToDecimal(reader["TRUCKNUM"]); if (reader["CTNNUM"] != DBNull.Value) data.CTNNUM = Convert.ToInt32(reader["CTNNUM"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.TRANSSTATUS = Convert.ToString(reader["TRANSSTATUS"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]); data.ORDERNO = Convert.ToString(reader["ORDERNO"]); data.TEMPLATENAME = Convert.ToString(reader["TEMPLATENAME"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CUSTOMERNAMEREF = Convert.ToString(reader["CUSTOMERNAMEREF"]); data.CUSTTEL = Convert.ToString(reader["CUSTTEL"]); data.CUSTATTN = Convert.ToString(reader["CUSTATTN"]); data.CONSIGNEENAME = Convert.ToString(reader["CONSIGNEENAME"]); data.CONSIGNEETEL = Convert.ToString(reader["CONSIGNEETEL"]); data.CONSIGNEEATTN = Convert.ToString(reader["CONSIGNEEATTN"]); data.CONSIGNEEADDR = Convert.ToString(reader["CONSIGNEEADDR"]); if (reader["BSDATE"] != DBNull.Value) data.BSDATE = Convert.ToDateTime(reader["BSDATE"]).ToString("yyyy-MM-dd"); data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]); data.SALE = Convert.ToString(reader["SALE"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]); data.YARD = Convert.ToString(reader["YARD"]); data.TRADETYPE = Convert.ToString(reader["TRADETYPE"]); 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["UNITKGS"] != DBNull.Value) data.UNITKGS = Convert.ToDecimal(reader["UNITKGS"]); if (reader["NETWEIGHT"] != DBNull.Value) data.NETWEIGHT = Convert.ToDecimal(reader["NETWEIGHT"]); if (reader["GPKGS"] != DBNull.Value) data.GPKGS = Convert.ToDecimal(reader["GPKGS"]); if (reader["GKGS"] != DBNull.Value) data.GKGS = Convert.ToDecimal(reader["GKGS"]); if (reader["GCBM"] != DBNull.Value) data.GCBM = Convert.ToDecimal(reader["GCBM"]); if (reader["GTRUCKNUM"] != DBNull.Value) data.GTRUCKNUM = Convert.ToDecimal(reader["GTRUCKNUM"]); data.UNITTYPE = Convert.ToString(reader["UNITTYPE"]); data.CTNALL= Convert.ToString(reader["CTNALL"]); if (reader["GCTNNUM"] != DBNull.Value) data.GCTNNUM = Convert.ToInt32(reader["GCTNNUM"]); data.OP = Convert.ToString(reader["OP"]); if (reader["GNETWEIGHT"] != DBNull.Value) data.GNETWEIGHT = Convert.ToDecimal(reader["GNETWEIGHT"]); if (reader["UNITPRICE"] != DBNull.Value) data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]); if (reader["TTLDR"] != DBNull.Value) data.TTLDR = Convert.ToDecimal(reader["TTLDR"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } public static DBResult DeleteDetail(MsOpTruckBulkPc headData) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdDelete = db.GetSqlStringCommand("delete from op_truck_bulk_pc_detail where BSNO='" + headData.BSNO + "'"); 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 DeletetruckBulkDetail(MsOpTruckBulkPcDetail bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { //if (bodyList != null) //{ // foreach (var enumValue in bodyList) // { var cmdDelete = db.GetSqlStringCommand("delete from op_truck_bulk_pc_detail where GID='" + bodyList.GID + "'"); db.ExecuteNonQuery(cmdDelete, tran); // } //} var cmdUpdate = db.GetSqlStringCommand( @"update op_truck_bulk_detail set PCPKGS=isnull(PCPKGS,0)-@PKGS,PCKGS=isnull(PCKGS,0)-@KGS,PCCBM=isnull(PCCBM,0)-@CBM,PCTRUCKNUM=isnull(PCTRUCKNUM,0)-@TRUCKNUM, PCNETWEIGHT=isnull(PCNETWEIGHT,0)-@NETWEIGHT,PCCTNNUM=isnull(PCCTNNUM,0)-@CTNNUM where GID=@GID "); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, bodyList.LINKGID); db.AddInParameter(cmdUpdate, "@PKGS", DbType.Decimal, bodyList.PKGS); db.AddInParameter(cmdUpdate, "@KGS", DbType.Decimal, bodyList.KGS); db.AddInParameter(cmdUpdate, "@CBM", DbType.Decimal, bodyList.CBM); db.AddInParameter(cmdUpdate, "@TRUCKNUM", DbType.Decimal, bodyList.TRUCKNUM); db.AddInParameter(cmdUpdate, "@NETWEIGHT", DbType.Decimal, bodyList.NETWEIGHT); db.AddInParameter(cmdUpdate, "@CTNNUM", DbType.Decimal, bodyList.CTNNUM); db.ExecuteNonQuery(cmdUpdate, tran); tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "删除成功"; return result; } public static DBResult AddBill(MsOpTruckBulkPc headData, List bodyList, 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_truck_bulk_pc_detail (GID,BSNO,LINKGID,LINKBSNO,PKGS,KGS,CBM,NETWEIGHT,CREATEUSER,CREATETIME,TRUCKNUM,CTNNUM) values (@GID,@BSNO,@LINKGID,@LINKBSNO,@PKGS,@KGS,@CBM,@NETWEIGHT,@CREATEUSER,@CREATETIME,@TRUCKNUM,@CTNNUM) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_truck_bulk_detail set PCPKGS=isnull(PCPKGS,0)+@PKGS,PCKGS=isnull(PCKGS,0)+@KGS,PCCBM=isnull(PCCBM,0)+@CBM,PCNETWEIGHT=isnull(PCNETWEIGHT,0)+@NETWEIGHT ,PCTRUCKNUM=isnull(PCTRUCKNUM,0)+@TRUCKNUM,PCCTNNUM=isnull(PCCTNNUM,0)+@CTNNUM where GID=@GID "); var cmdUpdatePc = db.GetSqlStringCommand( @"update op_truck_bulk_pc set PKGS=isnull((SELECT SUM(PKGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),KGS=isnull((SELECT SUM(KGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0), CBM=isnull((SELECT SUM(CBM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),NETWEIGHT=isnull((SELECT SUM(NETWEIGHT) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) ,TRUCKNUM=isnull((SELECT SUM(TRUCKNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),CTNNUM=isnull((SELECT SUM(CTNNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0), CTNALL=@CTNALL,FREIGHT=ISNULL(UNITPRICE,0)*isnull((SELECT SUM(CTNNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) from op_truck_bulk_pc B where BSNO=@BSNO "); var BSNOSTR = ""; var CTNALL = headData.CTNALL; if (bodyList != null) { foreach (var bulk in bodyList) { if (BSNOSTR=="") BSNOSTR = BSNOSTR + " BSNO='" + bulk.BSNO + "'"; else BSNOSTR = BSNOSTR + " OR BSNO='" + bulk.BSNO + "'"; } if (BSNOSTR == "") BSNOSTR = "1=2"; var detaillist = MsOpTruckBulkDAL.MsOpTruckBulkDAL.GetBodyList(BSNOSTR); if (detaillist != null) { foreach (var enumValue in detaillist) { if (CTNALL == ""||CTNALL==null) CTNALL = enumValue.CTNALL; var pkgs = enumValue.PKGS - enumValue.PCPKGS; if (pkgs < 0) pkgs = 0; var kgs = enumValue.KGS - enumValue.PCKGS; if (kgs < 0) kgs = 0; var cbm = enumValue.CBM - enumValue.PCCBM; if (cbm < 0) cbm = 0; var trucknum = enumValue.TRUCKNUM - enumValue.PCTRUCKNUM; if (trucknum < 0) trucknum = 0; var netweight = enumValue.NETWEIGHT - enumValue.PCNETWEIGHT; if (netweight < 0) netweight = 0; var ctnnum = 0; if (headData.TRANSTYPE == "集装箱"&&CTNALL==enumValue.CTNALL) ctnnum = enumValue.CTNNUM - enumValue.PCCTNNUM; if (ctnnum < 0) ctnnum = 0; if (((headData.TRANSTYPE=="普运")&&(pkgs != 0 || kgs != 0 || cbm != 0 || trucknum !=0)) || (headData.TRANSTYPE == "集装箱" && ctnnum != 0)) { cmdInsert.Parameters.Clear(); var GID = Guid.NewGuid().ToString(); db.AddInParameter(cmdInsert, "@GID", DbType.String, GID); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, enumValue.GID); db.AddInParameter(cmdInsert, "@LINKBSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@PKGS", DbType.Decimal, pkgs); db.AddInParameter(cmdInsert, "@KGS", DbType.Decimal, kgs); db.AddInParameter(cmdInsert, "@CBM", DbType.Decimal, cbm); db.AddInParameter(cmdInsert, "@TRUCKNUM", DbType.Decimal, trucknum); db.AddInParameter(cmdInsert, "@NETWEIGHT", DbType.Decimal, netweight); db.AddInParameter(cmdInsert, "@CTNNUM", DbType.Decimal,ctnnum); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString()); db.ExecuteNonQuery(cmdInsert, tran); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@PKGS", DbType.Decimal, pkgs); db.AddInParameter(cmdUpdate, "@KGS", DbType.Decimal, kgs); db.AddInParameter(cmdUpdate, "@CBM", DbType.Decimal, cbm); db.AddInParameter(cmdUpdate, "@TRUCKNUM", DbType.Decimal,trucknum); db.AddInParameter(cmdUpdate, "@NETWEIGHT", DbType.Decimal, netweight); db.AddInParameter(cmdUpdate, "@CTNNUM", DbType.Decimal, ctnnum); db.ExecuteNonQuery(cmdUpdate, tran); } } } cmdUpdatePc.Parameters.Clear(); db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdUpdatePc, "@CTNALL", DbType.String, CTNALL); db.ExecuteNonQuery(cmdUpdatePc, tran); } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "添加成功"; return result; } public static DBResult AddDetail(MsOpTruckBulkPc headData, List bodyList, 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_truck_bulk_pc_detail (GID,BSNO,LINKGID,LINKBSNO,PKGS,KGS,CBM,NETWEIGHT,CREATEUSER,CREATETIME,TRUCKNUM,CTNNUM) values (@GID,@BSNO,@LINKGID,@LINKBSNO,@PKGS,@KGS,@CBM,@NETWEIGHT,@CREATEUSER,@CREATETIME,@TRUCKNUM,@CTNNUM) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_truck_bulk_detail set PCPKGS=isnull(PCPKGS,0)+@PKGS,PCKGS=isnull(PCKGS,0)+@KGS,PCCBM=isnull(PCCBM,0)+@CBM,PCNETWEIGHT=isnull(PCNETWEIGHT,0)+@NETWEIGHT ,PCTRUCKNUM=isnull(PCTRUCKNUM,0)+@TRUCKNUM,PCCTNNUM=isnull(PCCTNNUM,0)+@CTNNUM where GID=@GID "); var cmdUpdatePc = db.GetSqlStringCommand( @"update op_truck_bulk_pc set PKGS=isnull((SELECT SUM(PKGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),KGS=isnull((SELECT SUM(KGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0), CBM=isnull((SELECT SUM(CBM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),NETWEIGHT=isnull((SELECT SUM(NETWEIGHT) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) ,TRUCKNUM=isnull((SELECT SUM(TRUCKNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),CTNNUM=isnull((SELECT SUM(CTNNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0), CTNALL=@CTNALL,FREIGHT=ISNULL(UNITPRICE,0)*isnull((SELECT SUM(CTNNUM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) from op_truck_bulk_pc B where BSNO=@BSNO "); var CTNALL = headData.CTNALL; if (bodyList != null) { foreach (var enumValue in bodyList) { var GID = enumValue.GID; if (CTNALL == "" || CTNALL == null) CTNALL = enumValue.CTNALL; if ((headData.TRANSTYPE == "集装箱" && CTNALL == enumValue.CTNALL)||(headData.TRANSTYPE != "集装箱")){ cmdInsert.Parameters.Clear(); GID = Guid.NewGuid().ToString(); db.AddInParameter(cmdInsert, "@GID", DbType.String, GID); db.AddInParameter(cmdInsert, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, enumValue.GID); db.AddInParameter(cmdInsert, "@LINKBSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsert, "@PKGS", DbType.Decimal, enumValue.NPCPKGS); db.AddInParameter(cmdInsert, "@KGS", DbType.Decimal, enumValue.NPCKGS); db.AddInParameter(cmdInsert, "@CBM", DbType.Decimal, enumValue.NPCCBM); db.AddInParameter(cmdInsert, "@NETWEIGHT", DbType.Decimal, enumValue.NPCNETWEIGHT); db.AddInParameter(cmdInsert, "@TRUCKNUM", DbType.Decimal, enumValue.NPCTRUCKNUM); db.AddInParameter(cmdInsert, "@CTNNUM", DbType.Decimal, enumValue.NPCCTNNUM); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString()); db.ExecuteNonQuery(cmdInsert, tran); cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@PKGS", DbType.Decimal, enumValue.NPCPKGS); db.AddInParameter(cmdUpdate, "@KGS", DbType.Decimal, enumValue.NPCKGS); db.AddInParameter(cmdUpdate, "@CBM", DbType.Decimal, enumValue.NPCCBM); db.AddInParameter(cmdUpdate, "@NETWEIGHT", DbType.Decimal, enumValue.NPCNETWEIGHT); db.AddInParameter(cmdUpdate, "@TRUCKNUM", DbType.Decimal, enumValue.NPCTRUCKNUM); db.AddInParameter(cmdUpdate, "@CTNNUM", DbType.Decimal, enumValue.NPCCTNNUM); db.ExecuteNonQuery(cmdUpdate, tran); } } cmdUpdatePc.Parameters.Clear(); db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdUpdatePc, "@CTNALL", DbType.String,CTNALL); db.ExecuteNonQuery(cmdUpdatePc, tran); } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "添加成功"; return result; } public static DBResult SetFreight(MsOpTruckBulkPc headData,string userid) { var result = new DBResult(); decimal unitprice = 0; decimal freight = 0; var Templatename = headData.TEMPLATENAME; var Contractno = headData.CONTRACTNO; var feeunit = headData.FEEUNIT; var priceunit = headData.PRICEUNIT; var unittype = headData.UNITTYPE; var sql = " CUSTOMERNAME='" + headData.TRUCKER + "' and GOODNAME='" +headData.GOODSNAME + "' and TRANTYPE='普货' and BSSTATUS='审核通过' and GID IN (SELECT TEMPLATEID FROM Cust_Truck_feetemplatedetail WHERE LOADPORT='" + headData.PORTLOAD + "' and DISTPORT='" + headData.PORTDISCHARGE + "') and CONTRACTNO not in (select CONTRACTNO from info_client_contract where CANCELDATE<'" + DateTime.Now.ToString("yyyy-MM-dd") + "')"; if (Templatename == "") { var feetemplate = MsCustTruckFeeTempldateDAL.GetData(sql); Templatename = feetemplate.TEMPLATENAME; Contractno = feetemplate.CONTRACTNO; feeunit = feetemplate.FEEUNIT; priceunit = feetemplate.PRICEUNIT; } if (Templatename != "" && Contractno != ""&&Templatename!=null) { sql = " LOADPORT='" + headData.PORTLOAD + "' and DISTPORT='" + headData.PORTDISCHARGE + "' AND TEMPLATEID in (select gid from [Cust_Truck_feetemplate] where TEMPLATENAME='" + Templatename + "' and CONTRACTNO='" + Contractno + "')"; var feetemplateDetail = MsCustTruckFeeTempldateDAL.GetBodyList(sql); if (feetemplateDetail.Count != 0 && (unittype == ""|| unittype ==null)) unittype = feetemplateDetail[0].UNITTYPE; if (unittype == "车型") { if (feetemplateDetail != null && headData.TRUCKNUM != 0) { foreach (var enumValue in feetemplateDetail) { if (headData.UNIT == enumValue.UNIT) { unitprice = enumValue.UNITPRICE; freight = enumValue.UNITPRICE * headData.TRUCKNUM; } } } } else if (unittype == "吨" || unittype == "公斤") { decimal FEEKGS = 0; decimal PRICEKGS = 0; if (feeunit == "净重") FEEKGS = headData.NETWEIGHT; else FEEKGS = headData.KGS; if (priceunit == "净重") PRICEKGS = headData.NETWEIGHT; else PRICEKGS = headData.KGS; if (feetemplateDetail != null && PRICEKGS != 0) { foreach (var enumValue in feetemplateDetail) { if (PRICEKGS >= enumValue.STARTWEIGHT && PRICEKGS < enumValue.ENDWEIGHT) { unitprice = enumValue.UNITPRICE; freight = enumValue.UNITPRICE * FEEKGS; } } } } else if (unittype == "立方") { if (feetemplateDetail != null && headData.CBM != 0) { foreach (var enumValue in feetemplateDetail) { if (headData.CBM >= enumValue.STARTWEIGHT && headData.CBM < enumValue.ENDWEIGHT) { unitprice = enumValue.UNITPRICE; freight = enumValue.UNITPRICE * headData.CBM; } } } } } Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdatePc = db.GetSqlStringCommand( @"update op_truck_bulk_pc set UNITPRICE=@UNITPRICE,FREIGHT=@FREIGHT,ORUNITPRICE=@ORUNITPRICE,ORFREIGHT=@ORFREIGHT, TEMPLATENAME=@TEMPLATENAME,CONTRACTNO=@CONTRACTNO,FEEUNIT=@FEEUNIT,TTLFREIGHT=@TTLFREIGHT ,PRICEUNIT=@PRICEUNIT,UNITTYPE=@UNITTYPE from op_truck_bulk_pc B where BSNO=@BSNO "); cmdUpdatePc.Parameters.Clear(); db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdUpdatePc, "@UNITPRICE", DbType.Decimal, unitprice); db.AddInParameter(cmdUpdatePc, "@FREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.AddInParameter(cmdUpdatePc, "@ORUNITPRICE", DbType.Decimal, unitprice); db.AddInParameter(cmdUpdatePc, "@ORFREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.AddInParameter(cmdUpdatePc, "@TEMPLATENAME", DbType.String,Templatename); db.AddInParameter(cmdUpdatePc, "@CONTRACTNO", DbType.String,Contractno); db.AddInParameter(cmdUpdatePc, "@FEEUNIT", DbType.String, feeunit); db.AddInParameter(cmdUpdatePc, "@PRICEUNIT", DbType.String,priceunit); db.AddInParameter(cmdUpdatePc, "@UNITTYPE", DbType.String, unittype); db.AddInParameter(cmdUpdatePc, "@TTLFREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.ExecuteNonQuery(cmdUpdatePc, tran); tran.Commit(); result.Success = true; result.Message = "添加成功!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } public static DBResult SetCtnFreight(MsOpTruckBulkPc headData, string userid) { var result = new DBResult(); decimal unitprice = 0; decimal freight = 0; var Templatename = headData.TEMPLATENAME; var Contractno = headData.CONTRACTNO; var sql = " CUSTOMERNAME='" + headData.TRUCKER + "' and GOODNAME='" +headData.GOODSNAME + "' and TRANTYPE='集装箱' and BSSTATUS='审核通过' and GID IN (SELECT TEMPLATEID FROM Cust_Truck_feetemplatedetail WHERE LOADPORT='" + headData.PORTLOAD + "' and DISTPORT='" + headData.PORTDISCHARGE + "') and CONTRACTNO not in (select CONTRACTNO from info_client_contract where CANCELDATE<'" + DateTime.Now.ToString("yyyy-MM-dd") + "')"; if (Templatename == "") { var feetemplate = MsCustTruckFeeTempldateDAL.GetData(sql); Templatename = feetemplate.TEMPLATENAME; Contractno = feetemplate.CONTRACTNO; } if (Templatename != "" && Contractno != ""&&headData.CTNALL!="") { sql = " LOADPORT='" + headData.PORTLOAD + "' and DISTPORT='" + headData.PORTDISCHARGE + "' AND TEMPLATEID in (select gid from [Cust_Truck_feetemplate] where TEMPLATENAME='" + Templatename + "' and CONTRACTNO='" + Contractno + "')"; var feetemplateDetail = MsCustTruckFeeTempldateDAL.GetBodyList(sql); if (feetemplateDetail != null && headData.CTNNUM != 0) { foreach (var enumValue in feetemplateDetail) { if (headData.CTNALL== enumValue.UNIT) { unitprice = enumValue.UNITPRICE; freight = enumValue.UNITPRICE * headData.CTNNUM; } } } } Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdUpdatePc = db.GetSqlStringCommand( @"update op_truck_bulk_pc set UNITPRICE=@UNITPRICE,FREIGHT=@FREIGHT,ORUNITPRICE=@ORUNITPRICE,ORFREIGHT=@ORFREIGHT, TEMPLATENAME=@TEMPLATENAME,CONTRACTNO=@CONTRACTNO,TTLFREIGHT=@TTLFREIGHT from op_truck_bulk_pc B where BSNO=@BSNO "); cmdUpdatePc.Parameters.Clear(); db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdUpdatePc, "@UNITPRICE", DbType.Decimal, unitprice); db.AddInParameter(cmdUpdatePc, "@FREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.AddInParameter(cmdUpdatePc, "@ORUNITPRICE", DbType.Decimal, unitprice); db.AddInParameter(cmdUpdatePc, "@ORFREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.AddInParameter(cmdUpdatePc, "@TEMPLATENAME", DbType.String, Templatename); db.AddInParameter(cmdUpdatePc, "@CONTRACTNO", DbType.String, Contractno); db.AddInParameter(cmdUpdatePc, "@TTLFREIGHT", DbType.Decimal, Math.Round(freight, 2)); db.ExecuteNonQuery(cmdUpdatePc, tran); tran.Commit(); result.Success = true; result.Message = "添加成功!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } #region 审核和撤销审核 public static DBResult SubmitAudit(String USERID, List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.CONTRACTNO != "" && enumValue.TEMPLATENAME != "" && enumValue.UNITPRICE == enumValue.ORUNITPRICE && enumValue.FREIGHT == enumValue.ORFREIGHT) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='审核通过',AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; } else { Resultmb WorkResult = WorkFlowDAL.WorkFlowStart("OpTruckBulkPcAudit", enumValue.BSNO, USERID,enumValue.CUSTNO,enumValue.BSNO,""); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("BILLNO=@BILLNO"); if (WorkResult.islast == true) { cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='审核通过',AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO"); } else { cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='提交审核' where BSNO=@BSNO"); } cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "提交审核成功"; } else { result = new DBResult(); result.Success = false; result.Message = "提交审核错误,请检查工作流!"; } } } } //if (result.Success != false) //{ // result = new DBResult(); // result.Success = true; // result.Message = "提交审核成功"; //} tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "提交审核错误,请重试或联系系统管理员 " + e.Message; return result; } } return result; } public static DBResult SubmitAuditBack(String USERID, List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.TEMPLATENAME != "") { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='新建',AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; } else { Resultmb WorkResult = WorkFlowDAL.WorkFlowReset("OpTruckBulkPcAudit", enumValue.BSNO, USERID); if (WorkResult.Success == true) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='新建' where BSNO=@BSNO"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); result = new DBResult(); result.Success = true; result.Message = "撤销提交成功"; } else { result = new DBResult(); result.Success = false; result.Message = "不允许撤回提交!"; } } } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "撤销提交错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult AuditList(List boday, String USERID) { var result = new DBResult(); var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); result.Success = true; result.Message = "审核通过"; using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var errmsg = ""; if (boday != null) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='审核通过',AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO"); var cmdupdate2 = db.GetSqlStringCommand("update op_truck_bulk_pc set AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO"); foreach (var enumValue in boday) { Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("OpTruckBulkPcAudit", enumValue.BSNO, USERID, tran,enumValue.CUSTNO); if (WorkResult.Success == true) { if (WorkResult.islast == true) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); headList.Add(enumValue); } else { cmdupdate2.Parameters.Clear(); db.AddInParameter(cmdupdate2, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate2, tran); } result.Success = true; result.Data = headList; result.Message = "审核通过"; } else { result.Success = false; result.Message = "没有权限审核"; } } } // result = new DBResult(); tran.Commit(); return result; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "审核出现错误,请重试或联系系统管理员"; return result; } } return result; } public static DBResult AuditBackList(List boday, String USERID, string reason) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (boday != null) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS='驳回提交',AUDITUSER='',AUDITTIME=null,REASON='" + reason + "' where BSNO=@BSNO"); foreach (var enumValue in boday) { if (enumValue.TRANSSTATUS == "提交审核" || enumValue.TRANSSTATUS == "审核通过") { if (enumValue.TEMPLATENAME != ""&& enumValue.CONTRACTNO != "" && enumValue.UNITPRICE == enumValue.ORUNITPRICE && enumValue.FREIGHT == enumValue.ORFREIGHT) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); } else { Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("OpTruckBulkPcAudit", enumValue.BSNO, USERID, reason, enumValue.BSNO, enumValue.BSNO, "驳回提交URL"); if (WorkResult.Success == true) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); db.ExecuteNonQuery(cmdupdate, tran); } } } } } result = new DBResult(); result.Success = true; result.Message = "完成驳回"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "驳回出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "完成驳回"; return result; } public static DBResult CreateFeeBl(MsOpTruckBulkPc headData, string userid) { var result = new DBResult(); var OP = SysUserDAL.GetData(" SHOWNAME='" + headData.OP + "'"); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsertFee = 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,CARGO_GID, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC) VALUES(@GID,@BSNO,@FEETYPE,@FEENAME,@FEEDESCRIPTION,@CUSTOMERTYPE,@CUSTOMERNAME,@UNIT,@UNITPRICE,@QUANTITY,@AMOUNT,@CURRENCY, @EXCHANGERATE, @REASON, @REMARK, @COMMISSIONRATE,@ENTEROPERATOR, @ENTERDATE,@ISOPEN, @ISADVANCEDPAY, @SORT, @FEESTATUS, @FEEFRT,@CARGO_GID, @TAXRATE,@NOTAXAMOUNT,@ACCTAXRATE,@LINENUM,@TAXUNITPRICE,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@ISINVOICE,@INPUTMODE,@LOCALCURR,@MANAGER,@ISACC) "); string sqlLb = "select ISFEE from op_truck_bulk_pc where bsno = '" + headData.BSNO + "'"; string ISFEE = db.ExecuteScalar(CommandType.Text, sqlLb).ToString(); if (ISFEE != null&&ISFEE != "1") { decimal kgs = 0; if (headData.FEEUNIT == "净重") kgs = headData.NETWEIGHT; else kgs = headData.KGS; cmdInsertFee.Parameters.Clear(); db.AddInParameter(cmdInsertFee, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsertFee, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdInsertFee, "@FEETYPE", DbType.Int16, 2); db.AddInParameter(cmdInsertFee, "@FEENAME", DbType.String, "陆运费"); db.AddInParameter(cmdInsertFee, "@FEEDESCRIPTION", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@CUSTOMERTYPE", DbType.String, "车队"); db.AddInParameter(cmdInsertFee, "@CUSTOMERNAME", DbType.String, headData.TRUCKER); if (headData.TRANSTYPE == "集装箱") { db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, headData.CTNALL); } else db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, headData.UNITTYPE); db.AddInParameter(cmdInsertFee, "@UNITPRICE", DbType.Decimal, headData.UNITPRICE); if (headData.TRANSTYPE == "集装箱") { db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal,headData.CTNNUM); } else { if (headData.UNITTYPE == "吨" || headData.UNITTYPE == "公斤") db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, kgs); else if (headData.UNITTYPE == "立方") db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, headData.CBM); else if (headData.UNITTYPE == "车型") db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, headData.TRUCKNUM); else db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, 1); } db.AddInParameter(cmdInsertFee, "@AMOUNT", DbType.Decimal, headData.TTLFREIGHT); db.AddInParameter(cmdInsertFee, "@CURRENCY", DbType.String, "RMB"); db.AddInParameter(cmdInsertFee, "@EXCHANGERATE", DbType.Decimal, 1); db.AddInParameter(cmdInsertFee, "@REASON", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@REMARK", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@COMMISSIONRATE", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@ENTEROPERATOR", DbType.String, OP.GID); db.AddInParameter(cmdInsertFee, "@ENTERDATE", DbType.String, DateTime.Now.ToString()); db.AddInParameter(cmdInsertFee, "@ISOPEN", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@ISADVANCEDPAY", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@SORT", DbType.Int16, 1); db.AddInParameter(cmdInsertFee, "@FEESTATUS", DbType.Int16, 0); db.AddInParameter(cmdInsertFee, "@FEEFRT", DbType.String, "PP"); db.AddInParameter(cmdInsertFee, "@CARGO_GID", DbType.String, headData.BSNO); db.AddInParameter(cmdInsertFee, "@TAXRATE", DbType.Decimal, headData.TAXRATE); db.AddInParameter(cmdInsertFee, "@NOTAXAMOUNT", DbType.Decimal, headData.FREIGHT); db.AddInParameter(cmdInsertFee, "@ACCTAXRATE", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@LINENUM", DbType.Int16, 1); db.AddInParameter(cmdInsertFee, "@TAXUNITPRICE", DbType.Decimal, headData.UNITPRICE); db.AddInParameter(cmdInsertFee, "@MODIFIEDUSER", DbType.String, OP.GID); db.AddInParameter(cmdInsertFee, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString()); db.AddInParameter(cmdInsertFee, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@PREAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsertFee, "@ISINVOICE", DbType.Boolean, false); db.AddInParameter(cmdInsertFee, "@INPUTMODE", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@LOCALCURR", DbType.String, "RMB"); db.AddInParameter(cmdInsertFee, "@MANAGER", DbType.String, ""); db.AddInParameter(cmdInsertFee, "@ISACC", DbType.Boolean, false); db.ExecuteNonQuery(cmdInsertFee, tran); var cmdUpdateBL = db.GetSqlStringCommand( @"update op_truck_bulk_pc set ISFEE='1' where BSNO=@BSNO "); cmdUpdateBL.Parameters.Clear(); db.AddInParameter(cmdUpdateBL, "@BSNO", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmdUpdateBL, tran); } else { var cmdUpdateBL = db.GetSqlStringCommand( @"update op_truck_bulk_pc set ISFEE='0' where BSNO=@BSNO "); cmdUpdateBL.Parameters.Clear(); db.AddInParameter(cmdUpdateBL, "@BSNO", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmdUpdateBL, tran); } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "生成费用出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "生成成功"; return result; } public static DBResult DelCreateFeeBl(MsOpTruckBulkPc headData, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (headData.ISFEE == "1") { var cmdDelFee = db.GetSqlStringCommand( @"delete from ch_fee where BSNO=@BSNO and CARGO_GID=@CARGO_GID "); cmdDelFee.Parameters.Clear(); db.AddInParameter(cmdDelFee, "@BSNO", DbType.String, headData.BSNO); db.AddInParameter(cmdDelFee, "@CARGO_GID", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmdDelFee, tran); var cmdUpdateBL = db.GetSqlStringCommand( @"update op_truck_bulk_pc set ISFEE='0' where BSNO=@BSNO "); cmdUpdateBL.Parameters.Clear(); db.AddInParameter(cmdUpdateBL, "@BSNO", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmdUpdateBL, tran); } tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "生成费用出现错误,请重试或联系系统管理员" + e.Message; return result; } } result.Success = true; result.Message = "生成成功"; return result; } public static bool GetFeeCount(string BSNO, string condition = "") { var isfee = false; String strSql = "Select count(*) as count from ch_fee where BSNO='" + BSNO + "'"; if (condition != "") strSql = strSql + " and " + condition; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } #endregion public static int p_update_status(string bsno) { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_update_truck_bulk"); db.AddInParameter(cmd, "@con_no", DbType.String, bsno); db.ExecuteNonQuery(cmd); return 0; } public static int p_update_pc(string bsno) { Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetStoredProcCommand("p_update_truck_bulk_pc"); db.AddInParameter(cmd, "@con_no", DbType.String, bsno); db.ExecuteNonQuery(cmd); return 0; } #endregion #region 状态操作 public static DBResult UpTransStatus(List boday, string status,string statusdate,string arriverremark="") { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var errmsg = ""; if (boday != null) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS=@TRANSSTATUS where BSNO=@BSNO"); if (status== "已到货") cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS=@TRANSSTATUS,ARRIVEDATE=@STATUSDATE,ARRIVEREMARK=ISNULL(ARRIVEREMARK,'')+@ARRIVEREMARK where BSNO=@BSNO"); else if (status == "已回单") cmdupdate = db.GetSqlStringCommand("update op_truck_bulk_pc set TRANSSTATUS=@TRANSSTATUS,RETURNDOCDATE=@STATUSDATE,ARRIVEREMARK=ISNULL(ARRIVEREMARK,'')+@ARRIVEREMARK,ETA=@ETA where BSNO=@BSNO"); foreach (var enumValue in boday) { cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@TRANSSTATUS", DbType.String, status); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, enumValue.BSNO); if (status == "已到货"|| status == "已回单") db.AddInParameter(cmdupdate, "@STATUSDATE", DbType.String, statusdate); if (status == "已到货") db.AddInParameter(cmdupdate, "@ARRIVEREMARK", DbType.String,"到货异常:"+arriverremark); if (status == "已回单") { db.AddInParameter(cmdupdate, "@ARRIVEREMARK", DbType.String, "回单异常:" + arriverremark); db.AddInParameter(cmdupdate, "@ETA", DbType.String, statusdate); } db.ExecuteNonQuery(cmdupdate, tran); } } result = new DBResult(); result.Success = true; result.Message = "更新完成"; tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"+e.Message; return result; } } return result; } public static DBResult UphuidanStatus(string bsno) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var isnot = true; var op_bulkList = MsOpTruckBulkDAL.MsOpTruckBulkDAL.GetBodyList("BSNO='"+bsno+"'"); foreach (var op_bulk in op_bulkList) { var pkgs = op_bulk.PKGS - op_bulk.PCPKGS; if (pkgs < 0) pkgs = 0; var kgs = op_bulk.KGS - op_bulk.PCKGS; if (kgs < 0) kgs = 0; var cbm = op_bulk.CBM - op_bulk.PCCBM; if (cbm < 0) cbm = 0; var trucknum = op_bulk.TRUCKNUM - op_bulk.PCTRUCKNUM; if (trucknum < 0) trucknum = 0; var netweight = op_bulk.NETWEIGHT - op_bulk.PCNETWEIGHT; if (netweight < 0) netweight = 0; var ctnnum = 0; ctnnum = op_bulk.CTNNUM - op_bulk.PCCTNNUM; if (ctnnum < 0) ctnnum = 0; if (pkgs != 0 || kgs != 0 || cbm != 0 || trucknum != 0||ctnnum != 0) { isnot = false; } } if (isnot) { var cmdupdate = db.GetSqlStringCommand("update op_truck_bulk set transstatus='已回单' where bsno in (select linkbsno from op_truck_bulk_pc_detail where bsno =@BSNO) And bsno not in (select linkbsno from op_truck_bulk_pc_detail d left join op_truck_bulk_pc p on d.bsno = p.bsno where p.transstatus <> '已回单')"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@BSNO", DbType.String, bsno); db.ExecuteNonQuery(cmdupdate, tran); } result = new DBResult(); result.Success = true; result.Message = "更新完成"; tran.Commit(); } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"; return result; } } return result; } #endregion #region 判断编码是否有重复 static public int GetRdCount(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" Count(BSNO) AS CT "); strSql.Append(" from op_truck_bulk_pc "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var ct=0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ct = Convert.ToInt16(reader["CT"]); } reader.Close(); } return ct; } #endregion #region 判断是否有FEE public static bool GetFeeCount(string BSNO) { var isfee = false; String strSql = "Select count(*) as count from ch_fee where BSNO='" + BSNO + "'"; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql)) { while (reader.Read()) { var evData = Convert.ToInt32(reader["count"]); if (evData > 0) { isfee = true; }; } reader.Close(); } return isfee; } #endregion #region 委托业务费用加锁 /// /// 委托业务费用加锁 /// /// 委托业务编号 /// 值等于1表示加锁成功 值不等于1表示加锁失败 public static int LockFeeStatus(string tempBSNO) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@BSNO",SqlDbType.VarChar,100) }; parms[0].Value = tempBSNO; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "UPDATE op_truck_bulk SET FEESTATUS = 1 WHERE BSNO = @BSNO", parms); sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } #endregion #region 委托业务费用解锁 /// /// 委托业务费用解锁 /// /// 委托业务编号 /// 值等于1表示解锁成功 值不等于1表示解锁失败 public static int UnLockFeeStatus(string tempBSNO) { int iResult = 0; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@BSNO",SqlDbType.VarChar,100) }; parms[0].Value = tempBSNO; SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, "UPDATE op_truck_bulk SET FEESTATUS =0 WHERE BSNO = @BSNO", parms); sqlTran.Commit(); iResult = 1;//状态为1表示更新成功 } catch (Exception execError) { iResult = -1;//有异常,更新失败 sqlTran.Rollback(); iResult = -2;//更新异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return iResult; } #endregion #region Rang权限范围 public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT"); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL "); strSql.Append(" from VW_User_Authority"); strSql.Append(" where [NAME]='modOpTruckBulkPcList' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; string VSSQL = ""; 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"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); VSSQL = Convert.ToString(reader["VSSQL"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (op_truck_bulk_pc.OP='" + username + "' OR op_truck_bulk_pc.CREATEUSER='" + userid + "' OR op_truck_bulk_pc.DDOP='" + username + "')"; } else if (visiblerange == "3") { str = " (op_truck_bulk_pc.OP='" + username + "' OR op_truck_bulk_pc.CREATEUSER='" + userid + "' OR op_truck_bulk_pc.DDOP='" + username + "')"; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (op_truck_bulk_pc.OP in (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 + "'))" + " OR op_truck_bulk_pc.CREATEUSER in (select GID from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))"; } else if (visiblerange == "1") { str = " (op_truck_bulk_pc.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))" + " OR op_truck_bulk_pc.CREATEUSER in (select USERID from user_company where COMPANYID='" + companyid + "'))"; } else if (visiblerange == "5") { if (tb == "index") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (op_truck_bulk_pc.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' "; } else { str = str + " or op_truck_bulk_pc.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' "; }; } str = str + ")"; reader.Close(); } } else { str = " (UPPER(op_truck_bulk_pc.Corpid)='" + companyid + "') "; } } else if (visiblerange == "6") { if (tb == "index") { var opstr = ""; var opidstr = ""; var userstr = new StringBuilder(); userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { while (reader.Read()) { if (opstr == "") { opstr = " ('" + Convert.ToString(reader["SHOWNAME"]) + "'"; } else { opstr = opstr + ",'" + Convert.ToString(reader["SHOWNAME"]) + "'"; }; if (opidstr == "") { opidstr = " ('" + Convert.ToString(reader["OPID"]) + "'"; } else { opidstr = opidstr + ",'" + Convert.ToString(reader["OPID"]) + "'"; }; } if (opstr != "") opstr = opstr + ")"; if (opidstr != "") opidstr = opidstr + ")"; reader.Close(); } if (opstr == "") opstr = "('" + username + "')"; str = " (op_truck_bulk_pc.OP in " + opstr + " or op_truck_bulk_pc.DDOP in " + opstr + " or op_truck_bulk_pc.CREATEUSER IN " + opidstr + " )"; } else { str = " (UPPER(op_truck_bulk_pc.Corpid)='" + companyid + "' ) "; } } else if (visiblerange == "0") { str = " 1=1 "; } return str; } #endregion } }