private void button1_Click(object sender, EventArgs e) { Form_customer fc = new Form_customer(); fc.Show(); this.Hide(); }
private void button_sign_in_Click(object sender, EventArgs e) { string username = textBox1.Text; string password = textBox2.Text; if (username == "admin" && password == "123") { Admin admin = new Admin(); admin.Visible = true; this.Hide(); } try { string sql = "select * from Customer where C_Name ='" + textBox1.Text + "' "; SqlCommand cmd = new SqlCommand(sql, m_con); m_con.Open(); SqlDataReader dreader = cmd.ExecuteReader(); if (dreader.Read()) { if (dreader[5].ToString().Equals(textBox2.Text)) { USER_ID = dreader[0].ToString(); if (string.IsNullOrWhiteSpace(textBox1.Text)) { textBox1.Focus(); textBox1.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { textBox2.Focus(); textBox2.BackColor = System.Drawing.Color.LightPink; } else { Form_customer fc = new Form_customer(); fc.Show(); this.Hide(); textBox1.Clear(); textBox2.Clear(); } } } dreader.Close(); } catch (Exception ex) { MessageBox.Show("Error"); } finally { m_con.Close(); } try { string sql2 = "select * from Driver where D_Name ='" + textBox1.Text + "' "; SqlCommand cmd2 = new SqlCommand(sql2, m_con); m_con.Open(); SqlDataReader dreader2 = cmd2.ExecuteReader(); if (dreader2.Read()) { if (dreader2[3].ToString().Equals(textBox2.Text)) { USER_ID = dreader2[0].ToString(); Form_employee fe = new Form_employee(); fe.Show(); this.Hide(); textBox1.Clear(); textBox2.Clear(); } dreader2.Close(); if (string.IsNullOrWhiteSpace(textBox2.Text)) { textBox2.Focus(); textBox2.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { textBox2.Focus(); textBox2.BackColor = System.Drawing.Color.LightPink; } else { Form_employee fe = new Form_employee(); fe.Show(); this.Hide(); textBox1.Clear(); textBox2.Clear(); } } } catch (Exception ex) { MessageBox.Show("Error"); } finally { m_con.Close(); } }
private void button1_Click(object sender, EventArgs e) { //step 1 - create the sql connection SqlConnection con = new SqlConnection(); //step 2 - rightclick on database - properties - connection string (address of the database the path) con.ConnectionString = "Data Source=DESKTOP-MHS4TMT\\SQLEXPRESS;Initial Catalog=Ayubo_drive;Integrated Security=True"; //step 3 - Open the sql connection con.Open(); //step 4 - Define the sql command SqlCommand cmd = new SqlCommand(); //step 5 - set the sql connection object to the sql command cmd.Connection = con; //step 6 - Define the sql query type in the sql command cmd.CommandType = CommandType.Text; //step 7 - set the sql query to the sql command cmd.CommandText = "Insert Into customer(C_Name,C_Address,C_Email,C_Contact_No,C_Password)values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "')"; if (string.IsNullOrWhiteSpace(textBox1.Text)) { textBox1.Focus(); textBox1.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox2.Text)) { textBox2.Focus(); textBox2.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox3.Text)) { textBox3.Focus(); textBox3.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox4.Text)) { textBox4.Focus(); textBox4.BackColor = System.Drawing.Color.LightPink; } if (string.IsNullOrWhiteSpace(textBox5.Text)) { textBox5.Focus(); textBox5.BackColor = System.Drawing.Color.LightPink; } else { //step 10 - Display a successfull message MessageBox.Show("Successfully inserted values"); textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); Form_customer fc = new Form_customer(); fc.Show(); this.Hide(); } //step 8 - execute the sql command cmd.ExecuteReader(); //step 9 - close the sql connection con.Close(); }