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/TruckMng/DAL/MsWlDjPc/MsWlDjPcDAL.cs

545 lines
24 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWlDjPc;
using DSWeb.TruckMng.Comm.Cookie;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
namespace DSWeb.Areas.TruckMng.DAL.MsWlDjPc
{
public partial class MsWlDjPcDAL
{
#region 主表
static public List<MsWlPcHead> GetDataList(string strCondition,string userid,string usercode,string orgcode)
{
var rangstr = GetRangDAStr("index", userid, usercode, orgcode);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,LrDate,JzDate,UserCode,UserName,OrgCode,OrgName");
strSql.Append(",TruckNo,");
strSql.Append("(select TruckNo from tMsWlTruck where TruckNo=tMsWlPcHead.TruckNo) as TruckNo_Ref");
strSql.Append(",DrvCode,");
strSql.Append("(select DrvName from tMsWlDriver where DrvCode=tMsWlPcHead.DrvCode) as DrvCode_Ref");
strSql.Append(",DrvName,Mobile,dbo.trimdate(ExpDate) ExpDate");
strSql.Append(",DstArea,DetiNation,FactoryAddr,LinkTel,LinkMan,RatedMil");
strSql.Append(",RatedFuel,FuelQty,RealMil,RealFuel,NoLoadMil,OverLoadMil,Ton");
strSql.Append(",AroundTon,LoadCount,ArriveDate,DdCode,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsWlPcHead.DdCode) as DdCode_Ref");
strSql.Append(",DdName,ReturnDate,RefBillNo,Remark");
strSql.Append(",BillStatus,");
strSql.Append(
"(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99026 and EnumValueID=tMsWlPcHead.BillStatus) as BillStatus_Ref");
strSql.Append(",FeeStatus,");
strSql.Append(
"(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99027 and EnumValueID=tMsWlPcHead.FeeStatus) as FeeStatus_Ref");
strSql.Append(",GId,TotalMil, convert(bigint ,TimeMark) as TimeMark,LoadPlace,LoadFuel,NoLoadFuel,BsType,");
strSql.Append(
"(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99025 and EnumValueID=tMsWlPcHead.BsType) as BsType_Ref");
strSql.Append(",ArriveTime,ReturnTime");
//strSql.Append(",NeadLoadDate,NeedArriveDate");
strSql.Append(",BillRises1,ChangedMil,ChangedFuel,ChangedReson");
strSql.Append(",FeeOpStatus,");
strSql.Append(
"(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99035 and EnumValueID=tMsWlPcHead.FeeOpStatus) as FeeOpStatus_Ref");
strSql.Append(",RunTimes,PcBillType");
strSql.Append(",(select sum(UNITPRICE) from ch_fee where BSNO= tMsWlPcHead.GId) TransTotal ");
strSql.Append(" from tMsWlPcHead ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by LrDate desc ");
return SetData(strSql);
}
private static List<MsWlPcHead> SetData(StringBuilder strSql)
{
var headList = new List<MsWlPcHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlPcHead data = new MsWlPcHead();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
if (reader["LrDate"] != DBNull.Value)
data.LrDate = Convert.ToDateTime(reader["LrDate"]);
if (reader["JzDate"] != DBNull.Value)
data.JzDate = Convert.ToDateTime(reader["JzDate"]);
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.TruckNo = Convert.ToString(reader["TruckNo"]);
data.TruckNo_Ref = Convert.ToString(reader["TruckNo_Ref"]);
data.DrvCode = Convert.ToString(reader["DrvCode"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
data.DrvCode_Ref = Convert.ToString(reader["DrvCode_Ref"]);
data.Mobile = Convert.ToString(reader["Mobile"]);
data.ExpDate = Convert.ToString(reader["ExpDate"]);
data.DstArea = Convert.ToString(reader["DstArea"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.FactoryAddr = Convert.ToString(reader["FactoryAddr"]);
data.LinkTel = Convert.ToString(reader["LinkTel"]);
data.LinkMan = Convert.ToString(reader["LinkMan"]);
data.RatedMil = Convert.ToDecimal(reader["RatedMil"]);
data.RatedFuel = Convert.ToDecimal(reader["RatedFuel"]);
data.FuelQty = Convert.ToDecimal(reader["FuelQty"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.RealFuel = Convert.ToDecimal(reader["RealFuel"]);
data.NoLoadMil = Convert.ToDecimal(reader["NoLoadMil"]);
data.OverLoadMil = Convert.ToDecimal(reader["OverLoadMil"]);
data.Ton = Convert.ToDecimal(reader["Ton"]);
data.AroundTon = Convert.ToDecimal(reader["AroundTon"]);
data.LoadCount = Convert.ToDecimal(reader["LoadCount"]);
data.ArriveDate = Convert.ToString(reader["ArriveDate"]);
data.DdCode = Convert.ToString(reader["DdCode"]);
data.DdCode_Ref = Convert.ToString(reader["DdCode_Ref"]);
data.DdName = Convert.ToString(reader["DdName"]);
data.ReturnDate = Convert.ToString(reader["ReturnDate"]);
data.RefBillNo = Convert.ToString(reader["RefBillNo"]);
data.Remark = Convert.ToString(reader["Remark"]);
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.GId = Convert.ToString(reader["GId"]);
data.TotalMil = Convert.ToDecimal(reader["TotalMil"]);
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.LoadFuel = Convert.ToDecimal(reader["LoadFuel"]);
data.NoLoadFuel = Convert.ToDecimal(reader["NoLoadFuel"]);
data.BsType = Convert.ToString(reader["BsType"]);
data.BsType_Ref = Convert.ToString(reader["BsType_Ref"]);
data.ArriveTime = Convert.ToString(reader["ArriveTime"]);
data.ReturnTime = Convert.ToString(reader["ReturnTime"]);
data.BillRises1 = Convert.ToString(reader["BillRises1"]);
data.ChangedMil = Convert.ToDecimal(reader["ChangedMil"]);
data.ChangedFuel = Convert.ToDecimal(reader["ChangedFuel"]);
data.ChangedReson = Convert.ToString(reader["ChangedReson"]);
data.FeeOpStatus = Convert.ToString(reader["FeeOpStatus"]);
data.FeeOpStatus_Ref = Convert.ToString(reader["FeeOpStatus_Ref"]);
data.RunTimes = Convert.ToDecimal(reader["RunTimes"]);
data.PcBillType = Convert.ToString(reader["PcBillType"]);
data.TransTotal = Convert.ToString(reader["TransTotal"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public MsWlPcHead GetHeadDataByBillNo(string billno,string userid,string usercode,string orgcode)
{
MsWlPcHead data = null;
var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsWlPcHead();
}
return data;
}
#endregion
#region 明细表Pound
static public List<MsWlDjPound> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,DjBillNo,GId,CustCode,");
strSql.Append("(select CodeAndName from vMsTruckClient where CustCode=tMsWlDjPound.CustCode) as CustCode_Ref");
strSql.Append(",CustName,");
strSql.Append("ClsName,DepartureDate,LoadPlace,UnLoadPlace");
strSql.Append(",PlanOverLoadMil,PlanNoLoadMil,PlanLoadCount,OverLoadMil,NoLoadMil,LoadCount,PNum,PKgs,Weight");
strSql.Append(",RatedFuel,RealFuel,TonMil,WorkTime");
strSql.Append(" from tMsWlDjPound ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetBodyData(strSql);
}
private static List<MsWlDjPound> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsWlDjPound>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlDjPound data = new MsWlDjPound();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.DjBillNo = Convert.ToString(reader["DjBillNo"]);
data.GId = Convert.ToString(reader["GId"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustCode_Ref = Convert.ToString(reader["CustCode_Ref"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.ClsName = Convert.ToString(reader["ClsName"]);
data.DepartureDate = Convert.ToString(reader["DepartureDate"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.UnLoadPlace = Convert.ToString(reader["UnLoadPlace"]);
data.PlanOverLoadMil = Convert.ToDecimal(reader["PlanOverLoadMil"]);
data.PlanNoLoadMil = Convert.ToDecimal(reader["PlanNoLoadMil"]);
data.PlanLoadCount = Convert.ToDecimal(reader["PlanLoadCount"]);
data.OverLoadMil = Convert.ToDecimal(reader["OverLoadMil"]);
data.NoLoadMil = Convert.ToDecimal(reader["NoLoadMil"]);
data.LoadCount = Convert.ToDecimal(reader["LoadCount"]);
data.PNum = Convert.ToDecimal(reader["PNum"]);
data.PKgs = Convert.ToDecimal(reader["PKgs"]);
data.Weight = Convert.ToDecimal(reader["Weight"]);
data.RatedFuel = Convert.ToDecimal(reader["RatedFuel"]);
data.RealFuel = Convert.ToDecimal(reader["RealFuel"]);
data.TonMil = Convert.ToDecimal(reader["TonMil"]);
data.WorkTime = Convert.ToString(reader["WorkTime"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 明细表
static public List<MsWlPcFixed> GetFixBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,CreditDebit,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99020 and EnumValueID=tMsWlPcFixed.CreditDebit) as CreditDebit_Ref");
strSql.Append(",FeeTypeCode,");
strSql.Append("(select Name from vMsTruckFeeType where FeeCode=tMsWlPcFixed.FeeTypeCode) as FeeTypeCode_Ref");
strSql.Append(",FeeTypeName,DistCount,Price,FsTotal,JsTotal,Remark,GId");
strSql.Append(",FeeStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99024 and EnumValueID=tMsWlPcFixed.FeeStatus) as FeeStatus_Ref");
strSql.Append(",SubmitDate,Auditoperator,AuditDate,AuditStatus");
strSql.Append(" from tMsWlPcFixed ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetFixBodyData(strSql);
}
private static List<MsWlPcFixed> SetFixBodyData(StringBuilder strSql)
{
var bodyList = new List<MsWlPcFixed>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlPcFixed data = new MsWlPcFixed();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.CreditDebit = Convert.ToString(reader["CreditDebit"]);
data.CreditDebit_Ref = Convert.ToString(reader["CreditDebit_Ref"]);
data.FeeTypeCode = Convert.ToString(reader["FeeTypeCode"]);
data.FeeTypeCode_Ref = Convert.ToString(reader["FeeTypeCode_Ref"]);
data.FeeTypeName = Convert.ToString(reader["FeeTypeName"]);
data.DistCount = Convert.ToDecimal(reader["DistCount"]);
data.Price = Convert.ToDecimal(reader["Price"]);
data.FsTotal = Convert.ToDecimal(reader["FsTotal"]);
data.JsTotal = Convert.ToDecimal(reader["JsTotal"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.GId = Convert.ToString(reader["GId"]);
data.FeeStatus = Convert.ToDecimal(reader["FeeStatus"]);
data.FeeStatus_Ref = Convert.ToString(reader["FeeStatus_Ref"]);
if (reader["SubmitDate"] != DBNull.Value)
data.SubmitDate = Convert.ToDateTime(reader["SubmitDate"]);
data.Auditoperator = Convert.ToString(reader["Auditoperator"]);
if (reader["AuditDate"] != DBNull.Value)
data.AuditDate = Convert.ToDateTime(reader["AuditDate"]);
data.AuditStatus = Convert.ToDecimal(reader["AuditStatus"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 参照部分
internal static List<MsWlPcHeadRefMsWlTruck> GetTruckNoList(string userid, string usercode, string orgcode)
{
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" A.TruckNo,A.DrvCode,isnull((select Mobile from tMsWlDriver B where B.DrvCode=A.DrvCode),'') as Mobile ");
strSql.Append(" from tMsWlTruck A");
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" where " + rangstr);
}
// strSql.Append(" from tMsWlTruck where UPPER(OrgCode)='" + OrgCode + "'");
var dataList = new List<MsWlPcHeadRefMsWlTruck>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWlPcHeadRefMsWlTruck();
#region Set DB data to Object
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.DrvCode = Convert.ToString(reader["DrvCode"]);
data.Mobile = Convert.ToString(reader["Mobile"]);
#endregion
dataList.Add(data);
}
reader.Close();
}
return dataList;
}
internal static List<MsWlPcHeadRefMsWlDriver> GetDrvNameList(string userid, string usercode, string orgcode)
{
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" DrvCode,DrvName");
strSql.Append(" from tMsWlDriver ");
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" where " + rangstr);
}
var dataList = new List<MsWlPcHeadRefMsWlDriver>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWlPcHeadRefMsWlDriver();
#region Set DB data to Object
data.DrvCode = Convert.ToString(reader["DrvCode"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
data.CodeAndName = data.DrvCode + "-" + data.DrvName;
#endregion
dataList.Add(data);
}
reader.Close();
}
return dataList;
}
public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modTruckDjCard' 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")
{
if (tb == "index")
{
str = " (UserCode='" + usercode + "' or DdCode='"+usercode+"')";
}
else if (tb == "index2")
{
str = " UserCode='" + usercode + "'";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var companyid = rangeDa.GetCORPID(userid);
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (UserCode in (select codename from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " or DdCode in (select codename from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
internal static decimal GetTruckFuel(string truckNo, string loadType, decimal ton, decimal mil)
{
var strSql = new StringBuilder();
strSql.Append("select CraneFuel,FuelTotal,FuelPrice ");
strSql.Append(" from vMsWlTruckFuel ");
strSql.Append(" where TruckNo='{0}' and LoadType='{1}'");
var sql = strSql.ToString();
sql = string.Format(sql, truckNo, loadType);
decimal fuel = 0;
decimal cranefuel = 0;
decimal fueltotal = 0;
decimal total = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
cranefuel = Convert.ToDecimal(reader["CraneFuel"]);
fueltotal = Convert.ToDecimal(reader["FuelTotal"]);
fuel = Convert.ToDecimal(reader["FuelPrice"]);
break;
}
reader.Close();
}
if (loadType== "1")
{
total = decimal.Round((mil * ton * fuel / 1000)+(mil * fueltotal / 100), 2);
return total;
}
else if (loadType == "0")
{
total = decimal.Round((cranefuel*ton/100)+(mil * fueltotal / 100), 2);
}
return total;
}
#endregion
public static List<MsWlDjPoundRefMsWlDjHead> GetDjBillNoList(string userid, string usercode, string orgcode)
{
var rangstr = GetRangDAStr("index2", userid, usercode, orgcode);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" BillNo");
strSql.Append(" from tMsWlDjHead");
strSql.Append(" where BillStatus<>'9'");
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" and " + rangstr);
}
var dataList = new List<MsWlDjPoundRefMsWlDjHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWlDjPoundRefMsWlDjHead();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
#endregion
dataList.Add(data);
}
reader.Close();
}
return dataList;
}
}
}