DelMattressExcutor.cs 4.9 KB

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