namespace FineUIPro.Web.common.WelderManage { using System; using System.Drawing; using BLL; using System.Linq; using ThoughtWorks.QRCode.Codec; using ThoughtWorks.QRCode.Codec.Data; using System.Text; using System.IO; public partial class WelderSave : PageBase { #region 定义项 /// /// 焊工id /// public string WED_ID { get { return (string)ViewState["WED_ID"]; } set { ViewState["WED_ID"] = value; } } /// /// 二维码路径id /// public string AttachUrl { get { return (string)ViewState["AttachUrl"]; } set { ViewState["AttachUrl"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.WED_ID = Request.Params["WED_ID"]; ///所属单位 this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = BLL.Base_UnitService.GetSubUnitList(); this.drpUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpUnit); ///班组 //this.drpEducation.DataTextField = "EDU_Name"; //this.drpEducation.DataValueField = "EDU_ID"; //this.drpEducation.DataSource = BLL.HJGL_TeamGroupService.GetEducationList(this.CurrUser.LoginProjectId); //this.drpEducation.DataBind(); //Funs.FineUIPleaseSelect(this.drpEducation); //var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); //if (pUnit == null || pUnit.UnitType == Const.UnitType_5) //{ // drpUnit.Enabled = true; //} //else //{ // drpUnit.SelectedValue = this.CurrUser.UnitId; // drpUnit.Enabled = false; //} this.PersonLoad(); } } #endregion #region 初始化页面信息 /// /// 初始化页面信息 /// protected void PersonLoad() { var person = BLL.HJGL_PersonManageService.GetWelderByWenId(WED_ID); if (person != null) { if (!String.IsNullOrEmpty(person.WED_Unit)) { this.drpUnit.SelectedValue = person.WED_Unit; } //this.drpEducation.Items.Clear(); //this.drpEducation.DataTextField = "TeamGroupName"; //this.drpEducation.DataValueField = "TeamGroupId"; //this.drpEducation.DataSource = BLL.Base_TeamGroupService.GetTeamGroupByUnit(drpUnit.SelectedValue); //this.drpEducation.DataBind(); //Funs.FineUIPleaseSelect(this.drpEducation); //if (!String.IsNullOrEmpty(person.EDU_ID)) //{ // var q = BLL.Base_TeamGroupService.GetTeamGroupByTeamGroupId(person.EDU_ID); // if (q != null) // { // this.drpEducation.SelectedValue = person.EDU_ID; // } //} this.txtName.Text = person.WED_Name; this.txtCode.Text = person.WED_Code; this.txtWorkCode.Text = person.WED_WorkCode; this.txtClass.Text = person.WED_Class; if (!String.IsNullOrEmpty(person.WED_Sex)) { this.drpSex.SelectedValue = person.WED_Sex; } this.txtRecordDate.Text = string.Format("{0:yyyy-MM-dd}", person.RecordDate); this.txtBirthday.Text = string.Format("{0:yyyy-MM-dd}", person.WED_Birthday); this.txtLimitDate.Text = string.Format("{0:yyyy-MM-dd}", person.LimitDate); if (person.WED_IfOnGuard.HasValue) { this.drpIfOnGuard.Checked = person.WED_IfOnGuard.Value; } this.txtIdentityCard.Text = person.IdentityCard; this.txtRemark.Text = person.WED_Remark; if (!string.IsNullOrEmpty(person.AttachUrl)) { this.AttachUrl = person.AttachUrl; this.btnSee.Hidden = false; this.btnQR.Hidden = false; this.btnQR.Text = "二维码重新生成"; } if (!string.IsNullOrEmpty(person.SignatureUrl)) { imgPhoto.ImageUrl = person.SignatureUrl; } } else { this.txtRecordDate.Text = DateTime.Now.Date.ToString(); } } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PersonManageMenuId, Const.BtnSave)) { if (this.drpUnit.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.txtCode.Text.Trim()) || string.IsNullOrEmpty(this.txtName.Text.Trim()) || string.IsNullOrEmpty(this.txtName.Text.Trim())) { Alert.ShowInTop("单位、焊工姓名、焊工代号、焊工身份证不能为空!", MessageBoxIcon.Warning); return; } if (BLL.HJGL_PersonManageService.IsExistWEDCode(this.txtCode.Text.Trim(), this.WED_ID)) { Alert.ShowInTop("此焊工代号已存在!", MessageBoxIcon.Warning); return; } if (BLL.HJGL_PersonManageService.IsExistIdentityCard(this.txtIdentityCard.Text.Trim(), this.WED_ID)) { Alert.ShowInTop("此身份证号已存在!", MessageBoxIcon.Warning); return; } this.SaveData(); Alert.ShowInTop("提交成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 提交数据 /// private void SaveData() { Model.HJGL_BS_Welder welder = new Model.HJGL_BS_Welder(); if (this.drpUnit.SelectedValue != BLL.Const._Null) { welder.WED_Unit = this.drpUnit.SelectedValue; } //if (this.drpEducation.SelectedValue != BLL.Const._Null) //{ // welder.EDU_ID = this.drpEducation.SelectedValue; //} welder.WED_Code = this.txtCode.Text.Trim(); welder.WED_Name = this.txtName.Text.Trim(); welder.WED_Sex = this.drpSex.SelectedValue; welder.RecordDate = Funs.GetNewDateTime(this.txtRecordDate.Text.Trim()); welder.WED_Birthday = Funs.GetNewDateTime(this.txtBirthday.Text.Trim()); welder.LimitDate = Funs.GetNewDateTime(this.txtLimitDate.Text.Trim()); welder.WED_WorkCode = this.txtWorkCode.Text.Trim(); welder.WED_Class = this.txtClass.Text.Trim(); welder.WED_IfOnGuard = this.drpIfOnGuard.Checked; welder.IdentityCard = this.txtIdentityCard.Text.Trim(); welder.WED_Remark = this.txtRemark.Text.Trim(); welder.ProjectId = this.CurrUser.LoginProjectId; welder.AttachUrl = this.AttachUrl; welder.SignatureUrl = imgPhoto.ImageUrl; if (string.IsNullOrEmpty(this.WED_ID)) { BLL.HJGL_PersonManageService.AddBSWelder(welder); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加人员信息"); } else { welder.WED_ID = WED_ID; BLL.HJGL_PersonManageService.UpdateBSWelder(welder); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改人员信息!"); } } #endregion #region 上传电子签名图片 /// /// 上传照片 /// /// /// 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; filePhoto.SaveAs(Server.MapPath("~/upload/" + fileName)); imgPhoto.ImageUrl = "~/upload/" + fileName; // 清空文件上传组件 filePhoto.Reset(); } } #endregion //protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) //{ // this.drpEducation.Items.Clear(); // this.drpEducation.DataTextField = "TeamGroupName"; // this.drpEducation.DataValueField = "TeamGroupId"; // this.drpEducation.DataSource = BLL.Base_TeamGroupService.GetTeamGroupByUnit(drpUnit.SelectedValue); // this.drpEducation.DataBind(); // Funs.FineUIPleaseSelect(this.drpEducation); //} /// /// 指纹登记 /// /// /// protected void lbWelderRead_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim())) { Alert.ShowInTop("身份证号码不能为空!", MessageBoxIcon.Warning); return; } string identityCard = string.Empty; var weld = BLL.HJGL_PersonManageService.GetWelderByWenId(this.WED_ID); if (weld != null) { identityCard = weld.IdentityCard; } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/FingerMark/RegisterFinger.aspx?userId={0}&flag=1", this.WED_ID), "登记指纹", 560, 500)); //PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/RLSB/WelderTrain.aspx?identityCard={0}", identityCard), "人脸训练", 560, 500)); } /// /// /// /// /// protected void btnQR_Click(object sender, EventArgs e) { //if (string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim())) //{ // Alert.ShowInTop("身份证号码不能为空!", MessageBoxIcon.Warning); // return; //} if (string.IsNullOrEmpty(this.WED_ID)) { this.SaveData(); } var welder = from x in Funs.DB.HJGL_BS_Welder where x.WED_Code == this.txtCode.Text.Trim() select x; if (welder.Count() == 1) { this.CreateCode_Simple(this.txtCode.Text.Trim()); } else { Alert.ShowInTop("焊工号不唯一!", MessageBoxIcon.Warning); return; } } /// /// /// /// /// protected void btnSee_Click(object sender, EventArgs e) { string url = string.Empty; var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(this.WED_ID); if (welder != null && !string.IsNullOrEmpty(welder.AttachUrl)) { url = welder.AttachUrl; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SeeQRImage.aspx?WelderId={0}", this.WED_ID), "焊工二维码", 400, 400)); } else { Alert.ShowInTop("二维码不存在!", MessageBoxIcon.Warning); return; } } //生成二维码方法一 private void CreateCode_Simple(string nr) { var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(this.WED_ID); if (welder != null) { BLL.UploadFileService.DeleteFile(Funs.RootPath, welder.AttachUrl);//删除二维码 string imageUrl = string.Empty; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeScale = nr.Length; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; System.Drawing.Image image = qrCodeEncoder.Encode(nr, Encoding.UTF8); string filepath = Server.MapPath("~/") + BLL.UploadFileService.QRCodeImageFilePath; //如果文件夹不存在,则创建 if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); } string filename = DateTime.Now.ToString("yyyymmddhhmmssfff").ToString() + ".jpg"; imageUrl = filepath + filename; System.IO.FileStream fs = new System.IO.FileStream(imageUrl, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write); image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg); fs.Close(); image.Dispose(); this.AttachUrl = BLL.UploadFileService.QRCodeImageFilePath + filename; welder.AttachUrl = this.AttachUrl; BLL.HJGL_PersonManageService.UpdateBSWelder(welder); this.btnSee.Hidden = false; this.btnQR.Hidden = false; this.btnQR.Text = "二维码重新生成"; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SeeQRImage.aspx?WelderId={0}", this.WED_ID), "二维码查看", 450, 450)); } else { Alert.ShowInTop("操作有误,重新生成!", MessageBoxIcon.Warning); } //二维码解码 //var codeDecoder = CodeDecoder(filepath); //this.Image1.ImageUrl = "~/image/" + filename + ".jpg"; } /// /// 二维码解码 /// /// 图片路径 /// public string CodeDecoder(string filePath) { if (!System.IO.File.Exists(filePath)) return null; Bitmap myBitmap = new Bitmap(Image.FromFile(filePath)); QRCodeDecoder decoder = new QRCodeDecoder(); string decodedString = decoder.decode(new QRCodeBitmapImage(myBitmap)); return decodedString; } /// /// 人脸采集 /// /// /// protected void btnWelderFaceRead_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim())) { Alert.ShowInTop("身份证号码不能为空!", MessageBoxIcon.Warning); return; } string identityCard = string.Empty; var weld = BLL.HJGL_PersonManageService.GetWelderByWenId(this.WED_ID); if (weld != null) { identityCard = weld.IdentityCard; } PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("~/RLSB/WelderTrain.aspx?identityCard={0}", identityCard), "人脸训练", 1260, 680)); } } }