Files
lserp_cs_6.0/插件库/PubFingerPrint/FrmMain.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

295 lines
12 KiB
C#

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 事件
/// <summary>
/// 初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// 释放时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// 部门查询值改变
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
/// <summary>
/// 删除按钮点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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));
}
}
/// <summary>
/// 行序号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 方法
/// <summary>
/// 初始化左侧搜索
/// </summary>
private void InitLeftSearchControl()
{
this.DepartmentSearch.TextEdit.EditValueChanged += OnDepartmentEditValueChanged;
}
/// <summary>
/// 初始化左侧员工表
/// </summary>
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));
}
}
/// <summary>
/// 初始化右侧员工表
/// </summary>
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;
}
/// <summary>
/// <para>说明:初始化部门数据</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2019-06-24 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
private void InitializeDeps()
{
DataTable table = WorkFlowBaseImpl.GetDeps();
this.DepartmentSearch.ValueMember = "departmentid";
this.DepartmentSearch.ValueField = "departmentid";
this.DepartmentSearch.TextField = "departmentname";
this.DepartmentSearch.SetDataSource(table);
}
/// <summary>
/// 获取员工信息
/// </summary>
/// <param name="depid"></param>
/// <param name="mf"></param>
/// <returns></returns>
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);
}
/// <summary>
/// 检查员工表列
/// </summary>
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
}
}