DeleteBedNetAreaExcutor.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Data.SqlClient;
  3. using System.Linq;
  4. using JLHHJSvr.BLL;
  5. using JLHHJSvr.Com;
  6. using JLHHJSvr.LJException;
  7. using LJLib.DAL.SQL;
  8. using LJLib.Net.SPI.Server;
  9. namespace JLHHJSvr.Excutor
  10. {
  11. internal sealed class DeleteBedNetAreaExcutor : ExcutorBase<DeleteBedNetAreaRequest, DeleteBedNetAreaResponse>
  12. {
  13. protected override void ExcuteInternal(DeleteBedNetAreaRequest request, object state, DeleteBedNetAreaResponse rslt)
  14. {
  15. var tokendata = BllHelper.GetToken(request.token);
  16. if (tokendata == null)
  17. {
  18. rslt.ErrMsg = "会话已经中断,请重新登录";
  19. return;
  20. }
  21. if (!request.list.Any())
  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. using (cmd.Transaction = con.BeginTransaction())
  31. {
  32. try
  33. {
  34. foreach (var area in request.list)
  35. {
  36. if (DbSqlHelper.Delete(cmd, area) == 0)
  37. {
  38. throw new LJCommonException($"床网分区定义资料不存在");
  39. }
  40. }
  41. cmd.Transaction.Commit();
  42. }
  43. catch (Exception e)
  44. {
  45. cmd.Transaction.Rollback();
  46. rslt.ErrMsg = e.ToString();
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }