/// <summary>
        /// 按数据类型获取数据库访问实现类
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库访问实现类</returns>
        public static string GetDbProviderClass(CurrentDbType dbType)
        {
            string returnValue = "RDIFramework.Utilities.SqlProvider";

            switch (dbType)
            {
            case CurrentDbType.SqlServer:
                returnValue = "RDIFramework.Utilities.SqlProvider";
                break;

            case CurrentDbType.Oracle:
                returnValue = "RDIFramework.Utilities.MSOracleProvider";
                break;

            case CurrentDbType.MySql:
                returnValue = "RDIFramework.Utilities.MySqlProvider";
                break;

            case CurrentDbType.DB2:
                returnValue = "RDIFramework.Utilities.DB2Provider";
                break;

            case CurrentDbType.SQLite:
                returnValue = "RDIFramework.Utilities.SqLiteProvider";
                break;
            }
            return(returnValue);
        }
Esempio n. 2
0
        public static string GetDbHelperClass(CurrentDbType dbType)
        {
            string str = "RDIFramework.Utilities.SqlHelper";

            switch (dbType)
            {
            case CurrentDbType.Oracle:
                return("RDIFramework.Utilities.MSOracleHelper");

            case CurrentDbType.SqlServer:
                return("RDIFramework.Utilities.SqlHelper");

            case CurrentDbType.Access:
                return(str);

            case CurrentDbType.DB2:
                return("RDIFramework.Utilities.DB2Helper");

            case CurrentDbType.MySql:
                return("RDIFramework.Utilities.MySqlHelper");

            case CurrentDbType.SQLite:
                return("RDIFramework.Utilities.SqLiteHelper");
            }
            return(str);
        }
Esempio n. 3
0
        //
        // 不是针对数据库的常用方法
        //

        #region public static string ObjectsToList(CurrentDbType DbType ,object ids) 字段值数组转换为字符串列表
        /// <summary>
        /// 字段值数组转换为字符串列表
        /// </summary>
        /// <param name="ids">字段值</param>
        /// <returns>字段值字符串</returns>
        public static string ObjectsToList(CurrentDbType DbType, Object[] ids)
        {
            string returnValue = string.Empty;
            string stringList  = string.Empty;

            for (int i = 0; i < ids.Length; i++)
            {
                switch (DbType)
                {
                case CurrentDbType.Access:
                    stringList += ids[i] + ", ";
                    break;

                default:
                    stringList += "'";
                    stringList += ids[i] + "',";
                    break;
                }
            }
            if (ids.Length == 0)
            {
                returnValue = " NULL ";
            }
            else
            {
                returnValue = CutLastDot(stringList.Substring(0, stringList.Length - 1));
            }
            return(returnValue);
        }
Esempio n. 4
0
        /// <summary>
        /// 按数据类型获取数据库访问实现类
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库访问实现类</returns>
        public static string GetDbHelperClass(CurrentDbType dbType)
        {
            string returnValue = "DotNet.Utilities.SqlHelper";

            switch (dbType)
            {
            case CurrentDbType.SqlServer:
                returnValue = "DotNet.Utilities.SqlHelper";
                break;

            case CurrentDbType.Oracle:
                returnValue = "DotNet.Utilities.MSOracleHelper";
                break;

            case CurrentDbType.Access:
                returnValue = "DotNet.Utilities.OleDbHelper";
                break;

            case CurrentDbType.MySql:
                returnValue = "DotNet.Utilities.MySqlHelper";
                break;

            case CurrentDbType.DB2:
                returnValue = "DotNet.Utilities.DB2Helper";
                break;

            case CurrentDbType.SQLite:
                returnValue = "DotNet.Utilities.SqLiteHelper";
                break;
            }
            return(returnValue);
        }
Esempio n. 5
0
        /// <summary>
        /// 按数据库类型获取数据库访问实现类
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库访问实现类</returns>
        public static string GetDbHelperClass(CurrentDbType dbType)
        {
            string returnValue = BaseDbInfo.RDbHelperNameSpace + ".SqlHelper";

            switch (dbType)
            {
            case CurrentDbType.SqlServer:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".SqlHelper";
                break;

            case CurrentDbType.MsOracle:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".MSOracleHelper";
                break;

            case CurrentDbType.MySql:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".MySqlHelper";
                break;

            case CurrentDbType.DB2:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".DB2Helper";
                break;

            case CurrentDbType.SQLite:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".SqLiteHelper";
                break;

            case CurrentDbType.Access:
                returnValue = BaseDbInfo.RDbHelperNameSpace + ".OleDbHelper";
                break;
            }
            return(returnValue);
        }
