using DevExpress.Utils; using DevExpress.XtraGrid.Views.Grid; using Lskj.Business.Impl; 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.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace Lskj.PubFingerPrint { public partial class FrmMain : Form { public ContextMenuStrip menuStrip = new ContextMenuStrip(); public Thread captureThread; public FrmMain() { InitializeComponent(); this.Load += FrmMain_Load; this.Disposed += FrmMain_Disposed; } #region 事件 /// /// 初始化 /// /// /// private void FrmMain_Load(object sender, EventArgs e) { try { if (!CheckTabColumns()) { MessageUtil.Show("数据表employeetab不存在FingerBuffer或IsFingerPrint列"); return; } if (StaticControl.fingerHelper != null) { StaticControl.fingerHelper.Close(); StaticControl.fingerHelper = null; } FingerHelper.FreeSensor(); StaticControl.fingerHelper = new FingerHelper(); StaticControl.fingerHelper.FPBuffer = new byte[StaticControl.fingerHelper.mfpWidth * StaticControl.fingerHelper.mfpHeight]; captureThread = new Thread(new ThreadStart(this.FrmFinger.DoCapture)); captureThread.IsBackground = true; captureThread.Start(); InitializeDeps(); InitLeftSearchControl(); InitLeftEmployeeGrid(); InitRightEmployeeGrid(); } catch (Exception ex) { MessageUtil.Show(ex.Message); } } /// /// 释放时 /// /// /// private void FrmMain_Disposed(object sender, EventArgs e) { this.FrmFinger.isDoCapture = true; if (StaticControl.fingerHelper != null) { StaticControl.fingerHelper.Close(); StaticControl.fingerHelper = null; } FingerHelper.FreeSensor(); if (captureThread != null) { captureThread.Abort(); } } private void OnFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e) { DataRow focusedRow = this.EmployeeView.GetDataRow(e.FocusedRowHandle); if (focusedRow != null) { this.FrmFinger.OnFrmFingerLoad(focusedRow); } } /// /// 部门查询值改变 /// /// /// private void OnDepartmentEditValueChanged(object sender, EventArgs e) { string depid = this.DepartmentSearch.EditValue; DataTable table = GetUsersInfo(depid, ""); DataTable sourceTab = table.Clone(); table.Select("isfingerprint=0").CopyToDataTable(sourceTab, LoadOption.OverwriteChanges); sourceTab.Columns["loginaccount"].ColumnName = "员工工号"; sourceTab.Columns["employeename"].ColumnName = "员工姓名"; this.EmployeeControl.DataSource = sourceTab; DataTable sourceRightTab = table.Clone(); table.Select("isfingerprint=1").CopyToDataTable(sourceRightTab, LoadOption.OverwriteChanges); sourceRightTab.Columns["loginaccount"].ColumnName = "员工工号"; sourceRightTab.Columns["employeename"].ColumnName = "员工姓名"; this.FrmFinger.PrintUserControl.DataSource = sourceRightTab; } /// /// 删除按钮点击 /// /// /// private void MenuStripItemClick(object sender, EventArgs e) { try { int[] selectIndexs = this.FrmFinger.PrintUserView.GetSelectedRows().OrderByDescending(n => n).ToArray(); foreach (int index in selectIndexs) { DataRow focusedUserRow = this.FrmFinger.PrintUserView.GetDataRow(index); if (focusedUserRow != null) { string employeeid = focusedUserRow["employeeid"] + ""; string saveSql = string.Format("update P_EmployeeTab set FingerBuffer = null,IsFingerPrint = 0 where EmployeeId = '{0}'", employeeid); SqlHelper.ExecuteNonQuery(saveSql); DataTable sourceTab = this.FrmFinger.PrintUserControl.DataSourceTable(); DataTable notPrintTab = this.EmployeeControl.DataSourceTable(); DataRow addRow = notPrintTab.NewRow(); addRow.ItemArray = focusedUserRow.ItemArray; sourceTab.Rows.Remove(focusedUserRow); notPrintTab.Rows.Add(addRow); } } } catch (Exception ex) { MessageUtil.Show(string.Format("删除失败,原因:{0}", ex.Message)); } } /// /// 行序号 /// /// /// private void OnCustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { try { e.Appearance.TextOptions.HAlignment = HorzAlignment.Center; if (e.Info.IsRowIndicator) { if (e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } } catch (Exception) { } } private void OnCustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { GridView gridView = (GridView)sender; try { if (e.RowHandle == gridView.FocusedRowHandle) e.Appearance.BackColor = ColorTranslator.FromHtml("#9feb6a"); } catch (Exception) { } } #endregion #region 方法 /// /// 初始化左侧搜索 /// private void InitLeftSearchControl() { this.DepartmentSearch.TextEdit.EditValueChanged += OnDepartmentEditValueChanged; } /// /// 初始化左侧员工表 /// private void InitLeftEmployeeGrid() { DataTable table = GetUsersInfo("", ""); DataTable sourceTab = table.Clone(); table.Select("isfingerprint=0").CopyToDataTable(sourceTab, LoadOption.OverwriteChanges); sourceTab.Columns["loginaccount"].ColumnName = "员工工号"; sourceTab.Columns["employeename"].ColumnName = "员工姓名"; this.EmployeeControl.DataSource = sourceTab; this.EmployeeView.OptionsBehavior.Editable = false; this.EmployeeView.OptionsSelection.MultiSelect = false; this.EmployeeView.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect; this.EmployeeView.FocusedRowObjectChanged += OnFocusedRowObjectChanged; this.EmployeeView.CustomDrawRowIndicator += OnCustomDrawRowIndicator; this.EmployeeView.CustomDrawCell += OnCustomDrawCell; if (sourceTab.Rows.Count > 0) { this.OnFocusedRowObjectChanged(null, new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs(0, null)); } } /// /// 初始化右侧员工表 /// private void InitRightEmployeeGrid() { DataTable table = GetUsersInfo("", ""); DataTable sourceTab = table.Clone(); table.Select("isfingerprint=1").CopyToDataTable(sourceTab, LoadOption.OverwriteChanges); sourceTab.Columns["loginaccount"].ColumnName = "员工工号"; sourceTab.Columns["employeename"].ColumnName = "员工姓名"; this.FrmFinger.PrintUserControl.DataSource = sourceTab; this.FrmFinger.PrintUserView.OptionsBehavior.Editable = false; this.FrmFinger.PrintUserView.OptionsSelection.MultiSelect = true; this.FrmFinger.PrintUserView.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CellSelect; this.FrmFinger.PrintUserView.CustomDrawRowIndicator += OnCustomDrawRowIndicator; this.FrmFinger.PrintUserView.CustomDrawCell += OnCustomDrawCell; ToolStripMenuItem menuItem = new ToolStripMenuItem(); menuItem.Text = "删除指纹"; menuItem.Click += new EventHandler(MenuStripItemClick); this.menuStrip.Items.Add(menuItem); this.FrmFinger.PrintUserControl.ContextMenuStrip = this.menuStrip; } /// /// 说明:初始化部门数据 /// 创建人:龚宇超 /// 创建日期:2019-06-24 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void InitializeDeps() { DataTable table = WorkFlowBaseImpl.GetDeps(); this.DepartmentSearch.ValueMember = "departmentid"; this.DepartmentSearch.ValueField = "departmentid"; this.DepartmentSearch.TextField = "departmentname"; this.DepartmentSearch.SetDataSource(table); } /// /// 获取员工信息 /// /// /// /// private DataTable GetUsersInfo(string depid, string mf) { string where = string.Empty; if (!string.IsNullOrEmpty(depid)) where = " and a.departmentid=" + depid; if (!string.IsNullOrEmpty(mf)) where = string.Format(" and (a.loginaccount like '%{0}%' or a.employeename like '%{0}%' or dbo.P_getpy(a.employeename) like '%{0}%')", mf); string sqlValue = "select a.loginaccount,a.employeeid,a.employeename,a.departmentid,a.fingerbuffer,isnull(a.isfingerprint,0) as isfingerprint,b.departmentname from p_employeeTab a left join P_DepartmentTab b on a.departmentid=b.departmentid where a.sign=0 and a.UseFlag=1 " + where + " order by a.employeeid"; return BaseImpl.GetDataTableResult(sqlValue); } /// /// 检查员工表列 /// private bool CheckTabColumns() { bool isCheck = false; try { string alterSql = ""; if (!BaseImpl.HasExistsColumn("p_employeeTab", "FingerBuffer")) { alterSql += "alter table p_employeeTab add FingerBuffer image;"; } if (!BaseImpl.HasExistsColumn("p_employeeTab", "IsFingerPrint")) { alterSql += "alter table p_employeeTab add IsFingerPrint int"; } if (!string.IsNullOrEmpty(alterSql)) { SqlHelper.ExecuteNonQuery(alterSql); } isCheck = true; } catch (Exception) { } return isCheck; } #endregion } }