document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  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 FrmPasien : Form
  15.     {
  16.         public FrmPasien()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         void ambildata()                              
  22.         {
  23.             tyo.tblpasien.Clear();
  24.             tyo.dapasien.Fill(tyo.tblpasien);
  25.         }
  26.  
  27.         void bersih()                    
  28.         {
  29.             tbkodepasien.Clear();
  30.             tbnamapasien.Clear();
  31.             cbjeniskelamin.SelectedIndex = -1;
  32.             cbstatus.SelectedIndex = -1;
  33.             cbpilihan.SelectedIndex = -1;
  34.             tbcari.Clear();
  35.             tbalamat.Clear();
  36.             tbkodepasien.Focus();
  37.         }
  38.  
  39.         private void FrmPasien_Load(object sender, EventArgs e)
  40.         {
  41.             this.KeyPreview = true;
  42.  
  43.             tyo.con = tyo.konek_db();
  44.  
  45.             tyo.dapasien = new OleDbDataAdapter
  46.                 (" select*from pasien", tyo.con);
  47.             ambildata();
  48.  
  49.             dataGridView1.DataSource = tyo.tblpasien;
  50.             dataGridView1.ReadOnly = true;
  51.             dataGridView1.AllowUserToAddRows = false;
  52.  
  53.             dataGridView1.Columns[0].HeaderText = "Kode Pasien";
  54.             dataGridView1.Columns[0].Width = 50;
  55.             dataGridView1.Columns[1].HeaderText = "Nama Pasien";
  56.             dataGridView1.Columns[1].Width = 100;
  57.             dataGridView1.Columns[2].HeaderText = "Jenis Kelamin";
  58.             dataGridView1.Columns[2].Width = 100;
  59.             dataGridView1.Columns[3].HeaderText = "Status";
  60.             dataGridView1.Columns[3].Width = 100;
  61.             dataGridView1.Columns[4].HeaderText = "Alamat";
  62.             dataGridView1.Columns[4].Width = 200;
  63.         }
  64.  
  65.         private void bttutup_Click(object sender, EventArgs e)
  66.         {
  67.             if (MessageBox.Show("Apakah Anda yakin akan menutup menu Pasien?", "Pesan",
  68.                   MessageBoxButtons.OKCancel,
  69.                   MessageBoxIcon.Question) == DialogResult.OK)
  70.                 Close();
  71.         }
  72.  
  73.         private void btsimpan_Click(object sender, EventArgs e)
  74.         {
  75.             tyo.cmd = new OleDbCommand
  76.                  ("select * from pasien where kd_pasien =\'" + tbkodepasien.Text + "\'", tyo.con);
  77.             tyo.dtr = tyo.cmd.ExecuteReader();
  78.  
  79.             if (tyo.dtr.HasRows)
  80.             {
  81.                 MessageBox.Show("kode tersebut sudah ada", "pesan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  82.                 tbkodepasien.Clear();
  83.                 tbkodepasien.Focus();
  84.             }
  85.             else if (tbkodepasien.Text.Trim() == "")
  86.             {
  87.                 MessageBox.Show("kd_pasien masih kosong", "pesan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  88.                 tbkodepasien.Clear();
  89.                 tbkodepasien.Focus();
  90.             }
  91.             else
  92.             {
  93.                 tyo.cmd = new OleDbCommand
  94.                     ("insert into pasien (kd_pasien,nm_pasien,jns_kel,status,alamat)" +
  95.                     "values(\'" + tbkodepasien.Text + "\'," +
  96.                     "\'" + tbnamapasien.Text + "\'," +
  97.                     "\'" + cbjeniskelamin.Text + "\'," +
  98.                     "\'" + cbstatus.Text + "\'," +
  99.                     "\'" + tbalamat.Text + "\')", tyo.con);
  100.                 tyo.cmd.ExecuteNonQuery();
  101.                 ambildata();
  102.  
  103.                 MessageBox.Show("Data udah disimpan", "pesan",
  104.                     MessageBoxButtons.OK,
  105.                     MessageBoxIcon.Information);
  106.                 bersih();
  107.             }
  108.         }
  109.  
  110.         private void bthapus_Click(object sender, EventArgs e)
  111.         {
  112.             int brs;
  113.             string kode;
  114.  
  115.             brs = dataGridView1.CurrentRow.Index;
  116.             kode = dataGridView1[0, brs].Value.ToString();
  117.  
  118.             if (MessageBox.Show("Apakah kd_pasien =" + kode + "\\n" +
  119.                               "ingin dihapus?", "Pesan",
  120.                     MessageBoxButtons.OKCancel,
  121.                     MessageBoxIcon.Question) == DialogResult.OK)
  122.             {
  123.  
  124.                 tyo.cmd = new OleDbCommand
  125.                     ("delete from PASIEN where kd_pasien=\'" + kode + "\'", tyo.con);
  126.                 tyo.cmd.ExecuteNonQuery();
  127.                 ambildata();
  128.  
  129.                 MessageBox.Show("Data sudah terhapus", "Pesan",
  130.                    MessageBoxButtons.OK,
  131.                    MessageBoxIcon.Information);
  132.             }
  133.         }
  134.  
  135.         private void btkoreksi_Click(object sender, EventArgs e)
  136.         {
  137.             if (btkoreksi.Text == "Koreksi")
  138.             {
  139.                 btkoreksi.Text = "Simpan Perubahan";
  140.                 btsimpan.Enabled = false;
  141.                 bthapus.Enabled = false;
  142.                 tbkodepasien.Enabled = false;
  143.  
  144.                 int brsh;
  145.                 brsh = dataGridView1.CurrentRow.Index;
  146.                 tbkodepasien.Text = dataGridView1[0, brsh].Value.ToString();
  147.                 tbnamapasien.Text = dataGridView1[1, brsh].Value.ToString();
  148.                 cbjeniskelamin.Text = dataGridView1[2, brsh].Value.ToString();
  149.                 cbstatus.Text = dataGridView1[3, brsh].Value.ToString();
  150.                 tbalamat.Text = dataGridView1[4, brsh].Value.ToString();
  151.  
  152.             }
  153.             else if (btkoreksi.Text == "Simpan Perubahan")
  154.             {
  155.                 btkoreksi.Text = "Koreksi";
  156.                 btsimpan.Enabled = true;
  157.                 bthapus.Enabled = true;
  158.                 tbkodepasien.Enabled = true;
  159.  
  160.                 tyo.cmd = new OleDbCommand
  161.                     ("update pasien set " +
  162.                     "nm_pasien  =\'" + tbnamapasien.Text + "\'," +
  163.                     "jns_kel =\'" + cbjeniskelamin.Text + "\'," +
  164.                      "status =\'" + cbstatus.Text + "\'," +
  165.                     "alamat=\'" + tbalamat.Text + "\' where " +
  166.                     "kd_pasien   =\'" + tbkodepasien.Text + "\'", tyo.con);
  167.                
  168.                 tyo.cmd.ExecuteNonQuery();
  169.                 ambildata();
  170.  
  171.                 MessageBox.Show("Data sudah di perbaharui", "Pesan",
  172.                   MessageBoxButtons.OK,
  173.                   MessageBoxIcon.Information);
  174.                 bersih();
  175.             }
  176.         }
  177.  
  178.         private void tbcari_TextChanged(object sender, EventArgs e)
  179.         {
  180.             if (cbpilihan.SelectedIndex == 0)
  181.             {
  182.                 tyo.dapasien = new OleDbDataAdapter
  183.                 ("select * from pasien where kd_pasien like \'%" +
  184.                  tbcari.Text + "%\'", tyo.con);
  185.             }
  186.             else if (cbpilihan.SelectedIndex == 1)
  187.             {
  188.                 tyo.dapasien = new OleDbDataAdapter
  189.                 ("select * from pasien where nm_pasien like \'%" +
  190.                  tbcari.Text + "%\'", tyo.con);
  191.             }
  192.             else if (cbpilihan.SelectedIndex == 2)
  193.             {
  194.                 tyo.dapasien = new OleDbDataAdapter
  195.                 ("select * from pasien where jns_kel like \'%" +
  196.                  tbcari.Text + "%\'", tyo.con);
  197.             }
  198.             else if (cbpilihan.SelectedIndex == 3)
  199.             {
  200.                 tyo.dapasien = new OleDbDataAdapter
  201.                 ("select * from pasien where status like \'%" +
  202.                  tbcari.Text + "%\'", tyo.con);
  203.             }
  204.             else if (cbpilihan.SelectedIndex == 4)
  205.             {
  206.                 tyo.dapasien = new OleDbDataAdapter
  207.                 ("select * from pasien where alamat like \'%" +
  208.                  tbcari.Text + "%\'", tyo.con);
  209.             }
  210.             ambildata();
  211.         }
  212.  
  213.         private void cbpilihan_SelectedIndexChanged(object sender, EventArgs e)
  214.         {
  215.             tbcari.Focus();
  216.         }
  217.  
  218.         private void btbatal_Click(object sender, EventArgs e)
  219.         {
  220.             if (MessageBox.Show("Apakah Anda yakin akan membatalkan input data?", "Pesan",
  221.                   MessageBoxButtons.OKCancel,
  222.                   MessageBoxIcon.Question) == DialogResult.OK)
  223.                 bersih();
  224.             tyo.dapasien = new OleDbDataAdapter
  225.              ("select * from pasien", tyo.con);
  226.             ambildata();
  227.         }
  228.     }
  229. }
');