F_MST_0202.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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 if (returnUserID == Constant.INT_IS_NEGATIE_SIX)
  232. {
  233. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\nAD域已存在,不允许创建用户"),
  234. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  235. }
  236. else
  237. {
  238. // 提示信息
  239. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "新建用户", "保存"),
  240. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  241. }
  242. }
  243. else
  244. {
  245. // 编辑
  246. this.btnSave.Enabled = false;
  247. this.btnCancel.Enabled = false;
  248. _userEntity.UserID = UserID;
  249. returnUserID = (int)DoAsync(new BaseAsyncMethod(EditUserInfo));
  250. this.btnSave.Enabled = true;
  251. this.btnCancel.Enabled = true;
  252. if (returnUserID > Constant.INT_IS_ZERO)
  253. {
  254. // 提示信息
  255. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "编辑用户", "保存"),
  256. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  257. this.Close();
  258. }
  259. // 组织机构不存在
  260. else if (returnUserID == -Constant.INT_IS_ONE)
  261. {
  262. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "不存在所选择的组织机构"),
  263. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  264. }
  265. // 组织机构是一级组织机构不允许建立用户
  266. else if (returnUserID == -Constant.INT_IS_TWO)
  267. {
  268. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n所选择的组织机构是一级组织机构,不允许创建用户"),
  269. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  270. }
  271. // 该组织机构下存在子级组织机构,不允许建立用户
  272. else if (returnUserID == -Constant.INT_IS_THREE)
  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_FIVE)
  278. {
  279. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n系统活动的用户数已经超过授权数,不允许创建用户"),
  280. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  281. }
  282. else if (returnUserID == -Constant.INT_IS_SIX)
  283. {
  284. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\n在审批流程节点中存在的用户不能停用"),
  285. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  286. }
  287. else if (returnUserID == -Constant.INT_IS_EIGHT)
  288. {
  289. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "\r\nAD域已存在,不允许创建用户"),
  290. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  291. }
  292. else
  293. {
  294. // 提示信息
  295. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "编辑用户", "保存"),
  296. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  297. }
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. this.btnSave.Enabled = true;
  303. this.btnCancel.Enabled = true;
  304. // 对异常进行共通处理
  305. ExceptionManager.HandleEventException(this.ToString(),
  306. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  307. }
  308. }
  309. /// <summary>
  310. /// 窗体加载事件
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void F_MST_0202_Load(object sender, EventArgs e)
  315. {
  316. try
  317. {
  318. if (this._editStatus == Constant.FormMode.CopyAndAdd)
  319. {
  320. this.Text = "复制工号【" + this.UserCode + "】";
  321. this.dtpLimitStartTime.Text = "8:00:00";
  322. this.dtpLimitEndTime.Text = "17:00:00";
  323. }
  324. //获取工种集合
  325. //GetJobs();
  326. // 为画面控件赋初始值
  327. this.chkValueFlag.Checked = true;
  328. this.dgvDataJobs.AutoGenerateColumns = false;
  329. // 加载打印机数据
  330. ClientRequestEntity cre = new ClientRequestEntity();
  331. cre.NameSpace = "MST0412";
  332. cre.Name = "GetBarcodePrinter";
  333. ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre);
  334. if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
  335. {
  336. DataTable dt = sre.Data.Tables[0];
  337. DataRow dr = dt.NewRow();
  338. dr["PrinterName"] = "无";
  339. dt.Rows.InsertAt(dr, 0);
  340. this.cobBarcodePrinter.DataSource = sre.Data.Tables[0];
  341. this.cobBarcodePrinter.DisplayMember = "PrinterName";
  342. this.cobBarcodePrinter.ValueMember = "PrinterID";
  343. }
  344. // 加载PLC
  345. cre = new ClientRequestEntity();
  346. cre.NameSpace = "MST0413";
  347. cre.Name = "GetPLC";
  348. sre = CommonModuleProxy.Service.DoRequest(cre);
  349. if (sre != null && sre.Status == Constant.ServiceResultStatus.Success)
  350. {
  351. DataTable dt = sre.Data.Tables[0];
  352. DataRow dr = dt.NewRow();
  353. dr["PLCName"] = "无";
  354. dt.Rows.InsertAt(dr, 0);
  355. this.cobPLC.DataSource = sre.Data.Tables[0];
  356. this.cobPLC.DisplayMember = "PLCName";
  357. this.cobPLC.ValueMember = "PLCID";
  358. }
  359. // 获取用户信息数据集
  360. DataSet userInfoData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserRowData));
  361. int isJobsHave = 0;
  362. if (userInfoData != null && userInfoData.Tables.Count > Constant.INT_IS_ZERO)
  363. {
  364. // 编辑数据 给页面所有项赋值
  365. if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  366. {
  367. DataRow userData = userInfoData.Tables[0].Rows[0];
  368. if (this._editStatus == Constant.FormMode.Edit)
  369. {
  370. this.txtUserCode.Text = userData["UserCode"].ToString();
  371. this.txtUserCode.Enabled = false;
  372. this.txtUserName.Text = userData["UserName"].ToString();
  373. }
  374. this.txtADUserCode.Text = userData["AD_USER_CODE"].ToString();
  375. this.txtMAC.Text = userData["LIMITMAC"].ToString();
  376. this.txtRemarks.Text = userData["Remarks"].ToString();
  377. this.chkValueFlag.Checked = userData["ValueFlag"].ToString() == "1" ? true : false;
  378. this.chkCanSmartLogin.Checked = userData["CanSmartLogin"].ToString() == "1" ? true : false;
  379. this.chkCanPCLogin.Checked = userData["CanPCLogin"].ToString() == "1" ? true : false;
  380. scbOrganization.CheckedData = userInfoData.Tables[0];
  381. scbOrganization.Text = userData["OrganizationName"].ToString();
  382. this.chkIsWorker.Checked = userData["IsWorker"].ToString() == "1" ? true : false;
  383. this.chkIsGroutingWorker.Checked = userData["IsGroutingWorker"].ToString() == "1" ? true : false;
  384. this.chkPublicBody.Checked = userData["ispublicbody"].ToString() == "1" ? true : false;
  385. this.chkPRD.Checked = userData["CanLoginPRD"].ToString() == "1" ? true : false;
  386. this.chkMBC.Checked = userData["CanLoginMBC"].ToString() == "1" ? true : false;
  387. if (userData["POST"] != DBNull.Value && userData["POST"] != null)
  388. {
  389. this.dkPost.PostName = userData["POSTName"].ToString();
  390. this.dkPost.PostID = Convert.ToInt32(userData["POSTId"]);
  391. }
  392. if (userData["LimitStartTime"] != DBNull.Value && userData["LimitStartTime"] != null)
  393. {
  394. this.cbTime.Checked = true;
  395. this.dtpLimitStartTime.Text = userData["LimitStartTime"].ToString();
  396. this.dtpLimitEndTime.Text = userData["LimitEndTime"].ToString();
  397. }
  398. else
  399. {
  400. this.cbTime.Checked = false;
  401. this.dtpLimitStartTime.Text = "8:00:00";
  402. this.dtpLimitEndTime.Text = "17:00:00";
  403. }
  404. // 条码打印机
  405. this.cobBarcodePrinter.SelectedValue = userData["BarcodePrinterID"];
  406. this.cobPLC.SelectedValue = userData["plcID"];
  407. }
  408. if (this._editStatus != Constant.FormMode.Add && userInfoData.Tables[1].Rows.Count > Constant.INT_IS_ZERO)
  409. {
  410. this.dgvDataJobs.AutoGenerateColumns = false;
  411. this.dgvDataJobs.DataSource = userInfoData.Tables[1];
  412. isJobsHave++;
  413. }
  414. }
  415. if (isJobsHave == Constant.INT_IS_ZERO)
  416. {
  417. _dtUserJobs.Columns.Add("JobsCode", System.Type.GetType("System.String"));
  418. _dtUserJobs.Columns.Add("JobsID", System.Type.GetType("System.String"));
  419. _dtUserJobs.Columns.Add("JobsName", System.Type.GetType("System.String"));
  420. _dtUserJobs.Columns.Add("Remarks", System.Type.GetType("System.String"));
  421. this.dgvDataJobs.DataSource = _dtUserJobs;
  422. }
  423. this.dgvDataJobs.IsSetInputColumnsColor = true;
  424. this.dtpLimitStartTime.Enabled = this.cbTime.Checked;
  425. this.dtpLimitEndTime.Enabled = this.cbTime.Checked;
  426. }
  427. catch (Exception ex)
  428. {
  429. // 对异常进行共通处理
  430. ExceptionManager.HandleEventException(this.ToString(),
  431. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  432. }
  433. }
  434. /// <summary>
  435. /// 输入工种编码
  436. /// </summary>
  437. /// <param name="sender"></param>
  438. /// <param name="e"></param>
  439. private void dgvDataJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  440. {
  441. try
  442. {
  443. if (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE)
  444. {
  445. return;
  446. }
  447. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  448. if ("JobsCode".Equals(columnItem.Name))
  449. {
  450. this._jobsCodeValue = this.dgvDataJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. // 对异常进行共通处理
  456. ExceptionManager.HandleEventException(this.ToString(),
  457. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  458. }
  459. }
  460. /// <summary>
  461. /// 弹出窗体
  462. /// </summary>
  463. /// <param name="sender"></param>
  464. /// <param name="e"></param>
  465. private void dgvDataJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  466. {
  467. #region 改用弹出窗体模式
  468. /*
  469. if (e.RowIndex != -1)
  470. {
  471. if (this.dgvDataJobs.Columns[e.ColumnIndex].Name == "JobsCode")
  472. {
  473. string JobsCode = this.dgvDataJobs.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  474. //看看这条记录有没有被选过
  475. for (int i = 0; i < this.dgvDataJobs.Rows.Count; i++)
  476. {
  477. if (i != e.RowIndex)
  478. {
  479. if (this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value != null)
  480. {
  481. if (JobsCode == this.dgvDataJobs.Rows[i].Cells["JobsCode"].Value.ToString())
  482. {
  483. // 提示信息
  484. MessageBox.Show("已经选择了该工种!",
  485. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  486. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  487. return;
  488. }
  489. }
  490. }
  491. }
  492. StringBuilder strbFilterExpressions = new StringBuilder();
  493. strbFilterExpressions.Append(string.Format("JobsId='{0}'", JobsCode));
  494. DataTable TableCopy = _dtJobs.Copy();
  495. TableCopy.DefaultView.RowFilter = strbFilterExpressions.ToString();
  496. DataTable EndTable = TableCopy.DefaultView.ToTable();
  497. if (EndTable.Rows.Count != 0)
  498. {
  499. this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsName"].Value = EndTable.Rows[0]["JobsName"].ToString();
  500. this.dgvDataJobs.Rows[e.RowIndex].Cells["Remarks"].Value = EndTable.Rows[0]["Remarks"].ToString();
  501. this.dgvDataJobs.Rows[e.RowIndex].Cells["JobsID"].Value = EndTable.Rows[0]["JobsID"].ToString();
  502. }
  503. else
  504. {
  505. this.dgvDataJobs.Rows.RemoveAt(e.RowIndex);
  506. }
  507. }
  508. }
  509. */
  510. #endregion
  511. try
  512. {
  513. if (this.dgvDataJobs.Rows.Count <= Constant.INT_IS_ONE || !_ShowFlag)
  514. {
  515. return;
  516. }
  517. DataGridViewRow rowItem = this.dgvDataJobs.Rows[e.RowIndex];
  518. DataGridViewColumn columnItem = this.dgvDataJobs.Columns[e.ColumnIndex];
  519. // 工种编号获取产品信息
  520. if ("JobsCode".Equals(columnItem.Name))
  521. {
  522. _ShowFlag = false;
  523. FormUtility.BindJobsRowDataSource(this.dgvDataJobs,
  524. e.RowIndex, columnItem.Name, _jobsCodeValue);
  525. // 设置可输入单元格的颜色
  526. this.dgvDataJobs.IsSetInputColumnsColor = true;
  527. }
  528. this._ShowFlag = true;
  529. }
  530. catch (Exception ex)
  531. {
  532. // 对异常进行共通处理
  533. ExceptionManager.HandleEventException(this.ToString(),
  534. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  535. }
  536. }
  537. /// <summary>
  538. /// 限制登陆时间选定改变事件
  539. /// </summary>
  540. /// <param name="sender"></param>
  541. /// <param name="e"></param>
  542. private void cbTime_CheckedChanged(object sender, EventArgs e)
  543. {
  544. this.dtpLimitStartTime.Enabled = this.cbTime.Checked;
  545. this.dtpLimitEndTime.Enabled = this.cbTime.Checked;
  546. }
  547. #endregion
  548. #region 私有方法
  549. /// <summary>
  550. /// 获取用户明细数据
  551. /// </summary>
  552. /// <returns></returns>
  553. private DataSet GetUserRowData()
  554. {
  555. try
  556. {
  557. return SystemModuleProxy.Service.GetUserRowData(UserID);
  558. }
  559. catch (Exception ex)
  560. {
  561. throw ex;
  562. }
  563. }
  564. /// <summary>
  565. /// 添加用户数据
  566. /// </summary>
  567. /// <returns></returns>
  568. private object AddUserInfo()
  569. {
  570. try
  571. {
  572. DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource;
  573. dtJobs.TableName = "dtJobs";
  574. this._userEntity.UserJobs = dtJobs;
  575. return SystemModuleProxy.Service.AddUserInfo(_userEntity);
  576. }
  577. catch (Exception ex)
  578. {
  579. throw ex;
  580. }
  581. }
  582. /// <summary>
  583. /// 是否存在相同的用户编码
  584. /// </summary>
  585. /// <returns></returns>
  586. private DataSet IsExistsUserCode()
  587. {
  588. try
  589. {
  590. return SystemModuleProxy.Service.IsExistsUserCode(this.txtUserCode.Text);
  591. }
  592. catch (Exception ex)
  593. {
  594. throw ex;
  595. }
  596. }
  597. /// <summary>
  598. /// 绑定下拉数据源
  599. /// </summary>
  600. /// <returns></returns>
  601. public DataTable datasourceCombox()
  602. {
  603. DataTable dt = new DataTable();
  604. dt.Columns.Add("ValueID");
  605. dt.Columns.Add("TextString");
  606. DataRow dr = dt.NewRow();
  607. dr["ValueID"] = 0;
  608. dr["TextString"] = "没有关联";
  609. dt.Rows.Add(dr);
  610. dr = dt.NewRow();
  611. dr["ValueID"] = 1;
  612. dr["TextString"] = "关联员工";
  613. dt.Rows.Add(dr);
  614. dr = dt.NewRow();
  615. dr["ValueID"] = 2;
  616. dr["TextString"] = "关联员工组";
  617. dt.Rows.Add(dr);
  618. return dt;
  619. }
  620. /// <summary>
  621. /// 编辑用户信息
  622. /// </summary>
  623. /// <returns></returns>
  624. private object EditUserInfo()
  625. {
  626. try
  627. {
  628. DataTable dtJobs = (DataTable)this.dgvDataJobs.DataSource;
  629. dtJobs.TableName = "dtJobs";
  630. this._userEntity.UserJobs = dtJobs;
  631. return SystemModuleProxy.Service.EditUserInfo(this._userEntity);
  632. }
  633. catch (Exception ex)
  634. {
  635. throw ex;
  636. }
  637. }
  638. /// <summary>
  639. /// 清空输入项
  640. /// </summary>
  641. private void InitializationForm()
  642. {
  643. this.txtUserCode.Clear();
  644. this.txtUserName.Clear();
  645. this.txtMAC.Clear();
  646. this.txtRemarks.Clear();
  647. this.scbOrganization.ClearValue();
  648. this.chkValueFlag.Checked = true;
  649. this._dtUserJobs.Rows.Clear();
  650. this.dgvDataJobs.IsSetInputColumnsColor = true;
  651. this.cobBarcodePrinter.SelectedIndex = 0;
  652. }
  653. /// <summary>
  654. /// 根据页面输入值,给用户对象实体赋值
  655. /// </summary>
  656. /// <returns></returns>
  657. private SUserEntity SetUserEntity()
  658. {
  659. SUserEntity userEntity = new SUserEntity();
  660. userEntity.AD_USER_CODE = this.txtADUserCode.Text.Trim();
  661. userEntity.UserCode = this.txtUserCode.Text.Trim();
  662. userEntity.UserName = this.txtUserName.Text.Trim();
  663. userEntity.OrganizationID = scbOrganization.SearchedPKMember;
  664. userEntity.IsWorker = chkIsWorker.Checked ? 1 : 0;
  665. userEntity.IsGroutingWorker = chkIsGroutingWorker.Checked ? 1 : 0;
  666. userEntity.LimitMAC = txtMAC.Text;
  667. if (this.cbTime.Checked == true)
  668. {
  669. userEntity.LimitStartTime = Convert.ToDateTime(dtpLimitStartTime.Text);
  670. userEntity.LimitEndTime = Convert.ToDateTime(dtpLimitEndTime.Text);
  671. }
  672. else
  673. {
  674. userEntity.LimitStartTime = null;
  675. userEntity.LimitEndTime = null;
  676. }
  677. if (this.dkPost.PostID != null)
  678. {
  679. userEntity.PostID = Convert.ToInt32(this.dkPost.PostID);
  680. }
  681. userEntity.CanSmartLogin = chkCanSmartLogin.Checked ? 1 : 0;
  682. userEntity.CanPCLogin = chkCanPCLogin.Checked ? 1 : 0;
  683. userEntity.Remarks = txtRemarks.Text;
  684. userEntity.ValueFlag = chkValueFlag.Checked ? 1 : 0;
  685. userEntity.Ispublicbody = chkPublicBody.Checked ? 1 : 0;
  686. userEntity.CanLoginPRD = "1"; // chkPRD.Checked ? "1" : "0";
  687. userEntity.CanLoginMBC = "0"; // chkMBC.Checked ? "1" : "0";
  688. // 新建用户默认密码
  689. DataSet ds = (DataSet)CommonModuleProxy.Service.GetSysSettingBySettingType("S_CMN_0001");
  690. string pwd = "dongke";
  691. if (ds.Tables[0].Rows.Count > 0)
  692. {
  693. pwd = ds.Tables[0].Rows[0]["SETTINGVALUE"].ToString();
  694. }
  695. userEntity.Password = Encryption.GetMD5String(pwd);
  696. if (this.cobBarcodePrinter.SelectedValue != null && this.cobBarcodePrinter.SelectedValue != DBNull.Value)
  697. {
  698. userEntity.BarcodePrinterID = Convert.ToInt32(this.cobBarcodePrinter.SelectedValue);
  699. }
  700. if (this.cobPLC.SelectedValue != null && this.cobPLC.SelectedValue != DBNull.Value)
  701. {
  702. userEntity.PLCID = Convert.ToInt32(this.cobPLC.SelectedValue);
  703. }
  704. return userEntity;
  705. }
  706. /// <summary>
  707. /// 验证输入格式是否正确
  708. /// </summary>
  709. /// <returns></returns>
  710. private bool CheckInputValidity()
  711. {
  712. if (string.IsNullOrEmpty(this.txtUserCode.Text.Trim()))
  713. {
  714. this.txtUserCode.IsMustInput = true;
  715. this.txtUserCode.Focus();
  716. return false;
  717. }
  718. this.txtUserCode.IsMustInput = false;
  719. if (string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
  720. {
  721. this.txtUserName.IsMustInput = true;
  722. this.txtUserName.Focus();
  723. return false;
  724. }
  725. this.txtUserName.IsMustInput = false;
  726. if (this.scbOrganization.SearchedPKMember == 0)
  727. {
  728. lblOrganization.IsMustInput = true;
  729. this.scbOrganization.Focus();
  730. return false;
  731. }
  732. lblOrganization.IsMustInput = false;
  733. return true;
  734. }
  735. /// <summary>
  736. /// 获取工种方法
  737. /// </summary>
  738. private void GetJobs()
  739. {
  740. try
  741. {
  742. //byte valueFlag = Convert.ToByte(false);
  743. //_dtJobs = SystemModuleProxy.Service.GetJobsData(valueFlag).Tables[0];
  744. //foreach(DataRow dr in _dtJobs.Rows)
  745. //{
  746. // dr["JobsCode"] = dr["JobsCode"].ToString() + "-" + dr["JobsName"].ToString();
  747. //}
  748. //this.JobsCode.DisplayMember = "JobsCode";
  749. //this.JobsCode.ValueMember = "JobsId";
  750. //this.JobsCode.DataSource = _dtJobs;
  751. }
  752. catch (Exception ex)
  753. {
  754. throw ex;
  755. }
  756. }
  757. #endregion
  758. }
  759. }