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/MsWlTyreRep/MsWlTyreRepDAL.cs

291 lines
12 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWlTyreRep;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
namespace DSWeb.Areas.TruckMng.DAL.MsWlTyreRep
{
public partial class MsWlTyreRepDAL
{
#region 主表
static public List<MsWlTyreRepHead> 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,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsWlTyreRepHead.UserCode) as UserCode_Ref");
strSql.Append(",UserName,TimeMark,OrgCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsWlTyreRepHead.OrgCode) as OrgCode_Ref");
strSql.Append(",OrgName,TruckNo");
strSql.Append(",CkCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsWlTyreRepHead.CkCode) as CkCode_Ref");
strSql.Append(",CkName,(select TruckSpec from tMsWlTruck where TruckNo=tMsWlTyreRepHead.TruckNo) as TruckNo_Ref");
strSql.Append(",RepDate,RepCode,");
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsWlTyreRepHead.RepCode) as RepCode_Ref");
strSql.Append(",RepName,Remark");
strSql.Append(" from tMsWlTyreRepHead ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetData(strSql);
}
private static List<MsWlTyreRepHead> SetData(StringBuilder strSql)
{
var headList = new List<MsWlTyreRepHead>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlTyreRepHead data = new MsWlTyreRepHead();
#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.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgCode_Ref = Convert.ToString(reader["OrgCode_Ref"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
data.CkCode = Convert.ToString(reader["CkCode"]);
data.CkCode_Ref = Convert.ToString(reader["CkCode_Ref"]);
data.CkName = Convert.ToString(reader["CkName"]);
data.TruckNo = Convert.ToString(reader["TruckNo"]);
data.TruckNo_Ref = Convert.ToString(reader["TruckNo_Ref"]);
data.RepDate = Convert.ToString(reader["RepDate"]);
data.RepCode = Convert.ToString(reader["RepCode"]);
data.RepCode_Ref = Convert.ToString(reader["RepCode_Ref"]);
data.RepName = Convert.ToString(reader["RepName"]);
data.Remark = Convert.ToString(reader["Remark"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public MsWlTyreRepHead GetHeadDataByBillNo(string billno, string userid, string usercode, string orgcode)
{
MsWlTyreRepHead data = null;
var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new MsWlTyreRepHead();
}
return data;
}
#endregion
#region 明细表
static public List<MsWlTyreRepBody> GetBodyList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("BillNo,SerialNo,PluCode,");
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsWlTyreRepBody.PluCode) as PluCode_Ref");
strSql.Append(",PluName,Spec,PcNo,TyreType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsWlTyreRepBody.TyreType) as TyreType_Ref");
strSql.Append(",TyrePos,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99015 and EnumValueID=tMsWlTyreRepBody.TyrePos) as TyrePos_Ref");
strSql.Append(",NewPluCode,");
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsWlTyreRepBody.NewPluCode) as NewPluCode_Ref");
strSql.Append(",NewPluName,NewSpec,NewPcNo,TyreStatus,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99022 and EnumValueID=tMsWlTyreRepBody.TyreStatus) as TyreStatus_Ref");
strSql.Append(",Remark,RealMil,PlanMil,NewTyreType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsWlTyreRepBody.NewTyreType) as NewTyreType_Ref");
strSql.Append(" from tMsWlTyreRepBody ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
return SetBodyData(strSql);
}
private static List<MsWlTyreRepBody> SetBodyData(StringBuilder strSql)
{
var bodyList = new List<MsWlTyreRepBody>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsWlTyreRepBody data = new MsWlTyreRepBody();
#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.PcNo = Convert.ToString(reader["PcNo"]);
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"]);
data.NewPluCode = Convert.ToString(reader["NewPluCode"]);
data.NewPluCode_Ref = Convert.ToString(reader["NewPluCode_Ref"]);
data.NewPluName = Convert.ToString(reader["NewPluName"]);
data.NewSpec = Convert.ToString(reader["NewSpec"]);
data.NewPcNo = Convert.ToString(reader["NewPcNo"]);
data.TyreStatus = Convert.ToString(reader["TyreStatus"]);
data.TyreStatus_Ref = Convert.ToString(reader["TyreStatus_Ref"]);
data.Remark = Convert.ToString(reader["Remark"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.NewTyreType = Convert.ToString(reader["NewTyreType"]);
data.NewTyreType_Ref = Convert.ToString(reader["NewTyreType_Ref"]);
data.PlanMil = Convert.ToDecimal(reader["PlanMil"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
#region 参照部分
internal static List<MsWlTyreRepHeadRefMsWlTruck> 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<MsWlTyreRepHeadRefMsWlTruck>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWlTyreRepHeadRefMsWlTruck();
#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;
}
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]='modTruckPj' 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
}
}