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/TruckMng/DAL/MsKfWx/MsKfWxDAL.cs

376 lines
15 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsKfWx;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.TruckMng.DAL.MsKfWx
{
public partial class MsKfWxDAL
{
#region 主表
static public List<MsKfWxHead> GetDataList(string strCondition, string userid, string usercode, string orgcode, string sort = null)
{
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");
strSql.Append(" ,(select CodeAndName from vMsTruckUser where UserCode=tMsKfWxHead.UserCode) as UserCode_Ref");
strSql.Append(" ,UserName,TimeMark,TruckNo");
strSql.Append(" ,(select TruckSpec from tMsWlTruck where TruckNo=tMsKfWxHead.TruckNo) as TruckNo_Ref");
strSql.Append(" ,PgDate,GzBgnDate,GzEndDate,OrgCode");
strSql.Append(" ,(select CodeAndName from vMsTruckOrg where OrgCode=tMsKfWxHead.OrgCode) as OrgCode_Ref");
strSql.Append(" ,OrgName,PlanEndDate,RealMil,Remark");
strSql.Append(" ,REPAIRDAYS,REPAIRAMOUNT,MATERIALAMOUNT,WORKAMOUNT,TYREAMOUNT,ACCDATE");
strSql.Append(" from tMsKfWxHead ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetData(strSql);
}
private static List<MsKfWxHead> SetData(StringBuilder strSql)
{
var headList = new List<MsKfWxHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsKfWxHead data = new MsKfWxHead();
#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.UserCode_Ref = Convert.ToString(reader["UserCode_Ref"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.TruckNo_Ref = Convert.ToString(reader["TruckNo_Ref"]);
data.PgDate = Convert.ToString(reader["PgDate"]);
data.GzBgnDate = Convert.ToString(reader["GzBgnDate"]);
data.GzEndDate = Convert.ToString(reader["GzEndDate"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgCode_Ref = Convert.ToString(reader["OrgCode_Ref"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
data.PlanEndDate = Convert.ToString(reader["PlanEndDate"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.REPAIRDAYS = Convert.ToString(reader["REPAIRDAYS"]);
data.REPAIRAMOUNT = Convert.ToString(reader["REPAIRAMOUNT"]);
data.MATERIALAMOUNT = Convert.ToString(reader["MATERIALAMOUNT"]);
data.WORKAMOUNT = Convert.ToString(reader["WORKAMOUNT"]);
data.TYREAMOUNT = Convert.ToString(reader["TYREAMOUNT"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public MsKfWxHead GetHeadDataByBillNo(string billno, string userid, string usercode, string orgcode)
{
MsKfWxHead data = null;
var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsKfWxHead();
}
return data;
}
#endregion
#region 明细表
static public List<MsKfWxBody> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,WxLxCode,");
strSql.Append("(select WxLxName from tMsKfBzWx where WxLxCode=tMsKfWxBody.WxLxCode) as WxLxCode_Ref");
strSql.Append(",WxItem,QuotaHours,RealHours,SkillUser,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsKfWxBody.SkillUser) as SkillUser_Ref");
strSql.Append(",KfWxUser,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsKfWxBody.KfWxUser) as KfWxUser_Ref");
strSql.Append(",Remark,MATERIALAMOUNT,WORKAMOUNT,TYREAMOUNT");
strSql.Append(" from tMsKfWxBody ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetBodyData(strSql);
}
private static List<MsKfWxBody> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsKfWxBody>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsKfWxBody data = new MsKfWxBody();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.WxLxCode = Convert.ToString(reader["WxLxCode"]);
data.WxLxCode_Ref = Convert.ToString(reader["WxLxCode_Ref"]);
data.WxItem = Convert.ToString(reader["WxItem"]);
data.QuotaHours = Convert.ToDecimal(reader["QuotaHours"]);
data.RealHours = Convert.ToDecimal(reader["RealHours"]);
data.SkillUser = Convert.ToString(reader["SkillUser"]);
data.SkillUser_Ref = Convert.ToString(reader["SkillUser_Ref"]);
data.KfWxUser = Convert.ToString(reader["KfWxUser"]);
data.KfWxUser_Ref = Convert.ToString(reader["KfWxUser_Ref"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.WORKAMOUNT = Convert.ToString(reader["WORKAMOUNT"]);
data.MATERIALAMOUNT = Convert.ToString(reader["MATERIALAMOUNT"]);
data.TYREAMOUNT = Convert.ToString(reader["TYREAMOUNT"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 明细表配件
static public List<MsKfWxPlu> GetWxPluList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,PluCode,");
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsKfWxPlu.PluCode) as PluCode_Ref");
strSql.Append(",PluName,Spec,Unit,Price,LyCount,Remark,PcNo");
strSql.Append(",TyreType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsKfWxPlu.TyreType) as TyreType_Ref");
strSql.Append(",TyrePos,PlanMil,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99015 and EnumValueID=tMsKfWxPlu.TyrePos) as TyrePos_Ref");
strSql.Append(" from tMsKfWxPlu ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetWxPluData(strSql);
}
private static List<MsKfWxPlu> SetWxPluData(StringBuilder strSql)
{
var wxPluList = new List<MsKfWxPlu>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsKfWxPlu data = new MsKfWxPlu();
#region Set DB data to Object
data.BillNo = Convert.ToString(reader["BillNo"]);
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.PluCode = Convert.ToString(reader["PluCode"]);
data.PluCode_Ref = Convert.ToString(reader["PluCode_Ref"]);
data.PluName = Convert.ToString(reader["PluName"]);
data.Spec = Convert.ToString(reader["Spec"]);
data.Unit = Convert.ToString(reader["Unit"]);
data.Price = Convert.ToDecimal(reader["Price"]);
data.LyCount = Convert.ToDecimal(reader["LyCount"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.PcNo = Convert.ToString(reader["PcNo"]);
data.PlanMil = Convert.ToDecimal(reader["PlanMil"]);
data.TyreType = Convert.ToString(reader["TyreType"]);
data.TyreType_Ref = Convert.ToString(reader["TyreType_Ref"]);
data.TyrePos = Convert.ToString(reader["TyrePos"]);
data.TyrePos_Ref = Convert.ToString(reader["TyrePos_Ref"]);
#endregion
wxPluList.Add(data);
}
reader.Close();
}
return wxPluList;
}
#endregion
#region 参照部分
internal static List<MsKfWxHeadRefMsWlTruck> GetTruckNoList(string userid, string usercode, string orgcode)
{
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" TruckNo,TruckSpec");
strSql.Append(" from tMsWlTruck");
if (!string.IsNullOrEmpty(rangstr))
{
strSql.Append(" where " + rangstr);
}
var dataList = new List<MsKfWxHeadRefMsWlTruck>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsKfWxHeadRefMsWlTruck();
#region Set DB data to Object
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.TruckSpec = data.TruckNo + "-" + Convert.ToString(reader["TruckSpec"]);
#endregion
dataList.Add(data);
}
reader.Close();
}
return dataList;
}
internal static List<MsKfWxBodyRefMsKfBzWx> GetWxLxCodeList()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" WxLxCode,WxLxName");
strSql.Append(" from tMsKfBzWx");
var dataList = new List<MsKfWxBodyRefMsKfBzWx>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsKfWxBodyRefMsKfBzWx();
#region Set DB data to Object
data.WxLxCode = Convert.ToString(reader["WxLxCode"]);
data.WxLxName = Convert.ToString(reader["WxLxName"]);
data.CodeAndName = Convert.ToString(reader["WxLxCode"]) + "-" + Convert.ToString(reader["WxLxName"]);
#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]='modTruckWx' 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 + "'";
}
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 + "'))";
}
else
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
#endregion
}
}