You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/OA/DAL/WorkFlow/WorkFlowDAL.cs

490 lines
21 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.OA.Models.WorkFlow;
using DSWeb.Areas.OA.Models.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.OA.DAL.WorkFlow
{
public partial class WorkFlowDAL
{
#region WorkFlow_Type列表
static public List<WorkFlowTypemb> GetTypeList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,NAME,DESCRIPTION,TYPENO ");
strSql.Append(" ,(select showname from [user] where gid=CREATEUSER) CREATEUSER,dbo.trimtime(CREATETIME) CREATETIME ");
strSql.Append(" ,(select showname from [user] where gid=MODIFIEDUSER) MODIFIEDUSER,dbo.trimtime(MODIFIEDTIME) MODIFIEDTIME ");
strSql.Append(" FROM WorkFlow_Type WT ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetTypeListData(strSql);
}
static public WorkFlowTypemb GetTypeData(string condition)
{
var list = GetTypeList(condition);
if (list.Count > 0)
return list[0];
return new WorkFlowTypemb();
}
private static List<WorkFlowTypemb> SetTypeListData(StringBuilder strSql)
{
var headList = new List<WorkFlowTypemb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlowTypemb data = new WorkFlowTypemb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.TYPENO = Convert.ToString(reader["TYPENO"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region WorkFlow列表
static public List<WorkFlowmb> GetWorkFlowList(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,[name],[description],[type],CREATEUSER, ");
strSql.Append(" (select showname from [user] u where u.gid=wf.CREATEUSER) CREATEUSER_REF, ");
strSql.Append(" dbo.trimdate(CREATETIME) CREATETIME,MODIFIEDUSER, ");
strSql.Append(" (select showname from [user] u where u.gid=wf.MODIFIEDUSER) MODIFIEDUSER_REF, ");
strSql.Append(" dbo.trimdate(MODIFIEDTIME) MODIFIEDTIME,COMPANYID, ");
//strSql.Append(" (select [name] from [COMPANY] c where c.gid=wf.COMPANYID) COMPANY_REF,DEPTGID, ");
//strSql.Append(" (select [deptname] from [sys_dept] sd where sd.gid=wf.DEPTGID) DEPT_REF from workflow wf ");
strSql.Append(" (select [name] from [COMPANY] c where c.gid=wf.COMPANYID) COMPANY_REF,ISDEFAULT,ISCONDITION,CONDITIONSQL,SORTNO from workflow wf ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
return SetWorkFlowData(strSql);
}
static public WorkFlowmb GetWorkFlowData(string condition)
{
var list = GetWorkFlowList(condition);
if (list.Count > 0)
return list[0];
return new WorkFlowmb();
}
private static List<WorkFlowmb> SetWorkFlowData(StringBuilder strSql)
{
var headList = new List<WorkFlowmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlowmb data = new WorkFlowmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.TYPE = Convert.ToString(reader["TYPE"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSER_REF = Convert.ToString(reader["CREATEUSER_REF"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDUSER_REF = Convert.ToString(reader["MODIFIEDUSER_REF"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.COMPANY_REF = Convert.ToString(reader["COMPANY_REF"]);
data.ISDEFAULT = Convert.ToString(reader["ISDEFAULT"]);
if (reader["ISCONDITION"] != DBNull.Value)
data.ISCONDITION = Convert.ToBoolean(reader["ISCONDITION"]);
data.CONDITIONSQL = Convert.ToString(reader["CONDITIONSQL"]);
if (reader["SORTNO"] != DBNull.Value)
data.SORTNO = Convert.ToString(reader["SORTNO"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region WorkFlow_Step列表
static public List<DSWeb.Areas.OA.Models.WorkFlow.WorkFlowStepmb> GetStepList ( string WorkFlowID )
{
var strSql = new StringBuilder();
strSql.Append(" select GID,[name],[description],CREATEUSER, ");
strSql.Append(" (select showname from [user] u where u.gid=ws.CREATEUSER)as CREATEUSER_REF, ");
strSql.Append(" dbo.trimdate(CREATETIME) CREATETIME,MODIFIEDUSER, ");
strSql.Append(" (select showname from [user] u where u.gid=ws.MODIFIEDUSER)as MODIFIEDUSER_REF, ");
strSql.Append(" dbo.trimdate(MODIFIEDTIME) MODIFIEDTIME,WORKFLOWID,STEPNO,AUDITOR, ");
strSql.Append(" (select showname from [user] u where u.gid=ws.AUDITOR)as AUDITOR_REF, ");
strSql.Append(" ISLAST,dbo.f_YN(ISLAST) ISLAST_REF,GROUPID,NEXTGROUP,stepno,REMARK ");
strSql.Append(" from workflow_step ws ");
if (!string.IsNullOrEmpty(WorkFlowID))
{
strSql.Append(" where " + WorkFlowID);
}
return SetStepData(strSql);
}
private static List<DSWeb.Areas.OA.Models.WorkFlow.WorkFlowStepmb> SetStepData ( StringBuilder strSql )
{
var headList = new List<DSWeb.Areas.OA.Models.WorkFlow.WorkFlowStepmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
DSWeb.Areas.OA.Models.WorkFlow.WorkFlowStepmb data = new DSWeb.Areas.OA.Models.WorkFlow.WorkFlowStepmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
data.STEPNO = Convert.ToString(reader["STEPNO"]);
data.AUDITOR = Convert.ToString(reader["AUDITOR"]);
data.AUDITOR_REF = Convert.ToString(reader["AUDITOR_REF"]);
data.ISLAST = Convert.ToString(reader["ISLAST"]);
data.ISLAST_REF = Convert.ToString(reader["ISLAST_REF"]);
data.GROUPID = Convert.ToString(reader["GROUPID"]);
data.NEXTGROUP = Convert.ToString(reader["NEXTGROUP"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSER_REF = Convert.ToString(reader["CREATEUSER_REF"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDUSER_REF = Convert.ToString(reader["MODIFIEDUSER_REF"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region WorkFlow_UserPath列表
static public List<WorkFlowUserPathmb> GetUserPathList(string WorkFlowID)
{
var strSql = new StringBuilder();
strSql.Append(" select id,Up.userid,u.showname username,u.DEPTNAME,workflowtypeno,workflowid,'' workflowname ");
strSql.Append(" from workflow_userpath up ");
strSql.Append(" left join VW_user u on u.userid=up.USERID ");
if (!string.IsNullOrEmpty(WorkFlowID))
{
strSql.Append(" where workflowid='" + WorkFlowID+"'");
}
return SetUserPathData(strSql);
}
private static List<WorkFlowUserPathmb> SetUserPathData(StringBuilder strSql)
{
var headList = new List<WorkFlowUserPathmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlowUserPathmb data = new WorkFlowUserPathmb();
#region Set DB data to Object
data.ID = Convert.ToString(reader["ID"]);
data.USERID = Convert.ToString(reader["USERID"]);
data.USERNAME = Convert.ToString(reader["USERNAME"]);
data.DEPTNAME = Convert.ToString(reader["DEPTNAME"]);
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
data.WORKFLOWTYPENO = Convert.ToString(reader["WORKFLOWTYPENO"]);
data.WORKFLOWNAME = Convert.ToString(reader["WORKFLOWNAME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region WorkFlow_UserState列表userpath
static public List<WorkFlowUserPathmb> GetUserStateList(string WorkFlowID)
{
var strSql = new StringBuilder();
strSql.Append(" select up.id,U.userid,up.workflowid,u.showname username,u.DEPTNAME,w.NAME WORKFLOWNAME,up.WORKFLOWTYPENO from VW_user u ");
strSql.Append(" left join workflow_UserPath Up on u.userid=up.USERID and up.workflowTypeNO=(select type from workflow where gid='" + WorkFlowID + "') ");
strSql.Append(" left join workflow_type wt on wt.TYPENO=up.workflowtypeno ");
strSql.Append(" left join workflow w on w.GID=up.WORKFLOWID where ");
strSql.Append(" U.userid not in(select userid from workflow_UserPath where workflowid='" + WorkFlowID + "') ");
strSql.Append(" and u.userid in (select userid from user_company where companyid=(select companyid from workflow where gid='" + WorkFlowID + "')) ");
//strSql.Append(" and u.ISDISABLE=0 ");
//if (!string.IsNullOrEmpty(WorkFlowID))
//{
// strSql.Append(" where " + WorkFlowID);
//}
return SetUserPathData(strSql);
}
#endregion
#region 修改userpath
static public Resultmb SaveUserPath(string WORKFLOWTYPENO,string WorkFlowID,String USERIDList)
{
var strSql = new StringBuilder();
var _count = 0;
var _Result = new Resultmb();
Database db = DatabaseFactory.CreateDatabase();
strSql.Append(" delete from workflow_userpath where WORKFLOWTYPENO='" + WORKFLOWTYPENO + "' and userid in (" + USERIDList + ") and workflowID not in (select GID FROM workflow WHERE ISNULL(ISCONDITION,0)=1)");
// strSql.Append(" delete from workflow_userpath where WORKFLOWTYPENO='" + WORKFLOWTYPENO + "' and userid in(" + USERIDList + ") ");
strSql.Append(" insert into workflow_userpath select gid,'" + WORKFLOWTYPENO + "','" + WorkFlowID + "' from [user] ");
strSql.Append(" where gid in(" + USERIDList + ")");
try
{
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
_Result.totalCount = _count;
}
catch (Exception ee)
{
_Result.Success = false;
_Result.Message = ee.Message;
}
return _Result;
}
static public Resultmb DelUserPath(string WORKFLOWTYPENO, string WorkFlowID, String USERIDList)
{
var strSql = new StringBuilder();
var _count = 0;
var _Result = new Resultmb();
Database db = DatabaseFactory.CreateDatabase();
strSql.Append(" delete from workflow_userpath where WORKFLOWTYPENO='" + WORKFLOWTYPENO + "' and userid in(" + USERIDList + ")");
try
{
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
_Result.totalCount = _count;
}
catch (Exception ee)
{
_Result.Success = false;
_Result.Message = ee.Message;
}
return _Result;
}
#endregion
#region 删除WorkFlow
static public int DeleteWorkFlow(string GID)
{
var strSql = new StringBuilder();
strSql.Append(" delete from WorkFlow where gid = '" + GID + "'");
strSql.Append(" delete from WorkFlow_step where workflowid = '" + GID + "'");
strSql.Append(" delete from workflow_UserPath where workflowid = '" + GID + "'");
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 增加wolkflow_type
static public int AddType(string GID)
{
var strSql = new StringBuilder();
strSql.Append(" insert into [workFlow_Type] (GID) values('"+GID+"')");
return setAddType(strSql);//ExecuteNonQuery
}
private static int setAddType(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 设置某workflow_type的默认workflow
static public int SetDefaultStep(string TYPE,string companyid)
{
var strSql = new StringBuilder();
strSql.Append(" update workflow set isdefault=0 where type=" + TYPE + " and companyid='"+companyid+"' ");
return SetDefaultStep(strSql);//ExecuteNonQuery
}
private static int SetDefaultStep(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region [查询]看是否有未完成的该工作流审批
static public List<WorkFlow_Usingmb> GetWorkFlowInUsingList ( string WorkFlowID )
{
var strSql = new StringBuilder();
strSql.Append(" select * from workflow_using ");
strSql.Append(" where workflowid='" + WorkFlowID + "' and FINISHED=0 ");
//strSql.Append(" and (wd.isdelete is null or wd.isdelete=0 ) ");
return SetWorkFlowState(strSql);
}
private static List<WorkFlow_Usingmb> SetWorkFlowState ( StringBuilder strSql )
{
var bodyList = new List<WorkFlow_Usingmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkFlow_Usingmb data = new WorkFlow_Usingmb();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
data.STEPNO = Convert.ToString(reader["STEPNO"]);/*
data.REJECTOR_ID = Convert.ToString(reader["REJECTOR_ID"]);
data.REJECT_TIME = Convert.ToString(reader["REJECT_TIME"]);
data.FINISHED = Convert.ToString(reader["FINISHED"]);
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);*/
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
#endregion
}
public partial class WorkLogDAL {
#region WorkLog列表
static public List<WorkLogmb> GetWorkLog ( string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(" select GID,BSNO,(select showname from [user] where [user].GID=WorkLog.OP) OP,dbo.trimtime(OPDATE) OPDATE,ACTNAME,ACTRESULT,REMARK ");
strSql.Append(" FROM WorkLog ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by OPDATE desc ");
}
return SetLogData(strSql);
}
static public WorkLogmb GetTypeData ( string condition )
{
var list = GetWorkLog(condition);
if (list.Count > 0)
return list[0];
return new WorkLogmb();
}
private static List<WorkLogmb> SetLogData ( StringBuilder strSql )
{
var headList = new List<WorkLogmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
WorkLogmb data = new WorkLogmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.OP = Convert.ToString(reader["OP"]);
data.OPDATE = Convert.ToString(reader["OPDATE"]);
data.ACTNAME = Convert.ToString(reader["ACTNAME"]);
data.ACTRESULT = Convert.ToString(reader["ACTRESULT"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
/*
public Boolean WriteWorkLog ( WorkLogmb WorkLog )
{
WorkLog.DbOperationType = DbOperationType.DbotIns;
WorkLog.ModelUIStatus = "I";
WorkLog.GID = System.Guid.NewGuid().ToString();
WorkLog.OP = Convert.ToString(Session["SHOWNAME"]);
WorkLog.OPDATE = DateTime.Now.ToLocalTime().ToString();
var modb = new ModelObjectRepository();
DBResult result = modb.Save(WorkLog);
return result.Success;
}*/
#endregion
}
}