S_CMN_013.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0201.cs
  5. * 2.功能描述:用户管理
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/10/28 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.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  21. namespace Dongke.IBOSS.PRD.Client.Controls
  22. {
  23. /// <summary>
  24. /// 用户管理
  25. /// </summary>
  26. public partial class S_CMN_013 : FormBase
  27. {
  28. #region 成员变量
  29. // 单例模式
  30. private static S_CMN_013 _instance;
  31. // 最后选择行
  32. private int _selecedRow;
  33. // 用户管理实体类
  34. private SUserEntity _userInfo;
  35. #endregion
  36. #region 属性
  37. /// <summary>
  38. /// 选择的数据
  39. /// </summary>
  40. public DataTable SelTable { get; set; }
  41. /// <summary>
  42. /// 传入的工号编码
  43. /// </summary>
  44. public string SetUserCode { get; set; }
  45. #endregion
  46. #region 单例模式
  47. /// <summary>
  48. /// 单例模式,防止重复创建窗体
  49. /// </summary>
  50. public static S_CMN_013 Instance
  51. {
  52. get
  53. {
  54. if (_instance == null)
  55. {
  56. _instance = new S_CMN_013();
  57. }
  58. return _instance;
  59. }
  60. }
  61. #endregion
  62. #region 构造函数
  63. public S_CMN_013()
  64. {
  65. InitializeComponent();
  66. this.Text = FormTitles.F_MST_0201;
  67. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  68. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  69. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  70. this.btnOK.Text = ButtonText.BTN_OK;
  71. this.btnClose.Text = ButtonText.BTN_CANCEL;
  72. }
  73. #endregion
  74. #region 事件
  75. /// <summary>
  76. /// 窗体加载事件
  77. /// </summary>
  78. /// <param name="sender"></param>
  79. /// <param name="e"></param>
  80. private void FrmUser_Load(object sender, EventArgs e)
  81. {
  82. try
  83. {
  84. // 设置表格不自动创建列
  85. this.dgvUser.AutoGenerateColumns = false;
  86. this.dgvUser.Columns["Sel"].ReadOnly = false;
  87. this.txtUserCode.Text = this.SetUserCode;
  88. this.btnSearch_Click(null, null);
  89. }
  90. catch (Exception ex)
  91. {
  92. // 对异常进行共通处理
  93. ExceptionManager.HandleEventException(this.ToString(),
  94. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  95. }
  96. }
  97. /// <summary>
  98. /// 释放成员变量
  99. /// </summary>
  100. /// <param name="sender"></param>
  101. /// <param name="e"></param>
  102. private void FrmOrganization_FormClosed(object sender, FormClosedEventArgs e)
  103. {
  104. _instance = null;
  105. }
  106. /// <summary>
  107. /// 搜索按钮事件
  108. /// </summary>
  109. /// <param name="sender"></param>
  110. /// <param name="e"></param>
  111. private void btnSearch_Click(object sender, EventArgs e)
  112. {
  113. try
  114. {
  115. // 根据页面设定用户实体值
  116. this.GetUserEntityFromLayout();
  117. // 记录当前选中行
  118. int selectRowIndex = this._selecedRow;
  119. // 异步处理
  120. this.btnSearch.Enabled = false;
  121. this.btnClearCondition.Enabled = false;
  122. DataSet userDataSet = (DataSet)DoAsync(new BaseAsyncMethod(this.SearchUserData));
  123. this.btnSearch.Enabled = true;
  124. this.btnClearCondition.Enabled = true;
  125. this.scbOrganization.EditReadOnly = true;
  126. if (userDataSet != null)
  127. {
  128. base.DataSource = (DataSet)userDataSet;
  129. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  130. {
  131. this.dgvUser.DataSource = this.DataSource.Tables[0];
  132. if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
  133. {
  134. // 提示未查找到数据
  135. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  136. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  137. }
  138. else
  139. {
  140. if (selectRowIndex >= Constant.INT_IS_ZERO)
  141. {
  142. if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
  143. {
  144. this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Selected = true;
  145. this.dgvUser.CurrentCell = this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Cells["UserCode"];
  146. }
  147. else
  148. {
  149. this.dgvUser.Rows[selectRowIndex].Selected = true;
  150. this.dgvUser.CurrentCell = this.dgvUser.Rows[selectRowIndex].Cells["UserCode"];
  151. }
  152. }
  153. }
  154. }
  155. }
  156. this.dgvUser.IsSetInputColumnsColor = true;
  157. }
  158. catch (Exception ex)
  159. {
  160. this.btnSearch.Enabled = true;
  161. this.btnClearCondition.Enabled = true;
  162. // 对异常进行共通处理
  163. ExceptionManager.HandleEventException(this.ToString(),
  164. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  165. }
  166. }
  167. /// <summary>
  168. /// 清空输入查询寻条件
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void btnClearCondition_Click(object sender, EventArgs e)
  173. {
  174. this.txtUserCode.Clear();
  175. this.txtUserName.Clear();
  176. this.scbOrganization.ClearValue();
  177. this.txtMAC.Clear();
  178. this.txtRemarks.Clear();
  179. }
  180. /// <summary>
  181. /// 选中行发生改变时 有效停用相互切换
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void dgvUser_CellEnter(object sender, DataGridViewCellEventArgs e)
  186. {
  187. if (dgvUser.Rows.Count > Constant.INT_IS_ZERO)
  188. {
  189. this._selecedRow = this.dgvUser.CurrentCell.RowIndex;
  190. }
  191. }
  192. /// <summary>
  193. /// KeyDown事件
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void dgvUser_KeyDown(object sender, KeyEventArgs e)
  198. {
  199. try
  200. {
  201. // 拷贝
  202. if (e.KeyData == (Keys.Control | Keys.C))
  203. {
  204. if (dgvUser.CurrentRow != null
  205. && !string.IsNullOrEmpty(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + string.Empty))
  206. {
  207. try
  208. {
  209. Clipboard.SetText(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + string.Empty);
  210. }
  211. catch
  212. {
  213. }
  214. }
  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 F_MST_0203_FormClosed(object sender, FormClosedEventArgs e)
  230. {
  231. _instance = null;
  232. }
  233. /// <summary>
  234. /// 自动适应列宽事件
  235. /// </summary>
  236. /// <param name="sender"></param>
  237. /// <param name="e"></param>
  238. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  239. {
  240. this.dgvUser.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  241. }
  242. /// <summary>
  243. /// 窗体关闭事件
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. private void tsbtnClose_Click(object sender, EventArgs e)
  248. {
  249. this.Close();
  250. }
  251. /// <summary>
  252. /// 解锁按钮事件
  253. /// </summary>
  254. /// <param name="sender"></param>
  255. /// <param name="e"></param>
  256. private void tsbtnUnlock_Click(object sender, EventArgs e)
  257. {
  258. try
  259. {
  260. // 提示用户确认解锁
  261. DialogResult msgBoxResult = MessageBox.Show(
  262. string.Format(Messages.MSG_CMN_Q002, "该用户", "解锁"), this.Text,
  263. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  264. if (msgBoxResult == DialogResult.Yes)
  265. {
  266. int result = (int)DoAsync(new BaseAsyncMethod(this.UnlockUserStatus));//解锁按钮方法
  267. if (result > Constant.INT_IS_ZERO)
  268. {
  269. // 提示信息
  270. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "用户管理", "解锁"),
  271. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  272. // 重新加载数据
  273. this.btnSearch_Click(sender, e);
  274. }
  275. else
  276. {
  277. // 提示信息
  278. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "用户管理", "解锁"),
  279. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  280. }
  281. }
  282. }
  283. catch (Exception ex)
  284. {
  285. // 对异常进行共通处理
  286. ExceptionManager.HandleEventException(this.ToString(),
  287. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  288. }
  289. }
  290. /// <summary>
  291. /// 全选
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  296. {
  297. try
  298. {
  299. for (int i = 0; i < this.dgvUser.Rows.Count; i++)
  300. {
  301. this.dgvUser.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  302. }
  303. }
  304. catch (Exception ex)
  305. {
  306. // 对异常进行共通处理
  307. ExceptionManager.HandleEventException(this.ToString(),
  308. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  309. }
  310. }
  311. /// <summary>
  312. /// 确定
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void btnOK_Click(object sender, EventArgs e)
  317. {
  318. try
  319. {
  320. this.Commit();
  321. }
  322. catch (Exception ex)
  323. {
  324. // 对异常进行共通处理
  325. ExceptionManager.HandleEventException(this.ToString(),
  326. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  327. }
  328. }
  329. /// <summary>
  330. /// 关闭窗体
  331. /// </summary>
  332. /// <param name="sender"></param>
  333. /// <param name="e"></param>
  334. private void btnClose_Click(object sender, EventArgs e)
  335. {
  336. this.Close();
  337. }
  338. #endregion
  339. #region 私有方法
  340. /// <summary>
  341. /// 点击确定或者回车键时调用
  342. /// </summary>
  343. private void Commit()
  344. {
  345. try
  346. {
  347. DataTable invDt = (DataTable)this.dgvUser.DataSource;
  348. if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO)
  349. {
  350. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  351. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  352. return;
  353. }
  354. invDt.AcceptChanges();
  355. invDt = invDt.Copy();
  356. string filter = "Sel = 1";
  357. invDt.DefaultView.RowFilter = filter;
  358. invDt = invDt.DefaultView.ToTable();
  359. // 如果选中了数据就关闭窗体,反之则不关
  360. if (invDt.Rows.Count > Constant.INT_IS_ZERO)
  361. {
  362. SelTable = invDt;
  363. this.DialogResult = DialogResult.OK;
  364. this.Close();
  365. }
  366. else
  367. {
  368. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  369. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. throw ex;
  375. }
  376. }
  377. /// <summary>
  378. /// 获取用户列表
  379. /// </summary>
  380. /// <returns></returns>
  381. private DataSet SearchUserData()
  382. {
  383. try
  384. {
  385. return SystemModuleProxy.Service.SearchUserData(this._userInfo);
  386. }
  387. catch (Exception ex)
  388. {
  389. throw ex;
  390. }
  391. }
  392. /// <summary>
  393. /// 获取输入的用户信息
  394. /// </summary>
  395. /// <returns></returns>
  396. private SUserEntity GetUserEntityFromLayout()
  397. {
  398. this._userInfo = new SUserEntity();
  399. // 用户编码
  400. this._userInfo.UserCode = this.txtUserCode.Text.Trim();
  401. // 用户姓名
  402. this._userInfo.UserName = this.txtUserName.Text.Trim();
  403. // 所属部门
  404. this._userInfo.OrganizationCode = scbOrganization.SearchedValue + "";
  405. // 所属部门
  406. this._userInfo.OrganizationID = scbOrganization.SearchedPKMember;
  407. // MAC
  408. this._userInfo.LimitMAC = this.txtMAC.Text.Trim();
  409. this._userInfo.IsWorker = Constant.WorkerNoFlag.No.GetHashCode();
  410. // 备注
  411. this._userInfo.Remarks = this.txtRemarks.Text.Trim();
  412. return _userInfo;
  413. }
  414. /// <summary>
  415. /// 保存组织机构
  416. /// </summary>
  417. /// <returns>影响的行数</returns>
  418. private object UnlockUserStatus()
  419. {
  420. try
  421. {
  422. return SystemModuleProxy.Service.UnlockUserStatus(Convert.ToInt32(this.dgvUser.CurrentRow.Cells["UserID"].Value));
  423. }
  424. catch (Exception ex)
  425. {
  426. throw ex;
  427. }
  428. }
  429. #endregion
  430. }
  431. }