F_MST_0210.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. }
  141. /// <summary>
  142. /// 单元格鼠标事件
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void dgvUser_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  147. {
  148. if (e.RowIndex != -1)
  149. {
  150. int UserId = Convert.ToInt32(this.dgvUser.Rows[e.RowIndex].Cells["UserID"].Value.ToString());
  151. DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
  152. this.dgvStaff.AutoGenerateColumns = false;
  153. this.dgvStaff.DataSource = dsStaff.Tables[0];
  154. }
  155. }
  156. /// <summary>
  157. /// 选定项改变事件
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void dgvUser_SelectionChanged(object sender, EventArgs e)
  162. {
  163. try
  164. {
  165. if (dgvUser.CurrentCell != null)
  166. {
  167. int UserId = Convert.ToInt32(this.dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells["UserID"].Value.ToString());
  168. DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
  169. this.dgvStaff.AutoGenerateColumns = false;
  170. this.dgvStaff.DataSource = dsStaff.Tables[0];
  171. }
  172. }
  173. catch (Exception ex)
  174. {
  175. // 对异常进行共通处理
  176. ExceptionManager.HandleEventException(this.ToString(),
  177. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  178. }
  179. }
  180. /// <summary>
  181. /// 新增按钮事件
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void tsbtnAddUser_Click(object sender, EventArgs e)
  186. {
  187. try
  188. {
  189. F_MST_0211 frmFMST0211 = new F_MST_0211(null, null);
  190. DialogResult dialogresult = frmFMST0211.ShowDialog();
  191. }
  192. catch (Exception ex)
  193. {
  194. // 对异常进行共通处理
  195. ExceptionManager.HandleEventException(this.ToString(),
  196. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  197. }
  198. }
  199. /// <summary>
  200. /// 单元格双击事件
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void dgvUser_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  205. {
  206. try
  207. {
  208. if (e.RowIndex != -Constant.INT_IS_ONE)
  209. {
  210. string userId = this.dgvUser.Rows[e.RowIndex].Cells["userId"].Value.ToString();
  211. string userCode = this.dgvUser.Rows[e.RowIndex].Cells["userCode"].Value.ToString();
  212. F_MST_0211 frmFMST0207 = new F_MST_0211(Convert.ToInt32(userId), userCode);
  213. DialogResult dialogresult = frmFMST0207.ShowDialog();
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. // 对异常进行共通处理
  219. ExceptionManager.HandleEventException(this.ToString(),
  220. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  221. }
  222. }
  223. /// <summary>
  224. /// 编辑按钮事件
  225. /// </summary>
  226. /// <param name="sender"></param>
  227. /// <param name="e"></param>
  228. private void tsbtnEditUser_Click(object sender, EventArgs e)
  229. {
  230. try
  231. {
  232. if (this.dgvUser.SelectedRows.Count != 0)
  233. {
  234. string userId = this.dgvUser.SelectedRows[0].Cells["userId"].Value.ToString();
  235. string userCode = this.dgvUser.SelectedRows[0].Cells["userCode"].Value.ToString();
  236. F_MST_0211 frmFMST0211 = new F_MST_0211(Convert.ToInt32(userId), userCode);
  237. DialogResult dialogresult = frmFMST0211.ShowDialog();
  238. }
  239. }
  240. catch (Exception ex)
  241. {
  242. // 对异常进行共通处理
  243. ExceptionManager.HandleEventException(this.ToString(),
  244. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  245. }
  246. }
  247. /// <summary>
  248. /// 窗体加载事件
  249. /// </summary>
  250. /// <param name="sender"></param>
  251. /// <param name="e"></param>
  252. private void F_MST_0210_Load(object sender, EventArgs e)
  253. {
  254. // 加载权限
  255. FormPermissionManager.FormPermissionControl(this.Name, this,
  256. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  257. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  258. }
  259. /// <summary>
  260. /// 自适应列宽
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  265. {
  266. this.dgvUser.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  267. }
  268. /// <summary>
  269. /// 关闭按钮事件
  270. /// </summary>
  271. /// <param name="sender"></param>
  272. /// <param name="e"></param>
  273. private void tsbtnClose_Click(object sender, EventArgs e)
  274. {
  275. this.Close();
  276. }
  277. /// <summary>
  278. /// 释放窗体
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void F_MST_0210_FormClosed(object sender, FormClosedEventArgs e)
  283. {
  284. _instance = null;
  285. }
  286. #endregion
  287. #region 私有方法
  288. /// <summary>
  289. /// 获取输入的用户信息
  290. /// </summary>
  291. /// <returns></returns>
  292. private SUserEntity GetUserEntityFromLayout()
  293. {
  294. this._userInfo = new SUserEntity();
  295. // 用户编码
  296. this._userInfo.UserCode = this.txtUserCode.Text.Trim();
  297. // 用户姓名
  298. this._userInfo.UserName = this.txtUserName.Text.Trim();
  299. // 所属部门
  300. this._userInfo.OrganizationCode = scbOrganization.SearchedValue + "";
  301. // 所属部门
  302. this._userInfo.OrganizationID = scbOrganization.SearchedPKMember;
  303. // 备注
  304. this._userInfo.Remarks = this.txtRemarks.Text.Trim();
  305. if (this.chkIsWorker.Checked == true)
  306. {
  307. _userInfo.IsWorker = 1;
  308. }
  309. else
  310. {
  311. _userInfo.IsWorker = 0;
  312. }
  313. return _userInfo;
  314. }
  315. /// <summary>
  316. /// 获取用户列表
  317. /// </summary>
  318. /// <returns></returns>
  319. private DataSet SearchUserData()
  320. {
  321. try
  322. {
  323. return SystemModuleProxy.Service.SearchUserData(this._userInfo);
  324. }
  325. catch (Exception ex)
  326. {
  327. throw ex;
  328. }
  329. }
  330. #endregion
  331. }
  332. }