0% found this document useful (0 votes)
5 views10 pages

16 Mca 57

MCA C# Lab programs

Uploaded by

anishpereira05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

16 Mca 57

MCA C# Lab programs

Uploaded by

anishpereira05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

db_EMS

Index.cs
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;

namespace lab1
{
public partial class Index : Form
{
public Index()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
EnterEmployee f2 = new EnterEmployee();
f2.Show();

private void button2_Click(object sender, EventArgs e)


{
ViewProjectLeaders f3 = new ViewProjectLeaders();
f3.Show();

private void button3_Click(object sender, EventArgs e)


{
ViewEngineers f4 = new ViewEngineers();
f4.Show();
}

private void button4_Click(object sender, EventArgs e)


{
ViewEmployees f5 = new ViewEmployees();
f5.Show();
}

private void label1_Click(object sender, EventArgs e)


{

}
}
}

EnterEmployee.cs
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;

namespace lab1
{
public partial class EnterEmployee : Form
{
SqlConnection con = new SqlConnection("Data Source=MCA-PC\\
SQLEXPRESS;Initial Catalog=db_EMS;Integrated Security=True");
public EnterEmployee()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmdsql = new SqlCommand("INSERT INTO
tbl_EmployeeDetails1(EmployeeName,IdEmployee,ContactNumber,IdDesignation,IdReport
ingTo)VALUES(@EmployeeName,@IdEmployee,@ContactNumber,@IdDesignation,@IdReporting
To)", con);
cmdsql.Parameters.AddWithValue("@EmployeeName", textBox1.Text);
cmdsql.Parameters.AddWithValue("@IdEmployee", textBox3.Text);
cmdsql.Parameters.AddWithValue("@ContactNumber", textBox2.Text);
cmdsql.Parameters.AddWithValue("@IdDesignation", comboBox1.Text);
cmdsql.Parameters.AddWithValue("@IdReportingTo", comboBox2.Text);
cmdsql.ExecuteNonQuery();
con.Close();
MessageBox.Show("Inserted successfully");

private void EnterEmployee_Load(object sender, EventArgs e)


{

con.Open();{

SqlDataReader rs;
SqlCommand cmd = new SqlCommand("select [IdDesignation] from
tbl_Designations", con);
rs = cmd.ExecuteReader();
while (rs.Read())
{
comboBox1.Items.Add(rs[0].ToString());

} con.Close();
}

con.Open();
SqlDataReader rs1;

SqlCommand cmd1 = new SqlCommand("select IdEmployee from


tbl_EmployeeDetails1 where IdDesignation= '1'", con);
rs1 = cmd1.ExecuteReader();
while (rs1.Read())
{
comboBox2.Items.Add(rs1[0].ToString());
}
con.Close();

private void textBox1_TextChanged(object sender, EventArgs e)


{

}
ViewProjectLeaders.cs

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;

namespace lab1
{
public partial class ViewProjectLeaders : Form
{
SqlConnection con = new SqlConnection("Data Source=MCA-PC\\
SQLEXPRESS;Initial Catalog=db_EMS;Integrated Security=True");
public ViewProjectLeaders()
{

InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
con.Open();
string str = "SELECT * FROM tbl_EmployeeDetails1 WHERE
IdReportingTo='" + comboBox1.Text + "'";
SqlDataAdapter da = new SqlDataAdapter(str, con);

DataTable table = new DataTable();


da.Fill(table);

dataGridView1.DataSource = table;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

private void ViewProjectLeaders_Load(object sender, EventArgs e)


{
try
{

string str3 = "SELECT IdDesignation FROM tbl_EmployeeDetails1


WHERE IdReportingTo=0 ";
con.Open();

SqlCommand cmdSql3 = new SqlCommand(str3, con);

SqlDataReader rs3;
rs3 = cmdSql3.ExecuteReader();
while (rs3.Read())
{
comboBox1.Items.Add(rs3[0]);
comboBox1.SelectedItem = rs3[0];
}
rs3.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{

}
}

ViewEngineers.cs

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;

namespace lab1
{
public partial class ViewEngineers : Form
{
SqlConnection con = new SqlConnection("Data Source=MCA-PC\\
SQLEXPRESS;Initial Catalog=db_EMS;Integrated Security=True");
public ViewEngineers()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
con.Open();
string str = "SELECT * FROM tbl_EmployeeDetails1 WHERE
IdReportingTo='" + comboBox1.Text + "'";
//EmployeeName '" + comboBox1.Text + "'"; IdDesignation=2 AND
SqlDataAdapter da = new SqlDataAdapter(str, con);

DataTable table = new DataTable();


da.Fill(table);

dataGridView1.DataSource = table;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

private void ViewEngineers_Load(object sender, EventArgs e)


{
try
{

string str3 = "SELECT IdDesignation FROM tbl_EmployeeDetails1


WHERE IdReportingTo=2 ";
con.Open();

SqlCommand cmdSql3 = new SqlCommand(str3, con);

SqlDataReader rs3;
rs3 = cmdSql3.ExecuteReader();
while (rs3.Read())
{
comboBox1.Items.Add(rs3[0]);
comboBox1.SelectedItem = rs3[0];
}
rs3.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

ViewEmployees.cs

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;

namespace lab1
{
public partial class ViewEmployees : Form
{
SqlConnection con = new SqlConnection("Data Source=MCA-PC\\
SQLEXPRESS;Initial Catalog=db_EMS;Integrated Security=True");
public ViewEmployees()
{
InitializeComponent();
}

private void ViewEmployees_Load(object sender, EventArgs e)


{
// TODO: This line of code loads data into the
'db_EMSDataSet3.tbl_EmployeeDetails1' table. You can move, or remove it, as
needed.
this.tbl_EmployeeDetails1TableAdapter.Fill(this.db_EMSDataSet3.tbl_EmployeeDetail
s1);
try
{

string str3 = "SELECT * FROM tbl_EmployeeDetails1 ";


con.Open();

SqlCommand cmdSql3 = new SqlCommand(str3, con);

SqlDataReader rs3;
rs3 = cmdSql3.ExecuteReader();
/* while (rs3.Read())
{
comboBox1.Items.Add(rs3[0]);
comboBox1.SelectedItem = rs3[0];
}*/
rs3.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

You might also like