LockTableExcutor.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using JLHHJSvr.BLL;
  6. using JLHHJSvr.Com;
  7. using JLHHJSvr.Com.Model;
  8. using JLHHJSvr.Helper;
  9. using JLHHJSvr.LJException;
  10. using LJLib.DAL.SQL;
  11. using LJLib.Net.SPI.Server;
  12. using LJLib.SQLEX;
  13. namespace JLHHJSvr.Excutor
  14. {
  15. internal sealed class LockTableExcutor : ExcutorBase<LockTableRequest, LockTableResponse>
  16. {
  17. protected override void ExcuteInternal(LockTableRequest request, object state, LockTableResponse rslt)
  18. {
  19. var tokendata = BllHelper.GetToken(request.token);
  20. if (tokendata == null)
  21. {
  22. rslt.ErrMsg = "会话已经中断,请重新登录";
  23. return;
  24. }
  25. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  26. using (var cmd = con.CreateCommand())
  27. {
  28. con.Open();
  29. foreach(var bill in request.lockList)
  30. {
  31. if (string.IsNullOrEmpty(bill.keyword)) throw new LJCommonException("加锁单据关键字错误,请检查!");
  32. }
  33. using (cmd.Transaction = con.BeginTransaction())
  34. {
  35. try
  36. {
  37. foreach(var bill in request.lockList)
  38. {
  39. LockHelper.LockBill(cmd, bill.keyword, bill.billid, bill.billcode,tokendata.username);
  40. }
  41. cmd.Transaction.Commit();
  42. }
  43. catch (Exception e)
  44. {
  45. cmd.Transaction?.Rollback();
  46. rslt.ErrMsg = e.Message;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }