using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace Trial
{
public partial class Form1 : Form
{
private int _attempts;
public static string user;
public Form1()
{
InitializeComponent();
tbuser.Text = user;
}
private void bexit_Click(object sender, EventArgs e)
{
this.Close();
MDIParent1 mp = new MDIParent1();
mp.Close();
}
public void blogin_Click(object sender, EventArgs e)
{
SqlConnection sc = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Marc\Documents\Trial.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("Select ROLE From login where username = '"+ tbuser.Text +"' and password = '"+ tbpass.Text +"'", sc);
DataTable dt = new System.Data.DataTable();
sda.Fill(dt);
if (dt.Rows.Count == 1)
{
_attempts = 0;
this.Hide();
MDIParent1 mp = new MDIParent1(dt.Rows[0][0].ToString());
mp.Show();
// ((Form)ss).Controls["label1"].Text = dt.Rows[0][0].ToString();
}
else
{
MessageBox.Show("Invalid Username or Password");
_attempts++;
}
if (_attempts == 3) this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void lpassword_Click(object sender, EventArgs e)
{
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void tbuser_TextChanged(object sender, EventArgs e)
{
}
}
}
MDIParent Form :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Trial
{
public partial class MDIParent1 : Form
{
public MDIParent1(string role)
{
InitializeComponent();
label1.Text = role;
}
SqlConnection scon = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Marc\Documents\Trial.mdf;Integrated Security=True;Connect Timeout=30");
public MDIParent1()
{
// TODO: Complete member initialization
}
private void mainWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
mainwindow mw = new mainwindow();
mw.MdiParent = this;
mw.Show();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void MDIParent1_Load(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void menuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void updateEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void addEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
{
EMPLOYEE addemp = new EMPLOYEE();
addemp.MdiParent = this;
addemp.Show();
}
private void searchEmployeeToolStripMenuItem_Click(object sender, EventArgs e)
{
EMPLOYEE2 srchemp = new EMPLOYEE2();
srchemp.MdiParent = this;
srchemp.Show();
}
private void employeeReportsToolStripMenuItem_Click(object sender, EventArgs e)
{
REPORT report = new REPORT();
report.MdiParent = this;
report.Show();
}
private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
{
SETTINGS settings = new SETTINGS();
settings.MdiParent = this;
settings.Show();
}
private void sts_Click(object sender, EventArgs e)
{
}
private void toolStripStatusLabel_Click(object sender, EventArgs e)
{
}
}
}