예제 #1
0
        /// <summary>
        /// Оновлення структури бази даних
        /// </summary>
        protected override void UpdateDB(ref bool pIsUseOld)
        {
            try
            {
                IsFirstStart = false;
                int CurVerConfig = 0, CurVerMid = 0, CurVerRC = 0;
                var Lines = SqlUpdateConfig.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                SQLite dbC = new SQLite(ConfigFile);
                var    wDB = new WDB(Path.Combine(Global.PathIni, "SQLite.sql"), dbC);

                CurVerConfig = wDB.GetConfig <int>("VerConfig");
                CurVerMid    = wDB.GetConfig <int>("VerMid");
                CurVerRC     = wDB.GetConfig <int>("VerRC");

                //Config
                var(Ver, IsReload) = Parse(Lines, CurVerConfig, dbC);
                if (Ver != CurVerConfig)
                {
                    wDB.SetConfig <int>("VerConfig", Ver);
                }

                //Mid
                if (File.Exists(MidFile))
                {
                    var dbMID = new SQLite(MidFile);
                    CurVerMid       = wDB.GetConfig <int>("VerMID");
                    Lines           = SqlUpdateMID.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                    (Ver, IsReload) = Parse(Lines, CurVerMid, dbMID);
                    dbMID.Close(true);
                    if (IsReload)
                    {
                        if (File.Exists(MidFile))
                        {
                            File.Delete(MidFile);
                        }
                        pIsUseOld = false;
                    }
                    if (Ver != CurVerMid)
                    {
                        wDB.SetConfig <int>("VerMID", Ver);
                    }
                }
                //RC
                CurVerRC = wDB.GetConfig <int>("VerRC");

                var cDT = DateTime.Now.Date.AddDays(-10);

                while (cDT <= DateTime.Now.Date)
                {
                    if (File.Exists(GetReceiptFile(cDT)))
                    {
                        var dbRC = new SQLite(GetReceiptFile(cDT));
                        Lines           = SqlUpdateRC.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                        (Ver, IsReload) = Parse(Lines, CurVerRC, dbRC);
                    }
                    cDT = cDT.AddDays(1);
                }
                if (Ver != CurVerRC)
                {
                    wDB.SetConfig <int>("VerRC", Ver);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        public WDB_SQLite(DateTime parD = default(DateTime), string parConnect = "", bool pIsUseOldDB = false)  : base(Path.Combine(Global.PathIni, "SQLite.sql"))
        {
            Connect    = parConnect;
            varVersion = "SQLite.0.0.1";
            DT         = parD != default(DateTime) ? parD.Date : DateTime.Today.Date;
            InitSQL();


            if (IsFirstStart)
            {
                UpdateDB(ref pIsUseOldDB);
            }


            if (!File.Exists(ConfigFile))
            {
                db = new SQLite(ConfigFile);
                db.ExecuteNonQuery(SqlCreateConfigTable);
                db.Close();
            }
            //db = new SQLite(ConfigFile);//,"",this.varCallWriteLogSQL);


            if (!File.Exists(ReceiptFile))
            {
                var receiptFilePath = Path.GetDirectoryName(ReceiptFile);
                if (!Directory.Exists(receiptFilePath))
                {
                    Directory.CreateDirectory(receiptFilePath);
                }
                //Створюємо щоденну табличку з чеками.
                var db = new SQLite(ReceiptFile);
                db.ExecuteNonQuery(SqlCreateReceiptTable);
                db.Close();
                db = null;
            }


            if (!File.Exists(MidFile))
            {
                if (pIsUseOldDB)
                {
                    db = new SQLite(ConfigFile);
                    var varLastMidFile = GetConfig <string>("Last_MID");
                    db = null;
                    if (!string.IsNullOrEmpty(varLastMidFile) && File.Exists(varLastMidFile))
                    {
                        LastMidFile = varLastMidFile;
                    }
                }
                if (!pIsUseOldDB || string.IsNullOrEmpty(LastMidFile))
                {
                    var db = new SQLite(MidFile);
                    db.ExecuteNonQuery(SqlCreateMIDTable);
                    db.Close();
                    db = null;
                }
            }

            /*
             * if (pTypeDb == eTypeDb.AllMid || pTypeDb == eTypeDb.AllRC)
             * {
             *  if (pTypeDb == eTypeDb.AllMid)
             *  {
             *      db = new SQLite(MidFile);
             *      db.ExecuteNonQuery("ATTACH '" + ReceiptFile + "' AS rc");
             *  }
             *  else
             *  {
             *      db = new SQLite(ReceiptFile);
             *      db.ExecuteNonQuery("ATTACH '" + MidFile + "' AS mid");
             *      //db.ExecuteNonQuery("ATTACH '" + ConfigFile + "' AS con");
             *  }
             *  db.ExecuteNonQuery("ATTACH '" + ConfigFile + "' AS con");
             * }
             *
             * if(pTypeDb == eTypeDb.Mid)
             *  db = new SQLite(MidFile);
             *
             * if(pTypeDb == eTypeDb.RC)
             *  db = new SQLite(ReceiptFile);
             *
             * if (pTypeDb == eTypeDb.Config)
             *  db = new SQLite(ConfigFile);
             */

            db = new SQLite(ReceiptFile);
            db.ExecuteNonQuery("ATTACH '" + MidFile + "' AS mid");
            db.ExecuteNonQuery("ATTACH '" + ConfigFile + "' AS con");

            db.ExecuteNonQuery("PRAGMA synchronous = EXTRA;");
            db.ExecuteNonQuery("PRAGMA journal_mode = DELETE;");
            db.ExecuteNonQuery("PRAGMA wal_autocheckpoint = 5;");
        }