private void pictureBox2_Click(object sender, EventArgs e) { String connect = @"Server=tcp:project-1.database.windows.net,1433;Initial Catalog=Data;Persist Security Info=False;User ID=Admin1;Password=Ad123456;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; SqlConnection con = new SqlConnection(connect); String query = "Select * from Login where id = '" + textBox1.Text.Trim() + "' and password = '******'"; SqlDataAdapter sda = new SqlDataAdapter(query, con); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count == 1) { if (dt.Rows[0][3].Equals("Student")) { SqlDataAdapter sda2 = new SqlDataAdapter("select * from Students where ID = '" + dt.Rows[0][0] + "'", con); DataTable dt2 = new DataTable(); sda2.Fill(dt2); Student student = new Student(dt2.Rows[0][1].ToString(), dt2.Rows[0][0].ToString(), dt.Rows[0][2].ToString(), dt2.Rows[0][2].ToString(), dt2.Rows[0][3].ToString(), (bool)dt2.Rows[0][4]); //first entrance of the student //need to change his initial password if (dt.Rows[0][0].Equals(dt.Rows[0][2]))//initial password equals ID { InitPassChange FM = new InitPassChange(); FM.RefToLastForm = this; this.Visible = false; FM.Show(); } //not the first entrence of the student else { if (!student.getStatus()) { MessageBox.Show("Your student's status is NOT active,\nplease go to 'Student's Accounts'"); } else { StudentMenu HA = new StudentMenu(student); HA.RefToMainMenu = this; this.Visible = false; HA.Show(); } } } else if (dt.Rows[0][3].Equals("Secretary")) { SqlDataAdapter sda2 = new SqlDataAdapter("select * from Secretary;", con); DataTable dt2 = new DataTable(); sda2.Fill(dt2); Secretary secretery = new Secretary(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt2.Rows[0][2].ToString()); SecretaryMenu HA = new SecretaryMenu(secretery); HA.RefToMainMenu = this; this.Visible = false; HA.Show(); } else if (dt.Rows[0][3].Equals("President")) { President president = new President(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString()); PresidentMenu HA = new PresidentMenu(president); HA.RefToMainMenu = this; this.Visible = false; HA.Show(); } else if (dt.Rows[0][3].Equals("HK")) { HouseKeeper houseKeeper = new HouseKeeper(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString()); HouseKeeperMenu HA = new HouseKeeperMenu(houseKeeper); HA.RefToMainMenu = this; this.Visible = false; HA.Show(); } else { MessageBox.Show("Unknown Permission"); } } else { MessageBox.Show("Please check your username and password"); } con.Close(); }
public static Form LogIn(String id, String pass) {/*login to system*/ DataTable t, dt = Program.get_dt("Select * from Login where Id='" + id + "' and Password='******'"); if (dt.Rows.Count != 0) { if (dt.Rows[0][3].Equals("HOD")) { HeadOfDepart_Main HA = new HeadOfDepart_Main(new CHeadOfDepartment(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt.Rows[0][4].ToString(), dt.Rows[0][3].ToString())); return(HA); } if (dt.Rows[0][3].Equals("TS")) { t = Program.get_dt("Select * from Teaching_Staff where Id='" + id + "'"); TeachingStaffMenu Ts = new TeachingStaffMenu(new CTeachingStaff(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt.Rows[0][4].ToString(), dt.Rows[0][3].ToString(), t.Rows[0][1].ToString(), t.Rows[0][2].ToString())); return(Ts); } if (dt.Rows[0][3].Equals("SEC")) { SecretaryFolder.Secretary_Menu Sec = new SecretaryFolder.Secretary_Menu(new CSecretary(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt.Rows[0][4].ToString(), dt.Rows[0][3].ToString())); return(Sec); } if (dt.Rows[0][3].Equals("ADS")) { Administration.Administration_main Es = new Administration.Administration_main(new CAdministration(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt.Rows[0][4].ToString(), dt.Rows[0][3].ToString())); return(Es); } //Branch B/// if (dt.Rows[0][3].Equals("Student")) { String conect = @"Server=tcp:project-1.database.windows.net,1433;Initial Catalog=Data;Persist Security Info=False;User ID=Admin1;Password=Ad123456;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; SqlConnection con = new SqlConnection(conect); SqlDataAdapter sda2 = new SqlDataAdapter("select * from Students where ID = '" + dt.Rows[0][0] + "'", con); DataTable dt2 = new DataTable(); sda2.Fill(dt2); Student student = new Student(dt2.Rows[0][1].ToString(), dt2.Rows[0][0].ToString(), dt.Rows[0][2].ToString(), dt2.Rows[0][2].ToString(), dt2.Rows[0][3].ToString(), (bool)dt2.Rows[0][4]); //first entrance of the student //need to change his initial password if (dt.Rows[0][0].Equals(dt.Rows[0][2]))//initial password equals ID { InitPassChange FM = new InitPassChange(); FM.RefToLastForm = new Login(); return(FM); } //not the first entrence of the student else { if (!student.getStatus()) { MessageBox.Show("Your student's status is NOT active,\nplease go to 'Student's Accounts'"); } else { StudentMenu HA = new StudentMenu(student); HA.RefToMainMenu = new Login(); return(HA); } } } if (dt.Rows[0][3].Equals("Secretary")) { String conect = @"Server=tcp:project-1.database.windows.net,1433;Initial Catalog=Data;Persist Security Info=False;User ID=Admin1;Password=Ad123456;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; SqlConnection con = new SqlConnection(conect); SqlDataAdapter sda2 = new SqlDataAdapter("select * from Secretary;", con); DataTable dt2 = new DataTable(); sda2.Fill(dt2); Secretary secretery = new Secretary(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString(), dt2.Rows[0][2].ToString()); SecretaryMenu HA = new SecretaryMenu(secretery); HA.RefToMainMenu = new Login(); return(HA); } if (dt.Rows[0][3].Equals("President")) { President president = new President(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString()); PresidentMenu HA = new PresidentMenu(president); HA.RefToMainMenu = new Login(); return(HA); } if (dt.Rows[0][3].Equals("HK")) { HouseKeeper houseKeeper = new HouseKeeper(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), dt.Rows[0][2].ToString()); HouseKeeperMenu HA = new HouseKeeperMenu(houseKeeper); HA.RefToMainMenu = new Login(); return(HA); } } return(new Login()); }