DeleteMattressFormulaExcutor.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.LJException;
  10. using LJLib.DAL.SQL;
  11. using LJLib.Net.SPI.Server;
  12. namespace JLHHJSvr.Excutor
  13. {
  14. internal sealed class DeleteMattressFormulaExcutor : ExcutorBase<DeleteMattressFormulaRequest, DeleteMattressFormulaResponse>
  15. {
  16. protected override void ExcuteInternal(DeleteMattressFormulaRequest request, object state, DeleteMattressFormulaResponse rslt)
  17. {
  18. var tokendata = BllHelper.GetToken(request.token);
  19. if (tokendata == null)
  20. {
  21. rslt.ErrMsg = "会话已经中断,请重新登录";
  22. return;
  23. }
  24. if (!request.list.Any())
  25. {
  26. rslt.ErrMsg = "至少提交一条需要删除的记录";
  27. return;
  28. }
  29. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  30. using (var cmd = con.CreateCommand())
  31. {
  32. con.Open();
  33. using (cmd.Transaction = con.BeginTransaction())
  34. {
  35. try
  36. {
  37. foreach (var mattress in request.list)
  38. {
  39. if (DbSqlHelper.Delete(cmd, mattress) == 0)
  40. {
  41. throw new LJCommonException($"床垫公式定义:{mattress.formulakind}不存在");
  42. }
  43. }
  44. cmd.Transaction.Commit();
  45. }
  46. catch (Exception e)
  47. {
  48. cmd.Transaction.Rollback();
  49. rslt.ErrMsg = e.ToString();
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }