BaseUpLoad.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using cuidian.Sql;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using WdtUtils.Proxy;
  9. using WdtUtils.Load;
  10. using WdtUtils;
  11. namespace WangToTempDb
  12. {
  13. public abstract class BaseUpLoad : IUpLoad
  14. {
  15. protected BaseProxy _proxy;
  16. protected ILoad _load;
  17. protected SqlConnection _tempDb, _targetDb;
  18. protected string _operType;
  19. protected Dictionary<string, string> _args;
  20. public BaseUpLoad()
  21. {
  22. __Init();
  23. }
  24. public void UpLoad(Dictionary<string, string> args)
  25. {
  26. _args = args;
  27. //_args.Add("page_no", "0");
  28. _args["page_no"] = "0";
  29. Result result = _LoadFirstPage();
  30. if (!result.IsSucess) return;
  31. if (result.TotalCount == 0) return;
  32. for (int i = 0; i <= result.PageCnt; i++)
  33. {
  34. _ImportData();
  35. _args["page_no"] = (i + 1).ToString();
  36. _LoadNextPage();
  37. }
  38. _DeleteDup();
  39. }
  40. protected string _ConvertStr(string data, bool space)
  41. {
  42. if (space) return _ConvertStr(data).Replace(" ", "");
  43. return _ConvertStr(data);
  44. }
  45. protected string _ConvertStr(string data)
  46. {
  47. return data.Replace("'", "''");
  48. }
  49. protected string _ConvertNotStr(string valueStr)
  50. {
  51. return string.IsNullOrWhiteSpace(valueStr) ? "0": valueStr;
  52. }
  53. protected virtual void _LoadNextPage()
  54. { }
  55. protected abstract Result _LoadFirstPage();
  56. protected virtual void _ImportData()
  57. {
  58. }
  59. protected virtual void _DeleteDup()
  60. { }
  61. protected void _InsertIntoTempDb(string sql,string source)
  62. {
  63. string msgSql = "insert into errmsg(opertype,msg,errorflag,sources) values('{0}','{1}',1,'{2}')";
  64. try
  65. {
  66. DbUtils.ExecuteNonQuery(sql, _tempDb);
  67. }
  68. catch (Exception ex)
  69. {
  70. DbUtils.ExecuteNonQuery(string.Format(msgSql,new object[] { _operType, ex.Message, source }), _tempDb);
  71. }
  72. }
  73. private void __Init()
  74. {
  75. _targetDb = ConnectionUtils.Instance.GetConnection();
  76. _tempDb = ConnectionUtils.Instance.GetConnection("TempDB");
  77. _SetLoader();
  78. }
  79. protected abstract void _SetLoader();
  80. }
  81. }