private void tambah_antrian(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtIdPasien.Text) && !string.IsNullOrEmpty(txtIdPasien.Text) &&
                cbPoliklinik.SelectedIndex != 0)
            {
                var cbp      = (ComboboxPairs)cbPoliklinik.SelectedItem;
                var policode = cbp.nama_poliklinik;
                var norm     = txtIdPasien.Text;
                var no_urut  = 0;

                var cmd = new DBCommand(conn);

                if (cmd.CountRmPasienExists(norm) == 1)
                {
                    var last = cmd.GetLastNoUrut(policode);

                    if (last == 0)
                    {
                        no_urut = 1;
                    }
                    else
                    {
                        no_urut = last + 1;
                    }

                    this.no_urut = no_urut;
                    poli         = cbp.kode_poliklinik;

                    if (cmd.InsertAntrian(norm, no_urut, policode))
                    {
                        MessageBox.Show("Pasien berhasil didaftarkan.\nNomor Antri: " + no_urut, "Informasi",
                                        MessageBoxButton.OK, MessageBoxImage.Information);
                        txtIdPasien.Text           = "";
                        cbPoliklinik.SelectedIndex = 0;

                        try
                        {
                            sck.Send(Encoding.ASCII.GetBytes("Update"));
                        }
                        catch (Exception)
                        {
                        }

                        var pd = new PrintDocument();
                        var ps = new PaperSize("", 300, 540);

                        pd.PrintPage      += Pd_PrintPage;
                        pd.PrintController = new StandardPrintController();
                        pd.DefaultPageSettings.Margins.Left   = 0;
                        pd.DefaultPageSettings.Margins.Right  = 0;
                        pd.DefaultPageSettings.Margins.Top    = 0;
                        pd.DefaultPageSettings.Margins.Bottom = 0;
                        pd.DefaultPageSettings.PaperSize      = ps;
                        pd.Print();
                    }
                    else
                    {
                        MessageBox.Show("Pasien gagal didaftarkan.", "Informasi", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Rekam medis pasien belum teraftar, periksa kembali data pasien.", "Perhatian",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show("Isikan data dengan benar, pastikan semua data telah benar.", "Perhatian",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Beispiel #2
0
        private void AddPasien_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            _mDaftarBaru = new MDaftarBaru(" ", " ", " ", " ", " ");
            var ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);

            ci.DateTimeFormat.ShortDatePattern  = "yyyy-MM-dd";
            Thread.CurrentThread.CurrentCulture = ci;

            var cmd = new DBCommand(conn);

            if (checkTextBoxValue() && dtTanggalLahir.SelectedDate != null)
            {
                var cbp      = (ComboboxPairs)cbPoliklinik.SelectedItem;
                var policode = cbp.nama_poliklinik;
                //DateTime dt = DateTime.ParseExact(, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                var norm = TxtNoRm.Text.ToUpper();
                no_rm = norm;
                var identitas    = TxtNoIdentitas.Text;
                var namaPasien   = TxtNamaPasien.Text;
                var noTelp       = TxtNoTelp.Text;
                var alamat       = TextAlamat.Text;
                var tglLahir     = dtTanggalLahir.SelectedDate.Value.Date.ToString("yyyy-MM-dd");
                var jenisKelamin = cbJenisKelamin.Text;
                var poliklinik   = policode;
                var golDarah     = cbGolDarah.Text;
                var jenis_id     = "";

                Debug.WriteLine(norm.Length);
                Debug.WriteLine(identitas.Length);
                Debug.WriteLine(namaPasien.Length);
                Debug.WriteLine(noTelp.Length);
                Debug.WriteLine(alamat.Length);
                Debug.WriteLine(jenisKelamin.Length);
                Debug.WriteLine(poliklinik.Length);
                Debug.WriteLine(golDarah.Length);


                if (chkKtp.IsChecked ?? true)
                {
                    jenis_id = chkKtp.Content.ToString();
                }

                if (chkSim.IsChecked ?? true)
                {
                    jenis_id = chkSim.Content.ToString();
                }

                if (chkKartuPelajar.IsChecked ?? true)
                {
                    jenis_id = chkKartuPelajar.Content.ToString();
                }

                if (chkLainnya.IsChecked ?? true)
                {
                    jenis_id = chkLainnya.Content.ToString();
                }

                if (!Regex.IsMatch(identitas, "^[A-Za-z]+$") && !Regex.IsMatch(noTelp, "^[A-Za-z]+$") &&
                    Regex.IsMatch(namaPasien, @"^[a-zA-Z\s]*$"))
                {
                    if (cmd.CountIdPasienExists(identitas) != 1)
                    {
                        if (cmd.CountRmPasienExists(norm) != 1)
                        {
                            if (cmd.InsertDataPasien(identitas, norm, namaPasien, tglLahir, jenisKelamin, noTelp,
                                                     alamat,
                                                     golDarah, jenis_id))
                            {
                                var last    = cmd.GetLastNoUrut(policode);
                                var no_urut = 0;

                                if (last == 0)
                                {
                                    no_urut = 1;
                                }
                                else
                                {
                                    no_urut = last + 1;
                                }

                                this.no_urut = no_urut;
                                poli         = cbp.kode_poliklinik;

                                if (cmd.InsertAntrian(norm, no_urut, policode))
                                {
                                    var isPrinted = false;

                                    if (chkCetakKartu.IsChecked == true)
                                    {
                                        while (!isPrinted)
                                        {
                                            try
                                            {
                                                if (!string.IsNullOrEmpty(identitas))
                                                {
                                                    if (sp.WriteBlock(Msb, blockIdPasien,
                                                                      Util.ToArrayByte16(identitas)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("ID pasien gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(jenis_id))
                                                {
                                                    if (sp.WriteBlock(Msb, blockJenisId, Util.ToArrayByte16(jenis_id)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Jenis Identitas pasien gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(golDarah))
                                                {
                                                    if (sp.WriteBlock(Msb, blockGolDarah,
                                                                      Util.ToArrayByte16(" " + golDarah)))
                                                    {
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Golongan Darah gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(norm))
                                                {
                                                    if (sp.WriteBlock(Msb, blockNoRekamMedis, Util.ToArrayByte16(norm)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Nomor rekam medis gagal ditulis");
                                                    }
                                                }

                                                if (namaPasien.Length > 48)
                                                {
                                                    namaPasien = namaPasien.Substring(0, 47);
                                                }

                                                if (!string.IsNullOrEmpty(namaPasien))
                                                {
                                                    if (sp.WriteBlockRange(Msb, blockNamaFrom, blockNamaTo,
                                                                           Util.ToArrayByte48(namaPasien)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Nama pasien gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(tglLahir))
                                                {
                                                    if (sp.WriteBlock(Msb, blockTglLahir, Util.ToArrayByte16(tglLahir)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Tanggal lahir pasien gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(jenisKelamin))
                                                {
                                                    if (sp.WriteBlock(Msb, blockJenisKelamin,
                                                                      Util.ToArrayByte16(jenisKelamin)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Jenis kelamin pasien gagal ditulis");
                                                    }
                                                }

                                                if (!string.IsNullOrEmpty(noTelp))
                                                {
                                                    if (sp.WriteBlock(Msb, blockNoTelp, Util.ToArrayByte16(noTelp)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Nomor telepon pasien gagal ditulis");
                                                    }
                                                }

                                                if (alamat.Length > 64)
                                                {
                                                    alamat = alamat.Substring(0, 63);
                                                }

                                                if (!string.IsNullOrEmpty(alamat))
                                                {
                                                    if (sp.WriteBlockRange(Msb, blockAlamatForm, blockAlamatTo,
                                                                           Util.ToArrayByte64(alamat)))
                                                    {
                                                        isPrinted = true;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Alamat pasien gagal ditulis");
                                                    }
                                                }

                                                isPrinted = true;
                                                if (isPrinted)
                                                {
                                                    break;
                                                }
                                            }
                                            catch (Exception)
                                            {
                                                var ans = MessageBox.Show(
                                                    "Penulisan kartu gagal, pastikan kartu sudah berada pada jangkauan reader.\nApakah anda ingin menulis kartu lain kali?",
                                                    "Error",
                                                    MessageBoxButton.YesNo, MessageBoxImage.Error);

                                                if (ans == MessageBoxResult.Yes)
                                                {
                                                    break;
                                                }

                                                sp.isoReaderInit();
                                            }
                                        }

                                        MessageBox.Show(
                                            "Pasien berhasil didaftarkan.\nKartu pasien berhasil ditulis.\nNomor Antri: " +
                                            no_urut + "", "Informasi", MessageBoxButton.OK,
                                            MessageBoxImage.Information);
                                        DataContext = _mDaftarBaru;
                                        cbPoliklinik.SelectedIndex   = 0;
                                        cbGolDarah.SelectedIndex     = 0;
                                        cbJenisKelamin.SelectedIndex = 0;
                                        cbPoliklinik.SelectedIndex   = 0;

                                        var pd = new PrintDocument();
                                        var ps = new PaperSize("", 300, 540);

                                        pd.PrintPage      += Pd_PrintPage;
                                        pd.PrintController = new StandardPrintController();
                                        pd.DefaultPageSettings.Margins.Left   = 0;
                                        pd.DefaultPageSettings.Margins.Right  = 0;
                                        pd.DefaultPageSettings.Margins.Top    = 0;
                                        pd.DefaultPageSettings.Margins.Bottom = 0;
                                        pd.DefaultPageSettings.PaperSize      = ps;
                                        pd.Print();

                                        try
                                        {
                                            //sck.Send(Encoding.ASCII.GetBytes("Update"));
                                            //sck2.Send(Encoding.ASCII.GetBytes("Update"));
                                            clientPoli.WriteLine("Update");
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Pasien berhasil didaftarkan.\nNomor Antri: " + no_urut,
                                                        "Informasi", MessageBoxButton.OK, MessageBoxImage.Information);
                                        DataContext                  = _mDaftarBaru;
                                        dtTanggalLahir.Text          = string.Empty;
                                        cbGolDarah.SelectedIndex     = 0;
                                        cbJenisKelamin.SelectedIndex = 0;
                                        cbPoliklinik.SelectedIndex   = 0;

                                        try
                                        {
                                            //sck.Send(Encoding.ASCII.GetBytes("Update"));
                                            //sck2.Send(Encoding.ASCII.GetBytes("Update"));
                                            clientPoli.WriteLine("Update");
                                        }
                                        catch
                                        {
                                        }

                                        var pd = new PrintDocument();
                                        var ps = new PaperSize("", 300, 540);

                                        pd.PrintPage      += Pd_PrintPage;
                                        pd.PrintController = new StandardPrintController();
                                        pd.DefaultPageSettings.Margins.Left   = 0;
                                        pd.DefaultPageSettings.Margins.Right  = 0;
                                        pd.DefaultPageSettings.Margins.Top    = 0;
                                        pd.DefaultPageSettings.Margins.Bottom = 0;
                                        pd.DefaultPageSettings.PaperSize      = ps;
                                        pd.Print();
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Data berhasil didaftarkan.", "Informasi", MessageBoxButton.OK,
                                                    MessageBoxImage.Information);

                                    try
                                    {
                                        //sck.Send(Encoding.ASCII.GetBytes("Update"));
                                        clientPoli.WriteLine("Update");
                                    }
                                    catch
                                    {
                                    }

                                    var pd = new PrintDocument();
                                    var ps = new PaperSize("", 300, 540);

                                    pd.PrintPage      += Pd_PrintPage;
                                    pd.PrintController = new StandardPrintController();
                                    pd.DefaultPageSettings.Margins.Left   = 0;
                                    pd.DefaultPageSettings.Margins.Right  = 0;
                                    pd.DefaultPageSettings.Margins.Top    = 0;
                                    pd.DefaultPageSettings.Margins.Bottom = 0;
                                    pd.DefaultPageSettings.PaperSize      = ps;
                                    pd.Print();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Data pasien gagal didaftartkan.", "Error", MessageBoxButton.OK,
                                                MessageBoxImage.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("No rekam medis sudah terdaftar.", "Informasi", MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("No indentitas sudah terdaftar.", "Informasi", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Harap periksa kembali data yang ingin di inputkan, pastikan semua sudah diisi.",
                                    "Perhatian", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show("Harap periksa kembali data yang ingin di inputkan, pastikan semua sudah diisi.",
                                "Perhatian", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            e.Handled = true;
        }