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 FrmAdm : Form
  15.     {
  16.         double vbiaya;
  17.  
  18.         public FrmAdm()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         void ambildata()
  24.         {
  25.             tyo.tbladm.Clear();
  26.             tyo.daadm.Fill(tyo.tbladm);
  27.         }
  28.  
  29.         void bersih()
  30.         {
  31.             tbkodeadministrasi.Clear();
  32.             tanggal.Value = DateTime.Now;
  33.  
  34.             cbkodepasien.Text = "";
  35.             tbnamapasien.Clear();
  36.             tbjeniskelamin.Clear();
  37.             tbstatus.Clear();
  38.             tbalamat.Clear();
  39.  
  40.             cbkodedokter.Text = "";
  41.             tbnamadokter.Clear();
  42.             tbspesialis.Clear();
  43.             tbtelpon.Clear();
  44.  
  45.             tbbiaya.Clear();
  46.             tbkodeadministrasi.Focus();
  47.         }
  48.  
  49.         private void FrmAdm_Load(object sender, EventArgs e)
  50.         {
  51.             this.KeyPreview = true;
  52.  
  53.             tyo.con = tyo.konek_db();
  54.             tyo.daadm = new OleDbDataAdapter
  55.                 ("select * from administrasi", tyo.con);
  56.             ambildata();
  57.  
  58.             dataGridView1.DataSource = tyo.tbladm;
  59.             dataGridView1.ReadOnly = true;
  60.             dataGridView1.AllowUserToAddRows = false;
  61.  
  62.             dataGridView1.Columns[0].HeaderText = "Kode Adm";
  63.             dataGridView1.Columns[0].Width = 100;
  64.  
  65.             dataGridView1.Columns[1].HeaderText = "Tanggal";
  66.             dataGridView1.Columns[1].Width = 130;
  67.             dataGridView1.Columns[1].DefaultCellStyle.Format = "dd MMMM yyyy";
  68.  
  69.             dataGridView1.Columns[2].HeaderText = "Kode Pasien";
  70.             dataGridView1.Columns[2].Width = 120;
  71.  
  72.             dataGridView1.Columns[3].HeaderText = "Kode Dokter";
  73.             dataGridView1.Columns[3].Width = 120;
  74.  
  75.             dataGridView1.Columns[4].HeaderText = "Biaya";
  76.             dataGridView1.Columns[4].Width = 150;
  77.             dataGridView1.Columns[4].DefaultCellStyle.Format = "Rp ##,##0";
  78.  
  79.             //mengambil kode pasien dari tabel pasien
  80.             cbkodepasien.Items.Clear();
  81.             tyo.cmd = new OleDbCommand
  82.                 ("select * from pasien", tyo.con);
  83.             tyo.dtr = tyo.cmd.ExecuteReader();
  84.             while (tyo.dtr.Read())
  85.             {
  86.                 cbkodepasien.Items.Add(tyo.dtr["kd_pasien"].ToString());
  87.             }
  88.  
  89.             //mengambil kode dokter dari tabel dokter
  90.             cbkodedokter.Items.Clear();
  91.             tyo.cmd = new OleDbCommand
  92.                 ("select * from dokter", tyo.con);
  93.             tyo.dtr = tyo.cmd.ExecuteReader();
  94.             while (tyo.dtr.Read())
  95.             {
  96.                 cbkodedokter.Items.Add(tyo.dtr["kd_dokter"].ToString());
  97.             }
  98.         }
  99.  
  100.         private void btcekpasien_Click(object sender, EventArgs e)
  101.         {
  102.             //menampilkan data pasien berdasarkan kode pasien
  103.             tyo.cmd = new OleDbCommand
  104.                 ("select * from pasien where kd_pasien='" + cbkodepasien.Text + "'", tyo.con);
  105.             tyo.dtr = tyo.cmd.ExecuteReader();
  106.             tyo.dtr.Read();
  107.  
  108.             if (tyo.dtr.HasRows)
  109.             {
  110.                 tbnamapasien.Text = tyo.dtr["nm_pasien"].ToString();
  111.                 tbjeniskelamin.Text = tyo.dtr["jns_kel"].ToString();
  112.                 tbstatus.Text = tyo.dtr["status"].ToString();
  113.                 tbalamat.Text = tyo.dtr["alamat"].ToString();
  114.                 cbkodedokter.Focus();
  115.             }
  116.             else
  117.             {
  118.                 MessageBox.Show("kode pasien tersebut tidak ada", "Pesan",
  119.                  MessageBoxButtons.OK,
  120.                  MessageBoxIcon.Exclamation);
  121.                 cbkodepasien.Text = "";
  122.                 tbnamapasien.Clear();
  123.                 tbjeniskelamin.Clear();
  124.                 tbstatus.Clear();
  125.                 tbalamat.Clear();
  126.                 cbkodepasien.Focus();
  127.             }
  128.         }
  129.  
  130.         private void btcekdokter_Click(object sender, EventArgs e)
  131.         {
  132.             //menampilkan data dokter berdasarkan kode dokter
  133.             tyo.cmd = new OleDbCommand
  134.                 ("select * from dokter where kd_dokter='" +
  135.                 cbkodedokter.Text + "'", tyo.con);
  136.  
  137.             tyo.dtr = tyo.cmd.ExecuteReader();
  138.             tyo.dtr.Read();
  139.             if (tyo.dtr.HasRows)
  140.             {
  141.                 tbnamadokter.Text = tyo.dtr["nm_dokter"].ToString();
  142.                 tbspesialis.Text = tyo.dtr["spesialis"].ToString();
  143.                 tbtelpon.Text = tyo.dtr["tlp"].ToString();
  144.                 tbbiaya.Focus();
  145.             }
  146.             else
  147.             {
  148.                 MessageBox.Show("kode dokter tersebut tidak ada", "Pesan",
  149.                  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  150.                 cbkodedokter.Text = "";
  151.                 tbnamadokter.Clear();
  152.                 tbspesialis.Clear();
  153.                 tbtelpon.Clear();
  154.                 cbkodedokter.Focus();
  155.             }
  156.         }
  157.  
  158.         private void tbbiaya_KeyPress(object sender, KeyPressEventArgs e)
  159.         {
  160.             if (char.IsDigit(e.KeyChar) == false &&
  161.                 (int)e.KeyChar != (int)Keys.Back &&
  162.                 (int)e.KeyChar != (int)Keys.Enter)
  163.             {
  164.                 e.Handled = true;
  165.             }
  166.         }
  167.  
  168.         private void tbbiaya_KeyDown(object sender, KeyEventArgs e)
  169.         {
  170.             if (e.KeyCode == Keys.Enter)
  171.             {
  172.                 SendKeys.Send("{TAB}");
  173.             }
  174.         }
  175.  
  176.         private void tbbiaya_TextChanged(object sender, EventArgs e)
  177.         {
  178.             if (tbbiaya.Text != "")
  179.             {
  180.                 vbiaya = double.Parse(tbbiaya.Text);
  181.                 tbbiaya.Text = vbiaya.ToString("#,##0");
  182.                 tbbiaya.SelectionStart = tbbiaya.Text.Length;
  183.             }
  184.         }
  185.  
  186.         private void bttutup_Click(object sender, EventArgs e)
  187.         {
  188.             if (MessageBox.Show("Apakah Anda yakin akan menutup menu Administrasi?", "Pesan",
  189.                     MessageBoxButtons.OKCancel,
  190.                     MessageBoxIcon.Question) == DialogResult.OK)
  191.  
  192.                 Close();
  193.         }
  194.  
  195.         private void btsimpan_Click(object sender, EventArgs e)
  196.         {
  197.             tyo.cmd = new OleDbCommand
  198.            ("select * from administrasi where kd_adm='" + tbkodeadministrasi.Text + "'", tyo.con);
  199.             tyo.dtr = tyo.cmd.ExecuteReader();
  200.  
  201.             if (tyo.dtr.HasRows)
  202.             {
  203.                 MessageBox.Show("kode Adm sudah ada", "Pesan",
  204.                     MessageBoxButtons.OK,
  205.                     MessageBoxIcon.Exclamation);
  206.                 tbkodeadministrasi.Clear();
  207.                 tbkodeadministrasi.Focus();
  208.             }
  209.             else if (tbkodeadministrasi.Text.Trim() == "")
  210.             {
  211.                 MessageBox.Show("kode Adm masih kosong", "Pesan",
  212.                     MessageBoxButtons.OK,
  213.                     MessageBoxIcon.Exclamation);
  214.                 tbkodeadministrasi.Clear();
  215.                 tbkodeadministrasi.Focus();
  216.             }
  217.             else if (tbnamapasien.Text.Trim() == "")
  218.             {
  219.                 MessageBox.Show("Cek data pasiennya", "Pesan",
  220.                     MessageBoxButtons.OK,
  221.                     MessageBoxIcon.Exclamation);
  222.                 cbkodepasien.Focus();
  223.             }
  224.             else if (tbnamadokter.Text.Trim() == "")
  225.             {
  226.                 MessageBox.Show("Cek data dokternya", "Pesan",
  227.                     MessageBoxButtons.OK,
  228.                     MessageBoxIcon.Exclamation);
  229.                 cbkodedokter.Focus();
  230.             }
  231.             else if (tbbiaya.Text.Trim() == "")
  232.             {
  233.                 MessageBox.Show("biaya masih kosong", "Pesan",
  234.                     MessageBoxButtons.OK,
  235.                     MessageBoxIcon.Exclamation);
  236.                 tbbiaya.Focus();
  237.             }
  238.             else
  239.             {
  240.                 tyo.cmd = new OleDbCommand
  241.                     ("insert into administrasi" +
  242.                      "(kd_adm,tgl,kd_pasien,kd_dokter,biaya) " +
  243.                      "values ('" + tbkodeadministrasi.Text + "'," +
  244.                              "'" + tanggal.Value.Date + "'," +
  245.                              "'" + cbkodepasien.Text + "'," +
  246.                              "'" + cbkodedokter.Text + "'," +
  247.                              "'" + vbiaya + "')", tyo.con);
  248.                 tyo.cmd.ExecuteNonQuery();
  249.                 ambildata();
  250.  
  251.                 MessageBox.Show("Data sudah tersimpan", "Pesan",
  252.                    MessageBoxButtons.OK,
  253.                    MessageBoxIcon.Information);
  254.                 bersih();
  255.             }
  256.         }
  257.  
  258.         private void cbpilihan_SelectedIndexChanged(object sender, EventArgs e)
  259.         {
  260.             tbcari.Focus();
  261.         }
  262.  
  263.         private void bthapus_Click(object sender, EventArgs e)
  264.         {
  265.             int brs;
  266.             string kode;
  267.  
  268.             brs = dataGridView1.CurrentRow.Index;
  269.             kode = dataGridView1[0, brs].Value.ToString();
  270.  
  271.             if (MessageBox.Show("Apakah Kode Administrasi " + kode + "\n" +
  272.                               "ingin dihapus?", "Pesan",
  273.                     MessageBoxButtons.OKCancel,
  274.                     MessageBoxIcon.Question) == DialogResult.OK)
  275.             {
  276.  
  277.                 tyo.cmd = new OleDbCommand
  278.                     ("delete from administrasi where kd_adm='" + kode + "'", tyo.con);
  279.                 tyo.cmd.ExecuteNonQuery();
  280.                 ambildata();
  281.  
  282.                 MessageBox.Show("Data sudah terhapus", "Pesan",
  283.                    MessageBoxButtons.OK,
  284.                    MessageBoxIcon.Information);
  285.             }
  286.         }
  287.  
  288.         private void btkoreksi_Click(object sender, EventArgs e)
  289.         {
  290.             if (btkoreksi.Text == "Koreksi")
  291.             {
  292.                 btkoreksi.Text = "Simpan Perubahan";
  293.                 btsimpan.Enabled = false;
  294.                 bthapus.Enabled = false;
  295.                 tbkodeadministrasi.Enabled = false;
  296.  
  297.                 int brsh;
  298.                 brsh = dataGridView1.CurrentRow.Index;
  299.                 tbkodeadministrasi.Text = dataGridView1[0, brsh].Value.ToString();
  300.                 tanggal.Text = dataGridView1[1, brsh].Value.ToString();
  301.                 cbkodepasien.Text = dataGridView1[2, brsh].Value.ToString();
  302.                 cbkodedokter.Text = dataGridView1[3, brsh].Value.ToString();
  303.                 tbbiaya.Text = dataGridView1[4, brsh].Value.ToString();
  304.  
  305.             }
  306.             else if (btkoreksi.Text == "Simpan Perubahan")
  307.             {
  308.                 btkoreksi.Text = "Koreksi";
  309.                 btsimpan.Enabled = true;
  310.                 bthapus.Enabled = true;
  311.                 tbkodeadministrasi.Enabled = true;
  312.  
  313.                 tyo.cmd = new OleDbCommand
  314.                     ("update administrasi set " +
  315.                     "tgl ='" +  DateTime.Now + "'," +
  316.                     "kd_pasien ='" + cbkodepasien.Text  + "'," +
  317.                     "kd_dokter ='" + cbkodedokter.Text  + "'," +
  318.                     "biaya ='" + vbiaya + "' where " +
  319.                     "kd_adm   ='" + tbkodeadministrasi.Text + "'", tyo.con);
  320.  
  321.                 tyo.cmd.ExecuteNonQuery();
  322.                 ambildata();
  323.  
  324.                 MessageBox.Show("Data sudah di Perbaharui", "Pesan",
  325.                   MessageBoxButtons.OK,
  326.                   MessageBoxIcon.Information);
  327.                 bersih();
  328.             }
  329.         }
  330.  
  331.         private void tbcari_TextChanged_1(object sender, EventArgs e)
  332.         {
  333.             if (cbpilihan.SelectedIndex == 0)
  334.             {
  335.                 tyo.daadm = new OleDbDataAdapter
  336.                  ("select * from administrasi where kd_adm like '%" +
  337.                  tbcari.Text + "%'", tyo.con);
  338.             }
  339.             else if (cbpilihan.SelectedIndex == 1)
  340.             {
  341.                 tyo.daadm = new OleDbDataAdapter
  342.                  ("select * from administrasi where tgl like '%" +
  343.                  tbcari.Text + "%'", tyo.con);
  344.             }
  345.             else if (cbpilihan.SelectedIndex == 2)
  346.             {
  347.                 tyo.daadm = new OleDbDataAdapter
  348.                  ("select * from administrasi where kd_pasien like '%" +
  349.                  tbcari.Text + "%'", tyo.con);
  350.             }
  351.             else if (cbpilihan.SelectedIndex == 3)
  352.             {
  353.                 tyo.daadm = new OleDbDataAdapter
  354.                  ("select * from administrasi where kd_dokter like '%" +
  355.                  tbcari.Text + "%'", tyo.con);
  356.             }
  357.             else if (cbpilihan.SelectedIndex == 4)
  358.             {
  359.                 tyo.daadm = new OleDbDataAdapter
  360.                  ("select * from administrasi where biaya like '%" +
  361.                  tbcari.Text + "%'", tyo.con);
  362.             }
  363.             ambildata();
  364.         }
  365.  
  366.         private void btbatal_Click(object sender, EventArgs e)
  367.         {
  368.             if (MessageBox.Show("Apakah Anda yakin akan membatalkan input data?", "Pesan",
  369.                     MessageBoxButtons.OKCancel,
  370.                     MessageBoxIcon.Question) == DialogResult.OK)
  371.             {
  372.                 bersih();
  373.             }
  374.         }
  375.  
  376.         private void cbkodepasien_KeyDown(object sender, KeyEventArgs e)
  377.         {
  378.             if (e.KeyCode == Keys.Enter)
  379.             {
  380.                 SendKeys.Send("{TAB}");
  381.             }
  382.         }
  383.  
  384.         private void tbkodeadministrasi_KeyDown(object sender, KeyEventArgs e)
  385.         {
  386.             if (e.KeyCode == Keys.Enter)
  387.             {
  388.                 SendKeys.Send("{TAB}");
  389.             }
  390.         }
  391.  
  392.         private void cbkodedokter_KeyDown(object sender, KeyEventArgs e)
  393.         {
  394.             if (e.KeyCode == Keys.Enter)
  395.             {
  396.                 SendKeys.Send("{TAB}");
  397.             }
  398.         }
  399.     }
  400. }