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/MsWlBulk/MsWlBulkDAL.cs

292 lines
14 KiB
C#

2 years ago

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWlBulk;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
namespace DSWeb.Areas.TruckMng.DAL
{
public partial class MsWlBulkDAL
{
#region Inquery DataList
static public List<MsWlBulkHead> 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,WcDate,UserCode,UserName,OrgCode");
strSql.Append(",OrgName,RptDate,YwType,convert(bigint ,TimeMark) as TimeMark,GId,SalesCode,");
strSql.Append("(select UserName from vMsTruckUser where UserCode=tMsWlBulkHead.SalesCode) as SalesCode_Ref");
strSql.Append(",SalesName,CustCode,");
strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsWlBulkHead.CustCode) as CustCode_Ref");
strSql.Append(",CustName,CustLinkman,DetiNation,LinkTel,Shipper,Consignee,CustDate");
strSql.Append(",DepartureDate,ArrivalDate,ClsName,PackSpec,CargoLevel,LoadItem,Weight");
strSql.Append(",LoadPlace,UnLoadPlace,OneMil,PayCustCode,");
strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsWlBulkHead.PayCustCode) as PayCustCode_Ref");
strSql.Append(",PayCustName,PayDate,TransPrice,LoadPrice,BillStatus,Vessel,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99029 and EnumValueID=tMsWlBulkHead.BillStatus) as BillStatus_Ref,RealWeight,DumpPrice");
strSql.Append(" from tMsWlBulkHead ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" order by LrDate desc ");
return SetData(strSql);
}
static public MsWlBulkHead GetData(string condition, string userid, string usercode, string orgcode)
{
var list = GetDataList(condition,userid,usercode,orgcode);
if (list.Count > 0)
return list[0];
return new MsWlBulkHead();
}
private static List<MsWlBulkHead> SetData(StringBuilder strSql)
{
var headList = new List<MsWlBulkHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBulkHead data = new MsWlBulkHead();
#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"]);
if (reader["WcDate"] != DBNull.Value)
data.WcDate = Convert.ToDateTime(reader["WcDate"]);
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.RptDate = Convert.ToString(reader["RptDate"]);
data.YwType = Convert.ToString(reader["YwType"]);
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.GId = Convert.ToString(reader["GId"]);
data.SalesCode = Convert.ToString(reader["SalesCode"]);
data.SalesCode_Ref = Convert.ToString(reader["SalesCode_Ref"]);
data.SalesName = Convert.ToString(reader["SalesName"]);
data.CustCode = Convert.ToString(reader["CustCode"]);
data.CustCode_Ref = Convert.ToString(reader["CustCode_Ref"]);
data.CustName = Convert.ToString(reader["CustName"]);
data.CustLinkman = Convert.ToString(reader["CustLinkman"]);
data.DetiNation = Convert.ToString(reader["DetiNation"]);
data.LinkTel = Convert.ToString(reader["LinkTel"]);
data.Shipper = Convert.ToString(reader["Shipper"]);
data.Consignee = Convert.ToString(reader["Consignee"]);
data.CustDate = Convert.ToString(reader["CustDate"]);
data.DepartureDate = Convert.ToString(reader["DepartureDate"]);
data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]);
data.ClsName = Convert.ToString(reader["ClsName"]);
data.PackSpec = Convert.ToString(reader["PackSpec"]);
data.CargoLevel = Convert.ToString(reader["CargoLevel"]);
data.LoadItem = Convert.ToString(reader["LoadItem"]);
data.Weight = Convert.ToDecimal(reader["Weight"]);
data.LoadPlace = Convert.ToString(reader["LoadPlace"]);
data.UnLoadPlace = Convert.ToString(reader["UnLoadPlace"]);
data.OneMil = Convert.ToDecimal(reader["OneMil"]);
data.PayCustCode = Convert.ToString(reader["PayCustCode"]);
data.PayCustCode_Ref = Convert.ToString(reader["PayCustCode_Ref"]);
data.PayCustName = Convert.ToString(reader["PayCustName"]);
data.PayDate = Convert.ToString(reader["PayDate"]);
data.TransPrice = Convert.ToDecimal(reader["TransPrice"]);
data.LoadPrice = Convert.ToDecimal(reader["LoadPrice"]);
data.BillStatus = Convert.ToString(reader["BillStatus"]);
data.BillStatus_Ref = Convert.ToString(reader["BillStatus_Ref"]);
data.RealWeight = Convert.ToDecimal(reader["RealWeight"]);
data.Vessel = Convert.ToString(reader["Vessel"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 明细表
static public List<MsWlBulkPoundView> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("l.BillNo,l.SerialNo,l.BulkBillNo,l.GId");
strSql.Append(",l.TransPrice,l.ClsName,l.PackSpec,l.DepartureDate,l.DepartureTime,l.LoadPlace,l.UnLoadPlace");
strSql.Append(",l.PlanOverLoadMil,l.PlanNoLoadMil,l.PlanLoadCount,l.OverLoadMil,l.NoLoadMil,l.LoadCount,l.Weight");
strSql.Append(",l.TransTotal,l.WorkTime,l.UnLoadCount,l.RatedFuel,l.TonMil,l.HeapWeight,l.OneMil,l.RealTransPrice,l.RealTransTotal");
strSql.Append(",(select TruckNo from tMsWlTruck where TruckNo=p.TruckNo) as TruckNo_Ref");
strSql.Append(",p.DrvName,p.oilticketno");
strSql.Append(" from tMsWlBulkPound l ");
strSql.Append(" left join tMsWlPcHead p on (p.billno=l.billno) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
/*
strSql.Append(" union all ");
strSql.Append(" 'z总计','','',''");
strSql.Append(",'','','','','','',''");
strSql.Append(",'','','',sum(l.OverLoadMil),'',sum(l.LoadCount),sum(l.Weight)");
strSql.Append(",sum(l.TransTotal),'','',sum(l.RatedFuel),sum(l.TonMil),'',sum(l.OneMil),sum(l.RealTransPrice),sum(l.RealTransTotal)");
strSql.Append(",''");
strSql.Append(",''");
strSql.Append(" from tMsWlBulkPound l ");
strSql.Append(" left join tMsWlPcHead p on (p.billno=l.billno) ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}*/
strSql.Append(" order by l.DepartureDate ");
return SetBodyData(strSql);
}
private static List<MsWlBulkPoundView> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsWlBulkPoundView>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlBulkPoundView data = new MsWlBulkPoundView();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.GId = Convert.ToString(reader["GId"]);
data.TransPrice = Convert.ToDecimal(reader["TransPrice"]);
data.ClsName = Convert.ToString(reader["ClsName"]);
data.PackSpec = Convert.ToString(reader["PackSpec"]);
data.DepartureDate = Convert.ToString(reader["DepartureDate"]);
data.DepartureTime = Convert.ToString(reader["DepartureTime"]);
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.Weight = Convert.ToDecimal(reader["Weight"]);
data.TransTotal = Convert.ToDecimal(reader["TransTotal"]);
data.WorkTime = Convert.ToString(reader["WorkTime"]);
data.UnLoadCount = Convert.ToDecimal(reader["UnLoadCount"]);
data.RatedFuel = Convert.ToDecimal(reader["RatedFuel"]);
data.TonMil = Convert.ToDecimal(reader["TonMil"]);
data.HeapWeight = Convert.ToDecimal(reader["HeapWeight"]);
data.OneMil = Convert.ToDecimal(reader["OneMil"]);
data.TruckNo = Convert.ToString(reader["TruckNo_Ref"]);
data.DrvName = Convert.ToString(reader["DrvName"]);
if (reader["RealTransPrice"] != DBNull.Value)
data.RealTransPrice = Convert.ToDecimal(reader["RealTransPrice"]);
if (reader["RealTransTotal"] != DBNull.Value)
data.RealTransTotal = Convert.ToDecimal(reader["RealTransTotal"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 参照部分
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]='modTruckBulk' 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 SalesCode='" + 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 SalesCode 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;
}
#endregion
}
}