Jump to content

C# MenuBar Issue

- - - - -

  • Please log in to reply
5 replies to this topic

#1
deb081900

deb081900

    Newbie

  • Members
  • Pip
  • 2 posts
Hi
I am using C# 2008 with Access 2007. I am using MDI on MDI a added a menu now that Menu have a Login MenuItem which is enable and other menu items are disabled at form load. Now I am try to implement this if login is successful then other menu items will be enabled automatically. I tried lots of technique but I can't able to access Menu Items from Login Form. What I tried here is the code - I just want to activate the deactivated menus after valid login and deactivate the login menu.


namespace EzBuddy

{

    public partial class UserLoginForm : Form

    {

        //public NewUser nuser1;

        private OleDbDataReader aReader;

        private OleDbCommand aCommand;

        private OleDbConnection aConnection;

        public int login_flag = 0;

        public UserLoginForm()

        {

            InitializeComponent();

        }

        public void menuEnable()

        {

           

        }

        public void login_code()

        {

            int x = LoginBox.TextLength;

            if (x < 5 || LoginBox.Text.Equals(""))

            {

                MessageBox.Show("ID is of minimum 5 digits as your Permanent Emplolee code or 9 digits as your Temporary Employee code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                LoginBox.Text = "";

                PasswordBox.Text = "";

                LoginBox.Focus();

            }

            try

            {

                database_Connection();

                aReader = aCommand.ExecuteReader();

               

                while (aReader.Read())

                {

                    if (aReader.GetString(0).Equals(LoginBox.Text) && aReader.GetString(1).Equals(PasswordBox.Text))

                    {

                         login_flag = 1;

                        break;

                    }

                    else

                    {

                        login_flag = 0;

                    }

                }

                if (login_flag == 1)

                {

                     

                    [B]MDIParentForm.loginToolStripMenuItem1.Enabled = false;

                    MDIParentForm.newToolStripMenuItem3.Enabled = true;

                    MDIParentForm.editToolStripMenuItem3.Enabled = true;

                    MDIParentForm.deleteToolStripMenuItem3.Enabled = true;

                    MDIParentForm.

                    MDIParentForm.searchToolStripMenuItem1.Enabled = true;

                    MDIParentForm.reportsToolStripMenuItem1.Enabled = true;

                    MDIParentForm.utilitiesToolStripMenuItem.Enabled =true;

[/B]

                    this.Dispose();

                }

                else

                {

                    LoginBox.Text = "";

                    PasswordBox.Text = "";

                    LoginBox.Focus();

                    loginMessage.Visible = true;

                    aReader.Close();

                    aConnection.Close();

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine("Error: {0}", ex.Message);

            }

            finally

            {

                aReader.Close();

                aConnection.Close();

            }

        }

        private void database_Connection()

        {

            try

            {

                aConnection.Open();

                Console.WriteLine("This is the returned data from Login table");

            }

            catch (OleDbException e)

            {

                Console.WriteLine("Error: {0}", e.Errors[0].Message);

            }

        }

        private void UserLoginForm_Load(object sender, EventArgs e)

        {

            aConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\KVSoftware\\KVStudent\\KV1StudentInformation.mdb");

            aCommand = new OleDbCommand("select * from Login", aConnection);

        }

        private void LoginButton_Click(object sender, EventArgs e)

        {

            login_code();

        }

    }

}




#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Ok well I assume you declare the MDIParentForm form somewhere right? Like:
Form1 MDIParentForm = new Form1(); 
If you do then goto the menuStrip(no such thing as menuBar ;) ) and in every menuItem of the menuStrip you need access to, change the property of modifier from "private" to "Public", that should do it for you. Also i think the link in my signature may help you.

EDIT: Heres the Link: C#, Working With Information Across Forms.

Good luck ~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
deb081900

deb081900

    Newbie

  • Members
  • Pip
  • 2 posts
Tnax for your consideration. I already changed the modifier property to public still I am getting error -
"Error 1 'EzBuddy.MDIParentForm' does not contain a definition for 'loginToolStripMenuItem1' C:\Documents and Settings\Vishal\My Documents\Visual Studio 2008\Projects\EzBuddy\EzBuddy\UserLoginForm.cs 60 35 EzBuddy"Above error is for MDIParentForm.loginToolStripMenuItem1.Enabled = false; shown in the code in previous post

#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Hmm, try double clicking on the 'loginToolStripMenuItem1', and let it create an event for it. Hopefully the compiler will recognize it then.

~ Committed.


A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Look at your UserLoginFor designer.cs file and make sure that "loginToolStripMenuItem1" is declared. If it's not in there, that would be the reason for your issue. (I think) ;)
-CDG10620
Software Developer

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

Look at your UserLoginFor designer.cs file and make sure that "loginToolStripMenuItem1" is declared. If it's not in there, that would be the reason for your issue. (I think)
Yeah im pretty sure thats the problem also, thats why I said create an event for it so it should declare it.

~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users