S_CMN_010.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_HR_0501.cs
  5. * 2.功能描述:选择员工信息
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯雪 2014/09/23 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.Client.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  20. namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
  21. {
  22. /// <summary>
  23. /// 选择员工信息
  24. /// </summary>
  25. public partial class S_CMN_010 : FormBase
  26. {
  27. #region 成员变量
  28. // 画面的数据源
  29. //private DataTable _dataSource;
  30. // 返回用户的DataRow
  31. private DataRow _staffRow;
  32. // 查询条件
  33. private int _userId;
  34. // 员工编号
  35. private string _staffCode;
  36. // 员工档案实体
  37. private DKStaffEntity _staffEntity = new DKStaffEntity();
  38. // 是否单选
  39. private bool _isSelectOne = false;
  40. #endregion
  41. #region 构造函数
  42. /// <summary>
  43. /// 构造函数
  44. /// </summary>
  45. public S_CMN_010()
  46. {
  47. InitializeComponent();
  48. // 按钮
  49. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  50. this.btnOK.Text = ButtonText.BTN_OK;
  51. this.btnClose.Text = ButtonText.BTN_CANCEL;
  52. this.Text = FormTitles.S_CMN_010;
  53. }
  54. #endregion
  55. #region 属性
  56. /// <summary>
  57. /// 返回选择的员工行
  58. /// </summary>
  59. public DataRow StaffRow
  60. {
  61. get
  62. {
  63. return _staffRow;
  64. }
  65. set
  66. {
  67. _staffRow = value;
  68. }
  69. }
  70. /// <summary>
  71. /// 返回选择的员工档案信息
  72. /// </summary>
  73. public DKStaffEntity StaffEntity
  74. {
  75. get
  76. {
  77. return _staffEntity;
  78. }
  79. set
  80. {
  81. _staffEntity = value;
  82. }
  83. }
  84. /// <summary>
  85. /// 工号
  86. /// </summary>
  87. public int UserId
  88. {
  89. get { return _userId; }
  90. set { _userId = value; }
  91. }
  92. public bool IsSelectOne
  93. {
  94. get
  95. {
  96. return _isSelectOne;
  97. }
  98. set
  99. {
  100. _isSelectOne = value;
  101. }
  102. }
  103. /// <summary>
  104. /// 员工编号
  105. /// </summary>
  106. public string StaffCode1
  107. {
  108. get { return _staffCode; }
  109. set { _staffCode = value; }
  110. }
  111. /// <summary>
  112. /// 选择的数据
  113. /// </summary>
  114. public DataTable SelTable { get; set; }
  115. #endregion
  116. #region 事件
  117. /// <summary>
  118. /// 页面加载事件
  119. /// </summary>
  120. /// <param name="sender"></param>
  121. /// <param name="e"></param>
  122. private void S_CMN_010_Load(object sender, EventArgs e)
  123. {
  124. try
  125. {
  126. this.dgvStaff.AutoGenerateColumns = false;
  127. this.txtStaffCode.Text = this._staffCode;
  128. this.Search();
  129. if (_isSelectOne == true)
  130. {
  131. this.chkChooseAll.Visible = false;
  132. this.Sel.Visible = false;
  133. this.dgvStaff.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  134. }
  135. }
  136. catch (Exception ex)
  137. {
  138. // 对异常进行共通处理
  139. ExceptionManager.HandleEventException(this.ToString(),
  140. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  141. }
  142. }
  143. /// <summary>
  144. /// 查询按钮按下事件
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. private void btnSearch_Click(object sender, EventArgs e)
  149. {
  150. try
  151. {
  152. this.Search();
  153. }
  154. catch (Exception ex)
  155. {
  156. // 对异常进行共通处理
  157. ExceptionManager.HandleEventException(this.ToString(),
  158. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  159. }
  160. }
  161. /// <summary>
  162. /// 确定按钮按下事件
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void btnOK_Click(object sender, EventArgs e)
  167. {
  168. try
  169. {
  170. if (_isSelectOne == true)
  171. {
  172. isSelectOneOK();
  173. }
  174. else
  175. {
  176. Commit();
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. // 对异常进行共通处理
  182. ExceptionManager.HandleEventException(this.ToString(),
  183. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  184. }
  185. }
  186. /// <summary>
  187. /// 关闭按钮按下事件
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void btnClose_Click(object sender, EventArgs e)
  192. {
  193. this.DialogResult = DialogResult.Cancel;
  194. this.Close();
  195. }
  196. /// <summary>
  197. /// 选择所有事件
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  202. {
  203. for (int i = 0; i < this.dgvStaff.Rows.Count; i++)
  204. {
  205. this.dgvStaff.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  206. }
  207. }
  208. /// <summary>
  209. /// 清空按钮事件
  210. /// </summary>
  211. /// <param name="sender"></param>
  212. /// <param name="e"></param>
  213. private void btnCancel_Click(object sender, EventArgs e)
  214. {
  215. this.txtStaffCode.Clear();
  216. this.txtStaffName.Clear();
  217. this.dkTargetobs.JobsID = null;
  218. this.dkTargetobs.Text = "";
  219. }
  220. /// <summary>
  221. /// 单元格双击事件
  222. /// </summary>
  223. /// <param name="sender"></param>
  224. /// <param name="e"></param>
  225. private void dgvStaff_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  226. {
  227. if (e.RowIndex < 0 || e.ColumnIndex < 0)
  228. {
  229. return;
  230. }
  231. try
  232. {
  233. String Staffid = this.dgvStaff.Rows[e.RowIndex].Cells["Staffid"].Value.ToString();
  234. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  235. if (invDt == null || invDt.Rows.Count == 0)
  236. {
  237. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  238. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  239. return;
  240. }
  241. invDt.AcceptChanges();
  242. invDt = invDt.Copy();
  243. string filter = "Staffid = " + Staffid;
  244. invDt.DefaultView.RowFilter = filter;
  245. invDt = invDt.DefaultView.ToTable();
  246. // 如果选中了数据就关闭窗体,反之则不关
  247. if (invDt.Rows.Count > 0)
  248. {
  249. SelTable = invDt;
  250. this.DialogResult = DialogResult.OK;
  251. this.Close();
  252. }
  253. else
  254. {
  255. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  256. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  257. }
  258. }
  259. catch (Exception ex)
  260. {
  261. throw ex;
  262. }
  263. }
  264. #endregion
  265. #region 方法
  266. /// <summary>
  267. /// 查询方法
  268. /// </summary>
  269. private void Search()
  270. {
  271. try
  272. {
  273. // 清空之前的查询结果
  274. this.dgvStaff.DataSource = null;
  275. // 为查询实体赋值
  276. SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
  277. searchStaffEntity.UserID = this._userId;
  278. searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  279. searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
  280. searchStaffEntity.Jobs = this.dkTargetobs.JobsID;
  281. DataSet result = (DataSet)DoAsync(() =>
  282. {
  283. return HRModuleProxy.Service.SearchStaffInfo(searchStaffEntity);
  284. });
  285. // 绑定明细数据
  286. this.dgvStaff.DataSource = result.Tables[0];
  287. this.dgvStaff.Focus();
  288. // 当没有查询结果时,提示无查询结构消息
  289. if (this.dgvStaff.RowCount <= Constant.INT_IS_ZERO)
  290. {
  291. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  292. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  293. this.txtStaffCode.Focus();
  294. this.btnOK.Enabled = false;
  295. return;
  296. }
  297. this.btnOK.Enabled = true;
  298. }
  299. catch (Exception ex)
  300. {
  301. throw ex;
  302. }
  303. }
  304. /// <summary>
  305. /// 提交时给取得的行赋值
  306. /// </summary>
  307. private void Commit()
  308. {
  309. try
  310. {
  311. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  312. if (invDt == null || invDt.Rows.Count == 0)
  313. {
  314. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  315. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  316. return;
  317. }
  318. invDt.AcceptChanges();
  319. invDt = invDt.Copy();
  320. string filter = "Sel = 1";
  321. invDt.DefaultView.RowFilter = filter;
  322. invDt = invDt.DefaultView.ToTable();
  323. // 如果选中了数据就关闭窗体,反之则不关
  324. if (invDt.Rows.Count > 0)
  325. {
  326. SelTable = invDt;
  327. this.DialogResult = DialogResult.OK;
  328. this.Close();
  329. }
  330. else
  331. {
  332. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  333. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. throw ex;
  339. }
  340. }
  341. protected void isSelectOneOK()
  342. {
  343. try
  344. {
  345. if (this.dgvStaff.SelectedRows.Count != 0)
  346. {
  347. String Staffid = this.dgvStaff.SelectedRows[0].Cells["Staffid"].Value.ToString();
  348. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  349. if (invDt == null || invDt.Rows.Count == 0)
  350. {
  351. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  352. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  353. return;
  354. }
  355. invDt.AcceptChanges();
  356. invDt = invDt.Copy();
  357. string filter = "Staffid = " + Staffid;
  358. invDt.DefaultView.RowFilter = filter;
  359. invDt = invDt.DefaultView.ToTable();
  360. // 如果选中了数据就关闭窗体,反之则不关
  361. if (invDt.Rows.Count > 0)
  362. {
  363. SelTable = invDt;
  364. this.DialogResult = DialogResult.OK;
  365. this.Close();
  366. }
  367. else
  368. {
  369. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  370. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  371. }
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. throw ex;
  377. }
  378. }
  379. #endregion
  380. }
  381. }