HelperBase.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using JLHHJSvr.LJFramework.Tools;
  2. using LJLib.InstallHelper;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace JLHHJSvr.BLL
  12. {
  13. internal abstract class HelperBase
  14. {
  15. /// <summary>
  16. /// 数据库连接
  17. /// </summary>
  18. public SqlCommand cmd { get; set; }
  19. /// <summary>
  20. /// ERP数据库连接
  21. /// </summary>
  22. public SqlCommand erp_cmd { get; set; }
  23. /// <summary>
  24. /// 预留的上下文
  25. /// </summary>
  26. public Context context { get; set; }
  27. public static T GetHelper<T>(SqlCommand cmd, Context context = null) where T : HelperBase, new()
  28. {
  29. var rslt = new T();
  30. rslt.cmd = cmd;
  31. rslt.context = context ?? new Context();
  32. return rslt;
  33. }
  34. public static T GetHelper<T>(SqlCommand cmd, SqlCommand erp_cmd,Context context = null) where T : HelperBase, new()
  35. {
  36. var rslt = new T();
  37. rslt.cmd = cmd;
  38. rslt.erp_cmd = erp_cmd;
  39. rslt.context = context ?? new Context();
  40. return rslt;
  41. }
  42. public JObject DoExecute(string apiName, JObject request)
  43. {
  44. var url = "http://127.0.0.1:" + GlobalVar.ERP_HTTPPort + "/api/common/" + apiName;
  45. var rslt = LJHttpUtil.PostRequest(url, request);
  46. return rslt;
  47. }
  48. public sealed class Context
  49. {
  50. private DateTime _opdate = DateTime.Now;
  51. public DateTime opdate
  52. {
  53. get { return _opdate; }
  54. set { _opdate = value; }
  55. }
  56. /// <summary>
  57. /// 用户登陆信息
  58. /// </summary>
  59. public TokenData tokendata { get; set; }
  60. }
  61. }
  62. }