private void button1_Click(object sender, EventArgs e) { Administator A1 = new Administator(); SQLiteConnection sqlite_conn; SQLiteConnection sqlite_conn1; SQLiteCommand sqlite_cmd; SQLiteCommand sqlite_cmd1; SQLiteDataReader sqlite_datareader; //SQLiteDataReader sqlite_datareader1; sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "select * from Login where Password ='******'"; sqlite_datareader = sqlite_cmd.ExecuteReader(); if (sqlite_datareader.Read()) { string a1 = sqlite_datareader.GetString(0); sqlite_conn.Close(); sqlite_conn1 = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn1.Open(); sqlite_cmd1 = sqlite_conn1.CreateCommand(); sqlite_cmd1.CommandText = "Update Login SET Password='******' where Password='******'"; sqlite_cmd1.ExecuteNonQuery(); A1.SetData(a1, textBox3.Text); sqlite_conn1.Close(); MessageBox.Show("Password Update"); textBox3.Clear(); textBox4.Clear(); } else { sqlite_conn.Close(); MessageBox.Show("Can't Update Password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox3.Clear(); textBox4.Clear(); } }
private void button4_Click(object sender, EventArgs e) { var result = MessageBox.Show("Do you want to delete your account ? After pressing yes you will be logout from account and your account will be remove!", "Delete Account", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { Administator A1 = new Administator(); SQLiteConnection sqlite_conn; SQLiteCommand sqlite_cmd; SQLiteDataReader sqlite_dataread; SQLiteConnection sqlite_conn1; SQLiteCommand sqlite_cmd1; sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "Select * from Login where Username='******' and Password='******'"; sqlite_dataread = sqlite_cmd.ExecuteReader(); if (sqlite_dataread.Read()) { sqlite_conn.Close(); sqlite_conn1 = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn1.Open(); sqlite_cmd1 = sqlite_conn1.CreateCommand(); sqlite_cmd1.CommandText = "Delete from Login where Username='******' and Password='******'"; sqlite_cmd1.ExecuteNonQuery(); sqlite_conn1.Close(); i = 1; this.Hide(); this.Close(); } else { i = 0; sqlite_conn.Close(); MessageBox.Show("Username and Password is incorrect!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
public void display_Data() { //SQLiteConnection sqlite_conn; //SQLiteCommand sqlite_cmd; //SQLiteDataReader sqlite_datareader; Administator A2 = new Administator(); using (SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;")) { sqlite_conn.Open(); using (SQLiteCommand sqlite_cmd = new SQLiteCommand("SELECT Username FROM Login where Username='******' and Password='******'", sqlite_conn)) { sqlite_cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); SQLiteDataAdapter da = new SQLiteDataAdapter(sqlite_cmd); da.Fill(dt); dataGridView1.DataSource = dt; sqlite_conn.Close(); } } //sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******'and Password='******'"; //sqlite_cmd.CommandText = "SELECT * FROM Login where Username='******' and Password='******'"; // sqlite_cmd.ExecuteNonQuery(); //DataTable dt = new DataTable(); //SQLiteDataAdapter da = new SQLiteDataAdapter(sqlite_cmd); //da.Fill(dt); //dataGridView1.DataSource = dt; }
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 } }
private void button2_Click(object sender, EventArgs e) { Administator A1 = new Administator(); if (string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox5.Text)) { MessageBox.Show("Please fill the missing field !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { SQLiteConnection sqlite_conn; SQLiteCommand sqlite_cmd; SQLiteDataReader sqlite_dataread; SQLiteConnection sqlite_conn1; SQLiteCommand sqlite_cmd1; SQLiteDataReader sqlite_dataread1; SQLiteConnection sqlite_conn2; SQLiteCommand sqlite_cmd2; sqlite_conn = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); sqlite_cmd.CommandText = "Select * from Login where Username='******' and Password='******'"; sqlite_dataread = sqlite_cmd.ExecuteReader(); if (sqlite_dataread.Read()) { sqlite_conn.Close(); sqlite_conn1 = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn1.Open(); sqlite_cmd1 = sqlite_conn1.CreateCommand(); sqlite_cmd1.CommandText = "select * from Login where Username='******'"; //UserName Verification sqlite_dataread1 = sqlite_cmd1.ExecuteReader(); if (!sqlite_dataread1.Read()) { sqlite_conn1.Close(); sqlite_conn2 = new SQLiteConnection("Data Source=Login.db;Version=3;Compress=True;"); sqlite_conn2.Open(); sqlite_cmd2 = sqlite_conn2.CreateCommand(); sqlite_cmd2.CommandText = "Update Login set Username='******' where Username='******' and Password='******'"; sqlite_cmd2.ExecuteNonQuery(); sqlite_conn2.Close(); A1.SetData(textBox2.Text, textBox5.Text); display_Data(); MessageBox.Show("Username Update", "UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox2.Clear(); textBox5.Clear(); } else { sqlite_conn1.Close(); MessageBox.Show("Username can not be Update", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox2.Clear(); textBox5.Clear(); } /*sqlite_cmd1.CommandText = "Update Login set Username='******' where Username='******' and Password='******'"; * sqlite_cmd1.ExecuteNonQuery(); * sqlite_conn1.Close(); */ } else { sqlite_conn.Close(); MessageBox.Show("Invalid Password ! Username can not be update", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBox2.Clear(); textBox5.Clear(); } } }