BaseDownLoad.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7. using cuidian.Sql;
  8. using System.Data.SqlClient;
  9. namespace TempDbToUfida.Sql
  10. {
  11. /// <summary>
  12. /// 从中间库下载到U8数据库的基类
  13. /// </summary>
  14. public abstract class BaseDownLoad : IDownLoad
  15. {
  16. /// <summary>
  17. /// 中间库源数据
  18. /// </summary>
  19. protected DataSet _sourceData;
  20. /// <summary>
  21. /// 主表名称
  22. /// </summary>
  23. protected string _mainTable;
  24. protected SqlConnection _tragetCon;
  25. protected string _operType;
  26. public void DownLoad()
  27. {
  28. _DownLoad();
  29. }
  30. /// <summary>
  31. /// 初始化源数据
  32. /// </summary>
  33. protected virtual void _InitSourceData()
  34. { }
  35. public BaseDownLoad()
  36. {
  37. _Init();
  38. _InitSourceData();
  39. }
  40. protected virtual void _DownLoad()
  41. {
  42. DataTable dt = _sourceData.Tables[_mainTable];
  43. foreach (DataRow item in dt.Rows)
  44. {
  45. _Process(item);
  46. }
  47. }
  48. protected virtual void _Init()
  49. {
  50. _tragetCon = ConnectionUtils.Instance.GetConnection();
  51. }
  52. protected virtual void _Process(DataRow dr)
  53. { }
  54. /// <summary>
  55. /// 检查数据是否存在
  56. /// </summary>
  57. /// <param name="sql"></param>
  58. /// <returns></returns>
  59. protected bool _CheckDup(string sql)
  60. {
  61. int i = Convert.ToInt16(DbUtils.ExecuteScalar(sql, _tragetCon));
  62. return i > 0;
  63. }
  64. protected virtual void _updateTempDb(DataRow dr)
  65. { }
  66. protected virtual string _buildUpdSql(DataRow dr)
  67. {
  68. return string.Empty;
  69. }
  70. }
  71. }