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 -
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();
}
}
}
Help me to solve this problem