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.OleDb;
namespace Prasetiyo
{
public partial class FrmAdm : Form
{
double vbiaya;
public FrmAdm()
{
InitializeComponent();
}
void ambildata()
{
tyo.tbladm.Clear();
tyo.daadm.Fill(tyo.tbladm);
}
void bersih()
{
tbkodeadministrasi.Clear();
tanggal.Value = DateTime.Now;
cbkodepasien.Text = "";
tbnamapasien.Clear();
tbjeniskelamin.Clear();
tbstatus.Clear();
tbalamat.Clear();
cbkodedokter.Text = "";
tbnamadokter.Clear();
tbspesialis.Clear();
tbtelpon.Clear();
tbbiaya.Clear();
tbkodeadministrasi.Focus();
}
private void FrmAdm_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
tyo.con = tyo.konek_db();
tyo.daadm = new OleDbDataAdapter
("select * from administrasi", tyo.con);
ambildata();
dataGridView1.DataSource = tyo.tbladm;
dataGridView1.ReadOnly = true;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns[0].HeaderText = "Kode Adm";
dataGridView1.Columns[0].Width = 100;
dataGridView1.Columns[1].HeaderText = "Tanggal";
dataGridView1.Columns[1].Width = 130;
dataGridView1.Columns[1].DefaultCellStyle.Format = "dd MMMM yyyy";
dataGridView1.Columns[2].HeaderText = "Kode Pasien";
dataGridView1.Columns[2].Width = 120;
dataGridView1.Columns[3].HeaderText = "Kode Dokter";
dataGridView1.Columns[3].Width = 120;
dataGridView1.Columns[4].HeaderText = "Biaya";
dataGridView1.Columns[4].Width = 150;
dataGridView1.Columns[4].DefaultCellStyle.Format = "Rp ##,##0";
//mengambil kode pasien dari tabel pasien
cbkodepasien.Items.Clear();
tyo.cmd = new OleDbCommand
("select * from pasien", tyo.con);
tyo.dtr = tyo.cmd.ExecuteReader();
while (tyo.dtr.Read())
{
cbkodepasien.Items.Add(tyo.dtr["kd_pasien"].ToString());
}
//mengambil kode dokter dari tabel dokter
cbkodedokter.Items.Clear();
tyo.cmd = new OleDbCommand
("select * from dokter", tyo.con);
tyo.dtr = tyo.cmd.ExecuteReader();
while (tyo.dtr.Read())
{
cbkodedokter.Items.Add(tyo.dtr["kd_dokter"].ToString());
}
}
private void btcekpasien_Click(object sender, EventArgs e)
{
//menampilkan data pasien berdasarkan kode pasien
tyo.cmd = new OleDbCommand
("select * from pasien where kd_pasien='" + cbkodepasien.Text + "'", tyo.con);
tyo.dtr = tyo.cmd.ExecuteReader();
tyo.dtr.Read();
if (tyo.dtr.HasRows)
{
tbnamapasien.Text = tyo.dtr["nm_pasien"].ToString();
tbjeniskelamin.Text = tyo.dtr["jns_kel"].ToString();
tbstatus.Text = tyo.dtr["status"].ToString();
tbalamat.Text = tyo.dtr["alamat"].ToString();
cbkodedokter.Focus();
}
else
{
MessageBox.Show("kode pasien tersebut tidak ada", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
cbkodepasien.Text = "";
tbnamapasien.Clear();
tbjeniskelamin.Clear();
tbstatus.Clear();
tbalamat.Clear();
cbkodepasien.Focus();
}
}
private void btcekdokter_Click(object sender, EventArgs e)
{
//menampilkan data dokter berdasarkan kode dokter
tyo.cmd = new OleDbCommand
("select * from dokter where kd_dokter='" +
cbkodedokter.Text + "'", tyo.con);
tyo.dtr = tyo.cmd.ExecuteReader();
tyo.dtr.Read();
if (tyo.dtr.HasRows)
{
tbnamadokter.Text = tyo.dtr["nm_dokter"].ToString();
tbspesialis.Text = tyo.dtr["spesialis"].ToString();
tbtelpon.Text = tyo.dtr["tlp"].ToString();
tbbiaya.Focus();
}
else
{
MessageBox.Show("kode dokter tersebut tidak ada", "Pesan",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
cbkodedokter.Text = "";
tbnamadokter.Clear();
tbspesialis.Clear();
tbtelpon.Clear();
cbkodedokter.Focus();
}
}
private void tbbiaya_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false &&
(int)e.KeyChar != (int)Keys.Back &&
(int)e.KeyChar != (int)Keys.Enter)
{
e.Handled = true;
}
}
private void tbbiaya_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
}
private void tbbiaya_TextChanged(object sender, EventArgs e)
{
if (tbbiaya.Text != "")
{
vbiaya = double.Parse(tbbiaya.Text);
tbbiaya.Text = vbiaya.ToString("#,##0");
tbbiaya.SelectionStart = tbbiaya.Text.Length;
}
}
private void bttutup_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Apakah Anda yakin akan menutup menu Administrasi?", "Pesan",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
Close();
}
private void btsimpan_Click(object sender, EventArgs e)
{
tyo.cmd = new OleDbCommand
("select * from administrasi where kd_adm='" + tbkodeadministrasi.Text + "'", tyo.con);
tyo.dtr = tyo.cmd.ExecuteReader();
if (tyo.dtr.HasRows)
{
MessageBox.Show("kode Adm sudah ada", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
tbkodeadministrasi.Clear();
tbkodeadministrasi.Focus();
}
else if (tbkodeadministrasi.Text.Trim() == "")
{
MessageBox.Show("kode Adm masih kosong", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
tbkodeadministrasi.Clear();
tbkodeadministrasi.Focus();
}
else if (tbnamapasien.Text.Trim() == "")
{
MessageBox.Show("Cek data pasiennya", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
cbkodepasien.Focus();
}
else if (tbnamadokter.Text.Trim() == "")
{
MessageBox.Show("Cek data dokternya", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
cbkodedokter.Focus();
}
else if (tbbiaya.Text.Trim() == "")
{
MessageBox.Show("biaya masih kosong", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
tbbiaya.Focus();
}
else
{
tyo.cmd = new OleDbCommand
("insert into administrasi" +
"(kd_adm,tgl,kd_pasien,kd_dokter,biaya) " +
"values ('" + tbkodeadministrasi.Text + "'," +
"'" + tanggal.Value.Date + "'," +
"'" + cbkodepasien.Text + "'," +
"'" + cbkodedokter.Text + "'," +
"'" + vbiaya + "')", tyo.con);
tyo.cmd.ExecuteNonQuery();
ambildata();
MessageBox.Show("Data sudah tersimpan", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
bersih();
}
}
private void cbpilihan_SelectedIndexChanged(object sender, EventArgs e)
{
tbcari.Focus();
}
private void bthapus_Click(object sender, EventArgs e)
{
int brs;
string kode;
brs = dataGridView1.CurrentRow.Index;
kode = dataGridView1[0, brs].Value.ToString();
if (MessageBox.Show("Apakah Kode Administrasi " + kode + "\n" +
"ingin dihapus?", "Pesan",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{
tyo.cmd = new OleDbCommand
("delete from administrasi where kd_adm='" + kode + "'", tyo.con);
tyo.cmd.ExecuteNonQuery();
ambildata();
MessageBox.Show("Data sudah terhapus", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
private void btkoreksi_Click(object sender, EventArgs e)
{
if (btkoreksi.Text == "Koreksi")
{
btkoreksi.Text = "Simpan Perubahan";
btsimpan.Enabled = false;
bthapus.Enabled = false;
tbkodeadministrasi.Enabled = false;
int brsh;
brsh = dataGridView1.CurrentRow.Index;
tbkodeadministrasi.Text = dataGridView1[0, brsh].Value.ToString();
tanggal.Text = dataGridView1[1, brsh].Value.ToString();
cbkodepasien.Text = dataGridView1[2, brsh].Value.ToString();
cbkodedokter.Text = dataGridView1[3, brsh].Value.ToString();
tbbiaya.Text = dataGridView1[4, brsh].Value.ToString();
}
else if (btkoreksi.Text == "Simpan Perubahan")
{
btkoreksi.Text = "Koreksi";
btsimpan.Enabled = true;
bthapus.Enabled = true;
tbkodeadministrasi.Enabled = true;
tyo.cmd = new OleDbCommand
("update administrasi set " +
"tgl ='" + DateTime.Now + "'," +
"kd_pasien ='" + cbkodepasien.Text + "'," +
"kd_dokter ='" + cbkodedokter.Text + "'," +
"biaya ='" + vbiaya + "' where " +
"kd_adm ='" + tbkodeadministrasi.Text + "'", tyo.con);
tyo.cmd.ExecuteNonQuery();
ambildata();
MessageBox.Show("Data sudah di Perbaharui", "Pesan",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
bersih();
}
}
private void tbcari_TextChanged_1(object sender, EventArgs e)
{
if (cbpilihan.SelectedIndex == 0)
{
tyo.daadm = new OleDbDataAdapter
("select * from administrasi where kd_adm like '%" +
tbcari.Text + "%'", tyo.con);
}
else if (cbpilihan.SelectedIndex == 1)
{
tyo.daadm = new OleDbDataAdapter
("select * from administrasi where tgl like '%" +
tbcari.Text + "%'", tyo.con);
}
else if (cbpilihan.SelectedIndex == 2)
{
tyo.daadm = new OleDbDataAdapter
("select * from administrasi where kd_pasien like '%" +
tbcari.Text + "%'", tyo.con);
}
else if (cbpilihan.SelectedIndex == 3)
{
tyo.daadm = new OleDbDataAdapter
("select * from administrasi where kd_dokter like '%" +
tbcari.Text + "%'", tyo.con);
}
else if (cbpilihan.SelectedIndex == 4)
{
tyo.daadm = new OleDbDataAdapter
("select * from administrasi where biaya like '%" +
tbcari.Text + "%'", tyo.con);
}
ambildata();
}
private void btbatal_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Apakah Anda yakin akan membatalkan input data?", "Pesan",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{
bersih();
}
}
private void cbkodepasien_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
}
private void tbkodeadministrasi_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
}
private void cbkodedokter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
}
}
}