215 lines
7.8 KiB
C#
215 lines
7.8 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.Areas.TruckMng.Models.MsWlTyre;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
namespace DSWeb.Areas.TruckMng.DAL.MsWlTyre
|
|
{
|
|
public partial class MsWlTyreDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<Models.MsWlTyre.MsWlTyre> GetDataList(string strCondition, string userid, string usercode, string orgcode, string sort = null)
|
|
{
|
|
var rangstr = GetRangDAStr("", 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("SerialNo,TruckNo,");
|
|
strSql.Append("(select TruckSpec from tMsWlTruck where TruckNo=tMsWlTyre.TruckNo) as TruckNo_Ref");
|
|
strSql.Append(",PluCode,");
|
|
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsWlTyre.PluCode) as PluCode_Ref");
|
|
strSql.Append(",Spec,TyreType,");
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsWlTyre.TyreType) as TyreType_Ref");
|
|
strSql.Append(",TyrePos,");
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99015 and EnumValueID=tMsWlTyre.TyrePos) as TyrePos_Ref");
|
|
strSql.Append(",PcNo,PlanMil,InitMil,InitDate,RealMil,OrgCode,Remark");
|
|
strSql.Append(" from tMsWlTyre ");
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
{
|
|
strSql.Append(" order by " + sortstring);
|
|
}
|
|
else
|
|
{
|
|
strSql.Append(" order by SerialNo");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public Models.MsWlTyre.MsWlTyre 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 Models.MsWlTyre.MsWlTyre();
|
|
}
|
|
|
|
|
|
private static List<Models.MsWlTyre.MsWlTyre> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<Models.MsWlTyre.MsWlTyre>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
Models.MsWlTyre.MsWlTyre data = new Models.MsWlTyre.MsWlTyre();
|
|
#region Set DB data to Object
|
|
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
|
|
data.TruckNo = Convert.ToString(reader["TruckNo"]);
|
|
data.TruckNo_Ref = Convert.ToString(reader["TruckNo_Ref"]);
|
|
data.PluCode = Convert.ToString(reader["PluCode"]);
|
|
data.PluCode_Ref = Convert.ToString(reader["PluCode_Ref"]);
|
|
data.Spec = Convert.ToString(reader["Spec"]);
|
|
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.PcNo = Convert.ToString(reader["PcNo"]);
|
|
data.PlanMil = Convert.ToDecimal(reader["PlanMil"]);
|
|
data.InitMil = Convert.ToDecimal(reader["InitMil"]);
|
|
data.InitDate = Convert.ToString(reader["InitDate"]);
|
|
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
|
|
data.OrgCode = Convert.ToString(reader["OrgCode"]);
|
|
data.Remark = Convert.ToString(reader["Remark"]);
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
internal static List<MsWlTyreRefMsWlTruck> GetTruckNoList(string userid, string usercode, string orgcode)
|
|
{
|
|
var rangstr = GetRangDAStr("", userid, usercode, orgcode);
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(" TruckNo,TruckSpec,TruckNo + '-' + TruckSpec as CodeAndName");
|
|
strSql.Append(" from tMsWlTruck");
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
{
|
|
strSql.Append(" where " + rangstr);
|
|
}
|
|
|
|
|
|
|
|
var dataList = new List<MsWlTyreRefMsWlTruck>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var data = new MsWlTyreRefMsWlTruck();
|
|
|
|
#region Set DB data to Object
|
|
|
|
data.TruckNo = Convert.ToString(reader["TruckNo"]);
|
|
data.TruckSpec = Convert.ToString(reader["TruckSpec"]);
|
|
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
|
|
|
|
#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")
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
else
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
|
|
}
|
|
else if (visiblerange == "1")
|
|
{
|
|
str = " UPPER(OrgCode)='" + orgcode + "'";
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|