Exemplo n.º 1
0
        public void Delete(int SensorID)
        {
            int IDX = ListID(SensorID);

            if (IDX != -1)
            {
                // remove from list
                cSensors.RemoveAt(IDX);

                // remove from database
                DAO.Recordset RS;
                string        SQL = "Select * from tblSensors where senID = " + SensorID.ToString();
                RS = mf.Dbase.DB.OpenRecordset(SQL);
                if (!RS.EOF)
                {
                    RS.Delete();
                }
                RS.Close();
            }
        }
Exemplo n.º 2
0
        public void TrimRecords(DAO.Database DB)
        {
            DAO.Recordset RS;
            string        SQL = "select * from tblProps";

            RS = DB.OpenRecordset(SQL);
            int dbMax = (int)(RS.Fields["dbMaxSize"].Value ?? 0);
            int Size  = (int)(new System.IO.FileInfo(cDB.Name).Length);

            RS.Close();
            if (Size > dbMax)
            {
                SQL = "Select top 20 percent * from tblRecords order by recID desc";
                RS  = DB.OpenRecordset(SQL);
                while (!RS.EOF)
                {
                    RS.Delete();
                    RS.MoveNext();
                }
                RS.Close();
            }
        }
Exemplo n.º 3
0
        public void Delete(byte ID)
        {
            int IDX = ListID(ID);

            if (IDX == -1)
            {
                throw new IndexOutOfRangeException();
            }

            // remove from list
            cControlBoxes.RemoveAt(IDX);

            // remove from database
            DAO.Recordset RS;
            string        SQL = "Select * from tblControlBoxes where cbID =" + ID.ToString();

            RS = mf.Dbase.DB.OpenRecordset(SQL);
            if (!RS.EOF)
            {
                RS.Delete();
            }
            RS.Close();
        }
Exemplo n.º 4
0
        private string CheckVersion(short Ver, string DBname)
        {
            string SQL;

            DAO.Recordset RS;
            string        Result = "";

            if (Ver > cDBversion)
            {
                // higher version, program out of date
                Result = "Database version does not match, software out of date.";
            }
            else if (Ver == cDBversion)
            {
                Result = "true";
            }
            else
            {
                // lower version, update

                // close current database
                try
                {
                    cDB.Close();
                }
                catch (Exception)
                {
                }

                // copy base file to tmp file in data folder
                string NewPath  = mf.Tls.DataFolder + "\\NewTmp.mdb";
                string BasePath = mf.Tls.SettingsFolder + "\\TempMonBase.mdb";
                File.WriteAllBytes(NewPath, Properties.Resources.Base);
                FileInfo BaseFile = new FileInfo(BasePath);

                // copy current database to tmp file in data folder
                string TmpPath = mf.Tls.DataFolder + "\\OldTmp.mdb";
                try
                {
                    // delete tmp file, if it exists
                    File.Delete(TmpPath);
                }
                catch (Exception Ex)
                {
                    mf.Tls.WriteErrorLog("clsDatabase: CheckVersion: " + Ex.Message);
                }
                FileInfo OldFile = new FileInfo(DBname);
                OldFile.CopyTo(TmpPath);

                // open new tmp database and old tmp database
                DAO.Database DBnew = cDBE.OpenDatabase(NewPath, DAO.DriverPromptEnum.dbDriverNoPrompt, false, "");
                DAO.Database DBold = cDBE.OpenDatabase(TmpPath, DAO.DriverPromptEnum.dbDriverNoPrompt, false, "");

                // delete new database properties records
                SQL = "select * from tblProps";
                RS  = DBnew.OpenRecordset(SQL);
                while (!RS.EOF)
                {
                    RS.Delete();
                    RS.MoveNext();
                }
                RS.Close();

                // copy matching data from old database to new database
                if (CopyData(DBnew, DBold))
                {
                    // update database properties
                    SQL = "select * from tblProps";
                    RS  = DBnew.OpenRecordset(SQL);
                    if (RS.EOF)
                    {
                        RS.AddNew();
                    }
                    else
                    {
                        RS.Edit();
                    }
                    RS.Fields["dbType"].Value    = DBtype;
                    RS.Fields["dbVersion"].Value = cDBversion;
                    RS.Update();
                    RS.Close();

                    // copy new updated database to current database name
                    DBnew.Close();
                    DBold.Close();
                    File.Delete(DBname);    // delete current file
                    FileInfo NewFile = new FileInfo(NewPath);
                    NewFile.CopyTo(DBname); // copy new file to current file name
                    File.Delete(TmpPath);   // delete tmp copy of current file
                    File.Delete(NewPath);   // delete new file
                    Result = "true";
                }
                else
                {
                    // failed to copy, remove new database and tmp database
                    File.Delete(TmpPath);   // delete tmp copy of current file
                    File.Delete(NewPath);   // delete new file
                    Result = "Failed to update database version.";
                }
            }
            return(Result);
        }