TAT_CMN_001.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:TAT_CMN_001.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 TAT_CMN_001 : FormBase
  26. {
  27. #region 成员变量
  28. // 画面的数据源
  29. //private DataTable _dataSource;
  30. // 返回用户的DataRow
  31. private DataRow _staffRow;
  32. // 查询条件
  33. private int _managerSalaryID;
  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 TAT_CMN_001()
  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 ManagerSalaryID
  88. {
  89. get { return _managerSalaryID; }
  90. set { _managerSalaryID = 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. #endregion
  221. #region 方法
  222. /// <summary>
  223. /// 查询方法
  224. /// </summary>
  225. private void Search()
  226. {
  227. try
  228. {
  229. // 清空之前的查询结果
  230. this.dgvStaff.DataSource = null;
  231. // 为查询实体赋值
  232. SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
  233. searchStaffEntity.ManagerSalaryID = this.ManagerSalaryID;
  234. searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
  235. searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
  236. searchStaffEntity.Jobs = this.dkTargetobs.JobsID;
  237. DataSet result = (DataSet)DoAsync(() =>
  238. {
  239. return HRModuleProxy.Service.SearchManagersOrMembers(searchStaffEntity);
  240. });
  241. // 绑定明细数据
  242. this.dgvStaff.DataSource = result.Tables[0];
  243. this.dgvStaff.Focus();
  244. // 当没有查询结果时,提示无查询结构消息
  245. if (this.dgvStaff.RowCount <= Constant.INT_IS_ZERO)
  246. {
  247. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  248. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  249. this.txtStaffCode.Focus();
  250. this.btnOK.Enabled = false;
  251. return;
  252. }
  253. this.btnOK.Enabled = true;
  254. }
  255. catch (Exception ex)
  256. {
  257. throw ex;
  258. }
  259. }
  260. /// <summary>
  261. /// 提交时给取得的行赋值
  262. /// </summary>
  263. private void Commit()
  264. {
  265. try
  266. {
  267. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  268. if (invDt == null || invDt.Rows.Count == 0)
  269. {
  270. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  271. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  272. return;
  273. }
  274. invDt.AcceptChanges();
  275. invDt = invDt.Copy();
  276. string filter = "Sel = 1";
  277. invDt.DefaultView.RowFilter = filter;
  278. invDt = invDt.DefaultView.ToTable();
  279. // 如果选中了数据就关闭窗体,反之则不关
  280. if (invDt.Rows.Count > 0)
  281. {
  282. SelTable = invDt;
  283. this.DialogResult = DialogResult.OK;
  284. this.Close();
  285. }
  286. else
  287. {
  288. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  289. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  290. }
  291. }
  292. catch (Exception ex)
  293. {
  294. throw ex;
  295. }
  296. }
  297. protected void isSelectOneOK()
  298. {
  299. try
  300. {
  301. if (this.dgvStaff.SelectedRows.Count != 0)
  302. {
  303. String Staffid = this.dgvStaff.SelectedRows[0].Cells["Staffid"].Value.ToString();
  304. DataTable invDt = (DataTable)this.dgvStaff.DataSource;
  305. if (invDt == null || invDt.Rows.Count == 0)
  306. {
  307. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  308. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  309. return;
  310. }
  311. invDt.AcceptChanges();
  312. invDt = invDt.Copy();
  313. string filter = "Staffid = " + Staffid;
  314. invDt.DefaultView.RowFilter = filter;
  315. invDt = invDt.DefaultView.ToTable();
  316. // 如果选中了数据就关闭窗体,反之则不关
  317. if (invDt.Rows.Count > 0)
  318. {
  319. SelTable = invDt;
  320. this.DialogResult = DialogResult.OK;
  321. this.Close();
  322. }
  323. else
  324. {
  325. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  326. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  327. }
  328. }
  329. }
  330. catch (Exception ex)
  331. {
  332. throw ex;
  333. }
  334. }
  335. #endregion
  336. }
  337. }