DeleteMattressBcpExcutor.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. namespace JLHHJSvr.Excutor
  11. {
  12. internal sealed class DeleteMattressBcpExcutor : ExcutorBase<DeleteMattressBcpRequest, DeleteMattressBcpResponse>
  13. {
  14. protected override void ExcuteInternal(DeleteMattressBcpRequest request, object state, DeleteMattressBcpResponse 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 = new SqlConnection(GlobalVar.ConnectionString))
  28. using (var cmd = con.CreateCommand())
  29. {
  30. con.Open();
  31. var power127 = UserHelper.CheckFuncPower(cmd, tokendata.empid, 127);
  32. if (!power127)
  33. {
  34. throw new LJCommonException("你没有删除权限");
  35. }
  36. foreach (var bill in request.list)
  37. {
  38. if (DbSqlHelper.SelectOne(cmd, bill, "flag") != 1)
  39. {
  40. throw new LJCommonException($"查找半成品报价单据失败!({bill.billid})");
  41. }
  42. if (bill.flag == 1)
  43. {
  44. throw new LJCommonException($"查找半成品报价单据已审核,不能删除!({bill.billid})");
  45. }
  46. }
  47. using (cmd.Transaction = con.BeginTransaction())
  48. {
  49. try
  50. {
  51. foreach (var bill in request.list)
  52. {
  53. // 删除半成品明细
  54. cmd.CommandText = @"DELETE FROM u_semi_finished_product_mx WHERE billid = @billid";
  55. cmd.Parameters.Clear();
  56. cmd.Parameters.AddWithValue("@billid", bill.billid.Value);
  57. cmd.ExecuteNonQuery();
  58. DbSqlHelper.Delete(cmd, bill);
  59. }
  60. cmd.Transaction.Commit();
  61. }
  62. catch (Exception e)
  63. {
  64. cmd.Transaction.Rollback();
  65. rslt.ErrMsg = e.ToString();
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }