internal Database(string dataFile)
 {
     FilePath   = dataFile;
     Connection = File.Exists(dataFile) ?
                  new SQLiteConnector(dataFile, true) :
                  CreateEmptyDatabase(dataFile);
 }
Example #2
0
        static Program()
        {
            string dataFolder = GetDataFolder();
            string dataFile   = Path.Combine(dataFolder, AppName + ".data");

            try
            {
                if (File.Exists(dataFile))
                {
                    dataConn = new SQLiteConnector(dataFile, true);
                }
                else
                {
                    const string ddlFile = "Data_definition.sql";                     // SQL script file that creates an empty database.
                    if (!File.Exists(ddlFile))
                    {
                        MessageBox.Show("Application file missing!\n" + ddlFile,
                                        AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Directory.CreateDirectory(dataFolder);                     // does nothing if already existing.
                    dataConn = new SQLiteConnector(dataFile, false);
                    dataConn.Write(File.ReadAllText(ddlFile));
                }
            }
            catch (Exception err)
            {
                MessageBox.Show($"Error creating database file!\n\n{err.GetType().Name}\n{err.Message}",
                                AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                dataConn = null;                 // to trigger early return from Main().
                return;
            }
            Debug.Assert(dataConn != null && File.Exists(dataFile));
        }
Example #3
0
        public Data(SQLiteConnector connection)
        {
            Debug.Assert(connection != null);
            this.connection = connection;

            Dirty = true;
        }
Example #4
0
 static void RunTest()
 {
     SQLiteConnector dbConnector = SQLiteConnector.Instance;
     // act
     //dbConnector.EmptyDB();
     //dbConnector.selectAll(dbTables.tblTermContent);
 }
Example #5
0
        public MainWindowVM()
        {
            bool   status  = false;
            string db_file = "db_file.sqlite";

            //Init and Test Database Connection
            IDBConnectorEF dbconn = new SQLiteConnector(db_file);

            status = dbconn.Open();
            if (status)
            {
                dbconn.Close();
            }

            if (status)
            {
                //Assign to application wide shared variable.
                AppData.DBConn = dbconn;

                //Add ViewModel to the Content list
                _ContentVM.Add(new Module.Client.ClientManagerVM());
                _ContentVM.Add(new Module.Service.ClientManagerVM());
                _ContentVM.Add(new Module.Other.OtherManagerVM());

                //Init Menu Bar Commands.
                InitializeCommands();
            }
        }
Example #6
0
 public FormCuentas(AdminMain parent)
 {
     InitializeComponent();
     this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     con       = new SQLiteConnector();
     fillGrids();
     this.parent = parent;
 }
Example #7
0
 public FormAddAcc(FormCuentas parent)
 {
     InitializeComponent();
     this.Icon   = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     this.parent = parent;
     con         = new SQLiteConnector();
     isEditing   = false;
 }
 /// <summary>
 /// Select which Datastorage to use
 /// </summary>
 /// <param name="dbType"></param>
 public static void InitalizeConnections(DataBaseType dbType)
 {
     if (dbType == DataBaseType.SQLite)
     {
         SQLiteConnector sql = new SQLiteConnector();
         Connection = sql;
     }
 }
        private SQLiteConnector CreateEmptyDatabase(string dataFile)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(dataFile));
            var connection = new SQLiteConnector(dataFile, false);

            connection.Write(ddl);
            return(connection);
        }
Example #10
0
 public FormCrearTrabajo(string idCourse, FormProfessor p)
 {
     InitializeComponent();
     this.Icon     = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     this.idCourse = idCourse;
     con           = new SQLiteConnector();
     parent        = p;
 }
Example #11
0
 public FormForum(string idAuthor, string idCourse, ForumMenu parent)
 {
     InitializeComponent();
     this.Icon     = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     this.idAuthor = idAuthor;
     this.idCourse = idCourse;
     con           = new SQLiteConnector();
     this.parent   = parent;
 }
Example #12
0
        public void InsertNewArrayAttributeRelationship()
        {
            using (SQLiteConnector connector = new SQLiteConnector(TestDataHelper.FilePath))
            {
                string sql = $"INSERT INTO DataSeries_Attributes (DataSeries_Id, Attributes_AttributeName) values('3', 'Some other attribute')";

                connector.WriteTextData(sql);
            }
        }
        public void WhenIAddANewAttribute(string attributeName)
        {
            using (SQLiteConnector connector = new SQLiteConnector(TestDataHelper.FilePath))
            {
                string sql = $"INSERT INTO Attributes (AttributeName) values('{attributeName}')";

                connector.WriteTextData(sql);
            }
        }
Example #14
0
 public FormEnviarCal(string idStudent, string idAssignment, FormRevisar parent)
 {
     InitializeComponent();
     this.Icon         = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     con               = new SQLiteConnector();
     this.idAssignment = idAssignment;
     this.idStudent    = idStudent;
     this.parent       = parent;
     setMax();
 }
Example #15
0
 public FormAddAcc(FormCuentas parent, string idUs, string accType)
 {
     InitializeComponent();
     con         = new SQLiteConnector();
     idUser      = idUs;
     this.parent = parent;
     isEditing   = true;
     accountType = accType;
     fillFields();
 }
Example #16
0
        public void InsertNewAttribute()
        {
            using (SQLiteConnector connector = new SQLiteConnector(TestDataHelper.FilePath))
            {
                string uniqueAttribute = "attribute " + DateTime.Now.ToString("ddMMyyyy_HHmmss.f");
                string sql             = $"INSERT INTO Attributes (AttributeName) values('{uniqueAttribute}')";

                connector.WriteTextData(sql);
            }
        }
Example #17
0
 public FormPosts(string idForum, string idAutor)
 {
     InitializeComponent();
     this.Icon    = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     con          = new SQLiteConnector();
     this.idForum = idForum;
     this.idAutor = idAutor;
     getTitle();
     GetOP();
 }
        public void MuseReturnNameWhenUsingWrongId()
        {
            SQLiteConnector con = new SQLiteConnector();

            using (var context = con.GetContext())
            {
                var r3 = con.GetRecord(4);
                Assert.IsNull(r3);
            }
        }
        public void MuseReturnNameWhenUsingWrongHebrewName()
        {
            SQLiteConnector con = new SQLiteConnector();

            using (var context = con.GetContext())
            {
                var r2 = con.GetRecord("ניסים");
                Assert.IsNull(r2.Result);
            }
        }
Example #20
0
 public FormRevisar(string idAssignment, string AssName, FormProfessor parent)
 {
     InitializeComponent();
     this.Icon         = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     this.idAssignment = idAssignment;
     AssignmentName    = AssName;
     setTitle();
     con = new SQLiteConnector();
     fillDataGridTrabajos();
     this.parent = parent;
 }
Example #21
0
 public FormProfessor(FormLogin l, string idAccount)
 {
     InitializeComponent();
     this.Icon      = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     con            = new SQLiteConnector();
     login          = l;
     this.idAccount = idAccount;
     setTitle();
     FillDataGridView();
     selectedCourse = "";
 }
Example #22
0
        public FormEditStudent(string idCourse, FormSendCourse parent)
        {
            InitializeComponent();
            this.Icon              = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            this.idCourse          = idCourse;
            numericUpDown1.Maximum = decimal.MaxValue;
            numericUpDown1.Minimum = 1;
            this.parent            = parent;

            con = new SQLiteConnector();
        }
        public void WhenIAssociateDataSeriesWithSomeOtherAttribute(int recordNum, string attributeName)
        {
            using (SQLiteConnector connector = new SQLiteConnector(TestDataHelper.FilePath))
            {
                string sql = $"INSERT INTO DataSeries_Attributes (DataSeries_Id, Attributes_AttributeName) values('{recordNum}', '{attributeName}')";

                connector.WriteTextData(sql);
            }

            UpdateDatabaseResults();
        }
Example #24
0
 public FormSendCourse(string idCourse, string courseName, string teacherID)
 {
     InitializeComponent();
     this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     con       = new SQLiteConnector();
     numericUpDown1.Minimum = 1;
     numericUpDown1.Maximum = decimal.MaxValue;
     this.idCourse          = idCourse;
     textBox1.Text          = courseName;
     numericUpDown1.Value   = Convert.ToDecimal(teacherID);
     fillStudents();
 }
        public void MuseReturnNameWhenUsingHebrewName()
        {
            SQLiteConnector con = new SQLiteConnector();

            using (var context = con.GetContext())
            {
                var r1 = con.GetRecord(1);
                Assert.IsNotNull(r1);
                Assert.AreEqual(r1.Hebrew, "משה");
                Assert.AreEqual(r1.English, "Moshe");
            }
        }
        public void MuseReturnNameWhenUsingId()
        {
            SQLiteConnector con = new SQLiteConnector();

            using (var context = con.GetContext())
            {
                var r1 = con.GetRecord(1);
                Assert.IsNotNull(r1);
                File.WriteAllText(@"c:\log\output.txt", r1.English);

                Assert.AreEqual(r1.Hebrew, "משה");
                Assert.AreEqual(r1.English, "Moshe");
            }
        }
        public void DbContextMustNotBeNull()
        {
            SQLiteConnector con = new SQLiteConnector();

            using (var context = con.GetContext())
            {
                Assert.IsNotNull(context);

                var r2 = con.GetRecord("דוד");
                Assert.IsNotNull(r2);
                Assert.AreEqual(r2.Result.Hebrew, "דוד");
                Assert.AreEqual(r2.Result.English, "David");
            }
        }
        public void WhenIAddANewDataSeriesToTheDatabase()
        {
            double[,] multiArray = DbDataConverter.ConvertTwoDoubleArrayToMultiDimArray(TestDataHelper.RetentionVols, TestDataHelper.RI);

            byte[] serializedScatterSeries = DbDataConverter.SerializeMultiDimentionalDoubleArray(multiArray);
            string name = "Visual Studio Test";
            string date = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.f");

            using (SQLiteConnector connector = new SQLiteConnector(TestDataHelper.FilePath))
            {
                string sql = $"INSERT INTO DataSeries (Name, AcquisitionDate, Data) values('{name}', '{date}', @serializedScatterSeries)";

                connector.WriteDataContainingParameters(sql, new KeyValuePair <string, byte[]>("serializedScatterSeries", serializedScatterSeries));
            }
        }
Example #29
0
        public static void InitializeConnections()
        {
            //if (db == DatabaseType.SQLite)
            //{
            //    SQLiteConnector sqlite = new SQLiteConnector();
            //    Connection = sqlite;
            //}
            //else if (db == DatabaseType.TextFile)
            //{
            //    TextConnector text = new TextConnector();
            //    Connection = text;
            //}
            SQLiteConnector sqlite = new SQLiteConnector();

            Connection = sqlite;
        }
Example #30
0
 /// <summary>
 /// Initialize connections.
 /// This connections we want to set up.
 /// (called at program starts).
 /// </summary>
 public static void InitializeConnections(DatabaseType db)
 {
     if (db == DatabaseType.SqlDb)
     {
         // TODO - St up the SQL Connection properly.
         SqlDbConnector sql = new SqlDbConnector();
         Connection = (IDataConnection)sql;
         CnnString  = ConfigurationManager.ConnectionStrings["SQLServer"].ConnectionString;
     }
     else if (db == DatabaseType.SQLite)
     {
         // TODO - Create Access Connection
         SQLiteConnector sql = new SQLiteConnector();
         Connection = sql;
         //CnnString = ConfigurationManager.ConnectionStrings["SQLite"].ConnectionString;
         CnnString = "Data Source=" + Environment.CurrentDirectory + "\\LessonsSchedulerDB.db;";
     }
 }
Example #31
0
        /// <summary>
        /// Obtiene el comando de SQLite para ser ejecutado en la conexión dada
        /// </summary>
        /// <param name="db">Conexión a la base de datos</param>
        /// <returns>El comando SQLite</returns>
        public SQLiteCommand GetCommand(SQLiteConnector db)
        {
            var result = db.Connection.CreateCommand();
            result.CommandText = SQL;
            result.Transaction = db.Transaction;

            if (parameters != null)
            {
                foreach (var parameterKey in parameters.Keys)
                {
                    var value = parameters[parameterKey];
                    result.Parameters.AddWithValue(parameterKey, value);
                }
            }

            return result;
        }