using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; using libzkfpcsharp; using Lskj.Control; using Lskj.Control.Model; using Lskj.Control.ZKFinger; using Lskj.Core; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace Lskj.PubFingerPrint { public partial class FingerControl : UserControl { public DataRow focusedRow; public bool isDoCapture = false; public GridControl PrintUserControl { get { return this.EmployeeControl; } } public GridView PrintUserView { get { return this.EmployeeView; } } public FingerControl() { InitializeComponent(); } public byte[] FingerBuffer { get { return StaticControl.fingerHelper.CapTmp; } } public void OnFrmFingerLoad(DataRow row) { try { this.focusedRow = row; string userName = row["员工姓名"] + ""; string userId = row["employeeid"] + ""; string loginaccount = row["员工工号"] + ""; string departName = row["departmentname"] + ""; this.userNameText.Text = userName; this.userIdText.Text = userId; this.userAcountText.Text = loginaccount; this.userDepartText.Text = departName; InfoLabel.Text = "请放手指"; } catch (Exception ex) { InfoLabel.Text = ex.Message; this.focusedRow = null; } } public void DoCapture() { while (!isDoCapture) { try { int cbCapTmp = 2048; int ret = zkfp2.AcquireFingerprint(StaticControl.fingerHelper.mDevHandle, StaticControl.fingerHelper.FPBuffer, StaticControl.fingerHelper.CapTmp, ref cbCapTmp); if (ret == zkfp.ZKFP_ERR_OK) { if (this.focusedRow != null) { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(StaticControl.fingerHelper.FPBuffer, StaticControl.fingerHelper.mfpWidth, StaticControl.fingerHelper.mfpHeight, ref ms); Bitmap bmp = new Bitmap(ms); ShowImg(bmp); } else { MessageUtil.Show("请选择录入人员"); } } } catch (Exception) { } } } private void ShowImg(Bitmap bt) { if (this.InvokeRequired) { this.Invoke(new Action(() => { FingerPicBox.Image = bt; })); } else { FingerPicBox.Image = bt; } } private void saveBtn_Click(object sender, EventArgs e) { if (StaticControl.fingerHelper.FPBuffer == null || StaticControl.fingerHelper.FPBuffer.Length == 0 || this.focusedRow == null) { MessageUtil.Show("请录入指纹后再保存"); } else { try { string saveSql = string.Format("update P_EmployeeTab set FingerBuffer = @Picture,IsFingerPrint = 1 where EmployeeId = '{0}'", this.userIdText.Text); SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@Picture",SqlDbType.Binary,FingerBuffer.Length), }; cmdParams[0].Value = FingerBuffer; int result = SqlHelper.ExecuteNonQuery(CommandType.Text, saveSql, cmdParams); if (result == 1) { MessageUtil.Show("指纹信息录入成功"); DataTable sourceTable = this.EmployeeControl.DataSourceTable(); DataRow addRow = sourceTable.NewRow(); addRow.ItemArray = this.focusedRow.ItemArray; this.focusedRow.Table.Rows.Remove(this.focusedRow); sourceTable.Rows.Add(addRow); } else { MessageUtil.Show("指纹信息录入失败,请重试"); } } catch (Exception ex) { MessageUtil.Show(string.Format("指纹信息录入失败,{0}", ex.Message)); } } } } }