S_CMN_010.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. try
  228. {
  229. String Staffid = this.dgvStaff.Rows[e.RowIndex].Cells["Staffid"].Value.ToString();
  230. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  231. if (invDt == null || invDt.Rows.Count == 0)
  232. {
  233. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  234. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  235. return;
  236. }
  237. invDt.AcceptChanges();
  238. invDt = invDt.Copy();
  239. string filter = "Staffid = " + Staffid;
  240. invDt.DefaultView.RowFilter = filter;
  241. invDt = invDt.DefaultView.ToTable();
  242. // 如果选中了数据就关闭窗体,反之则不关
  243. if (invDt.Rows.Count > 0)
  244. {
  245. SelTable = invDt;
  246. this.DialogResult = DialogResult.OK;
  247. this.Close();
  248. }
  249. else
  250. {
  251. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  252. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  253. }
  254. }
  255. catch (Exception ex)
  256. {
  257. throw ex;
  258. }
  259. }
  260. #endregion
  261. #region 方法
  262. /// <summary>
  263. /// 查询方法
  264. /// </summary>
  265. private void Search()
  266. {
  267. try
  268. {
  269. // 清空之前的查询结果
  270. this.dgvStaff.DataSource = null;
  271. // 为查询实体赋值
  272. SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
  273. searchStaffEntity.UserID = this._userId;
  274. searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  275. searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
  276. searchStaffEntity.Jobs = this.dkTargetobs.JobsID;
  277. DataSet result = (DataSet)DoAsync(() =>
  278. {
  279. return HRModuleProxy.Service.SearchStaffInfo(searchStaffEntity);
  280. });
  281. // 绑定明细数据
  282. this.dgvStaff.DataSource = result.Tables[0];
  283. this.dgvStaff.Focus();
  284. // 当没有查询结果时,提示无查询结构消息
  285. if (this.dgvStaff.RowCount <= Constant.INT_IS_ZERO)
  286. {
  287. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  288. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  289. this.txtStaffCode.Focus();
  290. this.btnOK.Enabled = false;
  291. return;
  292. }
  293. this.btnOK.Enabled = true;
  294. }
  295. catch (Exception ex)
  296. {
  297. throw ex;
  298. }
  299. }
  300. /// <summary>
  301. /// 提交时给取得的行赋值
  302. /// </summary>
  303. private void Commit()
  304. {
  305. try
  306. {
  307. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  308. if (invDt == null || invDt.Rows.Count == 0)
  309. {
  310. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  311. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  312. return;
  313. }
  314. invDt.AcceptChanges();
  315. invDt = invDt.Copy();
  316. string filter = "Sel = 1";
  317. invDt.DefaultView.RowFilter = filter;
  318. invDt = invDt.DefaultView.ToTable();
  319. // 如果选中了数据就关闭窗体,反之则不关
  320. if (invDt.Rows.Count > 0)
  321. {
  322. SelTable = invDt;
  323. this.DialogResult = DialogResult.OK;
  324. this.Close();
  325. }
  326. else
  327. {
  328. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  329. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. throw ex;
  335. }
  336. }
  337. protected void isSelectOneOK()
  338. {
  339. try
  340. {
  341. if (this.dgvStaff.SelectedRows.Count != 0)
  342. {
  343. String Staffid = this.dgvStaff.SelectedRows[0].Cells["Staffid"].Value.ToString();
  344. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  345. if (invDt == null || invDt.Rows.Count == 0)
  346. {
  347. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  348. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  349. return;
  350. }
  351. invDt.AcceptChanges();
  352. invDt = invDt.Copy();
  353. string filter = "Staffid = " + Staffid;
  354. invDt.DefaultView.RowFilter = filter;
  355. invDt = invDt.DefaultView.ToTable();
  356. // 如果选中了数据就关闭窗体,反之则不关
  357. if (invDt.Rows.Count > 0)
  358. {
  359. SelTable = invDt;
  360. this.DialogResult = DialogResult.OK;
  361. this.Close();
  362. }
  363. else
  364. {
  365. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  366. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  367. }
  368. }
  369. }
  370. catch (Exception ex)
  371. {
  372. throw ex;
  373. }
  374. }
  375. #endregion
  376. }
  377. }