Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Login Class

C#
private void loginButton_Click(object sender, EventArgs e)
        {
            username = userNameTextBox.Text;
            password = passwordTextBox.Text;
            role = roleSelectionComboBox.Text;
            if(username == "" || password == "" || role =="")
            {
                MessageBox.Show("Please fill all");
            }
            else
            {
                dbcon.Connection();
                query = "Login";
                com = new SqlCommand(query,dbcon.con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@useName", username);
                com.Parameters.AddWithValue("@pass", password);
                int userCount = (Int32)com.ExecuteScalar();
                if(userCount == 1)
                {
                    this.Hide();
                    Dashboard adminDashboard = new Dashboard();
                    Profile profileData = new Profile();
                    profileData.ProfileInfo(role);
                    adminDashboard.Show();
                }
                else 
                {
                    MessageBox.Show("count is 0");
                }
            }
        }


Dashboard


C#
public partial class Dashboard : Form
    {
        public string uname;
        public Dashboard()
        {
            Login LG = new Login();
            Profile pro = new Profile();
            uname = pro.ProfileInfo(LG.role);
            InitializeComponent();
        }

        

        private void Dashboard_Load(object sender, EventArgs e)
        {
            label1.Text = uname;
            //MessageBox.Show(profileInfo.UserName);
        }
    }


Profile.cs

C#
public class Profile
    {
        public string UserName{get; set;}
      //  public string ImageUrl { get; set; }
        public string ProfileInfo(string userName)
        {
            this.UserName = userName;
            return UserName;            
            //this.ImageUrl = imageUrl;
        }    
    }



Here comes my problem

Step1 : I am passing the value to profile.cs
C#
Profile profileData = new Profile();
        profileData.ProfileInfo(role);


Step2 : In Dashboard i want to display the name of the logged user as well all form related to that dashbaord do i am trying to use profileInfo function to do that.
step3: As a result when i am instantiating the class profile with out passing value i want to get details.

Thanks in advance.
If any one providing any useful link welcome.
Posted
Comments
[no name] 23-May-14 10:17am    
You need to pass the data between the forms. All you are doing here is creating new Profile objects to throw them away. See http://www.codeproject.com/search.aspx?q=pass+data&sbo=kw&x=0&y=0

1 solution

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900