using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.Areas.TruckMng.Models.KfCg; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.Models; namespace DSWeb.Areas.TruckMng.DAL.KfCg { public partial class KfCgDAL { #region 主表部分 static public List 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,LrTime,RzDate,RzTime,JzDate,UserCode"); strSql.Append(",UserName,TimeMark,OrgCode,OrgName,CkCode,CkName,PluType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99003 and EnumValueID=tKfCgHead.PluType) as PluType_Ref"); strSql.Append(",CgDate,CgyCode,"); strSql.Append("(select UserName from vMsTruckUser where UserCode=tKfCgHead.CgyCode) as CgyCode_Ref"); strSql.Append(",CgyName,CgCount,CgTotal,SdCount,ZxFlag,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99012 and EnumValueID=tKfCgHead.ZxFlag) as ZxFlag_Ref"); strSql.Append(",Remark"); strSql.Append(" from tKfCgHead "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } return SetData(strSql); } 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()) { KfCgHead data = new KfCgHead(); #region Set DB data to Object data.BillNo = Convert.ToString(reader["BillNo"]); data.LrDate = Convert.ToString(reader["LrDate"]); data.LrTime = Convert.ToString(reader["LrTime"]); data.RzDate = Convert.ToString(reader["RzDate"]); data.RzTime = Convert.ToString(reader["RzTime"]); data.JzDate = Convert.ToString(reader["JzDate"]); data.UserCode = Convert.ToString(reader["UserCode"]); data.UserName = Convert.ToString(reader["UserName"]); data.TimeMark = Convert.ToDecimal(reader["TimeMark"]); data.OrgCode = Convert.ToString(reader["OrgCode"]); data.OrgName = Convert.ToString(reader["OrgName"]); data.CkCode = Convert.ToString(reader["CkCode"]); data.CkName = Convert.ToString(reader["CkName"]); data.PluType = Convert.ToString(reader["PluType"]); data.PluType_Ref = Convert.ToString(reader["PluType_Ref"]); data.CgDate = Convert.ToString(reader["CgDate"]); data.CgyCode = Convert.ToString(reader["CgyCode"]); data.CgyCode_Ref = Convert.ToString(reader["CgyCode_Ref"]); data.CgyName = Convert.ToString(reader["CgyName"]); data.CgCount = Convert.ToDecimal(reader["CgCount"]); data.CgTotal = Convert.ToDecimal(reader["CgTotal"]); data.SdCount = Convert.ToDecimal(reader["SdCount"]); data.ZxFlag = Convert.ToString(reader["ZxFlag"]); data.ZxFlag_Ref = Convert.ToString(reader["ZxFlag_Ref"]); data.Remark = Convert.ToString(reader["Remark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public KfCgHead GetHeadDataByBillNo(string billno, string userid, string usercode, string orgcode) { KfCgHead data = null; var list = GetDataList(" BillNo='" + billno + "'",userid,usercode,orgcode); if (list.Count > 0) data = list[0]; if (data == null) { data = new KfCgHead(); } return data; } #endregion #region 明细表部分 static public List GetBodyList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("BillNo,SerialNo,PluCode,"); strSql.Append("(select PluName from tMsTruckPlu where PluCode=tKfCgBody.PluCode) as PluCode_Ref"); strSql.Append(",PluName,Spec,Unit,Price,CgCount,CgTotal,SdCount"); strSql.Append(",Remark"); strSql.Append(" from tKfCgBody "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } return SetBodyData(strSql); } private static List SetBodyData(StringBuilder strSql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { KfCgBody data = new KfCgBody(); #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.CgCount = Convert.ToDecimal(reader["CgCount"]); data.CgTotal = Convert.ToDecimal(reader["CgTotal"]); data.SdCount = Convert.ToDecimal(reader["SdCount"]); data.Remark = Convert.ToString(reader["Remark"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 参照部分 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 } }