Esempio n. 6
0
        public static IDbProvider GetHelper(CurrentDbType dbType = 1, string connectionString = null)
        {
            string      dbHelperClass = BusinessLogic.GetDbHelperClass(dbType);
            IDbProvider provider      = (IDbProvider)Assembly.Load(SystemInfo.DbHelperAssmely).CreateInstance(dbHelperClass, true);

            if (!string.IsNullOrEmpty(connectionString))
            {
                provider.ConnectionString = connectionString;
            }
            return(provider);
        }
        /// <summary>
        /// 获取指定的数据库连接
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <returns>数据库访问类</returns>
        public static IDbProvider GetProvider(CurrentDbType dbType = CurrentDbType.SqlServer, string connectionString = null)
        {
            // 这里是每次都获取新的数据库连接,否则会有并发访问的问题存在
            var dbProviderClass = BusinessLogic.GetDbProviderClass(dbType);
            var dbProvider      = (IDbProvider)Assembly.Load(SystemInfo.DbProviderAssmely).CreateInstance(dbProviderClass, true);

            if (!string.IsNullOrEmpty(connectionString) && dbProvider != null)
            {
                dbProvider.ConnectionString = connectionString;
            }
            return(dbProvider);
        }
Esempio n. 8
0
        public static string GetDataReaderQueryString(IDbProvider dbProvider, string tableName, string selectField, string where, int topLimit, string order)
        {
            string str = "SELECT " + selectField + " FROM " + tableName;

            if (tableName.Trim().IndexOf(" ") > 0)
            {
                str = "SELECT " + selectField + " FROM  (" + tableName + ")";
            }
            string str2 = where;

            if (topLimit != 0)
            {
                switch (dbProvider.CurrentDbType)
                {
                case CurrentDbType.Oracle:
                    if (string.IsNullOrEmpty(order))
                    {
                        str2 = AddWhere(str2, " ROWNUM < = " + topLimit);
                    }
                    break;

                case CurrentDbType.SqlServer:
                case CurrentDbType.Access:
                    str = "SELECT TOP " + topLimit.ToString() + " " + selectField + " FROM " + tableName;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(str2))
            {
                str = str + " WHERE " + str2;
            }
            if (!string.IsNullOrEmpty(order))
            {
                str = str + " ORDER BY " + order;
            }
            if (topLimit != null && topLimit > 0)
            {
                CurrentDbType currentDbType = dbProvider.CurrentDbType;
                if (currentDbType != CurrentDbType.Oracle)
                {
                    if (currentDbType == CurrentDbType.MySql)
                    {
                        str = str + " LIMIT 0, " + topLimit;
                    }
                    return(str);
                }
                if (!string.IsNullOrEmpty(order))
                {
                    str = string.Concat(new object[] { "SELECT * FROM (", str, ") WHERE ROWNUM < = ", topLimit });
                }
            }
            return(str);
        }
        /// <summary>
        /// 数据库连接的类型判断
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库类型</returns>
        public static CurrentDbType GetDbType(string dbType)
        {
            CurrentDbType returnValue = CurrentDbType.SqlServer;

            foreach (CurrentDbType currentDbType in Enum.GetValues(typeof(CurrentDbType)))
            {
                if (currentDbType.ToString().Equals(dbType))
                {
                    returnValue = currentDbType;
                    break;
                }
            }
            return(returnValue);
        }
Esempio n. 10
0
        /// <summary>
        /// 获取指定的数据库连接
        /// </summary>
        /// <param name="dataBaseType">数据库类型</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <returns>数据库访问类</returns>
        public static IDbHelper GetHelper(CurrentDbType dbType = CurrentDbType.MySql, string connectionString = null)
        {
            // 这里是每次都获取新的数据库连接,否则会有并发访问的问题存在
            string    dbHelperClass = SupportDbType.GetDbHelperClass(dbType); //根据数据库类型获得数据库接口类型的名字
            IDbHelper dbHelper      = (IDbHelper)Assembly.Load(BaseDbInfo.DBInterfaceAssmely).CreateInstance(dbHelperClass, true);

            //如果用反射的方法创建实例时出错,一定是dll文件名称BaseRTDbInfo.DBInterfaceAssmely不正确,或者命名空间+类名称dbHelperClass不正确
            //要重点检查BaseRTDbInfo.DBInterfaceAssmely和SupportDbType.GetDbHelperClass里面的的内容。
            //也就是检查dll文件名是否正确,每一个数据库连接类对应的命名空间+类名称是否正确。
            //在一个调试好的程序里,这里的创建过程是不会出错的,因此无需用try。
            if (!string.IsNullOrEmpty(connectionString))
            {
                dbHelper.ConnectionString = connectionString;
            }
            return(dbHelper);
        }
Esempio n. 11
0
        /// <summary>
        /// 获取指定的数据库连接
        /// </summary>
        /// <param name="dataBaseType">数据库类型</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <returns>数据库访问类</returns>
        public static IDbHelper GetHelper(CurrentDbType dbType = CurrentDbType.SqlServer, string connectionString = null)
        {
            // 这里是每次都获取新的数据库连接,否则会有并发访问的问题存在
            string    dbHelperClass = DbHelper.GetDbHelperClass(dbType);
            IDbHelper dbHelper      = (IDbHelper)Assembly.Load("Mshan.Utilities.DbUtilities").CreateInstance(dbHelperClass, true);

            if (!string.IsNullOrEmpty(connectionString))
            {
                dbHelper.ConnectionString = connectionString;
            }
            else
            {
                dbHelper.ConnectionString = BaseSystemInfo.UserCenterDbConnection;
            }
            return(dbHelper);
        }
Esempio n. 12
0
        /// <summary>
        /// 获得数据库当前日期
        /// </summary>
        /// <returns>当前日期</returns>
        public static string GetDbNow(CurrentDbType dbType)
        {
            string result = string.Empty;

            if (dbType == CurrentDbType.SqlServer)
            {
                result = " Getdate() ";
            }
            else if (dbType == CurrentDbType.Oracle)
            {
                result = " SYSDATE ";
            }
            else if (dbType == CurrentDbType.SQLite)
            {
                result = " datetime(CURRENT_TIMESTAMP, 'localtime') ";
            }
            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// 数据库连接的类型判断
        /// 2016-02-24 吉日嘎拉 忽略大小写,只要拼写正确就可以了,提高兼容性
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <param name="defaultDbType">默认数据库,防止设置有错误</param>
        /// <returns>数据库类型</returns>
        public static CurrentDbType GetDbType(string dbType, CurrentDbType defaultDbType = CurrentDbType.SqlServer)
        {
            CurrentDbType result = defaultDbType;

            if (!string.IsNullOrEmpty(dbType))
            {
                foreach (CurrentDbType currentDbType in Enum.GetValues(typeof(CurrentDbType)))
                {
                    if (currentDbType.ToString().Equals(dbType, StringComparison.OrdinalIgnoreCase))
                    {
                        result = currentDbType;
                        break;
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// 获取数据表 一参 参数为数组
        /// </summary>
        /// <param name="dbHelper">数据库类型</param>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="name">字段名</param>
        /// <param name="value">字段值</param>
        /// <param name="order">排序</param>
        /// <returns>数据表</returns>
        public static DataTable GetDataTable(CurrentDbType DbType, IDbHelper dbHelper, string tableName, string name, object[] values, string order = null)
        {
            string sqlQuery = " SELECT * "
                              + "   FROM " + tableName;

            if (values == null)
            {
                sqlQuery += "  WHERE " + name + " IS NULL";
            }
            else
            {
                sqlQuery += "  WHERE " + name + " IN (" + BaseBusinessLogic.ObjectsToList(DbType, values) + ")";
            }
            if (!String.IsNullOrEmpty(order))
            {
                sqlQuery += " ORDER BY " + order;
            }
            return(dbHelper.Fill(sqlQuery));
        }
Esempio n. 15
0
        /// <summary>
        /// 按数据类型获取数据库访问实现类
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns>数据库访问实现类</returns>
        public static string GetDbHelperClass(CurrentDbType dbType)
        {
            string result = "Mshan.Utilities.DbUtilities.SqlHelper";

            switch (dbType)
            {
            case CurrentDbType.SqlServer:
                result = "Mshan.Utilities.DbUtilities.SqlHelper";
                break;

            case CurrentDbType.Oracle:
                result = "Mshan.Utilities.DbUtilities.OracleHelper";
                // result = "Mshan.Utilities.DbUtilities.MSOracleHelper";
                break;

            case CurrentDbType.Access:
                result = "Mshan.Utilities.DbUtilities.OleDbHelper";
                break;

            case CurrentDbType.MySql:
                result = "Mshan.Utilities.DbUtilities.MySqlHelper";
                break;

            case CurrentDbType.DB2:
                result = "Mshan.Utilities.DbUtilities.DB2Helper";
                break;

            case CurrentDbType.SQLite:
                result = "Mshan.Utilities.DbUtilities.SqLiteHelper";
                break;

            case CurrentDbType.Ase:
                result = "Mshan.Utilities.DbUtilities.AseHelper";
                break;

            case CurrentDbType.PostgreSql:
                result = "Mshan.Utilities.DbUtilities.PostgreSqlHelper";
                break;
            }
            return(result);
        }
Esempio n. 16
0
        /// <summary>
        /// 获取分页数据(防注入功能的)
        /// </summary>
        /// <param name="recordCount">记录条数</param>
        /// <param name="tableName">数据来源表名</param>
        /// <param name="selectField">选择字段</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示多少条</param>
        /// <param name="conditions">查询条件</param>
        /// <param name="dbParameters">查询参数</param>
        /// <param name="orderBy">排序字段</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByPage(BaseUserInfo userInfo, out int recordCount, string tableName, string selectField, int pageIndex, int pageSize, string conditions, List <KeyValuePair <string, object> > dbParameters, string orderBy)
        {
            DataTable result = null;

            recordCount = 0;
            string connectionString = string.Empty;

            connectionString = ConfigurationHelper.AppSettings("OpenMasDbConnection", BaseSystemInfo.EncryptDbConnection);
            if (!string.IsNullOrEmpty(connectionString))
            {
                if (SecretUtil.IsSqlSafe(conditions))
                {
                    // 2016-02-24 吉日嘎拉 查询历史支持各种数据库访问方式
                    string openMasDbType = string.Empty;
                    openMasDbType = ConfigurationHelper.AppSettings("OpenMasDbType", BaseSystemInfo.EncryptDbConnection);
                    CurrentDbType dbType = CurrentDbType.SqlServer;
                    if (!string.IsNullOrEmpty(openMasDbType))
                    {
                        dbType = DbHelper.GetDbType(openMasDbType, CurrentDbType.SqlServer);
                    }

                    using (IDbHelper dbHelper = DbHelperFactory.GetHelper(dbType, connectionString))
                    {
                        recordCount = DbLogic.GetCount(dbHelper, tableName, conditions, dbHelper.MakeParameters(dbParameters));
                        result      = DbLogic.GetDataTableByPage(dbHelper, tableName, selectField, pageIndex, pageSize, conditions, dbHelper.MakeParameters(dbParameters), orderBy);
                    }
                }
                else
                {
                    if (System.Web.HttpContext.Current != null)
                    {
                        // 记录注入日志
                        FileUtil.WriteMessage("userInfo:" + userInfo.Serialize() + " " + conditions, System.Web.HttpContext.Current.Server.MapPath("~/Log/") + "SqlSafe" + DateTime.Now.ToString(BaseSystemInfo.DateFormat) + ".txt");
                    }
                }
            }

            return(result);
        }
Esempio n. 17
0
        public static CurrentDbType GetDbType(string dbType)
        {
            CurrentDbType sqlServer = CurrentDbType.SqlServer;

            using (IEnumerator enumerator = Enum.GetValues(typeof(CurrentDbType)).GetEnumerator())
            {
                CurrentDbType current;
                while (enumerator.MoveNext())
                {
                    current = (CurrentDbType)enumerator.Current;
                    if (current.ToString().Equals(dbType))
                    {
                        goto Label_0046;
                    }
                }
                return(sqlServer);

Label_0046:
                sqlServer = current;
            }
            return(sqlServer);
        }
Esempio n. 18
0
        /// <summary>
        /// 给UcPageControlByCode控件传递必需参数
        /// </summary>
        /// <param name="connStr">连接字符串</param>
        /// <param name="whereStatement">MsSql Where语句 </param>
        /// <param name="tbName">数据表名或视力名</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="primaryKeyName">主键值</param>
        /// <param name="fieldList">字段列表(默认为:*)</param>
        public void SetUcPageControlPars(CurrentDbType dbType, string dbConnstring, string whereStatement, string tbName
                                         , string orderField, string primaryKeyName, string fieldList)
        {
            if (dbConnstring == null)
            {
                DialogHelper.ShowErrorMsg("无可用数据库连接!");
                return;
            }
            else
            {
                this.pageDbType     = dbType;
                this.pageConnstring = dbConnstring;
            }

            this.SqlWhereStatement = whereStatement;
            this.TableName         = tbName;
            this.OrderField        = orderField;
            this.PrimaryKey        = primaryKeyName;
            if (!string.IsNullOrEmpty(fieldList.Trim()))
            {
                this.QueryFieldList = fieldList;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// 获得参数Sql表达式
        /// </summary>
        /// <param name="parameter">参数名称</param>
        /// <returns>字符串</returns>
        public static string GetParameter(CurrentDbType currentDbType, string parameter)
        {
            switch (currentDbType)
            {
            case CurrentDbType.SqlServer:
            case CurrentDbType.Access:
            case CurrentDbType.Ase:
            case CurrentDbType.PostgreSql:
            case CurrentDbType.SQLite:
                parameter = "@" + parameter;
                break;

            case CurrentDbType.DB2:
            case CurrentDbType.Oracle:
                parameter = ":" + parameter;
                break;

            case CurrentDbType.MySql:
                parameter = "?" + parameter;
                break;
            }
            return(parameter);
        }
Esempio n. 20
0
        /// <summary>
        /// 获取指定的数据库连接
        /// </summary>
        /// <param name="connectionString">数据库连接串</param>
        /// <returns>数据库访问类</returns>
        public static IDbHelper GetHelper(string connectionString)
        {
            CurrentDbType dbType = CurrentDbType.SqlServer;

            return(GetHelper(dbType, connectionString));
        }
Esempio n. 21
0
 /// <summary>
 /// 得到分页数据,同时把绑定到DataGridView控件中。
 /// </summary>
 /// <param name="dataControl">显示分页数据的控件(一般为DataGridView)</param>
 /// <param name="pageControl">分页控件名称</param>
 /// <param name="tableName">表名</param>
 /// <param name="pageDbType">数据库类型</param>
 /// <param name="primaryKey">主键名</param>
 /// <param name="orderField">排序字段</param>
 /// <param name="whereConditional">Where条件</param>
 /// <param name="queryFields">结果字段列表</param>
 /// <param name="connstring">数据库连接字符串</param>
 /// <returns></returns>
 public int BindPageData(UcDataGridView dataControl, UcPageControl pageControl, string tableName, CurrentDbType pageDbType
                         , string primaryKey  = "ID", string orderField = "ID", string whereConditional = "DELETEMARK = 0"
                         , string queryFields = "*", string connstring  = "")
 {
     pageData                = null;
     pageDataTable           = null;
     pageData                = new PageData();
     pageDataTable           = new DataTable();
     pageData.TableName      = tableName;
     pageData.PrimaryKey     = primaryKey;
     pageData.OrderStr       = orderField;
     pageData.PageIndex      = pageControl.PageCurrent;
     pageData.PageSize       = SystemInfo.PageSize; //指定分页大小(注:此句一定不能省略)
     pageControl.PageSize    = pageData.PageSize;   //指定此页面的分页大小(注:此句一定不能省略)
     pageData.QueryCondition = whereConditional;
     pageData.QueryFieldName = queryFields;
     pageData.PageDbType     = pageDbType;
     pageDataTable           = pageData.QueryDataTable(!string.IsNullOrEmpty(connstring.Trim()) ? connstring : SystemInfo.RDIFrameworkDbConection);
     pageControl.bindingSource.DataSource       = pageDataTable;
     pageControl.bindingNavigator.BindingSource = pageControl.bindingSource;
     //((DataGridView)dataControl).DataSource = null;
     //((DataGridView)dataControl).AutoGenerateColumns = false;
     //((DataGridView)dataControl).DataSource = ((DataTable)pageControl.bindingSource.DataSource).DefaultView;
     //this.AddCheckBoxColumn(((DataGridView)dataControl));
     dataControl.DataSource          = null;
     dataControl.AutoGenerateColumns = false;
     dataControl.DataSource          = pageControl.bindingSource;
     this.AddCheckBoxColumn(dataControl);
     pageControl.PageCount = pageData.TotalCount;
     return(pageData.TotalCount);
 }
Esempio n. 22
0
 /// <summary>
 /// 得到分页数据,同时把绑定到DataGridView控件中。
 /// </summary>
 /// <param name="dataControl">显示分页数据的控件(一般为DataGridView)</param>
 /// <param name="pageControl">分页控件名称</param>
 /// <param name="tableName">表名</param>
 /// <param name="pageDbType">数据库类型</param>
 /// <param name="connstring">数据库连接字符串</param>
 /// <returns></returns>
 public int BindPageData(UcDataGridView dataControl, UcPageControl pageControl, string tableName, CurrentDbType pageDbType, string connstring)
 {
     return(this.BindPageData(dataControl, pageControl, tableName, pageDbType, BusinessLogic.FieldId, BusinessLogic.FieldId, "DELETEMARK = 0", "*", connstring));
 }
Esempio n. 23
0
        /// <summary>
        /// 获取指定的数据库连接
        /// </summary>
        /// <param name="connectionString">数据库连接串</param>
        /// <returns>数据库访问类</returns>
        public static IDbHelper GetHelper(string connectionString)
        {
            CurrentDbType dbType = CurrentDbType.MySql; //如果不给定数据库类型,默认使用MySql。

            return(GetHelper(dbType, connectionString));
        }
 public BusinessDBProviderService(string dbConnection, CurrentDbType dbType)
 {
     ServiceDbConnection = dbConnection;
     ServiceDbType       = dbType;
 }
Esempio n. 25
0
 /// <summary>
 /// SqlBuilder
 /// </summary>
 /// <param name="currentDbType"></param>
 public SqlBuilder(CurrentDbType currentDbType)
 {
     _dbType      = currentDbType;
     DbParameters = new List <KeyValuePair <string, object> >();
 }
Esempio n. 26
0
        /// <summary>
        /// 远程数据同步的工具类
        /// </summary>
        /// <param name="fromDataBase">从服务器的哪个数据库获取数据</param>
        /// <param name="tableName">同步哪个表</param>
        /// <param name="primaryKeys">表的主键是什么</param>
        /// <param name="modifiedOn">同步的更新时间</param>
        /// <param name="toDataBaseDbType">同步到本地什么类型的数据库里?</param>
        /// <param name="dbConnection">同步的目标数据库连接方式?</param>
        /// <param name="toTableName">本地表</param>
        /// <param name="topLimit"></param>
        /// <param name="delete"></param>
        /// <returns>影响行数</returns>
        public static int SynchronousTable(string fromDataBase, string tableName, string[] primaryKeys, DateTime?modifiedOn, CurrentDbType toDataBaseDbType, string dbConnection, string toTableName, int topLimit, bool delete = true)
        {
            int result = 0;

            // 输入参数检查
            if (primaryKeys == null)
            {
                return(result);
            }
            if (topLimit == 0)
            {
                topLimit = 200;
            }

            int synchronousCount = topLimit;

            DataTable dataTable = null;

            while (synchronousCount >= topLimit)
            {
                // 一批一批写入数据库,提高同步的性能
                var        dbHelper   = DbHelperFactory.GetHelper(toDataBaseDbType, dbConnection);
                SQLBuilder sqlBuilder = new SQLBuilder(dbHelper);
                dbHelper.BeginTransaction();

                // string url = BaseSystemInfo.WebHost + "WebAPIV42/API/Synchronous/GetTopLimitTable";
                const string url = "http://userCenter.zt-express.com/WebAPIV42/API/Synchronous/GetTopLimitTable";

                WebClient           webClient  = new WebClient();
                NameValueCollection postValues = new NameValueCollection
                {
                    { "userInfo", BaseSystemInfo.UserInfo.Serialize() },
                    { "systemCode", BaseSystemInfo.SystemCode },
                    { "securityKey", BaseSystemInfo.SecurityKey },
                    { "dataBase", fromDataBase },
                    { "tableName", tableName },
                    { "toTableName", toTableName },
                    { "topLimit", topLimit.ToString() },
                    { "modifiedOn", modifiedOn.Value.ToString(BaseSystemInfo.DateTimeFormat) }
                };
                // 向服务器发送POST数据
                byte[] responseArray = webClient.UploadValues(url, postValues);
                string response      = Encoding.UTF8.GetString(responseArray);
                if (!string.IsNullOrEmpty(response))
                {
                    dataTable = (DataTable)JsonConvert.DeserializeObject(response, typeof(DataTable));
                }
                int r;
                // 出错的日志都需要能保存起来,这样有问题的可以找出原因来。
                for (r = 0; r < dataTable.Rows.Count; r++)
                {
                    // 先删除数据,修改的、新增的、都删除后添加来处理,问题就简单化了
                    // dbHelper.ExecuteNonQuery("DELETE FROM " + tableName + " WHERE " + primaryKey + " = '" + dataTable.Rows[r][primaryKey].ToString() + "'");
                    if (delete)
                    {
                        sqlBuilder.BeginDelete(toTableName);
                        for (int i = 0; i < primaryKeys.Length; i++)
                        {
                            string primaryKey = primaryKeys[i];
                            if (!string.IsNullOrWhiteSpace(primaryKey))
                            {
                                sqlBuilder.SetWhere(primaryKey, dataTable.Rows[r][primaryKey].ToString());
                            }
                        }
                        sqlBuilder.EndDelete();
                    }
                    // 然后插入数据
                    sqlBuilder.BeginInsert(toTableName);
                    for (int i = 0; i < dataTable.Columns.Count; i++)
                    {
                        // 这里能判断目标表里是否有这个字段存在就更完美了。
                        sqlBuilder.SetValue(dataTable.Columns[i].ColumnName, dataTable.Rows[r][dataTable.Columns[i].ColumnName]);
                    }
                    sqlBuilder.EndInsert();

                    if (DateTime.Parse(dataTable.Rows[r][BaseBusinessLogic.FieldModifiedOn].ToString()) > modifiedOn.Value)
                    {
                        modifiedOn = DateTime.Parse(dataTable.Rows[r][BaseBusinessLogic.FieldModifiedOn].ToString());
                    }
                    result++;
                }
                synchronousCount = dataTable.Rows.Count;

                // 批量提交
                try
                {
                    dbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    LogUtil.WriteException(ex);
                    dbHelper.RollbackTransaction();
                }
                finally
                {
                    dbHelper.Close();
                    dbHelper.Dispose();
                }
            }
            return(result);
        }
Esempio n. 27
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="businessDbType">当前商业数据库类型</param>
 /// <param name="businessDbConnection">当前商业数据库连接字符串</param>
 public IncomingCallService(CurrentDbType businessDbType, string businessDbConnection)
     : this()
 {
     BusinessDbType       = businessDbType;
     BusinessDbConnection = businessDbConnection;
 }
 public RDIFrameworkDBProviderService(string dbConnection, CurrentDbType dbType)
 {
     ServiceDbConnection = dbConnection;
     ServiceDbType       = dbType;
 }
Esempio n. 29
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="businessDbType">当前商业数据库类型</param>
 /// <param name="businessDbConnection">当前商业数据库连接字符串</param>
 public CUSTOMERCHANCEService(CurrentDbType businessDbType, string businessDbConnection)
     : this()
 {
     BusinessDbType       = businessDbType;
     BusinessDbConnection = businessDbConnection;
 }
Esempio n. 30
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="businessDbType">当前商业数据库类型</param>
 /// <param name="businessDbConnection">当前商业数据库连接字符串</param>
 public LinkManService(CurrentDbType businessDbType, string businessDbConnection)
     : this()
 {
     BusinessDbType       = businessDbType;
     BusinessDbConnection = businessDbConnection;
 }