DelMattressExcutor.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using DirectService.Tools;
  7. using JLHHJSvr.BLL;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.Com.Model;
  10. using JLHHJSvr.LJException;
  11. using JLHHJSvr.Tools;
  12. using LJLib.DAL.SQL;
  13. using LJLib.Net.SPI.Server;
  14. using LJLib.SQLEX;
  15. namespace JLHHJSvr.Excutor
  16. {
  17. internal sealed class DelMattressExcutor : ExcutorBase<DelMattressRequest, DelMattressResponse>
  18. {
  19. protected override void ExcuteInternal(DelMattressRequest request, object state, DelMattressResponse rslt)
  20. {
  21. var tokendata = BllHelper.GetToken(request.token);
  22. if (tokendata == null)
  23. {
  24. rslt.ErrMsg = "会话已经中断,请重新登录";
  25. return;
  26. }
  27. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  28. using (var cmd = con.CreateCommand())
  29. {
  30. con.Open();
  31. // 初始化属性
  32. //AutoInit.AutoInitS(cmd, request.mattress);
  33. using (cmd.Transaction = con.BeginTransaction())
  34. {
  35. try
  36. {
  37. var power77 = UserHelper.CheckFuncPower(cmd, tokendata.empid, 77);
  38. if (!power77)
  39. {
  40. throw new LJCommonException("你没有删除权限");
  41. }
  42. foreach (int itemid in request.mattressids)
  43. {
  44. var mattressInfo = new u_mattress() { mattressid = itemid };
  45. if (DbSqlHelper.SelectOne(cmd, mattressInfo, "flag, js1_flag, mattresscode, parentid") != 1)
  46. {
  47. rslt.ErrMsg = "查找报价单据失败:" + itemid;
  48. return;
  49. }
  50. if (mattressInfo.flag == 1)
  51. {
  52. throw new LJCommonException("床垫已审核,不能删除!(" + mattressInfo.mattresscode + ")");
  53. }
  54. if (mattressInfo.js1_flag == 1)
  55. {
  56. throw new LJCommonException("资料已技术审核不能删除!(" + mattressInfo.mattresscode + ")");
  57. }
  58. if (mattressInfo.parentid == null || mattressInfo.parentid == 0)
  59. {
  60. var list = new List<u_mattress>();
  61. var outputFields = @"flag, js1_flag, mattresscode";
  62. var selectStr = @" SELECT flag, js1_flag, mattresscode, parentid FROM u_mattress";
  63. var whereList = new List<string>();
  64. whereList.Add("parentid = @parentid");
  65. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@parentid", mattressInfo.mattressid } }, "mattressid", outputFields, 0, 0, list);
  66. if (list.Count > 0)
  67. {
  68. foreach(var mtitem in list)
  69. {
  70. if (mtitem.flag == 1)
  71. {
  72. throw new LJCommonException("副规格床垫已审核,不能删除!(" + mtitem.mattresscode + ")");
  73. }
  74. if (mtitem.js1_flag == 1)
  75. {
  76. throw new LJCommonException("副规格床垫资料已技术审核不能删除!(" + mtitem.mattresscode + ")");
  77. }
  78. }
  79. }
  80. }
  81. if (DbSqlHelper.Delete(cmd, mattressInfo) <= 0)
  82. {
  83. throw new LJCommonException("因网络或其它原因,删除床垫报价操作失败!");
  84. }
  85. cmd.CommandText = @"DELETE u_mattress WHERE parentid = @parentid";
  86. cmd.Parameters.Clear();
  87. cmd.Parameters.AddWithValue("@parentid", itemid);
  88. cmd.ExecuteNonQuery();
  89. }
  90. cmd.Transaction.Commit();
  91. }
  92. catch (Exception e)
  93. {
  94. cmd.Transaction.Rollback();
  95. rslt.ErrMsg = e.ToString();
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }