SGGL_SHJ/SGGL/FineUIPro.Web/Person/DepartPersonShunt.aspx.cs

469 lines
19 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.Person
{
public partial class DepartPersonShunt : PageBase
{
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
BLL.ProjectService.InitProjectDropDownList(this.drpProject, false);
Funs.FineUIPleaseSelect(this.drpProject, "请选择拟聘项目");
////权限按钮方法
this.GetButtonPower();
WorkPostService.InitWorkPostNameByTypeDropDownList2(this.drpWorkPost, "1", false); //加载管理岗位
Funs.FineUIPleaseSelect(this.drpWorkPost, "请选择岗位");
WorkPostService.InitWorkPostNameByTypeDropDownList(this.drpWP, "1", true); //加载管理岗位
PostTitleService.InitPostTitleDropDownList(this.drpPostTitle, false);
Funs.FineUIPleaseSelect(this.drpPostTitle, "请选择职称");
PracticeCertificateService.InitPracticeCertificateDropDownList(this.drpCertificate, false);
Funs.FineUIPleaseSelect(this.drpCertificate, "请选择职业资格证书");
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
this.BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
var getData = Person_ShuntService.getListData(this.drpWorkPost.SelectedValue,this.drpPostTitle.SelectedValue,String.Empty,this.drpCertificate.SelectedValue, Grid1);
Grid1.RecordCount = Person_ShuntService.count;
Grid1.DataSource = getData;
Grid1.DataBind();
}
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.DepartPersonShuntMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSure.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
string strShowNotify = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.Person_ShuntDetailService.DeleteShuntDetailByShuntId(rowID);
BLL.Person_ShuntApproveService.DeleteShuntApprovesByShuntId(rowID);
BLL.Person_ShuntService.DeleteShunt(rowID);
}
BindGrid();
if (!string.IsNullOrEmpty(strShowNotify))
{
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
}
else
{
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
}
#endregion
/// <summary>
/// 关闭弹出窗
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
/// <summary>
/// 确定按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSure_Click(object sender, EventArgs e)
{
if (this.drpProject.SelectedValue != BLL.Const._Null)
{
bool b = true;
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
if (this.Grid1.SelectedRowIndexArray.Contains(i))
{
AspNet.CheckBox cb = (AspNet.CheckBox)(this.Grid1.Rows[i].FindControl("cbSelect"));
if (cb.Checked) //选择项
{
string workPost = values.Value<string>("WorkPost");
if (string.IsNullOrEmpty(workPost))
{
b = false;
}
}
}
}
if (!b)
{
Alert.ShowInTop("勾选人员的拟聘岗位不能为空!", MessageBoxIcon.Warning);
return;
}
Model.Person_Shunt shunt = new Model.Person_Shunt();
shunt.Code = BLL.SQLHelper.RunProcNewId("SpGetNewCode3", "dbo.Person_Shunt", "Code", string.Empty);
shunt.ProjectId = this.drpProject.SelectedValue;
shunt.State = BLL.Const.Shunt_Complete;
shunt.CompileDate = DateTime.Now;
shunt.CompileMan = this.CurrUser.PersonId;
shunt.ShuntId = SQLHelper.GetNewID();
BLL.Person_ShuntService.AddShunt(shunt);
var workPosts = BLL.WorkPostService.GetWorkPostList();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
AspNet.CheckBox cb = (AspNet.CheckBox)(this.Grid1.Rows[i].FindControl("cbSelect"));
if (cb.Checked) //选择项
{
Model.Person_ShuntDetail detail = new Model.Person_ShuntDetail();
detail.ShuntDetailId = SQLHelper.GetNewID(typeof(Model.Person_ShuntDetail));
detail.ShuntId = shunt.ShuntId;
detail.UserId = this.Grid1.Rows[i].RowID;
string workPost = values.Value<string>("WorkPost");
var w = workPosts.FirstOrDefault(x => x.WorkPostName == workPost);
if (w != null)
{
detail.WorkPostId = w.WorkPostId;
}
detail.SortIndex = i;
BLL.Person_ShuntDetailService.AddShuntDetail(detail);
/////todo 修改人员注释掉的 后续优化
//var currProjectUser = BLL.ProjectUserService.GetCurrProjectUserByUserId(detail.UserId);
//if (currProjectUser != null)
//{
// currProjectUser.IsPost = false;
// BLL.ProjectUserService.UpdateProjectUser(currProjectUser);
//}
//var projectUser = BLL.ProjectUserService.GetProjectUserByUserIdProjectId(shunt.ProjectId, detail.UserId);
//if (projectUser == null)
//{
// var user = BLL.Person_PersonsService.GetPerson_PersonsById(detail.UserId);
// if (user != null)
// {
// user.ProjectId = this.drpProject.SelectedValue;
// user.ProjectWorkPostId = detail.WorkPostId;
// BLL.Person_PersonsService.UpdateUser(user);
// Model.Project_ProjectUser newProjectUser = new Model.Project_ProjectUser
// {
// ProjectId = shunt.ProjectId,
// UserId = detail.UserId,
// UnitId = user.UnitId,
// RoleId = user.RoleIds,
// IsPost = true
// };
// BLL.ProjectUserService.AddProjectUser(newProjectUser);
// Model.Sys_RoleItem roleItem = new Model.Sys_RoleItem();
// roleItem.ProjectId = shunt.ProjectId;
// roleItem.UserId = detail.UserId;
// roleItem.RoleId = user.RoleId;
// roleItem.IntoDate = DateTime.Now;
// BLL.RoleItemService.AddRoleItem(roleItem);
// if (!string.IsNullOrEmpty(user.IdentityCard))
// {
// /////当前用户是否已经添加到项目现场人员中
// //var sitePerson = BLL.Person_PersonsService.GetPerson_PersonsByIdentityCard(shunt.ProjectId, user.IdentityCard);
// //if (sitePerson == null)
// //{
// // Model.SitePerson_Person newPerson = new Model.SitePerson_Person
// // {
// // PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person)),
// // PersonName = user.PersonName,
// // IdentityCard = user.IdentityCard,
// // ProjectId = shunt.ProjectId,
// // UnitId = user.UnitId,
// // WorkPostId = detail.WorkPostId,
// // };
// // BLL.PersonService.AddPerson(newPerson);
// //}
// }
// }
//}
}
}
ShowNotify("拟聘成功!", MessageBoxIcon.Success);
BindGrid();
BLL.LogService.AddSys_Log(this.CurrUser, shunt.Code, shunt.ShuntId, BLL.Const.DepartPersonShuntMenuId, "编辑分流管理");
}
else
{
Alert.ShowInParent("请选择拟聘项目!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 确定按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnView_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ShuntList.aspx", "编辑 - ")));
}
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var shunt = BLL.Person_ShuntService.GetShunt(Id);
if (shunt != null)
{
if (shunt.State.Equals(Const.Shunt_Complete))
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
Model.Person_ShuntApprove approve = BLL.Person_ShuntApproveService.GetShuntApproveByShuntId(Id);
if (approve != null)
{
if (!string.IsNullOrEmpty(approve.ApproveMan))
{
if (this.CurrUser.PersonId == approve.ApproveMan || CurrUser.PersonId == Const.sysglyId)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DepartPersonShuntEdit.aspx?ShuntId={0}", Id, "编辑 - ")));
return;
}
else if (shunt.State == BLL.Const.Shunt_Complete)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DepartPersonShuntView.aspx?ShuntId={0}", Id, "查看 - ")));
return;
}
else
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
//if (this.btnMenuModify.Hidden || checks.State == BLL.Const.State_2) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
//{
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckListView.aspx?CheckControlCode={0}", codes, "查看 - ")));
// return;
//}
//else
//{
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("CheckListEdit.aspx?CheckControlCode={0}", codes, "编辑 - ")));
// return;
//}
}
else
{
Alert.ShowInTop("您不是当前办理人,无法编辑,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
protected void btnMenuView_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DepartPersonShuntView.aspx?ShuntId={0}", Id, "查看 - ")));
}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private string judgementDelete(string id)
{
string content = string.Empty;
if (Funs.DB.SitePerson_Person.FirstOrDefault(x => x.PersonId == id) != null)
{
content += "已在【项目员工】中使用,不能删除!";
}
return content;
}
#endregion
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
protected void ckbAll_CheckedChanged(object sender, CheckedEventArgs e)
{
BindGrid();
}
/// <summary>
/// 把状态转换代号为文字形式
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
protected string ConvertState(object state)
{
if (state != null)
{
if (state.ToString() == BLL.Const.Shunt_ReCompile)
{
return "重新编制";
}
else if (state.ToString() == BLL.Const.Shunt_Compile)
{
return "编制";
}
else if (state.ToString() == BLL.Const.Shunt_Audit)
{
return "审核";
}
else if (state.ToString() == BLL.Const.Shunt_Complete)
{
return "审批完成";
}
else
{
return "";
}
}
return "";
}
}
}