Guest User

Form Dokter

a guest
Aug 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.OleDb;
  11.  
  12. namespace Prasetiyo
  13. {
  14.     public partial class FrmDokter : Form
  15.     {
  16.         public FrmDokter()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         void ambildata()                                        
  22.         {
  23.             tyo.tbldokter.Clear();
  24.             tyo.dadokter.Fill(tyo.tbldokter);
  25.         }
  26.  
  27.         void bersih()                                              
  28.         {
  29.             tbkodedokter.Clear();
  30.             tbnamadokter.Clear();
  31.             cbspesialis.SelectedIndex = -1;
  32.             tbtelpon.Clear();
  33.             cbpilihan.SelectedIndex = -1;
  34.             tbcari.Clear();
  35.             tbkodedokter.Focus();
  36.         }
  37.  
  38.         private void FrmDokter_Load(object sender, EventArgs e)
  39.         {
  40.             this.KeyPreview = true;
  41.  
  42.             tyo.con = tyo.konek_db();
  43.  
  44.             tyo.dadokter = new OleDbDataAdapter (" select*from dokter", tyo.con);
  45.             ambildata();
  46.  
  47.             dataGridView1.DataSource = tyo.tbldokter;
  48.             dataGridView1.ReadOnly = true;
  49.             dataGridView1.AllowUserToAddRows = false;
  50.  
  51.             dataGridView1.Columns[0].HeaderText = "Kode Dokter";
  52.             dataGridView1.Columns[0].Width = 50;
  53.             dataGridView1.Columns[1].HeaderText = "Nama Dokter";
  54.             dataGridView1.Columns[1].Width = 100;
  55.             dataGridView1.Columns[2].HeaderText = "Spesialis";
  56.             dataGridView1.Columns[2].Width = 100;
  57.             dataGridView1.Columns[3].HeaderText = "Telpon";
  58.             dataGridView1.Columns[3].Width = 100;
  59.         }
  60.  
  61.         private void btsimpan_Click(object sender, EventArgs e)
  62.         {
  63.             tyo.cmd = new OleDbCommand
  64.                  ("select * from dokter where kd_dokter ='" + tbkodedokter.Text + "'", tyo.con);
  65.             tyo.dtr = tyo.cmd.ExecuteReader();
  66.  
  67.             if (tyo.dtr.HasRows)
  68.             {
  69.                 MessageBox.Show("kode tersebut sudah ada", "pesan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  70.                 tbkodedokter.Clear();
  71.                 tbkodedokter.Focus();
  72.             }
  73.        
  74.             else
  75.             {
  76.                 tyo.cmd = new OleDbCommand
  77.                     ("insert into dokter (kd_dokter,nm_dokter,spesialis,tlp)" +
  78.                     "values(" +
  79.                     "'" + tbkodedokter.Text + "'," +
  80.                     "'" + tbnamadokter.Text + "'," +
  81.                     "'" + cbspesialis.Text + "'," +
  82.                     "'" + tbtelpon.Text + "')", tyo.con);
  83.                 tyo.cmd.ExecuteNonQuery();
  84.                 ambildata();
  85.  
  86.                 MessageBox.Show("Data udah disimpan", "pesan",
  87.                     MessageBoxButtons.OK,
  88.                     MessageBoxIcon.Information);
  89.                 bersih();
  90.             }
  91.         }
  92.  
  93.         private void bthapus_Click(object sender, EventArgs e)
  94.         {
  95.             int brs;
  96.             string kode;
  97.  
  98.             brs = dataGridView1.CurrentRow.Index;
  99.             kode = dataGridView1[0, brs].Value.ToString();
  100.  
  101.             if (MessageBox.Show("Apakah kd_dokter =" + kode + "\n" +
  102.                               "ingin dihapus?", "Pesan",
  103.                     MessageBoxButtons.OKCancel,
  104.                     MessageBoxIcon.Question) == DialogResult.OK)
  105.             {
  106.  
  107.                 tyo.cmd = new OleDbCommand
  108.                     ("delete from dokter where kd_dokter='" + kode + "'", tyo.con);
  109.                 tyo.cmd.ExecuteNonQuery();
  110.                 ambildata();
  111.  
  112.                 MessageBox.Show("Data sudah terhapus", "Pesan",
  113.                    MessageBoxButtons.OK,
  114.                    MessageBoxIcon.Information);
  115.             }
  116.         }
  117.  
  118.         private void btkoreksi_Click(object sender, EventArgs e)
  119.         {
  120.             if (btkoreksi.Text == "Koreksi")
  121.             {
  122.                 btkoreksi.Text = "Simpan Perubahan";
  123.                 btsimpan.Enabled = false;
  124.                 bthapus.Enabled = false;
  125.                 tbkodedokter.Enabled = false;
  126.  
  127.                 int brsh;
  128.                 brsh = dataGridView1.CurrentRow.Index;
  129.                 tbkodedokter.Text = dataGridView1[0, brsh].Value.ToString();
  130.                 tbnamadokter.Text = dataGridView1[1, brsh].Value.ToString();
  131.                 cbspesialis.Text = dataGridView1[2, brsh].Value.ToString();
  132.                 tbtelpon.Text = dataGridView1[3, brsh].Value.ToString();
  133.  
  134.             }
  135.             else if (btkoreksi.Text == "Simpan Perubahan")
  136.             {
  137.                 btkoreksi.Text = "Koreksi";
  138.                 btsimpan.Enabled = true;
  139.                 bthapus.Enabled = true;
  140.                 tbkodedokter.Enabled = true;
  141.  
  142.                 tyo.cmd = new OleDbCommand
  143.                     ("update dokter set " +
  144.                     "nm_dokter ='" + tbnamadokter.Text + "'," +
  145.                     "spesialis ='" + cbspesialis.Text + "'," +
  146.                     "tlp='" + tbtelpon.Text + "' where " +
  147.                     "kd_dokter   ='" + tbkodedokter.Text + "'", tyo.con);
  148.  
  149.                 tyo.cmd.ExecuteNonQuery();
  150.                 ambildata();
  151.  
  152.                 MessageBox.Show("Data sudah di Perbaharui", "Pesan",
  153.                   MessageBoxButtons.OK,
  154.                   MessageBoxIcon.Information);
  155.                 bersih();
  156.             }
  157.         }
  158.  
  159.         private void tbcari_TextChanged(object sender, EventArgs e)
  160.         {
  161.             if (cbpilihan.SelectedIndex == 0)
  162.             {
  163.                 tyo.dadokter = new OleDbDataAdapter
  164.                 ("select * from dokter where kd_dokter like '%" +
  165.                  tbcari.Text + "%'", tyo.con);
  166.             }
  167.             else if (cbpilihan.SelectedIndex == 1)
  168.             {
  169.                 tyo.dadokter = new OleDbDataAdapter
  170.                 ("select * from dokter where nm_dokter like '%" +
  171.                  tbcari.Text + "%'", tyo.con);
  172.             }
  173.             else if (cbpilihan.SelectedIndex == 2)
  174.             {
  175.                 tyo.dadokter = new OleDbDataAdapter
  176.                 ("select * from dokter where spesialis like '%" +
  177.                  tbcari.Text + "%'", tyo.con);
  178.             }
  179.             else if (cbpilihan.SelectedIndex == 3)
  180.             {
  181.                 tyo.dadokter = new OleDbDataAdapter
  182.                 ("select * from dokter where tlp like '%" +
  183.                  tbcari.Text + "%'", tyo.con);
  184.             }
  185.  
  186.             ambildata();
  187.         }
  188.  
  189.         private void cbpilihan_SelectedIndexChanged(object sender, EventArgs e)
  190.         {
  191.             tbcari.Focus();
  192.         }
  193.  
  194.         private void bttutup_Click(object sender, EventArgs e)
  195.         {
  196.             if (MessageBox.Show("Apakah Anda yakin akan menutup menu Dokter?", "Pesan",
  197.                   MessageBoxButtons.OKCancel,
  198.                   MessageBoxIcon.Question) == DialogResult.OK)
  199.                 Close();
  200.         }
  201.  
  202.         private void btbatal_Click(object sender, EventArgs e)
  203.         {
  204.             if (MessageBox.Show("Apakah Anda yakin akan membatalkan input data?", "Pesan",
  205.                   MessageBoxButtons.OKCancel,
  206.                   MessageBoxIcon.Question) == DialogResult.OK)
  207.  
  208.                 bersih();
  209.             tyo.dadokter = new OleDbDataAdapter
  210.              ("select * from dokter", tyo.con);
  211.              ambildata();
  212.         }
  213.     }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment