versiondbfunc.cs

来自「JAVA的精彩实例」· CS 代码 · 共 97 行

CS
97
字号
using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using feiyun0112.cnblogs.com.CSDNReader.Model;

namespace feiyun0112.cnblogs.com.CSDNReader.Functions
{
    class VersionDBFunc
    {
        private VersionDBFunc()
        {
        }
        public  static  void UpdateDBVersion(string strOldDBVersion)
        {
            
            DBFunc db = new DBFunc(false, false);
            try
            {
                if (strOldDBVersion.CompareTo("20070125")<0)
                {
                    RunSql(db,"20070125");
                }

                //SettingDBFunc s = new SettingDBFunc();

                SettingDBFunc.SetSetting("DBVersion", Setting.Version);
            }
            catch 
            {
                
            }
            finally
            {
                db.Dispose();
            }
            
        }

        private static  void RunSql(DBFunc db,string strVersion)
        {
            string[] strSql = GetSql(strVersion);
            foreach(string s in strSql)
            {
                if (s.Length!= 0)
                {
                    try
                    {
                        db.ExecuteSql(s);
                    }
                    catch
                    {
                    }
                }
            }
        }

        private static string[] GetSql(string strVersion)
        {
            string[] strSql=new string[1];
            switch (strVersion)
            {
                case  "20070125":
                    strSql = new string[2];
                    strSql[0] = "alter table RoomInfo add column isGroup bit default 0";
                    strSql[1] = "alter table RoomInfo add column GroupID integer default 0";
                    break;
                default:
                    break;
            }
            return strSql;
        }


        public static void UpdateVersion(string strVersion)
        {
            DBFunc db = new DBFunc(false, false);
            try
            {
                
                //SettingDBFunc s = new SettingDBFunc();

                SettingDBFunc.SetSetting("CheckedVersion", strVersion);
            }
            catch
            {

            }
            finally
            {
                db.Dispose();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?