private void webBrowser_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e) { // IF IT NAVIGATE TO SUCCESS, GRAB THE TOKEN if (e.Url.ToString().Contains("#access_token=")) { responesUrl = e.Url.ToString(); int start_token = responesUrl.IndexOf("="); int end_token = responesUrl.IndexOf("&expires_in"); int len = end_token - start_token - 1; token = responesUrl.Substring(start_token + 1, len); this.webBrowser.Navigate("https://flexsurveys.com/wp-content/uploads/Employee-Survey-Successful.png"); this.user_fb_id = info(); DataTable dt = Program.get_dt("SELECT * FROM Login WHERE FB_id='" + this.user_fb_id + "'"); if (dt.Rows.Count == 0) { DialogResult dialogResult = MessageBox.Show("You must activate your acount with Facebook\n Activate now?", "Activate Facebook", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.ActivateFB(this.user_fb_id); f.Show(); } if (dialogResult == DialogResult.No) { this.webBrowser.Navigate(GetLogoutURL(token));//logout this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.Login(); f.Show(); } } else //chaking permission { if (dt.Rows[0][3].ToString().Equals("ADS"))//Aadmin { CAdministration User = 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()); this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.Administration.Administration_main(User); webBrowser.Navigate(GetLogoutURL(token));//logout f.Show(); } else if (dt.Rows[0][3].ToString().Equals("TS"))//Teaching stuff { DataTable dt2 = Program.get_dt("SELECT Type,Constraints FROM Teaching_staff WHERE id='" + dt.Rows[0][0].ToString() + "'"); CTeachingStaff User = 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(), dt2.Rows[0][0].ToString(), dt2.Rows[0][1].ToString()); this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.TeachingStaffMenu(User); webBrowser.Navigate(GetLogoutURL(token));//logout f.Show(); } else if (dt.Rows[0][3].ToString().Equals("SEC"))//Secratry { CSecretary User = 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()); this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.SecretaryFolder.Secretary_Menu(User); webBrowser.Navigate(GetLogoutURL(token));//logout f.Show(); } else if (dt.Rows[0][3].ToString().Equals("HOD"))//Head of department { CHeadOfDepartment User = 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()); this.Hide(); this.Closed += (s, args) => this.Close(); Form f = new BS_project2.HeadOfDepart_Main(User); webBrowser.Navigate(GetLogoutURL(token));//logout f.Show(); } else if (dt.Rows[0][3].ToString().Equals("Student"))//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;"; System.Data.SqlClient.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]); StudentMenu HA = new StudentMenu(student); HA.RefToMainMenu = new Login(); this.Hide(); this.Closed += (s, args) => this.Close(); webBrowser.Navigate(GetLogoutURL(token));//logout HA.Show(); } else if (dt.Rows[0][3].ToString().Equals("Secretary"))//secretary2 { 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(); this.Hide(); this.Closed += (s, args) => this.Close(); webBrowser.Navigate(GetLogoutURL(token));//logout HA.Show(); } else if (dt.Rows[0][3].ToString().Equals("HK"))//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(); this.Hide(); this.Closed += (s, args) => this.Close(); webBrowser.Navigate(GetLogoutURL(token));//logout HA.Show(); } else if (dt.Rows[0][3].ToString().Equals("President"))//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(); this.Hide(); this.Closed += (s, args) => this.Close(); webBrowser.Navigate(GetLogoutURL(token));//logout HA.Show(); } } } }
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()); }