using System ;
using System.Data ;
using System.Collections.Generic ;
using System.Text ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
using DSWeb.Areas.CommMng.Models ;
using HcUtility.Comm ;
using DSWeb.MvcShipping.Models.WMSNew ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.MvcShipping.Models.MsStevedores ;
using DSWeb.MvcShipping.DAL.MsSysParamSet ;
using System.Data.SqlClient ;
using DSWeb.DataAccess ;
using DSWeb.EntityDA ;
using System.Linq ;
using System.Data.Common ;
using System.Configuration ;
using DSWeb.MvcShipping.Models.MsOpCtnr ;
using DSWeb.MvcShipping.Helper.Repository ;
using DSWeb.MvcShipping.Models.MsOpSeae ;
namespace DSWeb.MvcShipping.DAL.MsOpCtnrDAL
{
public class MsOpCtnrDAL
{
static public List < CtnrList > GetDataList ( string strCondition , int start , int limit , string userid , string username , string companyid , out int total , string sort = null )
{
var rangstr = GetRangDAStr ( "index" , userid , username , companyid ) ;
if ( ! string . IsNullOrEmpty ( rangstr ) )
{
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strCondition = strCondition + " and " + rangstr ;
}
else
{
strCondition = rangstr ;
}
}
var strSql = new StringBuilder ( ) ;
strSql . Append ( @"select " ) ;
strSql . Append ( " BSNO,BLTYPE,BSSTATUS,CUSTNO, " ) ;
strSql . Append ( " BILLNO,CUSTOMERNAME,CNTRSOURCE,PORT,YARD,[MBLNO],[BSSOURCE],[BSSOURCEDETAIL],[VESSEL],[VOYNO],[ETD],[SALE],[PORTLOAD],[PORTDISCHARGE],[BillFeeStatus],[SALECORPID]," ) ;
strSql . Append ( " convert(char(10),BSDATE,20) AS BSDATE,convert(char(10),ACCDATE,20) AS ACCDATE," ) ;
strSql . Append ( " OP,CORPID,DRFEENAME,CRFEENAME,REMARK,FEESTATUS,RETURNTYPE,RETURNDATE,RETURNYARD," ) ;
strSql . Append ( "(SELECT top 1 SHOWNAME FROM dbo.[user] WHERE(GID = CREATEUSER)) AS CREATEUSER," ) ;
strSql . Append ( "(SELECT top 1 SHOWNAME FROM dbo.[user] WHERE(GID = MODIFIEDUSER)) AS MODIFIEDUSER," ) ;
strSql . Append ( "dbo.F_GetBillDrFeeStatus(BSNO) DRFEESTATUS,(CASE BSSTATUS WHEN 1 THEN '锁定' else '未锁定' end) as BSSTATUSREF ," ) ;
strSql . Append ( "dbo.F_GetBillCrFeeStatus(BSNO) CRFEESTATUS,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF," ) ;
//strSql.Append("CASE FEESTATUS WHEN 0 THEN '未锁定' ELSE '已锁定' END AS FEESTATUS,");
strSql . Append ( " convert(char(10),CREATETIME,20) AS CREATETIME,convert(char(10),MODIFIEDTIME,20) AS MODIFIEDTIME,CNTRTOTAL " ) ;
strSql . Append ( ",(CASE ISCREATEFEE WHEN 1 THEN '是' ELSE '' END) ISCREATEFEEREF " ) ;
strSql . Append ( " from op_ctnmng where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " and " + strCondition ) ;
}
if ( ! string . IsNullOrEmpty ( sort ) )
{
var so = JsonConvert . Deserialize < List < SortObject > > ( sort ) ;
string orderbyStr = " order by " ;
foreach ( var s in so )
{
orderbyStr + = s . property + " " + s . direction + "," ;
}
orderbyStr = orderbyStr . Substring ( 0 , orderbyStr . Length - 1 ) ;
strSql . Append ( orderbyStr ) ;
}
else
{
strSql . Append ( " order by BSDATE DESC " ) ;
}
int totalCount = 0 ;
StringBuilder sb = PagerHelper . PageSQL ( strSql . ToString ( ) , start , limit , out totalCount ) ;
total = totalCount ;
return SetData ( sb ) ;
}
private static List < CtnrList > SetData ( StringBuilder strSql )
{
var headList = new List < CtnrList > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
CtnrList data = new CtnrList ( ) ;
#region Set DB data to Object
data . BSNO = reader [ "BSNO" ] . ToString ( ) ;
data . BLTYPE = reader [ "BLTYPE" ] . ToString ( ) ;
data . BSSTATUS = Convert . ToBoolean ( ( reader [ "BSSTATUS" ] ) ) ;
data . FEESTATUS = Convert . ToBoolean ( ( reader [ "FEESTATUS" ] ) ) ;
data . BSSTATUSREF = Convert . ToString ( reader [ "BSSTATUSREF" ] ) ; // 业务状态
data . FEESTATUSREF = Convert . ToString ( reader [ "FEESTATUSREF" ] ) ; // 费用状态
data . DRFEESTATUS = getfeestatus ( Convert . ToString ( reader [ "DRFEESTATUS" ] ) ) ;
data . CRFEESTATUS = getfeestatus ( Convert . ToString ( reader [ "CRFEESTATUS" ] ) ) ;
data . CUSTNO = reader [ "CUSTNO" ] . ToString ( ) ;
data . BILLNO = reader [ "BILLNO" ] . ToString ( ) ;
data . CUSTNO = reader [ "CUSTNO" ] . ToString ( ) ;
data . BILLNO = reader [ "BILLNO" ] . ToString ( ) ;
data . CUSTOMERNAME = reader [ "CUSTOMERNAME" ] . ToString ( ) ;
data . CNTRSOURCE = reader [ "CNTRSOURCE" ] . ToString ( ) ;
data . BSDATE = reader [ "BSDATE" ] . ToString ( ) ;
data . ACCDATE = reader [ "ACCDATE" ] . ToString ( ) ;
data . OP = reader [ "OP" ] . ToString ( ) ;
data . CORPID = reader [ "CORPID" ] . ToString ( ) ;
data . PORT = reader [ "PORT" ] . ToString ( ) ;
data . YARD = reader [ "YARD" ] . ToString ( ) ;
data . DRFEENAME = reader [ "DRFEENAME" ] . ToString ( ) ;
data . CRFEENAME = reader [ "CRFEENAME" ] . ToString ( ) ;
data . REMARK = reader [ "REMARK" ] . ToString ( ) ;
data . CREATEUSER = reader [ "CREATEUSER" ] . ToString ( ) ;
data . CREATETIME = reader [ "CREATETIME" ] . ToString ( ) ;
data . MODIFIEDUSER = reader [ "MODIFIEDUSER" ] . ToString ( ) ;
data . MODIFIEDTIME = reader [ "MODIFIEDTIME" ] . ToString ( ) ;
data . MBLNO = reader [ "MBLNO" ] . ToString ( ) ;
data . BSSOURCE = reader [ "BSSOURCE" ] . ToString ( ) ;
data . BSSOURCEDETAIL = reader [ "BSSOURCEDETAIL" ] . ToString ( ) ;
data . VESSEL = reader [ "VESSEL" ] . ToString ( ) ;
data . VOYNO = reader [ "VOYNO" ] . ToString ( ) ;
if ( reader [ "ETD" ] ! = DBNull . Value )
data . ETD = Convert . ToDateTime ( reader [ "ETD" ] ) . ToString ( "yyyy-MM-dd" ) ; //到港日期
data . SALE = reader [ "SALE" ] . ToString ( ) ;
data . PORTLOAD = reader [ "PORTLOAD" ] . ToString ( ) ;
data . PORTDISCHARGE = reader [ "PORTDISCHARGE" ] . ToString ( ) ;
data . BillFeeStatus = reader [ "BillFeeStatus" ] . ToString ( ) ;
data . SALECORPID = reader [ "SALECORPID" ] . ToString ( ) ;
if ( reader [ "RETURNDATE" ] ! = DBNull . Value )
data . RETURNDATE = Convert . ToDateTime ( reader [ "RETURNDATE" ] ) . ToString ( "yyyy-MM-dd" ) ; //到港日期
data . RETURNTYPE = reader [ "RETURNTYPE" ] . ToString ( ) ;
data . CNTRTOTAL = reader [ "CNTRTOTAL" ] . ToString ( ) ;
data . ISCREATEFEEREF = reader [ "ISCREATEFEEREF" ] . ToString ( ) ;
data . RETURNYARD = reader [ "RETURNYARD" ] . ToString ( ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
public static List < CtnrDyDetail > GetDynaList ( string strCondition , string sort )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select CNTRNO,CTNSTATUS," ) ;
strSql . Append ( "convert(char(10),CTNSTATUSTIME,20) AS CTNSTATUSTIME, " ) ;
strSql . Append ( "PORT,YARD,CTNEF,CUSTNO,MBLNO,REMARK " ) ;
strSql . Append ( ",(CASE CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF " ) ;
strSql . Append ( " FROM op_ctnmng_ctnstatus " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition . Replace ( "~" , "" ) ) ;
}
strSql . Append ( " GROUP BY CNTRNO,CTNSTATUS," ) ;
strSql . Append ( "convert(char(10),CTNSTATUSTIME,20), " ) ;
strSql . Append ( "PORT,YARD,CTNEF,CUSTNO,MBLNO,REMARK " ) ;
strSql . Append ( ",(CASE CTNEF WHEN 'F' THEN '重' ELSE '空' END) " ) ;
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by CTNSTATUSTIME DESC " ) ;
}
return SetCtnrDyDetailData ( strSql ) ;
}
public static List < CtnrDetail > GetCtnrList ( string strCondition , string sort )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select c.CTNGID,c.CTNALL,c.CNTRNO,c.CNTRSOURCE,s.CTNSTATUS," ) ;
strSql . Append ( "convert(char(10),s.CTNSTATUSTIME,20) AS CTNSTATUSTIME, " ) ;
strSql . Append ( "s.PORT,s.YARD,s.CTNEF,s.CUSTNO,s.MBLNO,s.REMARK,c.ISSTOP " ) ;
strSql . Append ( ",(CASE s.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF " ) ;
strSql . Append ( ",(CASE c.ISSTOP WHEN 1 THEN '停用' ELSE '' END) ISSTOPREF " ) ;
strSql . Append ( ",c.ISBERETURN,(CASE c.ISBERETURN WHEN 1 THEN '是' ELSE '' END) ISBERETURNREF " ) ;
strSql . Append ( " FROM op_ctnmng_ctndetail C " ) ;
strSql . Append ( " left join (SELECT [CTNGID],[CNTRNO],[CTNSTATUS],[CTNSTATUSTIME],[PORT],[YARD],[CTNEF],[CUSTNO],[MBLNO],REMARK,ROW_NUMBER() OVER ( PARTITION BY CTNGID ORDER BY CTNSTATUSTIME DESC,CREATETIME DESC ) rid from op_ctnmng_ctnstatus) s " ) ;
strSql . Append ( " on (s.rid=1 and s.CTNGID=c.CTNGID) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition . Replace ( "~" , "" ) ) ;
}
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by CTNGID " ) ;
}
return SetCtnrDetailData ( strSql ) ;
}
public static List < CtnrDetailAX > GetDetailList ( string strCondition , string sort )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select mng.BSNO,detail.CTNGID,detail.CTNALL,detail.CNTRNO,detail.CNTRSOURCE,S.CTNSTATUS," ) ;
strSql . Append ( "convert(char(10),S.CTNSTATUSTIME,20) AS CTNSTATUSTIME, " ) ;
strSql . Append ( "S.PORT,S.YARD,S.CTNEF,S.CUSTNO,S.MBLNO,S.REMARK,DR,CR,(SELECT SUM(CR) FROM op_ctnmng_detail WHERE CTNGID=detail.CTNGID) MXCR,DRFEENAME,CRFEENAME " ) ;
strSql . Append ( ",(CASE S.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF,detail.RETURNYARD " ) ;
strSql . Append ( " FROM op_ctnmng_ctndetail detail left join op_ctnmng_detail mng " ) ;
strSql . Append ( " on detail.CTNGID=mng.CTNGID " ) ;
strSql . Append ( " left join op_ctnmng_ctnstatus s on (s.CTNGID=detail.CTNGID AND s.BSNO=mng.BSNO) " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition . Replace ( "~" , "" ) ) ;
}
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by detail.CTNGID " ) ;
}
return SetCtnrDetailAXData ( strSql ) ;
}
public static List < CtnrDetail > GetSearchDetailList ( string strCondition , string sort )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select detail.CTNGID,detail.CTNALL,detail.CNTRNO,detail.CNTRSOURCE,detail.CTNSTATUS," ) ;
strSql . Append ( "convert(char(10),detail.CTNSTATUSTIME,20) AS CTNSTATUSTIME, " ) ;
strSql . Append ( "detail.PORT,detail.YARD,detail.CTNEF,detail.CUSTNO,detail.MBLNO,detail.REMARK,detail.ISSTOP " ) ;
strSql . Append ( ",(CASE detail.CTNEF WHEN 'F' THEN '重' ELSE '空' END) CTNEFREF " ) ;
strSql . Append ( ",(CASE detail.ISSTOP WHEN 1 THEN '停用' ELSE '' END) ISSTOPREF " ) ;
strSql . Append ( ",detail.ISBERETURN,(CASE detail.ISBERETURN WHEN 1 THEN '是' ELSE '' END) ISBERETURNREF " ) ;
strSql . Append ( " FROM op_ctnmng_ctndetail detail left join op_ctnmng_detail mng " ) ;
strSql . Append ( " on detail.CTNGID=mng.CTNGID " ) ;
strSql . Append ( " left join op_ctnmng ctn on ctn.bsno = mng.bsno " ) ;
if ( ! string . IsNullOrEmpty ( strCondition ) )
{
strSql . Append ( " where " + strCondition . Replace ( "~" , "" ) ) ;
}
var sortstring = DatasetSort . Getsortstring ( sort ) ;
if ( ! string . IsNullOrEmpty ( sortstring ) )
{
strSql . Append ( " order by " + sortstring ) ;
}
else
{
strSql . Append ( " order by detail.CTNGID " ) ;
}
return SetCtnrDetailData ( strSql ) ;
}
public static bool Delete ( List < CtnrList > list , out string msg )
{
string message ;
string ids = "" ;
bool result = true ;
foreach ( var m in list )
{
ids + = "'" + m . BSNO + "'," ;
}
ids = ids . Substring ( 0 , ids . Length - 1 ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
foreach ( var items in list )
{
if ( items . BLTYPE = = "买箱" | | items . BLTYPE = = "租入" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "DELETE FROM op_ctnmng_ctndetail where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( items . BLTYPE = = "卖箱" | | items . BLTYPE = = "退租" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( items . BLTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( items . BLTYPE = = "租出" & & items . RETURNTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + items . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
var strSqlMng = new StringBuilder ( ) ;
strSqlMng . Append ( "DELETE FROM op_ctnmng_detail WHERE BSNO='" + items . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlMng . ToString ( ) , null ) ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "DELETE FROM op_ctnmng WHERE BSNO='" + items . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql . ToString ( ) , null ) ;
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "DELETE FROM op_ctnmng_ctnstatus WHERE BSNO='" + items . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
}
message = "删除成功!" ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result = false ;
message = ee . Message ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
msg = message ;
return result ;
}
public static bool DeleteAll ( string BSNO , bool isdeletectn )
{
bool result = true ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
if ( isdeletectn )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "DELETE FROM op_ctnmng_ctndetail WHERE BSNO = '" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else {
var strSqlCtnr2 = new StringBuilder ( ) ;
strSqlCtnr2 . Append ( "update op_ctnmng_ctndetail set ISSTOP=0 WHERE BSNO = '" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr2 . ToString ( ) , null ) ;
}
var strSqlMng = new StringBuilder ( ) ;
strSqlMng . Append ( "DELETE FROM op_ctnmng_detail WHERE BSNO ='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlMng . ToString ( ) , null ) ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "DELETE FROM op_ctnmng WHERE BSNO ='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql . ToString ( ) , null ) ;
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "DELETE FROM op_ctnmng_ctnstatus WHERE BSNO ='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result = false ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static bool DeleteAll ( CtnrList head )
{
bool result = true ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
if ( head . BLTYPE = = "卖箱" | | head . BLTYPE = = "退租" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( head . BLTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( head . BLTYPE = = "租出" & & head . RETURNTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where BSNO='" + head . BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
var strSqlMng = new StringBuilder ( ) ;
strSqlMng . Append ( "DELETE FROM op_ctnmng_detail WHERE BSNO ='" + head . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlMng . ToString ( ) , null ) ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "DELETE FROM op_ctnmng WHERE BSNO ='" + head . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql . ToString ( ) , null ) ;
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "DELETE FROM op_ctnmng_ctnstatus WHERE BSNO ='" + head . BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result = false ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static bool UpCtnStop ( string bSNO , List < CtnrDetail > detailBodyList )
{
bool result = true ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
foreach ( var item in detailBodyList ) {
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISSTOP=1,RETURNYARD='" + item . RETURNYARD + "' WHERE CTNGID = '" + item . CTNGID + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result = false ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static bool UpCtnIsReturn ( string bSNO , List < CtnrDetail > detailBodyList , string isreturn = "1" )
{
bool result = true ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
foreach ( var item in detailBodyList )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=1,RETURNYARD='" + item . RETURNYARD + "' WHERE CTNGID = '" + item . CTNGID + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result = false ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static DBResult DeleteCtnDetail ( List < CtnrDetail > list , string BSNO , bool isdeletectn )
{
var result = new DBResult ( ) ;
string ids = "" ;
foreach ( var m in list )
{
ids + = "'" + m . CTNGID + "'," ;
}
ids = ids . Substring ( 0 , ids . Length - 1 ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
if ( isdeletectn )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "DELETE FROM op_ctnmng_ctndetail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else {
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID IN (" + ids + ") " ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
var strSqlMng = new StringBuilder ( ) ;
strSqlMng . Append ( "DELETE FROM op_ctnmng_detail WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlMng . ToString ( ) , null ) ;
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "DELETE FROM op_ctnmng_ctnstatus WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
result . Success = true ;
result . Message = "删除成功" ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result . Success = false ;
result . Message = "删除出错," + ee . Message ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static DBResult SaveSellDetail ( CtnrList head , List < CtnrDetail > list , string BSNO , string USERID )
{
var result = new DBResult ( ) ;
string ids = "" ;
foreach ( var m in list )
{
ids + = "'" + m . CTNGID + "'," ;
}
ids = ids . Substring ( 0 , ids . Length - 1 ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "update op_ctnmng_ctnstatus set BSNO='' WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
foreach ( CtnrDetail item in list )
{
CtnrDyDetail dyDetail = new CtnrDyDetail ( ) ;
dyDetail . GID = Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
dyDetail . CNTRNO = item . CNTRNO ;
dyDetail . CREATETIME = DateTime . Now . ToString ( "yyyy - MM - dd HH: mm:ss" ) ;
dyDetail . CREATEUSER = USERID ;
dyDetail . CTNEF = item . CTNEF ;
dyDetail . CTNGID = item . CTNGID ;
dyDetail . CTNSTATUS = item . CTNSTATUS ;
dyDetail . CTNSTATUSTIME = item . CTNSTATUSTIME ;
dyDetail . MBLNO = item . MBLNO ;
dyDetail . YARD = item . YARD ;
dyDetail . PORT = item . PORT ;
dyDetail . CUSTNO = item . CUSTNO ;
dyDetail . REMARK = item . REMARK ;
dyDetail . BSNO = head . BSNO ;
var modbDy = new ModelObjectRepository ( ) ;
dyDetail . ModelUIStatus = "I" ;
dyDetail . DbOperationType = DbOperationType . DbotIns ;
result = modbDy . Save ( dyDetail ) ;
}
result . Success = true ;
result . Message = "删除成功" ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result . Success = false ;
result . Message = "删除出错," + ee . Message ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static DBResult DeleteCtnDetail ( CtnrList head , List < CtnrDetail > list , string BSNO , bool isdeletectn )
{
var result = new DBResult ( ) ;
string ids = "" ;
foreach ( var m in list )
{
ids + = "'" + m . CTNGID + "'," ;
}
ids = ids . Substring ( 0 , ids . Length - 1 ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
if ( head . BLTYPE = = "卖箱" | | head . BLTYPE = = "退租" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISSTOP=0 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( head . BLTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=1 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
else if ( head . BLTYPE = = "租出" & & head . RETURNTYPE = = "返箱" )
{
var strSqlCtnr = new StringBuilder ( ) ;
strSqlCtnr . Append ( "update op_ctnmng_ctndetail set ISBERETURN=0 where CTNGID in(select CTNGID from op_ctnmng_detail where CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "')" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlCtnr . ToString ( ) , null ) ;
}
var strSqlMng = new StringBuilder ( ) ;
strSqlMng . Append ( "DELETE FROM op_ctnmng_detail WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSqlMng . ToString ( ) , null ) ;
var strSql2 = new StringBuilder ( ) ;
strSql2 . Append ( "DELETE FROM op_ctnmng_ctnstatus WHERE CTNGID IN (" + ids + ") AND BSNO='" + BSNO + "'" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , strSql2 . ToString ( ) , null ) ;
result . Success = true ;
result . Message = "删除成功" ;
sqlTran . Commit ( ) ;
}
catch ( Exception ee )
{
result . Success = false ;
result . Message = "删除出错," + ee . Message ;
sqlTran . Rollback ( ) ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return result ;
}
public static bool DeleteMng ( string BSNO , out string msg )
{
string message ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
string DelSql = "DELETE FROM op_ctnmng WHERE BSNO ='" + BSNO + "'" ;
bool result = false ;
try
{
result = db . ExecuteNonQuery ( CommandType . Text , DelSql ) > 0 ;
if ( result )
{
message = "删除成功!" ;
}
else
{
message = "删除失败!" ;
}
}
catch ( Exception ex )
{
result = false ;
message = ex . Message ;
}
msg = message ;
return result ;
}
public static CtnrList GetData ( string conditions , string userid , string username , string companyid )
{
int total = 0 ;
var TList = GetDataList ( conditions , 0 , 1 , userid , username , companyid , out total ) ;
CtnrList ctnr = new CtnrList ( ) ;
if ( TList . Count > 0 )
{
ctnr = GetDataList ( conditions , 0 , 1 , userid , username , companyid , out total ) [ 0 ] ;
}
return ctnr ;
}
static public CtnrDetailAX GetCtnrDetailData ( string condition )
{
var _t = "" ;
var list = GetDetailList ( condition , _t ) ;
if ( list . Count > 0 )
return list [ 0 ] ;
return new CtnrDetailAX ( ) ;
}
private static List < CtnrDetailAX > SetCtnrDetailAXData ( StringBuilder strSql )
{
var headList = new List < CtnrDetailAX > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
CtnrDetailAX data = new CtnrDetailAX ( ) ;
#region Set DB data to Object
data . BSNO = Convert . ToString ( reader [ "BSNO" ] ) ;
data . CTNGID = Convert . ToString ( reader [ "CTNGID" ] ) ;
data . CTNALL = Convert . ToString ( reader [ "CTNALL" ] ) ;
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CNTRSOURCE = Convert . ToString ( reader [ "CNTRSOURCE" ] ) ;
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CTNSTATUS = Convert . ToString ( reader [ "CTNSTATUS" ] ) ;
data . CTNSTATUSTIME = Convert . ToString ( reader [ "CTNSTATUSTIME" ] ) ;
data . PORT = Convert . ToString ( reader [ "PORT" ] ) ;
data . YARD = Convert . ToString ( reader [ "YARD" ] ) ;
data . CTNEF = Convert . ToString ( reader [ "CTNEF" ] ) ;
data . CUSTNO = Convert . ToString ( reader [ "CUSTNO" ] ) ;
data . MBLNO = Convert . ToString ( reader [ "MBLNO" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . DRFEENAME = Convert . ToString ( reader [ "DRFEENAME" ] ) ;
data . CRFEENAME = Convert . ToString ( reader [ "CRFEENAME" ] ) ;
data . DR = Convert . ToString ( reader [ "DR" ] ) ;
data . CR = Convert . ToString ( reader [ "CR" ] ) ;
data . MXCR = Convert . ToString ( reader [ "MXCR" ] ) ;
data . CTNEFREF = Convert . ToString ( reader [ "CTNEFREF" ] ) ;
data . RETURNYARD = Convert . ToString ( reader [ "RETURNYARD" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < CtnrDyDetail > SetCtnrDyDetailData ( StringBuilder strSql )
{
var headList = new List < CtnrDyDetail > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
CtnrDyDetail data = new CtnrDyDetail ( ) ;
#region Set DB data to Object
//data.GID = Convert.ToString(reader["GID"]);
//data.CTNGID = Convert.ToString(reader["CTNGID"]);
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CTNSTATUS = Convert . ToString ( reader [ "CTNSTATUS" ] ) ;
data . CTNSTATUSTIME = Convert . ToString ( reader [ "CTNSTATUSTIME" ] ) ;
data . PORT = Convert . ToString ( reader [ "PORT" ] ) ;
data . YARD = Convert . ToString ( reader [ "YARD" ] ) ;
data . CTNEF = Convert . ToString ( reader [ "CTNEF" ] ) ;
data . CUSTNO = Convert . ToString ( reader [ "CUSTNO" ] ) ;
data . MBLNO = Convert . ToString ( reader [ "MBLNO" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . CTNEFREF = Convert . ToString ( reader [ "CTNEFREF" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
private static List < CtnrDetail > SetCtnrDetailData ( StringBuilder strSql )
{
var headList = new List < CtnrDetail > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
CtnrDetail data = new CtnrDetail ( ) ;
#region Set DB data to Object
data . CTNGID = Convert . ToString ( reader [ "CTNGID" ] ) ;
data . CTNALL = Convert . ToString ( reader [ "CTNALL" ] ) ;
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CNTRSOURCE = Convert . ToString ( reader [ "CNTRSOURCE" ] ) ;
data . CNTRNO = Convert . ToString ( reader [ "CNTRNO" ] ) ;
data . CTNSTATUS = Convert . ToString ( reader [ "CTNSTATUS" ] ) ;
data . CTNSTATUSTIME = Convert . ToString ( reader [ "CTNSTATUSTIME" ] ) ;
data . PORT = Convert . ToString ( reader [ "PORT" ] ) ;
data . YARD = Convert . ToString ( reader [ "YARD" ] ) ;
data . CTNEF = Convert . ToString ( reader [ "CTNEF" ] ) ;
data . CUSTNO = Convert . ToString ( reader [ "CUSTNO" ] ) ;
data . MBLNO = Convert . ToString ( reader [ "MBLNO" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
data . CTNEFREF = Convert . ToString ( reader [ "CTNEFREF" ] ) ;
if ( reader [ "ISSTOP" ] ! = DBNull . Value )
data . ISSTOP = Convert . ToBoolean ( reader [ "ISSTOP" ] ) ; //业务状态
data . ISSTOPREF = Convert . ToString ( reader [ "ISSTOPREF" ] ) ;
if ( reader [ "ISBERETURN" ] ! = DBNull . Value )
data . ISBERETURN = Convert . ToBoolean ( reader [ "ISBERETURN" ] ) ; //业务状态
data . ISBERETURNREF = Convert . ToString ( reader [ "ISBERETURNREF" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
#region 箱型
/// <summary>
/// 获取提单号下录入的箱型
/// </summary>
/// <returns></returns>
static public List < CodeCtnModel > GetCodeCtnList ( )
{
String strSql = @"SELECT DISTINCT CTN AS CTNALL FROM code_ctn" ;
return SetCodeCtnData ( strSql ) ;
}
private static List < CodeCtnModel > SetCodeCtnData ( String strSql )
{
var headList = new List < CodeCtnModel > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql ) )
{
while ( reader . Read ( ) )
{
CodeCtnModel data = new CodeCtnModel ( ) ;
#region Set DB data to Object
data . CTN = Convert . ToString ( reader [ "CTNALL" ] ) ;
# endregion
headList . Add ( data ) ;
}
reader . Close ( ) ;
}
return headList ;
}
# endregion
/// <summary>
/// 获取费用状态的显示文字
/// </summary>
/// <param name="feestatusint"></param>
/// <returns></returns>
public static string getfeestatus ( string feestatusint )
{
var result = "" ;
if ( feestatusint = = "0:" )
{
return "审核通过" ;
}
else if ( feestatusint = = "1:" )
{
return "录入状态" ;
}
else if ( feestatusint = = "2:" )
{
return "提交审核" ;
}
else if ( feestatusint = = "8:" )
{
return "部分结算" ;
}
else if ( feestatusint = = "9:" )
{
return "结算完毕" ;
}
else if ( feestatusint = = "" )
{
return "未录入" ;
}
else if ( feestatusint = = "3:" )
{
return "申请修改" ;
}
else if ( feestatusint = = "4:" )
{
return "申请删除" ;
}
else if ( feestatusint = = "6:" )
{
return "驳回提交" ;
}
else if ( feestatusint = = "7:" )
{
return "驳回申请" ;
}
else if ( feestatusint . IndexOf ( "9:" ) > - 1 )
{
return "部分结算" ;
}
else if ( feestatusint . IndexOf ( "8:" ) > - 1 )
{
return "部分结算" ;
}
else if ( feestatusint . IndexOf ( "0:" ) > - 1 )
{
return "部分审核" ;
}
else if ( feestatusint . IndexOf ( "2:" ) > - 1 )
{
return "部分提交" ;
}
else if ( feestatusint . IndexOf ( "6:" ) > - 1 )
{
return "驳回提交" ;
}
else if ( feestatusint . IndexOf ( "7:" ) > - 1 )
{
return "驳回申请" ;
}
return result ;
}
#region 权限范围
public static string GetRangDAStr ( string tb , string userid , string username , string companyid )
{
string str = "" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " VISIBLERANGE,OPERATERANGE,AUTHORITYID " ) ;
strSql . Append ( " from VW_User_Authority " ) ;
strSql . Append ( " where [NAME]='modCtnMng' and USERID='" + userid + "' and ISDELETE=0" ) ;
string visiblerange = "4" ;
string operaterange = "4" ;
string AUTHORITYID = "" ;
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" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( visiblerange = = "4" )
{
str = "1=2" ;
}
else if ( visiblerange = = "3" )
{
str = " (OP='" + username + "' OR SALE='" + username + "' OR CREATEUSER='" + userid + "')" ;
}
else if ( visiblerange = = "2" )
{
if ( tb = = "index" )
{
var rangeDa = new RangeDA ( ) ;
var deptid = rangeDa . GetDEPTGID ( userid ) ;
str = " (SALE in (select showname from vw_user where deptgid='" + deptid + "') OR OP in (select showname from vw_user where deptgid='" + deptid + "') OR CREATEUSER in (select userid from vw_user where deptgid='" + deptid + "'))" ;
//var userstr = new StringBuilder();
//userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
//Database userdb = DatabaseFactory.CreateDatabase();
//using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
//{
// str = "";
// while (reader.Read())
// {
// if (str == "")
// {
// str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.FRCUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
// }
// else
// {
// str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.CUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.DOC='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.FRCUSTSERVICE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
// };
// }
// str = str + ")";
// reader.Close();
//}
}
else
{
str = " UPPER(CORPID)='" + companyid + "'" ;
}
}
else if ( visiblerange = = "5" )
{
if ( tb = = "index" )
{
var userstr = new StringBuilder ( ) ;
userstr . Append ( " select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1" ) ;
Database userdb = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = userdb . ExecuteReader ( CommandType . Text , userstr . ToString ( ) ) )
{
str = "" ;
while ( reader . Read ( ) )
{
if ( str = = "" )
{
str = " (Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "'" ;
}
else
{
str = str + " or Corpid='" + Convert . ToString ( reader [ "COMPANYID" ] ) + "'" ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else
{
str = " UPPER(Corpid)='" + companyid + "'" ;
}
}
else if ( visiblerange = = "6" )
{
if ( tb = = "index" )
{
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 ( ) ) )
{
str = "" ;
while ( reader . Read ( ) )
{
if ( str = = "" )
{
str = " (SALE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR OP='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR CREATEUSER='" + Convert . ToString ( reader [ "OPID" ] ) + "' " ;
}
else
{
str = str + " or SALE='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' or OP='" + Convert . ToString ( reader [ "SHOWNAME" ] ) + "' OR CREATEUSER='" + Convert . ToString ( reader [ "OPID" ] ) + "'" ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else
{
str = " UPPER(Corpid)='" + companyid + "'" ;
}
}
else if ( visiblerange = = "1" )
{
str = " UPPER(Corpid)='" + companyid + "'" ;
}
return str ;
}
# endregion
#region 生成应收应付费用
public static bool CreateCost ( CtnrList head , List < CtnrDetailAX > CtnrListAX , string userid , out string msg )
{
//判断该单号是否已生成过费用
Database db = DatabaseFactory . CreateDatabase ( ) ;
string check = @"SELECT count(*) from op_ctnmng where ISCREATEFEE=1 and BSNO = '" + head . BSNO + "' " ;
if ( Convert . ToInt32 ( db . ExecuteScalar ( CommandType . Text , check ) ) > 0 )
{
msg = "已经生成过费用,不允许重复生成!" ;
return false ;
}
decimal dr = 0 ;
decimal cr = 0 ;
string crFeeName = "" ;
string drFeeName = "" ;
List < CtnrCost > list = new List < CtnrCost > ( ) ;
foreach ( var item in CtnrListAX )
{
//dr += Convert.ToDecimal(item.DR);
//cr += Convert.ToDecimal(item.CR);
//crFeeName = item.DRFEENAME;
//drFeeName = item.CRFEENAME;
CtnrCost s = new CtnrCost ( ) ;
s . BSNO = head . BSNO ;
s . CUSTOMERNAME = head . CUSTOMERNAME ;
s . FEENAME = crFeeName ;
s . FEE = cr ;
s . REMARK = item . CNTRNO ;
s . FEETYPE = "2" ;
list . Add ( s ) ;
CtnrCost t = new CtnrCost ( ) ;
t . BSNO = head . BSNO ;
t . CUSTOMERNAME = head . CUSTOMERNAME ;
t . FEENAME = drFeeName ;
t . FEE = dr ;
t . REMARK = item . CNTRNO ;
t . FEETYPE = "1" ;
list . Add ( t ) ;
}
bool rst = false ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
foreach ( var cm in list )
{
//if (cm.FEE > 0)
//{
StringBuilder sb = new StringBuilder ( ) ;
sb . Append ( @"insert into ch_fee (GID,BSNO,FEETYPE,FEENAME,REMARK,CUSTOMERNAME,UNIT,UNITPRICE,QUANTITY," ) ;
sb . Append ( @"AMOUNT,CURRENCY,EXCHANGERATE,FEESTATUS,NOTAXAMOUNT,TAXUNITPRICE,ENTEROPERATOR,WMSOUTBSNO) " ) ;
sb . Append ( @" VALUES(" ) ;
sb . Append ( "'" + Guid . NewGuid ( ) + "'," ) ; //GID
sb . Append ( "'" + cm . BSNO + "'," ) ; //BSNO
sb . Append ( "'" + cm . FEETYPE + "', " ) ; //FEETYPE
sb . Append ( "'" + cm . FEENAME + "'," ) ; //FEENAME
sb . Append ( "'" + cm . REMARK + "'," ) ; //REMARK
sb . Append ( "'" + cm . CUSTOMERNAME + "'," ) ; //CUSTOMERNAME
sb . Append ( "'" + "单票" + "'," ) ; //UNIT
sb . Append ( cm . FEE + "," ) ; //UNITPRICE
sb . Append ( "1" + "," ) ; //QUANTITY
sb . Append ( cm . FEE + "," ) ; //AMOUNT
sb . Append ( "'" + "RMB" + "'," ) ; //CURRENCY
sb . Append ( "1" + "," ) ; //EXCHANGERATE
sb . Append ( "1" + "," ) ; //FEESTATUS
sb . Append ( cm . FEE + "," ) ; //NOTAXAMOUNT
sb . Append ( cm . FEE + "," ) ; //TAXUNITPRICE
sb . Append ( "'" + userid + "'," ) ; //ENTEROPERATOR
sb . Append ( "'" + head . BSNO + "'" ) ; //ENTEROPERATOR
sb . Append ( ")" ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , sb . ToString ( ) , null ) ;
//}
}
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , "update op_ctnmng set ISCREATEFEE=1 where BSNO='" + head . BSNO + "'" , null ) ;
sqlTran . Commit ( ) ;
msg = "生成成功!" ;
rst = true ;
}
catch ( Exception )
{
msg = "生成失败!" ;
sqlTran . Rollback ( ) ;
rst = false ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return rst ;
}
public static bool CancelCost ( CtnrList head , string userid , out string msg )
{
Database db = DatabaseFactory . CreateDatabase ( ) ;
bool rst = false ;
using ( SqlTransaction sqlTran = SqlHelper . BeginTransaction ( SqlHelper . ConnectionStringLocalTransaction ) )
{
try
{
StringBuilder sb = new StringBuilder ( ) ;
sb . Append ( "delete from ch_fee where BSNO = '" + head . BSNO + "' and WMSOUTBSNO='" + head . BSNO + "' " ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , sb . ToString ( ) , null ) ;
SqlHelper . ExecuteNonQuery ( sqlTran , CommandType . Text , "update op_ctnmng set ISCREATEFEE=0 where BSNO='" + head . BSNO + "'" , null ) ;
sqlTran . Commit ( ) ;
msg = "取消费用成功!" ;
rst = true ;
}
catch ( Exception )
{
msg = "取消费用失败!" ;
sqlTran . Rollback ( ) ;
rst = false ;
}
finally
{
SqlHelper . CloseConnection ( ) ;
sqlTran . Dispose ( ) ;
}
}
return rst ;
}
public static bool GetFeeCount ( string BSNO )
{
var isfee = false ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "Select count(*) as count " ) ;
strSql . Append ( " from ch_fee " ) ;
strSql . Append ( " where BSNO='" + BSNO + "'" ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
var evData = Convert . ToInt32 ( reader [ "count" ] ) ;
if ( evData > 0 ) { isfee = true ; } ;
}
reader . Close ( ) ;
}
return isfee ;
}
internal static void CtnBsAdd ( string bSNO , List < MsOpSeaeDetail > bodyList , string userid )
{
throw new NotImplementedException ( ) ;
}
# endregion
}
}