using BLL; using System; using System.Linq; namespace FineUIPro.Web.HJGL.PersonManage { public partial class WelderManageEdit : PageBase { #region 定义变量 /// /// 照片附件路径 /// public string PhotoAttachUrl { get { return (string)ViewState["PhotoAttachUrl"]; } set { ViewState["PhotoAttachUrl"] = value; } } /// /// 二维码路径id /// public string QRCodeAttachUrl { get { return (string)ViewState["QRCodeAttachUrl"]; } set { ViewState["QRCodeAttachUrl"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); //BLL.Base_ProjectTypeService.InitProjectTypeDropDownList(this.drpPojectType, true, "请选择");//项目类型 BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpUnitId, this.CurrUser.LoginProjectId, Const.ProjectUnitType_2, true); string PersonId = Request.Params["PersonId"]; if (!string.IsNullOrEmpty(PersonId)) { var welder = BLL.SitePerson_PersonService.GetSitePersonByProjectIdPersonId(this.CurrUser.LoginProjectId, PersonId); if (welder != null) { this.txtWelderCode.Text = welder.WelderCode; this.txtWelderName.Text = welder.PersonName; if (!string.IsNullOrEmpty(welder.UnitId)) { this.drpUnitId.SelectedValue = welder.UnitId; } var getPersons = Person_PersonsService.GetPerson_PersonsById(welder.PersonId); if (getPersons != null) { this.rblSex.SelectedValue = getPersons.Sex; if (getPersons.Birthday.HasValue) { this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", getPersons.Birthday); } if (!string.IsNullOrEmpty(getPersons.PhotoUrl)) { this.PhotoAttachUrl = getPersons.PhotoUrl; this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl; } if (!string.IsNullOrEmpty(getPersons.QRCodeAttachUrl)) { this.QRCodeAttachUrl = getPersons.QRCodeAttachUrl; this.btnSee.Hidden = false; this.btnQR.Hidden = false; this.btnQR.Text = "二维码重新生成"; } } this.txtIdentityCard.Text = welder.IdentityCard; this.txtCertificateCode.Text = welder.CertificateCode; //if (string.IsNullOrEmpty(welder.CertificateCode)) //{ // this.txtCertificateCode.Text = welder.IdentityCard; //} //if (welder.CertificateLimitTime.HasValue) //{ // this.txtCertificateLimitTime.Text = string.Format("{0:yyyy-MM-dd}", welder.CertificateLimitTime); //} this.txtWelderLevel.Text = welder.WelderLevel; if (welder.States == Const.State_1) { cbIsUsed.Checked = true; } else { cbIsUsed.Checked = false; } this.txtRemark.Text = welder.Remark; } } else { this.cbIsUsed.Checked = true; } } } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { string PersonId = Request.Params["PersonId"]; var q = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.WelderCode == this.txtWelderCode.Text.Trim() && (x.PersonId != PersonId || (PersonId == null && PersonId != null)) && x.ProjectId == this.CurrUser.LoginProjectId); if (q != null) { Alert.ShowInTop("焊工号已经存在!", MessageBoxIcon.Warning); return; } if (this.drpUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("选择单位", MessageBoxIcon.Warning); return; } PersonId = SaveData(PersonId); ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } private string SaveData(string PersonId) { Model.SitePerson_Person newWelder = new Model.SitePerson_Person(); newWelder.ProjectId = this.CurrUser.LoginProjectId; newWelder.WelderCode = this.txtWelderCode.Text.Trim(); newWelder.PersonName = this.txtWelderName.Text.Trim(); newWelder.WorkPostId = Const.WorkPost_Welder; if (this.drpUnitId.SelectedValue != BLL.Const._Null) { newWelder.UnitId = this.drpUnitId.SelectedValue; } //newWelder.Sex = this.rblSex.SelectedValue; //newWelder.Birthday = Funs.GetNewDateTime(this.txtBirthday.Text.Trim()); newWelder.IdentityCard = this.txtIdentityCard.Text.Trim(); newWelder.CertificateCode = this.txtCertificateCode.Text.Trim(); //newWelder.CertificateLimitTime = Funs.GetNewDateTime(this.txtCertificateLimitTime.Text.Trim()); newWelder.WelderLevel = this.txtWelderLevel.Text.Trim(); //if (this.cbIsOnDuty.Checked) //{ // newWelder.IsUsed = true; //} //else //{ // newWelder.IsUsed = false; //} newWelder.Remark = this.txtRemark.Text.Trim(); //newWelder.PhotoUrl = this.PhotoAttachUrl; newWelder.Isprint = "0"; // newWelder.IsUsed = true; if (!string.IsNullOrEmpty(PersonId)) { if (!BLL.WelderService.IsExisWelderCode(PersonId, this.txtWelderCode.Text, this.CurrUser.LoginProjectId)) { newWelder.PersonId = PersonId; BLL.WelderService.UpdateWelder(newWelder); //BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.WelderManageMenuId, Const.BtnModify, PersonId); } else { Alert.ShowInParent("焊工号已经存在!", MessageBoxIcon.Warning); } } else { PersonId = SQLHelper.GetNewID(typeof(Model.SitePerson_Person)); if (!BLL.WelderService.IsExisWelderCode(PersonId, this.txtWelderCode.Text, this.CurrUser.LoginProjectId)) { newWelder.PersonId = PersonId; // BLL.WelderService.AddWelder(newWelder); //BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.WelderManageMenuId, Const.BtnAdd, PersonId); } else { Alert.ShowInParent("焊工号已经存在!", MessageBoxIcon.Warning); } } return PersonId; } #endregion protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpUnitId.SelectedValue != Const._Null) { var u = BLL.UnitService.GetUnitByUnitId(drpUnitId.SelectedValue); string prefix = u.UnitCode + "-HG-"; txtWelderCode.Text = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "SitePerson_Person", "WelderCode", prefix); } } #region 附件上传 /// /// 上传附件资源 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { string edit = "0"; string PersonId = Request.Params["PersonId"]; if (string.IsNullOrEmpty(PersonId)) { SaveData(PersonId); } else { edit = "1"; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/WelderManage&menuId={1}&edit={2}&strParam=4", PersonId, BLL.Const.WelderManageMenuId, edit))); } #endregion #region 照片上传 /// /// 上传照片 /// /// /// protected void btnPhoto_Click(object sender, EventArgs e) { //if (filePhoto.HasFile) //{ // string fileName = filePhoto.ShortFileName; // if (!ValidateFileType(fileName)) // { // ShowNotify("无效的文件类型", MessageBoxIcon.Warning); // return; // } // this.PhotoAttachUrl = BLL.UploadFileService.UploadAttachment(BLL.Funs.RootPath, this.filePhoto, this.PhotoAttachUrl, Const.WelderFilePath); // this.Image1.ImageUrl = "~/" + this.PhotoAttachUrl; //} } #endregion protected void btnQR_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim())) { Alert.ShowInTop("身份证不能为空!", MessageBoxIcon.Warning); return; } BLL.CreateQRCodeService.CreateCode_Simple("person$" + this.txtIdentityCard.Text.Trim()); } /// /// /// /// /// protected void btnSee_Click(object sender, EventArgs e) { string url = string.Empty; string PersonId = Request.Params["PersonId"]; var welder = Person_PersonsService.GetPerson_PersonsByProjectPersonId(PersonId); if (welder != null && !string.IsNullOrEmpty(welder.QRCodeAttachUrl)) { string strCode = "person$" + this.txtIdentityCard.Text.Trim(); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Controls/SeeQRImage.aspx?PersonId={0}&strCode={1}", welder.PersonId, strCode), "二维码查看", 400, 400)); //url = welder.QRCodeAttachUrl; //PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/Controls/SeeQRImage.aspx?PersonId={0}", PersonId), "二维码查看", 400, 400)); } else { Alert.ShowInTop("二维码不存在!", MessageBoxIcon.Warning); return; } } } }