S_CMN_003.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_003.cs
  5. * 2.功能描述:员工选择列表页面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/12 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. using Dongke.IBOSS.PRD.Client.DataModels;
  20. namespace Dongke.IBOSS.PRD.Client.Controls
  21. {
  22. /// <summary>
  23. /// 员工选择列表页面
  24. /// </summary>
  25. public partial class S_CMN_003 : FormBase
  26. {
  27. #region 成员变量
  28. private DataTable _dataSource; // 画面的数据源
  29. private DataRow _userRow; // 返回用户的DataRow
  30. private string _whereCondition; // 查询条件
  31. private DKStaffEntity _staffEntity = new DKStaffEntity(); // 员工档案实体
  32. #endregion
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. public S_CMN_003()
  38. : this("")
  39. {
  40. }
  41. /// <summary>
  42. /// 重载的构造函数
  43. /// </summary>
  44. /// <param name="organizationName">用户名称</param>
  45. public S_CMN_003(string userName)
  46. {
  47. InitializeComponent();
  48. this.txtStaffName.Text = userName;
  49. // 按钮
  50. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  51. this.btnOK.Text = ButtonText.BTN_OK;
  52. this.btnClose.Text = ButtonText.BTN_CANCEL;
  53. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  54. }
  55. /// <summary>
  56. /// 重载的构造函数
  57. /// </summary>
  58. /// <param name="organizationName">用户名称</param>
  59. public S_CMN_003(string userName, string whereCondition)
  60. {
  61. InitializeComponent();
  62. this.txtStaffName.Text = userName;
  63. this._whereCondition = whereCondition;
  64. // 按钮
  65. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  66. this.btnOK.Text = ButtonText.BTN_OK;
  67. this.btnClose.Text = ButtonText.BTN_CLOSE;
  68. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  69. }
  70. #endregion
  71. #region 属性
  72. /// <summary>
  73. /// 获取或者设定画面的数据源。
  74. /// </summary>
  75. [Description("获取或者设定画面的数据源。")]
  76. public new DataTable DataSource
  77. {
  78. get
  79. {
  80. return _dataSource;
  81. }
  82. set
  83. {
  84. _dataSource = value;
  85. }
  86. }
  87. /// <summary>
  88. /// 返回选择的组织行
  89. /// </summary>
  90. public DataRow UserRow
  91. {
  92. get
  93. {
  94. return _userRow;
  95. }
  96. set
  97. {
  98. _userRow = value;
  99. }
  100. }
  101. /// <summary>
  102. /// 返回选择的员工档案信息
  103. /// </summary>
  104. public DKStaffEntity StaffEntity
  105. {
  106. get
  107. {
  108. return _staffEntity;
  109. }
  110. set
  111. {
  112. _staffEntity = value;
  113. }
  114. }
  115. #endregion
  116. #region 控件事件
  117. /// <summary>
  118. /// 页面加载事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void S_CMN_003_Load(object sender, EventArgs e)
  123. {
  124. try
  125. {
  126. this.dgvUser.AutoGenerateColumns = false;
  127. if (!string.IsNullOrEmpty(this.txtStaffName.Text))
  128. {
  129. Search();
  130. }
  131. }
  132. catch (Exception ex)
  133. {
  134. // 对异常进行共通处理
  135. ExceptionManager.HandleEventException(this.ToString(),
  136. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  137. }
  138. }
  139. /// <summary>
  140. /// 查询按钮按下事件
  141. /// </summary>
  142. /// <param name="sender"></param>
  143. /// <param name="e"></param>
  144. private void btnSearch_Click(object sender, EventArgs e)
  145. {
  146. try
  147. {
  148. Search();
  149. }
  150. catch (Exception ex)
  151. {
  152. // 对异常进行共通处理
  153. ExceptionManager.HandleEventException(this.ToString(),
  154. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  155. }
  156. }
  157. /// <summary>
  158. /// 确定按钮按下事件
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void btnOK_Click(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. Commit();
  167. }
  168. catch (Exception ex)
  169. {
  170. // 对异常进行共通处理
  171. ExceptionManager.HandleEventException(this.ToString(),
  172. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  173. }
  174. }
  175. /// <summary>
  176. /// 关闭按钮按下事件
  177. /// </summary>
  178. /// <param name="sender"></param>
  179. /// <param name="e"></param>
  180. private void btnClose_Click(object sender, EventArgs e)
  181. {
  182. this.DialogResult = DialogResult.Cancel;
  183. this.Close();
  184. }
  185. /// <summary>
  186. /// KeyDown事件
  187. /// </summary>
  188. /// <param name="sender"></param>
  189. /// <param name="e"></param>
  190. private void dgvUser_KeyDown(object sender, KeyEventArgs e)
  191. {
  192. try
  193. {
  194. // 拷贝单元格文本到剪切板
  195. if (e.KeyData == (Keys.Control | Keys.C))
  196. {
  197. if (dgvUser.CurrentRow != null
  198. && !string.IsNullOrEmpty(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  199. {
  200. Clipboard.SetText(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  201. }
  202. }
  203. else if (e.KeyData == Keys.Enter)
  204. {
  205. Commit();
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. // 对异常进行共通处理
  211. ExceptionManager.HandleEventException(this.ToString(),
  212. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  213. }
  214. }
  215. /// <summary>
  216. /// 双击DataGridView窗体,返回选中记录
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void dgvUser_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  221. {
  222. try
  223. {
  224. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  225. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  226. {
  227. Commit();
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. // 对异常进行共通处理
  233. ExceptionManager.HandleEventException(this.ToString(),
  234. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  235. }
  236. }
  237. #endregion
  238. #region 私有方法
  239. /// <summary>
  240. /// 查询方法
  241. /// </summary>
  242. private void Search()
  243. {
  244. // 清空之前的查询结果
  245. this.dgvUser.DataSource = null;
  246. // 根据查询条件查询数据源中的数据,并显示
  247. DataTable userTable = this.DataSource.Copy();
  248. userTable.DefaultView.RowFilter = GetFilterExpression();
  249. this.dgvUser.DataSource = userTable.DefaultView.ToTable();
  250. this.dgvUser.Focus();
  251. // 当没有查询结果时,提示无查询结构消息
  252. if (this.dgvUser.RowCount <= 0)
  253. {
  254. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  255. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  256. this.txtStaffCode.Focus();
  257. this.btnOK.Enabled = false;
  258. return;
  259. }
  260. this.btnOK.Enabled = true;
  261. }
  262. /// <summary>
  263. /// 根据画面输入内容拼接过滤条件
  264. /// </summary>
  265. /// <returns></returns>
  266. private string GetFilterExpression()
  267. {
  268. StringBuilder strbFilterExpressions = new StringBuilder();
  269. strbFilterExpressions.Append("(1=1 and " + _whereCondition);
  270. if (!string.IsNullOrEmpty(this.txtStaffCode.Text))
  271. {
  272. // 用户编码条件
  273. strbFilterExpressions.Append(string.Format(" AND StaffCode LIKE '%{0}%' ",
  274. Utility.SelectFilterLike(this.txtStaffCode.Text.Trim())));
  275. }
  276. if (!string.IsNullOrEmpty(this.txtStaffName.Text))
  277. {
  278. // 用户名称条件
  279. strbFilterExpressions.Append(string.Format(" AND StaffName LIKE '%{0}%' ",
  280. Utility.SelectFilterLike(this.txtStaffName.Text.Trim())));
  281. }
  282. strbFilterExpressions.Append(")");
  283. return strbFilterExpressions.ToString();
  284. }
  285. /// <summary>
  286. /// 提交时给取得的行赋值
  287. /// </summary>
  288. private void Commit()
  289. {
  290. if (this.dgvUser.CurrentCell != null)
  291. {
  292. this.UserRow = this.dgvUser.GetDataRow(this.dgvUser.CurrentCell.RowIndex);
  293. //员工ID
  294. this._staffEntity.StaffID = int.Parse(this.UserRow["StaffID"].ToString().Trim());
  295. //员工编码
  296. this._staffEntity.StaffCode = this.UserRow["StaffCode"].ToString().Trim();
  297. //员工姓名
  298. this._staffEntity.StaffName = this.UserRow["StaffName"].ToString().Trim();
  299. //员工状态
  300. this._staffEntity.StaffStatus = int.Parse(this.UserRow["StaffStatus"].ToString().Trim());
  301. //工种
  302. if (!string.IsNullOrEmpty(this.UserRow["Jobs"].ToString()))
  303. {
  304. this._staffEntity.Jobs = int.Parse(this.UserRow["Jobs"].ToString().Trim());
  305. }
  306. this._staffEntity.JobsName = this.UserRow["Jobsname"].ToString().Trim();
  307. //所属部门
  308. if (!string.IsNullOrEmpty(this.UserRow["OrganizationID"].ToString()))
  309. {
  310. this._staffEntity.OrganizationID = int.Parse(this.UserRow["OrganizationID"].ToString().Trim());
  311. }
  312. this._staffEntity.OrganizationName = this.UserRow["Organizationname"].ToString().Trim();
  313. //职务
  314. if (!string.IsNullOrEmpty(this.UserRow["Post"].ToString()))
  315. {
  316. this._staffEntity.Post = int.Parse(this.UserRow["Post"].ToString().Trim());
  317. }
  318. this._staffEntity.PostName = this.UserRow["Postname"].ToString().Trim();
  319. //预计试用期结束日期
  320. if (!string.IsNullOrEmpty(this.UserRow["ExProbationEndDate"].ToString()))
  321. {
  322. this._staffEntity.ExProbationEndDate = DateTime.Parse(this.UserRow["ExProbationEndDate"].ToString().Trim());
  323. }
  324. this._staffEntity.OPTimeStamp = Convert.ToDateTime(this.UserRow["OPTimeStamp"]);
  325. //if (!string.IsNullOrEmpty(this.UserRow["UserID"].ToString().Trim()))
  326. //{
  327. // this._staffEntity.UserID = int.Parse(this.UserRow["UserID"].ToString().Trim());
  328. //}
  329. //this._staffEntity.UserCode = this.UserRow["UserCode"].ToString().Trim();
  330. // this._staffEntity.UserName = this.UserRow["UserName"].ToString().Trim();
  331. this.DialogResult = DialogResult.OK;
  332. this.Close();
  333. }
  334. }
  335. #endregion
  336. private void btnClearCondition_Click(object sender, EventArgs e)
  337. {
  338. this.txtStaffCode.Clear();
  339. this.txtStaffName.Clear();
  340. }
  341. }
  342. }