F_MST_0102.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0102.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.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.SystemModule
  22. {
  23. /// <summary>
  24. /// 组织机构新建/编辑界面
  25. /// </summary>
  26. public partial class F_MST_0102 : FormBase
  27. {
  28. #region 成员变量
  29. // 存储窗口的编辑状态
  30. private Constant.FormMode _editStatus;
  31. // 修改组织机构时存储上个窗口传过来的ID
  32. private int _organizationID;
  33. // 组织机构ID列表
  34. private List<int> _organizationIDList = new List<int>();
  35. // 组织机构编码
  36. private string _organizationCode;
  37. // 封装组织机构实体
  38. private OrganizationEntity _organization = new OrganizationEntity();
  39. // 上个窗口传过来的上级部门ID
  40. private int _parentOrganizationID;
  41. // 上个窗口传过来的上级部门编码
  42. private string _parentOrganizationCode;
  43. // 上个窗口传过来的上级部门名称
  44. private string _parentOrganizationName;
  45. // 过来的上级部门编码
  46. private string _parentOrganizationCodeTemp;
  47. #endregion
  48. #region 属性
  49. /// <summary>
  50. /// 父窗体组织机构编码
  51. /// </summary>
  52. public string ParentOrganizationCodeTemp
  53. {
  54. get
  55. {
  56. return _parentOrganizationCodeTemp;
  57. }
  58. set
  59. {
  60. _parentOrganizationCodeTemp = value;
  61. }
  62. }
  63. /// <summary>
  64. /// 组织机构ID列表
  65. /// </summary>
  66. public List<int> OrganizationIDList
  67. {
  68. get
  69. {
  70. return _organizationIDList;
  71. }
  72. set
  73. {
  74. _organizationIDList = value;
  75. }
  76. }
  77. /// <summary>
  78. /// 组织机构编码
  79. /// </summary>
  80. public string OrganizationCode
  81. {
  82. get
  83. {
  84. return _organizationCode;
  85. }
  86. set
  87. {
  88. _organizationCode = value;
  89. }
  90. }
  91. /// <summary>
  92. /// 上个窗口传过来的上级部门
  93. /// </summary>
  94. public int ParentOrganizationID
  95. {
  96. get
  97. {
  98. return _parentOrganizationID;
  99. }
  100. set
  101. {
  102. _parentOrganizationID = value;
  103. }
  104. }
  105. /// <summary>
  106. /// 上个窗口传过来的上级部门编码
  107. /// </summary>
  108. public string ParentOrganizationCode
  109. {
  110. get
  111. {
  112. return _parentOrganizationCode;
  113. }
  114. set
  115. {
  116. _parentOrganizationCode = value;
  117. }
  118. }
  119. /// <summary>
  120. /// 上个窗口传过来的上级部门名称
  121. /// </summary>
  122. public string ParentOrganizationName
  123. {
  124. get
  125. {
  126. return _parentOrganizationName;
  127. }
  128. set
  129. {
  130. _parentOrganizationName = value;
  131. }
  132. }
  133. #endregion
  134. #region 构造函数
  135. /// <summary>
  136. /// 构造函数
  137. /// </summary>
  138. public F_MST_0102()
  139. : this(Constant.FormMode.Add)
  140. {
  141. }
  142. /// <summary>
  143. /// 构造函数
  144. /// </summary>
  145. public F_MST_0102(Constant.FormMode editStatus)
  146. : this(editStatus, 0)
  147. {
  148. }
  149. /// <summary>
  150. /// 构造函数
  151. /// </summary>
  152. public F_MST_0102(Constant.FormMode editStatus, int organizationID)
  153. {
  154. InitializeComponent();
  155. this._editStatus = editStatus;
  156. // 根据新建、编辑状态为标题赋值
  157. if (editStatus == Constant.FormMode.Add)
  158. {
  159. this.Text = FormTitles.F_MST_0102_ADD;
  160. }
  161. else
  162. {
  163. this.Text = FormTitles.F_MST_0102_EDIT;
  164. // 存储上个窗口传过来的组织机构ID
  165. this._organizationID = organizationID;
  166. }
  167. // 按钮文本
  168. this.btnSave.Text = ButtonText.BTN_SAVE;
  169. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  170. }
  171. #endregion
  172. #region 事件
  173. /// <summary>
  174. /// 关闭按钮事件
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void btnClose_Click(object sender, EventArgs e)
  179. {
  180. this.Close();
  181. }
  182. /// <summary>
  183. /// 保存按钮事件
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void btnSave_Click(object sender, EventArgs e)
  188. {
  189. try
  190. {
  191. // 验证信息是否完整
  192. bool validResult = IsValidData();
  193. if (validResult)
  194. {
  195. string OrgCode = (string)DoAsync(new BaseAsyncMethod(() =>
  196. {
  197. return SystemModuleProxy.Service.GetOrganizationCode(this.ParentOrganizationCode);
  198. }));
  199. this.ParentOrganizationCodeTemp = OrgCode;
  200. this._organization = this.GetOrganization();//获取组织机构实体类
  201. this.btnSave.Enabled = false;
  202. this.btnCancel.Enabled = false;
  203. int result = (int)DoAsync(new BaseAsyncMethod(this.SaveOrganization));//保存按钮方法
  204. this.btnSave.Enabled = true;
  205. this.btnCancel.Enabled = true;
  206. if ((int)result > Constant.INT_IS_ZERO)//保存成功
  207. {
  208. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "组织机构", "保存"),
  209. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  210. this._organizationIDList.Add(Convert.ToInt32(result));
  211. this.DialogResult = DialogResult.OK;
  212. }
  213. else if (result == Constant.RETURN_IS_EXIST)
  214. {
  215. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "系统中存在有效的运营中心"),
  216. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  217. return;
  218. }
  219. else if (result == Constant.RETURN_IS_HAVEVALIDCHILD)//
  220. {
  221. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在有效的下级组织机构"),
  222. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  223. return;
  224. }
  225. else if (result == Constant.RETURN_IS_ENABLETOOPERATE)
  226. {
  227. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在员工"),
  228. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  229. return;
  230. }
  231. else if (result == Constant.RETURN_IS_DATAISNOTVALID)
  232. {
  233. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "该组织机构存在用户"),
  234. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  235. return;
  236. }
  237. else //保存机构有错误
  238. {
  239. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "组织机构", "保存"),
  240. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  241. }
  242. if (this._editStatus == Constant.FormMode.Edit)
  243. {
  244. this.Close();
  245. }
  246. else
  247. {
  248. // 重置窗口数据
  249. this.ResetFormData();
  250. }
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. this.btnSave.Enabled = true;
  256. this.btnCancel.Enabled = true;
  257. // 对异常进行共通处理
  258. ExceptionManager.HandleEventException(this.ToString(),
  259. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  260. }
  261. }
  262. /// <summary>
  263. /// 获取组织机构结果集
  264. /// </summary>
  265. /// <returns></returns>
  266. private DataSet GetOrganizationDataSource()
  267. {
  268. try
  269. {
  270. OrganizationEntity organization = new OrganizationEntity();
  271. // 票号开头字母
  272. organization.LetterMarket = this.LetterMarket.Text.Trim();
  273. // 联系电话
  274. organization.Telephone = this.txtTelephone.Text.Trim();
  275. // 地址
  276. organization.Address = this.txtAddress.Text;
  277. // 备注
  278. organization.Remarks = this.txtRemarks.Text;
  279. // 正常标识
  280. organization.ValueFlags = null;
  281. organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
  282. organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
  283. this._organization = organization;
  284. return SystemModuleProxy.Service.SelectOrganizationData(organization);
  285. }
  286. catch (Exception ex)
  287. {
  288. throw ex;
  289. }
  290. }
  291. /// <summary>
  292. /// 票头字母的限制输入
  293. /// </summary>
  294. /// <param name="sender"></param>
  295. /// <param name="e"></param>
  296. private void txtLetterMarket_KeyPress(object sender, KeyPressEventArgs e)
  297. {
  298. if ((e.KeyChar >= 'A' && e.KeyChar <= 'Z'))
  299. {
  300. e.Handled = false;
  301. }
  302. else
  303. {
  304. if ((int)e.KeyChar != Constant.INT_IS_EIGHT)
  305. {
  306. e.Handled = true;
  307. }
  308. }
  309. }
  310. /// <summary>
  311. /// 窗体加载事件
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void F_MST_0102_Load(object sender, EventArgs e)
  316. {
  317. try
  318. {
  319. // 若状态是添加,则有效标志为可用并且不显示
  320. if (this._editStatus == Constant.FormMode.Add)
  321. {
  322. this.chkValueFlag.Checked = true;
  323. this.chkValueFlag.Visible = false;
  324. this.txtOrganization.Text = ParentOrganizationName;
  325. }
  326. // 若状态是修改,则为窗口各控件赋值
  327. else
  328. {
  329. this.SetOrganizationData();
  330. }
  331. this.txtOrganizationName.Focus();
  332. }
  333. catch (Exception ex)
  334. {
  335. // 对异常进行共通处理
  336. ExceptionManager.HandleEventException(this.ToString(),
  337. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  338. }
  339. }
  340. #endregion
  341. #region 私有方法
  342. /// <summary>
  343. /// 为窗体各个控赋值
  344. /// </summary>
  345. private void SetOrganizationData()
  346. {
  347. try
  348. {
  349. // 获取组织机构信息
  350. this._organization = new OrganizationEntity();
  351. this._organization.OrganizationID = this._organizationID;
  352. DataSet result = (DataSet)DoAsync(new BaseAsyncMethod(this.GetOrganizationRowData));
  353. if (result != null && result.Tables.Count > Constant.INT_IS_ZERO && result.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  354. {
  355. DataRow organizationRow = result.Tables[0].Rows[0];
  356. // 编码
  357. this.txtOrganizationCode.Text = organizationRow["OrganizationCode"].ToString();
  358. // 名称
  359. this.txtOrganizationName.Text = organizationRow["OrganizationName"].ToString();
  360. // 全称
  361. this.txtOrganizationFullName.Text = organizationRow["OrganizationFullName"].ToString();
  362. // 负责人
  363. this.txtLeader.Text = organizationRow["Leader"].ToString();
  364. // 票头字母
  365. this.LetterMarket.Text = organizationRow["LetterMarket"].ToString();
  366. // 联系电话
  367. this.txtTelephone.Text = organizationRow["Telephone"].ToString();
  368. // 地址
  369. this.txtAddress.Text = organizationRow["Address"].ToString();
  370. // 备注
  371. this.txtRemarks.Text = organizationRow["Remarks"].ToString();
  372. // 正常标识
  373. this.chkValueFlag.Checked = Convert.ToBoolean(Convert.ToInt32(organizationRow["ValueFlag"]));
  374. this._organization.AccountID = Convert.ToInt32(organizationRow["AccountID"].ToString());
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. throw ex;
  380. }
  381. }
  382. /// <summary>
  383. /// 获取组织机构数据
  384. /// </summary>
  385. /// <returns></returns>
  386. private DataSet GetOrganizationRowData()
  387. {
  388. try
  389. {
  390. return SystemModuleProxy.Service.GetOrganizationRowData(this._organizationID);
  391. }
  392. catch (Exception ex)
  393. {
  394. throw ex;
  395. }
  396. }
  397. /// <summary>
  398. /// 验证输入是否完整
  399. /// </summary>
  400. /// <returns></returns>
  401. private bool IsValidData()
  402. {
  403. try
  404. {
  405. // 名称不能为空
  406. if (string.IsNullOrEmpty(this.txtOrganizationName.Text.Trim()))
  407. {
  408. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "名称"),
  409. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  410. this.txtOrganizationName.Focus();
  411. return false;
  412. }
  413. // 名称不能包含“→”
  414. else
  415. {
  416. if (this.txtOrganizationName.Text.Trim().Contains("→"))
  417. {
  418. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "名称不能包含“→”"),
  419. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  420. this.txtOrganizationName.Focus();
  421. return false;
  422. }
  423. }
  424. // 票头字母必须是两位字母
  425. if (!string.IsNullOrEmpty(this.LetterMarket.Text)
  426. && this.LetterMarket.Text.Trim().Length != Constant.INT_IS_TWO)
  427. {
  428. MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "票头字母必须是两位字母"),
  429. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  430. this.LetterMarket.Focus();
  431. return false;
  432. }
  433. return true;
  434. }
  435. catch (Exception ex)
  436. {
  437. throw ex;
  438. }
  439. }
  440. /// <summary>
  441. /// 保存组织机构
  442. /// </summary>
  443. /// <returns>影响的行数</returns>
  444. private object SaveOrganization()
  445. {
  446. try
  447. {
  448. OrganizationEntity organization = GetOrganization();
  449. return SystemModuleProxy.Service.SaveOrganization(organization);
  450. }
  451. catch (Exception ex)
  452. {
  453. throw ex;
  454. }
  455. }
  456. /// <summary>
  457. /// 给组织机构实体类传值
  458. /// </summary>
  459. /// <returns></returns>
  460. private OrganizationEntity GetOrganization()
  461. {
  462. OrganizationEntity organization = new OrganizationEntity();
  463. // 组织机构ID
  464. organization.OrganizationID = this._organizationID;
  465. // 编码
  466. organization.OrganizationCode = this.txtOrganizationCode.Text.Trim();
  467. // 名称
  468. organization.OrganizationName = this.txtOrganizationName.Text.Trim();
  469. // 全称 →
  470. organization.OrganizationFullName = this.txtOrganizationFullName.Text.Trim();
  471. // 负责人
  472. organization.Leader = this.txtLeader.Text.Trim();
  473. organization.ParentOrganizationID = this.ParentOrganizationID;
  474. organization.ParentOrganizationCode = this.ParentOrganizationCode;
  475. // 票头字母
  476. organization.LetterMarket = this.LetterMarket.Text.Trim();
  477. // 联系电话
  478. organization.Telephone = this.txtTelephone.Text.Trim();
  479. // 地址
  480. organization.Address = this.txtAddress.Text;
  481. // 备注
  482. organization.Remarks = this.txtRemarks.Text;
  483. // 正常标识
  484. organization.ValueFlag = Convert.ToByte(this.chkValueFlag.Checked);
  485. organization.in_UserID = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID;
  486. organization.in_AccountID = LogInUserInfo.CurrentUser.CurrentUserEntity.AccountID;
  487. return organization;
  488. }
  489. /// <summary>
  490. /// 重置窗口数据
  491. /// </summary>
  492. private void ResetFormData()
  493. {
  494. // 组织机构ID
  495. this._organizationID = Constant.INT_IS_ZERO;
  496. // 编码
  497. this.txtOrganizationCode.Clear();
  498. // 名称
  499. this.txtOrganizationName.Clear();
  500. // 全称
  501. this.txtOrganizationFullName.Clear();
  502. // 负责人
  503. this.txtLeader.Clear();
  504. // 票头字母
  505. this.LetterMarket.Clear();
  506. // 联系电话
  507. this.txtTelephone.Clear();
  508. // 地址
  509. this.txtAddress.Clear();
  510. // 备注
  511. this.txtRemarks.Clear();
  512. // 正常标识
  513. this.chkValueFlag.Checked = true;
  514. }
  515. #endregion
  516. }
  517. }