xinjiang/SGGL/FineUIPro.Web/HSSE/SitePerson/PersonInfoClock.aspx.cs

164 lines
7.2 KiB
C#

using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.HSSE.SitePerson
{
public partial class PersonInfoClock : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btnClose.OnClientClick = ActiveWindow.GetHideReference();
}
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if ((this.ckIn.Checked && !string.IsNullOrEmpty(this.txtInTime.Text)) || (this.ckOut.Checked && !string.IsNullOrEmpty(this.txtOutTime.Text)))
{
var getPersons = from x in Funs.DB.SitePerson_Person
join y in Funs.DB.Project_ProjectUnit on new{ x.ProjectId,x.UnitId} equals new { y.ProjectId,y.UnitId}
where x.ProjectId == this.CurrUser.LoginProjectId && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)
&& x.IsCardNoOK == true && x.InTime <= DateTime.Now && x.HeadImage != null
&& y.IsSynchro == true && x.RealNameAddTime.HasValue
select x;
if (getPersons.Count() > 0)
{
List<SitePerson_PersonInOut> list = new List<SitePerson_PersonInOut>();
foreach (var item in getPersons)
{
if (this.ckIn.Checked)
{
Model.SitePerson_PersonInOut newPersonInfo = new Model.SitePerson_PersonInOut
{
PersonInOutId = SQLHelper.GetNewID(),
PersonId = item.PersonId,
ProjectId = item.ProjectId,
WorkAreaId = item.WorkAreaId,
InOutWay = Const.InOutWay_2,
};
newPersonInfo.ProjectId = item.ProjectId;
newPersonInfo.PersonId = item.PersonId;
newPersonInfo.PersonName = item.PersonName;
newPersonInfo.IdentityCard = item.IdentityCard;
newPersonInfo.UnitId = item.UnitId;
newPersonInfo.UnitName = UnitService.GetUnitNameByUnitId(item.UnitId);
newPersonInfo.WorkPostId = item.WorkPostId;
if (!string.IsNullOrEmpty(item.WorkPostId))
{
var getWorkPost = WorkPostService.GetWorkPostById(item.WorkPostId);
if (getWorkPost != null)
{
newPersonInfo.WorkPostName = getWorkPost.WorkPostName;
newPersonInfo.PostType = getWorkPost.PostType;
}
}
if (string.IsNullOrEmpty(newPersonInfo.WorkAreaName) && !string.IsNullOrEmpty(newPersonInfo.WorkAreaId))
{
newPersonInfo.WorkAreaName = UnitWorkService.GetUnitWorkName(newPersonInfo.WorkAreaId);
}
newPersonInfo.IsIn = true;
newPersonInfo.ChangeTime = Funs.GetNewDateTimeOrNow(this.txtInTime.Text);
list.Add(newPersonInfo);
}
if (this.ckOut.Checked)
{
Model.SitePerson_PersonInOut newPersonInfo = new Model.SitePerson_PersonInOut
{
PersonInOutId = SQLHelper.GetNewID(),
PersonId = item.PersonId,
ProjectId = item.ProjectId,
WorkAreaId = item.WorkAreaId,
InOutWay = Const.InOutWay_2,
};
newPersonInfo.ProjectId = item.ProjectId;
newPersonInfo.PersonId = item.PersonId;
newPersonInfo.PersonName = item.PersonName;
newPersonInfo.IdentityCard = item.IdentityCard;
newPersonInfo.UnitId = item.UnitId;
newPersonInfo.UnitName = UnitService.GetUnitNameByUnitId(item.UnitId);
newPersonInfo.WorkPostId = item.WorkPostId;
if (!string.IsNullOrEmpty(item.WorkPostId))
{
var getWorkPost = WorkPostService.GetWorkPostById(item.WorkPostId);
if (getWorkPost != null)
{
newPersonInfo.WorkPostName = getWorkPost.WorkPostName;
newPersonInfo.PostType = getWorkPost.PostType;
}
}
if (string.IsNullOrEmpty(newPersonInfo.WorkAreaName) && !string.IsNullOrEmpty(newPersonInfo.WorkAreaId))
{
newPersonInfo.WorkAreaName = UnitWorkService.GetUnitWorkName(newPersonInfo.WorkAreaId);
}
newPersonInfo.IsIn = false;
newPersonInfo.ChangeTime = Funs.GetNewDateTimeOrNow(this.txtOutTime.Text);
list.Add(newPersonInfo);
}
}
BLL.PersonInOutService.AddPersonInOut(list);
}
else
{
Alert.ShowInParent("当前项目没有身份证合法的在岗人员!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInParent("请选择进场或出场!", MessageBoxIcon.Warning);
return;
}
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
protected void ck_CheckedChanged(object sender, CheckedEventArgs e)
{
this.txtInTime.Text = string.Empty;
if (this.ckIn.Checked)
{
this.txtInTime.Text = string.Format("{0:yyyy-MM-dd HH:mm}", System.DateTime.Now);
}
this.txtOutTime.Text = string.Empty;
if (this.ckOut.Checked)
{
this.txtOutTime.Text = string.Format("{0:yyyy-MM-dd HH:mm}", System.DateTime.Now);
}
}
}
}