form golongan ini ber fungsi untuk mengetahui/untuk menentukan gaji pokok
dimana coding yang ada di dalamnya adalah sebagai berikut:
1 D:\penggajian\penggajian\golongan.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace penggajian
{
//form golongan
public partial class golongan : Form
{
OleDbConnection varConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\
penggajian\penggajian\karyawan.accdb;Persist Security Info=false;");
DataSet varDS = new DataSet();
OleDbDataAdapter varDA = new OleDbDataAdapter();
DataTable varDetail;
DataRow varRow;
OleDbCommand varComm = new OleDbCommand();
OleDbDataReader varDR;
public golongan()
{
InitializeComponent();
}
private void bersih()
{
cmb_id.Text = "";
txt_gapok.Clear();
}
private void golongan_Load(object sender, EventArgs e)
{
varDA = new OleDbDataAdapter("SELECT * FROM tgolongan", varConn);
varDA.Fill(varDS, "tgolongan");
dgvgolongan.DataSource = varDS.Tables["tgolongan"];
}
private void btnsimpan_Click(object sender, EventArgs e)
{
if (cmb_id.Text == "")
{
MessageBox.Show("Masukkan kode barang sebelum disimpan", "Pesan Kesalahan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
else
{
DataColumn[] pk = { varDS.Tables["tgolongan"].Columns["Id_Golongan"] };
varDS.Tables["tgolongan"].PrimaryKey = pk;
varRow = varDS.Tables["tgolongan"].Rows.Find(cmb_id.Text);
if (varRow == null)
{
varRow = varDS.Tables["tgolongan"].NewRow();
varRow[0] = cmb_id.Text;
varRow[1] = txt_gapok.Text;
varDS.Tables["tgolongan"].Rows.Add(varRow);
OleDbCommandBuilder cmd = new OleDbCommandBuilder(varDA);
varDA.Update(varDS, "tgolongan");
MessageBox.Show("Data telah berhasil disimpan", "Pesan Informasi", MessageBoxButtons.OK
, MessageBoxIcon.Information);
bersih();
2 D:\penggajian\penggajian\golongan.cs
}
else
{
MessageBox.Show("Golongan sudah ada", "Pesan Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
}
}
private void btnubah_Click(object sender, EventArgs e)
{
if (cmb_id.Text == "")
{
MessageBox.Show("Tentukan kode barang sebelum dirubah", "Pesan Kesalahan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
else
{
DataColumn[] pk = { varDS.Tables["tgolongan"].Columns["Id_Golongan"] };
varDS.Tables["tgolongan"].PrimaryKey = pk;
varRow = varDS.Tables["tgolongan"].Rows.Find(cmb_id.Text);
if (varRow == null)
{
MessageBox.Show("Kode tidak terdaftar untuk dirubah", "Pesan Kesalahan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
else
{
varRow.BeginEdit();
varRow[1] = txt_gapok.Text;
varRow.EndEdit();
OleDbCommandBuilder cmd = new OleDbCommandBuilder(varDA);
varDA.Update(varDS, "tgolongan");
MessageBox.Show("Data telah berhasil disimpan", "Berhasil", MessageBoxButtons.OK,
MessageBoxIcon.Information);
bersih();
}
}
}
private void btnhapus_Click(object sender, EventArgs e)
{
if (cmb_id.Text == "")
{
MessageBox.Show("Tentukan kode barang sebelum dirubah", "Pesan Kesalahan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
else
{
DataColumn[] pk = { varDS.Tables["tgolongan"].Columns["Id_Golongan"] };
varDS.Tables["tgolongan"].PrimaryKey = pk;
varRow = varDS.Tables["tgolongan"].Rows.Find(cmb_id.Text);
if (varRow == null)
{
MessageBox.Show("Kode tidak terdaftar untuk dihapus", "Pesan Kesalahan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cmb_id.Focus();
}
else
{
varRow.Delete();
OleDbCommandBuilder cmd = new OleDbCommandBuilder(varDA);
3 D:\penggajian\penggajian\golongan.cs
varDA.Update(varDS, "tgolongan");
MessageBox.Show("Data telah berhasil dihapus", "Pesan Informasi", MessageBoxButtons.OK,
MessageBoxIcon.Information);
bersih();
}
}
}
private void btnbersih_Click(object sender, EventArgs e)
{
cmb_id.Text = "";
txt_gapok.Text = "";
}
private void btnkeluar_Click(object sender, EventArgs e)
{
this.Close();
}
private void dgvgolongan_SelectionChanged(object sender, EventArgs e)
{
try
{
cmb_id.Text = Convert.ToString(varDS.Tables["tgolongan"].Rows[dgvgolongan.CurrentRow.Index]
.ItemArray[0]);
txt_gapok.Text = Convert.ToString(varDS.Tables["tgolongan"].Rows[dgvgolongan.CurrentRow.
Index].ItemArray[1]);
}
catch
{
cmb_id.Text = "";
txt_gapok.Clear();
dgvgolongan.Focus();
}
}
private void dgvgolongan_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void cmb_id_KeyPress(object sender, KeyPressEventArgs e)
{
int varCount = 0;
if (e.KeyChar == (char)13)
{
try
{
varConn.Open();
varComm.Connection = varConn;
varComm.CommandText = "select * from tgolongan where Id_Golongan = '" + cmb_id.Text +
"'";
varDR = varComm.ExecuteReader();
while (varDR.Read())
{
varCount += 1;
txt_gapok.Text = varDR["Gaji_Pokok"].ToString();
}
if (varCount == 0)
{
MessageBox.Show("Data tidak ada", "Pesan Kesalahan", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
4 D:\penggajian\penggajian\golongan.cs
MessageBox.Show(ex.Message, "Pesan Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.
Error);
}
finally
{
//varDR.Close();
varConn.Close();
}
}
}
}
}