0% found this document useful (0 votes)
78 views6 pages

Simple Payroll System Programming

The document describes a simple payroll system created using object-oriented programming in C#. It includes two classes: Form1, which handles user login authentication against a SQL database, and mainform, which allows adding, deleting, and viewing employee records stored in a SQL database table. The mainform class contains methods for clearing textboxes, inserting new employee records into the database on save, deleting records, and loading records into a datagrid for viewing.

Uploaded by

Jozu the Great
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
78 views6 pages

Simple Payroll System Programming

The document describes a simple payroll system created using object-oriented programming in C#. It includes two classes: Form1, which handles user login authentication against a SQL database, and mainform, which allows adding, deleting, and viewing employee records stored in a SQL database table. The mainform class contains methods for clearing textboxes, inserting new employee records into the database on save, deleting records, and loading records into a datagrid for viewing.

Uploaded by

Jozu the Great
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

Computer Programming 3

SIMPLE PAYROLL SYSTEM WITH OBJECT ORIENTED PROGRAMMING

Form1.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 WindowsFormsApplication2
{
public partial class frm_login : Form
{

SqlConnection con = new SqlConnection("Data Source=inser PC here;Initial


Catalog=payroll_db;Integrated Security=True");

public frm_login()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
this.AcceptButton = this.button1;
}

private void button1_Click_1(object sender, EventArgs e)


{

string query = "Select * From tbl_userpass Where Username = '" +


tb_user.Text.Trim()+ "'and Password ='" + tb_pass.Text.Trim() +" '";
SqlDataAdapter sda = new SqlDataAdapter(query, con);
DataTable dtbl = new DataTable();
sda.Fill(dtbl);

mainform a = new mainform();

if (dtbl.Rows.Count == 1)
{
this.Hide();
a.Show();
}

else if (tb_user.Text == "" || tb_pass.Text == "")


{

MessageBox.Show("Please fill up all the fields");


}
else
{
MessageBox.Show("Invalid Username / Password");
}

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

private void label1_Click(object sender, EventArgs e)


{

private void tb_pass_KeyDown(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Enter) {

AcceptButton.PerformClick();
}
}
}
}

Form1.cs [DESIGN]
mainform.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 WindowsFormsApplication2
{
public partial class mainform : Form
{
SqlConnection con = new SqlConnection("Data Source=insert PC here;Initial
Catalog=payroll_db;Integrated Security=True");
SqlCommand cmd = new SqlCommand();

public mainform()
{
InitializeComponent();
}

void ClearAllText(Control con)


{
foreach (Control c in con.Controls)
{
if (c is TextBox)
((TextBox)c).Clear();
else
ClearAllText(c);
}
}

private void button2_Click(object sender, EventArgs e)


{

string del = dataGridView1.CurrentRow.Cells[0].Value.ToString();


con.Open();
cmd = new SqlCommand("DELETE FROM tbl_addemp WHERE ID = '" + del + "'", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Data Deleted");

string query = "SELECT * FROM tbl_addemp";


SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "Employee Info");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Employee Info";
dataGridView1.DataSource = dataGridView1.DataSource;
con.Close();
}

private void btn_save_Click(object sender, EventArgs e)


{
con.Open();
cmd = new SqlCommand("INSERT INTO tbl_addemp (ID, Firstname, Lastname,
Address, Gender, Status, TelNum, PhoneNum, SSSNum, Rate) VALUES ('" +tb_id.Text + "','" +
tb_fn.Text + "','" + tb_ln.Text + "','" + tb_add.Text + "','" + cb_gen.Text + "','" +
cb_stat.Text + "','" + tb_tnum.Text + "','" + tb_pnum.Text + "','" + tb_sss.Text + "','"
+ cb_rate.Text + "')",con);
cmd.ExecuteNonQuery();
MessageBox.Show("Saved");
con.Close();

string query = "SELECT * FROM tbl_addemp";


SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "Employee Info");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Employee Info";
dataGridView1.DataSource = dataGridView1.DataSource;
con.Close();

ClearAllText(this);

cb_gen.SelectedIndex = -1;
cb_rate.SelectedIndex = -1;
cb_stat.SelectedIndex = -1;
}
private void mainform_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'payroll_dbDataSet.tbl_addemp'
table. You can move, or remove it, as needed.
this.tbl_addempTableAdapter.Fill(this.payroll_dbDataSet.tbl_addemp);
}
}
}
mainform.cs [DESIGN]

You might also like