using System ;
using System.Data ;
using System.Data.Common ;
using System.Collections.Generic ;
using System.Text ;
using DSWeb.TruckMng.Models.MsOpTruckBulk ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
using DSWeb.EntityDA ;
using DSWeb.Areas.CommMng.Models ;
using HcUtility.Comm ;
using HcUtility.Core ;
using System.Data.SqlClient ;
using DSWeb.DataAccess ;
using DSWeb.Areas.CommMng.DAL ;
using System.Web ;
using DSWeb.MvcShipping.DAL.MsInfoClient ;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet ;
using DSWeb.TruckMng.DAL.MsCustTruckFeeTemplate ;
using DSWeb.MvcShipping.DAL.MsCodeOpMustField ;
using DSWeb.MvcShipping.Models.MsInfoClient ;
namespace DSWeb.TruckMng.DAL.MsOpTruckBulkDAL
{
public class MsOpTruckBulkDAL
{
#region Inquery DataList
static public List < MsOpTruckBulk > 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,CUSTNO" ) ;
}
strSql . Append ( @") as num , " ) ;
/ /
strSql . Append ( " op_truck_bulk.BSNO,op_truck_bulk.BSNO PARENTID, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF" ) ;
strSql . Append ( " ,TRANSSTATUS,[CUSTNO],[ORDERNO],[CONTRACTNO],TEMPLATENAME,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]" ) ;
strSql . Append ( " ,[BSSOURCEDETAIL],[OP],DDOP,[CUSTSERVICE],[SALE],[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[TRADETYPE],[GOODSNAME],[KGS],[NETWEIGHT],[PKGS],[KINDPKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK]" ) ;
strSql . Append ( " ,(select top 1 showname from [user] where GID=op_truck_bulk.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk.MODIFIEDUSER) as MODIFIEDUSER, " ) ;
strSql . Append ( " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLYFDR,I.TTLOTDR " ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCKGS" ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCPKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCPKGS" ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCCBM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCBM" ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCNETWEIGHT) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCNETWEIGHT" ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCTRUCKNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCTRUCKNUM" ) ;
strSql . Append ( ",ISNULL((SELECT SUM(PCCTNNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCTNNUM" ) ;
strSql . Append ( ",stuff((SELECT distinct t.CTNALL + '*' + convert(varchar,t.CTNNUM-t.PCCTNNUM)+ '/' FROM op_truck_bulk_detail t WHERE t.BSNO = op_truck_bulk.BSNO FOR xml path('')), 1, 0, '') NOPCCNTRTOTAL" ) ;
strSql . Append ( ",UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,ORUNITPRICE,ORFREIGHT,TRANSTYPE,MBLNO,YARD,CLOSINGDATE,CNTRTOTAL,ORDERNO1" ) ;
strSql . Append ( ",ISNULL((SELECT COUNT(*) FROM op_truck_bulk_detail d WHERE d.BSNO=op_truck_bulk.BSNO AND (d.ORUNITPRICE<>d.UNITPRICE or d.ORFREIGHT<>d.FREIGHT) ),0) AS NOFEECOUNT " ) ;
strSql . Append ( ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk.CUSTOMERNAME) AS CUSTOMERNAMEREF " ) ;
strSql . Append ( ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk.SALECORPID) as SALECORP,op_truck_bulk.BillFeeStatus FROM op_truck_bulk" ) ;
strSql . Append ( " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk.BSNO) " ) ;
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 ) ) ; / /
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 " ) ;
strSql . Append ( " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk.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 List < MsOpTruckBulk > 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.BSNO,op_truck_bulk.BSNO PARENTID, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF" ;
strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[ORDERNO],[CONTRACTNO],TEMPLATENAME,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]" ;
strSql = strSql + " ,[BSSOURCEDETAIL],op_truck_bulk.OP,DDOP,[CUSTSERVICE],[SALE],[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[TRADETYPE],[GOODSNAME],[KGS],[NETWEIGHT],[PKGS],[KINDPKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK]" ;
strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk.CREATEUSER) as CREATEUSER, op_truck_bulk.CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk.MODIFIEDUSER) as MODIFIEDUSER, " ;
strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLYFDR,I.TTLOTDR " ;
strSql = strSql + ",ISNULL((SELECT SUM(PCKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCPKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCPKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCBM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCBM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCTRUCKNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCTRUCKNUM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCNETWEIGHT) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCNETWEIGHT" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCTNNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCTNNUM" ;
strSql = strSql + ",CNTRTOTAL NOPCCNTRTOTAL" ;
strSql = strSql + ",UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,ORUNITPRICE,ORFREIGHT,TRANSTYPE,MBLNO,YARD,CLOSINGDATE,CNTRTOTAL,ORDERNO1" ;
strSql = strSql + ",ISNULL((SELECT COUNT(*) FROM op_truck_bulk_detail d WHERE d.BSNO=op_truck_bulk.BSNO AND (d.ORUNITPRICE<>d.UNITPRICE or d.ORFREIGHT<>d.FREIGHT) ),0) AS NOFEECOUNT " ;
strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk.CUSTOMERNAME) AS CUSTOMERNAMEREF " ;
strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk.SALECORPID) as SALECORP,op_truck_bulk.BillFeeStatus FROM op_truck_bulk" ;
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk.BSNO) " ;
strSql = strSql + " left join workflow_using wu on wu.bsno=op_truck_bulk.bsno where 1=1 " ;
if ( isaudit = = "3" )
strSql = strSql + " and dbo.[GetUsingStep](wu.WORKFLOWID,wu.currentid,'" + userid + "',wu.stepno)>0 " ;
else if ( isaudit = = "2" )
{
strSql = strSql + " and op_truck_bulk.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.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 ) ;
}
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.BSNO,op_truck_bulk.BSNO PARENTID, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF" ;
strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[ORDERNO],[CONTRACTNO],TEMPLATENAME,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]" ;
strSql = strSql + " ,[BSSOURCEDETAIL],[OP],DDOP,[CUSTSERVICE],[SALE],[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[TRADETYPE],[GOODSNAME],[KGS],[NETWEIGHT],[PKGS],[KINDPKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK]" ;
strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk.MODIFIEDUSER) as MODIFIEDUSER, " ;
strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLYFDR,I.TTLOTDR " ;
strSql = strSql + ",ISNULL((SELECT SUM(PCKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCPKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCPKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCBM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCBM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCTRUCKNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCTRUCKNUM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCNETWEIGHT) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCNETWEIGHT" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCTNNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCTNNUM" ;
strSql = strSql + ",stuff((SELECT distinct t.CTNALL + '*' + convert(varchar,t.CTNNUM-t.PCCTNNUM)+ '/' FROM op_truck_bulk_detail t WHERE t.BSNO = op_truck_bulk.BSNO FOR xml path('')), 1, 0, '') NOPCCNTRTOTAL" ;
strSql = strSql + ",UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,ORUNITPRICE,ORFREIGHT,TRANSTYPE,MBLNO,YARD,CLOSINGDATE,CNTRTOTAL,ORDERNO1" ;
strSql = strSql + ",ISNULL((SELECT COUNT(*) FROM op_truck_bulk_detail d WHERE d.BSNO=op_truck_bulk.BSNO AND (d.ORUNITPRICE<>d.UNITPRICE or d.ORFREIGHT<>d.FREIGHT) ),0) AS NOFEECOUNT " ;
strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk.CUSTOMERNAME) AS CUSTOMERNAMEREF " ;
strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk.SALECORPID) as SALECORP,op_truck_bulk.BillFeeStatus FROM op_truck_bulk" ;
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk.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 MsOpTruckBulk GetData ( string condition )
{
String strSql = "SELECT op_truck_bulk.BSNO,op_truck_bulk.BSNO PARENTID, BSSTATUS, FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF" ;
strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[ORDERNO],[CONTRACTNO],TEMPLATENAME,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],[ACCDATE] ,[BSSOURCE]" ;
strSql = strSql + " ,[BSSOURCEDETAIL],[OP],DDOP,[CUSTSERVICE],[SALE],[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[TRADETYPE],[GOODSNAME],[KGS],[NETWEIGHT],[PKGS],[KINDPKGS],[CBM],TRUCKNUM,[ISVOU],[VOUNO],[REMARK]" ;
strSql = strSql + " ,(select top 1 showname from [user] where GID=op_truck_bulk.CREATEUSER) as CREATEUSER, CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk.MODIFIEDUSER) as MODIFIEDUSER, " ;
strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(op_truck_bulk.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_truck_bulk.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLYFDR,I.TTLOTDR " ;
strSql = strSql + ",ISNULL((SELECT SUM(PCKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCPKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCPKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCBM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCBM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCTRUCKNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCTRUCKNUM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCNETWEIGHT) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCNETWEIGHT" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCTNNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCTNNUM" ;
strSql = strSql + ",CNTRTOTAL NOPCCNTRTOTAL" ;
strSql = strSql + ",UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,ORUNITPRICE,ORFREIGHT,TRANSTYPE,MBLNO,YARD,CLOSINGDATE,CNTRTOTAL,ORDERNO1" ;
strSql = strSql + ",0 AS NOFEECOUNT " ;
strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk.CUSTOMERNAME) AS CUSTOMERNAMEREF " ;
strSql = strSql + ",SALECORPID,(select [NAME] from [company] where GID=op_truck_bulk.SALECORPID) as SALECORP,op_truck_bulk.BillFeeStatus FROM op_truck_bulk" ;
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=op_truck_bulk.BSNO) " ;
if ( ! string . IsNullOrEmpty ( condition ) )
{
strSql + = " where " + condition ;
}
var list = SetData ( strSql ) ;
if ( list . Count > 0 )
{
return list [ 0 ] ;
}
return new MsOpTruckBulk ( ) ;
}
static public List < MsOpTruckBulk > GetAmendDataList ( 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 A.BSNO,A.PARENTID, BSSTATUS, A.FEESTATUS, (CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF, (CASE A.FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF" ;
strSql = strSql + " ,TRANSSTATUS,[CUSTNO],[ORDERNO],[CONTRACTNO],TEMPLATENAME,[CUSTOMERNAME],[CUSTTEL],[CUSTATTN],[CONSIGNEENAME],[CONSIGNEETEL],[CONSIGNEEATTN],[CONSIGNEEADDR],[BSDATE],A.ACCDATE ,[BSSOURCE]" ;
strSql = strSql + " ,[BSSOURCEDETAIL],[OP],DDOP,[CUSTSERVICE],A.[SALE],[CORPID],[ETD],ETA,[PORTLOAD],[PORTDISCHARGE],[TRADETYPE],[GOODSNAME],[KGS],[NETWEIGHT],[PKGS],[KINDPKGS],[CBM],TRUCKNUM,A.ISVOU,A.VOUNO,A.REMARKS REMARK" ;
strSql = strSql + " ,A.CREATEUSER, A.CREATETIME, (select top 1 showname from [user] where GID=op_truck_bulk.MODIFIEDUSER) as MODIFIEDUSER, " ;
strSql = strSql + " MODIFIEDTIME,STLNAME,STLDATE,dbo.F_GetBillDrFeeStatus(A.BSNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(A.BSNO) CRFEESTATUS,ISPRINTPR,I.TTLDR,I.TTLINVDR,I.TTLYFDR,I.TTLOTDR " ;
strSql = strSql + ",ISNULL((SELECT SUM(PCKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCPKGS) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCPKGS" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCBM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCBM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCTRUCKNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCTRUCKNUM" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCNETWEIGHT) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCNETWEIGHT" ;
strSql = strSql + ",ISNULL((SELECT SUM(PCCTNNUM) from op_truck_bulk_detail where BSNO=op_truck_bulk.BSNO),0) PCCTNNUM" ;
strSql = strSql + ",CNTRTOTAL NOPCCNTRTOTAL" ;
strSql = strSql + ",UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE,FEEUNIT,PRICEUNIT,ORUNITPRICE,ORFREIGHT,TRANSTYPE,MBLNO,YARD,CLOSINGDATE,CNTRTOTAL,ORDERNO1" ;
strSql = strSql + ",0 AS NOFEECOUNT " ;
strSql = strSql + ",(SELECT DESCRIPTION FROM info_client WHERE SHORTNAME=op_truck_bulk.CUSTOMERNAME) AS CUSTOMERNAMEREF " ;
strSql = strSql + ",A.AMENDNO SALECORPID,A.REASON SALECORP,op_truck_bulk.BillFeeStatus FROM op_amend A" ;
strSql = strSql + " LEFT JOIN op_truck_bulk ON (op_truck_bulk.BSNO=A.PARENTID)" ;
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV_truck I ON (I.BSNO=A.BSNO) " ;
strSql = strSql + " where A.BSNO IS NOT NULL AND op_truck_bulk.BSNO IS NOT NULL " ;
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 < MsOpTruckBulk > SetData ( String strSql )
{
var headList = new List < MsOpTruckBulk > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
MsOpTruckBulk data = new MsOpTruckBulk ( ) ;
#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 . PARENTID = Convert . ToString ( reader [ "PARENTID" ] ) ;
if ( reader [ "BSSTATUS" ] ! = DBNull . Value )
data . BSSTATUS = Convert . ToBoolean ( reader [ "BSSTATUS" ] ) ;
if ( reader [ "FEESTATUS" ] ! = DBNull . Value )
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 . ORDERNO = Convert . ToString ( reader [ "ORDERNO" ] ) ;
data . ORDERNO1 = Convert . ToString ( reader [ "ORDERNO1" ] ) ;
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 . 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 [ "CREATETIME" ] ! = DBNull . Value )
data . CREATETIME = Convert . ToDateTime ( reader [ "CREATETIME" ] ) . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
//if (reader["BSDATE"] != DBNull.Value)
// data.BSDATE = Convert.ToDateTime(reader["BSDATE"]);
data . ACCDATE = Convert . ToString ( reader [ "ACCDATE" ] ) ;
data . BSSOURCE = Convert . ToString ( reader [ "BSSOURCE" ] ) ;
data . BSSOURCEDETAIL = Convert . ToString ( reader [ "BSSOURCEDETAIL" ] ) ;
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" ] ) ;
//if (reader["ETD"] != DBNull.Value)
// data.ETD = Convert.ToDateTime(reader["ETD"]);
data . PORTLOAD = Convert . ToString ( reader [ "PORTLOAD" ] ) ;
data . PORTDISCHARGE = Convert . ToString ( reader [ "PORTDISCHARGE" ] ) ;
data . TRADETYPE = Convert . ToString ( reader [ "TRADETYPE" ] ) ;
data . GOODSNAME = Convert . ToString ( reader [ "GOODSNAME" ] ) ;
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" ] ) ;
data . KINDPKGS = Convert . ToString ( reader [ "KINDPKGS" ] ) ;
if ( reader [ "CBM" ] ! = DBNull . Value )
data . CBM = Convert . ToDecimal ( reader [ "CBM" ] ) ;
if ( reader [ "TRUCKNUM" ] ! = DBNull . Value )
data . TRUCKNUM = Convert . ToInt32 ( reader [ "TRUCKNUM" ] ) ;
data . CNTRTOTAL = Convert . ToString ( reader [ "CNTRTOTAL" ] ) ;
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" ] ) ;
data . MODIFIEDUSER = Convert . ToString ( reader [ "MODIFIEDUSER" ] ) ;
if ( reader [ "MODIFIEDTIME" ] ! = DBNull . Value )
data . MODIFIEDTIME = Convert . ToDateTime ( reader [ "MODIFIEDTIME" ] ) ;
data . ORDERNO = Convert . ToString ( reader [ "ORDERNO" ] ) ;
data . STLNAME = Convert . ToString ( reader [ "STLNAME" ] ) ;
data . STLDATE = Convert . ToString ( reader [ "STLDATE" ] ) ;
data . ISPRINTPR = Convert . ToString ( reader [ "ISPRINTPR" ] ) ;
decimal ttldr = 0 ;
if ( reader [ "TTLDR" ] ! = DBNull . Value )
ttldr = Convert . ToDecimal ( reader [ "TTLDR" ] ) ;
decimal ttlinvdr = 0 ;
if ( reader [ "TTLDR" ] ! = DBNull . Value )
ttlinvdr = Convert . ToDecimal ( reader [ "TTLINVDR" ] ) ;
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 [ "TTLDR" ] ! = DBNull . Value )
data . TTLDR = Math . Round ( Convert . ToDecimal ( reader [ "TTLDR" ] ) , 2 ) . ToString ( ) ;
if ( reader [ "TTLYFDR" ] ! = DBNull . Value )
data . TTLYFDR = Math . Round ( Convert . ToDecimal ( reader [ "TTLYFDR" ] ) , 2 ) . ToString ( ) ;
if ( reader [ "TTLOTDR" ] ! = DBNull . Value )
data . TTLOTDR = Math . Round ( Convert . ToDecimal ( reader [ "TTLOTDR" ] ) , 2 ) . ToString ( ) ;
if ( reader [ "PCKGS" ] ! = DBNull . Value )
data . PCKGS = Math . Round ( Convert . ToDecimal ( reader [ "PCKGS" ] ) , 6 ) ;
if ( reader [ "PCPKGS" ] ! = DBNull . Value )
data . PCPKGS = Convert . ToInt32 ( reader [ "PCPKGS" ] ) ;
if ( reader [ "PCCBM" ] ! = DBNull . Value )
data . PCCBM = Math . Round ( Convert . ToDecimal ( reader [ "PCCBM" ] ) , 2 ) ;
if ( reader [ "PCTRUCKNUM" ] ! = DBNull . Value )
data . PCTRUCKNUM = Convert . ToDecimal ( reader [ "PCTRUCKNUM" ] ) ;
if ( reader [ "PCNETWEIGHT" ] ! = DBNull . Value )
data . PCNETWEIGHT = Convert . ToDecimal ( reader [ "PCNETWEIGHT" ] ) ;
if ( reader [ "PCCTNNUM" ] ! = DBNull . Value )
data . PCCTNNUM = Convert . ToInt32 ( reader [ "PCCTNNUM" ] ) ;
data . NOPCKGS = data . KGS - data . PCKGS ;
data . NOPCPKGS = data . PKGS - data . PCPKGS ;
data . NOPCCBM = data . CBM - data . PCCBM ;
data . NOPCTRUCKNUM = data . TRUCKNUM - data . PCTRUCKNUM ;
data . NOPCNETWEIGHT = data . NETWEIGHT - data . PCNETWEIGHT ;
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" ] ) ;
data . TRANSTYPE = Convert . ToString ( reader [ "TRANSTYPE" ] ) ;
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 . FREIGHT ) + Convert . ToDecimal ( data . TTLOTDR ) ) , 2 ) . ToString ( ) ;
}
if ( data . TRANSTYPE = = "集装箱" )
{
var NOFEECOUNT = 0 ;
if ( reader [ "NOFEECOUNT" ] ! = DBNull . Value )
NOFEECOUNT = Convert . ToInt32 ( reader [ "NOFEECOUNT" ] ) ;
if ( data . CONTRACTNO ! = "" & & data . TEMPLATENAME ! = "" & & NOFEECOUNT = = 0 )
data . ISAUTOFEE = "否" ;
}
else
{
if ( data . CONTRACTNO ! = "" & & data . TEMPLATENAME ! = "" & & data . UNITPRICE = = data . ORUNITPRICE & & data . FREIGHT = = data . ORFREIGHT )
data . ISAUTOFEE = "否" ;
}
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" ) ;
data . NOPCCNTRTOTAL = Convert . ToString ( reader [ "NOPCCNTRTOTAL" ] ) ;
# 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 "部分提交" ;
}
return result ;
}
public static DBResult CreateFeeBl ( MsOpTruckBulk headData , string userid )
{
var result = new DBResult ( ) ;
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 )
");
if ( headData . 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 , 1 ) ;
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 . CUSTOMERNAME ) ;
db . AddInParameter ( cmdInsertFee , "@UNIT" , DbType . String , headData . UNITTYPE ) ;
db . AddInParameter ( cmdInsertFee , "@UNITPRICE" , DbType . Decimal , headData . UNITPRICE ) ;
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 db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertFee , "@AMOUNT" , DbType . Decimal , headData . FREIGHT ) ;
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 , userid ) ;
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 , 0 ) ;
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 , userid ) ;
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 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 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 CreateCtnFeeBl ( MsOpTruckBulk headData , List < MsOpTruckBulkDetail > bodyList , string userid )
{
var result = new DBResult ( ) ;
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 )
");
if ( headData . ISFEE ! = "1" )
{
//if (bodyList != null)
//{
// foreach (var enumValue in bodyList)
// {
// if (enumValue.FREIGHT != 0)
// {
// 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, 1);
// 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.CUSTOMERNAME);
// db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, enumValue.CTNALL);
// db.AddInParameter(cmdInsertFee, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
// db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, enumValue.CTNNUM);
// db.AddInParameter(cmdInsertFee, "@AMOUNT", DbType.Decimal, enumValue.FREIGHT);
// 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, userid);
// 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, 0);
// db.AddInParameter(cmdInsertFee, "@NOTAXAMOUNT", DbType.Decimal, enumValue.FREIGHT);
// db.AddInParameter(cmdInsertFee, "@ACCTAXRATE", DbType.Decimal, 0);
// db.AddInParameter(cmdInsertFee, "@LINENUM", DbType.Int16, 1);
// db.AddInParameter(cmdInsertFee, "@TAXUNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
// db.AddInParameter(cmdInsertFee, "@MODIFIEDUSER", DbType.String, userid);
// 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);
// }
// }
//}
if ( headData . FREIGHT ! = 0 )
{
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 , 1 ) ;
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 . CUSTOMERNAME ) ;
db . AddInParameter ( cmdInsertFee , "@UNIT" , DbType . String , "票" ) ;
db . AddInParameter ( cmdInsertFee , "@UNITPRICE" , DbType . Decimal , headData . FREIGHT ) ;
db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertFee , "@AMOUNT" , DbType . Decimal , headData . FREIGHT ) ;
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 , userid ) ;
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 , 0 ) ;
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 . FREIGHT ) ;
db . AddInParameter ( cmdInsertFee , "@MODIFIEDUSER" , DbType . String , userid ) ;
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 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 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 ( MsOpTruckBulk 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 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 ;
}
# endregion
#region 明细表
static public List < MsOpTruckBulkDetail > GetBodyList ( string strCondition , string sort = null )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( "GID,BSNO,GOODSNAME,PKGS,UNITKGS,NETWEIGHT,REMARK,CREATEUSER,CREATETIME,KGS,CBM,UNITTYPE,UNIT,UNITPRICE,FREIGHT,ISFEE" ) ;
strSql . Append ( ",PCPKGS,PCKGS,PCCBM,PCNETWEIGHT,TRUCKNUM,PCTRUCKNUM,CTNALL,CTNNUM,PCCTNNUM,ORUNITPRICE,ORFREIGHT " ) ;
strSql . Append ( " from op_truck_bulk_detail " ) ;
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 CREATETIME " ) ;
}
return SetBodyData ( strSql ) ;
}
private static List < MsOpTruckBulkDetail > SetBodyData ( StringBuilder strSql )
{
var bodyList = new List < MsOpTruckBulkDetail > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
MsOpTruckBulkDetail data = new MsOpTruckBulkDetail ( ) ;
#region Set DB data to Object
data . GID = Convert . ToString ( reader [ "GID" ] ) ;
data . BSNO = Convert . ToString ( reader [ "BSNO" ] ) ;
data . GOODSNAME = Convert . ToString ( reader [ "GOODSNAME" ] ) ;
if ( reader [ "PKGS" ] ! = DBNull . Value )
data . PKGS = Convert . ToDecimal ( reader [ "PKGS" ] ) ;
if ( reader [ "UNITKGS" ] ! = DBNull . Value )
data . UNITKGS = Convert . ToDecimal ( reader [ "UNITKGS" ] ) ;
if ( reader [ "NETWEIGHT" ] ! = DBNull . Value )
data . NETWEIGHT = Convert . ToDecimal ( reader [ "NETWEIGHT" ] ) ;
if ( reader [ "KGS" ] ! = DBNull . Value )
data . KGS = Convert . ToDecimal ( reader [ "KGS" ] ) ;
if ( reader [ "CBM" ] ! = DBNull . Value )
data . CBM = Convert . ToDecimal ( reader [ "CBM" ] ) ;
data . UNITTYPE = Convert . ToString ( reader [ "UNITTYPE" ] ) ;
data . UNIT = Convert . ToString ( reader [ "UNIT" ] ) ;
data . CTNALL = Convert . ToString ( reader [ "CTNALL" ] ) ;
if ( reader [ "UNITPRICE" ] ! = DBNull . Value )
data . UNITPRICE = Convert . ToDecimal ( reader [ "UNITPRICE" ] ) ;
if ( reader [ "FREIGHT" ] ! = DBNull . Value )
data . FREIGHT = Convert . ToDecimal ( reader [ "FREIGHT" ] ) ;
if ( reader [ "ORUNITPRICE" ] ! = DBNull . Value )
data . ORUNITPRICE = Convert . ToDecimal ( reader [ "ORUNITPRICE" ] ) ;
if ( reader [ "ORFREIGHT" ] ! = DBNull . Value )
data . ORFREIGHT = Convert . ToDecimal ( reader [ "ORFREIGHT" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . CREATEUSER = Convert . ToString ( reader [ "CREATEUSER" ] ) ;
if ( reader [ "CREATETIME" ] ! = DBNull . Value )
data . CREATETIME = Convert . ToString ( reader [ "CREATETIME" ] ) ;
data . ISFEE = Convert . ToString ( reader [ "ISFEE" ] ) ;
if ( reader [ "PCPKGS" ] ! = DBNull . Value )
data . PCPKGS = Convert . ToDecimal ( reader [ "PCPKGS" ] ) ;
if ( reader [ "PCKGS" ] ! = DBNull . Value )
data . PCKGS = Convert . ToDecimal ( reader [ "PCKGS" ] ) ;
if ( reader [ "PCCBM" ] ! = DBNull . Value )
data . PCCBM = Convert . ToDecimal ( reader [ "PCCBM" ] ) ;
if ( reader [ "PCNETWEIGHT" ] ! = DBNull . Value )
data . PCNETWEIGHT = Convert . ToDecimal ( reader [ "PCNETWEIGHT" ] ) ;
if ( reader [ "TRUCKNUM" ] ! = DBNull . Value )
data . TRUCKNUM = Convert . ToDecimal ( reader [ "TRUCKNUM" ] ) ;
if ( reader [ "PCTRUCKNUM" ] ! = DBNull . Value )
data . PCTRUCKNUM = Convert . ToDecimal ( reader [ "PCTRUCKNUM" ] ) ;
if ( reader [ "CTNNUM" ] ! = DBNull . Value )
data . CTNNUM = Convert . ToInt32 ( reader [ "CTNNUM" ] ) ;
if ( reader [ "PCCTNNUM" ] ! = DBNull . Value )
data . PCCTNNUM = Convert . ToInt32 ( reader [ "PCCTNNUM" ] ) ;
if ( data . PKGS > = data . PCPKGS ) data . NPCPKGS = data . PKGS - data . PCPKGS ;
if ( data . KGS > = data . PCKGS ) data . NPCKGS = data . KGS - data . PCKGS ;
if ( data . CBM > = data . PCCBM ) data . NPCCBM = data . CBM - data . PCCBM ;
if ( data . NETWEIGHT > = data . PCNETWEIGHT ) data . NPCNETWEIGHT = data . NETWEIGHT - data . PCNETWEIGHT ;
if ( data . TRUCKNUM > = data . PCTRUCKNUM ) data . NPCTRUCKNUM = data . TRUCKNUM - data . PCTRUCKNUM ;
if ( data . CTNNUM > = data . PCCTNNUM ) data . NPCCTNNUM = data . CTNNUM - data . PCCTNNUM ;
# endregion
bodyList . Add ( data ) ;
}
reader . Close ( ) ;
}
return bodyList ;
}
public static DBResult SaveDetail ( MsOpTruckBulk headData , List < MsOpTruckBulkDetail > 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_detail (GID,BSNO,GOODSNAME,PKGS,UNITKGS,NETWEIGHT,KGS,CBM,UNITTYPE,UNIT,UNITPRICE,FREIGHT,REMARK,CREATEUSER,CREATETIME,PCPKGS,PCKGS,PCCBM,TRUCKNUM,PCTRUCKNUM,CTNALL,CTNNUM,PCCTNNUM,ORUNITPRICE,ORFREIGHT)
values ( @GID , @BSNO , @GOODSNAME , @PKGS , @UNITKGS , @NETWEIGHT , @KGS , @CBM , @UNITTYPE , @UNIT , @UNITPRICE , @FREIGHT , @REMARK , @CREATEUSER , @CREATETIME , @PCPKGS , @PCKGS , @PCCBM , @TRUCKNUM , @PCTRUCKNUM , @CTNALL , @CTNNUM , @PCCTNNUM , @ORUNITPRICE , @ORFREIGHT ) ");
var cmdUpdate =
db . GetSqlStringCommand (
@ "update op_truck_bulk_detail set GOODSNAME=@GOODSNAME,PKGS=@PKGS,UNITKGS=@UNITKGS,NETWEIGHT=@NETWEIGHT,KGS=@KGS,CBM=@CBM,TRUCKNUM=@TRUCKNUM,UNITTYPE=@UNITTYPE,UNIT=@UNIT,UNITPRICE=@UNITPRICE,
FREIGHT = @FREIGHT , REMARK = @REMARK , CTNALL = @CTNALL , CTNNUM = @CTNNUM , ORUNITPRICE = @ORUNITPRICE , ORFREIGHT = @ORFREIGHT where GID = @GID ");
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
if ( enumValue . BSNO = = "*" | | enumValue . BSNO = = "" )
{
cmdInsert . Parameters . Clear ( ) ;
db . AddInParameter ( cmdInsert , "@GID" , DbType . String , Guid . NewGuid ( ) . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@BSNO" , DbType . String , headData . BSNO ) ;
db . AddInParameter ( cmdInsert , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdInsert , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdInsert , "@UNITKGS" , DbType . Decimal , enumValue . UNITKGS ) ;
db . AddInParameter ( cmdInsert , "@NETWEIGHT" , DbType . Decimal , enumValue . NETWEIGHT ) ;
db . AddInParameter ( cmdInsert , "@KGS" , DbType . Decimal , enumValue . KGS ) ;
db . AddInParameter ( cmdInsert , "@CBM" , DbType . Decimal , enumValue . CBM ) ;
db . AddInParameter ( cmdInsert , "@UNITTYPE" , DbType . String , enumValue . UNITTYPE ) ;
db . AddInParameter ( cmdInsert , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdInsert , "@UNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
db . AddInParameter ( cmdInsert , "@FREIGHT" , DbType . Decimal , enumValue . FREIGHT ) ;
db . AddInParameter ( cmdInsert , "@REMARK" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdInsert , "@CREATEUSER" , DbType . String , userid ) ;
db . AddInParameter ( cmdInsert , "@CREATETIME" , DbType . String , DateTime . Now . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@PCPKGS" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@PCKGS" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@PCCBM" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@TRUCKNUM" , DbType . Decimal , enumValue . TRUCKNUM ) ;
db . AddInParameter ( cmdInsert , "@PCTRUCKNUM" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@CTNALL" , DbType . String , enumValue . CTNALL ) ;
db . AddInParameter ( cmdInsert , "@CTNNUM" , DbType . Decimal , enumValue . CTNNUM ) ;
db . AddInParameter ( cmdInsert , "@PCCTNNUM" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsert , "@ORUNITPRICE" , DbType . Decimal , enumValue . ORUNITPRICE ) ;
db . AddInParameter ( cmdInsert , "@ORFREIGHT" , DbType . Decimal , enumValue . ORFREIGHT ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
}
else
{
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@GID" , DbType . String , enumValue . GID ) ;
db . AddInParameter ( cmdUpdate , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdUpdate , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdUpdate , "@UNITKGS" , DbType . Decimal , enumValue . UNITKGS ) ;
db . AddInParameter ( cmdUpdate , "@NETWEIGHT" , DbType . Decimal , enumValue . NETWEIGHT ) ;
db . AddInParameter ( cmdUpdate , "@KGS" , DbType . Decimal , enumValue . KGS ) ;
db . AddInParameter ( cmdUpdate , "@CBM" , DbType . Decimal , enumValue . CBM ) ;
db . AddInParameter ( cmdUpdate , "@TRUCKNUM" , DbType . Decimal , enumValue . TRUCKNUM ) ;
db . AddInParameter ( cmdUpdate , "@UNITTYPE" , DbType . String , enumValue . UNITTYPE ) ;
db . AddInParameter ( cmdUpdate , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdUpdate , "@UNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
db . AddInParameter ( cmdUpdate , "@FREIGHT" , DbType . Decimal , enumValue . FREIGHT ) ;
db . AddInParameter ( cmdUpdate , "@REMARK" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdUpdate , "@CTNALL" , DbType . String , enumValue . CTNALL ) ;
db . AddInParameter ( cmdUpdate , "@CTNNUM" , DbType . Decimal , enumValue . CTNNUM ) ;
db . AddInParameter ( cmdUpdate , "@ORUNITPRICE" , DbType . Decimal , enumValue . ORUNITPRICE ) ;
db . AddInParameter ( cmdUpdate , "@ORFREIGHT" , DbType . Decimal , enumValue . ORFREIGHT ) ;
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 DeleteDetail ( MsOpTruckBulk 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_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 ( MsOpTruckBulkDetail 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_detail where GID='" + bodyList . GID + "'" ) ;
db . ExecuteNonQuery ( cmdDelete , 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 CreateFeeDetail ( MsOpTruckBulk headData , List < MsOpTruckBulkDetail > 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_detail (GID,BSNO,GOODSNAME,PKGS,UNITKGS,NETWEIGHT,KGS,CBM,UNITTYPE,UNIT,UNITPRICE,FREIGHT,REMARK,CREATEUSER,CREATETIME,TRUCKNUM,PCTRUCKNUM)
values ( @GID , @BSNO , @GOODSNAME , @PKGS , @UNITKGS , @NETWEIGHT , @KGS , @CBM , @UNITTYPE , @UNIT , @UNITPRICE , @FREIGHT , @REMARK , @CREATEUSER , @CREATETIME , @TRUCKNUM , @PCTRUCKNUM ) ");
var cmdUpdate =
db . GetSqlStringCommand (
@"update op_truck_bulk_detail set GOODSNAME=@GOODSNAME,PKGS=@PKGS,UNITKGS=@UNITKGS,NETWEIGHT=@NETWEIGHT,KGS=@KGS,CBM=@CBM,TRUCKNUM=@TRUCKNUM,UNITTYPE=@UNITTYPE,UNIT=@UNIT,UNITPRICE=@UNITPRICE,FREIGHT=@FREIGHT,REMARK=@REMARK where GID=@GID " ) ;
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 )
");
if ( bodyList ! = null )
{
foreach ( var enumValue in bodyList )
{
var GID = enumValue . GID ;
if ( enumValue . BSNO = = "*" | | enumValue . BSNO = = "" )
{
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 , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdInsert , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdInsert , "@UNITKGS" , DbType . Decimal , enumValue . UNITKGS ) ;
db . AddInParameter ( cmdInsert , "@NETWEIGHT" , DbType . Decimal , enumValue . NETWEIGHT ) ;
db . AddInParameter ( cmdInsert , "@KGS" , DbType . Decimal , enumValue . KGS ) ;
db . AddInParameter ( cmdInsert , "@CBM" , DbType . Decimal , enumValue . CBM ) ;
db . AddInParameter ( cmdInsert , "@UNITTYPE" , DbType . String , enumValue . UNITTYPE ) ;
db . AddInParameter ( cmdInsert , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdInsert , "@UNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
db . AddInParameter ( cmdInsert , "@FREIGHT" , DbType . Decimal , enumValue . FREIGHT ) ;
db . AddInParameter ( cmdInsert , "@REMARK" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdInsert , "@CREATEUSER" , DbType . String , userid ) ;
db . AddInParameter ( cmdInsert , "@CREATETIME" , DbType . String , DateTime . Now . ToString ( ) ) ;
db . AddInParameter ( cmdInsert , "@TRUCKNUM" , DbType . Decimal , enumValue . TRUCKNUM ) ;
db . AddInParameter ( cmdInsert , "@PCTRUCKNUM" , DbType . Decimal , 0 ) ;
db . ExecuteNonQuery ( cmdInsert , tran ) ;
}
else
{
cmdUpdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdate , "@GID" , DbType . String , enumValue . GID ) ;
db . AddInParameter ( cmdUpdate , "@BSNO" , DbType . String , enumValue . BSNO ) ;
db . AddInParameter ( cmdUpdate , "@GOODSNAME" , DbType . String , enumValue . GOODSNAME ) ;
db . AddInParameter ( cmdUpdate , "@PKGS" , DbType . Decimal , enumValue . PKGS ) ;
db . AddInParameter ( cmdUpdate , "@UNITKGS" , DbType . Decimal , enumValue . UNITKGS ) ;
db . AddInParameter ( cmdUpdate , "@NETWEIGHT" , DbType . Decimal , enumValue . NETWEIGHT ) ;
db . AddInParameter ( cmdUpdate , "@KGS" , DbType . Decimal , enumValue . KGS ) ;
db . AddInParameter ( cmdUpdate , "@CBM" , DbType . Decimal , enumValue . CBM ) ;
db . AddInParameter ( cmdUpdate , "@UNITTYPE" , DbType . String , enumValue . UNITTYPE ) ;
db . AddInParameter ( cmdUpdate , "@UNIT" , DbType . String , enumValue . UNIT ) ;
db . AddInParameter ( cmdUpdate , "@UNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
db . AddInParameter ( cmdUpdate , "@FREIGHT" , DbType . Decimal , enumValue . FREIGHT ) ;
db . AddInParameter ( cmdUpdate , "@REMARK" , DbType . String , enumValue . REMARK ) ;
db . AddInParameter ( cmdUpdate , "@TRUCKNUM" , DbType . Decimal , enumValue . TRUCKNUM ) ;
db . ExecuteNonQuery ( cmdUpdate , tran ) ;
}
if ( enumValue . ISFEE ! = "1" )
{
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 , 1 ) ;
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 . CUSTOMERNAME ) ;
db . AddInParameter ( cmdInsertFee , "@UNIT" , DbType . String , enumValue . UNITTYPE ) ;
db . AddInParameter ( cmdInsertFee , "@UNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
if ( enumValue . UNITTYPE = = "吨" | | enumValue . UNITTYPE = = "公斤" )
db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , enumValue . KGS ) ;
else if ( enumValue . UNITTYPE = = "立方" )
db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , enumValue . CBM ) ;
else if ( enumValue . UNITTYPE = = "车型" )
db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , enumValue . TRUCKNUM ) ;
else db . AddInParameter ( cmdInsertFee , "@QUANTITY" , DbType . Decimal , 1 ) ;
db . AddInParameter ( cmdInsertFee , "@AMOUNT" , DbType . Decimal , enumValue . FREIGHT ) ;
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 , userid ) ;
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 , 1 ) ;
db . AddInParameter ( cmdInsertFee , "@FEEFRT" , DbType . String , "PP" ) ;
db . AddInParameter ( cmdInsertFee , "@CARGO_GID" , DbType . String , GID ) ;
db . AddInParameter ( cmdInsertFee , "@TAXRATE" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsertFee , "@NOTAXAMOUNT" , DbType . Decimal , enumValue . FREIGHT ) ;
db . AddInParameter ( cmdInsertFee , "@ACCTAXRATE" , DbType . Decimal , 0 ) ;
db . AddInParameter ( cmdInsertFee , "@LINENUM" , DbType . Int16 , 1 ) ;
db . AddInParameter ( cmdInsertFee , "@TAXUNITPRICE" , DbType . Decimal , enumValue . UNITPRICE ) ;
db . AddInParameter ( cmdInsertFee , "@MODIFIEDUSER" , DbType . String , userid ) ;
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_detail set ISFEE='1' where GID=@GID " ) ;
cmdUpdateBL . Parameters . Clear ( ) ;
db . AddInParameter ( cmdUpdateBL , "@GID" , DbType . String , GID ) ;
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 ;
}
# endregion
#region 审核和撤销审核
public static DBResult SubmitAudit ( String USERID , List < MsOpTruckBulk > bodyList , string companyid )
{
var result = new DBResult ( ) ;
var mustresult = ISMUSTBE ( bodyList , companyid ) ;
if ( mustresult . Success = = false )
return mustresult ;
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 isfee = GetCreateFeeCount ( enumValue . BSNO , db , tran ) ;
if ( enumValue . TRANSTYPE = = "普运" & & enumValue . CONTRACTNO ! = "" & & enumValue . TEMPLATENAME ! = "" & & enumValue . UNITPRICE = = enumValue . ORUNITPRICE & & enumValue . FREIGHT = = enumValue . ORFREIGHT )
{
var cmdupdate = db . GetSqlStringCommand ( "update op_truck_bulk 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 = "提交审核成功" ;
result . Data = "审核通过" ;
}
else if ( enumValue . TRANSTYPE = = "集装箱" & & enumValue . CONTRACTNO ! = "" & & enumValue . TEMPLATENAME ! = "" & & ! isfee )
{
var cmdupdate = db . GetSqlStringCommand ( "update op_truck_bulk 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 = "提交审核成功" ;
result . Data = "审核通过" ;
}
else
{
Resultmb WorkResult = WorkFlowDAL . WorkFlowStart ( "OpTruckBulkAudit" , 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 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 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 < MsOpTruckBulk > 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 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 ( "OpTruckBulkAudit" , enumValue . BSNO , USERID ) ;
if ( WorkResult . Success = = true )
{
var cmdupdate = db . GetSqlStringCommand ( "update op_truck_bulk 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 < MsOpTruckBulk > boday , String USERID )
{
var result = new DBResult ( ) ;
var headList = new List < MsOpTruckBulk > ( ) ;
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 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 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 ( "OpTruckBulkAudit" , 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 = new DBResult ( ) ;
result . Success = true ;
result . Data = headList ;
result . Message = "审核通过" ;
tran . Commit ( ) ;
}
catch ( Exception e )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "审核出现错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult AuditBackList ( List < MsOpTruckBulk > 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 set TRANSSTATUS='驳回提交',AUDITUSER='',AUDITTIME=null,REASON='" + reason + "' where BSNO=@BSNO" ) ;
foreach ( var enumValue in boday )
{
if ( enumValue . TRANSSTATUS = = "提交审核" | | enumValue . TRANSSTATUS = = "审核通过" )
{
if ( enumValue . TEMPLATENAME ! = "" )
{
cmdupdate . Parameters . Clear ( ) ;
db . AddInParameter ( cmdupdate , "@BSNO" , DbType . String , enumValue . BSNO ) ;
db . ExecuteNonQuery ( cmdupdate , tran ) ;
}
else {
Resultmb WorkResult = WorkFlowDAL . DeleteWorkFlowDo ( "OpTruckBulkAudit" , 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 ;
}
# endregion
public static string FormatDateStr ( string datestr ) {
var result = "" ;
if ( string . IsNullOrEmpty ( datestr ) ) return result ;
var tmp = '/' ;
if ( datestr . IndexOf ( "/" ) > 0 ) {
tmp = '/' ;
} else if ( datestr . IndexOf ( "-" ) > 0 )
{
tmp = '-' ;
}
var tmpstr = "" ;
var opList = datestr . Split ( tmp ) ;
foreach ( var opstr in opList )
{
tmpstr = opstr ;
if ( tmpstr . Length = = 1 ) tmpstr = "0" + tmpstr ;
if ( ! string . IsNullOrEmpty ( result ) )
result = result + "-" + tmpstr ;
else result = tmpstr ;
}
return result ;
}
public static DBResult 检 查 数 字 是 否 复 合 日 期 要 求 ( ref string DATEStr ) {
var result = new DBResult ( true , "" , DATEStr ) ;
var 原 = DATEStr ;
//允许为空
if ( string . IsNullOrWhiteSpace ( DATEStr ) ) return result ;
DATEStr = DATEStr . Replace ( "-" , "" ) . Replace ( "/" , "" ) . Trim ( ) ;
if ( DATEStr . Length ! = 8 ) {
result . SetErrorInfo ( "[" + 原 + "]日期错误。日期必须为8位数字, 或形如2000-01-01 2000/01/01的样式。" ) ;
return result ;
}
var isnum = int . TryParse ( DATEStr , out int a ) ;
if ( ! isnum )
{
result . SetErrorInfo ( "[" + 原 + "]日期错误。日期必须为8位数字, 或形如2000-01-01 2000/01/01的样式。" ) ;
return result ;
}
try
{
int y = int . Parse ( DATEStr . Substring ( 0 , 4 ) ) ;
int m = int . Parse ( DATEStr . Substring ( 4 , 2 ) ) ;
int d = int . Parse ( DATEStr . Substring ( 6 , 2 ) ) ;
var _temptime = new DateTime ( y , m , d ) ;
}
catch
{
result . SetErrorInfo ( "[" + 原 + "]无法转换为一个合法日期。" ) ;
return result ;
}
return result ;
}
#region EXCEL引入订单
public static bool ImportBsData ( HttpRequestBase request , DataTable table , string username , string userid , string corpid , out string msg , out List < MsOpTruckBulk > headList )
{
var isSucess = false ;
msg = "" ;
headList = new List < MsOpTruckBulk > ( ) ;
if ( table = = null ) throw new ArgumentNullException ( "table" ) ;
var imptime = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
var billNoList = new List < string > ( ) ;
var i = 1 ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
var CustnameList = new List < string > ( ) ;
foreach ( DataRow row in table . Rows )
{
var ORDERNO = Convert . ToString ( row [ "客户订单号" ] ) ;
if ( string . IsNullOrWhiteSpace ( ORDERNO ) ) continue ;
var _CUSTNAME = Convert . ToString ( row [ "客户" ] ) ;
if ( ! CustnameList . Contains ( _CUSTNAME ) ) {
CustnameList . Add ( _CUSTNAME ) ;
}
}
var infoClientList = new List < MsClient > ( ) ;
var desStr = "" ;
foreach ( var custname in CustnameList ) {
if ( desStr ! = "" ) desStr + = "," ;
desStr + = "'" + custname + "'" ;
}
infoClientList = MsInfoClientDAL . GetDataListAll ( "DESCRIPTION in(" + desStr + ")" , userid , "" , corpid ) ;
try
{
foreach ( DataRow row in table . Rows )
{
var ORDERNO = Convert . ToString ( row [ "客户订单号" ] ) ;
if ( string . IsNullOrWhiteSpace ( ORDERNO ) ) continue ;
var SALE = Convert . ToString ( row [ "客户经理" ] ) ;
var CUSTSERVICE = Convert . ToString ( row [ "运营经理" ] ) ;
var BSDATE = Convert . ToString ( row [ "受理日期" ] ) ;
BSDATE = FormatDateStr ( BSDATE ) ;
var _checkresult = 检 查 数 字 是 否 复 合 日 期 要 求 ( ref BSDATE ) ;
if ( ! _checkresult . Success ) {
msg = _checkresult . Message ;
return false ;
}
var ETD = Convert . ToString ( row [ "要求发货日期" ] ) ;
ETD = FormatDateStr ( ETD ) ;
_checkresult = 检 查 数 字 是 否 复 合 日 期 要 求 ( ref ETD ) ;
if ( ! _checkresult . Success )
{
msg = _checkresult . Message ;
return false ;
}
var CUSTNAME = Convert . ToString ( row [ "客户" ] ) ;
var PORTLOAD = Convert . ToString ( row [ "起始地" ] ) ;
var PORTDISCHARGE = Convert . ToString ( row [ "目的地" ] ) ;
var GOODSNAME = Convert . ToString ( row [ "品名" ] ) ;
var KINDPKGS = Convert . ToString ( row [ "计量单位" ] ) ;
var TRUCKTYPE = Convert . ToString ( row [ "需要车型" ] ) ;
var PKGS = Convert . ToString ( row [ "件数" ] ) ;
if ( PKGS = = "" ) PKGS = "0" ;
var NETWEIGHT = Convert . ToString ( row [ "净重" ] ) ;
if ( NETWEIGHT = = "" ) NETWEIGHT = "0" ;
var KGS = Convert . ToString ( row [ "毛重" ] ) ;
if ( KGS = = "" ) KGS = "0" ;
var FREIGHT = Convert . ToString ( row [ "运费" ] ) ;
if ( FREIGHT = = "" ) FREIGHT = "0" ;
var REMARK = Convert . ToString ( row [ "备注" ] ) ;
var CUSTATTN = Convert . ToString ( row [ "客户联系人" ] ) ;
var CUSTATTNTEL = Convert . ToString ( row [ "联系电话" ] ) ;
var ETA = Convert . ToString ( row [ "要求到货日期" ] ) ;
ETA = FormatDateStr ( ETA ) ;
_checkresult = 检 查 数 字 是 否 复 合 日 期 要 求 ( ref ETA ) ;
if ( ! _checkresult . Success )
{
msg = _checkresult . Message ;
return false ;
}
var CONSIGNEENAME = Convert . ToString ( row [ "收货单位" ] ) ;
var CONSIGNEEADDR = Convert . ToString ( row [ "详细地址" ] ) ;
var CONSIGNEEATTN = Convert . ToString ( row [ "联系人" ] ) ;
var CONSIGNEETEL = Convert . ToString ( row [ "电话" ] ) ;
var ct = MsOpTruckBulkDAL . GetRdCount ( " ORDERNO='" + ORDERNO + "' " ) ;
if ( ct ! = 0 )
{
msg = msg + "订单号重复" + ORDERNO ;
} else {
if ( CUSTNAME ! = "" )
{
MsClient client = infoClientList . Find ( x = > x . DESCRIPTION = = CUSTNAME ) ; //MsInfoClientDAL.GetData("DESCRIPTION='" + CUSTNAME + "'");
if ( client ! = null & & client . SHORTNAME ! = "" )
{
var head = new MsOpTruckBulk ( ) ;
head . OP = username ;
head . ORDERNO = ORDERNO ;
head . CUSTSERVICE = CUSTSERVICE ;
head . BSDATE = BSDATE ;
head . ETD = ETD ;
head . ETA = ETA ;
head . CUSTOMERNAME = client . SHORTNAME ;
head . PORTLOAD = PORTLOAD ;
head . PORTDISCHARGE = PORTDISCHARGE ;
head . GOODSNAME = GOODSNAME ;
head . KINDPKGS = KINDPKGS ;
head . UNIT = TRUCKTYPE ;
try
{
head . PKGS = Convert . ToInt32 ( PKGS ) ;
}
catch
{
head . PKGS = 0 ;
}
try
{
head . NETWEIGHT = Convert . ToDecimal ( NETWEIGHT ) ;
}
catch
{
head . NETWEIGHT = 0 ;
}
try
{
head . KGS = Convert . ToDecimal ( KGS ) ;
}
catch
{
head . KGS = 0 ;
}
head . REMARK = REMARK ;
head . CORPID = corpid ;
head . BSSTATUS = false ; //业务状态
head . FEESTATUS = false ; //费用状态
head . ISVOU = false ; //是否生成凭证
head . VOUNO = "" ; //凭证号
head . CREATEUSER = userid ; //创建人
head . CREATETIME = imptime ; //创建时间
head . BSNO = "toptruck" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
var transstr = "陆运普货订单" ;
head . TRANSTYPE = "普运" ;
if ( head . TRANSTYPE = = "集装箱" ) transstr = "陆运集运订单" ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='" + transstr + "'" , corpid ) ;
head . CUSTNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . CREATETIME . ToString ( ) . Trim ( ) , head . ACCDATE . ToString ( ) . Trim ( ) , "" , head . OP , head . SALECORPID ) ;
head . PCKGS = 0 ;
head . NOPCKGS = 0 ;
head . SALE = SALE ;
head . TTLYFDR = "0" ;
head . TRUCKNUM = 0 ;
head . CUSTATTN = CUSTATTN ;
head . CUSTTEL = CUSTATTNTEL ;
head . CONSIGNEENAME = CONSIGNEENAME ;
head . CONSIGNEEADDR = CONSIGNEEADDR ;
head . CONSIGNEEATTN = CONSIGNEEATTN ;
head . CONSIGNEETEL = CONSIGNEETEL ;
if ( head . CUSTOMERNAME ! = "" & & head . GOODSNAME ! = "" & & head . PORTLOAD ! = "" & & head . PORTDISCHARGE ! = "" )
{
var sql = " CUSTOMERNAME='" + head . CUSTOMERNAME + "' and GOODNAME='" + head . GOODSNAME + "' and TRANTYPE='普货' and BSSTATUS='审核通过' and GID IN (SELECT TEMPLATEID FROM Cust_Truck_feetemplatedetail WHERE LOADPORT='"
+ head . PORTLOAD + "' and DISTPORT='" + head . PORTDISCHARGE + "') and CONTRACTNO not in (select CONTRACTNO from info_client_contract where CANCELDATE<'" + DateTime . Now . ToString ( "yyyy-MM-dd" ) + "')" ;
var feetemplate = MsCustTruckFeeTempldateDAL . GetData ( sql ) ;
head . TEMPLATENAME = feetemplate . TEMPLATENAME ;
head . CONTRACTNO = feetemplate . CONTRACTNO ;
head . FEEUNIT = feetemplate . FEEUNIT ;
head . PRICEUNIT = feetemplate . PRICEUNIT ;
if ( head . TEMPLATENAME ! = "" )
{
sql = " LOADPORT='" + head . PORTLOAD + "' and DISTPORT='" + head . PORTDISCHARGE + "' AND TEMPLATEID in (select gid from [Cust_Truck_feetemplate] where TEMPLATENAME='" + head . TEMPLATENAME + "' and CONTRACTNO='" + head . CONTRACTNO + "')" ;
var feetemplateDetail = MsCustTruckFeeTempldateDAL . GetBodyList ( sql ) ;
if ( feetemplateDetail . Count ! = 0 )
{
head . UNITTYPE = feetemplateDetail [ 0 ] . UNITTYPE ;
if ( head . UNITTYPE = = "车型" )
{
if ( feetemplateDetail ! = null & & head . TRUCKNUM ! = 0 )
{
foreach ( var enumValue in feetemplateDetail )
{
if ( head . UNIT = = enumValue . UNIT )
{
head . UNITPRICE = enumValue . UNITPRICE ;
head . FREIGHT = enumValue . UNITPRICE * head . TRUCKNUM ;
head . ORUNITPRICE = head . UNITPRICE ;
head . ORFREIGHT = head . FREIGHT ;
}
}
}
}
else if ( head . UNITTYPE = = "吨" | | head . UNITTYPE = = "公斤" )
{
decimal FEEKGS = 0 ;
decimal PRICEKGS = 0 ;
if ( head . FEEUNIT = = "净重" ) FEEKGS = head . NETWEIGHT ; else FEEKGS = head . KGS ;
if ( head . PRICEUNIT = = "净重" ) PRICEKGS = head . NETWEIGHT ; else PRICEKGS = head . KGS ;
if ( feetemplateDetail ! = null & & PRICEKGS ! = 0 )
{
foreach ( var enumValue in feetemplateDetail )
{
if ( PRICEKGS > = enumValue . STARTWEIGHT & & PRICEKGS < enumValue . ENDWEIGHT )
{
head . UNITPRICE = enumValue . UNITPRICE ;
head . FREIGHT = enumValue . UNITPRICE * FEEKGS ;
head . ORUNITPRICE = head . UNITPRICE ;
head . ORFREIGHT = head . FREIGHT ;
}
}
}
}
else if ( head . UNITTYPE = = "立方" )
{
if ( feetemplateDetail ! = null & & head . CBM ! = 0 )
{
foreach ( var enumValue in feetemplateDetail )
{
if ( head . CBM > = enumValue . STARTWEIGHT & & head . CBM < enumValue . ENDWEIGHT )
{
head . UNITPRICE = enumValue . UNITPRICE ;
head . FREIGHT = enumValue . UNITPRICE * head . CBM ;
head . ORUNITPRICE = head . UNITPRICE ;
head . ORFREIGHT = head . FREIGHT ;
}
}
}
}
}
}
}
try
{
if ( Convert . ToDecimal ( FREIGHT ) ! = 0 )
head . FREIGHT = Convert . ToDecimal ( FREIGHT ) ;
}
catch
{
// head.FREIGHT = 0;
}
head . DbOperationType = DbOperationType . DbotIns ;
/ /
head . MODIFIEDUSER = userid ; //最后一次操作人
string rq = T_ALL_DA . GetStrSQL ( "rq" , "select getdate() as rq" ) ;
head . MODIFIEDTIME = DateTime . Parse ( rq ) ; //最后一次操作时间
var modb = new ModelObjectDB ( ) ;
DBResult result = modb . Save ( head ) ;
var BSNO = head . BSNO ;
if ( result . Success = = true )
{
var bodyList = new List < MsOpTruckBulkDetail > ( ) ;
var body = new MsOpTruckBulkDetail ( ) ;
body . BSNO = "*" ;
body . GOODSNAME = GOODSNAME ;
body . PKGS = head . PKGS ;
body . KGS = head . KGS ;
body . NETWEIGHT = head . NETWEIGHT ;
body . TRUCKNUM = head . TRUCKNUM ;
bodyList . Add ( body ) ;
result = MsOpTruckBulkDAL . SaveDetail ( head , bodyList , userid ) ;
isSucess = true ;
}
else {
msg = "客户订单号【" + ORDERNO + "】" + result . Message ;
return false ;
}
headList . Add ( head ) ;
i + + ;
}
else
{
msg = msg + "系统中不存在" + CUSTNAME ;
}
}
}
}
}
catch ( Exception e ) {
foreach ( var enumValue in headList )
{
var BSNO = enumValue . BSNO ;
var modb = new ModelObjectDB ( ) ;
DBResult result = modb . Delete ( enumValue ) ;
if ( result . Success = = true ) { MsSysBillNoSetDAL . DeleteBsNo ( enumValue . CUSTNO ) ; }
if ( result . Success = = true )
{
MsOpTruckBulkDAL . DeleteDetail ( enumValue ) ;
}
}
msg = msg + e . Message ;
return false ;
}
return isSucess ;
}
public static bool ImportBsCtnData ( HttpRequestBase request , DataTable table , string username , string userid , string corpid , out string msg , out List < MsOpTruckBulk > headList )
{
var isSucess = false ;
msg = "" ;
headList = new List < MsOpTruckBulk > ( ) ;
if ( table = = null ) throw new ArgumentNullException ( "table" ) ;
var imptime = DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) ;
var billNoList = new List < string > ( ) ;
var i = 1 ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
try
{
foreach ( DataRow row in table . Rows )
{
var ORDERNO = Convert . ToString ( row [ "客户订单号" ] ) ;
var CUSTNAME = Convert . ToString ( row [ "委托单位" ] ) ;
var MBLNO = Convert . ToString ( row [ "提单号" ] ) ;
var GOODSNAME = Convert . ToString ( row [ "品名" ] ) ;
var TRADETYPE = Convert . ToString ( row [ "托运类型(出口/进口)" ] ) ;
var SALE = Convert . ToString ( row [ "客户经理" ] ) ;
var CUSTSERVICE = Convert . ToString ( row [ "运营经理" ] ) ;
var ETD = Convert . ToString ( row [ "要求装货日期/要求卸货日期" ] ) ;
ETD = FormatDateStr ( ETD ) ;
var YARD = Convert . ToString ( row [ "提箱场站" ] ) ;
var PORTLOAD = Convert . ToString ( row [ "起始地" ] ) ;
var PORTDISCHARGE = Convert . ToString ( row [ "目的地" ] ) ;
var CTNALL = Convert . ToString ( row [ "箱型" ] ) ;
var CTNNUM = Convert . ToString ( row [ "箱量" ] ) ;
var FREIGHT = Convert . ToString ( row [ "应收运费" ] ) ;
if ( FREIGHT = = "" ) FREIGHT = "0" ;
var ORDERNO1 = Convert . ToString ( row [ "运输凭证编号" ] ) ;
var CONSIGNEENAME = Convert . ToString ( row [ "收货单位" ] ) ;
var CONSIGNEEADDR = Convert . ToString ( row [ "详细地址" ] ) ;
var CONSIGNEEATTN = Convert . ToString ( row [ "联系人" ] ) ;
var CONSIGNEETEL = Convert . ToString ( row [ "电话" ] ) ;
var CUSTATTN = Convert . ToString ( row [ "客户联系人" ] ) ;
var CUSTATTNTEL = Convert . ToString ( row [ "联系电话" ] ) ;
var REMARK = Convert . ToString ( row [ "备注" ] ) ;
var BSDATE = Convert . ToString ( row [ "接单日期" ] ) ;
BSDATE = FormatDateStr ( BSDATE ) ;
var ct = MsOpTruckBulkDAL . GetRdCount ( " ORDERNO='" + ORDERNO + "' " ) ;
if ( ct ! = 0 )
{
msg = msg + "订单号重复" + ORDERNO ;
}
else
{
if ( CUSTNAME ! = "" )
{
var isyard = true ;
//if (YARD != "")
//{
// var clientyard = MsInfoClientDAL.GetData("DESCRIPTION='" + YARD + "'");
// if (clientyard.SHORTNAME == "")
// {
// msg = msg + "系统中不存在场站-" + YARD;
// isyard = false;
// }
//}
//if (isyard)
//{
var client = MsInfoClientDAL . GetData ( "DESCRIPTION='" + CUSTNAME + "'" ) ;
if ( client . SHORTNAME ! = "" )
{
var head = new MsOpTruckBulk ( ) ;
head . OP = username ;
head . ORDERNO = ORDERNO ;
head . CUSTSERVICE = CUSTSERVICE ;
if ( ! string . IsNullOrEmpty ( BSDATE ) )
head . BSDATE = BSDATE ;
else head . BSDATE = imptime ;
head . ETD = ETD ;
// head.ETA = ETA;
head . CUSTOMERNAME = client . SHORTNAME ;
head . PORTLOAD = PORTLOAD ;
head . PORTDISCHARGE = PORTDISCHARGE ;
head . GOODSNAME = GOODSNAME ;
head . ORDERNO1 = ORDERNO1 ;
head . TRADETYPE = TRADETYPE ;
head . YARD = YARD ;
head . MBLNO = MBLNO ;
head . REMARK = REMARK ;
head . CORPID = corpid ;
head . BSNO = "toptruck" + Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
var transstr = "陆运集运订单" ;
head . TRANSTYPE = "集装箱" ;
var billnoset = MsSysBillNoSetDAL . GetData ( "OPLBNAME='" + transstr + "'" , corpid ) ;
head . PCKGS = 0 ;
head . NOPCKGS = 0 ;
head . SALE = SALE ;
head . TTLYFDR = "0" ;
head . TRUCKNUM = 0 ;
head . DbOperationType = DbOperationType . DbotIns ;
/ /
head . BSSTATUS = false ; //业务状态
head . FEESTATUS = false ; //费用状态
head . ISVOU = false ; //是否生成凭证
head . VOUNO = "" ; //凭证号
head . CREATEUSER = userid ; //创建人
head . CREATETIME = imptime ; //创建时间
head . ACCDATE = DateTime . Now . ToString ( "yyyy-MM" ) ;
head . MODIFIEDUSER = userid ; //最后一次操作人
string rq = T_ALL_DA . GetStrSQL ( "rq" , "select getdate() as rq" ) ;
head . MODIFIEDTIME = DateTime . Parse ( rq ) ; //最后一次操作时间
head . CONSIGNEENAME = CONSIGNEENAME ;
head . CONSIGNEEADDR = CONSIGNEEADDR ;
head . CONSIGNEEATTN = CONSIGNEEATTN ;
head . CONSIGNEETEL = CONSIGNEETEL ;
head . CUSTATTN = CUSTATTN ;
head . CUSTTEL = CUSTATTNTEL ;
head . CLOSINGDATE = null ;
var BSNO = head . BSNO ;
head . CUSTNO = MsSysBillNoSetDAL . GetBillNo ( billnoset , head . BSDATE . ToString ( ) . Trim ( ) , head . ACCDATE . ToString ( ) . Trim ( ) , "" , head . OP , head . SALECORPID ) ;
var bodyList = new List < MsOpTruckBulkDetail > ( ) ;
var body = new MsOpTruckBulkDetail ( ) ;
body . BSNO = "*" ;
body . GOODSNAME = GOODSNAME ;
body . CTNALL = CTNALL ;
// body.CTNNUM =CTNNUM;
try
{
body . CTNNUM = Convert . ToInt32 ( CTNNUM ) ;
}
catch
{
body . CTNNUM = 0 ;
}
head . CNTRTOTAL = body . CTNALL + "*" + body . CTNNUM . ToString ( ) ;
if ( head . CUSTOMERNAME ! = "" & & head . GOODSNAME ! = "" & & head . PORTLOAD ! = "" & & head . PORTDISCHARGE ! = "" )
{
var sql = " CUSTOMERNAME='" + head . CUSTOMERNAME + "' and GOODNAME='" + head . GOODSNAME + "' and TRANTYPE='集装箱' and BSSTATUS='审核通过' and GID IN (SELECT TEMPLATEID FROM Cust_Truck_feetemplatedetail WHERE LOADPORT='"
+ head . PORTLOAD + "' and DISTPORT='" + head . PORTDISCHARGE + "') and CONTRACTNO not in (select CONTRACTNO from info_client_contract where CANCELDATE<'" + DateTime . Now . ToString ( "yyyy-MM-dd" ) + "')" ;
var feetemplate = MsCustTruckFeeTempldateDAL . GetData ( sql ) ;
head . TEMPLATENAME = feetemplate . TEMPLATENAME ;
head . CONTRACTNO = feetemplate . CONTRACTNO ;
if ( head . TEMPLATENAME ! = "" )
{
sql = " LOADPORT='" + head . PORTLOAD + "' and DISTPORT='" + head . PORTDISCHARGE + "' AND TEMPLATEID in (select gid from [Cust_Truck_feetemplate] where TEMPLATENAME='" + head . TEMPLATENAME + "' and CONTRACTNO='" + head . CONTRACTNO + "')" ;
var feetemplateDetail = MsCustTruckFeeTempldateDAL . GetBodyList ( sql ) ;
if ( feetemplateDetail . Count ! = 0 )
{
if ( feetemplateDetail ! = null & & body . CTNNUM ! = 0 )
{
foreach ( var enumValue in feetemplateDetail )
{
if ( body . CTNALL = = enumValue . UNIT )
{
body . UNITPRICE = enumValue . UNITPRICE ;
body . FREIGHT = enumValue . UNITPRICE * body . CTNNUM ;
body . ORUNITPRICE = body . UNITPRICE ;
body . ORFREIGHT = body . FREIGHT ;
head . FREIGHT = body . FREIGHT ;
try
{
if ( Convert . ToDecimal ( FREIGHT ) ! = 0 )
body . FREIGHT = Convert . ToDecimal ( FREIGHT ) ;
}
catch
{
// head.FREIGHT = 0;
}
}
}
}
}
}
try
{
if ( Convert . ToDecimal ( FREIGHT ) ! = 0 )
head . FREIGHT = Convert . ToDecimal ( FREIGHT ) ;
}
catch
{
// head.FREIGHT = 0;
}
var modb = new ModelObjectDB ( ) ;
DBResult result = modb . Save ( head ) ;
bodyList . Add ( body ) ;
result = MsOpTruckBulkDAL . SaveDetail ( head , bodyList , userid ) ;
isSucess = true ;
}
headList . Add ( head ) ;
i + + ;
}
else
{
msg = msg + "系统中不存在客户-" + CUSTNAME ;
}
//}
}
}
}
}
catch ( Exception e )
{
msg = msg + e . Message ;
}
return isSucess ;
}
# 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 " ) ;
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 , 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 ;
}
public static bool GetCreateFeeCount ( string BSNO , string condition = "" )
{
var isfee = false ;
String strSql = "Select count(*) as count from op_truck_bulk_detail where (FREIGHT<>ORFREIGHT or UNITPRICE<>ORUNITPRICE) and 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 ;
}
public static bool GetCreateFeeCount ( string BSNO , Database db , DbTransaction tran )
{
var isfee = false ;
String strSql = "Select count(*) as count from op_truck_bulk_detail where (FREIGHT<>ORFREIGHT or UNITPRICE<>ORUNITPRICE) and BSNO='" + BSNO + "'" ;
using ( IDataReader reader = db . ExecuteReader ( tran , CommandType . Text , strSql ) )
{
while ( reader . Read ( ) )
{
var evData = Convert . ToInt32 ( reader [ "count" ] ) ;
if ( evData > 0 ) { isfee = true ; } ;
}
reader . Close ( ) ;
}
return isfee ;
}
# endregion
#region 委托业务费用加锁
/// <summary>
/// 委托业务费用加锁
/// </summary>
/// <param name="tempBSNO">委托业务编号</param>
/// <returns>值等于1表示加锁成功 值不等于1表示加锁失败</returns>
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 委托业务费用解锁
/// <summary>
/// 委托业务费用解锁
/// </summary>
/// <param name="tempBSNO">委托业务编号</param>
/// <returns>值等于1表示解锁成功 值不等于1表示解锁失败</returns>
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
public static DBResult ISMUSTBE ( List < MsOpTruckBulk > headList , string companyid )
{
var result = new DBResult ( ) ;
result . Success = true ;
var BSTYPE = "陆运普货订单" ;
if ( headList [ 0 ] . TRANSTYPE = = "集装箱" ) BSTYPE = "陆运集运订单" ;
var mustbelist = MsCodeOpMustFieldDAL . GetDataList ( "BSTYPE='" + BSTYPE + "'" , companyid ) ;
foreach ( var headData in headList )
{
foreach ( var enumValue in mustbelist )
{
if ( enumValue . FIELDNAME = = "ORDERNO" & & headData . ORDERNO = = "" )
{ result . Success = false ; result . Message = result . Message + "客户订单号不能为空;" ; }
if ( enumValue . FIELDNAME = = "SALE" & & headData . SALE = = "" )
{ result . Success = false ; result . Message = result . Message + "客户经理不能为空;" ; }
if ( enumValue . FIELDNAME = = "CUSTSERVICE" & & headData . CUSTSERVICE = = "" )
{ result . Success = false ; result . Message = result . Message + "运营不能为空;" ; }
if ( enumValue . FIELDNAME = = "OP" & & headData . OP = = "" )
{ result . Success = false ; result . Message = result . Message + "操作不能为空;" ; }
if ( enumValue . FIELDNAME = = "CUSTOMERNAME" & & headData . CUSTOMERNAME = = "" )
{ result . Success = false ; result . Message = result . Message + "委托单位不能为空;" ; }
if ( enumValue . FIELDNAME = = "CUSTATTN" & & headData . CUSTATTN = = "" )
{ result . Success = false ; result . Message = result . Message + "客户联系人不能为空;" ; }
if ( enumValue . FIELDNAME = = "GOODSNAME" & & headData . GOODSNAME = = "" )
{ result . Success = false ; result . Message = result . Message + "品名不能为空;" ; }
if ( enumValue . FIELDNAME = = "PORTLOAD" & & headData . PORTLOAD = = "" )
{ result . Success = false ; result . Message = result . Message + "启运地不能为空;" ; }
if ( enumValue . FIELDNAME = = "PORTDISCHARGE" & & headData . PORTDISCHARGE = = "" )
{ result . Success = false ; result . Message = result . Message + "目的地不能为空;" ; }
if ( enumValue . FIELDNAME = = "CUSTTEL" & & headData . CUSTTEL = = "" )
{ result . Success = false ; result . Message = result . Message + "客户联系电话不能为空;" ; }
if ( enumValue . FIELDNAME = = "ETD" & & ( headData . ETD = = "" | | headData . ETD = = null ) )
{ result . Success = false ; result . Message = result . Message + "要求派车日期不能为空;" ; }
if ( enumValue . FIELDNAME = = "ETA" & & ( headData . ETA = = "" | | headData . ETA = = null ) )
{ result . Success = false ; result . Message = result . Message + "要求到货日期不能为空;" ; }
if ( enumValue . FIELDNAME = = "CONSIGNEENAME" & & ( headData . CONSIGNEENAME = = "" | | headData . CONSIGNEENAME = = null ) )
{ result . Success = false ; result . Message = result . Message + "收货单位不能为空;" ; }
if ( enumValue . FIELDNAME = = "CONSIGNEEADDR" & & ( headData . CONSIGNEEADDR = = "" | | headData . CONSIGNEEADDR = = null ) )
{ result . Success = false ; result . Message = result . Message + "收货地址不能为空;" ; }
if ( enumValue . FIELDNAME = = "CONSIGNEEATTN" & & ( headData . CONSIGNEEATTN = = "" | | headData . CONSIGNEEATTN = = null ) )
{ result . Success = false ; result . Message = result . Message + "收货联系人不能为空;" ; }
if ( enumValue . FIELDNAME = = "CONSIGNEETEL" & & ( headData . CONSIGNEETEL = = "" | | headData . CONSIGNEETEL = = null ) )
{ result . Success = false ; result . Message = result . Message + "收货电话不能为空;" ; }
}
}
return result ;
}
#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]='modOpTruckBulkList' 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.OP='" + username + "' OR op_truck_bulk.CREATEUSER='" + userid + "' OR op_truck_bulk.SALE='" + username + "' OR op_truck_bulk.CUSTSERVICE='" + username + "')" ;
}
else if ( visiblerange = = "3" )
{
str = " (op_truck_bulk.OP='" + username + "' OR op_truck_bulk.CREATEUSER='" + userid + "' OR op_truck_bulk.SALE='" + username + "' OR op_truck_bulk.CUSTSERVICE='" + username + "')" ;
}
else if ( visiblerange = = "2" )
{
var rangeDa = new RangeDA ( ) ;
var deptname = rangeDa . GetDEPTNAME ( userid ) ;
str = " (op_truck_bulk.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.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 = = "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.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "' " ;
}
else
{
str = str + " or op_truck_bulk.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "' " ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else
{
str = " (UPPER(op_truck_bulk.Corpid)='" + companyid + "') " ;
}
}
else if ( visiblerange = = "6" )
{
if ( tb = = "index" )
{
var opstr = "" ;
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 ( opstr ! = "" ) opstr = opstr + ")" ;
reader . Close ( ) ;
}
if ( opstr = = "" ) opstr = "('" + username + "')" ;
str = " (op_truck_bulk.OP in " + opstr + " or op_truck_bulk.SALE in " + opstr + " or op_truck_bulk.CUSTSERVICE IN " + opstr + " or op_truck_bulk.CREATEUSER IN " + opstr + " )" ;
}
else
{
str = " (UPPER(op_truck_bulk.Corpid)='" + companyid + "' ) " ;
}
}
else if ( visiblerange = = "1" )
{
str = " (op_truck_bulk.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR op_truck_bulk.CREATEUSER in (select USERID from user_company where COMPANYID='" + companyid + "'))" ;
}
else if ( visiblerange = = "0" )
{
str = " 1=1 " ;
}
return str ;
}
public static string GetRpRangDAStr ( 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]='modOpTruckBulkList' 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 = " (B.OP='" + username + "' OR B.CREATEUSER='" + userid + "' OR B.SALE='" + username + "' OR B.CUSTSERVICE='" + username + "')" ;
}
else if ( visiblerange = = "3" )
{
str = " (B.OP='" + username + "' OR B.CREATEUSER='" + userid + "' OR B.SALE='" + username + "' OR B.CUSTSERVICE='" + username + "')" ;
}
else if ( visiblerange = = "2" )
{
var rangeDa = new RangeDA ( ) ;
var deptname = rangeDa . GetDEPTNAME ( userid ) ;
str = " (B.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 B.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 = = "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 = " (B.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "' " ;
}
else
{
str = str + " or B.Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "' " ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else
{
str = " (UPPER(B.Corpid)='" + companyid + "') " ;
}
}
else if ( visiblerange = = "6" )
{
if ( tb = = "index" )
{
var opstr = "" ;
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 ( opstr ! = "" ) opstr = opstr + ")" ;
reader . Close ( ) ;
}
if ( opstr = = "" ) opstr = "('" + username + "')" ;
str = " (B.OP in " + opstr + " or B.SALE in " + opstr + " or B.CUSTSERVICE IN " + opstr + " or B.CREATEUSER IN " + opstr + " )" ;
}
else
{
str = " (UPPER(B.Corpid)='" + companyid + "' ) " ;
}
}
else if ( visiblerange = = "1" )
{
str = " (B.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "'))"
+ " OR B.CREATEUSER in (select USERID from user_company where COMPANYID='" + companyid + "'))" ;
}
else if ( visiblerange = = "0" )
{
str = " 1=1 " ;
}
return str ;
}
# endregion
}
}