F_MST_0210.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0210.cs
  5. * 2.功能描述:员工关联
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/12 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Windows.Forms;
  14. using Dongke.IBOSS.PRD.Basics.BaseControls;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Basics.DockPanel;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  22. namespace Dongke.IBOSS.PRD.Client.SystemModule
  23. {
  24. /// <summary>
  25. /// 员工关联
  26. /// </summary>
  27. public partial class F_MST_0210 : DockPanelBase
  28. {
  29. #region 成员变量
  30. // 单例模式
  31. private static F_MST_0210 _instance;
  32. // 最后选择行
  33. private int _selecedRow;
  34. // 用户管理实体类
  35. private SUserEntity _userInfo;
  36. #endregion
  37. #region 构造函数
  38. public F_MST_0210()
  39. {
  40. InitializeComponent();
  41. this.Text = FormTitles.F_MST_0210;
  42. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  43. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  44. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  45. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  46. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  47. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  48. }
  49. #endregion
  50. #region 单例模式
  51. /// <summary>
  52. /// 单例模式,防止重复创建窗体
  53. /// </summary>
  54. public static F_MST_0210 Instance
  55. {
  56. get
  57. {
  58. if (_instance == null)
  59. {
  60. _instance = new F_MST_0210();
  61. }
  62. return _instance;
  63. }
  64. }
  65. #endregion
  66. #region 事件
  67. /// <summary>
  68. /// 搜索按钮事件
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. private void btnSearch_Click(object sender, EventArgs e)
  73. {
  74. try
  75. {
  76. // 根据页面设定用户实体值
  77. this.GetUserEntityFromLayout();
  78. // 记录当前选中行
  79. int selectRowIndex = this._selecedRow;
  80. // 异步处理
  81. this.btnSearch.Enabled = false;
  82. this.btnClearCondition.Enabled = false;
  83. DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.SearchUserData));
  84. this.btnSearch.Enabled = true;
  85. this.btnClearCondition.Enabled = true;
  86. this.scbOrganization.EditReadOnly = true;
  87. if (userDataSet != null)
  88. {
  89. base.DataSource = (DataSet)userDataSet;
  90. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  91. {
  92. this.dgvUser.DataSource = this.DataSource.Tables[0];
  93. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  94. {
  95. dgvStaff.DataSource = null;
  96. // 提示未查找到数据
  97. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  98. MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. }
  100. else
  101. {
  102. if (selectRowIndex >= Constant.INT_IS_ZERO)
  103. {
  104. if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
  105. {
  106. this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Selected = true;
  107. this.dgvUser.CurrentCell = this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Cells["UserCode"];
  108. }
  109. else
  110. {
  111. this.dgvUser.Rows[selectRowIndex].Selected = true;
  112. this.dgvUser.CurrentCell = this.dgvUser.Rows[selectRowIndex].Cells["UserCode"];
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. this.btnSearch.Enabled = true;
  122. this.btnClearCondition.Enabled = true;
  123. // 对异常进行共通处理
  124. ExceptionManager.HandleEventException(this.ToString(),
  125. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  126. }
  127. }
  128. /// <summary>
  129. /// 清空按钮事件
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void btnClearCondition_Click(object sender, EventArgs e)
  134. {
  135. this.txtUserCode.Clear();
  136. this.txtUserName.Clear();
  137. this.txtRemarks.Clear();
  138. this.scbOrganization.ClearValue();
  139. this.chkIsWorker.Checked = false;
  140. this.txtStaffName.Clear();
  141. }
  142. /// <summary>
  143. /// 单元格鼠标事件
  144. /// </summary>
  145. /// <param name="sender"></param>
  146. /// <param name="e"></param>
  147. private void dgvUser_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  148. {
  149. if (e.RowIndex != -1)
  150. {
  151. int UserId = Convert.ToInt32(this.dgvUser.Rows[e.RowIndex].Cells["UserID"].Value.ToString());
  152. DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
  153. this.dgvStaff.AutoGenerateColumns = false;
  154. this.dgvStaff.DataSource = dsStaff.Tables[0];
  155. }
  156. }
  157. /// <summary>
  158. /// 选定项改变事件
  159. /// </summary>
  160. /// <param name="sender"></param>
  161. /// <param name="e"></param>
  162. private void dgvUser_SelectionChanged(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. if (dgvUser.CurrentCell != null)
  167. {
  168. int UserId = Convert.ToInt32(this.dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells["UserID"].Value.ToString());
  169. DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
  170. this.dgvStaff.AutoGenerateColumns = false;
  171. this.dgvStaff.DataSource = dsStaff.Tables[0];
  172. }
  173. }
  174. catch (Exception ex)
  175. {
  176. // 对异常进行共通处理
  177. ExceptionManager.HandleEventException(this.ToString(),
  178. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  179. }
  180. }
  181. /// <summary>
  182. /// 新增按钮事件
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void tsbtnAddUser_Click(object sender, EventArgs e)
  187. {
  188. try
  189. {
  190. F_MST_0211 frmFMST0211 = new F_MST_0211(null, null);
  191. DialogResult dialogresult = frmFMST0211.ShowDialog();
  192. }
  193. catch (Exception ex)
  194. {
  195. // 对异常进行共通处理
  196. ExceptionManager.HandleEventException(this.ToString(),
  197. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  198. }
  199. }
  200. /// <summary>
  201. /// 单元格双击事件
  202. /// </summary>
  203. /// <param name="sender"></param>
  204. /// <param name="e"></param>
  205. private void dgvUser_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  206. {
  207. try
  208. {
  209. if (e.RowIndex != -Constant.INT_IS_ONE)
  210. {
  211. string userId = this.dgvUser.Rows[e.RowIndex].Cells["userId"].Value.ToString();
  212. string userCode = this.dgvUser.Rows[e.RowIndex].Cells["userCode"].Value.ToString();
  213. F_MST_0211 frmFMST0207 = new F_MST_0211(Convert.ToInt32(userId), userCode);
  214. DialogResult dialogresult = frmFMST0207.ShowDialog();
  215. }
  216. }
  217. catch (Exception ex)
  218. {
  219. // 对异常进行共通处理
  220. ExceptionManager.HandleEventException(this.ToString(),
  221. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  222. }
  223. }
  224. /// <summary>
  225. /// 编辑按钮事件
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void tsbtnEditUser_Click(object sender, EventArgs e)
  230. {
  231. try
  232. {
  233. if (this.dgvUser.SelectedRows.Count != 0)
  234. {
  235. string userId = this.dgvUser.SelectedRows[0].Cells["userId"].Value.ToString();
  236. string userCode = this.dgvUser.SelectedRows[0].Cells["userCode"].Value.ToString();
  237. F_MST_0211 frmFMST0211 = new F_MST_0211(Convert.ToInt32(userId), userCode);
  238. DialogResult dialogresult = frmFMST0211.ShowDialog();
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. // 对异常进行共通处理
  244. ExceptionManager.HandleEventException(this.ToString(),
  245. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  246. }
  247. }
  248. /// <summary>
  249. /// 窗体加载事件
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void F_MST_0210_Load(object sender, EventArgs e)
  254. {
  255. // 加载权限
  256. FormPermissionManager.FormPermissionControl(this.Name, this,
  257. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  258. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  259. }
  260. /// <summary>
  261. /// 自适应列宽
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  266. {
  267. this.dgvUser.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  268. }
  269. /// <summary>
  270. /// 关闭按钮事件
  271. /// </summary>
  272. /// <param name="sender"></param>
  273. /// <param name="e"></param>
  274. private void tsbtnClose_Click(object sender, EventArgs e)
  275. {
  276. this.Close();
  277. }
  278. /// <summary>
  279. /// 释放窗体
  280. /// </summary>
  281. /// <param name="sender"></param>
  282. /// <param name="e"></param>
  283. private void F_MST_0210_FormClosed(object sender, FormClosedEventArgs e)
  284. {
  285. _instance = null;
  286. }
  287. #endregion
  288. #region 私有方法
  289. /// <summary>
  290. /// 获取输入的用户信息
  291. /// </summary>
  292. /// <returns></returns>
  293. private SUserEntity GetUserEntityFromLayout()
  294. {
  295. this._userInfo = new SUserEntity();
  296. // 用户编码
  297. this._userInfo.UserCode = this.txtUserCode.Text.Trim();
  298. // 用户姓名
  299. this._userInfo.UserName = this.txtUserName.Text.Trim();
  300. // 所属部门
  301. this._userInfo.OrganizationCode = scbOrganization.SearchedValue + "";
  302. // 所属部门
  303. this._userInfo.OrganizationID = scbOrganization.SearchedPKMember;
  304. // 备注
  305. this._userInfo.Remarks = this.txtRemarks.Text.Trim();
  306. this._userInfo.StaffName = this.txtStaffName.Text.Trim();
  307. if (this.chkIsWorker.Checked == true)
  308. {
  309. _userInfo.IsWorker = 1;
  310. }
  311. else
  312. {
  313. _userInfo.IsWorker = 0;
  314. }
  315. if (chkValueFlag.Checked)
  316. {
  317. _userInfo.IsValueFlag = "1";
  318. }
  319. return _userInfo;
  320. }
  321. /// <summary>
  322. /// 获取用户列表
  323. /// </summary>
  324. /// <returns></returns>
  325. private DataSet SearchUserData()
  326. {
  327. try
  328. {
  329. return SystemModuleProxy.Service.SearchUserData(this._userInfo);
  330. }
  331. catch (Exception ex)
  332. {
  333. throw ex;
  334. }
  335. }
  336. #endregion
  337. }
  338. }