| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:S_CMN_003.cs
- * 2.功能描述:员工选择列表页面
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/09/12 1.00 新建
- *******************************************************************************/
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- namespace Dongke.IBOSS.PRD.Client.Controls
- {
- /// <summary>
- /// 员工选择列表页面
- /// </summary>
- public partial class S_CMN_003 : FormBase
- {
- #region 成员变量
- private DataTable _dataSource; // 画面的数据源
- private DataRow _userRow; // 返回用户的DataRow
- private string _whereCondition; // 查询条件
- private DKStaffEntity _staffEntity = new DKStaffEntity(); // 员工档案实体
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public S_CMN_003()
- : this("")
- {
- }
- /// <summary>
- /// 重载的构造函数
- /// </summary>
- /// <param name="organizationName">用户名称</param>
- public S_CMN_003(string userName)
- {
- InitializeComponent();
- this.txtStaffName.Text = userName;
- // 按钮
- this.btnSearch.Text = ButtonText.BTN_SEARCH;
- this.btnOK.Text = ButtonText.BTN_OK;
- this.btnClose.Text = ButtonText.BTN_CANCEL;
- this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
- }
- /// <summary>
- /// 重载的构造函数
- /// </summary>
- /// <param name="organizationName">用户名称</param>
- public S_CMN_003(string userName, string whereCondition)
- {
- InitializeComponent();
- this.txtStaffName.Text = userName;
- this._whereCondition = whereCondition;
- // 按钮
- this.btnSearch.Text = ButtonText.BTN_SEARCH;
- this.btnOK.Text = ButtonText.BTN_OK;
- this.btnClose.Text = ButtonText.BTN_CLOSE;
- this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 获取或者设定画面的数据源。
- /// </summary>
- [Description("获取或者设定画面的数据源。")]
- public new DataTable DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- _dataSource = value;
- }
- }
- /// <summary>
- /// 返回选择的组织行
- /// </summary>
- public DataRow UserRow
- {
- get
- {
- return _userRow;
- }
- set
- {
- _userRow = value;
- }
- }
- /// <summary>
- /// 返回选择的员工档案信息
- /// </summary>
- public DKStaffEntity StaffEntity
- {
- get
- {
- return _staffEntity;
- }
- set
- {
- _staffEntity = value;
- }
- }
- #endregion
- #region 控件事件
- /// <summary>
- /// 页面加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void S_CMN_003_Load(object sender, EventArgs e)
- {
- try
- {
- this.dgvUser.AutoGenerateColumns = false;
- if (!string.IsNullOrEmpty(this.txtStaffName.Text))
- {
- Search();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 查询按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSearch_Click(object sender, EventArgs e)
- {
- try
- {
- Search();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 确定按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnOK_Click(object sender, EventArgs e)
- {
- try
- {
- Commit();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- /// <summary>
- /// KeyDown事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 + ""))
- {
- Clipboard.SetText(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + "");
- }
- }
- else if (e.KeyData == Keys.Enter)
- {
- Commit();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 双击DataGridView窗体,返回选中记录
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvUser_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- try
- {
- // 判断是否是双击列头,如果是双击列头的话,不做任何操作
- if (-1 < e.RowIndex && -1 < e.ColumnIndex)
- {
- Commit();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 查询方法
- /// </summary>
- private void Search()
- {
- // 清空之前的查询结果
- this.dgvUser.DataSource = null;
- // 根据查询条件查询数据源中的数据,并显示
- DataTable userTable = this.DataSource.Copy();
- userTable.DefaultView.RowFilter = GetFilterExpression();
- this.dgvUser.DataSource = userTable.DefaultView.ToTable();
- this.dgvUser.Focus();
- // 当没有查询结果时,提示无查询结构消息
- if (this.dgvUser.RowCount <= 0)
- {
- MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
- this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
- this.txtStaffCode.Focus();
- this.btnOK.Enabled = false;
- return;
- }
- this.btnOK.Enabled = true;
- }
- /// <summary>
- /// 根据画面输入内容拼接过滤条件
- /// </summary>
- /// <returns></returns>
- private string GetFilterExpression()
- {
- StringBuilder strbFilterExpressions = new StringBuilder();
- strbFilterExpressions.Append("(1=1 and " + _whereCondition);
- if (!string.IsNullOrEmpty(this.txtStaffCode.Text))
- {
- // 用户编码条件
- strbFilterExpressions.Append(string.Format(" AND StaffCode LIKE '%{0}%' ",
- Utility.SelectFilterLike(this.txtStaffCode.Text.Trim())));
- }
- if (!string.IsNullOrEmpty(this.txtStaffName.Text))
- {
- // 用户名称条件
- strbFilterExpressions.Append(string.Format(" AND StaffName LIKE '%{0}%' ",
- Utility.SelectFilterLike(this.txtStaffName.Text.Trim())));
- }
- strbFilterExpressions.Append(")");
- return strbFilterExpressions.ToString();
- }
- /// <summary>
- /// 提交时给取得的行赋值
- /// </summary>
- private void Commit()
- {
- if (this.dgvUser.CurrentCell != null)
- {
- this.UserRow = this.dgvUser.GetDataRow(this.dgvUser.CurrentCell.RowIndex);
- //员工ID
- this._staffEntity.StaffID = int.Parse(this.UserRow["StaffID"].ToString().Trim());
- //员工编码
- this._staffEntity.StaffCode = this.UserRow["StaffCode"].ToString().Trim();
- //员工姓名
- this._staffEntity.StaffName = this.UserRow["StaffName"].ToString().Trim();
- //员工状态
- this._staffEntity.StaffStatus = int.Parse(this.UserRow["StaffStatus"].ToString().Trim());
- //工种
- if (!string.IsNullOrEmpty(this.UserRow["Jobs"].ToString()))
- {
- this._staffEntity.Jobs = int.Parse(this.UserRow["Jobs"].ToString().Trim());
- }
- this._staffEntity.JobsName = this.UserRow["Jobsname"].ToString().Trim();
- //所属部门
- if (!string.IsNullOrEmpty(this.UserRow["OrganizationID"].ToString()))
- {
- this._staffEntity.OrganizationID = int.Parse(this.UserRow["OrganizationID"].ToString().Trim());
- }
- this._staffEntity.OrganizationName = this.UserRow["Organizationname"].ToString().Trim();
- //职务
- if (!string.IsNullOrEmpty(this.UserRow["Post"].ToString()))
- {
- this._staffEntity.Post = int.Parse(this.UserRow["Post"].ToString().Trim());
- }
- this._staffEntity.PostName = this.UserRow["Postname"].ToString().Trim();
- //预计试用期结束日期
- if (!string.IsNullOrEmpty(this.UserRow["ExProbationEndDate"].ToString()))
- {
- this._staffEntity.ExProbationEndDate = DateTime.Parse(this.UserRow["ExProbationEndDate"].ToString().Trim());
- }
- this._staffEntity.OPTimeStamp = Convert.ToDateTime(this.UserRow["OPTimeStamp"]);
- //if (!string.IsNullOrEmpty(this.UserRow["UserID"].ToString().Trim()))
- //{
- // this._staffEntity.UserID = int.Parse(this.UserRow["UserID"].ToString().Trim());
- //}
- //this._staffEntity.UserCode = this.UserRow["UserCode"].ToString().Trim();
- // this._staffEntity.UserName = this.UserRow["UserName"].ToString().Trim();
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- }
- #endregion
- private void btnClearCondition_Click(object sender, EventArgs e)
- {
- this.txtStaffCode.Clear();
- this.txtStaffName.Clear();
- }
- }
- }
|