321 lines
13 KiB
C#
321 lines
13 KiB
C#
using BLL;
|
||
using FineUIPro.Web.HSSE.License;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
|
||
namespace FineUIPro.Web.ProjectData
|
||
{
|
||
public partial class PreProjectApply : PageBase
|
||
{
|
||
/// <summary>
|
||
/// 主键
|
||
/// </summary>
|
||
public string Id
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["Id"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["Id"] = value;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 项目名称
|
||
/// </summary>
|
||
public string ProjectName
|
||
{
|
||
get
|
||
{
|
||
return (string)ViewState["ProjectName"];
|
||
}
|
||
set
|
||
{
|
||
ViewState["ProjectName"] = value;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载页面
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
||
UnitService.InitBranchUnitDropDownList(this.drpUnit, true, true);
|
||
BindGrid();
|
||
var now = DateTime.Now;
|
||
this.Id = Request.QueryString["Id"];
|
||
this.ProjectName = Request.QueryString["ProjectName"];
|
||
if (!string.IsNullOrEmpty(this.Id))
|
||
{
|
||
var model = BLL.PreProjectApplyService.GetPreProjectApplyById(this.Id);
|
||
if (model != null)
|
||
{
|
||
//申请信息
|
||
this.drpUnit.SelectedValue = model.UnitId;
|
||
this.txtProjectName.Text = model.ProjectName.ToString();
|
||
//this.rblApplyType.SelectedValue = model.ApplyType.ToString();
|
||
this.txtApplyDescription.Text = model.ApplyDescription.ToString();
|
||
this.txtApplyUserName.Text = model.ApplyUserName.ToString();
|
||
this.txtApplyDate.Text = string.Format("{0:yyyy-MM-dd}", model.ApplyDate);
|
||
|
||
//审批信息
|
||
this.drpApprover.Value = model.ApproverUserId;
|
||
this.drpApprover.Text = model.ApproverUserName;
|
||
if (model.ApprovalDate != null)
|
||
{
|
||
this.txtApprovalDate.Text = string.Format("{0:yyyy-MM-dd}", model.ApprovalDate);
|
||
}
|
||
if (model.State == 0)
|
||
{//待审核
|
||
this.drpUnit.Readonly = true;
|
||
this.txtProjectName.Readonly = true;
|
||
this.txtApplyDescription.Readonly = true;
|
||
this.txtApplyDate.Readonly = true;
|
||
this.drpApprover.Readonly = true;
|
||
this.txtApplyDate.Readonly = true;
|
||
bool isAuditer = model.ApproverUserId == this.CurrUser.UserId || this.CurrUser.UserId == Const.hfnbdId || this.CurrUser.UserId == Const.sysglyId;
|
||
if (isAuditer)
|
||
{
|
||
this.btnApproval.Hidden = false;
|
||
this.btnSave.Hidden = true;
|
||
this.Audit.Hidden = false;
|
||
this.AuditDesc.Hidden = false;
|
||
this.rblState.SelectedValue = "1";
|
||
this.txtApprovalDate.Text = string.Format("{0:yyyy-MM-dd}", now);
|
||
}
|
||
else
|
||
{
|
||
this.btnApproval.Hidden = true;
|
||
this.btnSave.Hidden = false;
|
||
this.Audit.Hidden = true;
|
||
this.AuditDesc.Hidden = true;
|
||
this.Toolbar1.Hidden = true;
|
||
}
|
||
}
|
||
else
|
||
{ //已审核
|
||
this.Audit.Hidden = false;
|
||
this.AuditDesc.Hidden = false;
|
||
this.Toolbar1.Hidden = true;
|
||
this.rblState.SelectedValue = model.State.ToString();
|
||
this.txtApprovalDescription.Text = model.ApprovalDescription.ToString();
|
||
}
|
||
|
||
//if (!string.IsNullOrWhiteSpace(model.ApproverUserId))
|
||
//{
|
||
// //this.cbNext.SelectedValue = "1";
|
||
|
||
// bool isAuditer = model.ApproverUserId == this.CurrUser.UserId || this.CurrUser.UserId == Const.hfnbdId || this.CurrUser.UserId == Const.sysglyId;
|
||
// if (model.State == 0)
|
||
// {
|
||
// if (isAuditer)
|
||
// {
|
||
// this.Audit.Hidden = false;
|
||
// this.rblState.SelectedValue = "1";
|
||
// }
|
||
// else
|
||
// {
|
||
// this.Toolbar1.Hidden = true;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// this.Toolbar1.Hidden = true;
|
||
// }
|
||
//}
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.btnApproval.Hidden = true;
|
||
this.txtApprovalDate.Hidden = true;
|
||
if (!string.IsNullOrWhiteSpace(ProjectName.Trim()))
|
||
{
|
||
this.txtProjectName.Text = ProjectName.Trim();
|
||
}
|
||
this.txtApplyUserName.Text = this.CurrUser.UserName;
|
||
this.txtApplyDate.Text = string.Format("{0:yyyy-MM-dd}", now);
|
||
//this.txtApprovalDate.Text = string.Format("{0:yyyy-MM-dd}", now);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#region 人员下拉框绑定数据
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
string unitId = CommonService.GetThisUnitId();
|
||
string strSql = @"SELECT UserId,UserName,UserCode,role.RoleName"
|
||
+ @" FROM Sys_User AS users LEFT JOIN Sys_Role AS role ON users.RoleId= role.RoleId"
|
||
+ @" WHERE users.IsPost=1 AND role.IsAuditFlow=1 AND users.IsOffice =1 AND UnitId ='" + unitId + "'";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
|
||
{
|
||
strSql += " AND (UserName LIKE @Name OR UserCode LIKE @Name OR role.RoleName LIKE @Name)";
|
||
listStr.Add(new SqlParameter("@Name", "%" + this.txtUserName.Text.Trim() + "%"));
|
||
}
|
||
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
Grid1.RecordCount = tb.Rows.Count;
|
||
var table = this.GetPagedDataTable(Grid1, tb);
|
||
Grid1.DataSource = table;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
#region 查询
|
||
/// <summary>
|
||
/// 下拉框查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void TextBox_TextChanged(object sender, EventArgs e)
|
||
{
|
||
this.drpApprover.Values = null;
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 保存数据
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSave_Click(object sender, EventArgs e)
|
||
{
|
||
string unitId = this.drpUnit.SelectedValue;
|
||
string unitName = this.drpUnit.SelectedText;
|
||
string projectName = Regex.Replace(this.txtProjectName.Text, @"\s", "");
|
||
//string projectName = this.txtProjectName.Text.Trim();
|
||
//string applyType = this.rblApplyType.SelectedValue;
|
||
string applyType = "预立项";
|
||
string applyDescription = this.txtApplyDescription.Text.Trim();
|
||
string approverUserId = this.drpApprover.Value;
|
||
string approverUserName = this.drpApprover.Text;
|
||
if (string.IsNullOrWhiteSpace(unitId) || unitId == BLL.Const._Null)
|
||
{
|
||
Alert.ShowInTop("请选择所属单位!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (string.IsNullOrWhiteSpace(projectName))
|
||
{
|
||
Alert.ShowInTop("请输入项目名称!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (string.IsNullOrWhiteSpace(applyDescription))
|
||
{
|
||
Alert.ShowInTop("请输入申请说明!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (string.IsNullOrWhiteSpace(approverUserId))
|
||
{
|
||
Alert.ShowInTop("请选择审批人!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
var project = ProjectService.GetProjectByProjectName(projectName);
|
||
if (project != null)
|
||
{
|
||
Alert.ShowInTop($"系统中已存在同名项目,{project.ProjectName}({project.ProjectCode}),无需申请!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
var applyPro = PreProjectApplyService.GetPreProjectApplyByProjectName(projectName);
|
||
if (applyPro != null)
|
||
{
|
||
string auditStr = applyPro.State == 1 ? $"审核已通过,可以直接新增同名项目" : applyPro.State == 2 ? $"不通过[{applyPro.ApprovalDescription}]" : "待审核";
|
||
Alert.ShowInTop($"{projectName},{applyPro.ApplyUserName}于{applyPro.ApplyDate.ToString("yyyy-MM-dd")}已申请过。{auditStr};审核人:{applyPro.ApproverUserName}!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
DataGovernance_PreProjectApply apply = new DataGovernance_PreProjectApply();
|
||
apply.Id = SQLHelper.GetNewID(typeof(Model.DataGovernance_PreProjectApply));
|
||
apply.UnitId = unitId;
|
||
apply.UnitName = unitName;
|
||
apply.ProjectName = projectName;
|
||
apply.ApplyType = applyType;
|
||
apply.ApplyDescription = applyDescription;
|
||
apply.ApplyUserId = this.CurrUser.UserId;
|
||
apply.ApplyUserName = this.CurrUser.UserName;
|
||
apply.ApplyDate = DateTime.Now;
|
||
apply.State = 0;//申请状态(0:待审核,1:通过,2:不通过)
|
||
apply.ApproverUserId = approverUserId;
|
||
apply.ApproverUserName = approverUserName;
|
||
PreProjectApplyService.AddPreProjectApply(apply);
|
||
|
||
ShowNotify("申请成功!", MessageBoxIcon.Success);
|
||
// 2. 关闭本窗体,然后回发父窗体
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 不通过必填审核说明
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void rblState_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
string state = this.rblState.SelectedValue;
|
||
if (state == "2" )
|
||
{
|
||
this.txtApprovalDescription.Required = true;
|
||
this.txtApprovalDescription.ShowRedStar = true;
|
||
}
|
||
else
|
||
{
|
||
this.txtApprovalDescription.Required = false;
|
||
this.txtApprovalDescription.ShowRedStar = false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 审批
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnApproval_Click(object sender, EventArgs e)
|
||
{
|
||
string state = this.rblState.SelectedValue;
|
||
string approvalDescription = this.txtApprovalDescription.Text.Trim();
|
||
if (string.IsNullOrWhiteSpace(state))
|
||
{
|
||
Alert.ShowInTop("请选择审核结果!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(this.Id))
|
||
{
|
||
DataGovernance_PreProjectApply apply = new DataGovernance_PreProjectApply();
|
||
apply.Id = this.Id;
|
||
apply.State = int.Parse(state);
|
||
apply.ApprovalDescription = approvalDescription;
|
||
apply.ApproverUserId = this.CurrUser.UserId;
|
||
apply.ApproverUserName = this.CurrUser.UserName;
|
||
apply.ApprovalDate = DateTime.Now;
|
||
PreProjectApplyService.ApprovalPreProjectApply(apply);
|
||
}
|
||
|
||
ShowNotify("审核成功!", MessageBoxIcon.Success);
|
||
// 2. 关闭本窗体,然后回发父窗体
|
||
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
||
}
|
||
}
|
||
} |