using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.Areas.TruckMng.Models.MsWlTyreWx; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; namespace DSWeb.Areas.TruckMng.DAL.MsWlTyreWx { public partial class MsWlTyreWxDAL { #region Inquery DataList static public List GetDataList(string strCondition, string userid, string usercode, string orgcode) { 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,OrgCode,"); strSql.Append("(select CodeAndName from vMsTruckOrg where OrgCode=tMsWlTyreWx.OrgCode) as OrgCode_Ref"); strSql.Append(",TruckNo,"); strSql.Append("(select TruckSpec from tMsWlTruck where TruckNo=tMsWlTyreWx.TruckNo) as TruckNo_Ref"); strSql.Append(",PcNo,PluCode,"); strSql.Append("(select BarCode from tMsTruckPlu where PluCode=tMsWlTyreWx.PluCode) as PluCode_Ref"); strSql.Append(",PluName,Spec,TyreType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99013 and EnumValueID=tMsWlTyreWx.TyreType) as TyreType_Ref"); strSql.Append(",TyrePos,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99015 and EnumValueID=tMsWlTyreWx.TyrePos) as TyrePos_Ref"); strSql.Append(",WxTotal,WxDate,EtpName,Remark"); strSql.Append(" from tMsWlTyreWx "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } return SetData(strSql); } static public Models.MsWlTyreWx.MsWlTyreWx 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.MsWlTyreWx.MsWlTyreWx(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { Models.MsWlTyreWx.MsWlTyreWx data = new Models.MsWlTyreWx.MsWlTyreWx(); #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.TruckNo = Convert.ToString(reader["TruckNo"]); data.TruckNo_Ref = Convert.ToString(reader["TruckNo_Ref"]); data.PcNo = Convert.ToString(reader["PcNo"]); 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.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.WxTotal = Convert.ToDecimal(reader["WxTotal"]); data.WxDate = Convert.ToString(reader["WxDate"]); data.EtpName = Convert.ToString(reader["EtpName"]); data.Remark = Convert.ToString(reader["Remark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 参照部分 internal static List GetOrgCodeList() { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" OrgCode,OrgName,OrgCode + '-' + CodeAndName as CodeAndName"); strSql.Append(" from vMsTruckOrg"); var dataList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var data = new MsWlTyreWxRefMsTruckOrg(); #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 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(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var data = new MsWlTyreWxRefMsWlTruck(); #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") { 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 } }