DeleteMattressBcpExcutor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Data.SqlClient;
  3. using System.Linq;
  4. using JLHHJSvr.BLL;
  5. using JLHHJSvr.Com;
  6. using JLHHJSvr.Com.Model;
  7. using JLHHJSvr.LJException;
  8. using LJLib.DAL.SQL;
  9. using LJLib.Net.SPI.Server;
  10. using LJLib.SQLEX;
  11. namespace JLHHJSvr.Excutor
  12. {
  13. internal sealed class DeleteMattressBcpExcutor : ExcutorBase<DeleteMattressBcpRequest, DeleteMattressBcpResponse>
  14. {
  15. protected override void ExcuteInternal(DeleteMattressBcpRequest request, object state, DeleteMattressBcpResponse rslt)
  16. {
  17. var tokendata = BllHelper.GetToken(request.token);
  18. if (tokendata == null)
  19. {
  20. rslt.ErrMsg = "会话已经中断,请重新登录";
  21. return;
  22. }
  23. if (!request.list.Any())
  24. {
  25. rslt.ErrMsg = "至少提交一条需要删除的记录";
  26. return;
  27. }
  28. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  29. using (var cmd = con.CreateCommand())
  30. {
  31. con.Open();
  32. var power127 = UserHelper.CheckFuncPower(cmd, tokendata.empid, 127);
  33. if (!power127)
  34. {
  35. throw new LJCommonException("你没有删除权限");
  36. }
  37. foreach (var bill in request.list)
  38. {
  39. if (DbSqlHelper.SelectOne(cmd, bill, "flag") != 1)
  40. {
  41. throw new LJCommonException($"查找半成品报价单据失败!({bill.billid})");
  42. }
  43. if (bill.flag == 1)
  44. {
  45. throw new LJCommonException($"查找半成品报价单据已审核,不能删除!({bill.billid})");
  46. }
  47. }
  48. using (cmd.Transaction = con.BeginTransaction())
  49. {
  50. try
  51. {
  52. foreach (var bill in request.list)
  53. {
  54. // 删除半成品明细
  55. cmd.CommandText = @"DELETE FROM u_semi_finished_product_mx WHERE billid = @billid";
  56. cmd.Parameters.Clear();
  57. cmd.Parameters.AddWithValue("@billid", bill.billid.Value);
  58. cmd.ExecuteNonQuery();
  59. DbSqlHelper.Delete(cmd, bill);
  60. }
  61. cmd.Transaction.Commit();
  62. }
  63. catch (Exception e)
  64. {
  65. cmd.Transaction.Rollback();
  66. rslt.ErrMsg = e.ToString();
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }