DelMattressExcutor.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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,erp_mtrlid") != 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.erp_mtrlid > 0)
  59. {
  60. throw new LJCommonException($"床垫报价[{mattressInfo.mattresscode}]已生成L1物料编码,无法删除!");
  61. }
  62. if (mattressInfo.parentid == null || mattressInfo.parentid == 0)
  63. {
  64. var list = new List<u_mattress>();
  65. var outputFields = @"flag, js1_flag, mattresscode";
  66. var selectStr = @" SELECT flag, js1_flag, mattresscode, parentid FROM u_mattress";
  67. var whereList = new List<string>();
  68. whereList.Add("parentid = @parentid");
  69. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), new Dictionary<string, object>() { { "@parentid", mattressInfo.mattressid } }, "mattressid", outputFields, 0, 0, list);
  70. if (list.Count > 0)
  71. {
  72. foreach(var mtitem in list)
  73. {
  74. if (mtitem.flag == 1)
  75. {
  76. throw new LJCommonException("副规格床垫已审核,不能删除!(" + mtitem.mattresscode + ")");
  77. }
  78. if (mtitem.js1_flag == 1)
  79. {
  80. throw new LJCommonException("副规格床垫资料已技术审核不能删除!(" + mtitem.mattresscode + ")");
  81. }
  82. }
  83. }
  84. }
  85. if (DbSqlHelper.Delete(cmd, mattressInfo) <= 0)
  86. {
  87. throw new LJCommonException("因网络或其它原因,删除床垫报价操作失败!");
  88. }
  89. cmd.CommandText = @"DELETE u_mattress WHERE parentid = @parentid";
  90. cmd.Parameters.Clear();
  91. cmd.Parameters.AddWithValue("@parentid", itemid);
  92. cmd.ExecuteNonQuery();
  93. }
  94. cmd.Transaction.Commit();
  95. }
  96. catch (Exception e)
  97. {
  98. cmd.Transaction?.Rollback();
  99. rslt.ErrMsg = e.Message;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }