Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to hide Employee Attendance form on mdi parent form when a teacher wil login from login form and when admin login all forms will show.
Posted
Comments
Where is the issue?
Anil Raina 6-Oct-15 2:26am    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace SMS._forms
{
public partial class frm_login : Form
{
public frm_login()
{
InitializeComponent();
}
_class.clsODBC cls_ODBC = new SMS._class.clsODBC();
_forms.MDIParent mdi_Parent = new MDIParent();

private void cancel_Click(object sender, EventArgs e)
{
Application.Exit();
}


private void frm_login_Load(object sender, EventArgs e)
{
this.com_uName.Focus();
index_Load();
setUserName();
}
#region <=== Index Region ====>
private void index_Load()
{
this.com_uName.TabIndex = 0;
this.txtPass.TabIndex = 1;
this.btn_Login.TabIndex = 2;
this.cancel.TabIndex = 3;

}
#endregion

#region <=== Add Users in ComboBox ===>
private void setUserName()
{

try
{
if (cls_ODBC.cn.State == ConnectionState.Open)
{
cls_ODBC.cn.Close();

}

cls_ODBC.cn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select u_id from user_", cls_ODBC.cn);
da.Fill(ds, "user_");
this.com_uName.DataSource = ds.Tables["user_"];
this.com_uName.DisplayMember = "u_id";
this.com_uName.ValueMember = "u_id";
cls_ODBC.cn.Close();
}

catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion

#region <=== Check Valid User ===>

private void btn_Login_Click(object sender, EventArgs e)
{

try
{
OleDbCommand cmdlogin = new OleDbCommand("select * from user_ where u_id='" + this.com_uName.SelectedValue + "' and pw='" + this.txtPass .Text.Trim() + "'", this.cls_ODBC .cn);
if (cls_ODBC.cn.State == ConnectionState.Open)
{
cls_ODBC.cn.Close();
}

cls_ODBC.cn.Open();
OleDbDataReader drpassword = cmdlogin.ExecuteReader();
if (drpassword.Read())
{
cls_ODBC.cn.Close();
drpassword.Close();
cmdlogin.Dispose();
this.Dispose(true);

MessageBox.Show("Welcome User", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
mdi_Parent.Show();


}
else
{

MessageBox.Show("Username or Password is not valid ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message );
}
}


#endregion







}
}
This is my login page code What will I write more such that a user can not get access to employee attendance form(frmEmpAtt) on mdi parent form.
OriginalGriff 3-Oct-15 3:33am    
And?
What have you tried?
Where are you stuck?
What help do you need?
Anil Raina 6-Oct-15 2:26am    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace SMS._forms
{
public partial class frm_login : Form
{
public frm_login()
{
InitializeComponent();
}
_class.clsODBC cls_ODBC = new SMS._class.clsODBC();
_forms.MDIParent mdi_Parent = new MDIParent();

private void cancel_Click(object sender, EventArgs e)
{
Application.Exit();
}


private void frm_login_Load(object sender, EventArgs e)
{
this.com_uName.Focus();
index_Load();
setUserName();
}
#region <=== Index Region ====>
private void index_Load()
{
this.com_uName.TabIndex = 0;
this.txtPass.TabIndex = 1;
this.btn_Login.TabIndex = 2;
this.cancel.TabIndex = 3;

}
#endregion

#region <=== Add Users in ComboBox ===>
private void setUserName()
{

try
{
if (cls_ODBC.cn.State == ConnectionState.Open)
{
cls_ODBC.cn.Close();

}

cls_ODBC.cn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select u_id from user_", cls_ODBC.cn);
da.Fill(ds, "user_");
this.com_uName.DataSource = ds.Tables["user_"];
this.com_uName.DisplayMember = "u_id";
this.com_uName.ValueMember = "u_id";
cls_ODBC.cn.Close();
}

catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
#endregion

#region <=== Check Valid User ===>

private void btn_Login_Click(object sender, EventArgs e)
{

try
{
OleDbCommand cmdlogin = new OleDbCommand("select * from user_ where u_id='" + this.com_uName.SelectedValue + "' and pw='" + this.txtPass .Text.Trim() + "'", this.cls_ODBC .cn);
if (cls_ODBC.cn.State == ConnectionState.Open)
{
cls_ODBC.cn.Close();
}

cls_ODBC.cn.Open();
OleDbDataReader drpassword = cmdlogin.ExecuteReader();
if (drpassword.Read())
{
cls_ODBC.cn.Close();
drpassword.Close();
cmdlogin.Dispose();
this.Dispose(true);

MessageBox.Show("Welcome User", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
mdi_Parent.Show();


}
else
{

MessageBox.Show("Username or Password is not valid ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message );
}
}


#endregion







}
}
This is my login page code What will I write more such that a user can not get access to employee attendance form(frmEmpAtt) on mdi parent form.
BillWoodruff 3-Oct-15 4:40am    
Show the code you are using now, and tell us what doesn't work.

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