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
{
///
/// 加载页面
///
///
///
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, "按员工类别查询");
// 绑定表格
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)
{
BLL.Person_PersonsService.UpdatePassword(personId, BLL.Const.Password);
ShowNotify("密码已重置为原始密码!", MessageBoxIcon.Success);
}
else
{
ShowNotify("您没有权限!", MessageBoxIcon.Warning);
}
}
else if (commandName == "salary")
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonView.aspx?PersonId={0}", Grid1.SelectedRowID, "查看 - ")));
}
}
}
}
///
/// 绑定数据
///
private void BindGrid()
{
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, Grid1);
Grid1.RecordCount = Person_PersonsService.count;
Grid1.DataSource = getData;
Grid1.DataBind();
}
#region 查询
///
/// 查询
///
///
///
protected void btSearch_Click(object sender, EventArgs e)
{
this.BindGrid();
//if (this.PageSize.HasValue)
//{
// this.ddlPageSize.SelectedValue = this.PageSize.ToString();
//}
}
#endregion
#region 获取按钮权限
///
/// 获取按钮权限
///
///
///
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 删除数据
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
// this.PageSize = this.Grid1.PageIndex;
this.DeleteData();
}
///
/// 删除方法
///
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 分页
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
///
/// Grid行双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
///
/// 编辑数据方法
///
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 导入
///
/// 导入按钮
///
///
///
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("UserIn.aspx", "导入 - ")));
}
#endregion
#region 查看人员详细信息
///
/// 查看人员详细信息
///
///
///
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 导出按钮
/// 导出按钮
///
///
///
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();
}
///
/// 派遣
///
///
///
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 getDelte = new List();
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);
}
}
}
}