Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2012, 08:36 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hidden form containing user data to be used by other forms

Hi, this is my first post here, and I am new to C# so it may be a stupid question. After a quick search I don't think it has been covered before, so apologies if it has.

I am writing a program that users will need to log in to, and I would like their userID and permissions code to be available for use in other forms.

At the moment I have this for when people try to log in:

Code:
private void loginUser()
        {
            SqlConnection con = new SqlConnection("Data Source=DOMAINSERVER;Initial Catalog=RightSortFulfilment;Integrated Security=True");
            con.Open();

            string checkUser = "SELECT * FROM Humanresources.EmployeeLogins WHERE UserName ='" + txtUser.Text + "'";
            SqlCommand cmd = new SqlCommand(checkUser, con);
            SqlDataReader drd = cmd.ExecuteReader();
            
            if (drd.HasRows)
            {
                while (drd.Read())
                {
                    if (drd["Password"].ToString() == txtPass.Text)
                    {
                        txtPermissions.Text = drd["Admin"].ToString();
                        txtUserID.Text = drd["EmployeeID"].ToString();

                        MainCompanyScreen companyScreen = new MainCompanyScreen();

                        companyScreen.Show();

                        /*Application.OpenForms[0].Show();
                        this.Hide();*/
                    }
                    else
                    {
                        MessageBox.Show("Password incorrect. Please try again.", "RightSort Fulfilment");
                        txtPass.ResetText();
                        txtPass.Focus();
                    }
                }
            }
            else
            {
                MessageBox.Show("Username does not exist. Please try again.", "RightSort Fulfilment");
                txtUser.ResetText();
                txtPass.ResetText();
                txtUser.Focus();
            }
            drd.Close();
            con.Close();
        }
and then I have this code on the next form to give users with Admin rights access to certain functions that normal users won't have:

Code:
private void MainCompanyScreen_Load(object sender, EventArgs e)
        {
            LoginScreen loginForm = new LoginScreen();

            if (loginForm.txtPermissions.ToString() == "1")
            {
                staffToolStripMenuItem.Visible = true;
                deleteCompanyToolStripMenuItem.Enabled = true;
                amendCompanyToolStripMenuItem.Enabled = true;
                newToolStripMenuItem.Enabled = true;
            }
            else
            {
                staffToolStripMenuItem.Visible = false;
                deleteCompanyToolStripMenuItem.Enabled = false;
                amendCompanyToolStripMenuItem.Enabled = false;
                newToolStripMenuItem.Enabled = false; 
            }
        }
This doesn't seem to want to work (this is similar to how I would have done this type of thing in Access/VBA in the past), so I was wondering if I was missing something very obvious or if I need to use a class or method instead.

Many thanks in advance for any help you can send my way!

EDIT: Just thought I should mention that the data filling the txtUserID and txtPermissions text boxes are set as integers in sql server, and that when I run the program and click to login it runs okay, but regardless of whether the Permissions number is 0 or 1 it still only runs the 'else' statement.

Last edited by keefa3011; April 17th, 2012 at 09:49 AM..
  #2 (permalink)  
Old April 27th, 2012, 06:34 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the end I wrote a new public class to take the values from the correct database table row and store them as public strings for use at later points in the program.

Just in case anyone else has a similar issue in the future :)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
email to send user data from contact form CheckBoxList tompatamcat ASP.NET 3.5 Basics 6 March 26th, 2013 12:11 AM
How do I Insert Hidden Data Form Fields? jpjamie BOOK: Beginning ASP.NET Web Pages with WebMatrix 5 January 5th, 2012 12:45 PM
Forms or a solution for end user data entry? Scott B SQL Server 2005 0 October 19th, 2007 04:21 AM
Show web user control hidden see07 ASP.NET 1.x and 2.0 Application Design 4 February 3rd, 2005 12:09 PM
Hidden form value johnjohn Classic ASP Databases 2 November 10th, 2004 01:00 PM



All times are GMT -4. The time now is 01:21 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.