ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/Controls/AuditFlowControl.ascx.cs

309 lines
9.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.Controls
{
public partial class AuditFlowControl : System.Web.UI.UserControl
{
/// <summary>
/// 菜单ID
/// </summary>
public string MenuId
{
get;
set;
}
/// <summary>
/// 办理步骤
/// </summary>
public int Step
{
get;
set;
}
/// <summary>
/// 我的意见
/// </summary>
public string Opinions
{
get
{
return txtOpinions.Text.Trim();
}
}
/// <summary>
/// 下一步骤
/// </summary>
public int? NextStep
{
get
{
if (drpType.SelectedValue != null)
{
return Convert.ToInt32(drpType.SelectedValue.Trim());
}
else
{
return null;
}
}
}
/// <summary>
/// 办理人员
/// </summary>
public string HandleUser
{
get
{
return drpPerson.SelectedValue;
}
}
/// <summary>
/// 是否同意
/// </summary>
public bool IsAgree
{
get
{
return Convert.ToBoolean(rblIsAgree.SelectedValue);
}
}
#region
/// <summary>
///
/// </summary>
public string FlowModule
{
get
{
return (string)ViewState["FlowModule"];
}
set
{
ViewState["FlowModule"] = value;
}
}
public int AudiFlowStep
{
get
{
return (int)ViewState["AudiFlowStep"];
}
set
{
ViewState["AudiFlowStep"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FlowModule = this.MenuId;
AudiFlowStep = Step;
// 第一个步骤如编制隐藏意见
if (BLL.AudiFlowService.GetFristAuditFlowStep(FlowModule).AudiFlowStep == AudiFlowStep)
{
this.txtOpinions.Hidden = true;
this.rblIsAgree.Hidden = true;
}
else
{
this.txtOpinions.Hidden = false;
this.rblIsAgree.Hidden = false;
}
// 绑定办理步骤,设置默认办理步骤
this.drpType.Items.Clear();
this.drpType.DataTextField = "AuditFlowName";
this.drpType.DataValueField = "AudiFlowStep";
if (BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule).AudiFlowStep != this.AudiFlowStep)
{
this.drpType.DataSource = BLL.AudiFlowService.GetNextAuditFlowStep(this.FlowModule, this.AudiFlowStep);
}
else
{
this.drpType.DataSource = BLL.AudiFlowService.GetEndAuditFlowStepList(FlowModule);
this.drpPerson.Hidden = true;
}
this.drpType.DataBind();
drpType.SelectedIndex = 0;
// 绑定办理人和设置标题
var q = BLL.AudiFlowService.GetAuditFlow(this.FlowModule, Convert.ToInt32(this.drpType.SelectedValue));
if (q != null)
{
BindAuditUser(q.RoleId??"");
GetPanlTitle(ConvertRole(q.RoleId));
}
// 加载结束步骤,隐藏办理人
if (this.AudiFlowStep == BLL.AudiFlowService.GetPreStepOfEndStep(FlowModule))
{
this.drpPerson.Items.Clear();
this.drpPerson.Hidden = true;
}
}
}
protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.drpType.SelectedValue == BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule).AudiFlowStep.ToString())
{
this.drpPerson.Items.Clear();
this.drpPerson.Hidden = true;
}
else
{
this.drpPerson.Items.Clear();
this.drpPerson.Hidden = false;
var q = BLL.AudiFlowService.GetAuditFlow(this.FlowModule, Convert.ToInt32(this.drpType.SelectedValue));
if (q != null)
{
BindAuditUser(q.RoleId??"");
GetPanlTitle(ConvertRole(q.RoleId));
}
}
}
protected void rblIsAgree_SelectedIndexChanged(object sender, EventArgs e)
{
if (BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule) != null)
{
this.drpType.Items.Clear();
this.drpType.DataTextField = "AuditFlowName";
this.drpType.DataValueField = "AudiFlowStep";
if (this.rblIsAgree.SelectedValue == "True")
{
if (BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule).AudiFlowStep != this.AudiFlowStep)
{
this.drpType.DataSource = BLL.AudiFlowService.GetNextAuditFlowStep(this.FlowModule, this.AudiFlowStep);
}
else
{
this.drpType.DataSource = BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule);
}
this.drpType.DataBind();
}
else
{
this.drpPerson.Hidden = false;
this.drpType.DataSource = BLL.AudiFlowService.GetAudiFlowsByFlowModuleAndAudiFlowId(this.FlowModule, null);
this.drpType.DataBind();
Funs.FineUIReCompileSelect(this.drpType);
}
// 默认选第一项
drpType.SelectedIndex = 0;
if (this.drpType.SelectedValue == BLL.AudiFlowService.GetEndAuditFlowStep(FlowModule).AudiFlowStep.ToString()) //最后一步完成时隐藏办理人
{
this.drpPerson.Hidden = true;
}
Model.AudiFlow flow = null;
if (this.drpType.SelectedValue != "0")
{
flow = BLL.AudiFlowService.GetAuditFlow(this.FlowModule, Convert.ToInt32(this.drpType.SelectedValue));
}
else
{
// "0"为重新编制,重新编制办理人员为编制人
flow = BLL.AudiFlowService.GetFristAuditFlowStep(this.FlowModule);
}
if (flow != null)
{
BindAuditUser(flow.RoleId??"");
GetPanlTitle(ConvertRole(flow.RoleId));
}
}
else
{
Alert.ShowInTop("请设置流程的结束步骤!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 绑定审批用户
/// </summary>
/// <param name="roleIds"></param>
private void BindAuditUser(string roleIds)
{
string strSql = @"select pu.UserId,u.UserName from dbo.Project_User pu
left join dbo.Sys_User u on u.UserId=pu.UserId
left join dbo.Sys_Role r on pu.RoleId=r.RoleId
where pu.IsPost=1 and ProjectId=@ProjectId
and CHARINDEX(','+RTRIM(pu.RoleId)+',',','+@RoleIds+',')>0 ";
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@ProjectId",((Model.Sys_User)Session["CurrUser"]).LoginProjectId),
new SqlParameter("@RoleIds",roleIds)
};
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
this.drpPerson.DataSource = tb;
this.drpPerson.DataTextField = "UserName";
this.drpPerson.DataValueField = "UserId";
drpPerson.DataBind();
if (drpPerson.Items.Count > 0)
{
drpPerson.SelectedIndex = 0;
}
}
/// <summary>
/// 设置面板标题
/// </summary>
/// <param name="title"></param>
private void GetPanlTitle(string title)
{
Panel5.Title = "下一步流程设置(审批角色:" + title + ")";
}
/// <summary>
/// 得到角色名称字符串
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertRole(string roleIds)
{
string roleName = string.Empty;
if (roleIds != null)
{
string[] roles = roleIds.ToString().Split(',');
foreach (string roleId in roles)
{
var q = BLL.Sys_RoleService.GetRole(roleId);
if (q != null)
{
roleName += q.RoleName + ",";
}
}
if (roleName != string.Empty)
{
roleName = roleName.Substring(0, roleName.Length - 1); ;
}
}
return roleName;
}
}
}