Esempio n. 1
0
 // Functie pentru a sterge un capitol din baza de date
 public static void delete_capitole(string decizie, string title)
 {
     SQLiteConnection sqlite_conn;
     SQLiteCommand sqlite_cmd;
     string database_title = get_databaseName_tableName.get_databaseName(decizie, "capitole");
     string table_title = get_databaseName_tableName.get_tableName(decizie, "capitole");
        /* if (decizie == "info") { database_title = "Capitole.db"; table_title = "capitole";}
     if (decizie == "mate") { database_title = "Capitole_mate.db"; table_title = "capitole_mate"; }
     if (decizie == "bio") { database_title = "Capitole_bio.db"; table_title = "capitole_bio"; }*/
     try
     {
         sqlite_conn = new SQLiteConnection("Data Source=" + database_title + ";Version=3;New=False;Compress=True;");
         sqlite_conn.Open();
         sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = "delete from " + table_title + " where titlu = @titlu_capitol";
         SQLiteParameter parameter = new SQLiteParameter("@titlu_capitol", DbType.String);
         parameter.Value = title;
         sqlite_cmd.Parameters.Add(parameter);
         sqlite_cmd.ExecuteNonQuery();
         MessageBox.Show("Lectia a fost stearsa cu succes!");
         sqlite_conn.Close();
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 2
0
 internal override IDataParameter CreateIDataParameter(string name, object value)
 {
     SQLiteParameter p = new SQLiteParameter();
     p.ParameterName = name;
     p.Value = value;
     return p;
 }
Esempio n. 3
0
 private void pictureBox2_Click(object sender, EventArgs e)
 {
     if (nume.Text == "" || prenume.Text == "" || repass.Text == "" || password.Text == "" || username.Text == "")
         MessageBox.Show("Trebuie sa completati toate campurile!");
     else
         if (cross.Visible == true)
             MessageBox.Show("Parolele nu corespund!");
         else
         {
             string parola_criptata;
             parola_criptata = RC4Class.RC4_Class.RC4(password.Text, "38577af7-379f-421d-ad29-cd1994521704");
             SQLiteConnection sqlite_conn;
             SQLiteCommand sqlite_cmd;
             FileStream fstream;
             sqlite_conn = new SQLiteConnection("Data Source=LOGIN.db;Version=3;New=False;Compress=True;");
             try
             {
                 sqlite_conn.Open();
                 byte[] imageBt = null;
                 fstream = new FileStream(this.image_path.Text, FileMode.Open, FileAccess.Read);
                 BinaryReader br = new BinaryReader(fstream);
                 imageBt = br.ReadBytes((int)fstream.Length);
                 sqlite_cmd = sqlite_conn.CreateCommand();
                 sqlite_cmd.CommandText = "INSERT INTO utilizatori(nume, prenume, username, password,avatar) " +
                                                             "Values('" + nume.Text + "', '" + prenume.Text + "', '" + username.Text + "', '" + parola_criptata + "', @IMG);";
                 SQLiteParameter parameter = new SQLiteParameter("@IMG", System.Data.DbType.Binary);
                 SQLiteParameter parameter1 = new SQLiteParameter("@nume", System.Data.DbType.String);
                 SQLiteParameter parameter2 = new SQLiteParameter("@prenume", System.Data.DbType.String);
                 SQLiteParameter parameter3 = new SQLiteParameter("@username", System.Data.DbType.String);
                 SQLiteParameter parameter4 = new SQLiteParameter("@parola", System.Data.DbType.String);
                 parameter.Value = imageBt;
                 parameter1.Value = nume.Text;
                 parameter2.Value = prenume.Text;
                 parameter3.Value = username.Text;
                 parameter4.Value = parola_criptata;
                 sqlite_cmd.Parameters.Add(parameter);
                 sqlite_cmd.Parameters.Add(parameter1);
                 sqlite_cmd.Parameters.Add(parameter2);
                 sqlite_cmd.Parameters.Add(parameter3);
                 sqlite_cmd.Parameters.Add(parameter4);
                 sqlite_cmd.ExecuteNonQuery();
                 sqlite_conn.Close();
                 MessageBox.Show("Tocmai te-ai inscris in baza noastra de date!");
                 Login lg = new Login();
                 this.Hide();
                 lg.Show();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
 }
Esempio n. 4
0
 private IDbDataParameter CreateParameter(DataRow row, bool original)
 {
     String pPrefix;
     DataRowVersion rowVersion;
     if (original)
     {
         pPrefix = OriginalVersionParameterPrefix;
         rowVersion = DataRowVersion.Original;
     }
     else
     {
         pPrefix = "@";
         rowVersion = DataRowVersion.Current;
     }
     IDbDataParameter p = new SQLiteParameter(
         String.Concat(pPrefix,Convert.ToString(row["ColumnName"])),
         (DbType)Convert.ToInt32(row["ProviderType"]));
     p.SourceColumn = Convert.ToString(row["ColumnName"]);
     p.SourceVersion = rowVersion;
     return p;
 }
        private void creeaza_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true && textBox1.Text != null && richTextBox1.Text != null)
            {
                if(decizie=="info")
                    {
                        try
                        {
                            SQLiteConnection sqlite_conn;
                            SQLiteCommand sqlite_cmd;
                            sqlite_conn = new SQLiteConnection("Data Source=Capitole.db;Version=3;New=False;Compress=True;");
                            sqlite_conn.Open();
                            sqlite_cmd = sqlite_conn.CreateCommand();
                            sqlite_cmd.CommandText = "INSERT INTO capitole(titlu, teorie, id_html) " +
                                                                      "Values(@titlu, @teorie, @fd)";
                            SQLiteParameter param1 = new SQLiteParameter("@titlu", DbType.String);
                            SQLiteParameter param2 = new SQLiteParameter("@teorie", DbType.String);
                            SQLiteParameter param3 = new SQLiteParameter("@fd", DbType.String);
                            param1.Value = textBox1.Text;
                            param2.Value = richTextBox1.Text;
                            param3.Value = folder_guid.ToString();
                            sqlite_cmd.Parameters.Add(param1);
                            sqlite_cmd.Parameters.Add(param2);
                            sqlite_cmd.Parameters.Add(param3);
                            sqlite_cmd.ExecuteNonQuery();
                            MessageBox.Show("Capitolul a fost adaugat cu succes!");
                            sqlite_conn.Close();
                            textBox1.Clear();
                            richTextBox1.Clear();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }

                if(decizie=="mate")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Capitole_mate.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "INSERT INTO capitole_mate(titlu, teorie, id_html) values (@titlu, @teorie, @fd)";
                        SQLiteParameter param4 = new SQLiteParameter("@titlu", DbType.String);
                        SQLiteParameter param5 = new SQLiteParameter("@teorie", DbType.String);
                        SQLiteParameter param6 = new SQLiteParameter("@fd", DbType.String);
                        param4.Value = textBox1.Text;
                        param5.Value = richTextBox1.Text;
                        param6.Value = folder_guid.ToString();
                        sqlite_cmd.Parameters.Add(param4);
                        sqlite_cmd.Parameters.Add(param5);
                        sqlite_cmd.Parameters.Add(param6);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Capitolul a fost adaugat cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if (decizie == "bio")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Capitole_bio.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "INSERT INTO capitole_bio(titlu, teorie, id_html) " +
                                                                      "Values(@titlu, @teorie, @fd)";
                        SQLiteParameter param1 = new SQLiteParameter("@titlu", DbType.String);
                        SQLiteParameter param2 = new SQLiteParameter("@teorie", DbType.String);
                        SQLiteParameter param3 = new SQLiteParameter("@fd", DbType.String);
                        param1.Value = textBox1.Text;
                        param2.Value = richTextBox1.Text;
                        param3.Value = folder_guid.ToString();
                        sqlite_cmd.Parameters.Add(param1);
                        sqlite_cmd.Parameters.Add(param2);
                        sqlite_cmd.Parameters.Add(param3);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Capitolul a fost adaugat cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else if (checkBox2.Checked == true && textBox1.Text != null && richTextBox1.Text != null)
            {
                if (decizie == "info")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "INSERT INTO subcapitole(nume_subcapitol,text_subcapitol,nume_capitol,id_animatie, id_html) " +
                                                                  "Values(@ns,@ts,@nc,@ida,@idh)";
                        SQLiteParameter param1 = new SQLiteParameter("@ns", DbType.String);
                        SQLiteParameter param2 = new SQLiteParameter("@ts", DbType.String);
                        SQLiteParameter param3 = new SQLiteParameter("@nc", DbType.String);
                        SQLiteParameter param4 = new SQLiteParameter("@ida", DbType.String);
                        SQLiteParameter param5 = new SQLiteParameter("@idh", DbType.String);
                        param1.Value = textBox1.Text;
                        param2.Value = richTextBox1.Text;
                        param3.Value = capitol_parental;
                        param4.Value = cod_guid;
                        param5.Value = folder_guid.ToString();
                        sqlite_cmd.Parameters.Add(param1);
                        sqlite_cmd.Parameters.Add(param2);
                        sqlite_cmd.Parameters.Add(param3);
                        sqlite_cmd.Parameters.Add(param4);
                        sqlite_cmd.Parameters.Add(param5);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Subcapitolul a fost adaugat cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                if (decizie == "bio")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole_bio.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "INSERT INTO subcapitole_bio(nume_subcapitol,text_subcapitol,nume_capitol,id_animatie, id_html) " +
                                                                  "Values(@ns,@ts,@nc,@ida,@idh)";
                        SQLiteParameter param1 = new SQLiteParameter("@ns", DbType.String);
                        SQLiteParameter param2 = new SQLiteParameter("@ts", DbType.String);
                        SQLiteParameter param3 = new SQLiteParameter("@nc", DbType.String);
                        SQLiteParameter param4 = new SQLiteParameter("@ida", DbType.String);
                        SQLiteParameter param5 = new SQLiteParameter("@idh", DbType.String);
                        param1.Value = textBox1.Text;
                        param2.Value = richTextBox1.Text;
                        param3.Value = capitol_parental;
                        param4.Value = cod_guid;
                        param5.Value = folder_guid.ToString();
                        sqlite_cmd.Parameters.Add(param1);
                        sqlite_cmd.Parameters.Add(param2);
                        sqlite_cmd.Parameters.Add(param3);
                        sqlite_cmd.Parameters.Add(param4);
                        sqlite_cmd.Parameters.Add(param5);

                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Subcapitolul a fost adaugat cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                if (decizie == "mate")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole_mate.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "INSERT INTO subcapitole_mate(nume_subcapitol,text_subcapitol,nume_capitol,id_animatie, id_html) " +
                                                                  "Values(@ns,@ts,@nc,@ida,@idh)";
                        SQLiteParameter param1 = new SQLiteParameter("@ns", DbType.String);
                        SQLiteParameter param2 = new SQLiteParameter("@ts", DbType.String);
                        SQLiteParameter param3 = new SQLiteParameter("@nc", DbType.String);
                        SQLiteParameter param4 = new SQLiteParameter("@ida", DbType.String);
                        SQLiteParameter param5 = new SQLiteParameter("@idh", DbType.String);
                        param1.Value = textBox1.Text;
                        param2.Value = richTextBox1.Text;
                        param3.Value = capitol_parental;
                        param4.Value = cod_guid;
                        param5.Value = folder_guid.ToString();
                        sqlite_cmd.Parameters.Add(param1);
                        sqlite_cmd.Parameters.Add(param2);
                        sqlite_cmd.Parameters.Add(param3);
                        sqlite_cmd.Parameters.Add(param4);
                        sqlite_cmd.Parameters.Add(param5);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Subcapitolul a fost adaugat cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
                MessageBox.Show("Toate campurile trebuie sa fie completate iar un checkBox selectat!");
        }
 public SQLiteParameter Add(String parameterName, DbType dbType, int size, String sourceColumn)
 {
     SQLiteParameter param = new SQLiteParameter(parameterName,dbType);
     param.Size = size;
     if( sourceColumn != null )
         param.SourceColumn = sourceColumn;
     return Add(param);
 }
 public SQLiteParameter Add(SQLiteParameter param)
 {
     Add((Object)param);
     return param;
 }
        /// <summary>
        /// Create and prepare a SQLiteCommand, and call ExecuteReader with the appropriate CommandBehavior.
        /// </summary>
        /// <remarks>
        /// If we created and opened the connection, we want the connection to be closed when the DataReader is closed.
        /// 
        /// If the caller provided the connection, we want to leave it to them to manage.
        /// </remarks>
        /// <param name="connection">A valid SQLiteConnection, on which to execute this command</param>
        /// <param name="transaction">A valid SQLiteTransaction, or 'null'</param>
        /// <param name="commandType">The CommandType (TableDirect, Text)</param>
        /// <param name="commandText">The T-SQL command</param>
        /// <param name="commandParameters">An array of SQLiteParameters to be associated with the command or 'null' if no parameters are required</param>
        /// <param name="connectionOwnership">Indicates whether the connection parameter was provided by the caller, or created by SQLiteHelper</param>
        /// <returns>SQLiteDataReader containing the results of the command</returns>
        private static SQLiteDataReader ExecuteReader(SQLiteConnection connection, SQLiteTransaction transaction, CommandType commandType, string commandText, SQLiteParameter[] commandParameters, SQLiteConnectionOwnership connectionOwnership)
        {
            if( connection == null ) throw new ArgumentNullException( "connection" );

            bool mustCloseConnection = false;
            // Create a command and prepare it for execution
            SQLiteCommand cmd = new SQLiteCommand();
            try
            {
                PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection );

                // Create a reader
                SQLiteDataReader dataReader;

                // Call ExecuteReader with the appropriate CommandBehavior
                if (connectionOwnership == SQLiteConnectionOwnership.External)
                {
                    dataReader = cmd.ExecuteReader();
                }
                else
                {
                    dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                }

                // Detach the SQLiteParameters from the command object, so they can be used again.
                // HACK: There is a problem here, the output parameter values are fletched
                // when the reader is closed, so if the parameters are detached from the command
                // then the SQLiteReader can´t set its values.
                // When this happen, the parameters can´t be used again in other command.
                bool canClear = true;
                foreach(SQLiteParameter commandParameter in cmd.Parameters)
                {
                    if (commandParameter.Direction != ParameterDirection.Input)
                        canClear = false;
                }

                if (canClear)
                {
                    cmd.Parameters.Clear();
                }

                return dataReader;
            }
            catch
            {
                if( mustCloseConnection )
                    connection.Close();
                throw;
            }
        }
 /// <summary>
 /// This method is used to attach array of SQLiteParameters to a SQLiteCommand.
 /// 
 /// This method will assign a value of DbNull to any parameter with a direction of
 /// InputOutput and a value of null.  
 /// 
 /// This behavior will prevent default values from being used, but
 /// this will be the less common case than an intended pure output parameter (derived as InputOutput)
 /// where the user provided no input value.
 /// </summary>
 /// <param name="command">The command to which the parameters will be added</param>
 /// <param name="commandParameters">An array of SQLiteParameters to be added to command</param>
 private static void AttachParameters(SQLiteCommand command, SQLiteParameter[] commandParameters)
 {
     if( command == null ) throw new ArgumentNullException( "command" );
     if( commandParameters != null )
     {
         foreach (SQLiteParameter p in commandParameters)
         {
             if( p != null )
             {
                 // Check for derived output value with no value assigned
                 if ( ( p.Direction == ParameterDirection.InputOutput ||
                     p.Direction == ParameterDirection.Input ) &&
                     (p.Value == null))
                 {
                     p.Value = DBNull.Value;
                 }
                 command.Parameters.Add(p);
             }
         }
     }
 }
        /// <summary>
        /// This method opens (if necessary) and assigns a connection, transaction, command type and parameters 
        /// to the provided command
        /// </summary>
        /// <param name="command">The SQLiteCommand to be prepared</param>
        /// <param name="connection">A valid SQLiteConnection, on which to execute this command</param>
        /// <param name="transaction">A valid SQLiteTransaction, or 'null'</param>
        /// <param name="commandType">The CommandType (TableDirect, Text)</param>
        /// <param name="commandText">The T-SQL command</param>
        /// <param name="commandParameters">An array of SQLiteParameters to be associated with the command or 'null' if no parameters are required</param>
        /// <param name="mustCloseConnection"><c>true</c> if the connection was opened by the method, otherwose is false.</param>
        private static void PrepareCommand(SQLiteCommand command, SQLiteConnection connection, SQLiteTransaction transaction, CommandType commandType, string commandText, SQLiteParameter[] commandParameters, out bool mustCloseConnection )
        {
            if( command == null ) throw new ArgumentNullException( "command" );

            if(commandType == CommandType.StoredProcedure ) throw new ArgumentException("Stored Procedures are not supported.");

            // If the provided connection is not open, we will open it
            if (connection.State != ConnectionState.Open)
            {
                mustCloseConnection = true;
                connection.Open();
            }
            else
            {
                mustCloseConnection = false;
            }

            // Associate the connection with the command
            command.Connection = connection;

            // Set the command text (SQL statement)
            command.CommandText = commandText;

            // If we were provided a transaction, assign it
            if (transaction != null)
            {
                if( transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" );
                command.Transaction = transaction;
            }

            // Set the command type
            command.CommandType = commandType;

            // Attach the command parameters if they are provided
            if (commandParameters != null)
            {
                AttachParameters(command, commandParameters);
            }
            return;
        }
Esempio n. 11
0
 public static string Main(string parola_input, string username_input, PictureBox picAvatar, GroupBox gb, Label lb, PictureBox pb1, PictureBox pb2, string DECIZIE, Label pct1, Label pct2, Label pct3, Label pct4, Label pct5, string logged_as)
 {
     //Functia efectiva ce verifica cele doua valori introduse de catre utilizator(nume de utilizatori si parola)
     string parola_criptata;
     parola_criptata = RC4Class.RC4_Class.RC4(parola_input, "38577af7-379f-421d-ad29-cd1994521704");
     SQLiteConnection sqlite_conn;
     SQLiteCommand sqlite_cmd;
     SQLiteDataReader sqlite_datareader;
     sqlite_conn = new SQLiteConnection("Data Source=LOGIN.db;Version=3;New=False;Compress=True;");
     try
     {
         sqlite_conn.Open();
         sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = "SELECT * FROM utilizatori where username= @usr and password= @pass ";
         SQLiteParameter param1 = new SQLiteParameter("@usr", DbType.String);
         param1.Value = username_input;
         sqlite_cmd.Parameters.Add(param1);
         SQLiteParameter param2 = new SQLiteParameter("@pass", DbType.String);
         param2.Value = parola_criptata;
         sqlite_cmd.Parameters.Add(param2);
         sqlite_datareader = sqlite_cmd.ExecuteReader();
         int count = 0;
         while (sqlite_datareader.Read())
         {
             count++;
         }
         if (count == 1)
         {
             get_avatar(picAvatar, username_input);
             get_score(username_input, DECIZIE, pct1, pct2, pct3, pct4, pct5);
             logged_as = username_input;
             MessageBox.Show("Datele sunt corecte!");
             gb.Visible = true;
             lb.Text = username_input + "!";
             pb1.Visible = true;
             pb2.Visible = false;
             sqlite_conn.Close();
             return username_input;
         }
         else
         {
             MessageBox.Show("Datele sunt incorecte!");
             sqlite_conn.Close();
             return "";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return "";
     }
 }
Esempio n. 12
0
 public static void get_score(string username, string decizie, Label lb1, Label lb2, Label lb3, Label lb4, Label lb5)
 {
     //Iau din baza de date cele 5 procente salvate in funtie de disciplina
     int starting_value = 0;
     //schimb coloana de la care incepe citirea datelor { [(5-9)->informatica] [(10-14)->matematica] [(15-19)->biologie]}
     if (decizie == "info") { starting_value = 5;  }
     if (decizie == "mate") { starting_value = 10; }
     if (decizie == "bio")  { starting_value = 15; }
     SQLiteConnection sqlite_conn;
     SQLiteCommand sqlite_command;
     SQLiteDataReader sqlite_data_reader;
     sqlite_conn = new SQLiteConnection("Data Source=LOGIN.db;Version=3;New=False;Compress=True;");
     sqlite_conn.Open();
     sqlite_command = sqlite_conn.CreateCommand();
     sqlite_command.CommandText = "SELECT * FROM utilizatori where username= @user";
     SQLiteParameter param = new SQLiteParameter("@user", DbType.String);
     param.Value = username;
     sqlite_command.Parameters.Add(param);
     sqlite_data_reader = sqlite_command.ExecuteReader();
     while(sqlite_data_reader.Read())
     {
         lb1.Text = sqlite_data_reader.GetString(starting_value);
         lb2.Text = sqlite_data_reader.GetString(starting_value + 1);
         lb3.Text = sqlite_data_reader.GetString(starting_value + 2);
         lb4.Text = sqlite_data_reader.GetString(starting_value + 3);
         lb5.Text = sqlite_data_reader.GetString(starting_value + 4);
     }
     sqlite_conn.Close();
 }
Esempio n. 13
0
        public static void get_avatar(PictureBox pb, string username)
        {
            //Iau imaginea de avatar din baza de date in functie de username
            SQLiteCommand sql_command;
            SQLiteConnection sqlite_conn;
            SQLiteDataReader sql_datareader;
            sqlite_conn = new SQLiteConnection("Data Source=LOGIN.db;Version=3;New=False;Compress=True;");
            sqlite_conn.Open();
            sql_command = sqlite_conn.CreateCommand();
            sql_command.CommandText = "SELECT avatar FROM utilizatori where username= @user";
            SQLiteParameter param = new SQLiteParameter("@user", DbType.String);
            param.Value = username;
            sql_command.Parameters.Add(param);
            sql_datareader = sql_command.ExecuteReader();
            while (sql_datareader.Read())
            {
                byte[] img = (byte[])(sql_datareader["avatar"]);
                if (img == null)

                    pb.Image = null;
                else
                {
                    MemoryStream ms = new MemoryStream(img);
                    pb.Image = Image.FromStream(ms);
                }
            }
            sqlite_conn.Close();
        }
Esempio n. 14
0
 // editez continutul unui subcapitol pentru Edit.cs
 public static void edit_subcapitole(string decizie, string subc_title, string nume_nou, string teorie_noua)
 {
     string database_title = "";
     string table_title = "";
     if (decizie == "info") { database_title = "Subcapitole.db"; table_title = "subcapitole"; }
     if (decizie == "mate") { database_title = "Subcapitole_mate.db"; table_title = "subcapitole_mate"; }
     if (decizie == "bio") { database_title = "Subcapitole_bio.db"; table_title = "subcapitole_bio"; }
     try
     {
         SQLiteConnection sqlite_conn;
         SQLiteCommand sqlite_cmd;
         sqlite_conn = new SQLiteConnection("Data Source=" + database_title + ";Version=3;New=False;Compress=True;");
         sqlite_conn.Open();
         sqlite_cmd = sqlite_conn.CreateCommand();
         sqlite_cmd.CommandText = ("update " +table_title+ " set nume_subcapitol = @titlu , text_subcapitol = @teor where nume_subcapitol = @tt");
         SQLiteParameter param1 = new SQLiteParameter("@titlu", DbType.String);
         SQLiteParameter param2 = new SQLiteParameter("@teor", DbType.String);
         SQLiteParameter param3 = new SQLiteParameter("@tt", DbType.String);
         param1.Value = nume_nou;
         param2.Value = teorie_noua;
         param3.Value = subc_title;
         sqlite_cmd.Parameters.Add(param1);
         sqlite_cmd.Parameters.Add(param2);
         sqlite_cmd.Parameters.Add(param3);
         sqlite_cmd.ExecuteNonQuery();
         MessageBox.Show("Lectia a fost modificata cu succes!");
         sqlite_conn.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void adauga_intrebarea_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
            {
                if (textBox1.Text == textBox5.Text || textBox2.Text == textBox5.Text || textBox3.Text == textBox5.Text || textBox4.Text == textBox5.Text)
                {
                    if(decizie == "info")
                    {
                        try
                        {
                            SQLiteConnection sqlite_conn;
                            SQLiteCommand sqlite_cmd;
                            sqlite_conn = new SQLiteConnection("Data Source=Intrebari.db;Version=3;New=False;Compress=True;");
                            sqlite_conn.Open();
                            sqlite_cmd = sqlite_conn.CreateCommand();
                            sqlite_cmd.CommandText = "INSERT INTO intrebari(textl, var1, var2, var3, varcorecta, cap_parental) " +
                                                                      "Values(@txt, @v1, @v2, @v3, @vc, @cap);";
                            SQLiteParameter param1 = new SQLiteParameter("@txt", DbType.String);
                            SQLiteParameter param2 = new SQLiteParameter("@v1", DbType.String);
                            SQLiteParameter param3 = new SQLiteParameter("@v2", DbType.String);
                            SQLiteParameter param4 = new SQLiteParameter("@v3", DbType.String);
                            SQLiteParameter param5 = new SQLiteParameter("@vc", DbType.String);
                            SQLiteParameter param6 = new SQLiteParameter("@cap", DbType.String);
                            param1.Value = textBox1.Text;
                            param2.Value = textBox2.Text;
                            param3.Value = textBox3.Text;
                            param4.Value = textBox4.Text;
                            param5.Value = textBox5.Text;
                            param6.Value = checkedListBox1.SelectedItem.ToString();
                            sqlite_cmd.Parameters.Add(param1);
                            sqlite_cmd.Parameters.Add(param2);
                            sqlite_cmd.Parameters.Add(param3);
                            sqlite_cmd.Parameters.Add(param4);
                            sqlite_cmd.Parameters.Add(param5);
                            sqlite_cmd.Parameters.Add(param6);
                            sqlite_cmd.ExecuteNonQuery();
                            MessageBox.Show("Intrebarea a fost adaugata cu succes!");
                            sqlite_conn.Close();
                            textBox1.Clear();
                            textBox2.Clear();
                            textBox3.Clear();
                            textBox4.Clear();
                            textBox5.Clear();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }

                    if (decizie == "mate")
                    {
                        try
                        {
                            SQLiteConnection sqlite_conn;
                            SQLiteCommand sqlite_cmd;
                            sqlite_conn = new SQLiteConnection("Data Source=Intrebari_mate.db;Version=3;New=False;Compress=True;");
                            sqlite_conn.Open();
                            sqlite_cmd = sqlite_conn.CreateCommand();
                            sqlite_cmd.CommandText = "INSERT INTO intrebari_mate(text, var1, var2, var3, varcorecta, cap_parental) " +
                                                                      "Values('" + this.textBox1.Text + "', '" + this.textBox2.Text + "', '" + this.textBox3.Text + "', '" + this.textBox4.Text + "', '" + this.textBox5.Text + "', '" + checkedListBox1.SelectedItem.ToString() + "');";
                            sqlite_cmd.ExecuteNonQuery();
                            MessageBox.Show("Intrebarea a fost adaugata cu succes!");
                            sqlite_conn.Close();
                            textBox1.Clear();
                            textBox2.Clear();
                            textBox3.Clear();
                            textBox4.Clear();
                            textBox5.Clear();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }

                    if (decizie == "bio")
                    {
                        try
                        {
                            SQLiteConnection sqlite_conn;
                            SQLiteCommand sqlite_cmd;
                            sqlite_conn = new SQLiteConnection("Data Source=Intrebari_bio.db;Version=3;New=False;Compress=True;");
                            sqlite_conn.Open();
                            sqlite_cmd = sqlite_conn.CreateCommand();
                            sqlite_cmd.CommandText = "INSERT INTO intrebari_bio(text, var1, var2, var3, varcorecta, cap_parental) " +
                                                                      "Values('" + this.textBox1.Text + "', '" + this.textBox2.Text + "', '" + this.textBox3.Text + "', '" + this.textBox4.Text + "', '" + this.textBox5.Text + "', '" + checkedListBox1.SelectedItem.ToString() + "');";
                            sqlite_cmd.ExecuteNonQuery();
                            MessageBox.Show("Intrebarea a fost adaugata cu succes!");
                            sqlite_conn.Close();
                            textBox1.Clear();
                            textBox2.Clear();
                            textBox3.Clear();
                            textBox4.Clear();
                            textBox5.Clear();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }

                }
                else
                    MessageBox.Show("Raspunsul corect nu se potriveste cu variantele de raspuns!");

            }
            else
                MessageBox.Show("Trebuie sa completati toate campurile!");
        }
Esempio n. 16
0
        private void delete_Click(object sender, EventArgs e)
        {
            if(checkBox1.Checked == true)
            {
                if (decizie == "info")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Capitole.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "delete from capitole where titlu = @titlu_capitol";
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_capitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if (decizie == "mate")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Capitole_mate.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "delete from capitole_mate where titlu = @titlu_capitol";
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_capitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if(decizie == "bio")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Capitole_bio.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = "delete from capitole_bio where titlu = @titlu_capitol";
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_capitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

            }
            else
            {
                if(decizie == "info")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = ("delete from subcapitole where nume_subcapitol = @titlu_subcapitol");
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_subcapitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if(decizie == "mate")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole_mate.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = ("delete from subcapitole_mate where nume_subcapitol = @titlu_subcapitol");
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_subcapitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                if(decizie == "bio")
                {
                    try
                    {
                        SQLiteConnection sqlite_conn;
                        SQLiteCommand sqlite_cmd;
                        sqlite_conn = new SQLiteConnection("Data Source=Subcapitole_bio.db;Version=3;New=False;Compress=True;");
                        sqlite_conn.Open();
                        sqlite_cmd = sqlite_conn.CreateCommand();
                        sqlite_cmd.CommandText = ("delete from subcapitole_bio where nume_subcapitol = @titlu_subcapitol");
                        SQLiteParameter parameter = new SQLiteParameter("@titlu_subcapitol", DbType.String);
                        parameter.Value = textBox1.Text;
                        sqlite_cmd.Parameters.Add(parameter);
                        sqlite_cmd.ExecuteNonQuery();
                        MessageBox.Show("Lectia a fost stearsa cu succes!");
                        sqlite_conn.Close();
                        textBox1.Clear();
                        richTextBox1.Clear();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

            }
        }