namespace FineUIPro.Web.common.WelderManage { using BLL; using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SgManager.AI; using System; using System.Collections.Generic; using System.Configuration; using System.Drawing; using System.IO; using System.Linq; using System.Text; using ThoughtWorks.QRCode.Codec; using ThoughtWorks.QRCode.Codec.Data; 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; //} if (this.CurrUser.UserId == BLL.Const.GlyId) { this.drpIfOnGuard.Enabled = true; } else { this.drpIfOnGuard.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; } if (!string.IsNullOrEmpty(person.PhotoUrl)) { imgPhoto1.ImageUrl = person.PhotoUrl; } } 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; welder.PhotoUrl = imgPhoto1.ImageUrl; //welder.IsOAM = true; 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, "修改人员信息!"); } if (!string.IsNullOrEmpty(welder.PhotoUrl) ) { Alert.ShowInParent(PersonFace(welder), MessageBoxIcon.Warning); } } #endregion public string PersonFace(Model.HJGL_BS_Welder person) { string message = string.Empty; string filePath = Server.MapPath(person.PhotoUrl); List kqFace = null; try { //ErrLogInfo.WriteLog("filePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePathfilePath:" + filePath); kqFace = (List)SgManager.AI.FaceClass.SearchFileFace(filePath); if (kqFace != null || kqFace.Count > 0 || kqFace[0].errMess == "SUCCESS") { string result = FaceClass.FaceVerify(filePath); JObject jresult = JObject.Parse(result); JObject lvresult = jresult.Value("result"); bool isOK = false; if (jresult.Value("error_code") == 0) { if (lvresult.Value("face_liveness") >= ConfigAppSetting.getConfigAppSetting("BD_face_liveness") ? true : false)//99.5%//活体度 { if (Convert.ToDouble(lvresult["face_list"][0]["location"]["width"]) > ConfigAppSetting.getConfigAppSetting("BD_width") ? true : false) { if (Convert.ToDouble(lvresult["face_list"][0]["location"]["height"]) > ConfigAppSetting.getConfigAppSetting("BD_height") ? true : false) { if (System.Math.Abs(Convert.ToDouble(lvresult["face_list"][0]["angle"]["roll"])) <= ConfigAppSetting.getConfigAppSetting("BD_roll") ? true : false)//角度正负度数 { if (System.Math.Abs(Convert.ToDouble(lvresult["face_list"][0]["angle"]["yaw"])) <= ConfigAppSetting.getConfigAppSetting("BD_roll") + 1 ? true : false)//角度正负度数 { if (System.Math.Abs(Convert.ToDouble(lvresult["face_list"][0]["angle"]["pitch"])) <= ConfigAppSetting.getConfigAppSetting("BD_roll") + 1 ? true : false)//角度正负度数 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["left_eye"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["right_eye"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["nose"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["mouth"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["left_cheek"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["right_cheek"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["occlusion"]["chin_contour"]) <= ConfigAppSetting.getConfigAppSetting("BD_occlusion") ? true : false)// 0为无遮挡,1是完全遮挡 { if (Convert.ToDouble(lvresult["face_list"][0]["quality"]["blur"]) <= ConfigAppSetting.getConfigAppSetting("BD_blur") ? true : false)//模糊度,0---1,小于0.7 { isOK = true; } else message = "清晰度检测失败"; ; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "遮挡检测失败"; } else message = "角度检测失败"; } else message = "角度检测失败"; } else message = "角度检测失败"; } else message = "宽高检测失败"; } else message = "宽高检测失败"; } else message = "人脸动态检测失败"; } else message = "识别不到人脸"; if (isOK) { var faceResult = FaceClass.addByBase64(person.WED_ID, person.IdentityCard, filePath, AccessToken.getAccessToken()); var face = JsonConvert.DeserializeObject(faceResult); // JsonConvert.DeserializeObject(myPunishItem); if (face.error_code == 0 || face.error_code == 223105) { message = "人脸库注册成功!"; // face_token = face.result.face_token; //APIPersonService.SaveSitePerson(person); } else { message = "注册人脸库失败" + face.error_code + face.error_msg; } } else { message += "注册人脸库失败"; } } } catch (Exception ex) { message = "注册人脸库失败"; ErrLogInfo.WriteLog(ex, "PC-人员信息保存", "SitePerson.PersonListEdit"); } return message; } #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(); } } protected void filePhoto1_FileSelected(object sender, EventArgs e) { if (filePhoto1.HasFile) { string fileName = filePhoto1.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!"); return; } fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_"); fileName = DateTime.Now.Ticks.ToString() + "_" + fileName; filePhoto1.SaveAs(Server.MapPath("~/upload/" + fileName)); imgPhoto1.ImageUrl = "~/upload/" + fileName; // 清空文件上传组件 filePhoto1.Reset(); var welder = Funs.DB.HJGL_BS_Welder.FirstOrDefault(x=>x.WED_ID== WED_ID); welder.PhotoUrl = imgPhoto1.ImageUrl.Replace("/", "\\"); Funs.DB.SubmitChanges(); Alert.ShowInParent(PersonFace(welder), MessageBoxIcon.Warning); } } #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)); } /// /// 证件复印件 /// /// /// protected void btnAttachUrl2_Click(object sender, EventArgs e) { string edit = "0"; // 表示能打开附件上传窗口,但不能上传附件 if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PersonManageMenuId, Const.BtnSave)) { edit = "1"; } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Common/WelderManage&menuId={1}&edit={2}", this.WED_ID + "F", Const.HJGL_PersonManageMenuId, edit))); } } }