private void btnSave_Click(object sender, EventArgs e) { if (tbName.Text == "" || tbName == null) { MessageBox.Show("이름을 입력하세요.", "알림", MessageBoxButtons.OK); return; } else if (tbIdnum.Text == "" || tbIdnum == null) { MessageBox.Show("주민번호를 입력하세요.", "알림", MessageBoxButtons.OK); return; } else if (tbPhone.Text == "" || tbPhone == null) { MessageBox.Show("연락처를 입력하세요.", "알림", MessageBoxButtons.OK); return; } else if (pbFingerPrint.Image == null) { MessageBox.Show("지문을 입력하세요.", "알림", MessageBoxButtons.OK); return; } if (MessageBox.Show("저장하시겠습니까?", "알림", MessageBoxButtons.YesNo) == DialogResult.Yes) { int rtn = 0; byte[] iBytes = BBDataConverter.ImageToByte(BBDataConverter.GrayRawToBitmap(fingerSensor.getRawImage(), FingerSensorPacket.SIZE_FP_WIDTH, FingerSensorPacket.SIZE_FP_HEIGHT)); m_user = userManager.Enroll(iBytes, tbName.Text, tbIdnum.Text, tbPhone.Text, tbEmail.Text); switch (mode) { case MODE.SAVE: rtn = userManager.InsertUser(m_user); break; case MODE.MODIFY: m_user.Id = Int32.Parse(tbId.Text.ToString()); rtn = userManager.UpdateUser(m_user); break; } if (rtn > 0) { StatusMessage("사용자(" + m_user.Name + ") 정보가 저장되었습니다."); this.DialogResult = DialogResult.OK; this.Close(); } else { StatusMessage("사용자(" + m_user.Name + ") 정보가 저장되지 않았습니다."); } } }
private void btnConfirm_Click(object sender, EventArgs e) { try { EnableFingerPrintComponent(false); if (fingerSensor.CmdCmosLed(true) == 0) { UpdateStatusMessage("Input your finger on sensor."); if (fingerSensor.CmdCaptureFinger() == 0) { UpdateStatusMessage("Exporting deleted fingerprint data"); if (fingerSensor.CmdGetRawImage() == 0) { UpdateStatusMessage("Succeed export fingerprint data."); pbImage.Image = BBDataConverter.GrayRawToBitmap(fingerSensor.getRawImage(), FingerSensorPacket.SIZE_FP_WIDTH, FingerSensorPacket.SIZE_FP_HEIGHT); UserManager fpm = new UserManager(); MyPerson guest = fpm.Enroll(BBDataConverter.ImageToByte(pbImage.Image), "guest"); MyPerson match = fpm.recognition(guest); if (match != null) { UpdateCompLogMsg("Matched person(" + match.Name + "): " + VerifyUserMatchRate(guest, match)); } else { UpdateCompLogMsg("No matching person found."); } UpdateCompMatchedUser(match); } else { UpdateStatusMessage("Failed export fingerparint data."); } } else { UpdateStatusMessage("Time out or can not delected fingerprint."); } } } catch (Exception ex) { Console.WriteLine(ex.Message); UpdateStatusMessage("Failed export fingerparint data."); } finally { fingerSensor.CmdCmosLed(false); EnableFingerPrintComponent(true); } }
private void btnScan_Click(object sender, EventArgs e) { if (pbFingerPrint.Image != null) { if (MessageBox.Show("지문 정보를 변경하시겠습니까?", "알림", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } try { EnableFingerPrintButton(false); if (fingerSensor.CmdCmosLed(true) == 0) { StatusMessage("Input your finger on sensor."); if (fingerSensor.CmdCaptureFinger() == 0) { StatusMessage("Exporting deleted fingerprint data"); if (fingerSensor.CmdGetRawImage() == 0) { StatusMessage("Succeed export fingerprint data."); Invoke((MethodInvoker) delegate { pbFingerPrint.Image = BBDataConverter.GrayRawToBitmap(fingerSensor.getRawImage(), FingerSensorPacket.SIZE_FP_WIDTH, FingerSensorPacket.SIZE_FP_HEIGHT); }); } else { StatusMessage("Failed export fingerparint data."); } } else { StatusMessage("Time out or can not delected fingerprint."); } } } catch (Exception ex) { Console.WriteLine(ex.Message); StatusMessage("Failed export fingerparint data."); } finally { fingerSensor.CmdCmosLed(false); EnableFingerPrintButton(true); } }
//public static Packet ByteToStruct(byte[] buffer) //{ // MemoryStream ms = new MemoryStream(buffer, false); // return ByteToStruct(ms); //} //public static Packet ByteToStruct(MemoryStream ms) //{ // BinaryReader br = new BinaryReader(ms); // try // { // Packet pkt = new Packet(); // pkt.type = (PktType)br.ReadInt32(); // pkt.userId = br.ReadInt32(); // pkt.carId = StringUtil.ExtendedTrim(Encoding.UTF8.GetString(br.ReadBytes(16))); // pkt.response = br.ReadInt32(); // pkt.dataLen = br.ReadInt32(); // switch (pkt.type) // { // case PktType.AUTH: // pkt.data = br.ReadBytes(pkt.dataLen); // //pkt.fingerPrint = Image.FromStream(new MemoryStream(pkt.data)); // //pkt.fingerPrint = Image.FromStream(new MemoryStream(BBDataConverter.ImageToByte(BBDataConverter.GrayRawToBitmap(pkt.data, 160, 120)))); // pkt.fingerPrint = BBDataConverter.BytesToImage(pkt.data); // break; // case PktType.PASSENGER: // pkt.guid = BBDataConverter.ByteToString(br.ReadBytes(pkt.dataLen - 4)); // pkt.psgCnt = BitConverter.ToInt32(br.ReadBytes(4), 0); // break; // case PktType.ORDER: // pkt.guid = BBDataConverter.ByteToString(br.ReadBytes(pkt.dataLen - 4)); // pkt.accessId = BitConverter.ToInt32(br.ReadBytes(4), 0); // break; // } // br.Close(); // ms.Close(); // return pkt; // } // catch (Exception e) // { // throw e; // } //} public static Packet DataParser(MemoryStream ms, Packet pkt) { BinaryReader br = new BinaryReader(ms); try { pkt.data = br.ReadBytes(pkt.dataLen); switch (pkt.type) { case PktType.AUTH: pkt.fingerPrint = BBDataConverter.GrayRawToBitmap(FingerSensor.ScaleImage320x240(pkt.data), FingerSensorPacket.SIZE_FP_WIDTH, FingerSensorPacket.SIZE_FP_HEIGHT); break; case PktType.PASSENGER: pkt.guid = BBDataConverter.ByteToString(pkt.data.Take(pkt.dataLen - 4).ToArray()); //pkt.guid = BBDataConverter.ByteToString(br.ReadBytes(pkt.dataLen - 4)); //pkt.psgCnt = BitConverter.ToInt32(br.ReadBytes(4), 0); pkt.psgCnt = BBDataConverter.BytesToInt32(pkt.data.Skip(pkt.dataLen - 4).ToArray()); break; case PktType.ORDER: pkt.guid = BBDataConverter.ByteToString(pkt.data.Take(pkt.dataLen - 4).ToArray()); //pkt.guid = BBDataConverter.ByteToString(br.ReadBytes(pkt.dataLen - 4)); //pkt.accessId = BitConverter.ToInt32(br.ReadBytes(4), 0); pkt.accessId = BBDataConverter.BytesToInt32(pkt.data.Skip(pkt.dataLen - 4).ToArray()); break; case PktType.ONCE: pkt.psgCnt = BBDataConverter.BytesToInt32(pkt.data.Take(19200).ToArray()); pkt.fingerPrint = BBDataConverter.GrayRawToBitmap(FingerSensor.ScaleImage320x240(pkt.data.Skip(4).ToArray()), FingerSensorPacket.SIZE_FP_WIDTH, FingerSensorPacket.SIZE_FP_HEIGHT); break; } br.Close(); ms.Close(); return(pkt); } catch (Exception e) { throw e; } }