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.

1034 lines
46 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.CommMng.DAL;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.TruckMng.Models.MsWlBs;
using DSWeb.TruckMng.DAL.MsCustTruckFeeTemplate;
namespace DSWeb.Areas.TruckMng.DAL.MsWlBs
{
public partial class MsWlBsDAL
{
static public List<MsWlBsHead> GetPcBodyList(string condition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("b.BillNo,b.LrDate,b.JzDate,b.UserCode,b.UserName,b.OrgCode,b.OrgName");
strSql.Append(",b.GId LogisticsNo,b.CustCode,b.CustName,b.CustName+'-'+b.BillNo as CustName_Ref");
//strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsWlBsHead.CustCode) as CustName_Ref");
strSql.Append(",b.CustDate,b.VoyVeg,");
strSql.Append("(select VoyName from vMsTruckVoyInfo where VoyCode=b.VoyVeg) as VoyVeg_Ref");
strSql.Append(",b.EtDate,b.EndPortDate,b.MblNo,b.SalesCode,");
strSql.Append("(select top 1 UserName from vMsTruckUser where UserCode=b.SalesCode) as SalesCode_Ref");
strSql.Append(",b.SalesName,b.DispatchCode,");
strSql.Append("(select top 1 UserName from vMsTruckUser where UserCode=b.DispatchCode) as DispatchCode_Ref");
strSql.Append(",b.DispatchName,b.SendYardCode,");
strSql.Append("(select top 1 CustName from vMsTruckClient where CustCode=b.SendYardCode) as SendYardCode_Ref");
strSql.Append(",b.SendYardName,b.RtnYardCode,b.RtnYard,b.DstArea,b.DetiNation,b.DetiLinkTel,b.DetiLinkMan");
strSql.Append(",b.Remark,b.BsType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99025 and EnumValueID=b.BsType) as BsType_Ref");
strSql.Append(",b.BillStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99026 and EnumValueID=b.BillStatus) as BillStatus_Ref");
strSql.Append(",b.BsStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99029 and EnumValueID=b.BsStatus) as BsStatus_Ref");
strSql.Append(",b.FeeStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99027 and EnumValueID=b.FeeStatus) as FeeStatus_Ref");
strSql.Append(",d.GId, convert(bigint ,TimeMark) as TimeMark");
strSql.Append(",b.CustLikeManCode,b.CustLikeManName,b.CustTel");
strSql.Append(",b.NeadLoadDate,b.NeedArriveDate,b.BillRises1");
strSql.Append(",b.FeeOpStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99035 and EnumValueID=b.FeeOpStatus) as FeeOpStatus_Ref");
strSql.Append(",b.VoyVegSe,b.GoodsName");
strSql.Append(",0 pctype");//0派车 1未派车 用来对应费用颜色1录入状态无色 0审核通过绿色
strSql.Append(",dbo.f_bs_truckNo(b.billno) TruckNo,d.LINKGID CtnInfo");
strSql.Append(",b.PKGS,b.KINDPKGS,b.KGS,b.CBM");
strSql.Append(",0 PCPKGS,0 PCKGS,0 PCCBM,b.LoadPlace,b.FactoryAddr");
strSql.Append(",b.TRANSSTATUS,b.ORDERNO,b.CONTRACTNO,b.TEMPLATENAME,b.ISFEE,b.PORTLOAD,d.ContainerType,d.ContainerQty");
strSql.Append(" from tMsWlPcHead_detail d left join tMsWlBsHead b on (b.gid=d.LINKBSNO) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" where " + condition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by b.LrDate desc ");
}
return SetPcBodyData(strSql);
}
private static List<MsWlBsHead> SetPcBodyData(StringBuilder strSql)
{
var headList = new List<MsWlBsHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBsHead data = new MsWlBsHead();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
if (reader["LrDate"] != DBNull.Value)
data.LrDate = Convert.ToDateTime(Convert.ToDateTime(reader["LrDate"]).ToString("yyyy-MM-dd HH:mm:ss"));
if (reader["JzDate"] != DBNull.Value)
data.JzDate = Convert.ToDateTime(reader["JzDate"]);
data.ContainerType= Convert.ToString(reader["ContainerType"]);
if (reader["ContainerQty"] != DBNull.Value)
data.ContainerQty = Convert.ToString(reader["ContainerQty"]);
data.UserCode = Convert.ToString(reader["UserCode"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
data.LogisticsNo = Convert.ToString(reader["LogisticsNo"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CustName_Ref = Convert.ToString(reader["CustName_Ref"]);
data.CustDate = Convert.ToString(reader["CustDate"]);
data.VoyVeg = Convert.ToString(reader["VoyVeg"]);
data.VoyVeg_Ref = Convert.ToString(reader["VoyVeg_Ref"]);
data.EtDate = Convert.ToString(reader["EtDate"]);
data.EndPortDate = Convert.ToString(reader["EndPortDate"]);
data.MblNo = Convert.ToString(reader["MblNo"]);
data.SalesCode = Convert.ToString(reader["SalesCode"]);
data.SalesCode_Ref = Convert.ToString(reader["SalesCode_Ref"]);
data.SalesName = Convert.ToString(reader["SalesName"]);
data.DispatchCode = Convert.ToString(reader["DispatchCode"]);
data.DispatchCode_Ref = Convert.ToString(reader["DispatchCode_Ref"]);
data.DispatchName = Convert.ToString(reader["DispatchName"]);
data.SendYardCode = Convert.ToString(reader["SendYardCode"]);
data.SendYardCode_Ref = Convert.ToString(reader["SendYardCode_Ref"]);
data.SendYardName = Convert.ToString(reader["SendYardName"]);
data.RtnYardCode = Convert.ToString(reader["RtnYardCode"]);
data.RtnYard = Convert.ToString(reader["RtnYard"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.FactoryAddr = Convert.ToString(reader["FactoryAddr"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.DetiLinkTel = Convert.ToString(reader["DetiLinkTel"]);
data.DetiLinkMan = Convert.ToString(reader["DetiLinkMan"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.BsType_Ref = Convert.ToString(reader["BsType_Ref"]);
data.BillStatus = Convert.ToString(reader["BillStatus"]);
data.BillStatus_Ref = Convert.ToString(reader["BillStatus_Ref"]);
data.FeeStatus = Convert.ToString(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
data.BsStatus = Convert.ToString(reader["BsStatus"]);
data.BsStatus_Ref = Convert.ToString(reader["BsStatus_Ref"]);
data.GId = Convert.ToString(reader["GId"]);
if (reader["TimeMark"] != DBNull.Value)
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.CustLikeManCode = Convert.ToString(reader["CustLikeManCode"]);
data.CustLikeManName = Convert.ToString(reader["CustLikeManName"]);
data.CustTel = Convert.ToString(reader["CustTel"]);
data.NeadLoadDate = Convert.ToString(reader["NeadLoadDate"]);
data.NeedArriveDate = Convert.ToString(reader["NeedArriveDate"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.FeeOpStatus = Convert.ToString(reader["FeeOpStatus"]);
data.FeeOpStatus_Ref = Convert.ToString(reader["FeeOpStatus_Ref"]);
data.VoyVegSe = Convert.ToString(reader["VoyVegSe"]);
data.GoodsName = Convert.ToString(reader["GoodsName"]);
data.PcType = Convert.ToString(reader["PcType"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.CtnInfo = Convert.ToString(reader["CtnInfo"]);
if (reader["PKGS"] != DBNull.Value)
data.PKGS = Convert.ToDecimal(reader["PKGS"]);
if (reader["KGS"] != DBNull.Value)
data.KGS = Convert.ToDecimal(reader["KGS"]);
if (reader["CBM"] != DBNull.Value)
data.CBM = Convert.ToDecimal(reader["CBM"]);
data.KINDPKGS = Convert.ToString(reader["KINDPKGS"]);
if (reader["PCPKGS"] != DBNull.Value)
data.PCPKGS = Convert.ToDecimal(reader["PCPKGS"]);
if (reader["PCKGS"] != DBNull.Value)
data.PCKGS = Convert.ToDecimal(reader["PCKGS"]);
if (reader["PCCBM"] != DBNull.Value)
data.PCCBM = Convert.ToDecimal(reader["PCCBM"]);
data.NPKGS = data.PKGS - data.PCPKGS;
data.NKGS = data.KGS - data.PCKGS;
data.NCBM = data.CBM - data.PCCBM;
data.TRANSSTATUS = Convert.ToString(reader["TRANSSTATUS"]);
data.ORDERNO = Convert.ToString(reader["ORDERNO"]);
data.CONTRACTNO = Convert.ToString(reader["CONTRACTNO"]);
data.TEMPLATENAME = Convert.ToString(reader["TEMPLATENAME"]);
data.ISFEE = Convert.ToString(reader["ISFEE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult CreateFeeDetail(MsWlBsHead headData, List<MsWlBsCtn> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsertFee =
db.GetSqlStringCommand(
@"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY,
EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT,CARGO_GID,
TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,ISINVOICE,INPUTMODE,LOCALCURR,MANAGER,ISACC)
VALUES(@GID,@BSNO,@FEETYPE,@FEENAME,@FEEDESCRIPTION,@CUSTOMERTYPE,@CUSTOMERNAME,@UNIT,@UNITPRICE,@QUANTITY,@AMOUNT,@CURRENCY,
@EXCHANGERATE, @REASON, @REMARK, @COMMISSIONRATE,@ENTEROPERATOR, @ENTERDATE,@ISOPEN, @ISADVANCEDPAY, @SORT, @FEESTATUS, @FEEFRT,@CARGO_GID,
@TAXRATE,@NOTAXAMOUNT,@ACCTAXRATE,@LINENUM,@TAXUNITPRICE,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@ISINVOICE,@INPUTMODE,@LOCALCURR,@MANAGER,@ISACC)
");
var feetemplatelist = MsCustTruckFeeTempldateDAL.GetBodyList(" TEMPLATEID in (select gid from [Cust_Truck_feetemplate] where TEMPLATENAME='" + headData.TEMPLATENAME + "' and CONTRACTNO='" + headData.CONTRACTNO + "' and TRANTYPE='集装箱' )");
if (bodyList != null&& feetemplatelist.Count!=0)
{
foreach (var enumValue in bodyList)
{
decimal unitprice = 0;
foreach (var feetemplate in feetemplatelist)
{
if (feetemplate.UNIT == enumValue.ContainerType) unitprice = feetemplate.UNITPRICE;
}
if (headData.ISFEE != "1")
{
cmdInsertFee.Parameters.Clear();
db.AddInParameter(cmdInsertFee, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertFee, "@BSNO", DbType.String, headData.GId);
db.AddInParameter(cmdInsertFee, "@FEETYPE", DbType.Int16, 1);
db.AddInParameter(cmdInsertFee, "@FEENAME", DbType.String, "陆运费");
db.AddInParameter(cmdInsertFee, "@FEEDESCRIPTION", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@CUSTOMERTYPE", DbType.String, "委托单位");
db.AddInParameter(cmdInsertFee, "@CUSTOMERNAME", DbType.String, headData.CustName);
db.AddInParameter(cmdInsertFee, "@UNIT", DbType.String, enumValue.ContainerType);
db.AddInParameter(cmdInsertFee, "@UNITPRICE", DbType.Decimal, unitprice);
db.AddInParameter(cmdInsertFee, "@QUANTITY", DbType.Decimal, enumValue.ContainerQty);
db.AddInParameter(cmdInsertFee, "@AMOUNT", DbType.Decimal, unitprice* enumValue.ContainerQty);
db.AddInParameter(cmdInsertFee, "@CURRENCY", DbType.String, "RMB");
db.AddInParameter(cmdInsertFee, "@EXCHANGERATE", DbType.Decimal, 1);
db.AddInParameter(cmdInsertFee, "@REASON", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@REMARK", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@COMMISSIONRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertFee, "@ENTEROPERATOR", DbType.String, userid);
db.AddInParameter(cmdInsertFee, "@ENTERDATE", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdInsertFee, "@ISOPEN", DbType.Boolean, false);
db.AddInParameter(cmdInsertFee, "@ISADVANCEDPAY", DbType.Boolean, false);
db.AddInParameter(cmdInsertFee, "@SORT", DbType.Int16, 1);
db.AddInParameter(cmdInsertFee, "@FEESTATUS", DbType.Int16, 0);
db.AddInParameter(cmdInsertFee, "@FEEFRT", DbType.String, "PP");
db.AddInParameter(cmdInsertFee, "@CARGO_GID", DbType.String, headData.GId);
db.AddInParameter(cmdInsertFee, "@TAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertFee, "@NOTAXAMOUNT", DbType.Decimal,unitprice* enumValue.ContainerQty);
db.AddInParameter(cmdInsertFee, "@ACCTAXRATE", DbType.Decimal, 0);
db.AddInParameter(cmdInsertFee, "@LINENUM", DbType.Int16, 1);
db.AddInParameter(cmdInsertFee, "@TAXUNITPRICE", DbType.Decimal, unitprice);
db.AddInParameter(cmdInsertFee, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdInsertFee, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString());
db.AddInParameter(cmdInsertFee, "@WMSOUTBSNO", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@PREAMOUNT", DbType.Decimal, 0);
db.AddInParameter(cmdInsertFee, "@ISINVOICE", DbType.Boolean, false);
db.AddInParameter(cmdInsertFee, "@INPUTMODE", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@LOCALCURR", DbType.String, "RMB");
db.AddInParameter(cmdInsertFee, "@MANAGER", DbType.String, "");
db.AddInParameter(cmdInsertFee, "@ISACC", DbType.Boolean, false);
db.ExecuteNonQuery(cmdInsertFee, tran);
var cmdUpdateBL =
db.GetSqlStringCommand(
@"update tMsWlBsHead set ISFEE='1' where BillNo=@BillNo ");
cmdUpdateBL.Parameters.Clear();
db.AddInParameter(cmdUpdateBL, "@BillNo", DbType.String,headData.BillNo);
db.ExecuteNonQuery(cmdUpdateBL, tran);
}
}
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "生成费用出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "生成成功";
return result;
}
public static DBResult DelCreateFee(MsWlBsHead headData, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData.ISFEE == "1")
{
var cmdDelFee =
db.GetSqlStringCommand(
@"delete from ch_fee where BSNO=@BSNO and CARGO_GID=@CARGO_GID ");
cmdDelFee.Parameters.Clear();
db.AddInParameter(cmdDelFee, "@BSNO", DbType.String, headData.GId);
db.AddInParameter(cmdDelFee, "@CARGO_GID", DbType.String, headData.GId);
db.ExecuteNonQuery(cmdDelFee, tran);
var cmdUpdateBL =
db.GetSqlStringCommand(
@"update tMsWlBsHead set ISFEE='0' where BillNo=@BillNo ");
cmdUpdateBL.Parameters.Clear();
db.AddInParameter(cmdUpdateBL, "@BillNo", DbType.String, headData.BillNo);
db.ExecuteNonQuery(cmdUpdateBL, tran);
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "生成费用出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "生成成功";
return result;
}
public static DBResult DeletetruckDetail(MsWlBsHead bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
//if (bodyList != null)
//{
// foreach (var enumValue in bodyList)
// {
var cmdDelete = db.GetSqlStringCommand("delete from tMsWlPcHead_detail where GID='" + bodyList.GId + "'");
db.ExecuteNonQuery(cmdDelete, tran);
// }
//}
var cmdUpdate =
db.GetSqlStringCommand(
@"update tMsWlBsCtn set PCQTY=isnull(PCQTY,0)-@PCQTY where GID=@GID ");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, bodyList.CtnInfo);
db.AddInParameter(cmdUpdate, "@PCQTY", DbType.Decimal, bodyList.ContainerQty);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
public static bool GetFeeCount(string BSNO, string condition = "")
{
var isfee = false;
String strSql = "Select count(*) as count from ch_fee where BSNO='" + BSNO + "'";
if (condition != "")
strSql = strSql + " and " + condition;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql))
{
while (reader.Read())
{
var evData = Convert.ToInt32(reader["count"]);
if (evData > 0) { isfee = true; };
}
reader.Close();
}
return isfee;
}
public static DBResult AddBill(MsWlPcHead_WFSDEdit headData, List<MsWlBsHead> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into tMsWlPcHead_detail (GID,BSNO,LINKGID,LINKBSNO,ContainerType,ContainerQty,CREATEUSER,CREATETIME)
values (@GID,@BSNO,@LINKGID,@LINKBSNO,@ContainerType,@ContainerQty,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update tMsWlBsCtn set PCQTY=isnull(PCQTY,0)+@PCQTY where GID=@GID ");
//var cmdUpdatePc =
// db.GetSqlStringCommand(
// @"update op_truck_bulk_pc set PKGS=isnull((SELECT SUM(PKGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),KGS=isnull((SELECT SUM(KGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),
//CBM=isnull((SELECT SUM(CBM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) from op_truck_bulk_pc B where BSNO=@BSNO ");
if (bodyList != null)
{
foreach (var bulk in bodyList)
{
var detaillist = GetCtnBodyList("BillNo='" + bulk.GId + "' and ISNULL(PCQTY,0)<>ContainerQty ");
if (detaillist != null)
{
foreach (var enumValue in detaillist)
{
cmdInsert.Parameters.Clear();
var GID = Guid.NewGuid().ToString();
db.AddInParameter(cmdInsert, "@GID", DbType.String, GID);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, headData.BillNo);
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, enumValue.GID);
db.AddInParameter(cmdInsert, "@LINKBSNO", DbType.String, enumValue.BillNo);
var pkgs = enumValue.ContainerQty-enumValue.PCQTY;
if (pkgs < 0) pkgs = 0;
db.AddInParameter(cmdInsert, "@ContainerQty", DbType.Decimal, pkgs);
db.AddInParameter(cmdInsert, "@ContainerType", DbType.String, enumValue.ContainerType);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@PCQTY", DbType.Decimal, pkgs);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
//cmdUpdatePc.Parameters.Clear();
//db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO);
//db.ExecuteNonQuery(cmdUpdatePc, tran);
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "添加成功";
return result;
}
public static DBResult AddDetail(MsWlPcHead_WFSDEdit headData, List<MsWlBsCtn> bodyList, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into tMsWlPcHead_detail (GID,BSNO,LINKGID,LINKBSNO,ContainerType,ContainerQty,CREATEUSER,CREATETIME)
values (@GID,@BSNO,@LINKGID,@LINKBSNO,@ContainerType,@ContainerQty,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update tMsWlBsCtn set PCQTY=isnull(PCQTY,0)+@PCQTY where GID=@GID ");
//var cmdUpdatePc =
// db.GetSqlStringCommand(
// @"update op_truck_bulk_pc set PKGS=isnull((SELECT SUM(PKGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),KGS=isnull((SELECT SUM(KGS) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0),
//CBM=isnull((SELECT SUM(CBM) FROM op_truck_bulk_pc_detail where BSNO=B.BSNO),0) from op_truck_bulk_pc B where BSNO=@BSNO ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
var GID = enumValue.GID;
cmdInsert.Parameters.Clear();
GID = Guid.NewGuid().ToString();
db.AddInParameter(cmdInsert, "@GID", DbType.String, GID);
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, headData.BillNo);
db.AddInParameter(cmdInsert, "@LINKGID", DbType.String, enumValue.GID);
db.AddInParameter(cmdInsert, "@LINKBSNO", DbType.String, enumValue.BillNo);
var pkgs =enumValue.NPCQTY;
if (pkgs < 0) pkgs = 0;
db.AddInParameter(cmdInsert, "@ContainerQty", DbType.Decimal, pkgs);
db.AddInParameter(cmdInsert, "@ContainerType", DbType.String, enumValue.ContainerType);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString());
db.ExecuteNonQuery(cmdInsert, tran);
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@PCQTY", DbType.Decimal, enumValue.NPCQTY);
db.ExecuteNonQuery(cmdUpdate, tran);
}
//cmdUpdatePc.Parameters.Clear();
//db.AddInParameter(cmdUpdatePc, "@BSNO", DbType.String, headData.BSNO);
//db.ExecuteNonQuery(cmdUpdatePc, tran);
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "添加过程出现错误,请重试或联系系统管理员" + e.Message;
return result;
}
}
result.Success = true;
result.Message = "添加成功";
return result;
}
//public static DBResult DeletetruckBulkDetail(MsOpTruckBulkPcDetail bodyList)
//{
// var result = new DBResult();
// Database db = DatabaseFactory.CreateDatabase();
// using (var conn = db.CreateConnection())
// {
// conn.Open();
// var tran = conn.BeginTransaction();
// try
// {
// //if (bodyList != null)
// //{
// // foreach (var enumValue in bodyList)
// // {
// var cmdDelete = db.GetSqlStringCommand("delete from op_truck_bulk_pc_detail where GID='" + bodyList.GID + "'");
// db.ExecuteNonQuery(cmdDelete, tran);
// // }
// //}
// var cmdUpdate =
// db.GetSqlStringCommand(
// @"update op_truck_bulk_detail set PCPKGS=isnull(PCPKGS,0)-@PKGS,PCKGS=isnull(PCKGS,0)-@KGS,PCCBM=isnull(PCCBM,0)-@CBM where GID=@GID ");
// cmdUpdate.Parameters.Clear();
// db.AddInParameter(cmdUpdate, "@GID", DbType.String, bodyList.LINKGID);
// db.AddInParameter(cmdUpdate, "@PKGS", DbType.Decimal, bodyList.PKGS);
// db.AddInParameter(cmdUpdate, "@KGS", DbType.Decimal, bodyList.KGS);
// db.AddInParameter(cmdUpdate, "@CBM", DbType.Decimal, bodyList.CBM);
// db.ExecuteNonQuery(cmdUpdate, tran);
// tran.Commit();
// }
// catch (Exception e)
// {
// tran.Rollback();
// result.Success = false;
// result.Message = "删除出现错误,请重试或联系系统管理员" + e.Message;
// return result;
// }
// }
// result.Success = true;
// result.Message = "删除成功";
// return result;
//}
public static DBResult UpTransStatus(List<MsWlPcHead_WFSDEdit> boday, string status)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var errmsg = "";
if (boday != null)
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlPcHead set TRANSSTATUS=@TRANSSTATUS where GID=@GID");
foreach (var enumValue in boday)
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@TRANSSTATUS", DbType.String, status);
db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.gId);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
result = new DBResult();
result.Success = true;
result.Message = "更新完成";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "更新出现错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static int p_update_status(string bsno)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("p_update_WlBsHead");
db.AddInParameter(cmd, "@con_no", DbType.String, bsno);
db.ExecuteNonQuery(cmd);
return 0;
}
#region 审核和撤销审核
public static DBResult SubmitAudit(String USERID, List<MsWlBsHead> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.TEMPLATENAME != "")
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='审核通过' where BillNo=@BillNo");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "提交审核成功";
}
else
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowStart("OpTruckBulkAudit", enumValue.BillNo, USERID,enumValue.BillNo,enumValue.BillNo,"");
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("BillNo=@BillNo");
if (WorkResult.islast == true)
{
cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='审核通过' where BillNo=@BillNo");
}
else
{
cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='提交审核' where BillNo=@BillNo");
}
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "提交审核成功";
}
else
{
result = new DBResult();
result.Success = false;
result.Message = "提交审核错误,请检查工作流!";
}
}
}
}
//if (result.Success != false)
//{
// result = new DBResult();
// result.Success = true;
// result.Message = "提交审核成功";
//}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "提交审核错误,请重试或联系系统管理员 " + e.Message;
return result;
}
}
return result;
}
public static DBResult SubmitAuditBack(String USERID, List<MsWlBsHead> bodyList)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.TEMPLATENAME != "")
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='新增' where BillNo=@BillNo");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销提交成功";
}
else
{
Resultmb WorkResult = WorkFlowDAL.WorkFlowReset("OpTruckBulkAudit", enumValue.BillNo, USERID);
if (WorkResult.Success == true)
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='新增' where BillNo=@BillNo");
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
result = new DBResult();
result.Success = true;
result.Message = "撤销提交成功";
}
else
{
result = new DBResult();
result.Success = false;
result.Message = "不允许撤回提交!";
}
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "撤销提交错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult AuditList(List<MsWlBsHead> boday, String USERID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var errmsg = "";
if (boday != null)
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='审核通过' where BillNo=@BillNo");
// var cmdupdate2 = db.GetSqlStringCommand("update op_truck_bulk set AUDITUSER='" + USERID + "',AUDITTIME='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where BSNO=@BSNO");
foreach (var enumValue in boday)
{
Resultmb WorkResult = WorkFlowDAL.InsertWorkFlowDo("OpTruckBulkAudit", enumValue.BillNo, USERID, tran,enumValue.BillNo);
if (WorkResult.Success == true)
{
if (WorkResult.islast == true)
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
//cmdupdate2.Parameters.Clear();
//db.AddInParameter(cmdupdate2, "@BSNO", DbType.String, enumValue.BSNO);
//db.ExecuteNonQuery(cmdupdate2, tran);
}
}
}
}
result = new DBResult();
result.Success = true;
result.Message = "审核通过";
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "审核出现错误,请重试或联系系统管理员";
return result;
}
}
return result;
}
public static DBResult AuditBackList(List<MsWlBsHead> boday, String USERID, string reason)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (boday != null)
{
var cmdupdate = db.GetSqlStringCommand("update tMsWlBsHead set TRANSSTATUS='驳回提交' where BillNo=@BillNo");
foreach (var enumValue in boday)
{
if (enumValue.TRANSSTATUS == "提交审核" || enumValue.TRANSSTATUS == "审核通过")
{
if (enumValue.TEMPLATENAME != "")
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
Resultmb WorkResult = WorkFlowDAL.DeleteWorkFlowDo("OpTruckBulkAudit", enumValue.BillNo, USERID, reason, enumValue.BillNo, enumValue.BillNo, "驳回提交URL");
if (WorkResult.Success == true)
{
cmdupdate.Parameters.Clear();
db.AddInParameter(cmdupdate, "@BillNo", DbType.String, enumValue.BillNo);
db.ExecuteNonQuery(cmdupdate, tran);
}
}
}
}
}
result = new DBResult();
result.Success = true;
result.Message = "完成驳回";
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "驳回出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "完成驳回";
return result;
}
#endregion
}
}