using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.Areas.TruckMng.Models; using DSWeb.Areas.TruckMng.Models.MsWlTruck; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using System.Data.SqlClient; namespace DSWeb.Areas.TruckMng.DAL.MsWlTruck { public partial class MsWlTruckDAL { #region Inquery DataList static public List GetDataList(string strCondition, string userid, string usercode, string orgcode, string sort = null) { 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("ROW_NUMBER() OVER (ORDER BY OrgCode) AS RowNumber,OrgCode,TruckNo,TruckSpec,TruckType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99019 and EnumValueID=tMsWlTruck.TruckType) as TruckType_Ref"); strSql.Append(",TrunkColor,TrunkBrand,LoadCount,CjNo,FdjNo,dbo.trimdate(GzDate) GzDate,dbo.trimdate(ZrDate) ZrDate,dbo.trimdate(BfDate) BfDate"); strSql.Append(",DrvCode,"); strSql.Append("(select DrvName from tMsWlDriver where DrvCode=tMsWlTruck.DrvCode) as DrvCode_Ref"); strSql.Append(",DrvName,NowStatus,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99018 and EnumValueID=tMsWlTruck.NowStatus) as NowStatus_Ref"); strSql.Append(",TruncClass,NsDqDate,VerifiType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99016 and EnumValueID=tMsWlTruck.VerifiType) as VerifiType_Ref"); strSql.Append(",InsureType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99021 and EnumValueID=tMsWlTruck.InsureType) as InsureType_Ref"); strSql.Append(",InsureDate,AcciDate,AcciExplain,DealResult,RepairDate,IsRotine,Remark"); strSql.Append(",Emissions,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99031 and EnumValueID=tMsWlTruck.Emissions) as Emissions_Ref"); strSql.Append(",BizProperty,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99032 and EnumValueID=tMsWlTruck.BizProperty) as BizProperty_Ref"); strSql.Append(",NativeAddr,MngOrg"); strSql.Append(",Property,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99033 and EnumValueID=tMsWlTruck.Property) as Property_Ref"); strSql.Append(",FuelType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99034 and EnumValueID=tMsWlTruck.FuelType) as FuelType_Ref"); strSql.Append(",Level2Date,UnloadFuel,CraneFuel,BasisFuel,TonMilFuel,YouLiaoType "); strSql.Append(",OWNER,(select shortname from info_client where GID=tMsWlTruck.OWNER) OWNER_REF,WORKNO,LINKTRUCKNO"); strSql.Append(" from tMsWlTruck "); 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); } static public Models.MsWlTruck.MsWlTruck 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.MsWlTruck.MsWlTruck(); } 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.MsWlTruck.MsWlTruck data = new Models.MsWlTruck.MsWlTruck(); #region Set DB data to Object data.RowNumber = Convert.ToString(reader["RowNumber"]); data.OrgCode = Convert.ToString(reader["OrgCode"]); data.TruckNo = Convert.ToString(reader["TruckNo"]); data.TruckSpec = Convert.ToString(reader["TruckSpec"]); data.TruckType = Convert.ToString(reader["TruckType"]); data.TruckType_Ref = Convert.ToString(reader["TruckType_Ref"]); data.TrunkColor = Convert.ToString(reader["TrunkColor"]); data.TrunkBrand = Convert.ToString(reader["TrunkBrand"]); data.LoadCount = Convert.ToDecimal(reader["LoadCount"]); data.CjNo = Convert.ToString(reader["CjNo"]); data.FdjNo = Convert.ToString(reader["FdjNo"]); data.GzDate = Convert.ToString(reader["GzDate"]); data.ZrDate = Convert.ToString(reader["ZrDate"]); data.BfDate = Convert.ToString(reader["BfDate"]); data.DrvCode = Convert.ToString(reader["DrvCode"]); data.DrvCode_Ref = Convert.ToString(reader["DrvCode_Ref"]); data.DrvName = Convert.ToString(reader["DrvName"]); data.NowStatus = Convert.ToString(reader["NowStatus"]); data.NowStatus_Ref = Convert.ToString(reader["NowStatus_Ref"]); data.TruncClass = Convert.ToString(reader["TruncClass"]); data.NsDqDate = Convert.ToString(reader["NsDqDate"]); data.VerifiType = Convert.ToString(reader["VerifiType"]); data.VerifiType_Ref = Convert.ToString(reader["VerifiType_Ref"]); data.InsureType = Convert.ToString(reader["InsureType"]); data.InsureType_Ref = Convert.ToString(reader["InsureType_Ref"]); data.InsureDate = Convert.ToString(reader["InsureDate"]); data.AcciDate = Convert.ToString(reader["AcciDate"]); data.AcciExplain = Convert.ToString(reader["AcciExplain"]); data.DealResult = Convert.ToString(reader["DealResult"]); data.RepairDate = Convert.ToString(reader["RepairDate"]); data.IsRotine = Convert.ToString(reader["IsRotine"]); data.Remark = Convert.ToString(reader["Remark"]); data.Emissions=Convert.ToString(reader["Emissions"]); data.Emissions_Ref = Convert.ToString(reader["Emissions_Ref"]); data.BizProperty = Convert.ToString(reader["BizProperty"]); data.BizProperty_Ref = Convert.ToString(reader["BizProperty_Ref"]); data.NativeAddr = Convert.ToString(reader["NativeAddr"]); data.MngOrg = Convert.ToString(reader["MngOrg"]); data.Property = Convert.ToString(reader["Property"]); data.Property_Ref = Convert.ToString(reader["Property_Ref"]); data.FuelType = Convert.ToString(reader["FuelType"]); data.FuelType_Ref = Convert.ToString(reader["FuelType_Ref"]); data.Level2Date = Convert.ToString(reader["Level2Date"]); data.UnloadFuel = Convert.ToDecimal(reader["UnloadFuel"]); data.CraneFuel = Convert.ToDecimal(reader["CraneFuel"]); data.BasisFuel = Convert.ToDecimal(reader["BasisFuel"]); data.TonMilFuel = Convert.ToDecimal(reader["TonMilFuel"]); data.OWNER = Convert.ToString(reader["OWNER"]); data.OWNER_REF = Convert.ToString(reader["OWNER_REF"]); data.WORKNO = Convert.ToString(reader["WORKNO"]); data.LINKTRUCKNO = Convert.ToString(reader["LINKTRUCKNO"]); data.YouLiaoType = Convert.ToString(reader["YouLiaoType"] == DBNull.Value ? "" : reader["YouLiaoType"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion //GetTruckFeeList(condition, sort); static public List GetTruckFeeList(string strCondition, string userid, string usercode, string orgcode, string sort = null) {/* 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 * from tmswlTruckFee "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } return SetTruckFee(strSql); } static public MsWlTruckFee GetTruckFee(string strCondition, string userid, string usercode, string orgcode, string sort = null) { var list = GetTruckFeeList(strCondition, userid, usercode, orgcode); if (list.Count > 0) return list[0]; return new MsWlTruckFee(); } private static List SetTruckFee(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { MsWlTruckFee data = new MsWlTruckFee(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TruckNo = Convert.ToString(reader["TruckNo"]); data.FeeDate = Convert.ToString(reader["FeeDate"]); data.FeeName = Convert.ToString(reader["FeeName"]); data.Amount = Convert.ToString(reader["Amount"]); data.Remark = Convert.ToString(reader["Remark"]); data.Inserted = Convert.ToString(reader["Inserted"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #region 明细表 static public List GetBodyList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("TruckNo,SerialNo,LoadType,"); strSql.Append("(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99030 and EnumValueID=tMsWlTruckFuel.LoadType) as LoadType_Ref"); strSql.Append(",Condition1,Ton1,Condition2,Ton2,FuelTotal,Remark,FuelPrice"); strSql.Append(" from tMsWlTruckFuel "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by SerialNo "); 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()) { MsWlTruckFuel data = new MsWlTruckFuel(); #region Set DB data to Object data.TruckNo = Convert.ToString(reader["TruckNo"]); data.SerialNo = Convert.ToDecimal(reader["SerialNo"]); data.LoadType = Convert.ToString(reader["LoadType"]); data.LoadType_Ref = Convert.ToString(reader["LoadType_Ref"]); data.Condition1 = Convert.ToString(reader["Condition1"]); data.Ton1 = Convert.ToDecimal(reader["Ton1"]); data.Condition2 = Convert.ToString(reader["Condition2"]); data.Ton2 = Convert.ToDecimal(reader["Ton2"]); data.FuelTotal = Convert.ToDecimal(reader["FuelTotal"]); data.Remark = Convert.ToString(reader["Remark"]); data.FuelPrice = Convert.ToDecimal(reader["FuelPrice"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 参照部分 internal static List GetDrvCodeList(string userid, string usercode, string orgcode) { var rangstr = GetRangDAStr("", userid, usercode, orgcode); var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" DrvCode,DrvName,DrvCode + '-' + DrvName as CodeAndName"); strSql.Append(" from tMsWlDriver"); 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 MsWlTruckRefMsWlDriver(); #region Set DB data to Object data.DrvCode = Convert.ToString(reader["DrvCode"]); data.DrvName = Convert.ToString(reader["DrvName"]); 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]='modTruckCar' 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") { str = " UPPER(OrgCode)='" + orgcode + "'"; } else if (visiblerange == "1") { str = " UPPER(OrgCode)='" + orgcode + "'"; } return str; } #endregion #region 20160516 车辆组 public static List GetTruckTeamList ( string strCondition, string sort ) { var strSql = new StringBuilder(); strSql.Append(" select *,(select name from company where codename=orgcode) COMPANYNAME from tMsWlTruckTeam "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } return SetTruckTeamData(strSql); } private static List SetTruckTeamData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { var data = new MsWlTruckTeam(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.ORGCODE = Convert.ToString(reader["ORGCODE"]); data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]); data.TEAMNAME = Convert.ToString(reader["TEAMNAME"]); data.INSERTED = Convert.ToString(reader["INSERTED"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static Int32 UpdTeamTruck ( string TRUCKNO, string TEAMGID ) { var strSql = new StringBuilder(); strSql.Append(" update tMsWlTruck set TEAMGID='" + TEAMGID + "' where TruckNo='" + TRUCKNO + "' "); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } #endregion internal static List GetTruckNoList(string userid, string usercode, string orgcode, string condition) { var rangstr = GetRangDAStr("", userid, usercode, orgcode); var strSql = new StringBuilder(); strSql.Append(" SELECT A.TruckNo,A.DrvCode,isnull((select Mobile from tMsWlDriver B where B.DrvCode=A.DrvCode),'') as Mobile "); strSql.Append(" ,A.WORKNO+'-'+A.TruckNo as WORKNOTruckNo "); strSql.Append(" ,(select drvname from tMsWlDriver where drvcode= A.drvcode) DrvName "); strSql.Append(" ,(select name from company where codename= A.orgcode) COMPANYNAME "); strSql.Append(" ,(select teamname from tMswlTruckTeam where GID=A.TEAMGID and TruckNo= A.TruckNo) TEAMNAME "); strSql.Append(" from tMsWlTruck A "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } } else 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 TruckSimplemb(); #region Set DB data to Object data.TruckNo = Convert.ToString(reader["TruckNo"]); data.DrvCode = Convert.ToString(reader["DrvCode"]); data.DrvName = Convert.ToString(reader["DrvName"]); data.Mobile = Convert.ToString(reader["Mobile"]); data.WORKNOTruckNo = Convert.ToString(reader["WORKNOTruckNo"]); data.COMPANYNAME = Convert.ToString(reader["COMPANYNAME"]); data.TEAMNAME = Convert.ToString(reader["TEAMNAME"]); #endregion dataList.Add(data); } reader.Close(); } return dataList; } #region 车辆月度数据 static public List GetTruckMonthList ( string strCondition ) { var strSql = new StringBuilder(); strSql.Append("select GID,TRUCKNO,ACCDATE,ZJF,BXF,GZCR from tmswltruck_month "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } return SetTruckMonthData(strSql); } private static List SetTruckMonthData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { Models.MsWlTruck.TruckMonthmb data = new Models.MsWlTruck.TruckMonthmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]); data.ACCDATE = Convert.ToString(reader["ACCDATE"]); data.ZJF = Convert.ToString(reader["ZJF"]); data.BXF = Convert.ToString(reader["BXF"]); data.GZCR = Convert.ToString(reader["GZCR"]); //data.XLCR = Convert.ToString(reader["XLCR"]); //data.ZCR = Convert.ToString(reader["ZCR"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 车辆证件上传 static public List GetTruckCertList ( string TruckNo ) { string strCondition = " where m.TruckNo = '"+TruckNo+"' and m.DelFlag = 0"; var strSql = new StringBuilder(); strSql.Append(@"select m.GID, m.TRUCKNO, m.Pic_Type, m.Pic_Path, m.Pic_Name, m.UpdateTime, t.SHOWNAME Operator, CASE m.Pic_Type WHEN 1 THEN '行车证' WHEN 2 THEN '营运证' WHEN 3 THEN '驾驶证' WHEN 4 THEN '资格证' WHEN 5 THEN '车俩照片' WHEN 6 THEN '驾驶员身份证' END AS CertTypeName from tMsWlTruck_CertPic m LEFT JOIN [user] t ON t.GID = m.Operator"); if (strCondition.Trim() != String.Empty) { strSql.Append(strCondition); } return SetTruckCertData(strSql); } private static List SetTruckCertData ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { Models.MsWlTruck.MsWlTruckCert data = new Models.MsWlTruck.MsWlTruckCert(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TruckNo = Convert.ToString(reader["TRUCKNO"]); data.Pic_Type = Convert.ToInt32(Convert.ToString(reader["Pic_Type"])); data.Pic_Name = Convert.ToString(reader["Pic_Name"]); data.Pic_Path = Convert.ToString(reader["Pic_Path"]); data.UpdateTime =DateTime.Parse(reader["UpdateTime"].ToString()).ToShortDateString(); data.Operator = Convert.ToString(reader["Operator"]); data.CertTypeName = Convert.ToString(reader["CertTypeName"]); //data.XLCR = Convert.ToString(reader["XLCR"]); //data.ZCR = Convert.ToString(reader["ZCR"]); #endregion headList.Add(data); } reader.Close(); } return headList; } /// /// 保存汽车证件 /// /// 证件实体类 /// 保存方式0:添加,1:更新 /// static public bool SaveTruckCert ( MsWlTruckCert TruckCert,int SaveType ,out string msg) { try { StringBuilder sb = new StringBuilder(); if (SaveType==0) { sb.Append("insert into tMsWlTruck_CertPic (GID,TruckNo,Pic_Type,Pic_Name,Pic_Path,CreateTime,Operator)"); sb.Append(" values("); sb.Append("'" + TruckCert.GID + "',"); sb.Append("'" + TruckCert.TruckNo + "',"); sb.Append("'" + TruckCert.Pic_Type + "',"); sb.Append("'" + TruckCert.Pic_Name + "',"); sb.Append("'" + TruckCert.Pic_Path + "',"); sb.Append("'" + TruckCert.CreateTime + "',"); sb.Append("'" + TruckCert.Operator + "'"); sb.Append(")"); } else { sb.Append("update tMsWlTruck_CertPic set "); sb.Append("Pic_Type='" + TruckCert.Pic_Type + "',"); sb.Append("Pic_Name='" + TruckCert.Pic_Name + "',"); sb.Append("Pic_Path='" + TruckCert.Pic_Path + "',"); sb.Append("Operator='" + TruckCert.Operator + "'"); sb.Append("where GID='"+TruckCert.GID+"'"); } Database db = DatabaseFactory.CreateDatabase(); int rst = db.ExecuteNonQuery(CommandType.Text,sb.ToString()); msg = ""; return rst > 0; } catch (Exception ex) { msg = ex.Message; return false; throw; } } static public bool DelTruckCert ( List TruckCert, out string msg ) { try { string gids = ""; for (int i = 0; i < TruckCert.Count; i++) { gids += "'"+TruckCert[i].GID+"',"; } if (gids.Length>0) { gids = gids.Substring(0, gids.Length - 1); } StringBuilder sb = new StringBuilder(); sb.Append("update tMsWlTruck_CertPic set DelFlag = 1 "); sb.Append("where gid in (" + gids + ")"); Database db = DatabaseFactory.CreateDatabase(); int rst = db.ExecuteNonQuery(CommandType.Text, sb.ToString()); msg = ""; return rst>0; } catch (Exception ex) { msg = ex.Message; return false; throw; } } #endregion } }