123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- using CollectInformation.HCUSBSDK;
- using CollectInformation.Tools;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using System.Xml;
- namespace CollectInformation
- {
- public partial class MainForm : Form
- {
- Dictionary<string, string> loginUser = null;
- //Dictionary<string, string> user = null;
- Dictionary<string, string> securityInfo = null;
- HCUSBUtils hcUSBUtils = null;
- bool isInit = false;
- string sdkLevel = "";
- string devName = "";
- bool isLoginD = false;
- public MainForm()
- {
- InitializeComponent();
- }
- public MainForm(Dictionary<string, string> loginUser)
- {
- InitializeComponent();
- this.loginUser = loginUser;
- if (loginUser != null)
- {
- this.Text = loginUser["name"] + "欢迎您使用" + this.Text;
- }
- isInit = false;
- this.btnLinkEquipment.Enabled = true;
- this.btnReadID.Enabled = false;
- initD();
- }
- private void initD()
- {
- this.hcUSBUtils = new HCUSBUtils();
- this.sdkLevel = "SDK lv " + hcUSBUtils.initSDK();
- this.isInit = this.hcUSBUtils.TraverseDevice();
- if (this.isInit)
- {
- this.devName = System.Text.Encoding.UTF8.GetString(this.hcUSBUtils.m_aHidDevInfo[0].szDeviceName).TrimEnd('\0');
- this.labLinkStatus.Text = "" + this.devName + " | " + this.sdkLevel;
- }
- else
- {
- this.isInit = false;
- MessageBox.Show("当前设备链接失败,请尝试重新链接,或联系管理员。", "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- if (securityInfo == null)
- {
- clear();
- }
- }
- private void btnReplaceUser_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("您将要使用当前身份证信息覆盖报名人员信息,此操作无法撤销,请确定是否进行操作!", "系统警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
- {
- this.labName2.Text = this.labName.Text;
- this.labSex2.Text = this.labSex.Text;
- this.labNation2.Text = this.labNation.Text;
- this.labBirthday2.Text = this.labBirthday.Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
- this.securityInfo["name"] = this.labName.Text;
- this.securityInfo["gender"] = this.labSex.Text;
- this.securityInfo["nation"] = this.labNation.Text;
- this.securityInfo["birth"] = this.labBirthday.Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
- }
- }
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (e.CloseReason == CloseReason.UserClosing)
- {
- if (MessageBox.Show("您确定要退出采集终端么?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- else
- {
- Application.Exit();
- }
- }
- }
- private void btnLinkEquipment_Click(object sender, EventArgs e)
- {
- if (!this.isInit)
- {
- initD();
- }
- if (this.isInit)
- {
- this.isLoginD = hcUSBUtils.LoginDevice();
- if (this.isLoginD)
- {
- MessageBox.Show("设备链接成功。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.btnReadID.Enabled = true;
- this.labLinkStatus.Text = "已连接 " + this.devName + " | " + this.sdkLevel;
- }
- else
- {
- MessageBox.Show("当前设备链接失败,请尝试重新链接,或联系管理员。", "异常提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- private void btnReadID_Click(object sender, EventArgs e)
- {
- // 获取身份证信息
- string inputStr = "{\"IdentityInfoCond\":{}}";
- string outputStr = this.hcUSBUtils.CollectionNoImage(1, inputStr).TrimEnd('\0');
- try
- {
- Dictionary<string, object> d1 = JsonConvert.DeserializeObject<Dictionary<string, object>>(outputStr);
- if (d1.ContainsKey("statusString"))
- {
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + d1["statusString"], "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- catch (Exception)
- {
- XmlDocument xdoc = new XmlDocument();
- xdoc.LoadXml(outputStr);
- XmlNamespaceManager nsMgr = new XmlNamespaceManager(xdoc.NameTable);
- nsMgr.AddNamespace("ns", "http://www.isapi.org/ver20/XMLSchema");
- XmlNode statusNode = xdoc.SelectSingleNode("/ns:ResponseStatus/ns:statusString", nsMgr);
- if (statusNode != null)
- {
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + statusNode.InnerText, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else
- {
- outputStr = JsonConvert.SerializeXmlNode(xdoc.FirstChild);
- }
- }
- Dictionary<String, object> os = JsonConvert.DeserializeObject<Dictionary<string, object>>(outputStr);
- Dictionary<string, object> IdentityInfoD = JsonConvert.DeserializeObject<Dictionary<string, object>>(os["IdentityInfo"].ToString());
- this.labName.Text = IdentityInfoD["chnName"].ToString();
- this.labSex.Text = IdentityInfoD["sex"].ToString() == "male" ? "男" : IdentityInfoD["sex"].ToString() == "female" ? "女" : "未知";
- string nationIndex = IdentityInfoD["nation"].ToString().PadLeft(2, '0');
- this.labNation.Text = Nationality.GetNationality(ref nationIndex);
- this.labBirthday.Text = this.getDate(IdentityInfoD["birth"].ToString());
- this.labAddress.Text = IdentityInfoD["addr"].ToString();
- this.labID.Text = IdentityInfoD["IDCardNo"].ToString(); // "220182199603257024";
- this.labSigning.Text = IdentityInfoD["issuingAuthority"].ToString();
- this.labValidity.Text = this.getDate(IdentityInfoD["startDate"].ToString()) + " 至 " + this.getDate(IdentityInfoD["endDate"].ToString());
- // 使用身份证号获取待采集人员
- string url = constants.host + string.Format(constants.fetch, "security_guard_base") + "?status=1&card=" + labID.Text;
- Dictionary<string, string> res = HttpUitls.Get(url, constants.userToken);
- if (res["code"] == "0")
- {
- MessageBox.Show("系统出现异常,请联系管理员进行处理!\r\n错误信息:" + res["message"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- Dictionary<string, Object> retData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (retData["errcode"].ToString() == "0")
- {
- Dictionary<string, Object> ret = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (ret["data"] != null)
- {
- string securityStr = JsonConvert.SerializeObject(ret["data"]);
- this.securityInfo = JsonConvert.DeserializeObject<Dictionary<string, string>>(securityStr);
- this.labName2.Text = securityInfo["name"];
- this.labBeforeName.Text = securityInfo["beforeName"];
- this.labSex2.Text = securityInfo["gender"];
- this.labNation2.Text = securityInfo["nation"];
- this.labBirthday2.Text = securityInfo["birth"];
- this.labLevel.Text = securityInfo["grade"];
- this.labCompany.Text = securityInfo["sign_company"];
- this.labID2.Text = securityInfo["card"];
- this.btnOK.Enabled = true;
- if (securityInfo["collect_photo"].ToString() == "已采集")
- {
- this.btnGetImage.Enabled = false;
- url = constants.host + string.Format(constants.fetch, "security_guard_collect") + "?type=人像&security_guard_id=" + securityInfo["id"].ToString();
- Dictionary<string, string> resCollect = HttpUitls.Get(url, constants.userToken);
- if (res["code"] == "0")
- {
- this.btnGetImage.Enabled = true;
- }
- else
- {
- Dictionary<string, Object> collect = JsonConvert.DeserializeObject<Dictionary<string, Object>>(resCollect["data"]);
- string collectStr = JsonConvert.SerializeObject(collect["data"]);
- Dictionary<string, string> collect1 = JsonConvert.DeserializeObject<Dictionary<string, string>>(collectStr);
- this.picUser.ImageLocation = constants.urlbase + collect1["data"].ToString();
- }
- }
- else
- {
- this.btnGetImage.Enabled = true;
- }
- this.btnGetFingerprint.Enabled = true;
- this.btnReplaceUser.Enabled = true;
- }
- else
- {
- MessageBox.Show("没有对应的待采集人员信息!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else
- {
- MessageBox.Show("服务端返回异常信息,请联系管理员!\r\n异常信息:" + retData["errmsg"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void btnClear_Click(object sender, EventArgs e)
- {
- clear();
- }
- private void clear()
- {
- // 清空身份证读取信息
- this.labName.Text = "";
- this.labSex.Text = "";
- this.labNation.Text = "";
- this.labBirthday.Text = "";
- this.labAddress.Text = "";
- this.labID.Text = "";
- this.labSigning.Text = "";
- this.labValidity.Text = "";
- // 清空采集人员信息
- this.securityInfo = null;
- this.labName2.Text = "";
- this.labBeforeName.Text = "";
- this.labSex2.Text = "";
- this.labNation2.Text = "";
- this.labBirthday2.Text = "";
- this.labLevel.Text = "";
- this.labUserFingerprint.Text = "";
- this.labCompany.Text = "";
- this.labID2.Text = "";
- this.picUser.Image = null;
- // 控制管理按钮
- this.btnReplaceUser.Enabled = false;
- this.btnOK.Enabled = false;
- this.btnGetFingerprint.Enabled = false;
- this.btnGetImage.Enabled = false;
- }
- private void btnOK_Click(object sender, EventArgs e)
- {
- if (this.securityInfo != null)
- {
- // 上传指纹采集信息,并修改保安员状态
- if (this.labUserFingerprint.Text == "" || this.labUserFingerprint.Text == "未获取")
- {
- MessageBox.Show("请采集指纹信息!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else if(this.securityInfo["collect_photo"] != "已采集" && this.picUser.Image == null)
- {
- MessageBox.Show("请采集人像信息!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- string url = constants.host + string.Format(constants.fetch, "security_guard_others") + "?security_guard_id=" + this.securityInfo["id"];
- Dictionary<string, string> res = HttpUitls.Get(url, constants.userToken);
- if (res["code"] == "0")
- {
- MessageBox.Show("系统出现异常,请联系管理员进行处理!\r\n错误信息:" + res["message"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- Dictionary<string, Object> retData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (retData["errcode"].ToString() == "0")
- {
- Dictionary<string, Object> ret = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (ret["data"] != null)
- {
- string otherStr = JsonConvert.SerializeObject(ret["data"]);
- Dictionary<string, string> securityOther = JsonConvert.DeserializeObject<Dictionary<string, string>>(otherStr);
- //securityOther["fingerprint_num"] = this.labUserFingerprint.Text;
- securityOther["fingerprint_date"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- securityOther["fingerprint_personal"] = this.loginUser["name"];
- securityOther["fingerprint_office"] = this.loginUser["belong_company"];
- this.editSecurityOtherInfo(securityOther);
- }
- }
- else
- {
- MessageBox.Show("服务端返回异常信息,请联系管理员!\r\n异常信息:" + retData["errmsg"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- Dictionary<string, string> collect = new Dictionary<string, string>();
- collect["name"] = this.securityInfo["name"];
- collect["security_guard_id"] = this.securityInfo["id"];
- collect["type"] = "指纹";
- collect["data"] = this.labUserFingerprint.Text;
- collect["collect_personal"] = this.loginUser["name"];
- collect["collect_police"] = this.loginUser["belong_company"];
- if (this.createSecurityCollect(collect))
- {
- if (this.securityInfo["collect_photo"] == "已采集")
- {
- this.securityInfo["status"] = "2";
- this.securityInfo["collect_fingerprint"] = "已采集";
- if (this.editSecurityBassInfo(this.securityInfo))
- {
- MessageBox.Show("信息上传成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- clear();
- }
- }
- else
- {
- this.securityInfo["collect_fingerprint"] = "已采集";
- this.editSecurityBassInfo(this.securityInfo);
- // 上传头像信息,并修改保安员状态
- string upLoadUrl = string.Format(constants.filehost, "baoan", "collect", DateTime.Now.ToString("yyyyMMdd"), this.securityInfo["card"]);
- Dictionary<string, string> upLoadRes = HttpUitls.UploadImage(upLoadUrl, this.picUser.ImageLocation, constants.userToken);
- if (upLoadRes["code"] != "0")
- {
- Dictionary<string, Object> tempData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(upLoadRes["data"]);
- if (tempData["errcode"].ToString() == "0")
- {
- //Dictionary<string, Object> upLoadResData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(tempData["data"].ToString());
- collect = new Dictionary<string, string>();
- collect["name"] = this.securityInfo["name"];
- collect["security_guard_id"] = this.securityInfo["id"];
- collect["type"] = "人像";
- collect["data"] = tempData["uri"].ToString();
- collect["collect_personal"] = this.loginUser["name"];
- collect["collect_police"] = this.loginUser["belong_company"];
- if (this.createSecurityCollect(collect))
- {
- // 全部处理成功后,修改保安员状态
- this.securityInfo["collect_photo"] = "已采集";
- this.securityInfo["status"] = "2";
- if (this.editSecurityBassInfo(this.securityInfo))
- {
- MessageBox.Show("信息上传成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- clear();
- }
- }
- }
- }
- }
- }
- else
- {
- MessageBox.Show("指纹信息保存失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- else
- {
- MessageBox.Show("没有需要提交写信息,请重新操作!", "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- this.btnOK.Enabled = false;
- }
- }
- bool editSecurityBassInfo(Dictionary<string, string> security)
- {
- bool rest = false;
- // 创建修改链接
- string url = constants.host + string.Format(constants.update, "security_guard_base") + "?id=" + security["id"];
- string data = JsonConvert.SerializeObject(security);
- Dictionary<string, string> res = HttpUitls.Post(url, data, "", constants.userToken);
- if (res["code"] == "0")
- {
- MessageBox.Show("系统出现异常,请联系管理员进行处理!\r\n错误信息:" + res["message"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- Dictionary<string, Object> retData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (retData["errcode"].ToString() == "0")
- {
- rest = true;
- }
- else
- {
- MessageBox.Show("服务端返回异常信息,请联系管理员!\r\n异常信息:" + retData["errmsg"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- return rest;
- }
- bool editSecurityOtherInfo(Dictionary<string, string> securityOther)
- {
- bool rest = false;
- // 创建修改链接
- string url = constants.host + string.Format(constants.update, "security_guard_others") + "?id=" + securityOther["id"];
- string data = JsonConvert.SerializeObject(securityOther);
- Dictionary<string, string> res = HttpUitls.Post(url, data, "", constants.userToken);
- if (res["code"] == "0")
- {
- MessageBox.Show("系统出现异常,请联系管理员进行处理!\r\n错误信息:" + res["message"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- Dictionary<string, Object> retData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (retData["errcode"].ToString() == "0")
- {
- rest = true;
- }
- else
- {
- MessageBox.Show("服务端返回异常信息,请联系管理员!\r\n异常信息:" + retData["errmsg"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- return rest;
- }
- bool createSecurityCollect(Dictionary<string, string> collect)
- {
- bool rest = false;
- // 创建修改链接
- string url = constants.host + string.Format(constants.install, "security_guard_collect");
- string data = JsonConvert.SerializeObject(collect);
- Dictionary<string, string> res = HttpUitls.Post(url, data, "", constants.userToken);
- if (res["code"] == "0")
- {
- MessageBox.Show("系统出现异常,请联系管理员进行处理!\r\n错误信息:" + res["message"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- Dictionary<string, Object> retData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res["data"]);
- if (retData["errcode"].ToString() == "0")
- {
- rest = true;
- }
- else
- {
- MessageBox.Show("服务端返回异常信息,请联系管理员!\r\n异常信息:" + retData["errmsg"], "系统异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- return rest;
- }
- private void btnGetImage_Click(object sender, EventArgs e)
- {
- string filePath = Application.StartupPath + "\\" + constants.tempFiles;
- string fileName = "tempImage.png";
- string outputStr = this.hcUSBUtils.CaptureFace(filePath, fileName);
- if (outputStr != null)
- {
- try
- {
- Dictionary<string, string> d1 = JsonConvert.DeserializeObject<Dictionary<string, string>>(outputStr);
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + d1["statusString"], "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- catch (Exception)
- {
- XmlDocument xdoc = new XmlDocument();
- xdoc.LoadXml(outputStr);
- XmlNamespaceManager nsMgr = new XmlNamespaceManager(xdoc.NameTable);
- nsMgr.AddNamespace("ns", "http://www.isapi.org/ver20/XMLSchema");
- XmlNode statusNode = xdoc.SelectSingleNode("/ns:ResponseStatus/ns:statusString", nsMgr);
- if (statusNode != null)
- {
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + statusNode.InnerText, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- XmlNode captureProgressNode = xdoc.SelectSingleNode("/ns:CaptureFaceData/ns:captureProgress", nsMgr);
- if (captureProgressNode != null && captureProgressNode.InnerText == "100")
- {
- // 使用第一张图片
- string fileFullPath = filePath + "\\0_" + fileName;
- this.picUser.ImageLocation = fileFullPath;
- }
- else
- {
- MessageBox.Show("人像采集失败,请重新尝试。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- }
- private void btnGetFingerprint_Click(object sender, EventArgs e)
- {
- string inputStr = "<CaptureFingerPrintCond xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\">" +
- "<fingerNo>1</fingerNo>" +
- "</CaptureFingerPrintCond>";
- string outputStr = this.hcUSBUtils.CollectionNoImage(2, inputStr).TrimEnd('\0');
- if (outputStr != null)
- {
- try
- {
- Dictionary<string, string> d1 = JsonConvert.DeserializeObject<Dictionary<string, string>>(outputStr);
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + d1["statusString"], "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- catch (Exception)
- {
- XmlDocument xdoc = new XmlDocument();
- xdoc.LoadXml(outputStr);
- XmlNamespaceManager nsMgr = new XmlNamespaceManager(xdoc.NameTable);
- nsMgr.AddNamespace("ns", "http://www.isapi.org/ver20/XMLSchema");
- //outputStr = JsonConvert.SerializeXmlNode(xdoc.FirstChild);
- XmlNode statusNode = xdoc.SelectSingleNode("/ns:ResponseStatus/ns:statusString", nsMgr);
- if (statusNode != null)
- {
- MessageBox.Show("设备未返回正确信息请重新尝试!错误信息:" + statusNode.InnerText, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- XmlNode fingerDataNode = xdoc.SelectSingleNode("/ns:CaptureFingerPrint/ns:fingerData", nsMgr);
- if (fingerDataNode != null)
- {
- string finger = fingerDataNode.InnerText;
- this.labUserFingerprint.Text = finger;
- }
- else
- {
- MessageBox.Show("指纹采集失败,请重新尝试。", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- }
- string getDate(string str)
- {
- string yyyy = str.Substring(0,4);
- string mm = str.Substring(4, 2);
- string dd = str.Substring(6, 2);
- return yyyy + "年" + mm + "月" + dd + "日";
- }
- }
- }
|