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/WorkFlow/WorkFlowGridSource.aspx.cs

457 lines
17 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.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
namespace DSWeb.WorkFlow
{
public partial class WorkFlowGridSource : System.Web.UI.Page
{
private string strHandle;//如果值为list则返回所有工作流设置信息
private string strWorkFlowID;//工作流GID
private string strAuditorID;//审核人GID
private string strWorkFlowStepID;//工作流步骤GID
private string strUserID;//用户GID
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
if(Request.QueryString["flowid"] != null)
{
strWorkFlowID = Request.QueryString["flowid"].ToString();
}
if (Request.QueryString["auditor"] != null)
{
strAuditorID = Request.QueryString["auditor"].ToString();
}
if(Request.QueryString["stepid"] != null)
{
strWorkFlowStepID = Request.QueryString["stepid"].ToString();
}
if (strHandle != null)
{
if (strHandle == "workflowlist")
{
Response.Write(GetWorkFlowList());//获取工作流workflow信息
}
if (strHandle == "steplist" && strWorkFlowID != null)
{
Response.Write(GetWorkFlowSteps(strWorkFlowID));
}
if (strHandle == "usertree")
{
//获取公司用户信息树
Response.Write(GetUserTree());
}
if (strHandle == "companytree")
{
Response.Write(GetCompanyTree());
}
if (strHandle == "depttree")
{
Response.Write(GetDepartmentTree());
}
if (strHandle == "updateauditor" && strAuditorID != null && strWorkFlowStepID != null)
{
Response.Write(UpdateWorkFlowStepAuditor(strAuditorID,strWorkFlowStepID,strWorkFlowID));
}
if (strHandle == "delete")
{
Response.Write(DeleteWorkFlowByFlowID(strWorkFlowID));
}
if (strHandle == "deleteStep")
{
Response.Write(DeleteWorkFlowStepByStepID(strWorkFlowStepID));
}
}
}
#region
/// <summary>
///
/// </summary>
/// <returns></returns>
public int DeleteWorkFlowStepByStepID(string strWorkFlowStepID)
{
int iResult = 0;
WorkFlowDoDA doDA = new WorkFlowDoDA();
int iDo = doDA.GetExistWorkFlowStepID(strWorkFlowStepID);
WorkFlowStepDA StepDA = new WorkFlowStepDA();
if (iDo > 0)
{ //工作流步骤已经开始使用,不能删除
iResult = -2;
}
else
{ //工作流没有生效,直接删除
iResult = StepDA.DeletetWorkFlowStepByID(strWorkFlowStepID);
}
return iResult;
}
#endregion
#region
/// <summary>
///
/// </summary>
/// <returns></returns>
public int DeleteWorkFlowByFlowID(string tempWorkFlowID)
{
int iResult = 0;
WorkFlowStepDA StepDA = new WorkFlowStepDA();
int iStep = StepDA.GetExistWorkFlowID(tempWorkFlowID);
//WorkFlowDoDA doDA = new WorkFlowDoDA();
//int iDo = doDA.GetExistWorkFlowID(tempWorkFlowID);
WorkFlowDA FlowDA = new WorkFlowDA();
if (iStep>0 )
{ //工作流已经定义工作步骤设isdelete=1
iResult = FlowDA.DeleteWorkFlowByID(tempWorkFlowID, 0);
}
else
{ //工作流没有生效,直接删除
iResult = FlowDA.DeleteWorkFlowByID(tempWorkFlowID, 1);
}
return iResult;
}
#endregion
#region 更新工作流步骤审核人信息
/// <summary>
/// 更新工作流步骤审核人信息
/// </summary>
/// <param name="tempAuditorID">审核人GID</param>
/// <param name="tempWorkFlowStepID">工作流步骤GID</param>
/// <param name="tempWorkFlowID">工作流GID</param>
/// <returns>值1表示更新成功 值-1-2表示更新异常 值-3表示工作流内存在未完成的审核记录,不能修改工作流审核人信息</returns>
private int UpdateWorkFlowStepAuditor(string tempAuditorID,string tempWorkFlowStepID,string tempWorkFlowID)
{
int iResult = 0;
WorkFlowStepDA workFlowStepDA = new WorkFlowStepDA();
if (!(tempWorkFlowID == ""))
{
iResult = workFlowStepDA.UpdateStepAuditor(tempWorkFlowID, tempWorkFlowStepID, tempAuditorID, strUserID);
}
else
{
}
return iResult;
}
#endregion
#region 获取工作流步骤信息
/// <summary>
/// 获取工作流步骤信息
/// </summary>
/// <param name="tempWorkFlowID">工作流GID</param>
/// <returns>获得工作流详细信息</returns>
public string GetWorkFlowSteps(string tempWorkFlowID)
{
WorkFlowDA workFlowDA = new WorkFlowDA();
DataTable sourceTable;
string strSql = String.Format("SELECT A.GID,A.STEPNO,A.NAME,A.DESCRIPTION,'查看条件',B.SHOWNAME as AUDITOR, CASE WHEN A.ISMUST = 1 THEN 1 ELSE 0 END as ISMUST, CASE WHEN A.ISLAST = 1 THEN 1 ELSE 0 END as ISLAST,"
+ " CASE WHEN A.ISPARALLEL = 1 THEN 1 ELSE 0 END as ISPARALLEL,CASE WHEN A.ISDEPARTMENT = 1 THEN 1 ELSE 0 END as ISDEPARTMENT,(SELECT DEPTNAME FROM sys_dept WHERE GID = A.DEPARTMENTID) as DEPTNAME, "
+ " C.SHOWNAME as CREATEUSER, A.CREATETIME "
+ " FROM workflow_step as A LEFT JOIN [user] as B ON A.AUDITOR = B.GID LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE A.WORKFLOWID = '{0}' ORDER BY A.STEPNO ASC ", tempWorkFlowID);
sourceTable = workFlowDA.GetDataSetBySql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取工作流workflow信息
/// <summary>
/// workflow工作流表信息
/// </summary>
/// <returns>返回json数据</returns>
public string GetWorkFlowList()
{
WorkFlowDA workFlowDA = new WorkFlowDA();
DataTable sourceTable;
string strSql = " SELECT A.GID, A.NAME,A.DESCRIPTION,C.DESCRIPTION,'查看' as STEP,B.SHOWNAME as CREATEUSER,A.CREATETIME,A.STATE,A.SORT,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END "
+ " FROM workflow as A LEFT JOIN [user] as B ON A.CREATEUSER = B.GID LEFT JOIN sys_module as C ON A.MODULEID = C.GID ORDER BY A.CREATETIME DESC ";
sourceTable = workFlowDA.GetDataSetBySql(strSql).Tables[0];
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取公司用户信息树
/// <summary>
/// 获取公司用户信息树
/// </summary>
/// <returns>返回JSON用户信息数据</returns>
public string GetUserTree()
{
StringBuilder userBuilder = new StringBuilder();
IList<CompanyEntity> companyEntities = new List<CompanyEntity>();
CompanyDA companyDA = new CompanyDA();
companyEntities = companyDA.GetAllCompany();
userBuilder.Append("{id:0");
if (companyEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int k = 0; k < companyEntities.Count; k++)
{
if (k == 0)
{
userBuilder.Append("{id:\"" + companyEntities[k].GID + "#comp\",");
}
else
{
userBuilder.Append(",{id:\"" + companyEntities[k].GID + "#comp\",");
}
userBuilder.Append("text:\"" + companyEntities[k].NAME + "\"");
IList<SysDeptEntity> sysDeptEntities = new List<SysDeptEntity>();
sysDeptEntities = new SysDeptDA().GetDepartmentByCompanyID(companyEntities[k].GID);
if (sysDeptEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int j = 0; j < sysDeptEntities.Count; j++)
{
userBuilder.Append("{id:\"" + sysDeptEntities[j].GID + "#dept\",");
userBuilder.Append("text:\"" + sysDeptEntities[j].DEPTNAME + "\"");
IList<UserEntity> userEntities = new List<UserEntity>();
userEntities = new UserDA().GetUserByCompanyAndDept(companyEntities[k].GID, sysDeptEntities[j].DEPTNAME);
if (userEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int i = 0; i < userEntities.Count; i++)
{
userBuilder.Append("{id:\"" + userEntities[i].Gid + "#user\",");
userBuilder.Append("text:\"" + userEntities[i].ShowName + "\"");
if (i == userEntities.Count - 1)
{
userBuilder.Append("}");
}
else
{
userBuilder.Append("},");
}
}
userBuilder.Append("]");
}
if (j == sysDeptEntities.Count - 1)
{
userBuilder.Append("}");
}
else
{
userBuilder.Append("},");
}
}
userBuilder.Append("]");
}
userBuilder.Append("}");
}
userBuilder.Append("]");
}
userBuilder.Append("}");
return userBuilder.ToString();
}
#endregion
#region 获取公司信息树
/// <summary>
/// 获取公司信息树
/// </summary>
/// <returns>返回JSON用户信息数据</returns>
public string GetCompanyTree()
{
StringBuilder userBuilder = new StringBuilder();
IList<CompanyEntity> companyEntities = new List<CompanyEntity>();
CompanyDA companyDA = new CompanyDA();
companyEntities = companyDA.GetAllCompany();
userBuilder.Append("{id:0");
if (companyEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int k = 0; k < companyEntities.Count; k++)
{
if (k == 0)
{
userBuilder.Append("{id:\"" + companyEntities[k].GID + "\",");
}
else
{
userBuilder.Append(",{id:\"" + companyEntities[k].GID + "\",");
}
userBuilder.Append("text:\"" + companyEntities[k].NAME + "\"");
userBuilder.Append("}");
}
userBuilder.Append("]");
}
userBuilder.Append("}");
return userBuilder.ToString();
}
#endregion
#region 获取分公司和部门信息
/// <summary>
/// 获取分公司和部门信息
/// </summary>
/// <returns>返回JSON Tree数据</returns>
private string GetDepartmentTree()
{
StringBuilder userBuilder = new StringBuilder();
IList<CompanyEntity> companyEntities = new List<CompanyEntity>();
CompanyDA companyDA = new CompanyDA();
companyEntities = companyDA.GetAllCompany();
userBuilder.Append("{id:0");
if (companyEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int k = 0; k < companyEntities.Count; k++)
{
if (k == 0)
{
userBuilder.Append("{id:\"" + companyEntities[k].GID + "#comp\",");
}
else
{
userBuilder.Append(",{id:\"" + companyEntities[k].GID + "#comp\",");
}
userBuilder.Append("text:\"" + companyEntities[k].NAME + "\"");
IList<SysDeptEntity> sysDeptEntities = new List<SysDeptEntity>();
sysDeptEntities = new SysDeptDA().GetDepartmentByCompanyID(companyEntities[k].GID);
if (sysDeptEntities.Count > 0)
{
userBuilder.Append(",item:[");
for (int j = 0; j < sysDeptEntities.Count; j++)
{
userBuilder.Append("{id:\"" + sysDeptEntities[j].GID + "#dept\",");
userBuilder.Append("text:\"" + sysDeptEntities[j].DEPTNAME + "\"");
if (j == sysDeptEntities.Count - 1)
{
userBuilder.Append("}");
}
else
{
userBuilder.Append("},");
}
}
userBuilder.Append("]");
}
userBuilder.Append("}");
}
userBuilder.Append("]");
}
userBuilder.Append("}");
return userBuilder.ToString();
}
#endregion
}
}