public Boolean UpdateDatabase(DataTable dataTable)
 {
     if (DbType == DatabaseType.MSSqlServer)
     {
         return(SqlServerConnection.UpdateDatabase(dataTable));
     }
     else if (DbType == DatabaseType.SqLite)
     {
         return(SqliteConnection.Instance.UpdateDatabase(dataTable));
     }
     else
     {
         throw new ArgumentException();
     }
 }
 public void ExecuteQueryUsingCache(string selectCommandText)
 {
     if (DbType == DatabaseType.MSSqlServer)
     {
         SqlServerConnection.ExecuteQuery_delay(selectCommandText);
     }
     else if (DbType == DatabaseType.SqLite)
     {
         throw new NotImplementedException();
     }
     else
     {
         throw new ArgumentException();
     }
 }
 public int ExecuteUpdate(string commandText)
 {
     if (DbType == DatabaseType.MSSqlServer)
     {
         return(SqlServerConnection.ExecuteUpdate(commandText));
     }
     else if (DbType == DatabaseType.SqLite)
     {
         return(SqliteConnection.Instance.ExecuteUpdate(commandText));
     }
     else
     {
         throw new ArgumentException();
     }
 }
 public DataTable ExecuteQuery(string selectCommandText)
 {
     if (DbType == DatabaseType.MSSqlServer)
     {
         return(SqlServerConnection.ExecuteQuery(selectCommandText));
     }
     else if (DbType == DatabaseType.SqLite)
     {
         return(SqliteConnection.Instance.ExecuteQuery(selectCommandText));
     }
     else
     {
         throw new ArgumentException();
     }
 }
 public Boolean ConnectionOpenned()
 {
     if (DbType == DatabaseType.MSSqlServer)
     {
         return(SqlServerConnection.ConnectionOpenned());
     }
     else if (DbType == DatabaseType.SqLite)
     {
         return(SqliteConnection.Instance.ConnectionOpenned());
     }
     else
     {
         throw new ArgumentException();
     }
 }
        public static void CloseConnection()
        {
            if (!ConnectionOpenned())
            {
                return;
            }

            try
            {
                SqlServerConnection.GetConnection().Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 清除所有缓存并提交到数据库,自定义Cache文件路径
        /// </summary>
        /// <returns></returns>
        public static int CleanDbAndExecuteTasks(string cacheFilename)
        {
            int effectedRows = 0;

            string[] commands = GetAllLines(cacheFilename);
            if (commands == null)
            {
                return(-1);
            }

            foreach (string str in commands)
            {
                int tmp = SqlServerConnection.ExecuteUpdate(str);
                effectedRows += tmp > 0 ? tmp : 0;
            }
            File.Delete(cacheFilename);
            return(effectedRows);
        }
Beispiel #8
0
        /// <summary>
        /// 清除所有缓存并提交到数据库,自定义Cache文件路径
        /// </summary>
        /// <returns></returns>
        public static int CleanDbAndExecuteTasks(string cacheFilename)
        {
            int effectedRows = 0;

            string[] commands = GetAllLines(cacheFilename);
            if (commands == null)
            {
                return(-1);
            }
            try
            {
                effectedRows = SqlServerConnection.ExecuteSqlWithGoUseTran(commands);
                File.Delete(cacheFilename);
                return(effectedRows);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public static void OpenConnection()
 {
     if (ConnectionOpenned())
     {
         return;
     }
     if (GetConnection().State == ConnectionState.Connecting)
     {
         throw new Exception("无法建立数据库连接,数据库状态为正在连接");
     }
     try
     {
         TimeUtil.Tik();
         SqlServerConnection.GetConnection().Open();
         TimeUtil.Tok();
     }
     catch (Exception)
     {
         throw;
     }
 }