private void button1_Click(object sender, EventArgs e) { DataTable dt = log.Login(this.textBox1.Text, this.textBox2.Text); if (dt.Rows.Count > 0) { this.id = this.textBox1.Text; this.passowrd = this.textBox2.Text; permission = dt.Rows[0][3].ToString(); perm = Int32.Parse(permission); if (perm == 2) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenPageAdmin); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 4) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenSecretary); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 5) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenLect); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 6) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenDirect); th.SetApartmentState(ApartmentState.STA); th.Start(); } } else { MessageBox.Show("Login Failed"); } }
private void button1_Click(object sender, EventArgs e) { DataTable dt = log.Login(this.textBox1.Text, this.textBox2.Text); if (dt.Rows.Count > 0) { this.id = this.textBox1.Text; this.passowrd = this.textBox2.Text; permission = dt.Rows[0][3].ToString(); perm = Int32.Parse(permission); //Globals.LoggedUser.setName(name); Globals.LoggedUser.setPerm(permission); Globals.LoggedUser.setId(id); Globals.LoggedUser.setPwd(this.passowrd); //Branch B String query = "select * from Login where Id = '" + this.id.ToString() + "'and Password = '******'"; StringBuilder sb = new StringBuilder(); using (SqlCommand q = new SqlCommand(query, Globals.conn)) { using (SqlDataReader dr = q.ExecuteReader()) { if (!dr.HasRows) { //MessageBox.Show("No Such this username or password!", "ERROR", MessageBoxButtons.OK); return; } while (dr.Read()) { //getting the information from database. permission = dr[3].ToString(); //getting the field of User : Student/Admin/.. id = dr[0].ToString(); name = dr[1].ToString(); //Student Fields Email = dr[5].ToString(); Semester = dr[6].ToString(); Address = dr[7].ToString(); /////////////////////////////////// //Updating the Instance fields. Globals.LoggedUser.setName(name); Globals.LoggedUser.setPerm(permission); Globals.LoggedUser.setId(id); Globals.LoggedUser.setPwd(this.passowrd); ////////////////////////////////// } } } if (perm == 0) { //Globals.LoggedUser = new User(); Globals.LoggedUser = new Classes.Student(Globals.LoggedUser); Globals.LoggedUser.setName(name); Globals.LoggedUser.setPerm(permission); Globals.LoggedUser.setId(id); Globals.LoggedUser.setPwd(this.passowrd); //Student fields (Globals.LoggedUser as Classes.Student).setAddress(Address); (Globals.LoggedUser as Classes.Student).setSemester(Semester); (Globals.LoggedUser as Classes.Student).setMail(Email); ////////////////................/////////////////// ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenStudentPortal); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 1) { //BranchB Globals.GlobalSecretary.setName(name); Globals.GlobalSecretary.setPerm(permission); Globals.GlobalSecretary.setId(id); Globals.GlobalSecretary.setPwd(this.passowrd); ///// ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenSecretaryPortal); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 2) { //BranchB Globals.GlobalAdmin.setName(name); Globals.GlobalAdmin.setPerm(permission); Globals.GlobalAdmin.setId(id); Globals.GlobalAdmin.setPwd(this.passowrd); // ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenPageAdmin); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 3) { //BranchB Tech Globals.GlobalTechnican.setName(name); Globals.GlobalTechnican.setPerm(permission); Globals.GlobalTechnican.setId(id); Globals.GlobalTechnican.setPwd(this.passowrd); // ((Form)this.TopLevelControl).Close(); Thread th = new Thread(GoTechnical); th.SetApartmentState(ApartmentState.STA); th.Start(); } //if (perm == 4) //{ // ((Form)this.TopLevelControl).Close(); // Thread th = new Thread(OpenSecretary); // th.SetApartmentState(ApartmentState.STA); // th.Start(); //} if (perm == 5) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenLect); th.SetApartmentState(ApartmentState.STA); th.Start(); } if (perm == 6) { ((Form)this.TopLevelControl).Close(); Thread th = new Thread(OpenDirect); th.SetApartmentState(ApartmentState.STA); th.Start(); } } else { MessageBox.Show("Login Failed", "login page", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } }