DS7/DSWeb/Areas/TruckMng/DAL/MsLsPluAcc/MsLsPluAccDAL.cs

240 lines
8.9 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsLsPluAcc;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.TruckMng.DAL.MsLsPluAcc
{
public partial class MsLsPluAccDAL
{
#region Inquery DataList
static public List<Models.MsLsPluAcc.MsLsPluAcc> 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,JzDate,UserCode,UserName,TzType,");
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99004 and EnumValueID=tMsLsPluAcc.TzType) as TzType_Ref");
strSql.Append(",BillNo,OrgCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsLsPluAcc.OrgCode) as OrgCode_Ref");
strSql.Append(",PluCode,");
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsLsPluAcc.PluCode) as PluCode_Ref");
strSql.Append(",CkCode,");
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsLsPluAcc.CkCode) as CkCode_Ref");
strSql.Append(",JxFsCount,JxJcCount,Remark");
strSql.Append(" from tMsLsPluAcc ");
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.MsLsPluAcc.MsLsPluAcc 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.MsLsPluAcc.MsLsPluAcc();
}
private static List<Models.MsLsPluAcc.MsLsPluAcc> SetData(StringBuilder strSql)
{
var headList = new List<Models.MsLsPluAcc.MsLsPluAcc>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Models.MsLsPluAcc.MsLsPluAcc data = new Models.MsLsPluAcc.MsLsPluAcc();
#region Set DB data to Object
data.SerialNo = Convert.ToDecimal(reader["SerialNo"]);
data.JzDate = Convert.ToString(reader["JzDate"]);
data.UserCode = Convert.ToString(reader["UserCode"]);
data.UserName = Convert.ToString(reader["UserName"]);
data.TzType = Convert.ToString(reader["TzType"]);
data.TzType_Ref = Convert.ToString(reader["TzType_Ref"]);
data.BillNo = Convert.ToString(reader["BillNo"]);
data.OrgCode = Convert.ToString(reader["OrgCode"]);
data.OrgCode_Ref = Convert.ToString(reader["OrgCode_Ref"]);
data.PluCode = Convert.ToString(reader["PluCode"]);
data.PluCode_Ref = Convert.ToString(reader["PluCode_Ref"]);
data.CkCode = Convert.ToString(reader["CkCode"]);
data.CkCode_Ref = Convert.ToString(reader["CkCode_Ref"]);
data.JxFsCount = Convert.ToDecimal(reader["JxFsCount"]);
data.JxJcCount = Convert.ToDecimal(reader["JxJcCount"]);
data.Remark = Convert.ToString(reader["Remark"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 参照部分
internal static List<MsLsPluAccRefMsTruckOrg> GetOrgCodeList()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" OrgCode,OrgName,OrgCode + '-' + CodeAndName as CodeAndName");
strSql.Append(" from vMsTruckOrg");
var dataList = new List<MsLsPluAccRefMsTruckOrg>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsLsPluAccRefMsTruckOrg();
#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<MsLsPluAccRefMsTruckOrg> GetCkCodeList()
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" OrgCode,OrgName,OrgCode + '-' + CodeAndName as CodeAndName");
strSql.Append(" from vMsTruckOrg");
var dataList = new List<MsLsPluAccRefMsTruckOrg>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsLsPluAccRefMsTruckOrg();
#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")
{
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
}
}