private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtDocumentNumberSearch.Text) || String.IsNullOrEmpty(txtDocumentNumberSearch.Text)) { MessageBox.Show("Please fill in all required fields"); } else { try { XmlSerial serial = new XmlSerial(); DTO.StaffMember staffMember = new DTO.StaffMember(); staffMember.name = this.lblNameResult.Text; staffMember.documentNumber = this.lblDocumentNumberResult.Text; staffMember.fingerprint = Functions.ImageToByteArray(this.picFingerprint.Image); staffMember.fingerprintTemplateBytes = MemTemplate.Bytes; staffMember.fingerprintTemplateSize = MemTemplate.Size; String XmlizedString = serial.SerializeObject(staffMember); XmlDocument xmlDoc = new XmlDocument(); string path = Path.GetFullPath("DB/StaffRepository.xml"); xmlDoc.Load(path); StaffMemberList staffMembers = serial.DeserializeObject <StaffMemberList>(xmlDoc.InnerXml); if (staffMembers.staffMemberList != null) { if (staffMembers.staffMemberList.Where(s => s.documentNumber == staffMember.documentNumber).Count() > 0) { var val = staffMembers.staffMemberList.Where(s => s.documentNumber == staffMember.documentNumber).FirstOrDefault(); val.name = staffMember.name; val.fingerprint = staffMember.fingerprint; } else { List <DTO.StaffMember> smList = staffMembers.staffMemberList.ToList(); smList.Add(staffMember); staffMembers.staffMemberList = smList.ToArray(); } } else { List <DTO.StaffMember> smList = new List <DTO.StaffMember>(); smList.Add(staffMember); staffMembers.staffMemberList = smList.ToArray(); } XmlizedString = serial.SerializeObject <StaffMemberList>(staffMembers); xmlDoc = new XmlDocument(); xmlDoc.InnerXml = XmlizedString; if (File.Exists(path)) { File.Delete(path); } xmlDoc.Save(path); byte[] fingerprint = Functions.ImageToByteArray(this.picFingerprint.Image); UpdateStaffFingerprint(currentStaffMember); MessageBox.Show(this, "Staff member updated successfully!", "OTC", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); Close(); } catch (Exception ex) { MessageBox.Show(this, string.Format("Error trying to save the staff member. Exception: {0}", ex.Message), "OTC", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
protected void Compare(Template template, Sample sample, string type) { DPFP.FeatureSet features = ExtractFeatures(sample, DPFP.Processing.DataPurpose.Verification); DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result(); XmlSerial serial = new XmlSerial(); XmlDocument xmlDoc = new XmlDocument(); string path = Path.GetFullPath("DB/StaffRepository.xml"); xmlDoc.Load(path); StaffMemberList staffMembers = serial.DeserializeObject <StaffMemberList>(xmlDoc.InnerXml); foreach (DTO.StaffMember staffMember in staffMembers.staffMemberList) { MemoryStream ms = new MemoryStream(staffMember.fingerprintTemplateBytes); template = new DPFP.Template(ms); Verificator.Verify(features, template, ref result); XmlSerial punchSerial = new XmlSerial(); XmlDocument punchXmlDoc = new XmlDocument(); Punch punch = new DTO.Punch(); string newPunchType = ""; string punchXmlizedString = punchSerial.SerializeObject(punch); string punchPath = Path.GetFullPath("DB/PunchRepository.xml"); punchXmlDoc.Load(punchPath); PunchList punches = punchSerial.DeserializeObject <PunchList>(punchXmlDoc.InnerXml); List <Punch> punchList = punches.punchList.ToList(); punch = new DTO.Punch(); if (punchList.Where(p => p.documentNumber == staffMember.documentNumber).Count() > 0) { var val = punches.punchList.Where(p => p.documentNumber == staffMember.documentNumber).Last(); if (val.type == "I") { newPunchType = "O"; } else if (val.type == "O") { newPunchType = "I"; } } else { newPunchType = "I"; } punch.type = newPunchType; punch.documentNumber = staffMember.documentNumber; punch.createdAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); punchList.Add(punch); punches.punchList = punchList.ToArray(); punchXmlizedString = punchSerial.SerializeObject <PunchList>(punches); punchXmlDoc = new XmlDocument(); punchXmlDoc.InnerXml = punchXmlizedString; if (features != null) { if (result.Verified) { if (lblStaffMemberNameResult.InvokeRequired) { lblStaffMemberNameResult.BeginInvoke((MethodInvoker) delegate { lblStaffMemberNameResult.Visible = true; lblStaffMemberNameResult.Text = staffMember.name; }); } if (lblPunchDateTimeResult.InvokeRequired) { lblPunchDateTimeResult.BeginInvoke((MethodInvoker) delegate { lblPunchDateTimeResult.Visible = true; lblPunchDateTimeResult.Text = DateTime.Now.ToString("HH:mm:ss"); if (punch.type == "I") { lblPunchTypeResult.ForeColor = System.Drawing.Color.Blue; lblPunchTypeResult.Visible = true; lblPunchTypeResult.Text = "IN"; } else if (punch.type == "O") { lblPunchTypeResult.ForeColor = System.Drawing.Color.Red; lblPunchTypeResult.Visible = true; lblPunchTypeResult.Text = "OUT"; } else { lblPunchTypeResult.ForeColor = System.Drawing.Color.Blue; lblPunchTypeResult.Text = "IN"; } }); } if (picCheck.InvokeRequired) { picCheck.BeginInvoke((MethodInvoker) delegate { picCheck.Visible = true; picCheck.Image = (Image)Resources.ResourceManager.GetObject("check"); }); } System.Media.SystemSounds.Beep.Play(); punchXmlDoc.Save(punchPath); SavePunch(punch); } } } Thread.Sleep(1000); ClearFields(); }