DeleteBedNetVarExcutor.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 DeleteBedNetVarExcutor : ExcutorBase<DeleteBedNetVarRequest, DeleteBedNetVarResponse>
  12. {
  13. protected override void ExcuteInternal(DeleteBedNetVarRequest request, object state, DeleteBedNetVarResponse 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 bednetvar in request.list)
  35. {
  36. // 删除明细
  37. cmd.CommandText = @"DELETE FROM u_bednet_varmx WHERE varid = @varid";
  38. cmd.Parameters.Clear();
  39. cmd.Parameters.AddWithValue("@varid", bednetvar.varid.Value);
  40. cmd.ExecuteNonQuery();
  41. if (DbSqlHelper.Delete(cmd, bednetvar) == 0)
  42. {
  43. throw new LJCommonException($"弹簧资料不存在");
  44. }
  45. }
  46. cmd.Transaction.Commit();
  47. }
  48. catch (Exception e)
  49. {
  50. cmd.Transaction.Rollback();
  51. rslt.ErrMsg = e.ToString();
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }