DeleteBedNetVarExcutor.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. using LJLib.SQLEX;
  10. namespace JLHHJSvr.Excutor
  11. {
  12. internal sealed class DeleteBedNetVarExcutor : ExcutorBase<DeleteBedNetVarRequest, DeleteBedNetVarResponse>
  13. {
  14. protected override void ExcuteInternal(DeleteBedNetVarRequest request, object state, DeleteBedNetVarResponse rslt)
  15. {
  16. var tokendata = BllHelper.GetToken(request.token);
  17. if (tokendata == null)
  18. {
  19. rslt.ErrMsg = "会话已经中断,请重新登录";
  20. return;
  21. }
  22. if (!request.list.Any())
  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. using (cmd.Transaction = con.BeginTransaction())
  32. {
  33. try
  34. {
  35. foreach (var bednetvar in request.list)
  36. {
  37. // 删除明细
  38. cmd.CommandText = @"DELETE FROM u_bednet_varmx WHERE varid = @varid";
  39. cmd.Parameters.Clear();
  40. cmd.Parameters.AddWithValue("@varid", bednetvar.varid.Value);
  41. cmd.ExecuteNonQuery();
  42. if (DbSqlHelper.Delete(cmd, bednetvar) == 0)
  43. {
  44. throw new LJCommonException($"弹簧资料不存在");
  45. }
  46. }
  47. cmd.Transaction.Commit();
  48. }
  49. catch (Exception e)
  50. {
  51. cmd.Transaction.Rollback();
  52. rslt.ErrMsg = e.ToString();
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }