/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_0201.cs * 2.功能描述:用户管理 * 编辑履历: * 作者 日期 版本 修改内容 * 陈冰 2014/10/28 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.Client.CommonModule; using Dongke.IBOSS.PRD.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; namespace Dongke.IBOSS.PRD.Client.Controls { /// /// 用户管理 /// public partial class S_CMN_013 : FormBase { #region 成员变量 // 单例模式 private static S_CMN_013 _instance; // 最后选择行 private int _selecedRow; // 用户管理实体类 private SUserEntity _userInfo; #endregion #region 属性 /// /// 选择的数据 /// public DataTable SelTable { get; set; } /// /// 传入的工号编码 /// public string SetUserCode { get; set; } #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static S_CMN_013 Instance { get { if (_instance == null) { _instance = new S_CMN_013(); } return _instance; } } #endregion #region 构造函数 public S_CMN_013() { 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.btnOK.Text = ButtonText.BTN_OK; this.btnClose.Text = ButtonText.BTN_CANCEL; } #endregion #region 事件 /// /// 窗体加载事件 /// /// /// private void FrmUser_Load(object sender, EventArgs e) { try { // 设置表格不自动创建列 this.dgvUser.AutoGenerateColumns = false; this.dgvUser.Columns["Sel"].ReadOnly = false; this.txtUserCode.Text = this.SetUserCode; this.btnSearch_Click(null, null); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 释放成员变量 /// /// /// private void FrmOrganization_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 搜索按钮事件 /// /// /// 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 BaseAsyncMethod(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]; if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO) { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } 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.dgvUser.IsSetInputColumnsColor = true; } 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 btnClearCondition_Click(object sender, EventArgs e) { this.txtUserCode.Clear(); this.txtUserName.Clear(); this.scbOrganization.ClearValue(); this.txtMAC.Clear(); this.txtRemarks.Clear(); } /// /// 选中行发生改变时 有效停用相互切换 /// /// /// private void dgvUser_CellEnter(object sender, DataGridViewCellEventArgs e) { 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 F_MST_0203_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 自动适应列宽事件 /// /// /// 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 BaseAsyncMethod(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 chkChooseAll_CheckedChanged(object sender, EventArgs e) { try { for (int i = 0; i < this.dgvUser.Rows.Count; i++) { this.dgvUser.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 确定 /// /// /// private void btnOK_Click(object sender, EventArgs e) { try { this.Commit(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭窗体 /// /// /// private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 私有方法 /// /// 点击确定或者回车键时调用 /// private void Commit() { try { DataTable invDt = (DataTable)this.dgvUser.DataSource; if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } invDt.AcceptChanges(); invDt = invDt.Copy(); string filter = "Sel = 1"; invDt.DefaultView.RowFilter = filter; invDt = invDt.DefaultView.ToTable(); // 如果选中了数据就关闭窗体,反之则不关 if (invDt.Rows.Count > Constant.INT_IS_ZERO) { SelTable = invDt; this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { throw ex; } } /// /// 获取用户列表 /// /// 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 = scbOrganization.SearchedValue + ""; // 所属部门 this._userInfo.OrganizationID = scbOrganization.SearchedPKMember; // MAC this._userInfo.LimitMAC = this.txtMAC.Text.Trim(); this._userInfo.IsWorker = Constant.WorkerNoFlag.No.GetHashCode(); // 备注 this._userInfo.Remarks = this.txtRemarks.Text.Trim(); return _userInfo; } /// /// 保存组织机构 /// /// 影响的行数 private object UnlockUserStatus() { try { return SystemModuleProxy.Service.UnlockUserStatus(Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value)); } catch (Exception ex) { throw ex; } } #endregion } }