123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using cuidian.Sql;
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WdtUtils.Proxy;
- using WdtUtils.Load;
- using WdtUtils;
- namespace WangToTempDb
- {
- public abstract class BaseUpLoad : IUpLoad
- {
- protected BaseProxy _proxy;
- protected ILoad _load;
- protected SqlConnection _tempDb, _targetDb;
- protected string _operType;
- protected Dictionary<string, string> _args;
- public BaseUpLoad()
- {
- __Init();
- }
- public void UpLoad(Dictionary<string, string> args)
- {
- _args = args;
- //_args.Add("page_no", "0");
- _args["page_no"] = "0";
- Result result = _LoadFirstPage();
- if (!result.IsSucess) return;
- if (result.TotalCount == 0) return;
-
- for (int i = 0; i <= result.PageCnt; i++)
- {
- _ImportData();
- _args["page_no"] = (i + 1).ToString();
- _LoadNextPage();
-
- }
-
- _DeleteDup();
- }
- protected string _ConvertStr(string data, bool space)
- {
- if (space) return _ConvertStr(data).Replace(" ", "");
- return _ConvertStr(data);
- }
- protected string _ConvertStr(string data)
- {
- return data.Replace("'", "''");
- }
-
- protected string _ConvertNotStr(string valueStr)
- {
- return string.IsNullOrWhiteSpace(valueStr) ? "0": valueStr;
- }
- protected virtual void _LoadNextPage()
- { }
- protected abstract Result _LoadFirstPage();
- protected virtual void _ImportData()
- {
-
- }
-
- protected virtual void _DeleteDup()
- { }
-
- protected void _InsertIntoTempDb(string sql,string source)
- {
- string msgSql = "insert into errmsg(opertype,msg,errorflag,sources) values('{0}','{1}',1,'{2}')";
- try
- {
- DbUtils.ExecuteNonQuery(sql, _tempDb);
- }
- catch (Exception ex)
- {
- DbUtils.ExecuteNonQuery(string.Format(msgSql,new object[] { _operType, ex.Message, source }), _tempDb);
- }
-
- }
- private void __Init()
- {
- _targetDb = ConnectionUtils.Instance.GetConnection();
- _tempDb = ConnectionUtils.Instance.GetConnection("TempDB");
- _SetLoader();
- }
- protected abstract void _SetLoader();
- }
- }
|