Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Archiwum\\Archiwum.sqlite");



            SQLiteConnection con = new SQLiteConnection("Data Source='" + path + "';Version=3;");
            try
            {
                con.Open();
                sql = "Select * from Uzytkownicy where Nazwa='" + comboBox1.SelectedValue + "'and Uzytkownik='" + textBox1.Text + "'and Haslo='" + textBox2.Text + "'";
                SQLiteCommand cmd = new SQLiteCommand(sql, con);
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader.HasRows)
                    {
                        y = true;
                    }
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                con.Close();
            }
            if (y != true)
            {
                MessageBox.Show("Podałeś złe dane logowania");
                textBox1.Text = string.Empty;
                textBox1.BackColor = Color.Yellow;
                textBox2.Focus();
                textBox2.Text = string.Empty;

            }
            else
            {
                con = new SQLiteConnection("Data Source='" + path + "';Version=3;");
                try
                {
                    con.Open();
                    sql = "Delete from Zalogowany";
                    SQLiteCommand cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Insert into Zalogowany (Nazwa,Uzytkownik,Haslo) Values ('" + comboBox1.SelectedValue + "','" + textBox1.Text + "','" + textBox2.Text + "')";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    con.Close();
                }
                this.Visible = false;
                Form5 form5 = new Form5();

                form5.ShowDialog();


                Form6 form6 = new Form6();
                form6.Close();

            }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            path   = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Archiwum\\Archiwum.sqlite");
            folder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Archiwum");
            SQLiteConnection con;

            filePath = @"c:\users\empla\documents\visual studio 2013\Projects\Moja_Ksiegowosc\Moja_Ksiegowosc\Resources\SQLite_icon.ico";

            Directory.CreateDirectory(folder);

            zmiana_ikony(folder + @"\", filePath, "Archiwum");
            if (!System.IO.File.Exists(path))
            {
                SQLiteConnection.CreateFile(path);
            }

            if (checkBox1.Checked == false)
            {
                if (textBox1.Text == string.Empty)
                {
                    MessageBox.Show("Podaj Identyfikator firmy");
                    textBox1.Focus();
                    textBox1.BackColor = Color.Yellow;
                    return;
                }
                identyfikator = textBox1.Text.Split();

                if (identyfikator.Count() > 1)
                {
                    MessageBox.Show("Musisz podać identyfikator firmy bez znaku spacji");
                    textBox1.Focus();
                    textBox1.Text      = string.Empty;
                    textBox1.BackColor = Color.Yellow;
                    return;
                }



                if (textBox2.Text == string.Empty)
                {
                    MessageBox.Show("Podaj nazwę użytkownika");
                    textBox2.Focus();
                    textBox2.BackColor = Color.Yellow;
                    return;
                }
                if (textBox3.Text == string.Empty)
                {
                    MessageBox.Show("Podaj hasło");
                    textBox3.Focus();
                    textBox3.BackColor = Color.Yellow;
                    return;
                }


                con = new SQLiteConnection("Data Source ='" + path + "';Version=3;");
                try
                {
                    con.Open();
                    sql = "Create table if not exists Uzytkownicy (Nazwa varchar(20),Uzytkownik varchar(20),Haslo varchar(20),Sciezka varchar (20))";
                    SQLiteCommand cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Select * from Uzytkownicy where Nazwa='" + textBox1.Text + "'";
                    cmd = new SQLiteCommand(sql, con);
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (textBox1.Text == reader["Nazwa"].ToString())
                        {
                            textBox1.Text = string.Empty;
                            textBox1.Focus();
                            textBox1.BackColor = Color.Yellow;
                            MessageBox.Show("Podałeś istniejący identyfikator firmy podaj inny");
                            reader.Close();
                            return;
                        }
                    }
                    sql = "Insert into Uzytkownicy (Nazwa,Uzytkownik,Haslo,Sciezka) Values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + path + "')";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Create table if not exists Zalogowany (Nazwa varchar(20),Uzytkownik varchar(20),Haslo varchar(20))";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Delete from Zalogowany";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Insert into Zalogowany(Nazwa ,Uzytkownik,Haslo) Values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    con.Close();
                }



                this.Visible = false;
                Form3 form3 = new Form3();
                rozpoczecie       = true;
                form3.rozpoczecie = rozpoczecie;
                form3.ShowDialog();
                this.Close();
            }
            else
            {
                if (textBox2.Text == string.Empty)
                {
                    MessageBox.Show("Podaj Nazwe użytkownika");
                    textBox2.Focus();
                    textBox2.BackColor = Color.Yellow;
                    return;
                }
                if (textBox3.Text == string.Empty)
                {
                    MessageBox.Show("Podaj Hasło");
                    textBox3.Focus();
                    textBox3.BackColor = Color.Yellow;
                    return;
                }
                if (!System.IO.File.Exists(path))
                {
                    SQLiteConnection.CreateFile(path);
                }
                con = new SQLiteConnection("Data Source='" + path + "';Version=3;");
                try
                {
                    con.Open();
                    sql = "Create table if not exists Uzytkownicy (Nazwa varchar(20),Uzytkownik varchar(20),Haslo varchar(20),Sciezka varchar (20))";
                    SQLiteCommand cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Create table if not exists Zalogowany (Nazwa varchar(20),Uzytkownik varchar(20),Haslo varchar(20))";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Select * from Uzytkownicy where Nazwa ='" + comboBox2.SelectedValue + "'";
                    cmd = new SQLiteCommand(sql, con);
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            MessageBox.Show("Wybrałeś firme o takim samym identyfikatorze podaj inny identyfikator");
                            return;
                        }
                    }

                    sql = "Delete from Zalogowany";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                    sql = "Insert into Zalogowany(Nazwa ,Uzytkownik,Haslo) Values ('" + comboBox2.SelectedValue + "','" + textBox2.Text + "','" + textBox3.Text + "')";
                    cmd = new SQLiteCommand(sql, con);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    con.Close();
                }



                con = new SQLiteConnection("Data Source='" + openFileDialog1.FileName + "';Version=3;");
                try
                {
                    con.Open();
                    sql = "Select * from Uzytkownicy where Nazwa='" + comboBox2.SelectedValue + "'and Uzytkownik='" + textBox2.Text + "'and Haslo='" + textBox3.Text + "'";
                    SQLiteCommand    cmd    = new SQLiteCommand(sql, con);
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            y = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    con.Close();
                }
                if (y == false)
                {
                    MessageBox.Show("Podałeś nieprawidłowe dane logowanie");
                    textBox2.Text = string.Empty;
                    textBox3.Text = string.Empty;
                    textBox2.Focus();
                    textBox2.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    con = new SQLiteConnection("Data Source ='" + path + "';Version=3;");
                    try
                    {
                        con.Open();
                        sql = "Insert into Uzytkownicy(Nazwa,Uzytkownik,Haslo,Sciezka) values ('" + comboBox2.SelectedValue + "','" + textBox2.Text + "','" + textBox3.Text + "','" + openFileDialog1.FileName + "')";
                        SQLiteCommand cmd = new SQLiteCommand(sql, con);
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        con.Close();
                    }



                    Form5 form5 = new Form5();
                    form5.Show();
                    Close();
                }
            }
        }