namespace FineUIPro.Web.Personal
{
using BLL;
using FastReport.Utils;
using Model;
using System;
using System.IO;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
public partial class PersonalInfo : PageBase
{
#region 定义变量
///
/// 照片附件路径
///
public string PhotoAttachUrl
{
get
{
return (string)ViewState["PhotoAttachUrl"];
}
set
{
ViewState["PhotoAttachUrl"] = value;
}
}
#endregion
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpMaritalStatus, "MARITAL_STATUS", true);
BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpNation, "MINZU_TYPE", true);
BasicDataService.InitBasicDataProjectUnitDropDownList(this.drpEduLevel, "EDU_LEVEL", true);
PositionService.InitPositionDropDownList(this.drpPosition, true);
PostTitleService.InitPostTitleDropDownList(this.drpPostTitle, true);
/// Tab1加载页面方法
this.Tab1LoadData();
if (this.CurrUser.PersonId == Const.hfnbdId)
{
this.btnCustomQuery.Hidden = false;
this.lbSystemVersion.Hidden = false;
this.lbSystemVersion.Text = Funs.SystemVersion;
}
}
}
#region Tab1
///
/// Tab1加载页面方法
///
private void Tab1LoadData()
{
var getData = Person_PersonsService.GetPerson_PersonsById(this.CurrUser.PersonId);
if (getData != null)
{
this.txtUserName.Text = getData.PersonName;
this.txtJobNum.Text = getData.JobNum;
if (!string.IsNullOrEmpty(getData.Sex))
{
this.rblSex.SelectedValue = getData.Sex;
}
this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", getData.Birthday);
this.drpMaritalStatus.SelectedValue = getData.MaritalStatus ?? Const._Null;
this.drpNation.SelectedValue = getData.Nation;
this.txtUnit.Text = UnitService.GetUnitNameByUnitId(getData.UnitId);
this.txtAccount.Text = getData.Account;
this.txtIdentityCard.Text = getData.IdentityCard;
this.txtTelephone.Text = getData.Telephone;
this.txtGraduate.Text = getData.Graduate;
this.drpEduLevel.SelectedValue = getData.EduLevel ?? Const._Null;
this.drpPosition.SelectedValue = getData.PositionId ?? Const._Null;
this.drpPostTitle.SelectedValue = getData.PostTitleId ?? Const._Null;
if (!string.IsNullOrEmpty(getData.PhotoUrl))
{
this.PhotoAttachUrl = getData.PhotoUrl;
imgPhoto.ImageUrl = ("~/" + getData.PhotoUrl);
}
}
}
#endregion
protected void btnCustomQuery_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../SysManage/CustomQuery.aspx"), "查询"));
}
///
/// -照片上传
///
///
///
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 = "~/" + UploadFileService.PersonBaseInfoFilePath + DateTime.Now.Year + "-" + DateTime.Now.Month + "/";
string fileMapPath = Server.MapPath(url + fileName);
filePhoto.SaveAs(fileMapPath);
if (File.Exists(fileMapPath))
{
FileInfo fileInfo = new FileInfo(fileMapPath);
double size = Math.Ceiling(fileInfo.Length * 1.0 / 1024.0);
if (size > 300)
{
Alert.ShowInTop("照片大小超过300KB,请重新上传!", MessageBoxIcon.Warning);
return;
}
}
imgPhoto.ImageUrl = url + fileName;
// 清空文件上传组件
filePhoto.Reset();
}
}
///
/// 身份证变化
///
///
///
protected void txtIdentityCard_Blur(object sender, EventArgs e)
{
bool isok = true;
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text))
{
string idCard = this.txtIdentityCard.Text.Trim();
var q2 = Funs.DB.Person_Persons.FirstOrDefault(x => x.IdentityCard == idCard && x.PersonId != this.CurrUser.PersonId);
if (q2 != null)
{
ShowNotify("输入的身份证号码已存在!", MessageBoxIcon.Warning);
return;
}
if (!IDCardValid.CheckIDCard(idCard))
{
isok = false;
ShowNotify("输入的身份证号码有误!", MessageBoxIcon.Warning);
}
if (isok)
{
///生成二维码
this.hdUrl.Text = BLL.CreateQRCodeService.CreateCode_Simple("person$" + idCard);
DateTime? birth = IDCardValid.getBirthByIDCard(idCard);
if (birth.HasValue)
{
this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", birth.Value);
}
}
}
}
///
///
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
var getData = Person_PersonsService.GetPerson_PersonsById(this.CurrUser.PersonId);
if (getData != null)
{
getData.JobNum = this.txtJobNum.Text.Trim();
getData.Sex = this.rblSex.SelectedValue;
getData.IdentityCard = this.txtIdentityCard.Text.Trim();
getData.Birthday = IDCardValid.getBirthByIDCard(getData.IdentityCard);
getData.Telephone = this.txtTelephone.Text.Trim();
getData.Graduate = this.txtGraduate.Text.Trim();
if (!string.IsNullOrEmpty(this.hdUrl.Text))
{
getData.QRCodeAttachUrl = this.hdUrl.Text;
}
if (this.drpMaritalStatus.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpMaritalStatus.SelectedValue))
{
getData.MaritalStatus = this.drpMaritalStatus.SelectedValue;
}
if (this.drpNation.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpNation.SelectedValue))
{
getData.Nation = this.drpNation.SelectedValue;
}
if (this.drpNation.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpNation.SelectedValue))
{
getData.Nation = this.drpNation.SelectedValue;
}
if (this.drpEduLevel.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpEduLevel.SelectedValue))
{
getData.EduLevel = this.drpEduLevel.SelectedValue;
}
if (this.drpPosition.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpPosition.SelectedValue))
{
getData.PositionId = this.drpPosition.SelectedValue;
}
if (this.drpPostTitle.SelectedValue != Const._Null && !string.IsNullOrEmpty(this.drpPostTitle.SelectedValue))
{
getData.PostTitleId = this.drpPostTitle.SelectedValue;
}
if (!string.IsNullOrEmpty(imgPhoto.ImageUrl) && imgPhoto.ImageUrl != "~/res/images/blank.png")
{
getData.PhotoUrl = imgPhoto.ImageUrl.Replace("~/", "");
getData.HeadImage = AttachFileService.SetImageToByteArray(Funs.RootPath + getData.PhotoUrl);
}
else
{
getData.PhotoUrl = null;
getData.HeadImage = null;
}
string info = Person_PersonsService.ValidPersonInfo(getData);
if (string.IsNullOrEmpty(info))
{
Person_PersonsService.UpdatePerson(getData);
LogService.AddSys_Log(this.CurrUser, getData.PersonName, getData.PersonId, BLL.Const.PersonalInfoMenuId, BLL.Const.BtnModify);
Alert.ShowInParent("保存成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInParent(info, MessageBoxIcon.Warning);
}
}
}
///
///
///
///
///
protected void btnALLSave_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../Person/PersonEdit.aspx?PersonId={0}", this.CurrUser.PersonId, "编辑 - ")));
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.Tab1LoadData();
}
}
}