F_MST_0202.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0202.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.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. using Dongke.IBOSS.PRD.Client.Controls;
  20. using Dongke.IBOSS.PRD.Client.DataModels;
  21. using Dongke.IBOSS.PRD.WCF.DataModels;
  22. using Dongke.IBOSS.PRD.WCF.Proxys;
  23. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  24. namespace Dongke.IBOSS.PRD.Client.SystemModule
  25. {
  26. /// <summary>
  27. /// 新建/编辑用户管理
  28. /// </summary>
  29. public partial class F_MST_0202 : FormBase
  30. {
  31. #region 成员变量
  32. // 页面传过来用户ID
  33. private int _userID;
  34. // 用户实体类
  35. private SUserEntity _userEntity;
  36. // 编辑状态
  37. private Constant.FormMode _editStatus;
  38. // 新建的用户ID集合
  39. private List<int> _userIDList = new List<int>();
  40. // 用户代码
  41. private string _userCode;
  42. // 工种集合
  43. private DataTable _dtJobs;
  44. // 工种关联数据源
  45. private DataTable _dtUserJobs = new DataTable();
  46. // 记录编辑前的缺陷编码
  47. private string _jobsCodeValue;
  48. // 控制弹窗标识
  49. private bool _ShowFlag = true;
  50. #endregion
  51. #region 构造函数
  52. public F_MST_0202()
  53. {
  54. InitializeComponent();
  55. }
  56. /// <summary>
  57. /// 构造函数
  58. /// </summary>
  59. /// <param name="frmStatus">窗体状态</param>
  60. public F_MST_0202(Constant.FormMode frmStatus)
  61. {
  62. InitializeComponent();
  63. _editStatus = frmStatus;
  64. // 设置窗口标题,当为新建状态时显示新建用户,当为编辑状态时显示编辑用户
  65. if (frmStatus == Constant.FormMode.Add)
  66. {
  67. this.Text = FormTitles.F_MST_0202_ADD;
  68. this.dtpLimitStartTime.Text = "8:00:00";
  69. this.dtpLimitEndTime.Text = "17:00:00";
  70. }
  71. else if (frmStatus == Constant.FormMode.Edit)
  72. {
  73. this.Text = FormTitles.F_MST_0202_EDIT;
  74. this.txtUserCode.Enabled = false;
  75. }
  76. // 工具栏按钮文本赋值
  77. this.btnSave.Text = ButtonText.BTN_SAVE;
  78. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  79. }
  80. #endregion
  81. #region 属性
  82. /// <summary>
  83. /// 页面传过来的用户ID
  84. /// </summary>
  85. public int UserID
  86. {
  87. get
  88. {
  89. return this._userID;
  90. }
  91. set
  92. {
  93. this._userID = value;
  94. }
  95. }
  96. /// <summary>
  97. /// 页面传过来的用户代码
  98. /// </summary>
  99. public string UserCode
  100. {
  101. get
  102. {
  103. return this._userCode;
  104. }
  105. set
  106. {
  107. this._userCode = value;
  108. }
  109. }
  110. /// <summary>
  111. /// 用户ID集合
  112. /// </summary>
  113. public List<int> UserIDList
  114. {
  115. get
  116. {
  117. return _userIDList;
  118. }
  119. set
  120. {
  121. _userIDList = value;
  122. }
  123. }
  124. #endregion
  125. #region 事件
  126. /// <summary>
  127. /// 保存按钮事件
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. private void btnSave_Click(object sender, EventArgs e)
  132. {
  133. try
  134. {
  135. // 验证输入是否正确
  136. if (!this.CheckInputValidity())
  137. {
  138. return;
  139. }
  140. //校验绑定工种情况
  141. int rowCount = 0;
  142. foreach (DataGridViewRow gvrFor in this.dgvDataJobs.Rows)
  143. {
  144. if (gvrFor.IsNewRow == false)
  145. {
  146. //JobsID
  147. if (gvrFor.Cells["JobsID"].Value != null && gvrFor.Cells["JobsID"].Value.ToString() != "")
  148. {
  149. rowCount++;
  150. }
  151. }
  152. }
  153. if (chkIsWorker.Checked == true)
  154. {
  155. if (rowCount == Constant.INT_IS_ZERO)
  156. {
  157. // 提示信息
  158. MessageBox.Show("生产工号必须绑定至少一个工种!",
  159. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  160. return;
  161. }
  162. }
  163. else
  164. {
  165. if (rowCount > Constant.INT_IS_ONE)
  166. {
  167. // 提示信息
  168. MessageBox.Show("非生产工号只能绑定一个工种!",
  169. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  170. return;
  171. }
  172. }
  173. int returnUserID = Constant.INT_IS_ZERO;
  174. _userEntity = this.SetUserEntity();
  175. if (_editStatus == Constant.FormMode.Add || _editStatus == Constant.FormMode.CopyAndAdd)
  176. {
  177. // 判断是否存在重复的用户编号
  178. DataSet userCodeData = (DataSet)DoAsync(new BaseAsyncMethod(IsExistsUserCode));
  179. if (userCodeData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  180. {
  181. MessageBox.Show(string.Format(Messages.MSG_CMN_W011, this.txtUserCode.Text.Trim(), "用户信息"),
  182. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  183. this.txtUserCode.Focus();
  184. return;
  185. }
  186. if (_editStatus == Constant.FormMode.CopyAndAdd)
  187. {
  188. _userEntity.UserID = UserID;
  189. }
  190. // 新建用户,返回新建的用户ID
  191. this.btnSave.Enabled = false;
  192. this.btnCancel.Enabled = false;
  193. returnUserID = (int)DoAsync(new BaseAsyncMethod(AddUserInfo));
  194. this.btnSave.Enabled = true;
  195. this.btnCancel.Enabled = true;
  196. if (returnUserID > Constant.INT_IS_ZERO)
  197. {
  198. // 提示信息
  199. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建用户", "保存"),
  200. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  201. this._userIDList.Add(returnUserID);
  202. if (_editStatus == Constant.FormMode.CopyAndAdd)
  203. {
  204. this.Close();
  205. return;
  206. }
  207. this.InitializationForm();
  208. }// 组织机构不存在
  209. else if (returnUserID == -Constant.INT_IS_ONE)
  210. {
  211. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "不存在所选择的组织机构"),
  212. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  213. }
  214. // 组织机构是一级组织机构不允许建立用户
  215. else if (returnUserID == -Constant.INT_IS_TWO)
  216. {
  217. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构是一级组织机构,不允许创建用户"),
  218. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  219. }
  220. // 该组织机构下存在子级组织机构,不允许建立用户
  221. else if (returnUserID == -Constant.INT_IS_THREE)
  222. {
  223. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构存在子级组织,不允许创建用户"),
  224. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  225. }
  226. else if (returnUserID == -Constant.INT_IS_FIVE)
  227. {
  228. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n系统活动的用户数已经超过授权数,不允许创建用户"),
  229. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  230. }
  231. else
  232. {
  233. // 提示信息
  234. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "新建用户", "保存"),
  235. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  236. }
  237. }
  238. else
  239. {
  240. // 编辑
  241. this.btnSave.Enabled = false;
  242. this.btnCancel.Enabled = false;
  243. _userEntity.UserID = UserID;
  244. returnUserID = (int)DoAsync(new BaseAsyncMethod(EditUserInfo));
  245. this.btnSave.Enabled = true;
  246. this.btnCancel.Enabled = true;
  247. if (returnUserID > Constant.INT_IS_ZERO)
  248. {
  249. // 提示信息
  250. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "编辑用户", "保存"),
  251. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  252. this.Close();
  253. }
  254. // 组织机构不存在
  255. else if (returnUserID == -Constant.INT_IS_ONE)
  256. {
  257. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "不存在所选择的组织机构"),
  258. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  259. }
  260. // 组织机构是一级组织机构不允许建立用户
  261. else if (returnUserID == -Constant.INT_IS_TWO)
  262. {
  263. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构是一级组织机构,不允许创建用户"),
  264. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  265. }
  266. // 该组织机构下存在子级组织机构,不允许建立用户
  267. else if (returnUserID == -Constant.INT_IS_THREE)
  268. {
  269. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构存在子级组织,不允许创建用户"),
  270. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  271. }
  272. else if (returnUserID == -Constant.INT_IS_FIVE)
  273. {
  274. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n系统活动的用户数已经超过授权数,不允许创建用户"),
  275. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  276. }
  277. else if (returnUserID == -Constant.INT_IS_SIX)
  278. {
  279. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n在审批流程节点中存在的用户不能停用"),
  280. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  281. }
  282. else
  283. {
  284. // 提示信息
  285. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "编辑用户", "保存"),
  286. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  287. }
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. this.btnSave.Enabled = true;
  293. this.btnCancel.Enabled = true;
  294. // 对异常进行共通处理
  295. ExceptionManager.HandleEventException(this.ToString(),
  296. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  297. }
  298. }
  299. /// <summary>
  300. /// 窗体加载事件
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void F_MST_0202_Load(object sender, EventArgs e)
  305. {
  306. try
  307. {
  308. if (this._editStatus == Constant.FormMode.CopyAndAdd)
  309. {
  310. this.Text = "复制工号【" + this.UserCode + "】";
  311. this.dtpLimitStartTime.Text = "8:00:00";
  312. this.dtpLimitEndTime.Text = "17:00:00";
  313. }
  314. //获取工种集合
  315. //GetJobs();
  316. // 为画面控件赋初始值
  317. this.chkValueFlag.Checked = true;
  318. this.dgvDataJobs.AutoGenerateColumns = false;
  319. // 加载打印机数据
  320. ClientRequestEntity cre = new ClientRequestEntity();
  321. cre.NameSpace = "MST0412";
  322. cre.Name = "GetBarcodePrinter";
  323. ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre);
  324. if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
  325. {
  326. DataTable dt = sre.Data.Tables[0];
  327. DataRow dr = dt.NewRow();
  328. dr["PrinterName"] = "无";
  329. dt.Rows.InsertAt(dr, 0);
  330. this.cobBarcodePrinter.DataSource = sre.Data.Tables[0];
  331. this.cobBarcodePrinter.DisplayMember = "PrinterName";
  332. this.cobBarcodePrinter.ValueMember = "PrinterID";
  333. }
  334. // 加载PLC
  335. cre = new ClientRequestEntity();
  336. cre.NameSpace = "MST0413";
  337. cre.Name = "GetPLC";
  338. sre = CommonModuleProxy.Service.DoRequest(cre);
  339. if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
  340. {
  341. DataTable dt = sre.Data.Tables[0];
  342. DataRow dr = dt.NewRow();
  343. dr["PLCName"] = "无";
  344. dt.Rows.InsertAt(dr, 0);
  345. this.cobPLC.DataSource = sre.Data.Tables[0];
  346. this.cobPLC.DisplayMember = "PLCName";
  347. this.cobPLC.ValueMember = "PLCID";
  348. }
  349. // 获取用户信息数据集
  350. DataSet userInfoData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserRowData));
  351. int isJobsHave = 0;
  352. if (userInfoData != null && userInfoData.Tables.Count > Constant.INT_IS_ZERO)
  353. {
  354. // 编辑数据 给页面所有项赋值
  355. if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  356. {
  357. DataRow userData = userInfoData.Tables[0].Rows[0];
  358. if (this._editStatus == Constant.FormMode.Edit)
  359. {
  360. this.txtUserCode.Text = userData["UserCode"].ToString();
  361. this.txtUserCode.Enabled = false;
  362. this.txtUserName.Text = userData["UserName"].ToString();
  363. }
  364. this.txtMAC.Text = userData["LIMITMAC"].ToString();
  365. this.txtRemarks.Text = userData["Remarks"].ToString();
  366. this.chkValueFlag.Checked = userData["ValueFlag"].ToString() == "1" ? true : false;
  367. this.chkCanSmartLogin.Checked = userData["CanSmartLogin"].ToString() == "1" ? true : false;
  368. this.chkCanPCLogin.Checked = userData["CanPCLogin"].ToString() == "1" ? true : false;
  369. scbOrganization.CheckedData = userInfoData.Tables[0];
  370. scbOrganization.Text = userData["OrganizationName"].ToString();
  371. this.chkIsWorker.Checked = userData["IsWorker"].ToString() == "1" ? true : false;
  372. this.chkIsGroutingWorker.Checked = userData["IsGroutingWorker"].ToString() == "1" ? true : false;
  373. this.chkPublicBody.Checked = userData["ispublicbody"].ToString() == "1" ? true : false;
  374. this.chkPRD.Checked = userData["CanLoginPRD"].ToString() == "1" ? true : false;
  375. this.chkMBC.Checked = userData["CanLoginMBC"].ToString() == "1" ? true : false;
  376. if (userData["POST"] != DBNull.Value && userData["POST"] != null)
  377. {
  378. this.dkPost.PostName = userData["POSTName"].ToString();
  379. this.dkPost.PostID = Convert.ToInt32(userData["POSTId"]);
  380. }
  381. if (userData["LimitStartTime"] != DBNull.Value && userData["LimitStartTime"] != null)
  382. {
  383. this.cbTime.Checked = true;
  384. this.dtpLimitStartTime.Text = userData["LimitStartTime"].ToString();
  385. this.dtpLimitEndTime.Text = userData["LimitEndTime"].ToString();
  386. }
  387. else
  388. {
  389. this.cbTime.Checked = false;
  390. this.dtpLimitStartTime.Text = "8:00:00";
  391. this.dtpLimitEndTime.Text = "17:00:00";
  392. }
  393. // 条码打印机
  394. this.cobBarcodePrinter.SelectedValue = userData["BarcodePrinterID"];
  395. this.cobPLC.SelectedValue = userData["plcID"];
  396. }
  397. if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[1].Rows.Count > Constant.INT_IS_ZERO)
  398. {
  399. this.dgvDataJobs.AutoGenerateColumns = false;
  400. this.dgvDataJobs.DataSource = userInfoData.Tables[1];
  401. isJobsHave++;
  402. }
  403. }
  404. if (isJobsHave == Constant.INT_IS_ZERO)
  405. {
  406. _dtUserJobs.Columns.Add("JobsCode", System.Type.GetType("System.String"));
  407. _dtUserJobs.Columns.Add("JobsID", System.Type.GetType("System.String"));
  408. _dtUserJobs.Columns.Add("JobsName", System.Type.GetType("System.String"));
  409. _dtUserJobs.Columns.Add("Remarks", System.Type.GetType("System.String"));
  410. this.dgvDataJobs.DataSource = _dtUserJobs;
  411. }
  412. this.dgvDataJobs.IsSetInputColumnsColor = true;
  413. this.dtpLimitStartTime.Enabled = this.cbTime.Checked;
  414. this.dtpLimitEndTime.Enabled = this.cbTime.Checked;
  415. }
  416. catch (Exception ex)
  417. {
  418. // 对异常进行共通处理
  419. ExceptionManager.HandleEventException(this.ToString(),
  420. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  421. }
  422. }
  423. /// <summary>
  424. /// 输入工种编码
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. private void dgvDataJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  429. {
  430. try
  431. {
  432. if (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE)
  433. {
  434. return;
  435. }
  436. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  437. if ("JobsCode".Equals(columnItem.Name))
  438. {
  439. this._jobsCodeValue = this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  440. }
  441. }
  442. catch (Exception ex)
  443. {
  444. // 对异常进行共通处理
  445. ExceptionManager.HandleEventException(this.ToString(),
  446. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  447. }
  448. }
  449. /// <summary>
  450. /// 弹出窗体
  451. /// </summary>
  452. /// <param name="sender"></param>
  453. /// <param name="e"></param>
  454. private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  455. {
  456. #region 改用弹出窗体模式
  457. /*
  458. if (e.RowIndex != -1)
  459. {
  460. if (this.dgvDataJobs.Columns[e.ColumnIndex].Name == "JobsCode")
  461. {
  462. string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  463. //看看这条记录有没有被选过
  464. for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++)
  465. {
  466. if (i != e.RowIndex)
  467. {
  468. if (this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value != null)
  469. {
  470. if (JobsCode == this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value.ToString())
  471. {
  472. // 提示信息
  473. MessageBox.Show("已经选择了该工种!",
  474. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  475. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  476. return;
  477. }
  478. }
  479. }
  480. }
  481. StringBuilder strbFilterExpressions = new StringBuilder();
  482. strbFilterExpressions.Append(string.Format("JobsId='{0}'", JobsCode));
  483. DataTable TableCopy = _dtJobs.Copy();
  484. TableCopy.DefaultView.RowFilter = strbFilterExpressions.ToString();
  485. DataTable EndTable = TableCopy.DefaultView.ToTable();
  486. if (EndTable.Rows.Count != 0)
  487. {
  488. this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsName"].Value = EndTable.Rows[0]["JobsName"].ToString();
  489. this.dgvDataJobs.Rows[e.RowIndex].Cells["Remarks"].Value = EndTable.Rows[0]["Remarks"].ToString();
  490. this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsID"].Value = EndTable.Rows[0]["JobsID"].ToString();
  491. }
  492. else
  493. {
  494. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  495. }
  496. }
  497. }
  498. */
  499. #endregion
  500. try
  501. {
  502. if (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE || !_ShowFlag)
  503. {
  504. return;
  505. }
  506. DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex];
  507. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  508. // 工种编号获取产品信息
  509. if ("JobsCode".Equals(columnItem.Name))
  510. {
  511. _ShowFlag = false;
  512. FormUtility.BindJobsRowDataSource(this.dgvDataJobs,
  513. e.RowIndex, columnItem.Name, _jobsCodeValue);
  514. // 设置可输入单元格的颜色
  515. this.dgvDataJobs.IsSetInputColumnsColor = true;
  516. }
  517. this._ShowFlag = true;
  518. }
  519. catch (Exception ex)
  520. {
  521. // 对异常进行共通处理
  522. ExceptionManager.HandleEventException(this.ToString(),
  523. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  524. }
  525. }
  526. /// <summary>
  527. /// 限制登陆时间选定改变事件
  528. /// </summary>
  529. /// <param name="sender"></param>
  530. /// <param name="e"></param>
  531. private void cbTime_CheckedChanged(object sender, EventArgs e)
  532. {
  533. this.dtpLimitStartTime.Enabled = this.cbTime.Checked;
  534. this.dtpLimitEndTime.Enabled = this.cbTime.Checked;
  535. }
  536. #endregion
  537. #region 私有方法
  538. /// <summary>
  539. /// 获取用户明细数据
  540. /// </summary>
  541. /// <returns></returns>
  542. private DataSet GetUserRowData()
  543. {
  544. try
  545. {
  546. return SystemModuleProxy.Service.GetUserRowData(UserID);
  547. }
  548. catch (Exception ex)
  549. {
  550. throw ex;
  551. }
  552. }
  553. /// <summary>
  554. /// 添加用户数据
  555. /// </summary>
  556. /// <returns></returns>
  557. private object AddUserInfo()
  558. {
  559. try
  560. {
  561. DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource;
  562. dtJobs.TableName = "dtJobs";
  563. this._userEntity.UserJobs = dtJobs;
  564. return SystemModuleProxy.Service.AddUserInfo(_userEntity);
  565. }
  566. catch (Exception ex)
  567. {
  568. throw ex;
  569. }
  570. }
  571. /// <summary>
  572. /// 是否存在相同的用户编码
  573. /// </summary>
  574. /// <returns></returns>
  575. private DataSet IsExistsUserCode()
  576. {
  577. try
  578. {
  579. return SystemModuleProxy.Service.IsExistsUserCode(this.txtUserCode.Text);
  580. }
  581. catch (Exception ex)
  582. {
  583. throw ex;
  584. }
  585. }
  586. /// <summary>
  587. /// 绑定下拉数据源
  588. /// </summary>
  589. /// <returns></returns>
  590. public DataTable datasourceCombox()
  591. {
  592. DataTable dt = new DataTable();
  593. dt.Columns.Add("ValueID");
  594. dt.Columns.Add("TextString");
  595. DataRow dr = dt.NewRow();
  596. dr["ValueID"] = 0;
  597. dr["TextString"] = "没有关联";
  598. dt.Rows.Add(dr);
  599. dr = dt.NewRow();
  600. dr["ValueID"] = 1;
  601. dr["TextString"] = "关联员工";
  602. dt.Rows.Add(dr);
  603. dr = dt.NewRow();
  604. dr["ValueID"] = 2;
  605. dr["TextString"] = "关联员工组";
  606. dt.Rows.Add(dr);
  607. return dt;
  608. }
  609. /// <summary>
  610. /// 编辑用户信息
  611. /// </summary>
  612. /// <returns></returns>
  613. private object EditUserInfo()
  614. {
  615. try
  616. {
  617. DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource;
  618. dtJobs.TableName = "dtJobs";
  619. this._userEntity.UserJobs = dtJobs;
  620. return SystemModuleProxy.Service.EditUserInfo(this._userEntity);
  621. }
  622. catch (Exception ex)
  623. {
  624. throw ex;
  625. }
  626. }
  627. /// <summary>
  628. /// 清空输入项
  629. /// </summary>
  630. private void InitializationForm()
  631. {
  632. this.txtUserCode.Clear();
  633. this.txtUserName.Clear();
  634. this.txtMAC.Clear();
  635. this.txtRemarks.Clear();
  636. this.scbOrganization.ClearValue();
  637. this.chkValueFlag.Checked = true;
  638. this._dtUserJobs.Rows.Clear();
  639. this.dgvDataJobs.IsSetInputColumnsColor = true;
  640. this.cobBarcodePrinter.SelectedIndex = 0;
  641. }
  642. /// <summary>
  643. /// 根据页面输入值,给用户对象实体赋值
  644. /// </summary>
  645. /// <returns></returns>
  646. private SUserEntity SetUserEntity()
  647. {
  648. SUserEntity userEntity = new SUserEntity();
  649. userEntity.UserCode = this.txtUserCode.Text.Trim();
  650. userEntity.UserName = this.txtUserName.Text.Trim();
  651. userEntity.OrganizationID = scbOrganization.SearchedPKMember;
  652. userEntity.IsWorker = chkIsWorker.Checked ? 1 : 0;
  653. userEntity.IsGroutingWorker = chkIsGroutingWorker.Checked ? 1 : 0;
  654. userEntity.LimitMAC = txtMAC.Text;
  655. if (this.cbTime.Checked == true)
  656. {
  657. userEntity.LimitStartTime = Convert.ToDateTime(dtpLimitStartTime.Text);
  658. userEntity.LimitEndTime = Convert.ToDateTime(dtpLimitEndTime.Text);
  659. }
  660. else
  661. {
  662. userEntity.LimitStartTime = null;
  663. userEntity.LimitEndTime = null;
  664. }
  665. if (this.dkPost.PostID != null)
  666. {
  667. userEntity.PostID = Convert.ToInt32(this.dkPost.PostID);
  668. }
  669. userEntity.CanSmartLogin = chkCanSmartLogin.Checked ? 1 : 0;
  670. userEntity.CanPCLogin = chkCanPCLogin.Checked ? 1 : 0;
  671. userEntity.Remarks = txtRemarks.Text;
  672. userEntity.ValueFlag = chkValueFlag.Checked ? 1 : 0;
  673. userEntity.Ispublicbody = chkPublicBody.Checked ? 1 : 0;
  674. userEntity.CanLoginPRD = "1"; // chkPRD.Checked ? "1" : "0";
  675. userEntity.CanLoginMBC = "0"; // chkMBC.Checked ? "1" : "0";
  676. // 新建用户默认密码
  677. DataSet ds = (DataSet)CommonModuleProxy.Service.GetSysSettingBySettingType("S_CMN_0001");
  678. string pwd = "dongke";
  679. if (ds.Tables[0].Rows.Count > 0)
  680. {
  681. pwd = ds.Tables[0].Rows[0]["SETTINGVALUE"].ToString();
  682. }
  683. userEntity.Password = Encryption.GetMD5String(pwd);
  684. if (this.cobBarcodePrinter.SelectedValue != null && this.cobBarcodePrinter.SelectedValue != DBNull.Value)
  685. {
  686. userEntity.BarcodePrinterID = Convert.ToInt32(this.cobBarcodePrinter.SelectedValue);
  687. }
  688. if (this.cobPLC.SelectedValue != null && this.cobPLC.SelectedValue != DBNull.Value)
  689. {
  690. userEntity.PLCID = Convert.ToInt32(this.cobPLC.SelectedValue);
  691. }
  692. return userEntity;
  693. }
  694. /// <summary>
  695. /// 验证输入格式是否正确
  696. /// </summary>
  697. /// <returns></returns>
  698. private bool CheckInputValidity()
  699. {
  700. if (string.IsNullOrEmpty(this.txtUserCode.Text.Trim()))
  701. {
  702. this.txtUserCode.IsMustInput = true;
  703. this.txtUserCode.Focus();
  704. return false;
  705. }
  706. this.txtUserCode.IsMustInput = false;
  707. if (string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
  708. {
  709. this.txtUserName.IsMustInput = true;
  710. this.txtUserName.Focus();
  711. return false;
  712. }
  713. this.txtUserName.IsMustInput = false;
  714. if (this.scbOrganization.SearchedPKMember == 0)
  715. {
  716. lblOrganization.IsMustInput = true;
  717. this.scbOrganization.Focus();
  718. return false;
  719. }
  720. lblOrganization.IsMustInput = false;
  721. return true;
  722. }
  723. /// <summary>
  724. /// 获取工种方法
  725. /// </summary>
  726. private void GetJobs()
  727. {
  728. try
  729. {
  730. //byte valueFlag = Convert.ToByte(false);
  731. //_dtJobs = SystemModuleProxy.Service.GetJobsData(valueFlag).Tables[0];
  732. //foreach(DataRow dr in _dtJobs.Rows)
  733. //{
  734. // dr["JobsCode"] = dr["JobsCode"].ToString() + "-" + dr["JobsName"].ToString();
  735. //}
  736. //this.JobsCode.DisplayMember = "JobsCode";
  737. //this.JobsCode.ValueMember = "JobsId";
  738. //this.JobsCode.DataSource = _dtJobs;
  739. }
  740. catch (Exception ex)
  741. {
  742. throw ex;
  743. }
  744. }
  745. #endregion
  746. }
  747. }