コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;
            SQLiteDataReader sqlite_datareader;

            if (!File.Exists("ReceptionistLogin.db"))
            {
                sqlite_conn = new SQLiteConnection("Data Source=ReceptionistLogin.db;Version=3;New=True;Compress=True;");

                sqlite_conn.Open();

                sqlite_cmd = sqlite_conn.CreateCommand();


                sqlite_cmd.CommandText = "CREATE TABLE Login (Username varchar2 (100) NOT NULL UNIQUE, Password varchar2 (100));";
                sqlite_cmd.ExecuteNonQuery();


                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('aqibahmed60', 'abcabc');";
                sqlite_cmd.ExecuteNonQuery();

                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('ossaidahmed', '1234');";
                sqlite_cmd.ExecuteNonQuery();

                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('HafizHarisAlam', 'otaku');";
                sqlite_cmd.ExecuteNonQuery();


                sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******'and Password='******'";
                sqlite_datareader      = sqlite_cmd.ExecuteReader();

                Receptionists R10 = new Receptionists();
                R10.SetData(textBox1.Text, textBox2.Text);

                if (sqlite_datareader.Read())
                {
                    sqlite_conn.Close();
                    Billing_DB();
                    this.Hide();
                    Receptionist R1 = new Receptionist();
                    R1.ShowDialog();

                    LoginForm L1 = new LoginForm();
                    L1.ShowDialog();
                }

                else
                {
                    MessageBox.Show("Invalid Login", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox1.Clear();
                    textBox2.Clear();
                }

                sqlite_conn.Close();
            }


            else
            {
                sqlite_conn = new SQLiteConnection("Data Source=ReceptionistLogin.db;Version=3;Compress=True;");
                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();

                sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******'and Password='******'";

                Receptionists R10 = new Receptionists();
                R10.SetData(textBox1.Text, textBox2.Text);


                sqlite_datareader = sqlite_cmd.ExecuteReader();
                if (sqlite_datareader.Read())
                {
                    this.Hide();
                    sqlite_conn.Close();
                    Receptionist R1 = new Receptionist();
                    R1.ShowDialog();

                    LoginForm L1 = new LoginForm();
                    L1.ShowDialog();
                }

                else
                {
                    MessageBox.Show("Invalid Login", "Login Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox1.Clear();
                    textBox2.Clear();
                }


                sqlite_conn.Close();
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // We use these three SQLite objects:

            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;
            SQLiteDataReader sqlite_datareader;

            if (!File.Exists("Login.db"))
            {
                // create a new database connection:
                sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;New=True;Compress=True;");

                // open the connection
                sqlite_conn.Open();

                // create a new SQL command:
                sqlite_cmd = sqlite_conn.CreateCommand();

                // Let the SQLiteCommand object know our SQL-Query:
                sqlite_cmd.CommandText = "CREATE TABLE Login (Username varchar2 (100), Password varchar2 (100));";


                // Now lets execute the SQL ;D
                sqlite_cmd.ExecuteNonQuery();

                // Lets insert something into our new table:
                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('aqibahmed60', 'abcabc');";

                // And execute this again ;D
                sqlite_cmd.ExecuteNonQuery();

                // ...and inserting another line:
                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('ossaidahmed', '1234');";

                // And execute this again ;D
                sqlite_cmd.ExecuteNonQuery();

                // ...and inserting another line:
                sqlite_cmd.CommandText = "INSERT INTO Login (Username,Password) VALUES ('HafizHarisAlam', 'otaku');";

                // And execute this again ;D
                sqlite_cmd.ExecuteNonQuery();

                // But how do we read something out of our table ?
                // First lets build a SQL-Query again:
                sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******'and Password='******'";

                Administator A1 = new Administator();

                A1.SetData(textBox1.Text, textBox2.Text);

                // Now the SQLiteCommand object can give us a DataReader-Object:
                sqlite_datareader = sqlite_cmd.ExecuteReader();


                // The SQLiteDataReader allows us to run through the result lines:
                if (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
                {
                    sqlite_conn.Close();
                    Employee_DB();
                    Product_DB();
                    Package_DB();
                    Total_Cost_DB();
                    Make_Up_DB();
                    Cutting_DB();
                    Nail_Art_DB();
                    this.Hide();
                    MainForm m1 = new MainForm();
                    m1.ShowDialog();

                    LoginForm L1 = new LoginForm();
                    L1.ShowDialog();
                }

                else
                {
                    MessageBox.Show("Invalid Login", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox1.Clear();
                    textBox2.Clear();
                }

                // We are ready, now lets cleanup and close our connection:
                sqlite_conn.Close();
            }


            else
            {
                sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;");
                sqlite_conn.Open();
                sqlite_cmd = sqlite_conn.CreateCommand();

                // But how do we read something out of our table ?
                // First lets build a SQL-Query again:
                sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******'and Password='******'";
                Administator A1 = new Administator();

                A1.SetData(textBox1.Text, textBox2.Text);
                // Now the SQLiteCommand object can give us a DataReader-Object:
                sqlite_datareader = sqlite_cmd.ExecuteReader();

                // The SQLiteDataReader allows us to run through the result lines:
                if (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
                {
                    this.Hide();
                    sqlite_conn.Close();
                    MainForm m1 = new MainForm();
                    m1.ShowDialog();

                    LoginForm L1 = new LoginForm();
                    L1.ShowDialog();
                }

                else
                {
                    MessageBox.Show("Invalid Login", "Login Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    textBox1.Clear();
                    textBox2.Clear();
                }

                sqlite_conn.Close();
                // We are ready, now lets cleanup and close our connection
            }
        }