You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcContainer/DAL/MsOpCtnApply/MsOpCtnApplyDAL.cs

2453 lines
120 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcContainer.Models.MsOpPrice;
using DSWeb.MvcContainer.Models.MsOpCtnApply;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.MvcShipping.Models.MsChFee;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcContainer.DAL.MsOpCtnApply
{
public class MsOpCtnApplyDAL
{
#region Inquery DataList
static public List<OpCtnApply> GetDataList(int start, int limit, string strCondition, string pricetype, string companyid, string userid, string username, string sort = null)
{
var rangstr = GetRangDAStr(pricetype, userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
sortstring = sortstring.Replace("CTNNUMS", "(select count(*) from op_ctnapplyctnitems where AUDITSTATUS='生成业务卡' AND LINKGID=b.GID)");
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by INPUTTIME DESC ");
}
strSql.Append(@") as num , ");
strSql.Append(" [GID],[BSNO],[BSDATE],BSSTATUS,[SALE],[OP],[GOODSNAME],[GOODTYPE],[PORTLOAD],[PORTDISCHARGE]");
strSql.Append(",[CTNALL],[CTNNUM],[ISOWNERBOOKING],[CUSTOMERNAME],[FACTORYNAME],[FACTORYADDR],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[ISGOODSNAMESAME],[PREGOODSNAME],[CURGOODSNAME],[PRODUCTGOODSNAME],OWNERCTN");
strSql.Append(",[PH],[DENSITY],[UNNO],[DCLASS],[SDCLASS],[PACKINGGROUP],[ISPOLLUTEOCEAN],[MELTINGPOINT]");
strSql.Append(",[BOILINGPOINT],[FLASHPOINT],[IMDG],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[SUBMITBY],[SUBMITTIME]");
strSql.Append(",[AGENTINPUTBY],[CYCLEDAYS],[CHANGERATE],[FULL_CTN_FREE_STORAGE_DAY],[FULL_CTN_OVER_STORAGE_RATE]");
strSql.Append(",[CLEAR_CTN_FREE_STORAGE_DAY],[CLEAR_CTN_OVER_STORAGE_RATE],[NO_CLEAR_CTN_FREE_STORAGE_DAY]");
strSql.Append(",[NO_CLEAR_CTN_OVER_STORAGE_RATE],[CTN_PRICE],[CURRENCY],[CTN_INCOME],[LOAD_FREE_USECTNE_DAY],[LOAD_OVER_USECTNE_RATE]");
strSql.Append(",[DEST_FREE_USECTNE_DAY],[DEST_OVER_USECTNE_RATE],[COSTAUDITSTATUS],[COSTAUDITBY],[COSTAUDITTIME],[COSTSUBMITBY],[COSTSUBMITTIME]");
strSql.Append(",[COSTAUDITRESULT],[COMPANYID],PLANCTNDATE,[ACCAUDITSTATUS],[ACCAUDITBY],[ACCAUDITTIME],[ACCAUDITRESULT]");
strSql.Append(",[SLOAD_FREE_USECTNE_DAY],[SLOAD_OVER_USECTNE_RATE],[SDEST_FREE_USECTNE_DAY],[SDEST_OVER_USECTNE_RATE]");
strSql.Append(",[MNGAUDITRESULT],[AGENTNAME],ISPORTLOADDATE,[BSAUDITSTATUS],[BSAUDITBY],[BSAUDITTIME],[BSAUDITRESULT],ADDCTNSTATUS");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTAUDITBY) as COSTAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.ACCAUDITBY) as ACCAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.BSAUDITBY) as BSAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTSUBMITBY) as COSTSUBMITBYREF");
strSql.Append(",(select SUM(case CURRENCY when 'USD' THEN AMOUNT ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as USDCOST");
strSql.Append(",(select SUM(case when CURRENCY<>'USD' THEN AMOUNT*EXCHANGERATE ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as RMBCOST");
// strSql.Append(",(select count(*) from op_ctnbscard where applyno=b.bsno) as CTNNUMS");
strSql.Append(",(select count(*) from op_ctnapplyctnitems where AUDITSTATUS='生成业务卡' AND LINKGID=b.GID) as CTNNUMS");
strSql.Append(",[MNGAUDITSTATUS],[MNGAUDITBY],[MNGAUDITTIME],(select ShowName from [user] where GID=b.MNGAUDITBY) as MNGAUDITBYREF");
strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称)
strSql.Append(",isnull(DESTPORT_STATOIN,'') DESTPORT_STATOIN");//目的港还箱堆场
strSql.Append(",isnull(SERVICE,'') SERVICE ");//运输条款
strSql.Append(",isnull(NEEDBEHEATED,0)NEEDBEHEATED,isnull(EMPTYCTNALLOCATION,0) EMPTYCTNALLOCATION");//是否加热,空箱调拨
strSql.Append(",isnull(WEIGHT,0) WEIGHT ");//重量
strSql.Append(",dbo.trimdate(PREI_ETD)PREI_ETD ");//预计开船日期
strSql.Append(" from op_ctnapply b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); //
return SetData(strSql);
}
public static int getTotalCount(string strCondition, string pricetype, string companyid, string userid, string username)
{
var rangstr = GetRangDAStr(pricetype, userid, username, 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_ctnapply b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
static public string GetDataListStr(string strCondition, string pricetype, string companyid, string userid, string username, string sort = null)
{
var rangstr = GetRangDAStr(pricetype, userid, username, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[BSNO],[BSDATE],BSSTATUS,[SALE],[OP],[GOODSNAME],[GOODTYPE],[PORTLOAD],[PORTDISCHARGE]");
strSql.Append(",[CTNALL],[CTNNUM],[ISOWNERBOOKING],[CUSTOMERNAME],[FACTORYNAME],[FACTORYADDR],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[ISGOODSNAMESAME],[PREGOODSNAME],[CURGOODSNAME],[PRODUCTGOODSNAME],OWNERCTN");
strSql.Append(",[PH],[DENSITY],[UNNO],[DCLASS],[SDCLASS],[PACKINGGROUP],[ISPOLLUTEOCEAN],[MELTINGPOINT]");
strSql.Append(",[BOILINGPOINT],[FLASHPOINT],[IMDG],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[SUBMITBY],[SUBMITTIME]");
strSql.Append(",[AGENTINPUTBY],[CYCLEDAYS],[CHANGERATE],[FULL_CTN_FREE_STORAGE_DAY],[FULL_CTN_OVER_STORAGE_RATE]");
strSql.Append(",[CLEAR_CTN_FREE_STORAGE_DAY],[CLEAR_CTN_OVER_STORAGE_RATE],[NO_CLEAR_CTN_FREE_STORAGE_DAY]");
strSql.Append(",[NO_CLEAR_CTN_OVER_STORAGE_RATE],[CTN_PRICE],CURRENCY,[CTN_INCOME],[LOAD_FREE_USECTNE_DAY],[LOAD_OVER_USECTNE_RATE]");
strSql.Append(",[DEST_FREE_USECTNE_DAY],[DEST_OVER_USECTNE_RATE],[COSTAUDITSTATUS],[COSTAUDITBY],[COSTAUDITTIME],[COSTSUBMITBY],[COSTSUBMITTIME]");
strSql.Append(",[COSTAUDITRESULT],[COMPANYID],PLANCTNDATE,[ACCAUDITSTATUS],[ACCAUDITBY],[ACCAUDITTIME],[ACCAUDITRESULT]");
strSql.Append(",[SLOAD_FREE_USECTNE_DAY],[SLOAD_OVER_USECTNE_RATE],[SDEST_FREE_USECTNE_DAY],[SDEST_OVER_USECTNE_RATE]");
strSql.Append(",[MNGAUDITRESULT],[AGENTNAME],ISPORTLOADDATE,[BSAUDITSTATUS],[BSAUDITBY],[BSAUDITTIME],[BSAUDITRESULT],ADDCTNSTATUS");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTAUDITBY) as COSTAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.ACCAUDITBY) as ACCAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.BSAUDITBY) as BSAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTSUBMITBY) as COSTSUBMITBYREF");
strSql.Append(",(select SUM(case CURRENCY when 'USD' THEN AMOUNT ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as USDCOST");
strSql.Append(",(select SUM(case when CURRENCY<>'USD' THEN AMOUNT*EXCHANGERATE ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as RMBCOST");
strSql.Append(",[MNGAUDITSTATUS],[MNGAUDITBY],[MNGAUDITTIME],(select ShowName from [user] where GID=b.MNGAUDITBY) as MNGAUDITBYREF");
strSql.Append(" from op_ctnapply b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by INPUTTIME DESC ");
}
return strSql.ToString();
}
static public OpCtnApply GetData(string condition, string pricetype, string companyid, string userid,string username)
{
OpCtnApply data = null;
var list = GetDataList(0,1,condition, pricetype,companyid, userid,username);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new OpCtnApply();
data.COMPANYID = companyid;
}
return data;
}
static public OpCtnApply GetData(string condition, string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[BSNO],[BSDATE],BSSTATUS,[SALE],[OP],[GOODSNAME],[GOODTYPE],[PORTLOAD],[PORTDISCHARGE]");
strSql.Append(",[CTNALL],[CTNNUM],[ISOWNERBOOKING],[CUSTOMERNAME],[FACTORYNAME],[FACTORYADDR],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[ISGOODSNAMESAME],[PREGOODSNAME],[CURGOODSNAME],[PRODUCTGOODSNAME],OWNERCTN");
strSql.Append(",[PH],[DENSITY],[UNNO],[DCLASS],[SDCLASS],[PACKINGGROUP],[ISPOLLUTEOCEAN],[MELTINGPOINT]");
strSql.Append(",[BOILINGPOINT],[FLASHPOINT],[IMDG],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[SUBMITBY],[SUBMITTIME]");
strSql.Append(",[AGENTINPUTBY],[CYCLEDAYS],[CHANGERATE],[FULL_CTN_FREE_STORAGE_DAY],[FULL_CTN_OVER_STORAGE_RATE]");
strSql.Append(",[CLEAR_CTN_FREE_STORAGE_DAY],[CLEAR_CTN_OVER_STORAGE_RATE],[NO_CLEAR_CTN_FREE_STORAGE_DAY]");
strSql.Append(",[NO_CLEAR_CTN_OVER_STORAGE_RATE],[CTN_PRICE],CURRENCY,[CTN_INCOME],[LOAD_FREE_USECTNE_DAY],[LOAD_OVER_USECTNE_RATE]");
strSql.Append(",[DEST_FREE_USECTNE_DAY],[DEST_OVER_USECTNE_RATE],[COSTAUDITSTATUS],[COSTAUDITBY],[COSTAUDITTIME],[COSTSUBMITBY],[COSTSUBMITTIME]");
strSql.Append(",[COSTAUDITRESULT],[COMPANYID],PLANCTNDATE,[ACCAUDITSTATUS],[ACCAUDITBY],[ACCAUDITTIME],[ACCAUDITRESULT]");
strSql.Append(",[SLOAD_FREE_USECTNE_DAY],[SLOAD_OVER_USECTNE_RATE],[SDEST_FREE_USECTNE_DAY],[SDEST_OVER_USECTNE_RATE]");
strSql.Append(",[MNGAUDITRESULT],[AGENTNAME],ISPORTLOADDATE,[BSAUDITSTATUS],[BSAUDITBY],[BSAUDITTIME],[BSAUDITRESULT],ADDCTNSTATUS");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.ACCAUDITBY) as ACCAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.BSAUDITBY) as BSAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTAUDITBY) as COSTAUDITBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.COSTSUBMITBY) as COSTSUBMITBYREF");
strSql.Append(",(select SUM(case CURRENCY when 'USD' THEN AMOUNT ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as USDCOST");
strSql.Append(",(select SUM(case when CURRENCY<>'USD' THEN AMOUNT*EXCHANGERATE ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.GID) as RMBCOST");
strSql.Append(",(select count(*) from op_ctnbscard where applyno=b.bsno) as CTNNUMS");
strSql.Append(",[MNGAUDITSTATUS],[MNGAUDITBY],[MNGAUDITTIME],(select ShowName from [user] where GID=b.MNGAUDITBY) as MNGAUDITBYREF");
strSql.Append(",GOODSNAME+'_'+(select top 1 chemicalgoodsname from code_msds where CHEMICALCGOODSNAME=GOODSNAME) GOODSNAMEREF");//货物名称(含英文简称)
strSql.Append(",isnull(DESTPORT_STATOIN,'') DESTPORT_STATOIN");//目的港还箱堆场
strSql.Append(",isnull(SERVICE,'') SERVICE ");//运输条款
strSql.Append(",isnull(NEEDBEHEATED,0)NEEDBEHEATED,isnull(EMPTYCTNALLOCATION,0) EMPTYCTNALLOCATION");//是否加热,空箱调拨
strSql.Append(",isnull(WEIGHT,0) WEIGHT ");//重量
strSql.Append(",dbo.trimdate(PREI_ETD)PREI_ETD ");//预计开船日期
strSql.Append(" from op_ctnapply b ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list = SetData(strSql);
if (list.Count > 0)
return list[0];
return new OpCtnApply();
}
private static List<OpCtnApply> SetData(StringBuilder strSql)
{
var headList = new List<OpCtnApply>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpCtnApply data = new OpCtnApply();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]).ToString("yyyy-MM-dd");
var usdexrate = GetUsdExrate(data.BSDATE,"USD");
data.BSSTATUS = Convert.ToString(reader["BSSTATUS"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.OP = Convert.ToString(reader["OP"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODTYPE = Convert.ToString(reader["GOODTYPE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CTNALL = Convert.ToString(reader["CTNALL"]);
if (reader["CTNNUM"] != DBNull.Value)
data.CTNNUM = Convert.ToInt16(reader["CTNNUM"]);
if (reader["ISOWNERBOOKING"] != DBNull.Value)
data.ISOWNERBOOKING = Convert.ToBoolean(reader["ISOWNERBOOKING"]);
if (reader["ISPORTLOADDATE"] != DBNull.Value)
data.ISPORTLOADDATE = Convert.ToBoolean(reader["ISPORTLOADDATE"]);
data.OWNERCTN = Convert.ToString(reader["OWNERCTN"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.FACTORYNAME = Convert.ToString(reader["FACTORYNAME"]);
data.FACTORYADDR = Convert.ToString(reader["FACTORYADDR"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
data.CTNNUMS = Convert.ToString(reader["CTNNUMS"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["PLANCTNDATE"] != DBNull.Value)
data.PLANCTNDATE = Convert.ToDateTime(reader["PLANCTNDATE"]).ToString("yyyy-MM-dd");
if (reader["ISGOODSNAMESAME"] != DBNull.Value)
data.ISGOODSNAMESAME = Convert.ToBoolean(reader["ISGOODSNAMESAME"]);
data.PREGOODSNAME = Convert.ToString(reader["PREGOODSNAME"]);
data.CURGOODSNAME = Convert.ToString(reader["CURGOODSNAME"]);
data.PRODUCTGOODSNAME = Convert.ToString(reader["PRODUCTGOODSNAME"]);
data.PH = Convert.ToString(reader["PH"]);
data.DENSITY = Convert.ToString(reader["DENSITY"]);
data.UNNO = Convert.ToString(reader["UNNO"]);
data.DCLASS = Convert.ToString(reader["DCLASS"]);
data.SDCLASS = Convert.ToString(reader["SDCLASS"]);
data.PACKINGGROUP = Convert.ToString(reader["PACKINGGROUP"]);
if (reader["ISPOLLUTEOCEAN"] != DBNull.Value)
data.ISPOLLUTEOCEAN = Convert.ToBoolean(reader["ISPOLLUTEOCEAN"]);
data.MELTINGPOINT = Convert.ToString(reader["MELTINGPOINT"]);
data.BOILINGPOINT = Convert.ToString(reader["BOILINGPOINT"]);
data.FLASHPOINT = Convert.ToString(reader["FLASHPOINT"]);
data.IMDG = Convert.ToString(reader["IMDG"]);
data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]);
data.AUDITBY = Convert.ToString(reader["AUDITBY"]);
data.AUDITBYREF = Convert.ToString(reader["AUDITBYREF"]);
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]);
data.SUBMITBY = Convert.ToString(reader["SUBMITBY"]);
if (reader["SUBMITTIME"] != DBNull.Value)
data.SUBMITTIME = Convert.ToDateTime(reader["SUBMITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.AGENTINPUTBY = Convert.ToString(reader["AGENTINPUTBY"]);
if (reader["CYCLEDAYS"] != DBNull.Value)
data.CYCLEDAYS = Convert.ToDecimal(reader["CYCLEDAYS"]);
if (reader["CHANGERATE"] != DBNull.Value)
data.CHANGERATE = Convert.ToDecimal(reader["CHANGERATE"]);
if (reader["FULL_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.FULL_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["FULL_CTN_FREE_STORAGE_DAY"]);
if (reader["FULL_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.FULL_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["FULL_CTN_OVER_STORAGE_RATE"]);
if (reader["CLEAR_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.CLEAR_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["CLEAR_CTN_FREE_STORAGE_DAY"]);
if (reader["CLEAR_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.CLEAR_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["CLEAR_CTN_OVER_STORAGE_RATE"]);
if (reader["NO_CLEAR_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.NO_CLEAR_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["NO_CLEAR_CTN_FREE_STORAGE_DAY"]);
if (reader["NO_CLEAR_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.NO_CLEAR_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["NO_CLEAR_CTN_OVER_STORAGE_RATE"]);
if (reader["CTN_PRICE"] != DBNull.Value)
data.CTN_PRICE = Convert.ToDecimal(reader["CTN_PRICE"]);
if (reader["CURRENCY"] != DBNull.Value)
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
//if (reader["CTN_INCOME"] != DBNull.Value)
// data.CTN_INCOME = Convert.ToDecimal(reader["CTN_INCOME"]);
if (reader["LOAD_FREE_USECTNE_DAY"] != DBNull.Value)
data.LOAD_FREE_USECTNE_DAY = Convert.ToDecimal(reader["LOAD_FREE_USECTNE_DAY"]);
if (reader["LOAD_OVER_USECTNE_RATE"] != DBNull.Value)
data.LOAD_OVER_USECTNE_RATE = Convert.ToDecimal(reader["LOAD_OVER_USECTNE_RATE"]);
if (reader["DEST_FREE_USECTNE_DAY"] != DBNull.Value)
data.DEST_FREE_USECTNE_DAY = Convert.ToDecimal(reader["DEST_FREE_USECTNE_DAY"]);
if (reader["DEST_OVER_USECTNE_RATE"] != DBNull.Value)
data.DEST_OVER_USECTNE_RATE = Convert.ToDecimal(reader["DEST_OVER_USECTNE_RATE"]);
if (reader["SLOAD_FREE_USECTNE_DAY"] != DBNull.Value)
data.SLOAD_FREE_USECTNE_DAY = Convert.ToDecimal(reader["SLOAD_FREE_USECTNE_DAY"]);
if (reader["SLOAD_OVER_USECTNE_RATE"] != DBNull.Value)
data.SLOAD_OVER_USECTNE_RATE = Convert.ToDecimal(reader["SLOAD_OVER_USECTNE_RATE"]);
if (reader["SDEST_FREE_USECTNE_DAY"] != DBNull.Value)
data.SDEST_FREE_USECTNE_DAY = Convert.ToDecimal(reader["SDEST_FREE_USECTNE_DAY"]);
if (reader["SDEST_OVER_USECTNE_RATE"] != DBNull.Value)
data.SDEST_OVER_USECTNE_RATE = Convert.ToDecimal(reader["SDEST_OVER_USECTNE_RATE"]);
data.COSTAUDITSTATUS = Convert.ToString(reader["COSTAUDITSTATUS"]);
data.COSTAUDITBY = Convert.ToString(reader["COSTAUDITBY"]);
data.COSTAUDITBYREF = Convert.ToString(reader["COSTAUDITBYREF"]);
if (reader["COSTAUDITTIME"] != DBNull.Value)
data.COSTAUDITTIME = Convert.ToDateTime(reader["COSTAUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COSTSUBMITBY = Convert.ToString(reader["COSTSUBMITBY"]);
data.COSTSUBMITBYREF = Convert.ToString(reader["COSTSUBMITBYREF"]);
if (reader["COSTSUBMITTIME"] != DBNull.Value)
data.COSTSUBMITTIME = Convert.ToDateTime(reader["COSTSUBMITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COSTAUDITRESULT = Convert.ToString(reader["COSTAUDITRESULT"]);
data.ACCAUDITSTATUS = Convert.ToString(reader["ACCAUDITSTATUS"]);
data.ACCAUDITBY = Convert.ToString(reader["ACCAUDITBY"]);
data.ACCAUDITBYREF = Convert.ToString(reader["ACCAUDITBYREF"]);
if (reader["ACCAUDITTIME"] != DBNull.Value)
data.ACCAUDITTIME = Convert.ToDateTime(reader["ACCAUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.ACCAUDITRESULT = Convert.ToString(reader["ACCAUDITRESULT"]);
if (reader["USDCOST"] != DBNull.Value)
data.COSTUSD = Convert.ToDecimal(reader["USDCOST"]);
if (reader["RMBCOST"] != DBNull.Value)
data.COSTRMB= Convert.ToDecimal(reader["RMBCOST"]);
data.COSTTTL = Math.Round(data.COSTUSD + data.COSTRMB / usdexrate,2);
if ((data.CYCLEDAYS != 0) && (data.CTNNUM != 0))
{
if (data.CURRENCY == "USD")
data.CTN_INCOME = Math.Round((data.CTN_PRICE - data.COSTTTL / data.CTNNUM) / data.CYCLEDAYS, 2);
else {
var otexrate = GetUsdExrate(data.BSDATE, data.CURRENCY);
var ttldr = data.CTN_PRICE * otexrate;
data.CTN_INCOME = Math.Round(((ttldr / usdexrate) - data.COSTTTL / data.CTNNUM) / data.CYCLEDAYS, 2);
}
}
data.MNGAUDITSTATUS = Convert.ToString(reader["MNGAUDITSTATUS"]);
data.MNGAUDITBY = Convert.ToString(reader["MNGAUDITBY"]);
data.MNGAUDITBYREF = Convert.ToString(reader["MNGAUDITBYREF"]);
if (reader["MNGAUDITTIME"] != DBNull.Value)
data.MNGAUDITTIME = Convert.ToDateTime(reader["MNGAUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]);
data.MNGAUDITRESULT = Convert.ToString(reader["MNGAUDITRESULT"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.ADDCTNSTATUS = Convert.ToString(reader["ADDCTNSTATUS"]);
data.BSAUDITSTATUS = Convert.ToString(reader["BSAUDITSTATUS"]);
data.BSAUDITBY = Convert.ToString(reader["BSAUDITBY"]);
data.BSAUDITBYREF = Convert.ToString(reader["BSAUDITBYREF"]);
if (reader["BSAUDITTIME"] != DBNull.Value)
data.BSAUDITTIME = Convert.ToDateTime(reader["BSAUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.BSAUDITRESULT = Convert.ToString(reader["BSAUDITRESULT"]);
data.GOODSNAMEREF = Convert.ToString(reader["GOODSNAMEREF"]);
data.DESTPORT_STATOIN = Convert.ToString(reader["DESTPORT_STATOIN"]);
data.SERVICE = Convert.ToString(reader["SERVICE"]);
data.NEEDBEHEATED = Convert.ToBoolean(reader["NEEDBEHEATED"]);
data.WEIGHT = Convert.ToDecimal(reader["WEIGHT"]);
data.PREI_ETD = Convert.ToString(reader["PREI_ETD"]);
data.EMPTYCTNALLOCATION = Convert.ToBoolean(reader["EMPTYCTNALLOCATION"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteOpCtnApply(List<OpCtnApply> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_ctnapply where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#region 申请修改
static public OpCtnApplyModify GetModifyData(string condition, string userid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[BSNO],[BSDATE],MDSTATUS,[SALE],[OP],[GOODSNAME],[GOODTYPE],[PORTLOAD],[PORTDISCHARGE]");
strSql.Append(",[CTNALL],[CTNNUM],[ISOWNERBOOKING],[CUSTOMERNAME],[FACTORYNAME],[FACTORYADDR],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[ISGOODSNAMESAME],[PREGOODSNAME],[CURGOODSNAME],[PRODUCTGOODSNAME]");
strSql.Append(",[PH],[DENSITY],[UNNO],[DCLASS],[SDCLASS],[PACKINGGROUP],[ISPOLLUTEOCEAN],[MELTINGPOINT]");
strSql.Append(",[BOILINGPOINT],[FLASHPOINT],[IMDG],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT]");
strSql.Append(",[AGENTINPUTBY],[CYCLEDAYS],[CHANGERATE],[FULL_CTN_FREE_STORAGE_DAY],[FULL_CTN_OVER_STORAGE_RATE]");
strSql.Append(",[CLEAR_CTN_FREE_STORAGE_DAY],[CLEAR_CTN_OVER_STORAGE_RATE],[NO_CLEAR_CTN_FREE_STORAGE_DAY]");
strSql.Append(",[NO_CLEAR_CTN_OVER_STORAGE_RATE],[CTN_PRICE],CURRENCY,[CTN_INCOME],[LOAD_FREE_USECTNE_DAY],[LOAD_OVER_USECTNE_RATE]");
strSql.Append(",[DEST_FREE_USECTNE_DAY],[DEST_OVER_USECTNE_RATE]");
strSql.Append(",[COMPANYID],PLANCTNDATE,APPLYID,MODIFYTYPE,REASON");
strSql.Append(",[SLOAD_FREE_USECTNE_DAY],[SLOAD_OVER_USECTNE_RATE],[SDEST_FREE_USECTNE_DAY],[SDEST_OVER_USECTNE_RATE]");
strSql.Append(",[AGENTNAME],ISPORTLOADDATE");
strSql.Append(",(select ShowName from [user] where GID=b.INPUTBY) as INPUTBYREF");
strSql.Append(",(select ShowName from [user] where GID=b.AUDITBY) as AUDITBYREF");
strSql.Append(",(select SUM(case CURRENCY when 'USD' THEN AMOUNT ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.APPLYID) as USDCOST");
strSql.Append(",(select SUM(case when CURRENCY<>'USD' THEN AMOUNT*EXCHANGERATE ELSE 0 END) from [op_ctnapplycostitems] where LINKGID=b.APPLYID) as RMBCOST");
strSql.Append(",isnull(DESTPORT_STATOIN,'') DESTPORT_STATOIN");//目的港还箱堆场
strSql.Append(",isnull(SERVICE,'') SERVICE ");//运输条款
strSql.Append(",isnull(NEEDBEHEATED,0)NEEDBEHEATED,isnull(EMPTYCTNALLOCATION,0) EMPTYCTNALLOCATION");//是否加热,空箱调拨
strSql.Append(",isnull(WEIGHT,0) WEIGHT ");//重量
strSql.Append(",dbo.trimdate(PREI_ETD)PREI_ETD ");//预计开船日期
strSql.Append(" from op_ctnapply_modify b ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var list = SetModifyData(strSql);
if (list.Count > 0)
return list[0];
return new OpCtnApplyModify();
}
private static List<OpCtnApplyModify> SetModifyData(StringBuilder strSql)
{
var headList = new List<OpCtnApplyModify>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpCtnApplyModify data = new OpCtnApplyModify();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.APPLYID = Convert.ToString(reader["APPLYID"]);
data.MODIFYTYPE= Convert.ToString(reader["MODIFYTYPE"]);
data.REASON = Convert.ToString(reader["REASON"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.BSDATE = Convert.ToDateTime(reader["BSDATE"]).ToString("yyyy-MM-dd");
data.MDSTATUS = Convert.ToString(reader["MDSTATUS"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.OP = Convert.ToString(reader["OP"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
data.GOODTYPE = Convert.ToString(reader["GOODTYPE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CTNALL = Convert.ToString(reader["CTNALL"]);
if (reader["CTNNUM"] != DBNull.Value)
data.CTNNUM = Convert.ToInt16(reader["CTNNUM"]);
if (reader["ISOWNERBOOKING"] != DBNull.Value)
data.ISOWNERBOOKING = Convert.ToBoolean(reader["ISOWNERBOOKING"]);
if (reader["ISPORTLOADDATE"] != DBNull.Value)
data.ISPORTLOADDATE = Convert.ToBoolean(reader["ISPORTLOADDATE"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.FACTORYNAME = Convert.ToString(reader["FACTORYNAME"]);
data.FACTORYADDR = Convert.ToString(reader["FACTORYADDR"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
data.AGENTNAME = Convert.ToString(reader["AGENTNAME"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["PLANCTNDATE"] != DBNull.Value)
data.PLANCTNDATE = Convert.ToDateTime(reader["PLANCTNDATE"]).ToString("yyyy-MM-dd");
if (reader["ISGOODSNAMESAME"] != DBNull.Value)
data.ISGOODSNAMESAME = Convert.ToBoolean(reader["ISGOODSNAMESAME"]);
data.PREGOODSNAME = Convert.ToString(reader["PREGOODSNAME"]);
data.CURGOODSNAME = Convert.ToString(reader["CURGOODSNAME"]);
data.PRODUCTGOODSNAME = Convert.ToString(reader["PRODUCTGOODSNAME"]);
data.PH = Convert.ToString(reader["PH"]);
data.DENSITY = Convert.ToString(reader["DENSITY"]);
data.UNNO = Convert.ToString(reader["UNNO"]);
data.DCLASS = Convert.ToString(reader["DCLASS"]);
data.SDCLASS = Convert.ToString(reader["SDCLASS"]);
data.PACKINGGROUP = Convert.ToString(reader["PACKINGGROUP"]);
if (reader["ISPOLLUTEOCEAN"] != DBNull.Value)
data.ISPOLLUTEOCEAN = Convert.ToBoolean(reader["ISPOLLUTEOCEAN"]);
data.MELTINGPOINT = Convert.ToString(reader["MELTINGPOINT"]);
data.BOILINGPOINT = Convert.ToString(reader["BOILINGPOINT"]);
data.FLASHPOINT = Convert.ToString(reader["FLASHPOINT"]);
data.IMDG = Convert.ToString(reader["IMDG"]);
data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]);
data.AUDITBY = Convert.ToString(reader["AUDITBY"]);
data.AUDITBYREF = Convert.ToString(reader["AUDITBYREF"]);
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]);
data.AGENTINPUTBY = Convert.ToString(reader["AGENTINPUTBY"]);
if (reader["CYCLEDAYS"] != DBNull.Value)
data.CYCLEDAYS = Convert.ToDecimal(reader["CYCLEDAYS"]);
if (reader["CHANGERATE"] != DBNull.Value)
data.CHANGERATE = Convert.ToDecimal(reader["CHANGERATE"]);
if (reader["FULL_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.FULL_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["FULL_CTN_FREE_STORAGE_DAY"]);
if (reader["FULL_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.FULL_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["FULL_CTN_OVER_STORAGE_RATE"]);
if (reader["CLEAR_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.CLEAR_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["CLEAR_CTN_FREE_STORAGE_DAY"]);
if (reader["CLEAR_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.CLEAR_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["CLEAR_CTN_OVER_STORAGE_RATE"]);
if (reader["NO_CLEAR_CTN_FREE_STORAGE_DAY"] != DBNull.Value)
data.NO_CLEAR_CTN_FREE_STORAGE_DAY = Convert.ToDecimal(reader["NO_CLEAR_CTN_FREE_STORAGE_DAY"]);
if (reader["NO_CLEAR_CTN_OVER_STORAGE_RATE"] != DBNull.Value)
data.NO_CLEAR_CTN_OVER_STORAGE_RATE = Convert.ToDecimal(reader["NO_CLEAR_CTN_OVER_STORAGE_RATE"]);
if (reader["CTN_PRICE"] != DBNull.Value)
data.CTN_PRICE = Convert.ToDecimal(reader["CTN_PRICE"]);
if (reader["CURRENCY"] != DBNull.Value)
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["CTN_INCOME"] != DBNull.Value)
data.CTN_INCOME = Convert.ToDecimal(reader["CTN_INCOME"]);
if (reader["LOAD_FREE_USECTNE_DAY"] != DBNull.Value)
data.LOAD_FREE_USECTNE_DAY = Convert.ToDecimal(reader["LOAD_FREE_USECTNE_DAY"]);
if (reader["LOAD_OVER_USECTNE_RATE"] != DBNull.Value)
data.LOAD_OVER_USECTNE_RATE = Convert.ToDecimal(reader["LOAD_OVER_USECTNE_RATE"]);
if (reader["DEST_FREE_USECTNE_DAY"] != DBNull.Value)
data.DEST_FREE_USECTNE_DAY = Convert.ToDecimal(reader["DEST_FREE_USECTNE_DAY"]);
if (reader["DEST_OVER_USECTNE_RATE"] != DBNull.Value)
data.DEST_OVER_USECTNE_RATE = Convert.ToDecimal(reader["DEST_OVER_USECTNE_RATE"]);
if (reader["SLOAD_FREE_USECTNE_DAY"] != DBNull.Value)
data.SLOAD_FREE_USECTNE_DAY = Convert.ToDecimal(reader["SLOAD_FREE_USECTNE_DAY"]);
if (reader["SLOAD_OVER_USECTNE_RATE"] != DBNull.Value)
data.SLOAD_OVER_USECTNE_RATE = Convert.ToDecimal(reader["SLOAD_OVER_USECTNE_RATE"]);
if (reader["SDEST_FREE_USECTNE_DAY"] != DBNull.Value)
data.SDEST_FREE_USECTNE_DAY = Convert.ToDecimal(reader["SDEST_FREE_USECTNE_DAY"]);
if (reader["SDEST_OVER_USECTNE_RATE"] != DBNull.Value)
data.SDEST_OVER_USECTNE_RATE = Convert.ToDecimal(reader["SDEST_OVER_USECTNE_RATE"]);
if (reader["USDCOST"] != DBNull.Value)
data.COSTUSD = Convert.ToDecimal(reader["USDCOST"]);
if (reader["RMBCOST"] != DBNull.Value)
data.COSTRMB = Convert.ToDecimal(reader["RMBCOST"]);
//var usdexrate = GetUsdExrate(data.BSDATE, "USD");
//data.COSTTTL = Math.Round(data.COSTUSD + data.COSTRMB / usdexrate, 2);
//if ((data.CYCLEDAYS != 0) && (data.CTNNUM != 0))
// data.CTN_INCOME = Math.Round((data.CTN_PRICE - data.COSTTTL / data.CTNNUM) / data.CYCLEDAYS, 2);
var usdexrate = GetUsdExrate(data.BSDATE, "USD");
data.COSTTTL = Math.Round(data.COSTUSD + data.COSTRMB / usdexrate, 2);
if ((data.CYCLEDAYS != 0) && (data.CTNNUM != 0))
{
if (data.CURRENCY == "USD")
data.CTN_INCOME = Math.Round((data.CTN_PRICE - data.COSTTTL / data.CTNNUM) / data.CYCLEDAYS, 2);
else
{
var otexrate = GetUsdExrate(data.BSDATE, data.CURRENCY);
var ttldr = data.CTN_PRICE * otexrate;
data.CTN_INCOME = Math.Round(((ttldr / usdexrate) - data.COSTTTL / data.CTNNUM) / data.CYCLEDAYS, 2);
}
}
data.DESTPORT_STATOIN = Convert.ToString(reader["DESTPORT_STATOIN"]);
data.SERVICE = Convert.ToString(reader["SERVICE"]);
data.NEEDBEHEATED = Convert.ToBoolean(reader["NEEDBEHEATED"]);
data.WEIGHT = Convert.ToDecimal(reader["WEIGHT"]);
data.PREI_ETD = Convert.ToString(reader["PREI_ETD"]);
data.EMPTYCTNALLOCATION = Convert.ToBoolean(reader["EMPTYCTNALLOCATION"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult AuditGoods(OpCtnApply headdata,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set ISGOODSNAMESAME=@ISGOODSNAMESAME,PRODUCTGOODSNAME=@PRODUCTGOODSNAME,AUDITSTATUS=@AUDITSTATUS,AUDITBY=@AUDITBY,AUDITTIME=@AUDITTIME,
AUDITRESULT=@AUDITRESULT,BSSTATUS=@BSSTATUS where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@ISGOODSNAMESAME", DbType.Boolean, headdata.ISGOODSNAMESAME);
db.AddInParameter(cmdUpdate, "@PRODUCTGOODSNAME", DbType.String, headdata.PRODUCTGOODSNAME);
db.AddInParameter(cmdUpdate, "@AUDITSTATUS", DbType.String, headdata.AUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@AUDITBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@AUDITTIME", DbType.String,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@AUDITRESULT", DbType.String, headdata.AUDITRESULT);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult SaveCost(OpCtnApply headdata)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set AGENTINPUTBY=@AGENTINPUTBY,CYCLEDAYS=@CYCLEDAYS,CHANGERATE=@CHANGERATE,
FULL_CTN_FREE_STORAGE_DAY=@FULL_CTN_FREE_STORAGE_DAY,FULL_CTN_OVER_STORAGE_RATE=@FULL_CTN_OVER_STORAGE_RATE,
CLEAR_CTN_FREE_STORAGE_DAY=@CLEAR_CTN_FREE_STORAGE_DAY,CLEAR_CTN_OVER_STORAGE_RATE=@CLEAR_CTN_OVER_STORAGE_RATE,
NO_CLEAR_CTN_FREE_STORAGE_DAY=@NO_CLEAR_CTN_FREE_STORAGE_DAY,NO_CLEAR_CTN_OVER_STORAGE_RATE=@NO_CLEAR_CTN_OVER_STORAGE_RATE,
CTN_PRICE=@CTN_PRICE,CURRENCY=@CURRENCY,AGENTNAME=@AGENTNAME,
LOAD_FREE_USECTNE_DAY=@LOAD_FREE_USECTNE_DAY,
LOAD_OVER_USECTNE_RATE=@LOAD_OVER_USECTNE_RATE,
DEST_FREE_USECTNE_DAY=@DEST_FREE_USECTNE_DAY,
DEST_OVER_USECTNE_RATE=@DEST_OVER_USECTNE_RATE,
COSTAUDITSTATUS=@COSTAUDITSTATUS,BSSTATUS=@BSSTATUS,
DESTPORT_STATOIN=@DESTPORT_STATOIN
where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@AGENTINPUTBY", DbType.String, headdata.AGENTINPUTBY);
db.AddInParameter(cmdUpdate, "@CYCLEDAYS", DbType.Decimal, headdata.CYCLEDAYS);
db.AddInParameter(cmdUpdate, "@CHANGERATE", DbType.Decimal, headdata.CHANGERATE);
db.AddInParameter(cmdUpdate, "@FULL_CTN_FREE_STORAGE_DAY", DbType.Decimal, headdata.FULL_CTN_FREE_STORAGE_DAY);
db.AddInParameter(cmdUpdate, "@FULL_CTN_OVER_STORAGE_RATE", DbType.Decimal, headdata.FULL_CTN_OVER_STORAGE_RATE);
db.AddInParameter(cmdUpdate, "@CLEAR_CTN_FREE_STORAGE_DAY", DbType.Decimal, headdata.CLEAR_CTN_FREE_STORAGE_DAY);
db.AddInParameter(cmdUpdate, "@CLEAR_CTN_OVER_STORAGE_RATE", DbType.Decimal, headdata.CLEAR_CTN_OVER_STORAGE_RATE);
db.AddInParameter(cmdUpdate, "@NO_CLEAR_CTN_FREE_STORAGE_DAY", DbType.Decimal, headdata.NO_CLEAR_CTN_FREE_STORAGE_DAY);
db.AddInParameter(cmdUpdate, "@NO_CLEAR_CTN_OVER_STORAGE_RATE", DbType.Decimal, headdata.NO_CLEAR_CTN_OVER_STORAGE_RATE);
db.AddInParameter(cmdUpdate, "@CTN_PRICE", DbType.Decimal, headdata.CTN_PRICE);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, headdata.CURRENCY);
db.AddInParameter(cmdUpdate, "@COSTAUDITSTATUS", DbType.String, headdata.COSTAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@AGENTNAME", DbType.String, headdata.AGENTNAME);
db.AddInParameter(cmdUpdate, "@LOAD_FREE_USECTNE_DAY", DbType.String, headdata.LOAD_FREE_USECTNE_DAY);
db.AddInParameter(cmdUpdate, "@LOAD_OVER_USECTNE_RATE", DbType.String, headdata.LOAD_OVER_USECTNE_RATE);
db.AddInParameter(cmdUpdate, "@DEST_FREE_USECTNE_DAY", DbType.String, headdata.DEST_FREE_USECTNE_DAY);
db.AddInParameter(cmdUpdate, "@DEST_OVER_USECTNE_RATE", DbType.String, headdata.DEST_OVER_USECTNE_RATE);
db.AddInParameter(cmdUpdate, "@DESTPORT_STATOIN", DbType.String, headdata.DESTPORT_STATOIN);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult SubmitCostAuditBack(string GID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("update op_ctnapply set COSTAUDITSTATUS='未提交',BSSTATUS='成本审核撤销提交',COSTSUBMITBY='',COSTSUBMITTIME='' where GID='" + GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销审核出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "撤销审核成功";
return result;
}
public static DBResult AccAudit(OpCtnApply headdata)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set ACCAUDITSTATUS=@ACCAUDITSTATUS,ACCAUDITBY=@ACCAUDITBY,ACCAUDITTIME=@ACCAUDITTIME,ACCAUDITRESULT=@ACCAUDITRESULT,
BSSTATUS=@BSSTATUS where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@ACCAUDITSTATUS", DbType.String, headdata.ACCAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@ACCAUDITBY", DbType.String, headdata.ACCAUDITBY);
db.AddInParameter(cmdUpdate, "@ACCAUDITTIME", DbType.String, headdata.ACCAUDITTIME);
db.AddInParameter(cmdUpdate, "@ACCAUDITRESULT", DbType.String, headdata.ACCAUDITRESULT);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult BsAudit(OpCtnApply headdata)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set BSAUDITSTATUS=@BSAUDITSTATUS,BSAUDITBY=@BSAUDITBY,BSAUDITTIME=@BSAUDITTIME,BSAUDITRESULT=@BSAUDITRESULT,
BSSTATUS=@BSSTATUS where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@BSAUDITSTATUS", DbType.String, headdata.BSAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@BSAUDITBY", DbType.String, headdata.BSAUDITBY);
db.AddInParameter(cmdUpdate, "@BSAUDITTIME", DbType.String, headdata.BSAUDITTIME);
db.AddInParameter(cmdUpdate, "@BSAUDITRESULT", DbType.String, headdata.BSAUDITRESULT);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult AuditCost(OpCtnApply headdata, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set CTN_PRICE=@CTN_PRICE,CURRENCY=@CURRENCY,LOAD_FREE_USECTNE_DAY=@LOAD_FREE_USECTNE_DAY,
LOAD_OVER_USECTNE_RATE=@LOAD_OVER_USECTNE_RATE,DEST_FREE_USECTNE_DAY=@DEST_FREE_USECTNE_DAY,DEST_OVER_USECTNE_RATE=@DEST_OVER_USECTNE_RATE,
COSTAUDITSTATUS=@COSTAUDITSTATUS,COSTAUDITBY=@COSTAUDITBY,COSTAUDITTIME=@COSTAUDITTIME,
COSTAUDITRESULT=@COSTAUDITRESULT,BSSTATUS=@BSSTATUS,MNGAUDITSTATUS=@MNGAUDITSTATUS
,AGENTNAME=@AGENTNAME where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@CTN_PRICE", DbType.Decimal, headdata.CTN_PRICE);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, headdata.CURRENCY);
db.AddInParameter(cmdUpdate, "@LOAD_FREE_USECTNE_DAY", DbType.Decimal, headdata.LOAD_FREE_USECTNE_DAY);
db.AddInParameter(cmdUpdate, "@LOAD_OVER_USECTNE_RATE", DbType.Decimal, headdata.LOAD_OVER_USECTNE_RATE);
db.AddInParameter(cmdUpdate, "@DEST_FREE_USECTNE_DAY", DbType.Decimal, headdata.DEST_FREE_USECTNE_DAY);
db.AddInParameter(cmdUpdate, "@DEST_OVER_USECTNE_RATE", DbType.Decimal, headdata.DEST_OVER_USECTNE_RATE);
db.AddInParameter(cmdUpdate, "@COSTAUDITSTATUS", DbType.String, headdata.COSTAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@COSTAUDITBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@COSTAUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@COSTAUDITRESULT", DbType.String, headdata.COSTAUDITRESULT);
db.AddInParameter(cmdUpdate, "@MNGAUDITSTATUS", DbType.String, headdata.MNGAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@AGENTNAME", DbType.String, headdata.AGENTNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult MNGAudit(OpCtnApply 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.BSSTATUS == "总经理审核通过")
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set MNGAUDITSTATUS=@MNGAUDITSTATUS,MNGAUDITBY=@MNGAUDITBY,MNGAUDITTIME=@MNGAUDITTIME,BSSTATUS=@BSSTATUS where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@MNGAUDITSTATUS", DbType.String, headdata.MNGAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@MNGAUDITBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MNGAUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.ExecuteNonQuery(cmdUpdate, tran);
}
else
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapply set MNGAUDITSTATUS=@MNGAUDITSTATUS,MNGAUDITBY=@MNGAUDITBY,MNGAUDITTIME=@MNGAUDITTIME,BSSTATUS=@BSSTATUS,
COSTAUDITSTATUS=@COSTAUDITSTATUS, ACCAUDITSTATUS=@ACCAUDITSTATUS
,MNGAUDITRESULT=@MNGAUDITRESULT where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, headdata.GID);
db.AddInParameter(cmdUpdate, "@MNGAUDITSTATUS", DbType.String, headdata.MNGAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@BSSTATUS", DbType.String, headdata.BSSTATUS);
db.AddInParameter(cmdUpdate, "@MNGAUDITBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@MNGAUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@COSTAUDITSTATUS", DbType.String, headdata.MNGAUDITSTATUS);
db.AddInParameter(cmdUpdate, "@ACCAUDITSTATUS", DbType.String, headdata.ACCAUDITSTATUS);
//db.AddInParameter(cmdUpdate, "@COSTAUDITBY", DbType.String, userid);
//db.AddInParameter(cmdUpdate, "@COSTAUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@MNGAUDITRESULT", DbType.String, headdata.MNGAUDITRESULT);
db.ExecuteNonQuery(cmdUpdate, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult SubmitAddCtn(string GID,string bsstatus)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bsstatus == "配箱完成" || bsstatus == "总经理审核通过")
{
var cmdDelete = db.GetSqlStringCommand("update op_ctnapply set BSSTATUS='" + bsstatus + "',ADDCTNSTATUS='" + bsstatus + "' where GID='" + GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
else
{
var cmdDelete = db.GetSqlStringCommand("update op_ctnapply set BSSTATUS='" + bsstatus + "' where GID='" + GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销审核出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "撤销审核成功";
return result;
}
#endregion
#region OpCtnApplyCostItems
static public List<OpCtnApplyCostitems> GetCtnApplyCostItemsList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],PRICETYPE,[FEENAME],[UNITPRICE] ,[UNIT],[CURRENCY],QUANTITY");
strSql.Append(",[AMOUNT],[AUDITSTATUS],[AUDITBY],[AUDITTIME],[AUDITRESULT],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID],[CUSTOMERNAME],EXCHANGERATE,GOODSNAME ");
strSql.Append(",(select ShowName from [user] where GID=op_ctnapplycostitems.INPUTBY) as INPUTBYREF");
strSql.Append(" from op_ctnapplycostitems ");
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 ITEMSNO");
}
return SetCtnApplyCostItemsData(strSql);
}
private static List<OpCtnApplyCostitems> SetCtnApplyCostItemsData(StringBuilder strSql)
{
var headList = new List<OpCtnApplyCostitems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpCtnApplyCostitems data = new OpCtnApplyCostitems();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
//if (reader["ITEMSNO"] != DBNull.Value)
// data.ITEMSNO = Convert.ToInt16(reader["ITEMSNO"]);
data.FEENAME = Convert.ToString(reader["FEENAME"]);
data.UNIT = Convert.ToString(reader["UNIT"]);
if (reader["UNITPRICE"] != DBNull.Value)
data.UNITPRICE = Convert.ToDecimal(reader["UNITPRICE"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["QUANTITY"] != DBNull.Value)
data.QUANTITY = Convert.ToDecimal(reader["QUANTITY"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
if (reader["EXCHANGERATE"] != DBNull.Value)
data.EXCHANGERATE = Convert.ToDecimal(reader["EXCHANGERATE"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.INPUTBYREF = Convert.ToString(reader["INPUTBYREF"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]);
data.AUDITBY = Convert.ToString(reader["AUDITBY"]);
data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]);
data.PRICETYPE = Convert.ToString(reader["PRICETYPE"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.GOODSNAME = Convert.ToString(reader["GOODSNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCtnApplyCostItems(List<OpCtnApplyCostitems> bodyList, string PID, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_ctnapplycostitems (GID,LINKGID,ITEMSNO,PRICETYPE,FEENAME,UNIT,UNITPRICE,CURRENCY,INPUTBY,INPUTTIME,REMARKS,
QUANTITY,AMOUNT,CUSTOMERNAME,EXCHANGERATE,GOODSNAME)
values (@GID,@LINKGID,@ITEMSNO,@PRICETYPE,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@INPUTBY,@INPUTTIME,@REMARKS,@QUANTITY,
@AMOUNT,@CUSTOMERNAME,@EXCHANGERATE,@GOODSNAME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapplycostitems set FEENAME=@FEENAME,UNIT=@UNIT,UNITPRICE=@UNITPRICE,CURRENCY=@CURRENCY,QUANTITY=@QUANTITY,AMOUNT=@AMOUNT,
REMARKS=@REMARKS,ITEMSNO=@ITEMSNO,CUSTOMERNAME=@CUSTOMERNAME,EXCHANGERATE=@EXCHANGERATE,GOODSNAME=@GOODSNAME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdInsert, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@QUANTITY", DbType.Decimal, enumValue.QUANTITY);
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdInsert, "@EXCHANGERATE", DbType.Decimal, enumValue.EXCHANGERATE);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdInsert, "@PRICETYPE", DbType.String, enumValue.PRICETYPE);
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdInsert, "@ITEMSNO", DbType.String, enumValue.ITEMSNO);
db.AddInParameter(cmdInsert, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@FEENAME", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdUpdate, "@UNIT", DbType.String, enumValue.UNIT);
db.AddInParameter(cmdUpdate, "@UNITPRICE", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdate, "@QUANTITY", DbType.Decimal, enumValue.QUANTITY);
db.AddInParameter(cmdUpdate, "@AMOUNT", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdUpdate, "@EXCHANGERATE", DbType.Decimal, enumValue.EXCHANGERATE);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdUpdate, "@CUSTOMERNAME", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdUpdate, "@ITEMSNO", DbType.String, enumValue.ITEMSNO);
db.AddInParameter(cmdUpdate, "@GOODSNAME", DbType.String, enumValue.GOODSNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteOpCtnApplyCostItems(List<OpCtnApplyCostitems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_ctnapplycostitems where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT Count(BSNO) AS CT from op_ctnapply (NOLOCK) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
#region OpCtnApplySaleitems
static public List<OpCtnApplySaleitems> GetCtnApplySaleItemsList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],ITEMSNO,[ITEMNAME],[REMARKS]");
strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID]");
strSql.Append(" from op_ctnapplysalesitems ");
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 ITEMSNO");
}
return SetCtnApplySaleItemsData(strSql);
}
private static List<OpCtnApplySaleitems> SetCtnApplySaleItemsData(StringBuilder strSql)
{
var headList = new List<OpCtnApplySaleitems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpCtnApplySaleitems data = new OpCtnApplySaleitems();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
if (reader["ITEMSNO"] != DBNull.Value)
data.ITEMSNO = Convert.ToInt16(reader["ITEMSNO"]);
data.ITEMNAME = Convert.ToString(reader["ITEMNAME"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCtnApplySaleItems(List<OpCtnApplySaleitems> bodyList, string PID, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_ctnapplysalesitems (GID,LINKGID,ITEMSNO,ITEMNAME,INPUTBY,INPUTTIME,REMARKS)
values (@GID,@LINKGID,@ITEMSNO,@ITEMNAME,@INPUTBY,@INPUTTIME,@REMARKS
) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapplysalesitems set ITEMSNO=@ITEMSNO,ITEMNAME=@ITEMNAME,REMARKS=@REMARKS where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.LINKGID == "*" || enumValue.LINKGID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@ITEMSNO", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdInsert, "@ITEMNAME", DbType.String, enumValue.ITEMNAME);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@ITEMSNO", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdUpdate, "@ITEMNAME", DbType.String, enumValue.ITEMNAME);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteOpCtnApplySaleItems(List<OpCtnApplySaleitems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_ctnapplysalesitems where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
#region OpCtnApplyCtnitems
static public List<OpCtnApplyCtnitems> GetCtnApplyCtnItemsList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT [GID],[LINKGID],ITEMSNO,[CTNNO],[REMARKS],OWNERCTN,TANKVOLUMN,AUDITSTATUS,AUDITBY,AUDITTIME,AUDITRESULT");
strSql.Append(",[INPUTBY],[INPUTTIME],[COMPANYID],INSPECTION_EXPIRE_DATE,INSURANCE_EXPIRE_DATE,CURPORT,CURSTATOIN,PREGOODNAME");
strSql.Append(",(select CTNPROP from [code_ctntk] where CTNNO=b.CTNNO) as CTNPROP");
strSql.Append(" from op_ctnapplyctnitems b ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ITEMSNO");
}
return SetCtnApplyCtnItemsData(strSql);
}
private static List<OpCtnApplyCtnitems> SetCtnApplyCtnItemsData(StringBuilder strSql)
{
var headList = new List<OpCtnApplyCtnitems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
OpCtnApplyCtnitems data = new OpCtnApplyCtnitems();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.LINKGID = Convert.ToString(reader["LINKGID"]);
if (reader["ITEMSNO"] != DBNull.Value)
data.ITEMSNO = Convert.ToInt16(reader["ITEMSNO"]);
data.CTNNO = Convert.ToString(reader["CTNNO"]);
data.CTNPROP = Convert.ToString(reader["CTNPROP"]);
data.OWNERCTN = Convert.ToString(reader["OWNERCTN"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.TANKVOLUMN = Convert.ToString(reader["TANKVOLUMN"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
if (reader["INPUTTIME"] != DBNull.Value)
data.INPUTTIME = Convert.ToDateTime(reader["INPUTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");
if (reader["INSPECTION_EXPIRE_DATE"] != DBNull.Value)
data.INSPECTION_EXPIRE_DATE = Convert.ToDateTime(reader["INSPECTION_EXPIRE_DATE"]).ToString("yyyy-MM-dd");
if (reader["INSURANCE_EXPIRE_DATE"] != DBNull.Value)
data.INSURANCE_EXPIRE_DATE = Convert.ToDateTime(reader["INSURANCE_EXPIRE_DATE"]).ToString("yyyy-MM-dd");
data.CURPORT = Convert.ToString(reader["CURPORT"]);
data.CURSTATOIN = Convert.ToString(reader["CURSTATOIN"]);
data.PREGOODNAME = Convert.ToString(reader["PREGOODNAME"]);
data.AUDITSTATUS = Convert.ToString(reader["AUDITSTATUS"]);
data.AUDITBY = Convert.ToString(reader["AUDITBY"]);
if (reader["AUDITTIME"] != DBNull.Value)
data.AUDITTIME = Convert.ToDateTime(reader["AUDITTIME"]).ToString("yyyy-MM-dd");
data.AUDITRESULT = Convert.ToString(reader["AUDITRESULT"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCtnApplyCtnItems(List<OpCtnApplyCtnitems> bodyList, string PID, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_ctnapplyctnitems (GID,LINKGID,ITEMSNO,CTNNO,INPUTBY,INPUTTIME,REMARKS,OWNERCTN,TANKVOLUMN
,INSPECTION_EXPIRE_DATE,INSURANCE_EXPIRE_DATE,CURPORT,CURSTATOIN,PREGOODNAME)
values (@GID,@LINKGID,@ITEMSNO,@CTNNO,@INPUTBY,@INPUTTIME,@REMARKS,@OWNERCTN,@TANKVOLUMN
,@INSPECTION_EXPIRE_DATE,@INSURANCE_EXPIRE_DATE,@CURPORT,@CURSTATOIN,@PREGOODNAME ) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapplyctnitems set ITEMSNO=@ITEMSNO,CTNNO=@CTNNO,REMARKS=@REMARKS,OWNERCTN=@OWNERCTN,TANKVOLUMN=@TANKVOLUMN
,INSPECTION_EXPIRE_DATE=@INSPECTION_EXPIRE_DATE,INSURANCE_EXPIRE_DATE=@INSURANCE_EXPIRE_DATE,
CURPORT=@CURPORT,CURSTATOIN=@CURSTATOIN,PREGOODNAME=@PREGOODNAME where GID=@GID ");
var cmdUpdateCtn =
db.GetSqlStringCommand(
@"update code_ctntk set CTNSTATUS='不可用' where CTNNO=@CTNNO ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.INSPECTION_EXPIRE_DATE == "") enumValue.INSPECTION_EXPIRE_DATE = null;
if (enumValue.INSURANCE_EXPIRE_DATE == "") enumValue.INSURANCE_EXPIRE_DATE = null;
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@ITEMSNO", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdInsert, "@CTNNO", DbType.String, enumValue.CTNNO);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@OWNERCTN", DbType.String, enumValue.OWNERCTN);
db.AddInParameter(cmdInsert, "@TANKVOLUMN", DbType.String, enumValue.TANKVOLUMN);
db.AddInParameter(cmdInsert, "@INSPECTION_EXPIRE_DATE", DbType.String, enumValue.INSPECTION_EXPIRE_DATE);
db.AddInParameter(cmdInsert, "@INSURANCE_EXPIRE_DATE", DbType.String, enumValue.INSURANCE_EXPIRE_DATE);
db.AddInParameter(cmdInsert, "@CURPORT", DbType.String, enumValue.CURPORT);
db.AddInParameter(cmdInsert, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN);
db.AddInParameter(cmdInsert, "@PREGOODNAME", DbType.String, enumValue.PREGOODNAME);
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@ITEMSNO", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdUpdate, "@CTNNO", DbType.String, enumValue.CTNNO);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdUpdate, "@OWNERCTN", DbType.String, enumValue.OWNERCTN);
db.AddInParameter(cmdUpdate, "@TANKVOLUMN", DbType.String, enumValue.TANKVOLUMN);
db.AddInParameter(cmdUpdate, "@INSPECTION_EXPIRE_DATE", DbType.String, enumValue.INSPECTION_EXPIRE_DATE);
db.AddInParameter(cmdUpdate, "@INSURANCE_EXPIRE_DATE", DbType.String, enumValue.INSURANCE_EXPIRE_DATE);
db.AddInParameter(cmdUpdate, "@CURPORT", DbType.String, enumValue.CURPORT);
db.AddInParameter(cmdUpdate, "@CURSTATOIN", DbType.String, enumValue.CURSTATOIN);
db.AddInParameter(cmdUpdate, "@PREGOODNAME", DbType.String, enumValue.PREGOODNAME);
db.ExecuteNonQuery(cmdUpdate, tran);
}
cmdUpdateCtn.Parameters.Clear();
db.AddInParameter(cmdUpdateCtn, "@CTNNO", DbType.String, enumValue.CTNNO);
db.ExecuteNonQuery(cmdUpdateCtn, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult DeleteOpCtnApplyCtnItems(List<OpCtnApplyCtnitems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("delete from op_ctnapplyctnitems where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdUpdateCtn =
db.GetSqlStringCommand(
@"update code_ctntk set CTNSTATUS='可用' where CTNNO=@CTNNO ");
cmdUpdateCtn.Parameters.Clear();
db.AddInParameter(cmdUpdateCtn, "@CTNNO", DbType.String, enumValue.CTNNO);
db.ExecuteNonQuery(cmdUpdateCtn, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult UpOpCtnApplyCtnItems(string GID,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdUpdate =
db.GetSqlStringCommand(
@"update op_ctnapplyctnitems set AUDITSTATUS=@AUDITSTATUS,AUDITBY=@AUDITBY,AUDITTIME=@AUDITTIME where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@AUDITSTATUS", DbType.String, "生成业务卡");
db.AddInParameter(cmdUpdate, "@AUDITBY", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@AUDITTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@GID", DbType.String, GID);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult SaveSaleToOpCtnRepair(List<OpCtnApplySaleitems> bodyList, string PID, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_ctnrepair (GID,LINKGID,REPAIRITEMS,INPUTBY,INPUTTIME,AUDITSTATUS)
values (@GID,@LINKGID,@REPAIRITEMS,@INPUTBY,@INPUTTIME,@AUDITSTATUS) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, PID);
db.AddInParameter(cmdInsert, "@REPAIRITEMS", DbType.String, enumValue.ITEMNAME);
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, userid);
db.AddInParameter(cmdInsert, "@INPUTTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@AUDITSTATUS", DbType.String, "录入状态");
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员"; //+ex.ToString
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult SaveFee(List<OpCtnApplyCostitems> bodyList, string bsno, string userid,Int16 ctnnum)
{
var result = new DBResult();
int feestatus = 1;
var OPCTNFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='OPCTNFEESTATUSISAUDIT'");
if (OPCTNFEESTATUSISAUDIT.PARAMVALUE == "1")
{
feestatus = 0;
}
T_ALL_DA T_ALL_DA = new T_ALL_DA();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,
EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,
TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,IsCrmOrderFee)
VALUES
(@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency,
@exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt,
@taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@IsCrmOrderFee) ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@bsno", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16,2);
db.AddInParameter(cmdInsert, "@fee_name", DbType.String, enumValue.FEENAME);
db.AddInParameter(cmdInsert, "@customer_type", DbType.String,"");
db.AddInParameter(cmdInsert, "@customer_name", DbType.String, enumValue.CUSTOMERNAME);
db.AddInParameter(cmdInsert, "@unit", DbType.String, enumValue.UNIT);
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumValue.AMOUNT / ctnnum);
else db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumValue.AMOUNT);
var strDESCRIPTION = T_ALL_DA.GetStrSQL("DESCRIPTION", "select top 1 DESCRIPTION from code_fee where [NAME]='" + enumValue.FEENAME + "'");
db.AddInParameter(cmdInsert, "@fee_description", DbType.String, strDESCRIPTION);
db.AddInParameter(cmdInsert, "@quantity",DbType.Decimal, 1);
if (ctnnum !=0)
db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, enumValue.AMOUNT / ctnnum);
else db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdInsert, "@currency", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal,enumValue.EXCHANGERATE);
db.AddInParameter(cmdInsert, "@reason", DbType.String, "");
db.AddInParameter(cmdInsert, "@remark", DbType.String, enumValue.REMARKS);
// db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE);
db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid);
db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@is_open", DbType.String,"0");
db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String,"0");
db.AddInParameter(cmdInsert, "@sort", DbType.Int16, enumValue.ITEMSNO);
db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, feestatus);
db.AddInParameter(cmdInsert, "@fee_frt", DbType.String,"");
db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0);
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumValue.AMOUNT / ctnnum);
else db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumValue.AMOUNT);
db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, enumValue.ITEMSNO);
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.AMOUNT / ctnnum);
else db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.AMOUNT);
// db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.UNITPRICE);
db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String,"");
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, enumValue.AMOUNT / ctnnum);
else db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, enumValue.AMOUNT);
if (enumValue.PRICETYPE=="1")
db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "海运出口报价");
else if (enumValue.PRICETYPE=="2")
db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "海运进口报价");
else if (enumValue.PRICETYPE=="3")
db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "代理报价");
else if (enumValue.PRICETYPE=="4")
db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "场站报价");
else db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "");
db.AddInParameter(cmdInsert, "@IsCrmOrderFee", DbType.String, "1");
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
/// <summary>
/// 从apply表的成本核算信息生成应收费用
/// </summary>
/// <param name="ctnprice"></param>
/// <param name="bsno"></param>
/// <param name="userid"></param>
/// <param name="ctnnum"></param>
/// <param name="cust"></param>
/// <returns></returns>
public static DBResult SaveFeeDR(decimal ctnprice,string currency, string bsno, string userid, Int16 ctnnum,string cust)
{
var result = new DBResult();
int feestatus = 1;
var OPCTNFEESTATUSISAUDIT = MsSysParamSetDAL.GetData("PARAMNAME='OPCTNFEESTATUSISAUDIT'");
if (OPCTNFEESTATUSISAUDIT.PARAMVALUE == "1")
{
feestatus = 0;
}
var TANKCTNFEECUSTOMERNAME = MsSysParamSetDAL.GetData("PARAMNAME='TANKCTNFEECUSTOMERNAME'").PARAMVALUE;
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,
EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,
TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE)
VALUES
(@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency,
@exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt,
@taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE) ");
if (bsno != "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@bsno", DbType.String, bsno);
db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 1);
db.AddInParameter(cmdInsert, "@fee_name", DbType.String, "罐箱费");
db.AddInParameter(cmdInsert, "@customer_type", DbType.String, "");
db.AddInParameter(cmdInsert, "@customer_name", DbType.String, TANKCTNFEECUSTOMERNAME);
db.AddInParameter(cmdInsert, "@unit", DbType.String, "TEU");
db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, ctnprice);
db.AddInParameter(cmdInsert, "@fee_description", DbType.String, "TANK RENTAL");
db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1);
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, ctnprice);
else db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, ctnprice);
db.AddInParameter(cmdInsert, "@currency", DbType.String, currency);
var exchangerate = MsChFeeDAL.GetExrate("", "", currency);
db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, exchangerate);
db.AddInParameter(cmdInsert, "@reason", DbType.String, "");
db.AddInParameter(cmdInsert, "@remark", DbType.String, "");
// db.AddInParameter(cmdInsert, "@CARGO_GID", DbType.String, enumValue.PRICETYPE);
db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid);
db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0");
db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0");
db.AddInParameter(cmdInsert, "@sort", DbType.Int16, 0);
db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, feestatus);
db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, "");
db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0);
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, ctnprice);
else db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, ctnprice);
db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, 0);
db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, 0);
db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, "");
if (ctnnum != 0)
db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, ctnprice );
else db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, ctnprice);
db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "手工");
db.ExecuteNonQuery(cmdInsert, tran);
}
tran.Commit();
}
catch (Exception E)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员"+E.Message;
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
public static DBResult SubmitGoodsAudit(string GID,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("update op_ctnapply set AUDITSTATUS='提交审核',BSSTATUS='提交适货审核',SUBMITBY='" +userid+ "',SUBMITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "提交审核出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "提交审核成功";
return result;
}
public static DBResult SubmitGoodsAuditBack(string GID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("update op_ctnapply set AUDITSTATUS='未提交',BSSTATUS='未提交',SUBMITBY='',SUBMITTIME=null where GID='" + GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销审核出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "撤销审核成功";
return result;
}
public static DBResult AuditFee(List<OpPriceItems> 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 != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("update op_price_items set FEESTATUS=0,AUDITOPERATOR='" + userid + "',AUDITDATE='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static DBResult AuditBack(List<OpPriceItems> headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData != null)
{
foreach (var enumValue in headData)
{
var cmdDelete = db.GetSqlStringCommand("update op_price_items set FEESTATUS=6,AUDITOPERATOR='',AUDITDATE=null where GID='" + enumValue.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static string GetBillBsNo(string masterbsno)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var strSql = new StringBuilder();
strSql.Append("select top 1 bsno from op_ctnbscard where bsno like '%" + masterbsno + "%' order by bsno desc ");
var i = 1;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = Convert.ToString(reader["bsno"]);
var strnumno1=evData.Replace(masterbsno,"");
try
{
i = Convert.ToInt16(strnumno1) + 1;
}
catch (Exception)
{
}
}
reader.Close();
}
var strnum = i.ToString();
if (strnum.Length == 1) strnum = "0" + strnum;
return masterbsno + strnum;
}
public static decimal GetUsdExrate(string currdate, string curr)
{
decimal result = -1;
if (currdate == "")
{
var strSql = new StringBuilder();
strSql.Append("Select CODENAME,DEFAULTRATE ");
strSql.Append(" from code_currency where CODENAME='"+ curr + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
result = Convert.ToDecimal(reader["DEFAULTRATE"]);
}
reader.Close();
}
}
else
{
var strSql = new StringBuilder();
strSql.Append("Select CURRENCYID,VALUE ");
strSql.Append(" from currency_exchange ");
strSql.Append(" left join code_currency c on (c.GID=currency_exchange.CURRENCYID) ");
strSql.Append(" where c.CODENAME='" + curr + "' and STARTTIME<='" + currdate + "' and ENDTIME>='" + currdate + "'");
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
result = Convert.ToDecimal(reader["VALUE"]);
}
reader.Close();
}
if (result == -1)
{
var strSql2 = new StringBuilder();
strSql2.Append("Select CODENAME,DEFAULTRATE ");
strSql2.Append(" from code_currency where CODENAME='USD'");
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql2.ToString()))
{
while (reader.Read())
{
result = Convert.ToDecimal(reader["DEFAULTRATE"]);
}
reader.Close();
}
}
}
return result;
}
#region 权限范围
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
string modustr = "modOpCtnApply";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='" + modustr + "' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " (b.inputby='"+userid+"' or b.OP='" + username + "' OR b.SALE='" + username + "' or b.AGENTINPUTBY='" + username + "' )";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select GID,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.INPUTBY='" + Convert.ToString(reader["GID"]) + "' or b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.AGENTINPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
}
else
{
str = str + " or b.INPUTBY='" + Convert.ToString(reader["GID"]) + "' or b.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "' OR b.AGENTINPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "' ";
};
}
str = str + ")";
reader.Close();
}
}
else
{
str = " b.COMPANYID='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " b.COMPANYID='" + companyid + "'";
}
return str;
}
#endregion
}
}