Beispiel #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()]);
 }
Beispiel #2
0
        public void ExplicitCastToDbDate()
        {
            DateTime date = new DateTime(2013, 2, 20, 1, 2, 3, 99, DateTimeKind.Utc);
            // yes, we like to explicitly "loose" infos:
            DbDate target = (DbDate)date;

            Assert.AreEqual(2013, target.Year);
            Assert.AreEqual(2, target.Month);
            Assert.AreEqual(20, target.Day);
        }
Beispiel #3
0
        public void ConvertibleCasts()
        {
            object self = new DbDate(2013, 11, 5);

            DbDate selfCasted = (DbDate)self;

            Assert.AreEqual(self, selfCasted);

            Assert.AreEqual(self, GetDbDateByObjectT((DbDate)self));
            Assert.AreEqual(self, GetDbDateByIConvertibleT((DbDate)self));
        }
Beispiel #4
0
        public void CtorAndProperties()
        {
            DbDate date = new DbDate();

            Assert.AreEqual(DbDate.MinValue, date);

            date = new DbDate(9999, 12, 31);
            Assert.AreEqual(DbDate.MaxValue, date);

            date = new DbDate(1, 2, 3);
            Assert.AreEqual(1, date.Year);
            Assert.AreEqual(2, date.Month);
            Assert.AreEqual(3, date.Day);
        }
Beispiel #5
0
        public void ImplicitCastToDateTime()
        {
            DbDate   date   = new DbDate(2013, 2, 13);
            DateTime target = date;

            // expected zeros on the unused time part of DateTime:
            Assert.AreEqual(0, target.Hour);
            Assert.AreEqual(0, target.Minute);
            Assert.AreEqual(0, target.Second);
            Assert.AreEqual(0, target.Millisecond);

            Assert.AreEqual(2013, target.Year);
            Assert.AreEqual(2, target.Month);
            Assert.AreEqual(13, target.Day);

            Assert.AreEqual(DateTimeKind.Utc, target.Kind);
        }
Beispiel #6
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);
        }
Beispiel #7
0
 public void CtorFailOnInvalidLeapYearDayUpperBound()
 {
     // this was not a leap year:
     DbDate date = new DbDate(2001, 2, 29);
 }
Beispiel #8
0
 public void CtorFailOnInconsistentDayUpperBound()
 {
     // april has only 30 days:
     DbDate date = new DbDate(2001, 4, 31);
 }
Beispiel #9
0
 public void CtorFailOnDayUpperBound()
 {
     DbDate date = new DbDate(9999, 1, 32);
 }
Beispiel #10
0
 public void CtorFailOnDayLowerBound()
 {
     DbDate date = new DbDate(2000, 1, 0);
 }
Beispiel #11
0
 public void CtorFailOnMonthUpperBound()
 {
     DbDate date = new DbDate(2, 13, 1);
 }
Beispiel #12
0
 public void CtorFailOnMonthLowerBound()
 {
     DbDate date = new DbDate(1, 0, 1);
 }
Beispiel #13
0
 public void CtorFailOnYearUpperBound()
 {
     DbDate date = new DbDate(10000, 1, 1);
 }
Beispiel #14
0
 public void CtorFailOnYearLowerBound()
 {
     DbDate date = new DbDate(0, 1, 1);
 }
Beispiel #15
0
        public void MaxValue()
        {
            DbDate date = DbDate.MaxValue;

            Assert.AreEqual(99991231, date.Ticks);
        }
Beispiel #16
0
        public void MinValue()
        {
            DbDate date = DbDate.MinValue;

            Assert.AreEqual(0, date.Ticks);
        }