405 lines
16 KiB
C#
405 lines
16 KiB
C#
using BLL;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
|
||
namespace FineUIPro.Web.Person
|
||
{
|
||
public partial class DepartPerson : 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);
|
||
////权限按钮方法
|
||
this.GetButtonPower();
|
||
this.btnNew.OnClientClick = Window1.GetShowReference("PersonEdit.aspx?UnitId=" + Const.UnitId_SEDIN + "&DepartId=" + Const.Depart_constructionId) + "return false;";
|
||
ProjectService.InitProjectShortNameDropDownList(this.drpProject, false);
|
||
Funs.FineUIPleaseSelect(drpProject, "按项目查询");
|
||
DropListService.InitConstDropDownList(this.drpIsPost, DropListService.Group_IsPost, true);
|
||
this.drpIsPost.SelectedValue = Const._True;
|
||
DropListService.InitConstDropDownList(this.drpPersonType, DropListService.Group_PersonType, false);
|
||
Funs.FineUIPleaseSelect(drpPersonType, "按员工类别查询");
|
||
|
||
WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, false);
|
||
Funs.FineUIPleaseSelect(drpWorkPost, "按岗位查询");
|
||
// 绑定表格
|
||
this.BindGrid();
|
||
|
||
if (this.CurrUser.PersonId == Const.sysglyId || this.CurrUser.PersonId == Const.hfnbdId)
|
||
{
|
||
this.btnResetItem.Hidden = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
string arg = GetRequestEventArgument(); // 此函数所在文件:PageBase.cs
|
||
string[] args = arg.Split('$');
|
||
string personId = Grid1.SelectedRowID;
|
||
if (args.Length > 0 && !string.IsNullOrEmpty(personId))
|
||
{
|
||
var commandName = args[0];
|
||
if (commandName == "editit")
|
||
{
|
||
if (!this.btnMenuEdit.Hidden)
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonEdit.aspx?PersonId={0}&UnitId={1}&DepartId={2}", personId, Const.sedinId, Const.Depart_constructionId, "编辑 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("您没有权限!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
if (commandName == "dispatch")
|
||
{
|
||
if (!this.btnMenuEdit.Hidden)
|
||
{
|
||
////人员直接派遣时候
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectPersonEdit.aspx?PersonId={0}&Type=P", personId, "查看 - ")));
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("您没有权限!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else if (commandName == "details")
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonView.aspx?PersonId={0}", personId, "查看 - ")));
|
||
}
|
||
else if (commandName == "reset")
|
||
{
|
||
if (!this.btnMenuEdit.Hidden)
|
||
{
|
||
var getperson = Person_PersonsService.GetPerson_PersonsById(personId);
|
||
if (getperson != null)
|
||
{
|
||
BLL.Person_PersonsService.UpdatePassword(personId, Funs.getInitialPassword(getperson.UnitId, getperson.IdentityCard));
|
||
ShowNotify("密码已重置为原始密码!", MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("您没有权限!", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
else if (commandName == "salary")
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonView.aspx?PersonId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
string[] workPostIds= this.drpWorkPost.SelectedValueArray.Where(x => x != Const._Null).ToArray();
|
||
var getData = Person_PersonsService.getListData(Const.UnitId_SEDIN, Const.Depart_constructionId, this.drpProject.SelectedValue,
|
||
this.txtPersonName.Text.Trim(), this.txtIdCard.Text.Trim(), this.drpIsPost.SelectedValue, this.drpPersonType.SelectedValue, null, workPostIds, Grid1);
|
||
Grid1.RecordCount = Person_PersonsService.count;
|
||
Grid1.DataSource = getData;
|
||
Grid1.DataBind();
|
||
}
|
||
|
||
#region 查询
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btSearch_Click(object sender, EventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
//if (this.PageSize.HasValue)
|
||
//{
|
||
// this.ddlPageSize.SelectedValue = this.PageSize.ToString();
|
||
//}
|
||
}
|
||
#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.DepartPersonMenuId);
|
||
if (buttonList.Count() > 0)
|
||
{
|
||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||
{
|
||
this.btnNew.Hidden = false;
|
||
this.btnImport.Hidden = false;
|
||
}
|
||
if (buttonList.Contains(BLL.Const.BtnModify))
|
||
{
|
||
this.btnMenuEdit.Hidden = false;
|
||
this.btnMenuDispatch.Hidden = false;
|
||
}
|
||
if (buttonList.Contains(BLL.Const.BtnDelete))
|
||
{
|
||
this.btnMenuDelete.Hidden = false;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 删除数据
|
||
/// <summary>
|
||
/// 右键删除事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
||
{
|
||
// this.PageSize = this.Grid1.PageIndex;
|
||
this.DeleteData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除方法
|
||
/// </summary>
|
||
private void DeleteData()
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||
{
|
||
string strShowNotify = Person_PersonsService.DeletePersons(Grid1.SelectedRowIDArray, this.CurrUser);
|
||
BindGrid();
|
||
if (!string.IsNullOrEmpty(strShowNotify))
|
||
{
|
||
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
|
||
}
|
||
else
|
||
{
|
||
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#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>
|
||
/// 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()
|
||
{
|
||
//this.PageSize = this.Grid1.PageIndex;
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
if (this.btnMenuEdit.Hidden)
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonView.aspx?PersonId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
else
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonEdit.aspx?PersonId={0}&UnitId={1}&DepartId={2}", Grid1.SelectedRowID, Const.sedinId, Const.Depart_constructionId, "编辑 - ")));
|
||
}
|
||
}
|
||
|
||
#region 导入
|
||
/// <summary>
|
||
/// 导入按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnImport_Click(object sender, EventArgs e)
|
||
{
|
||
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("UserIn.aspx", "导入 - ")));
|
||
}
|
||
#endregion
|
||
|
||
#region 查看人员详细信息
|
||
/// <summary>
|
||
/// 查看人员详细信息
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnSee_Click(object sender, EventArgs e)
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInParent("请选择一条记录!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonView.aspx?PersonId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
#endregion
|
||
|
||
#region 导出按钮
|
||
/// 导出按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnOut_Click(object sender, EventArgs e)
|
||
{
|
||
Response.ClearContent();
|
||
string filename = Funs.GetNewFileName();
|
||
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("部门人员列表" + filename, System.Text.Encoding.UTF8) + ".xls");
|
||
Response.ContentType = "application/excel";
|
||
Response.ContentEncoding = Encoding.UTF8;
|
||
this.Grid1.PageSize = this.Grid1.RecordCount;
|
||
this.BindGrid();
|
||
Response.Write(GetGridTableHtml(Grid1));
|
||
Response.End();
|
||
}
|
||
#endregion
|
||
|
||
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 派遣
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDispatch_Click(object sender, EventArgs e)
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
var getPerson = Person_PersonsService.GetPerson_PersonsById(Grid1.SelectedRowID);
|
||
if (getPerson != null && getPerson.IsPost == true)
|
||
{
|
||
var getcuuProject = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == getPerson.IdentityCard && x.States == Const.ProjectPersonStates_1);
|
||
if (getcuuProject != null && (getPerson.MultiProject == false|| !getPerson.MultiProject.HasValue))
|
||
{
|
||
SitePerson_PersonService.SetSitePerson_PersonStates(getcuuProject.SitePersonId, Const.ProjectPersonStates_2, DateTime.Now);
|
||
}
|
||
////人员直接派遣时候
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectPersonEdit.aspx?PersonId={0}&Type=P", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent("请选择在岗人员派遣!", MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
protected void btnResetItem_Click(object sender, EventArgs e)
|
||
{
|
||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||
{
|
||
int count = 0;
|
||
var getSitePersons = db.SitePerson_PersonItem.Where(x=>x.IdentityCard != null).Select(x => x.IdentityCard).Distinct();
|
||
if (getSitePersons.Count() > 0)
|
||
{
|
||
foreach (var item in getSitePersons)
|
||
{
|
||
var getItems = db.SitePerson_PersonItem.Where(x => x.IdentityCard == item && x.OutTime.HasValue);
|
||
if (getItems.Count() > 0)
|
||
{
|
||
List<Model.SitePerson_PersonItem> getDelte = new List<Model.SitePerson_PersonItem>();
|
||
foreach (var ip in getItems)
|
||
{
|
||
var a = ip.InTime;
|
||
var b = ip.OutTime;
|
||
|
||
var getEx = getItems.FirstOrDefault(x => x.ProjectId == ip.ProjectId && x.PersonItemId != ip.PersonItemId && x.InTime <= ip.InTime && (x.OutTime > ip.OutTime || !x.OutTime.HasValue));
|
||
if (getEx != null)
|
||
{
|
||
count++;
|
||
getDelte.Add(ip);
|
||
}
|
||
}
|
||
if (getDelte.Count() > 0)
|
||
{
|
||
db.SitePerson_PersonItem.DeleteAllOnSubmit(getDelte);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
var getProjetItems = from x in getItems
|
||
join y in db.Base_Project on x.ProjectId equals y.ProjectId
|
||
where x.OutTime > y.EndDate
|
||
select x;
|
||
if (getProjetItems.Count() > 0)
|
||
{
|
||
foreach (var pitm in getProjetItems)
|
||
{
|
||
var getP = db.Base_Project.FirstOrDefault(x => x.ProjectId == pitm.ProjectId);
|
||
if (getP != null && getP.EndDate.HasValue)
|
||
{
|
||
pitm.OutTime = getP.EndDate;
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
Alert.ShowInParent("操作完成!共清理" + count.ToString() + "行。", MessageBoxIcon.Warning);
|
||
}
|
||
}
|
||
}
|
||
} |