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/MsLsKc/MsLsKcDAL.cs

210 lines
7.3 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsLsKc;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.TruckMng.DAL.MsLsKc
{
public partial class MsLsKcDAL
{
#region Inquery DataList
static public List<Models.MsLsKc.MsLsKc> 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("SerialNo,OrgCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsLsKc.OrgCode) as OrgCode_Ref");
strSql.Append(",CkCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsLsKc.CkCode) as CkCode_Ref");
strSql.Append(",PluCode,JxCount,JxTotal,");
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsLsKc.PluCode) as PluCode_Ref");
strSql.Append(" from tMsLsKc ");
if (strCondition.Trim() != String.Empty)
{
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.MsLsKc.MsLsKc 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.MsLsKc.MsLsKc();
}
private static List<Models.MsLsKc.MsLsKc> SetData(StringBuilder strSql)
{
var headList = new List<Models.MsLsKc.MsLsKc>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Models.MsLsKc.MsLsKc data = new Models.MsLsKc.MsLsKc();
#region Set DB data to Object
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgCode_Ref = Convert.ToString(reader["OrgCode_Ref"]);
data.CkCode = Convert.ToString(reader["CkCode"]);
data.CkCode_Ref = Convert.ToString(reader["CkCode_Ref"]);
data.PluCode = Convert.ToString(reader["PluCode"]);
data.PluCode_Ref = Convert.ToString(reader["PluCode_Ref"]);
data.JxCount = Convert.ToDecimal(reader["JxCount"]);
data.JxTotal = Convert.ToDecimal(reader["JxTotal"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 参照部分
internal static List<MsLsKcRefMsTruckOrg> GetOrgCodeList()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" OrgCode,OrgName,OrgCode + '-' + CodeAndName as CodeAndName");
strSql.Append(" from vMsTruckOrg");
var dataList = new List<MsLsKcRefMsTruckOrg>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsLsKcRefMsTruckOrg();
#region Set DB data to Object
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
data.CodeAndName = Convert.ToString(reader["CodeAndName"]);
#endregion
dataList.Add(data);
}
reader.Close();
}
return dataList;
}
internal static List<MsLsKcRefMsTruckOrg> GetCkCodeList()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" OrgCode,OrgName,OrgCode + '-' + CodeAndName as CodeAndName");
strSql.Append(" from vMsTruckOrg");
var dataList = new List<MsLsKcRefMsTruckOrg>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsLsKcRefMsTruckOrg();
#region Set DB data to Object
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgName = Convert.ToString(reader["OrgName"]);
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")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
else if (visiblerange == "2")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
else if (visiblerange == "1")
{
str = " UPPER(OrgCode)='" + orgcode + "'";
}
return str;
}
#endregion
}
}