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 _args; public BaseUpLoad() { __Init(); } public void UpLoad(Dictionary 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(); } }