SaveDeptExcutor.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using JLHHJSvr.BLL;
  7. using JLHHJSvr.Com;
  8. using JLHHJSvr.Helper;
  9. using JLHHJSvr.LJException;
  10. using JLHHJSvr.Tools;
  11. using LJLib.DAL.SQL;
  12. using LJLib.Net.SPI.Server;
  13. using LJLib.SQLEX;
  14. namespace JLHHJSvr.Excutor
  15. {
  16. internal sealed class SaveDeptExcutor : ExcutorBase<SaveDeptRequest, SaveDeptResponse>
  17. {
  18. protected override void ExcuteInternal(SaveDeptRequest request, object state, SaveDeptResponse rslt)
  19. {
  20. var tokendata = BllHelper.GetToken(request.token);
  21. if (tokendata == null)
  22. {
  23. rslt.ErrMsg = "会话已经中断,请重新登录";
  24. return;
  25. }
  26. if (request.dept == null)
  27. {
  28. rslt.ErrMsg = "未提交部门信息";
  29. return;
  30. }
  31. if (string.IsNullOrEmpty(request.dept.deptname))
  32. {
  33. rslt.ErrMsg = "请录入部门名称!";
  34. return;
  35. }
  36. if (request.dept.pricelistid == null || request.dept.pricelistid <= 0)
  37. {
  38. rslt.ErrMsg = "请选择价格表!";
  39. return;
  40. }
  41. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  42. using (var cmd = con.CreateCommand())
  43. {
  44. con.Open();
  45. // 初始化属性
  46. AutoInit.AutoInitS(cmd, request.dept);
  47. var helper = HelperBase.GetHelper<BasicInfoHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  48. using (cmd.Transaction = con.BeginTransaction())
  49. {
  50. try
  51. {
  52. var dtNow = DateTime.Now;
  53. helper.SaveDept(request.dept);
  54. cmd.Transaction.Commit();
  55. }
  56. catch (Exception e)
  57. {
  58. cmd.Transaction?.Rollback();
  59. rslt.ErrMsg = e.Message;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }