示例#1
0
 /// <summary>
 /// 获取指定日期段内的数据库。
 /// <para>请勿释放</para>
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public SQLiteConnection GetConnection(DbDate date = default)
 {
     if (date == default)
     {
         date = DbDate.Now;
     }
     return(Connections[date.ToString()]);
 }
示例#2
0
        /// <summary>
        /// 获取一个可用的数据库的名称
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        private string GetDbName(DbDate date = default)
        {
            if (date == default)
            {
                date = DateTime.Now;
            }
            string dbFloder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Application.ProductName, "Database");

            if (!Directory.Exists(dbFloder))
            {
                Directory.CreateDirectory(dbFloder);
            }
            string dbName = Path.Combine(dbFloder, date.ToString() + ".db");

            if (!File.Exists(dbName) && date.Month >= DateTime.Now.Month)
            {
                try
                {
                    SQLiteConnection.CreateFile(dbName);
                    using (SQLiteConnection Connection = new SQLiteConnection($"Data Source={dbName};Version=3;"))
                    {
                        string sql = @"create table vk_key (Id integer primary key autoincrement, Code integer(4), Time varchar, Status integer(1) default 2);";
                        Connection.Open();
                        Connection.Execute(sql);
                        Connection.Close();
                    }
                }
                catch
                {
                    if (File.Exists(dbName))
                    {
                        File.Delete(dbName);
                    }
                }
            }
            else
            {
            }
            return(dbName);
        }