You are on page 1of 8

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.SqlClient;
using System.IO;
namespace WindowsApplication3
{
public partial class frmUserAuthenticate : Form
{
SqlConnection con,con1;
public frmUserAuthenticate()
{
InitializeComponent();
}
private void frmUserAuthenticate_Load(object sender, EventArgs e)
{
try
{
con = new SqlConnection(DB.Getcon());
con.Open();

txtUserId.Focus();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
bool Ok = false;
SqlCommand com = new SqlCommand("select * from Emp",con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Form1 frm = new Form1();
string UserId = txtUserId.Text;
frm.lblUserId.Text = UserId;
byte[] b;
b = (byte[])dr["img"];
MemoryStream ms = new MemoryStream();
ms = new MemoryStream(b);
frm.ImgClicked.Image = Image.FromStream(ms);
frm.ImgClicked.SizeMode = PictureBoxSizeMode.StretchImage;
frm.Show();
Ok = true;
}
dr.Close();
if (!Ok)
{
MessageBox.Show("Invalid UserID/Password");
return;
}

}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void glassButton2_Click(object sender, EventArgs e)
{
con1=new SqlConnection(DB.Getcon());
try
{

int count = 0;
string id = txtUserId.Text;
string pass = txtPass.Text;

string user = null, upass = null, utype=null;


con1.Open();
string str = "select * from emp where emailid='"+txtUserId.Text+"'";
SqlCommand cm = new SqlCommand(str, con1);
SqlDataReader dr1 = cm.ExecuteReader();
while (dr1.Read())
{
user = dr1["emailid"].ToString();
upass = dr1["nam"].ToString();
utype = dr1["utype"].ToString();
}
con1.Close();
if (id.Equals(user) && pass.Equals(upass) && utype == "Employee")
{
bool Ok = false;
SqlCommand com = new SqlCommand("select * from emp where emailid='" +
txtUserId.Text + "'", con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Form1 frm = new Form1();
string UserId = txtUserId.Text;
frm.lblUserId.Text = UserId;
byte[] b;
b = (byte[])dr["img"];
MemoryStream ms = new MemoryStream();
ms = new MemoryStream(b);
frm.ImgClicked.Image = Image.FromStream(ms);
frm.ImgClicked.SizeMode = PictureBoxSizeMode.StretchImage;
frm.Show();
this.Hide();
Ok = true;
}
dr.Close();
if (!Ok)
{
MessageBox.Show("Invalid UserID/Password", "Cannot Access",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserId.Text = "";
txtUserId.Focus();
return;
}
}
else
{
//count++;
//MessageBox.Show(count.ToString());
}

}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);

private void glassButton1_Click(object sender, EventArgs e)


{
Application.Exit();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
frmAdminLogin frm = new frmAdminLogin();
frm.Show();
this.Hide();
}
}

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.IO;
using System.Data.SqlClient;
namespace WindowsApplication3

public partial class frmAdmin : Form


{
SqlConnection con;
public frmAdmin()
{
InitializeComponent();
}
private void glassButton3_Click(object sender, EventArgs e)
{
frmEmployee frm = new frmEmployee();
frm.Show();
lst.Visible = false;
lblSearch.Visible = false;
txtSearch.Visible = false;
lblClisk.Visible = false;
}
private void glassButton2_Click(object sender, EventArgs e)
{
frmUserAuthenticate frm = new frmUserAuthenticate();
frm.Show();
this.Hide();
}
private void glassButton1_Click(object sender, EventArgs e)
{
getlist();
}
void getlist()
{
lst.Visible = true;
lblSearch.Visible = true;
txtSearch.Visible = true;
lblClisk.Visible = true;
lst.Items.Clear();
try
{

SqlCommand com = new SqlCommand("select * from emp where nam like'"


+txtSearch.Text+"%' order by nam", con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
lst.Items.Add(dr["Id"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["nam"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["desig"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["address"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["phone"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["dt"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["c_cat"].ToString());
lst.Items[lst.Items.Count - 1].SubItems.Add(dr["age"].ToString());
}
dr.Close();
}
catch (SqlException ex)

MessageBox.Show(ex.Message);

}
}
private void frmAdmin_Load(object sender, EventArgs e)
{
try
{
con = new SqlConnection(DB.Getcon());
con.Open();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);

private void glassButton4_Click(object sender, EventArgs e)


{
Application.Exit();
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
getlist();
}
private void lst_DoubleClick(object sender, EventArgs e)
{
try
{
SqlCommand com = new SqlCommand("select * from Emp where Id=" +
lst.SelectedItems[0].Text + "", con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
frmEmployee frm = new frmEmployee();
byte[] b;
b = (byte[])dr["img"];
MemoryStream ms = new MemoryStream();
ms = new MemoryStream(b);
frm.Img.Image = Image.FromStream(ms);
frm.Img.SizeMode = PictureBoxSizeMode.StretchImage;
frm.txtAddress.Text = dr["address"].ToString();
frm.txtName.Text = dr["nam"].ToString();
frm.txtDesig.Text = dr["desig"].ToString();
frm.txtPhone.Text = dr["phone"].ToString();
frm.txtUserId.Text = dr["EmailID"].ToString();
frm.comboBox1.SelectedValue = dr["c_cat"].ToString();
frm.textBox1.Text = dr["age"].ToString();

/*byte[] b2;
b2 = (byte[])dr["imgThumb"];
MemoryStream ms2 = new MemoryStream();

ms2 = new MemoryStream(b2);


frm.ImgThumb.Image = Image.FromStream(ms2);
frm.ImgThumb.SizeMode = PictureBoxSizeMode.StretchImage;*/
frm.Show();
}
dr.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);

private void glassButton5_Click(object sender, EventArgs e)


{
addEmp ap = new addEmp();
ap.Show();
}
private void glassButton6_Click(object sender, EventArgs e)
{
//adminFace fm = new adminFace();
Form1 fm = new Form1();
fm.Show();
}
private void glassButton7_Click(object sender, EventArgs e)
{
EmpReport ep = new EmpReport();
ep.Show();
}