Example #1
0
        public int login(Entities.EntityLogin obj)
        {
            sqlDataAccess da  = new sqlDataAccess();
            SqlCommand    cmd = da.GetCommand("select keyid,status from login where userid = '" + obj.Username + "'and password like '" + obj.Password + "'");

            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
            SqlDataAdapter DAdap = new SqlDataAdapter(cmd);
            DataTable      dt    = new DataTable();

            DAdap.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].Equals("st"))
                {
                    if (dt.Rows[0][1].Equals("active"))
                    {
                        cmd.Connection.Close();
                        return(1);//student and active
                    }
                    else
                    {
                        cmd.Connection.Close();
                        return(4); //inactive
                    }
                }
                else if (dt.Rows[0][0].Equals("fc"))
                {
                    if (dt.Rows[0][1].Equals("active"))
                    {
                        cmd.Connection.Close();
                        return(2);//faculty and active
                    }
                    else
                    {
                        cmd.Connection.Close();
                        return(4); //inactive
                    }
                }
                else if (dt.Rows[0][0].Equals("lb"))
                {
                    cmd.Connection.Close();
                    return(3);
                }
                else
                {
                    return(4);
                }
            }
            else
            {
                cmd.Connection.Close();
                return(0);
            }
        }
Example #2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            Entities.EntityLogin nlog = new Entities.EntityLogin();
            nlog.Username = userNameBox.Text;
            nlog.Password = passwordBox.Text;
            nlog.KeyId    = "st";
            nlog.Status   = "";
            DataAccess.LibraryInfo lib = new DataAccess.LibraryInfo(nlog.Username);
            int a = lib.login(nlog);

            if (a == 1)
            {
                //MessageBox.Show("Student");
                this.Hide();
                Student st = new Student(this.userNameBox.Text);
                st.Show();
            }
            if (a == 2)
            {
                //MessageBox.Show("faculty");
                this.Hide();
                Faculty fc = new Faculty(this.userNameBox.Text);
                fc.Show();
            }
            if (a == 3)
            {
                //MessageBox.Show("Librarian");
                this.Hide();
                Librarian lib1 = new Librarian(this.userNameBox.Text);
                lib1.Show();
            }
            if (a == 4)
            {
                MessageBox.Show("Inactive");
            }
            else if (a == 0)
            {
                MessageBox.Show("Username or Password Incorrect.");
            }
        }