/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0201.cs
* 2.功能描述:用户管理
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2014/09/12 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.DockPanel;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 用户管理
///
public partial class F_MST_0201 : DockPanelBase
{
#region 成员变量
// 单例模式
private static F_MST_0201 _instance;
// 最后选择行
private int _selecedRow;
// 用户管理实体类
private SUserEntity _userInfo;
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0201 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0201();
}
return _instance;
}
}
#endregion
#region 构造函数
public F_MST_0201()
{
InitializeComponent();
this.Text = FormTitles.F_MST_0201;
this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
this.tsbtnResetPassword.Text = ButtonText.TSBTN_RESETPASSWORD;
this.tsbtnUnlock.Text = ButtonText.TSBTN_UNLOCK;
this.tsbtnFunctionRight.Text = ButtonText.TSBTN_FUNCTIONRIGHT;
this.tsbtnPurviewRight.Text = ButtonText.TSBTN_PURVIEWRIGHT;
this.tsbPrintUserCode.Text = ButtonText.TSBTN_PRINTUSERCODE;
}
#endregion
#region 事件
///
/// 窗体加载事件
///
///
///
private void FrmUser_Load(object sender, EventArgs e)
{
try
{
//加载权限
//FormPermissionManager.FormPermissionControl(this.Name, this,
// Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
// Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
// 设置表格不自动创建列
this.dgvUser.AutoGenerateColumns = false;
this.SetToolStripButtonEnable();
this.scbOrganization.EditReadOnly = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 用户范围权限
///
///
///
private void tsbtnRight_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentRow != null)
{
string UserCode = this.dgvUser.CurrentRow.Cells["UserCode"].Value.ToString();
F_MST_0204 frmMST0204 = new F_MST_0204(Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value), UserCode);
DialogResult dialogResult = frmMST0204.ShowDialog();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 搜索按钮事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
// 根据页面设定用户实体值
this.GetUserEntityFromLayout();
// 记录当前选中行
int selectRowIndex = this._selecedRow;
// 异步处理
this.btnSearch.Enabled = false;
this.btnClearCondition.Enabled = false;
DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.SearchUserData));
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
this.scbOrganization.EditReadOnly = true;
if (userDataSet != null)
{
base.DataSource = (DataSet)userDataSet;
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
this.dgvUser.DataSource = this.DataSource.Tables[0];
//foreach (DataGridViewRow gvrFor in this.dgvUser.Rows)
//{
// string ValueStr = "";
// string ValueNum = gvrFor.Cells["ValueFlag"].Value.ToString();
// switch (ValueNum)
// {
// case "1":
// ValueStr = "正常";
// break;
// case "0":
// ValueStr = "停用";
// break;
// default:
// break;
// }
// gvrFor.Cells["checkValueFlag"].Value = ValueStr;
// string StateStr = gvrFor.Cells["IsLocked"].Value.ToString();
// if (StateStr == "1")
// {
// gvrFor.Cells["IsLocked"].Value = "锁死";
// }
// else
// {
// gvrFor.Cells["IsLocked"].Value = "正常";
// }
//}
if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
{
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (selectRowIndex >= Constant.INT_IS_ZERO)
{
if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
{
this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Selected = true;
this.dgvUser.CurrentCell = this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Cells["UserCode"];
}
else
{
this.dgvUser.Rows[selectRowIndex].Selected = true;
this.dgvUser.CurrentCell = this.dgvUser.Rows[selectRowIndex].Cells["UserCode"];
}
}
}
}
}
this.SetToolStripButtonEnable();
}
catch (Exception ex)
{
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 清空输入查询寻条件
///
///
///
private void btnClear_Click(object sender, EventArgs e)
{
this.txtUserCode.Clear();
this.txtUserName.Clear();
this.scbOrganization.ClearValue();
this.txtMAC.Clear();
this.txtRemarks.Clear();
this.chkVYes.Checked = true;
this.chkVNo.Checked = true;
this.chkLYes.Checked = true;
this.chkLNo.Checked = true;
}
///
/// 设置按钮的状态
///
///
///
private void dgvUser_SelectionChanged(object sender, EventArgs e)
{
if (dgvUser.CurrentCell == null)
{
this.tsbtnEdit.Enabled = false;
this.tsbtnResetPassword.Enabled = false;
this.tsbtnUnlock.Enabled = false;
this.tsbtnPurviewRight.Enabled = false;
this.tsbtnFunctionRight.Enabled = false;
}
else
{
string ValueFlag = this.dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells["IsLocked"].Value.ToString();
if (ValueFlag == "锁死" || ValueFlag == "1")
{
this.tsbtnUnlock.Enabled = true;
}
else
{
this.tsbtnUnlock.Enabled = false;
}
this.tsbtnEdit.Enabled = true;
this.tsbtnResetPassword.Enabled = true;
this.tsbtnPurviewRight.Enabled = true;
this.tsbtnFunctionRight.Enabled = true;
}
}
///
/// 选中行发生改变时 有效停用相互切换
///
///
///
private void dgvUser_CellEnter(object sender, DataGridViewCellEventArgs e)
{
this.SetToolStripButtonEnable();
if (dgvUser.Rows.Count > Constant.INT_IS_ZERO)
{
this._selecedRow = this.dgvUser.CurrentCell.RowIndex;
}
}
///
/// KeyDown事件
///
///
///
private void dgvUser_KeyDown(object sender, KeyEventArgs e)
{
try
{
// 拷贝
if (e.KeyData == (Keys.Control | Keys.C))
{
if (dgvUser.CurrentRow != null
&& !string.IsNullOrEmpty(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + string.Empty))
{
try
{
Clipboard.SetText(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + string.Empty);
}
catch
{
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 双击进入编辑页面
///
///
///
private void dgvUser_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (-Constant.INT_IS_ONE < e.RowIndex && -Constant.INT_IS_ONE < e.ColumnIndex && this.tsbtnEdit.Enabled && this.tsbtnEdit.Visible)
{
this.tsbtnEditUser_Click(sender, e);
}
}
///
/// 添加用户
///
///
///
private void tsbtnAddUser_Click(object sender, EventArgs e)
{
try
{
F_MST_0202 frmMST0202 = new F_MST_0202(Constant.FormMode.Add);
DialogResult dialogResult = frmMST0202.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
List userIDList = frmMST0202.UserIDList;
int[] iDList = new int[userIDList.Count];
for (int i = 0; i < userIDList.Count; i++)
{
iDList[i] = userIDList[i];
}
SUserEntity userInfos = new SUserEntity();
DataSet userDataSet = SystemModuleProxy.Service.SearchUserData(userInfos);
if (userDataSet != null && userDataSet.Tables.Count > Constant.INT_IS_ZERO
&& userDataSet.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
this.dgvUser.DataSource = null;
this.dgvUser.DataSource = userDataSet.Tables[0];
// 设置ToolStripButton按钮状态
this.SetToolStripButtonEnable();
this.dgvUser.ReadOnly = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 范围权限按钮事件
///
///
///
private void tsbtnFunctionRight_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentRow != null)
{
int intUserID = Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value);
string UserCode = this.dgvUser.CurrentRow.Cells["UserCode"].Value.ToString();
F_MST_0203 frmMST0203 = new F_MST_0203(intUserID, UserCode);
frmMST0203.ShowDialog();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体关闭事件
///
///
///
private void F_MST_0203_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 单击编辑按钮跳转页面
///
///
///
private void tsbtnEditUser_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentRow != null)
{
F_MST_0202 frmMST0202 = new F_MST_0202(Constant.FormMode.Edit);
frmMST0202.UserID = Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value);
frmMST0202.UserCode = this.dgvUser.CurrentRow.Cells["UserCode"].Value.ToString();
DialogResult dialogResult = frmMST0202.ShowDialog();
if (dialogResult.Equals(DialogResult.OK))
{
// 重新加载GridView
this.btnSearch_Click(sender, e);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 复制用户
///
///
///
private void tsbtnCopy_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentRow == null)
{
return;
}
F_MST_0202 frmMST0202 = new F_MST_0202(Constant.FormMode.CopyAndAdd);
frmMST0202.UserID = Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value);
frmMST0202.UserCode = this.dgvUser.CurrentRow.Cells["UserCode"].Value.ToString();
DialogResult dialogResult = frmMST0202.ShowDialog();
// 重新加载GridView
if (dialogResult == DialogResult.OK)
{
List userIDList = frmMST0202.UserIDList;
int[] iDList = new int[userIDList.Count];
for (int i = 0; i < userIDList.Count; i++)
{
iDList[i] = userIDList[i];
}
SUserEntity userInfos = new SUserEntity();
DataSet userDataSet = SystemModuleProxy.Service.SearchUserData(userInfos);
if (userDataSet != null && userDataSet.Tables.Count > Constant.INT_IS_ZERO
&& userDataSet.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
this.dgvUser.DataSource = null;
this.dgvUser.DataSource = userDataSet.Tables[0];
// 设置ToolStripButton按钮状态
this.SetToolStripButtonEnable();
this.dgvUser.ReadOnly = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 重置密码按钮事件
///
///
///
private void tsbtnResetPassword_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.CurrentRow != null)
{
// 提示用户确认重置密码
DialogResult msgBoxResult = MessageBox.Show(
string.Format(Messages.MSG_CMN_Q002, "该用户", "重置密码"), this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (msgBoxResult == DialogResult.Yes)
{
// 用户默认密码
DataSet ds = (DataSet)CommonModuleProxy.Service.GetSysSettingBySettingType("S_CMN_0001");
string pwd = "dongke";
if (ds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
pwd = ds.Tables[0].Rows[0]["SETTINGVALUE"].ToString();
}
string userCode = this.dgvUser.CurrentRow.Cells["UserCode"].Value.ToString();
string userName = this.dgvUser.CurrentRow.Cells["UserName"].Value.ToString();
string passWord = pwd;
string returenPassWord = SystemModuleProxy.Service.SaveUserPassWord(passWord, userCode, userName);
this.dgvUser.ReadOnly = true;
this.scbOrganization.EditReadOnly = true;
//修改成功
if (!string.IsNullOrEmpty(returenPassWord))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "用户管理", "重置密码"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "用户管理", "重置密码"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 自动适应列宽事件
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvUser.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 窗体关闭事件
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 解锁按钮事件
///
///
///
private void tsbtnUnlock_Click(object sender, EventArgs e)
{
try
{
// 提示用户确认解锁
DialogResult msgBoxResult = MessageBox.Show(
string.Format(Messages.MSG_CMN_Q002, "该用户", "解锁"), this.Text,
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (msgBoxResult == DialogResult.Yes)
{
int result = (int)DoAsync(new AsyncMethod(this.UnlockUserStatus));//解锁按钮方法
if (result > Constant.INT_IS_ZERO)
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "用户管理", "解锁"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
// 重新加载数据
this.btnSearch_Click(sender, e);
}
else
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "用户管理", "解锁"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 数据表格鼠标点击事件
///
///
///
private void dgvUser_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
//if (e.RowIndex != -Constant.INT_IS_ONE)
//{
// string ValueFlag = this.dgvUser.Rows[e.RowIndex].Cells["IsLocked"].Value.ToString();
// if (ValueFlag == "锁死" || ValueFlag == "1")
// {
// this.tsbtnUnlock.Enabled = true;
// }
// else
// {
// this.tsbtnUnlock.Enabled = false;
// }
//}
}
///
/// 打印工号事件
///
///
///
private void tsbPrintCode_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.Rows.Count == Constant.INT_IS_ZERO)
{
// 提示信息
MessageBox.Show(Messages.MSG_CMN_W023,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
List codeList = new List();
foreach (DataGridViewRow row in this.dgvUser.Rows)
{
codeList.Add(row.Cells["UserCode"].Value.ToString());
}
F_MST_0205 fMST0205 = new F_MST_0205();
fMST0205.BarcodeList = codeList;
fMST0205.ShowDialog();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 获取用户列表
///
///
private DataSet SearchUserData()
{
try
{
return SystemModuleProxy.Service.SearchUserData(this._userInfo);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取输入的用户信息
///
///
private SUserEntity GetUserEntityFromLayout()
{
this._userInfo = new SUserEntity();
// 用户编码
this._userInfo.UserCode = this.txtUserCode.Text.Trim();
// 用户姓名
this._userInfo.UserName = this.txtUserName.Text.Trim();
// 所属部门
this._userInfo.OrganizationCode = this.scbOrganization.SearchedValue+"";
// 所属部门
this._userInfo.OrganizationID = scbOrganization.SearchedPKMember;
// MAC
this._userInfo.LimitMAC = this.txtMAC.Text.Trim();
// 备注
this._userInfo.Remarks = this.txtRemarks.Text.Trim();
if (this.chkVYes.Checked != this.chkVNo.Checked)
{
if (this.chkVNo.Checked)
{
this._userInfo.IsValueFlag = "0";
}
else if (this.chkVYes.Checked)
{
this._userInfo.IsValueFlag = "1";
}
}
if (this.chkLYes.Checked != this.chkLNo.Checked)
{
if (this.chkLNo.Checked)
{
this._userInfo.IsLocked = "1";
}
else if (this.chkLYes.Checked)
{
this._userInfo.IsLocked = "0";
}
}
return _userInfo;
}
///
/// 设置工具按钮的可用状态
///
private void SetToolStripButtonEnable()
{
if (this.dgvUser.CurrentCell != null)
{
this.tsbtnUnlock.Enabled = true;
this.tsbtnResetPassword.Enabled = true;
this.tsbtnEdit.Enabled = true;
this.tsbtnCopy.Enabled = true;
this.tsbtnPurviewRight.Enabled = true;
this.tsbtnFunctionRight.Enabled = true;
//int valueFlag = Convert.ToInt32(dgvUser.CurrentRow.Cells["valueFlag"].Value.ToString());
string valueFlag = this.dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells["IsLocked"].Value.ToString();
if (valueFlag == "1")
{
this.tsbtnUnlock.Enabled = true;
}
else
{
this.tsbtnUnlock.Enabled = false;
}
// admin用户不能分配权限
//if ("ADMIN".Equals(dgvUser.CurrentRow.Cells["UserCode"].Value.ToString().ToUpper()))
//{
// this.tsbtnFunctionRight.Enabled = false;
//}
}
else
{
this.tsbtnUnlock.Enabled = false;
this.tsbtnResetPassword.Enabled = false;
this.tsbtnEdit.Enabled = false;
this.tsbtnCopy.Enabled = false;
this.tsbtnPurviewRight.Enabled = false;
this.tsbtnFunctionRight.Enabled = false;
}
}
///
/// 保存组织机构
///
/// 影响的行数
private object UnlockUserStatus()
{
try
{
return SystemModuleProxy.Service.UnlockUserStatus(Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}