ab56a9bcf7
SVN-Revision: r240
413 lines
17 KiB
C#
413 lines
17 KiB
C#
using DevExpress.XtraGrid.Columns;
|
|
using Lskj.Business;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Control.Model;
|
|
using Lskj.Core;
|
|
using Lskj.Data;
|
|
using Lskj.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubUserPrivate
|
|
{
|
|
public partial class FrmMain : Form
|
|
{
|
|
/// <summary>
|
|
/// 全部的人员
|
|
/// </summary>
|
|
public DataTable AllUserTable = new DataTable();
|
|
/// <summary>
|
|
/// 全部的私有人员人员
|
|
/// </summary>
|
|
public DataTable AllPrivateUserTable = new DataTable();
|
|
/// <summary>
|
|
/// 全部的私密人员
|
|
/// </summary>
|
|
public List<string> AllPrivateUser = new List<string>();
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
this.Load += FrmMain_Load;
|
|
}
|
|
/// <summary>
|
|
/// 窗体加载时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmMain_Load(object sender, EventArgs e)
|
|
{
|
|
if (CheckPrivateUserTable())
|
|
{
|
|
this.AllUserTable = GetUsersInfo("", "");
|
|
this.AllPrivateUserTable = this.AllUserTable.Clone();
|
|
this.AllPrivateUser = GetPrivateUsersInfo();
|
|
this.AllUserTable.DefaultView.Sort = "employeeid";
|
|
this.AllPrivateUserTable.DefaultView.Sort = "employeeid";
|
|
InitGrid();
|
|
InitBtn();
|
|
|
|
}
|
|
else
|
|
{
|
|
Lskj.Control.MessageUtil.Show("私有模块数据表不存在或功能未开启,请联系管理员");
|
|
return;
|
|
}
|
|
}
|
|
private void InitBtn()
|
|
{
|
|
this.Save.Click += new EventHandler(OnPrivateSave);
|
|
this.SetRemovePermissions.Click += new EventHandler(OnPrivateDeleteClick);
|
|
}
|
|
/// <summary>
|
|
/// 初始化左侧表格
|
|
/// </summary>
|
|
private void InitGrid()
|
|
{
|
|
|
|
this.AllQuickControlEx.GridView.Columns.AddVisible("loginaccount", "员工工号").MinWidth = 100;
|
|
this.AllQuickControlEx.GridView.Columns.AddVisible("employeename", "员工姓名").MinWidth = 200;
|
|
this.AllQuickControlEx.GridView.Columns.AddVisible("departmentname", "部门名称").MinWidth = 200;
|
|
|
|
this.checkGrid.GridView.Columns.AddVisible("loginaccount", "员工工号").MinWidth = 100;
|
|
this.checkGrid.GridView.Columns.AddVisible("employeename", "员工姓名").MinWidth = 200;
|
|
this.checkGrid.GridView.Columns.AddVisible("departmentname", "部门名称").MinWidth = 200;
|
|
|
|
this.AllQuickControlEx.GridView.BestFitColumns();//设置根据内容填充列宽
|
|
this.AllQuickControlEx.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;
|
|
|
|
GridDragGrid dragPrivateGrid = new GridDragGrid(this.AllQuickControlEx.GridView, this.checkGrid.GridView);
|
|
GridDragGrid dragPrivateGridNew = new GridDragGrid(this.checkGrid.GridView, this.AllQuickControlEx.GridView);
|
|
|
|
GridDragGrid.GridAddCheckBox(this.checkGrid.GridView);
|
|
GridDragGrid.GridAddCheckBox(this.AllQuickControlEx.GridView);
|
|
|
|
this.checkGrid.GridView.OptionsSelection.EnableAppearanceFocusedCell = false;
|
|
this.AllQuickControlEx.GridControl.AllowDrop = true;
|
|
this.checkGrid.GridControl.AllowDrop = true;
|
|
this.AllQuickControlEx.GridView.OptionsBehavior.Editable = false;
|
|
this.checkGrid.GridView.OptionsBehavior.Editable = false;
|
|
this.AllQuickControlEx.GridView.OptionsCustomization.AllowSort = false;
|
|
this.checkGrid.GridView.OptionsCustomization.AllowSort = false;
|
|
|
|
this.AllQuickControlEx.gridControl.DataSource = AllUserTable;
|
|
this.checkGrid.GridControl.DataSource = AllPrivateUserTable;
|
|
this.AllQuickControlEx.GridView.BestFitColumns();
|
|
this.checkGrid.GridView.BestFitColumns();
|
|
foreach (string item in AllPrivateUser)
|
|
{
|
|
try
|
|
{
|
|
DataRow dataRow = AllUserTable.Select().Where(n => (n["employeeid"] + "").Equals(item)).FirstOrDefault();
|
|
if (dataRow != null)
|
|
{
|
|
AllPrivateUserTable.Rows.Add(dataRow.ItemArray);
|
|
AllUserTable.Rows.Remove(dataRow);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
public void PrivateAccessPermissions(DataRow rowItem, string privateTag)
|
|
{
|
|
DataRow dr = this.AllPrivateUserTable.NewRow();
|
|
dr.ItemArray = rowItem.ItemArray;
|
|
this.AllPrivateUserTable.Rows.Add(dr);
|
|
}
|
|
/// <summary>
|
|
/// 判断私有模块权限表格是否存在
|
|
/// </summary>
|
|
private bool CheckPrivateUserTable()
|
|
{
|
|
try
|
|
{
|
|
string alterSql = "";
|
|
if (!BaseImpl.HasExistsColumn("p_employeeTab", "isPrivateLogin"))
|
|
{
|
|
alterSql += "alter table p_employeeTab add isPrivateLogin int;";
|
|
}
|
|
if (!string.IsNullOrEmpty(alterSql))
|
|
{
|
|
SqlHelper.ExecuteNonQuery(alterSql);
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 下方数据删除,上方取消勾选
|
|
/// </summary>
|
|
/// <param name="rowItem"></param>
|
|
public void RemovePermissions(DataRow rowItem)
|
|
{
|
|
DataRow dr = this.AllUserTable.NewRow();
|
|
dr.ItemArray = rowItem.ItemArray;
|
|
this.AllUserTable.Rows.Add(dr);
|
|
}
|
|
#region 事件
|
|
/// <summary>
|
|
/// 设置私密权限保存事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnPrivateSave(object sender, EventArgs e)
|
|
{
|
|
//if (!CheckPassWord())
|
|
//{
|
|
// return;
|
|
//}
|
|
int[] rowNumbers = this.AllQuickControlEx.GridView.GetSelectedRows();
|
|
List<DataRow> addRows = new List<DataRow>();
|
|
foreach (int rowIndex in rowNumbers)
|
|
{
|
|
DataRow rowItem = this.AllQuickControlEx.GridView.GetDataRow(rowIndex);
|
|
addRows.Add(rowItem);
|
|
}
|
|
foreach (DataRow dr in addRows)
|
|
{
|
|
PrivateAccessPermissions(dr, "1");
|
|
this.AllUserTable.Rows.Remove(dr);
|
|
}
|
|
SaveProvate();
|
|
}
|
|
/// <summary>\
|
|
/// 删除权限 QuickOperationControlEx表
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnPrivateDeleteClick(object sender, EventArgs e)
|
|
{
|
|
//if (!CheckPassWord())
|
|
//{
|
|
// return;
|
|
//}
|
|
int[] rowNumbers = this.checkGrid.GridView.GetSelectedRows();
|
|
if (rowNumbers.Length == 0) return;
|
|
List<DataRow> deleteRows = new List<DataRow>();
|
|
|
|
foreach (int rowIndex in rowNumbers)
|
|
{
|
|
DataRow rowItem = this.checkGrid.GridView.GetDataRow(rowIndex);
|
|
deleteRows.Add(rowItem);
|
|
}
|
|
|
|
foreach (DataRow dr in deleteRows)
|
|
{
|
|
RemovePermissions(dr);
|
|
this.AllPrivateUserTable.Rows.Remove(dr);
|
|
}
|
|
SaveProvate();
|
|
}
|
|
/// <summary>
|
|
/// 检查密码状态
|
|
/// </summary>
|
|
private bool CheckPassWord()
|
|
{
|
|
bool isCheck = false;
|
|
int keyHandle = ERPInfo.Instance.keyHandles[0];
|
|
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
|
|
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
|
|
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
|
|
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
|
|
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
|
|
if (rtn == 0)
|
|
{
|
|
byte[] readBuffer = new byte[256];
|
|
int add = 0;
|
|
int len = 256;
|
|
int readPageRtn = SmartX1Api.SmartX1ReadPage(keyHandle, 1, add, ref len, readBuffer);
|
|
if (readPageRtn == 0)
|
|
{
|
|
string savePassword = Encoding.Default.GetString(readBuffer);
|
|
if (savePassword.Equals(ERPInfo.Instance.dogVerifyPasswordDefault) || string.IsNullOrWhiteSpace(savePassword.Replace("\0", "")))
|
|
{
|
|
MessageUtil.Show("当前未设置U盾密码,请设置后重试");
|
|
}
|
|
else
|
|
{
|
|
isCheck = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
}
|
|
SmartX1Api.SmartX1Close(keyHandle);
|
|
return isCheck;
|
|
}
|
|
/// <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,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 List<string> GetPrivateUsersInfo()
|
|
{
|
|
List<string> readVerifyStrList = new List<string>();
|
|
try
|
|
{
|
|
int keyHandle = ERPInfo.Instance.keyHandles[0];
|
|
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
|
|
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
|
|
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
|
|
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
|
|
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
|
|
if (rtn == 0)
|
|
{
|
|
string writeKey = string.Format("{0}_{1}", DBConfig.Instance.ServerName, DBConfig.Instance.DataBase);
|
|
int length = 256;
|
|
byte[] readBuffer = new byte[length];
|
|
int readRtn = SmartX1Api.SmartX1ReadPage(keyHandle, 1, 0, ref length, readBuffer);
|
|
if (readRtn == 0)
|
|
{
|
|
Dictionary<string, string> readKeysValues = new Dictionary<string, string>();
|
|
string readVerifyStr = Encoding.Default.GetString(readBuffer);
|
|
string[] readVerifyStrArray = readVerifyStr.Replace("\0", "").Split(';');//获取多个账套设置
|
|
foreach (string readVerify in readVerifyStrArray)
|
|
{
|
|
string[] readKeyValue = readVerify.Split('^');//获取单个账套
|
|
if (readKeyValue.Length == 2)
|
|
{
|
|
readKeysValues.Add(readKeyValue[0], readKeyValue[1]);
|
|
}
|
|
}
|
|
if (readKeysValues.ContainsKey(writeKey))//如果存在当前账套
|
|
{
|
|
readVerifyStrList = readKeysValues[writeKey].Split('^').ToList();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return readVerifyStrList;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return readVerifyStrList;
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return readVerifyStrList;
|
|
}
|
|
private void SaveProvate()
|
|
{
|
|
|
|
WaitForm.ShowForm(ResourceKeys.DataSaving);
|
|
try
|
|
{
|
|
|
|
string sql = string.Empty;
|
|
string writeStr = string.Empty;
|
|
foreach (DataRow dr in this.AllPrivateUserTable.Rows)
|
|
{
|
|
writeStr += string.Format("{0},", dr["employeeid"] + "");
|
|
}
|
|
int keyHandle = ERPInfo.Instance.keyHandles[0];
|
|
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
|
|
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
|
|
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
|
|
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
|
|
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
|
|
if (rtn == 0)
|
|
{
|
|
string writeKey = string.Format("{0}_{1}", DBConfig.Instance.ServerName, DBConfig.Instance.DataBase);
|
|
int length = 256;
|
|
byte[] readBuffer = new byte[length];
|
|
int readRtn = SmartX1Api.SmartX1ReadPage(keyHandle, 1, 0, ref length, readBuffer);
|
|
if (readRtn == 0)
|
|
{
|
|
Dictionary<string, string> readKeysValues = new Dictionary<string, string>();
|
|
string readVerifyStr = Encoding.Default.GetString(readBuffer);
|
|
string[] readVerifyStrArray = readVerifyStr.Replace("\0", "").Split(';');//获取多个账套设置
|
|
foreach (string readVerify in readVerifyStrArray)
|
|
{
|
|
string[] readKeyValue = readVerify.Split('^');//获取单个账套
|
|
if (readKeyValue.Length == 2)
|
|
{
|
|
readKeysValues.Add(readKeyValue[0], readKeyValue[1]);
|
|
}
|
|
}
|
|
if (readKeysValues.ContainsKey(writeKey))//如果存在当前账套
|
|
{
|
|
readKeysValues[writeKey] = writeStr.TrimEnd(',');
|
|
}
|
|
else
|
|
{
|
|
readKeysValues.Add(writeKey, writeStr.TrimEnd(','));
|
|
}
|
|
string allWriteStr = string.Empty;
|
|
foreach (string key in readKeysValues.Keys)
|
|
{
|
|
allWriteStr += string.Format("{0}^{1};", key, readKeysValues[key]);
|
|
}
|
|
byte[] writeBuffer = Encoding.Default.GetBytes(allWriteStr);
|
|
int writeRtn = SmartX1Api.SmartX1WritePage(keyHandle, 1, 0, 256, writeBuffer);
|
|
if (writeRtn == 0)
|
|
{
|
|
MessageUtil.Show("保存成功");
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("U盾验证失败,请重试或联系管理员");
|
|
return;
|
|
}
|
|
SmartX1Api.SmartX1Close(keyHandle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show("保存失败");
|
|
}
|
|
finally
|
|
{
|
|
WaitForm.HideForm();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|