private void btnSubmit_Click(object sender, EventArgs e) { try { if (txtFullName.Text == "" || txtNameWithInitial.Text == "" || txtAddress.Text == "" || dateTimePicker1.Text == "" || txtMobile.Text == "" || dateTimePicker2.Text == "" || comboBox1.Text == "" || txtUserName.Text == "" || txtPassword.Text == "") { MessageBox.Show("Fill All Required Field"); } else { //dp MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imgArr = new byte[ms.Length]; string admin = ""; string gender = ""; string password = txtPassword.Text; passwordHashing pass = new passwordHashing(); if (checkBox1.Checked) { admin = "T"; } if (radMale.Checked) { gender = "Male"; } if (radFemale.Checked) { gender = "Female"; } string subject = comboBox1.SelectedItem.ToString(); SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\Muhammad Salman\source\repos\SchoolManagementSystem-master\Final\SchoolManagementSystem\SchoolManagementSystem\SchoolManagementSystem.mdf;Integrated Security=True;Connect Timeout=30"); con.Open(); string str = "INSERT INTO Academic(full_name,initial,dob,gender,address,mobile,email,doe,subject,user_name,password,is_admin,dp) VALUES('" + txtFullName.Text + "','" + txtNameWithInitial.Text + "','" + dateTimePicker1.Text + "','" + gender + "','" + txtAddress.Text + "','" + txtMobile.Text + "','" + txtEmail.Text + "','" + dateTimePicker2.Text + "','" + subject + "','" + txtUserName.Text + "','" + pass.encodePassword(password) + "','" + admin + "','" + imgArr + "')"; SqlCommand cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); string str1 = "SELECT TOP(1) ac_id FROM Academic ORDER BY 1 DESC"; SqlCommand cmd1 = new SqlCommand(str1, con); SqlDataReader read = cmd1.ExecuteReader(); read.Read(); string id = read["ac_id"].ToString(); MessageBox.Show("" + txtNameWithInitial.Text + "'s Data Added " + "Your Index number is " + id); read.Close(); con.Close(); } } catch (SqlException ex) { MessageBox.Show(ex.Message); } }
private void btnLogin_Click(object sender, EventArgs e) { passwordHashing pass = new passwordHashing(); try { if (txtUserName.Text == "" || txtPassword.Text == "") { MessageBox.Show("Please Enter User Name and Password"); } else { SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\AdeeSL\c#\SMS\SchoolManagementSystem\SchoolManagementSystem\SchoolManagementSystem.mdf;Integrated Security=True;Connect Timeout=30"); con.Open(); string str = "SELECT ac_id FROM Academic WHERE user_name='" + txtUserName.Text + "' and password='******' UNION SELECT nac_id FROM NonAcademic WHERE user_name='" + txtUserName.Text + "' and password='******' "; SqlCommand cmd = new SqlCommand(str, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { Home h1 = new Home(); h1.Show(); this.Hide(); } else { MessageBox.Show("Invalide User Name or Password"); } } } catch (SqlException ex) { MessageBox.Show(ex.Message); } }
private void btnSubmit_Click(object sender, EventArgs e) { try { if (txtFullName.Text == "" || txtNameWithInitial.Text == "" || txtAddress.Text == "" || dateTimePicker1.Text == "" || txtMobile.Text == "" || dateTimePicker2.Text == "" || comboBox1.Text == "" || (txtPassword.Visible == true && txtPassword.Text == "") || (txtUserName.Visible == true && txtUserName.Text == "")) { MessageBox.Show("Fill All Required Field"); } else { string admin = ""; string gender = ""; string password = txtPassword.Text; passwordHashing pass = new passwordHashing(); if (radMale.Checked) { gender = "Male"; } if (radFemale.Checked) { gender = "Female"; } if (checkBox1.Checked) { admin = "T"; } string job = comboBox1.SelectedItem.ToString(); SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\AdeeSL\c#\SMS\SchoolManagementSystem\SchoolManagementSystem\SchoolManagementSystem.mdf;Integrated Security=True;Connect Timeout=30"); con.Open(); string str = "INSERT INTO NonAcademic(full_name,initial,dob,gender,address,mobile,email,doe,subject,user_name,password,is_admin) VALUES('" + txtFullName.Text + "','" + txtNameWithInitial.Text + "','" + dateTimePicker1.Text + "','" + gender + "','" + txtAddress.Text + "','" + txtMobile.Text + "','" + txtEmail.Text + "','" + dateTimePicker2.Text + "','" + job + "','" + txtUserName.Text + "','" + pass.encodePassword(password) + "','" + admin + "')"; SqlCommand cmd = new SqlCommand(str, con); cmd.ExecuteNonQuery(); string str1 = "SELECT TOP(1) nac_id FROM NonAcademic ORDER BY 1 DESC"; SqlCommand cmd1 = new SqlCommand(str1, con); SqlDataReader read = cmd1.ExecuteReader(); read.Read(); string id = read["nac_id"].ToString(); MessageBox.Show("" + txtNameWithInitial.Text + "'s Data Added " + "Your Index number is " + id); read.Close(); con.Close(); } } catch (SqlException ex) { MessageBox.Show(ex.Message); } }