Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 FrmDokter : Form
- {
- public FrmDokter()
- {
- InitializeComponent();
- }
- void ambildata()
- {
- tyo.tbldokter.Clear();
- tyo.dadokter.Fill(tyo.tbldokter);
- }
- void bersih()
- {
- tbkodedokter.Clear();
- tbnamadokter.Clear();
- cbspesialis.SelectedIndex = -1;
- tbtelpon.Clear();
- cbpilihan.SelectedIndex = -1;
- tbcari.Clear();
- tbkodedokter.Focus();
- }
- private void FrmDokter_Load(object sender, EventArgs e)
- {
- this.KeyPreview = true;
- tyo.con = tyo.konek_db();
- tyo.dadokter = new OleDbDataAdapter (" select*from dokter", tyo.con);
- ambildata();
- dataGridView1.DataSource = tyo.tbldokter;
- dataGridView1.ReadOnly = true;
- dataGridView1.AllowUserToAddRows = false;
- dataGridView1.Columns[0].HeaderText = "Kode Dokter";
- dataGridView1.Columns[0].Width = 50;
- dataGridView1.Columns[1].HeaderText = "Nama Dokter";
- dataGridView1.Columns[1].Width = 100;
- dataGridView1.Columns[2].HeaderText = "Spesialis";
- dataGridView1.Columns[2].Width = 100;
- dataGridView1.Columns[3].HeaderText = "Telpon";
- dataGridView1.Columns[3].Width = 100;
- }
- private void btsimpan_Click(object sender, EventArgs e)
- {
- tyo.cmd = new OleDbCommand
- ("select * from dokter where kd_dokter ='" + tbkodedokter.Text + "'", tyo.con);
- tyo.dtr = tyo.cmd.ExecuteReader();
- if (tyo.dtr.HasRows)
- {
- MessageBox.Show("kode tersebut sudah ada", "pesan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- tbkodedokter.Clear();
- tbkodedokter.Focus();
- }
- else
- {
- tyo.cmd = new OleDbCommand
- ("insert into dokter (kd_dokter,nm_dokter,spesialis,tlp)" +
- "values(" +
- "'" + tbkodedokter.Text + "'," +
- "'" + tbnamadokter.Text + "'," +
- "'" + cbspesialis.Text + "'," +
- "'" + tbtelpon.Text + "')", tyo.con);
- tyo.cmd.ExecuteNonQuery();
- ambildata();
- MessageBox.Show("Data udah disimpan", "pesan",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- bersih();
- }
- }
- 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 kd_dokter =" + kode + "\n" +
- "ingin dihapus?", "Pesan",
- MessageBoxButtons.OKCancel,
- MessageBoxIcon.Question) == DialogResult.OK)
- {
- tyo.cmd = new OleDbCommand
- ("delete from dokter where kd_dokter='" + 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;
- tbkodedokter.Enabled = false;
- int brsh;
- brsh = dataGridView1.CurrentRow.Index;
- tbkodedokter.Text = dataGridView1[0, brsh].Value.ToString();
- tbnamadokter.Text = dataGridView1[1, brsh].Value.ToString();
- cbspesialis.Text = dataGridView1[2, brsh].Value.ToString();
- tbtelpon.Text = dataGridView1[3, brsh].Value.ToString();
- }
- else if (btkoreksi.Text == "Simpan Perubahan")
- {
- btkoreksi.Text = "Koreksi";
- btsimpan.Enabled = true;
- bthapus.Enabled = true;
- tbkodedokter.Enabled = true;
- tyo.cmd = new OleDbCommand
- ("update dokter set " +
- "nm_dokter ='" + tbnamadokter.Text + "'," +
- "spesialis ='" + cbspesialis.Text + "'," +
- "tlp='" + tbtelpon.Text + "' where " +
- "kd_dokter ='" + tbkodedokter.Text + "'", tyo.con);
- tyo.cmd.ExecuteNonQuery();
- ambildata();
- MessageBox.Show("Data sudah di Perbaharui", "Pesan",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- bersih();
- }
- }
- private void tbcari_TextChanged(object sender, EventArgs e)
- {
- if (cbpilihan.SelectedIndex == 0)
- {
- tyo.dadokter = new OleDbDataAdapter
- ("select * from dokter where kd_dokter like '%" +
- tbcari.Text + "%'", tyo.con);
- }
- else if (cbpilihan.SelectedIndex == 1)
- {
- tyo.dadokter = new OleDbDataAdapter
- ("select * from dokter where nm_dokter like '%" +
- tbcari.Text + "%'", tyo.con);
- }
- else if (cbpilihan.SelectedIndex == 2)
- {
- tyo.dadokter = new OleDbDataAdapter
- ("select * from dokter where spesialis like '%" +
- tbcari.Text + "%'", tyo.con);
- }
- else if (cbpilihan.SelectedIndex == 3)
- {
- tyo.dadokter = new OleDbDataAdapter
- ("select * from dokter where tlp like '%" +
- tbcari.Text + "%'", tyo.con);
- }
- ambildata();
- }
- private void cbpilihan_SelectedIndexChanged(object sender, EventArgs e)
- {
- tbcari.Focus();
- }
- private void bttutup_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Apakah Anda yakin akan menutup menu Dokter?", "Pesan",
- MessageBoxButtons.OKCancel,
- MessageBoxIcon.Question) == DialogResult.OK)
- Close();
- }
- 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();
- tyo.dadokter = new OleDbDataAdapter
- ("select * from dokter", tyo.con);
- ambildata();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment