using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOpTaskNew; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using HcUtility.Comm; using DSWeb.MvcShipping.Models.MsUserAuthority; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.CommMng.DAL; using HcUtility.Core; namespace DSWeb.Areas.MvcShipping.DAL { public class MsOpTaskNewDAL { #region Inquery DataList static public List GetDataList(int start, int limit, string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append(@"SELECT * from (SELECT row_number() over ("); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by TASKBEGINDATE DESC "); } strSql.Append(@") as num , * from (SELECT "); strSql.Append("t.GID,t.TASKNO,t.PTASKNO,t.TASKTYPE,t.TASKSOURCE,t.TASKSTATUS,t.TASKTITLE,t.TASKDESCRIP,t.CREATEUSER,t.CORPID,t.CREATETIME,t.TASKBEGINDATE"); strSql.Append(",t.COMPLETETYPE,t.COMPLETETIME,t.KPI,t.FILENO,t.MAILNO,t.FILEPATH,t.ISPUBLIC,t.ISCOMPLETE,t.REMARK,t.CUSTNO"); strSql.Append(",t.TASKCLASS,t.DEPT,t.TASKOP,t.MBLNO,t.PORTLOAD,t.PORTDISCHARGE,t.SALE,t.OP,t.BSNO,t.MODIFYUSER,t.MODIFYTIME "); strSql.Append(",(select ShowName from [user] where GID=t.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=t.MODIFYUSER) as MODIFYUSERREF"); strSql.Append(",CASE WHEN COMPLETETIME IS NULL THEN DATEDIFF(DAY, CREATETIME, GETDATE()) ELSE DATEDIFF(DAY, CREATETIME, COMPLETETIME) END WORKDAY"); strSql.Append(" from op_task_new t "); strSql.Append(") AS t"); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } strSql.Append(@")as t "); strSql.Append(string.Format("where t.num>{0} and t.num<={1} order by t.num ", start, start + limit)); // return SetData(strSql); } public static int getTotalCount(string strCondition, string userid, string usercode, string companyid) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } StringBuilder strSql = new StringBuilder(); strSql.Append("select count(*) "); strSql.Append(" from (select *,CASE WHEN COMPLETETIME IS NULL THEN DATEDIFF(DAY, CREATETIME, GETDATE()) ELSE DATEDIFF(DAY, CREATETIME, COMPLETETIME) END WORKDAY "); strSql.Append(" from op_task_new) as t "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } int cnt = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { cnt = Convert.ToInt32(reader[0]); } } return cnt; } static public OpTaskNew GetData(string condition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("t.GID,t.TASKNO,t.PTASKNO,t.TASKTYPE,t.TASKSOURCE,t.TASKSTATUS,t.TASKTITLE,t.TASKDESCRIP,t.CREATEUSER,t.CORPID,t.CREATETIME,t.TASKBEGINDATE"); strSql.Append(",t.COMPLETETYPE,t.COMPLETETIME,t.KPI,t.FILENO,t.MAILNO,t.FILEPATH,t.ISPUBLIC,t.ISCOMPLETE,t.REMARK,t.CUSTNO"); strSql.Append(",t.TASKCLASS,t.DEPT,t.TASKOP,t.MBLNO,t.PORTLOAD,t.PORTDISCHARGE,t.SALE,t.OP,t.BSNO,t.MODIFYUSER,t.MODIFYTIME "); strSql.Append(",(select ShowName from [user] where GID=t.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=t.MODIFYUSER) as MODIFYUSERREF"); strSql.Append(",CASE WHEN COMPLETETIME IS NULL THEN DATEDIFF(DAY, CREATETIME, GETDATE()) ELSE DATEDIFF(DAY, CREATETIME, COMPLETETIME) END WORKDAY"); strSql.Append(" from op_task_new t "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var list = SetData(strSql); if (list.Count > 0) return list[0]; return new OpTaskNew(); } 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()) { OpTaskNew data = new OpTaskNew(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TASKNO = Convert.ToString(reader["TASKNO"]); data.PTASKNO = Convert.ToString(reader["PTASKNO"]); data.TASKTYPE = Convert.ToString(reader["TASKTYPE"]); data.TASKSOURCE = Convert.ToString(reader["TASKSOURCE"]); data.TASKSTATUS = Convert.ToString(reader["TASKSTATUS"]); data.TASKTITLE = Convert.ToString(reader["TASKTITLE"]); data.TASKDESCRIP = Convert.ToString(reader["TASKDESCRIP"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CORPID = Convert.ToString(reader["CORPID"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["TASKBEGINDATE"] != DBNull.Value) data.TASKBEGINDATE = Convert.ToDateTime(reader["TASKBEGINDATE"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["COMPLETETIME"] != DBNull.Value) data.COMPLETETIME = Convert.ToDateTime(reader["COMPLETETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 data.COMPLETETYPE = Convert.ToString(reader["COMPLETETYPE"]); data.FILENO = Convert.ToString(reader["FILENO"]); data.MAILNO = Convert.ToString(reader["MAILNO"]); data.FILEPATH = Convert.ToString(reader["FILEPATH"]); data.ISPUBLIC = Convert.ToString(reader["ISPUBLIC"]); data.ISCOMPLETE = Convert.ToString(reader["ISCOMPLETE"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.OP = Convert.ToString(reader["OP"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.SALE = Convert.ToString(reader["SALE"]); if (reader["MODIFYTIME"] != DBNull.Value) data.MODIFYTIME = Convert.ToDateTime(reader["MODIFYTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); if (reader["TASKCLASS"] != DBNull.Value) data.TASKCLASS = Convert.ToInt16(reader["TASKCLASS"]); data.SALE = Convert.ToString(reader["SALE"]); data.DEPT = Convert.ToString(reader["DEPT"]); data.TASKOP = Convert.ToString(reader["TASKOP"]); data.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]); data.MODIFYUSERREF = Convert.ToString(reader["MODIFYUSERREF"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); if (reader["WORKDAY"] != DBNull.Value) data.WORKDAY = Convert.ToInt32(reader["WORKDAY"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion static public List GetTaskCountList(string strCondition, string userid, string usercode, string companyid, string sort = null) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT TASKSTATUS,COUNT(1) ALLCOUNT,SUM(CASE WHEN TASKCLASS=2 THEN 1 ELSE 0 END) GCOUNT"); strSql.Append(",SUM(CASE WHEN TASKCLASS=1 THEN 1 ELSE 0 END) ZCOUNT"); strSql.Append(",SUM(CASE WHEN TASKCLASS<>2 AND TASKCLASS<>1 THEN 1 ELSE 0 END) DCOUNT "); strSql.Append(",SUM(CASE WHEN WORKDAY<=10 THEN 1 ELSE 0 END) D10COUNT "); strSql.Append(",SUM(CASE WHEN WORKDAY>10 AND WORKDAY<=20 THEN 1 ELSE 0 END) D20COUNT"); strSql.Append(",SUM(CASE WHEN WORKDAY>20 AND WORKDAY<=30 THEN 1 ELSE 0 END) D30COUNT "); strSql.Append(",SUM(CASE WHEN WORKDAY>30 THEN 1 ELSE 0 END) DOV30COUNT"); strSql.Append(" from V_OP_TASK_NEW t left join v_op_bill b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where t.TASKSTATUS!='待挂单' and " + strCondition); } if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } strSql.Append(" GROUP BY TASKSTATUS"); return SetCountData(strSql); } private static List SetCountData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpTaskCount data = new OpTaskCount(); #region Set DB data to Object data.TASKSTATUS = Convert.ToString(reader["TASKSTATUS"]); if (reader["ALLCOUNT"] != DBNull.Value) data.ALLCOUNT = Convert.ToInt32(reader["ALLCOUNT"]); if (reader["GCOUNT"] != DBNull.Value) data.GCOUNT = Convert.ToInt32(reader["GCOUNT"]); if (reader["ZCOUNT"] != DBNull.Value) data.ZCOUNT = Convert.ToInt32(reader["ZCOUNT"]); if (reader["DCOUNT"] != DBNull.Value) data.DCOUNT = Convert.ToInt32(reader["DCOUNT"]); if (reader["D10COUNT"] != DBNull.Value) data.D10COUNT = Convert.ToInt32(reader["D10COUNT"]); if (reader["D20COUNT"] != DBNull.Value) data.D20COUNT = Convert.ToInt32(reader["D20COUNT"]); if (reader["D30COUNT"] != DBNull.Value) data.D30COUNT = Convert.ToInt32(reader["D30COUNT"]); if (reader["DOV30COUNT"] != DBNull.Value) data.DOV30COUNT = Convert.ToInt32(reader["DOV30COUNT"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetBSList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT CUSTNO,MBLNO,BSNO,PORTLOAD,PORTDISCHARGE,SALE,OP"); strSql.Append(" from v_op_bs_bsno "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } return SetBSData(strSql); } private static List SetBSData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BS data = new BS(); #region Set DB data to Object data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]); data.PORTDICHARGE = Convert.ToString(reader["PORTDISCHARGE"]); data.SALE = Convert.ToString(reader["SALE"]); data.OP = Convert.ToString(reader["OP"]); #endregion headList.Add(data); } reader.Close(); } return headList; } static public List GetTaskDetailList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT GID,PGID,TASKDESCRIP,MODIFYUSER,MODIFYTIME,CREATEUSER,CREATETIME"); strSql.Append(",(select ShowName from [user] where GID=op_task_detail.CREATEUSER) as CREATEUSERREF"); strSql.Append(",(select ShowName from [user] where GID=op_task_detail.MODIFYUSER) as MODIFYUSERREF"); strSql.Append(" from op_task_detail "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } return SetTaskDetailData(strSql); } private static List SetTaskDetailData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpTaskDetail data = new OpTaskDetail(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.PGID = Convert.ToString(reader["PGID"]); data.TASKDESCRIP = Convert.ToString(reader["TASKDESCRIP"]); data.MODIFYUSER = Convert.ToString(reader["MODIFYUSER"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["MODIFYTIME"] != DBNull.Value) data.MODIFYTIME = Convert.ToDateTime(reader["MODIFYTIME"]).ToString("yyyy-MM-dd HH:mm:ss"); data.MODIFYUSERREF = Convert.ToString(reader["MODIFYUSERREF"]); data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult SaveFitingsBody(List bodyList, string PID, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"insert into op_task_detail (GID,[PGID],[TASKDESCRIP],[CREATEUSER],[CREATETIME],[MODIFYUSER],[MODIFYTIME]) values (@GID,@PGID,@TASKDESCRIP,@CREATEUSER,@CREATETIME,@MODIFYUSER,@MODIFYTIME) "); var cmdUpdate = db.GetSqlStringCommand( @"update op_task_detail set TASKDESCRIP=@TASKDESCRIP,MODIFYUSER=@MODIFYUSER,MODIFYTIME=@MODIFYTIME where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { if (enumValue.PGID == "*" || enumValue.PGID == "") { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@PGID", DbType.String, PID); db.AddInParameter(cmdInsert, "@TASKDESCRIP", DbType.String, enumValue.TASKDESCRIP); db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@MODIFYUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdInsert, tran); } else { cmdUpdate.Parameters.Clear(); db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdUpdate, "@TASKDESCRIP", DbType.String, enumValue.TASKDESCRIP); db.AddInParameter(cmdUpdate, "@MODIFYUSER", DbType.String, userid); db.AddInParameter(cmdUpdate, "@MODIFYTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.ExecuteNonQuery(cmdUpdate, tran); } } } tran.Commit(); } catch (Exception E) { tran.Rollback(); result.Success = false; result.Message = "保存出现错误,请重试或联系系统管理员" + E.Message; return result; } } result.Success = true; result.Message = "保存成功" + result.Message; return result; } static public List GetTaskLogList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT GID,PGID,DESCRIP,CREATEUSER,CREATETIME"); strSql.Append(",(select ShowName from [user] where GID=op_task_log.CREATEUSER) as CREATEUSERREF"); strSql.Append(" from op_task_log "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where 1=1 and " + strCondition); } strSql.Append(" ORDER BY CREATETIME DESC "); return SetTaskLogData(strSql); } private static List SetTaskLogData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpTaskLog data = new OpTaskLog(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.PGID = Convert.ToString(reader["PGID"]); data.DESCRIP = Convert.ToString(reader["DESCRIP"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]); #endregion headList.Add(data); } reader.Close(); } return headList; } public static DBResult UpTransStatus(List bodyList, string transstatus,string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { var cmdupdate = db.GetSqlStringCommand("update op_task_new set TASKSTATUS=@TASKSTATUS,MODIFYUSER='" + userid + "',MODIFYTIME=GETDATE() where GID=@GID"); if (transstatus == "完成") cmdupdate = db.GetSqlStringCommand("update op_task_new set TASKSTATUS=@TASKSTATUS,ISCOMPLETE=1,COMPLETETYPE='人工',COMPLETETIME=GETDATE(),MODIFYUSER='" + userid + "',MODIFYTIME=GETDATE() where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdupdate, "@TASKSTATUS", DbType.String, transstatus); db.ExecuteNonQuery(cmdupdate, tran); var optasklog = new OpTaskLog(); optasklog.GID = Guid.NewGuid().ToString(); optasklog.PGID = enumValue.GID; optasklog.DESCRIP = "更新状态为"+ transstatus; optasklog.CREATEUSER = userid; optasklog.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); optasklog.DbOperationType = DbOperationType.DbotIns; var modb = new ModelObjectDB(); modb.Save(optasklog); } } tran.Commit(); result.Success = true; result.Message = "更新完成!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } public static DBResult UpdateTaskOpList(List bodyList, string taskop, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { foreach (var enumValue in bodyList) { var cmdupdate = db.GetSqlStringCommand("update op_task_new set TASKOP=@TASKOP,MODIFYUSER='" + userid + "',MODIFYTIME=GETDATE() where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdupdate, "@TASKOP", DbType.String, taskop); db.ExecuteNonQuery(cmdupdate, tran); var optasklog = new OpTaskLog(); optasklog.GID = Guid.NewGuid().ToString(); optasklog.PGID = enumValue.GID; optasklog.DESCRIP = "指派给" + taskop; optasklog.CREATEUSER = userid; optasklog.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); optasklog.DbOperationType = DbOperationType.DbotIns; var modb = new ModelObjectDB(); modb.Save(optasklog); } } tran.Commit(); result.Success = true; result.Message = "更新完成!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } static public List GetTaskTreeRefList(string PARENTID, string strCondition, string userid, string usercode, string companyid) { var rangstr = GetRangDAStr("index", userid, usercode, companyid); if (!string.IsNullOrEmpty(rangstr)) { if (!string.IsNullOrEmpty(strCondition)) { strCondition = strCondition + " and " + rangstr; } else { strCondition = rangstr; } } var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append(" GID,NAME,DESCRIPTION,PARENTID,TYPE,TASTCOUNT from (SELECT GID,NAME,DESCRIPTION,PARENTID,TYPE,sum(TASTCOUNT) TASTCOUNT "); strSql.Append(" from ( select DISTINCT convert(varchar(20),isnull(ISCOMPLETE,0)) GID,(CASE WHEN ISCOMPLETE=1 THEN '已完成' ELSE '未完成' END) NAME,(CASE WHEN ISCOMPLETE=1 THEN '已完成' ELSE '未完成' END) DESCRIPTION ,'-1' PARENTID,'0' TYPE,COUNT(*) TASTCOUNT from op_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where TASKSTATUS!='待挂单' and " + strCondition); } strSql.Append(" GROUP BY t.ISCOMPLETE) as z group by GID,NAME,DESCRIPTION,PARENTID,TYPE "); strSql.Append(" union select DISTINCT TASKTYPE+''+convert(varchar(20),isnull(ISCOMPLETE,0)) GID, TASKTYPE NAME, TASKTYPE DESCRIPTION,isnull(ISCOMPLETE,0) PARENTID, '1' TYPE, COUNT(*) TASTCOUNT from op_task_new t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where TASKSTATUS!='待挂单' and " + strCondition); } strSql.Append(" GROUP BY TASKTYPE, ISNULL(ISCOMPLETE,0)) as v "); strSql.Append(" where parentid='" + PARENTID + "' "); return SetUserTreeRefData(strSql); } private static List SetUserTreeRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { UserTreeRefModel data = new UserTreeRefModel(); #region Set DB data to Object data.id = Convert.ToString(reader["GID"]); data.NAME = Convert.ToString(reader["NAME"]); data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]); data.PARENTID = Convert.ToString(reader["PARENTID"]); data.TYPE = Convert.ToString(reader["TYPE"]); if (reader["TASTCOUNT"] != DBNull.Value) data.TASTCOUNT =Convert.ToInt32(reader["TASTCOUNT"]); data.DESCRIPTION = data.DESCRIPTION + "(" + data.TASTCOUNT + ")"; if (data.TYPE == "1") { data.leaf = true; data.expanded = true; } else { data.leaf = false; data.expanded = true; }; #endregion headList.Add(data); } reader.Close(); } return headList; } #region 保存,删除 public static DBResult DeleteTask(List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"delete from op_task_new where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功" + result.Message; return result; } public static DBResult DeleteTaskDetail(List bodyList,string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"delete from op_task_detail where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdInsert, tran); var optasklog = new OpTaskLog(); optasklog.GID = Guid.NewGuid().ToString(); optasklog.PGID = enumValue.PGID; optasklog.DESCRIP = "删除问题进展" + enumValue.TASKDESCRIP; optasklog.CREATEUSER = userid; optasklog.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); optasklog.DbOperationType = DbOperationType.DbotIns; var modb = new ModelObjectDB(); modb.Save(optasklog); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功" + result.Message; return result; } #endregion #region Rang权限范围 public static string GetRangDAStr(string tb, string userid, string username, string companyid) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT"); strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID "); strSql.Append(" from VW_User_Authority"); strSql.Append(" where [NAME]='modOpTaskNew' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; string AUTHORITYID = ""; 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"]); AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (t.TASKOP='" + username + "' or t.ISPUBLIC=1 or t.CREATEUSER='"+ userid + "') "; } else if (visiblerange == "3") { str = " (t.TASKOP='" + username + "' or t.ISPUBLIC=1 or t.CREATEUSER='" + userid + "') "; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptid = rangeDa.GetDEPTGID(userid); str = $" exists(select 1 from vw_user where deptgid='{deptid}' and (SHOWNAME in(t.TASKOP) or USERID=t.CREATEUSER)) "; } else if (visiblerange == "1") { str = " b.CORPID='" + companyid + "'"; } else if (visiblerange == "5") { var userstr = new StringBuilder(); userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1"); Database userdb = DatabaseFactory.CreateDatabase(); using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString())) { str = ""; while (reader.Read()) { if (str == "") { str = " (B.CORPID='" + Convert.ToString(reader["COMPANYID"]) + "'"; } else { str = str + " or B.CORPID='" + Convert.ToString(reader["COMPANYID"]) + "' "; }; } str = str + ")"; reader.Close(); } } else if (visiblerange == "6") { str = " EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where ((t.TASKOP=U.SHOWNAME) OR (t.CREATEUSER=U.GID)) AND P.userid='" + userid + "' and P.AUTHORITYID='" + AUTHORITYID + "' and P.VISIBLERANGE=1) "; } return str; } #endregion #region 参照部分 #endregion } }