|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DSWeb.Areas.TruckMng.Models.MsKfJh;
|
|
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
|
|
using DSWeb.EntityDA;
|
|
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.TruckMng.DAL.MsKfJh
|
|
|
|
|
{
|
|
|
|
|
public partial class MsKfJhDAL
|
|
|
|
|
{
|
|
|
|
|
#region 主表
|
|
|
|
|
|
|
|
|
|
static public List<MsKfJhHead> 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=tMsKfJhHead.UserCode) as UserCode_Ref");
|
|
|
|
|
strSql.Append(",UserName,TimeMark,OrgCode,");
|
|
|
|
|
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsKfJhHead.OrgCode) as OrgCode_Ref");
|
|
|
|
|
strSql.Append(",OrgName,BillType,");
|
|
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99010 and EnumValueID=tMsKfJhHead.BillType) as BillType_Ref");
|
|
|
|
|
strSql.Append(",CkCode,");
|
|
|
|
|
strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsKfJhHead.CkCode) as CkCode_Ref");
|
|
|
|
|
strSql.Append(",CkName,JhDate,JhrCode,");
|
|
|
|
|
strSql.Append("(select CodeAndName from vMsTruckUser where UserCode=tMsKfJhHead.JhrCode) as JhrCode_Ref");
|
|
|
|
|
strSql.Append(",JhrName,JhCount,JhTotal,Remark,PluType,");
|
|
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99003 and EnumValueID=tMsKfJhHead.PluType) as PluType_Ref");
|
|
|
|
|
strSql.Append(",Supplier,");
|
|
|
|
|
strSql.Append("(select CustName from vMsTruckClient where CustCode=tMsKfJhHead.Supplier) as Supplier_Ref");
|
|
|
|
|
strSql.Append(" from tMsKfJhHead ");
|
|
|
|
|
|
|
|
|
|
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<MsKfJhHead> SetData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<MsKfJhHead>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
MsKfJhHead data = new MsKfJhHead();
|
|
|
|
|
#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.BillType = Convert.ToString(reader["BillType"]);
|
|
|
|
|
data.BillType_Ref = Convert.ToString(reader["BillType_Ref"]);
|
|
|
|
|
data.CkCode = Convert.ToString(reader["CkCode"]);
|
|
|
|
|
data.CkCode_Ref = Convert.ToString(reader["CkCode_Ref"]);
|
|
|
|
|
data.CkName = Convert.ToString(reader["CkName"]);
|
|
|
|
|
data.JhDate = Convert.ToString(reader["JhDate"]);
|
|
|
|
|
data.JhrCode = Convert.ToString(reader["JhrCode"]);
|
|
|
|
|
data.JhrCode_Ref = Convert.ToString(reader["JhrCode_Ref"]);
|
|
|
|
|
data.JhrName = Convert.ToString(reader["JhrName"]);
|
|
|
|
|
data.JhCount = Convert.ToDecimal(reader["JhCount"]);
|
|
|
|
|
data.JhTotal = Convert.ToDecimal(reader["JhTotal"]);
|
|
|
|
|
data.Remark = Convert.ToString(reader["Remark"]);
|
|
|
|
|
data.PluType = Convert.ToString(reader["PluType"]);
|
|
|
|
|
data.PluType_Ref = Convert.ToString(reader["PluType_Ref"]);
|
|
|
|
|
data.Supplier = Convert.ToString(reader["Supplier"]);
|
|
|
|
|
data.Supplier_Ref = Convert.ToString(reader["Supplier_Ref"]);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public MsKfJhHead GetHeadDataByBillNo(string billno, string userid, string usercode, string orgcode)
|
|
|
|
|
{
|
|
|
|
|
MsKfJhHead data = null;
|
|
|
|
|
var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode);
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
data = list[0];
|
|
|
|
|
|
|
|
|
|
if (data == null)
|
|
|
|
|
{
|
|
|
|
|
data = new MsKfJhHead();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 明细表
|
|
|
|
|
|
|
|
|
|
static public List<MsKfJhBody> GetBodyList(string strCondition)
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT ");
|
|
|
|
|
strSql.Append("BillNo,SerialNo,PluCode,");
|
|
|
|
|
strSql.Append("(select PluName from tMsTruckPlu where PluCode=tMsKfJhBody.PluCode) as PluCode_Ref");
|
|
|
|
|
strSql.Append(",PluName,Spec,Unit,Price,JhCount,JhTotal,Remark");
|
|
|
|
|
strSql.Append(",PcNo,TyreType,RealMil,");
|
|
|
|
|
strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsKfJhBody.TyreType) as TyreType_Ref");
|
|
|
|
|
strSql.Append(" from tMsKfJhBody ");
|
|
|
|
|
|
|
|
|
|
if (strCondition.Trim() != String.Empty)
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where " + strCondition);
|
|
|
|
|
}
|
|
|
|
|
return SetBodyData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<MsKfJhBody> SetBodyData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var bodyList = new List<MsKfJhBody>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
MsKfJhBody data = new MsKfJhBody();
|
|
|
|
|
#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.JhCount = Convert.ToDecimal(reader["JhCount"]);
|
|
|
|
|
data.JhTotal = Convert.ToDecimal(reader["JhTotal"]);
|
|
|
|
|
data.Remark = Convert.ToString(reader["Remark"]);
|
|
|
|
|
data.PcNo = Convert.ToString(reader["PcNo"]);
|
|
|
|
|
data.TyreType = Convert.ToString(reader["TyreType"]);
|
|
|
|
|
data.TyreType_Ref = Convert.ToString(reader["TyreType_Ref"]);
|
|
|
|
|
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bodyList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
internal static List<MsKfJhHeadRefMsTruckOrg> GetTruckNoList()
|
|
|
|
|
{
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("select description from info_client where isother=1");
|
|
|
|
|
|
|
|
|
|
var dataList = new List<MsKfJhHeadRefMsTruckOrg>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
var data = new MsKfJhHeadRefMsTruckOrg();
|
|
|
|
|
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
|
|
|
|
|
data.CodeAndName = Convert.ToString(reader["description"]);
|
|
|
|
|
|
|
|
|
|
#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 = " UserCode='" + usercode + "'";
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|