SGGL_JT/SUBQHSE/FineUIPro.Web/CQMS/Comprehensive/CqmsPersonEdit.aspx.cs

632 lines
24 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using System;
using System.Linq;
namespace FineUIPro.Web.CQMS.Comprehensive
{
public partial class CqmsPersonEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string PersonId
{
get { return (string)ViewState["PersonId"]; }
set { ViewState["PersonId"] = value; }
}
/// <summary>
/// 项目ID
/// </summary>
public string ProjectId
{
get { return (string)ViewState["ProjectId"]; }
set { ViewState["ProjectId"] = value; }
}
#endregion
#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();
////权限按钮方法
if (Request.Params["type"] != "-1")
{
this.GetButtonPower();
}
if (!string.IsNullOrEmpty(Request.Params["Company"]))
{
this.btnSave.Hidden = true;
}
this.ProjectId = Request.Params["ProjectId"];
this.PersonId = Request.Params["PersonId"];
this.InitDropDownList();
this.drpIdcardType.SelectedValue = "SHENFEN_ZHENGJIAN";
if (!string.IsNullOrEmpty(this.PersonId))
{
var person = BLL.PersonService.GetPersonById(this.PersonId);
if (person != null)
{
this.ProjectId = person.ProjectId;
if (!string.IsNullOrEmpty(person.Sex))
{
this.rblSex.SelectedValue = person.Sex;
}
if (!string.IsNullOrEmpty(person.UnitId))
{
var unit = BLL.UnitService.GetUnitByUnitId(person.UnitId);
if (unit != null)
{
this.drpUnitId.SelectedValue = unit.UnitId;
drpUnitId_OnSelectedIndexChanged(null, null);
}
}
if (!string.IsNullOrEmpty(person.WorkAreaId))
{
txtWorkArea.Values = person.WorkAreaId.Split(',');
}
if (!string.IsNullOrEmpty(person.WorkPostId))
{
this.drpPost.SelectedValue = person.WorkPostId;
}
if (!string.IsNullOrEmpty(person.TeamGroupId))
{
this.drpTeamGroup.SelectedValue = person.TeamGroupId;
}
if (!string.IsNullOrEmpty(person.MainCNProfessionalId))
{
this.drpMainCNProfessional.SelectedValue = person.MainCNProfessionalId;
}
this.rblIsUsed.SelectedValue = person.IsUsed ? "True" : "False";
this.txtCardNo.Text = person.CardNo;
this.txtPersonName.Text = person.PersonName;
this.txtIdentityCard.Text = person.IdentityCard;
this.txtTelephone.Text = person.Telephone;
if (person.InTime.HasValue)
{
this.txtInTime.Text = string.Format("{0:yyyy-MM-dd}", person.InTime);
}
if (person.OutTime.HasValue)
{
this.txtOutTime.Text = string.Format("{0:yyyy-MM-dd}", person.OutTime);
}
if (person.Birthday.HasValue)
{
this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", person.Birthday);
}
if (!string.IsNullOrEmpty(person.PhotoUrl))
{
imgPhoto.ImageUrl = ("~/" + person.PhotoUrl);
}
if (!string.IsNullOrEmpty(person.IdcardType))
{
this.drpIdcardType.SelectedValue = person.IdcardType;
}
this.rblIsTrain.SelectedValue = person.IsTrain.HasValue && person.IsTrain == true ? "true" : "false";
}
}
else
{
this.txtInTime.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
this.rblIsUsed.SelectedValue = "True";
}
}
}
#endregion
/// <summary>
/// 初始化下拉框
/// </summary>
private void InitDropDownList()
{
gvWorkArea.DataSource = BLL.UnitWorkService.GetUnitWorkLists(this.ProjectId);
gvWorkArea.DataBind();//单位工程
var postList = Funs.DB.Base_WorkPost.Where(x => x.IsCQMSCheck == true).OrderBy(x => x.WorkPostCode).ToList();
drpPost.DataValueField = "WorkPostId";
drpPost.DataTextField = "WorkPostName";
drpPost.DataSource = postList;
drpPost.DataBind();
Funs.FineUIPleaseSelect(drpPost);
CNProfessionalService.InitCNProfessionalDownList(this.drpMainCNProfessional, true);
BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true);
BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpIdcardType, "ZHENGJIAN_TYPE", true);
}
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtPersonName.Text))
{
ShowNotify("人员姓名不能为空!", MessageBoxIcon.Warning);
return;
}
if (this.drpIdcardType.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择证件类型!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
ShowNotify("证件号码不能为空!", MessageBoxIcon.Warning);
return;
}
if (this.drpUnitId.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择所属单位!", MessageBoxIcon.Warning);
return;
}
if (this.drpPost.SelectedValue == BLL.Const._Null)
{
ShowNotify("请选择所属岗位!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtInTime.Text))
{
ShowNotify("入场时间不能为空!", MessageBoxIcon.Warning);
return;
}
SaveData();
var porject = BLL.ProjectService.GetProjectByProjectId(this.ProjectId);
if (!string.IsNullOrWhiteSpace(porject.SubjectUnit) && !string.IsNullOrWhiteSpace(porject.SubjectProject))
{
//项目关联了总包单位项目,保存成功后自动推送至总包单位
APIPersonSyncService.pushPersonLists(this.ProjectId, this.PersonId);
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
protected void SaveData()
{
Model.SitePerson_Person person = new Model.SitePerson_Person
{
Sex = this.rblSex.SelectedValue,
ProjectId = this.ProjectId
};
if (!string.IsNullOrEmpty(this.drpUnitId.SelectedValue))
{
person.UnitId = this.drpUnitId.SelectedValue;
}
if (this.rblIsTrain.SelectedValue == "true")
{
person.IsTrain = true;
}
else
{
person.IsTrain = false;
}
if (this.drpIdcardType.SelectedValue != BLL.Const._Null)
{
person.IdcardType = this.drpIdcardType.SelectedValue;
}
if (this.drpTeamGroup.SelectedValue != BLL.Const._Null)
{
person.TeamGroupId = this.drpTeamGroup.SelectedValue;
}
if (!string.IsNullOrWhiteSpace(String.Join(",", this.txtWorkArea.Values)))
{
person.WorkAreaId = string.Join(",", txtWorkArea.Values);
}
if (this.drpPost.SelectedValue != BLL.Const._Null)
{
person.WorkPostId = this.drpPost.SelectedValue;
}
if (!string.IsNullOrEmpty(this.rblIsUsed.SelectedValue))
{
person.IsUsed = Convert.ToBoolean(this.rblIsUsed.SelectedValue);
}
if (!string.IsNullOrEmpty(this.txtCardNo.Text.Trim()))
{
person.CardNo = this.txtCardNo.Text.Trim();
}
person.PersonName = this.txtPersonName.Text.Trim();
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
person.IdentityCard = this.txtIdentityCard.Text.Trim();
}
person.Telephone = this.txtTelephone.Text.Trim();
if (!string.IsNullOrEmpty(this.txtInTime.Text.Trim()))
{
person.InTime = Convert.ToDateTime(this.txtInTime.Text.Trim());
}
if (!string.IsNullOrEmpty(this.txtOutTime.Text.Trim()))
{
person.OutTime = Convert.ToDateTime(this.txtOutTime.Text.Trim());
}
if (this.drpMainCNProfessional.SelectedValue != Const._Null)
{
person.MainCNProfessionalId = this.drpMainCNProfessional.SelectedValue;
}
if (!string.IsNullOrEmpty(this.txtBirthday.Text.Trim()))
{
person.Birthday = Convert.ToDateTime(this.txtBirthday.Text.Trim());
}
if (!string.IsNullOrEmpty(imgPhoto.ImageUrl) && imgPhoto.ImageUrl != "~/res/images/blank_150.png")
{
person.PhotoUrl = imgPhoto.ImageUrl.Replace("~/", "");
person.HeadImage = AttachFileService.SetImageToByteArray(Funs.RootPath + person.PhotoUrl);
}
else
{
person.PhotoUrl = null;
person.HeadImage = null;
}
if (string.IsNullOrEmpty(PersonId))
{
if (!string.IsNullOrEmpty(this.txtCardNo.Text.Trim()))
{
int cardNoCount =
BLL.PersonService.GetPersonCountByCardNo(this.ProjectId, this.txtCardNo.Text.Trim());
if (cardNoCount > 0)
{
ShowNotify("此卡号已存在,不能重复!", MessageBoxIcon.Warning);
return;
}
}
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
person.IdentityCard = this.txtIdentityCard.Text.Trim();
var identityCardCount = PersonService.GetPersonCountByIdentityCard(this.txtIdentityCard.Text.Trim(), this.CurrUser.LoginProjectId);
if (identityCardCount != null)
{
var isUsed = string.Empty;
if (person.IsUsed)
{
isUsed = "在岗";
}
else
{
isUsed = "离岗";
}
var unitName = UnitService.GetShortUnitNameByUnitId(identityCardCount.UnitId);
Notify n = new Notify
{
Target = Target.Top,
Message = "此身份证号已存在" + unitName + "单位下,不能重复,目前" + isUsed,
MessageBoxIcon = MessageBoxIcon.Warning,
PositionX = Position.Center,
PositionY = Position.Top,
DisplayMilliseconds = 10000,
ShowHeader = false
};
n.Show();
return;
}
}
this.PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person));
person.PersonId = this.PersonId;
BLL.PersonService.AddPerson(person);
BLL.LogService.AddSys_Log(this.CurrUser, person.PersonName, person.PersonId, BLL.Const.PersonListMenuId,
BLL.Const.BtnAdd);
}
else
{
var getPerson = BLL.PersonService.GetPersonById(PersonId);
if (getPerson != null)
{
person.FromPersonId = getPerson.FromPersonId;
}
person.PersonId = PersonId;
BLL.PersonService.UpdatePerson(person);
//判断并更新项目用户的主副专业信息
var projectUser =
BLL.ProjectUserService.GetProjectUserByProjectIdAndIdentityCard(this.ProjectId,
person.IdentityCard);
if (projectUser != null)
{
projectUser.MainCNProfessionalId = person.MainCNProfessionalId;
projectUser.ViceCNProfessionalId = person.ViceCNProfessionalId;
BLL.ProjectUserService.UpdateProjectUser(projectUser);
}
BLL.LogService.AddSys_Log(this.CurrUser, person.PersonName, person.PersonId, BLL.Const.PersonListMenuId,
BLL.Const.BtnModify);
}
///上传人脸库
var getProject = ProjectService.GetProjectByProjectId(person.ProjectId);
if (!string.IsNullOrEmpty(person.PhotoUrl) && getProject != null && getProject.IsFace == true)
{
Alert.ShowInParent(APIPersonService.PersonFace(person), MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 上传照片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void filePhoto_FileSelected(object sender, EventArgs e)
{
if (filePhoto.HasFile)
{
string fileName = filePhoto.ShortFileName;
if (!ValidateFileType(fileName))
{
ShowNotify("无效的文件类型!");
return;
}
fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
string url = "~/FileUpload/PersonBaseInfo/" + DateTime.Now.Year + "-" + DateTime.Now.Month + "/";
filePhoto.SaveAs(Server.MapPath(url + fileName));
imgPhoto.ImageUrl = url + fileName;
// 清空文件上传组件
filePhoto.Reset();
}
}
#endregion
#region
/// <summary>
/// 验证身份证 卡号是否存在
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtCardNo.Text))
{
var q = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.CardNo == this.txtCardNo.Text.Trim() && (x.PersonId != this.PersonId || (this.PersonId == null && x.PersonId != null)));
if (q != null)
{
ShowNotify("输入的卡号已存在!", MessageBoxIcon.Warning);
}
}
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
var q2 = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.IdentityCard == this.txtIdentityCard.Text.Trim() && (x.PersonId != this.PersonId || (this.PersonId == null && x.PersonId != null)));
if (q2 != null)
{
var isUsed = string.Empty;
if (q2.IsUsed)
{
isUsed = "在岗";
}
else
{
isUsed = "离岗";
}
var unitName = UnitService.GetShortUnitNameByUnitId(q2.UnitId);
Notify n = new Notify
{
Target = Target.Top,
Message = "此身份证号已存在" + unitName + "单位下,不能重复,目前" + isUsed,
MessageBoxIcon = MessageBoxIcon.Warning,
PositionX = Position.Center,
PositionY = Position.Top,
DisplayMilliseconds = 10000,
ShowHeader = false
};
n.Show();
}
}
}
#endregion
#region
/// <summary>
/// 判断按钮权限
/// </summary>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId,
BLL.Const.PersonListMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
this.filePhoto.Hidden = false;
}
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnQR_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim()))
{
Alert.ShowInTop("身份证号码不能为空!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtPersonName.Text))
{
ShowNotify("人员姓名不能为空!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtInTime.Text))
{
ShowNotify("入场时间不能为空!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.PersonId))
{
this.SaveData();
}
string strCode = "person$" + this.txtIdentityCard.Text.Trim();
PageContext.RegisterStartupScript(Window1.GetShowReference(
String.Format("~/Controls/SeeQRImage.aspx?PersonId={0}&strCode={1}", this.PersonId, strCode), "二维码查看",
400, 400));
}
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttachUrl4_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.PersonId))
{
SaveData();
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format(
"~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/PersonBaseInfo&menuId={1}&strParam=4",
this.PersonId, BLL.Const.PersonListMenuId)));
}
#endregion
protected void txtIdentityCard_TextChanged(object sender, EventArgs e)
{
bool isok = true;
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
string idCard = this.txtIdentityCard.Text.Trim();
var q2 = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.ProjectId == this.CurrUser.LoginProjectId && x.IdentityCard == idCard && (x.PersonId != this.PersonId || (this.PersonId == null && x.PersonId != null)));
if (q2 != null)
{
isok = false;
var isUsed = string.Empty;
if (q2.IsUsed)
{
isUsed = "在岗";
}
else
{
isUsed = "离岗";
}
var unitName = UnitService.GetShortUnitNameByUnitId(q2.UnitId);
Notify n = new Notify
{
Target = Target.Top,
Message = "此身份证号已存在" + unitName + "单位下,不能重复,目前" + isUsed,
MessageBoxIcon = MessageBoxIcon.Warning,
PositionX = Position.Center,
PositionY = Position.Top,
DisplayMilliseconds = 10000,
ShowHeader = false
};
n.Show();
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
if (this.drpIdcardType.SelectedValue == "SHENFEN_ZHENGJIAN")
{
if (!IDCardValid.CheckIDCard(idCard))
{
isok = false;
ShowNotify("输入的身份证号码有误!", MessageBoxIcon.Warning);
}
}
if (isok)
{
string birthDateStr = "";
if (idCard.Length == 18) //如果是新的二代身份证直接取中间8位日期
{
birthDateStr = idCard.Substring(6, 8);
}
else if (idCard.Length == 15) //如果是老的一代身份证取中间6位日期
{
birthDateStr = "19" + idCard.Substring(6, 6);
}
var Birthday = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
this.txtBirthday.SelectedDate = Birthday;
}
}
}
protected void drpUnitId_OnSelectedIndexChanged(object sender, EventArgs e)
{
TeamGroupService.InitTeamGroupProjectUnitDropDownList(this.drpTeamGroup, this.ProjectId,
this.drpUnitId.SelectedValue, true);
}
protected void txtPersonName_TextChanged(object sender, EventArgs e)
{
var model = (from x in Funs.DB.Sys_User where x.UserName == txtPersonName.Text.Trim() select x)
.FirstOrDefault();
if (model != null)
{
txtPersonName.Text = model.UserName;
txtTelephone.Text = model.Telephone;
txtIdentityCard.Text = model.IdentityCard;
txtIdentityCard_TextChanged(null, null);
rblSex.SelectedValue = model.Sex == "1" ? "1" : "2";
}
}
}
}