Esempio n. 1
0
        private static void Main(string[] args)
        {
            so = new SmartCardOperation();
            if (so.IsReaderAvailable())
            {
                so.isoReaderInit();

                var user = Util.ToArrayByte16("ADM001");
                var pass = Util.ToArrayByte32(Encryptor.MD5Hash("ADM001"));

                if (so.WriteBlock(Msb, BlockUsername, user))
                {
                    //Console.WriteLine(user.ToString());
                    Console.WriteLine(Util.ToASCII(so.ReadBlock(Msb, BlockUsername), 0, user.Length));
                }

                if (so.WriteBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo, pass))
                {
                    Console.WriteLine(Util.ToASCII(so.ReadBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo), 0,
                                                   pass.Length));
                }
            }
            else
            {
                Console.WriteLine("Reader not available");
            }

            Console.ReadLine();
        }
Esempio n. 2
0
        private void BtnCetakKartu_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                sp.isoReaderInit();
                //card = new MifareCard(isoReader);

                var id     = "";
                var nama   = "";
                var telp   = "";
                var alamat = "";
                var jenisK = "";

                if (dtgDataApoteker.SelectedItems.Count > 0)
                {
                    foreach (MApoteker data in dtgDataApoteker.SelectedItems)
                    {
                        id     = data.id_apoteker;
                        nama   = data.nama_apoteker;
                        jenisK = data.jenis_kelamin;
                        telp   = data.no_telp;
                        alamat = data.alamat;
                    }
//                    for (var i = 0; i < dtgDataApoteker.SelectedItems.Count; i++)
//                    {
//                        id =
//                            (dtgDataApoteker.SelectedCells[0].Column
//                                .GetCellContent(dtgDataApoteker.SelectedItems[i]) as TextBlock)
//                            .Text;
//                        nama =
//                            (dtgDataApoteker.SelectedCells[1].Column
//                                .GetCellContent(dtgDataApoteker.SelectedItems[i]) as TextBlock)
//                            .Text;
//                        jenisK =
//                            (dtgDataApoteker.SelectedCells[2].Column
//                                .GetCellContent(dtgDataApoteker.SelectedItems[i]) as TextBlock)
//                            .Text;
//                        telp =
//                            (dtgDataApoteker.SelectedCells[3].Column
//                                .GetCellContent(dtgDataApoteker.SelectedItems[i]) as TextBlock)
//                            .Text;
//                        alamat =
//                            (dtgDataApoteker.SelectedCells[4].Column
//                                .GetCellContent(dtgDataApoteker.SelectedItems[i]) as TextBlock)
//                            .Text;
//                    }

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (sp.WriteBlock(Msb, BlockId, Util.ToArrayByte16(id)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Id gagal ditulis.");
                        }
                    }

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

                    if (!string.IsNullOrEmpty(nama))
                    {
                        if (sp.WriteBlockRange(Msb, BlockNamaFrom, BlockNamaTo, Util.ToArrayByte48(nama)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Nama gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(telp))
                    {
                        if (sp.WriteBlock(Msb, BlockTelp, Util.ToArrayByte16(telp)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("telp gagal ditulis.");
                        }
                    }

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

                    if (!string.IsNullOrEmpty(alamat))
                    {
                        if (sp.WriteBlockRange(Msb, BlockAlamatFrom, BlockAlamatTo, Util.ToArrayByte64(alamat)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("alamat gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(jenisK))
                    {
                        if (sp.WriteBlock(Msb, BlockJenisKelamin, Util.ToArrayByte16(jenisK)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Jenis kelamin gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (sp.WriteBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo,
                                               Util.ToArrayByte32(Encryptor.MD5Hash(id))))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Password gagal ditulis.");
                        }
                    }

                    MessageBox.Show("Kartu staff berhasil ditulis.", "Informasi", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Pilih data yang ingin di cetak", "Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Terjadi kesalahan, pastikan kartu sudah berada pada jangkauan reader.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                sp.isoReaderInit();
            }
        }
Esempio n. 3
0
        private void AddDokter_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            _mDaftarBaru = new MPendaftaran(" ", " ", " ", " ", " ", " ");

            if (checkTextBoxValue())
            {
                var nama   = txtNamaDokter.Text;
                var id     = txtidDokter.Text.ToUpper();
                var telp   = txtTelpDokter.Text;
                var alamat = TextAlamat.Text;
                var jenisK = cbJenisKelamin.Text;

                if (!Regex.IsMatch(telp, "^[A-Za-z]+$") && Regex.IsMatch(nama, @"^[a-zA-Z\s]*$"))
                {
                    if (cmd.UpdateDataStaff(id, nama, jenisK, telp, alamat))
                    {
                        var isPrinted = false;

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

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

                                    if (!string.IsNullOrEmpty(nama))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockNamaFrom, BlockNamaTo,
                                                               Util.ToArrayByte48(nama)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Nama gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(telp))
                                    {
                                        if (sp.WriteBlock(Msb, BlockTelp, Util.ToArrayByte16(telp)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("telp gagal ditulis.");
                                        }
                                    }

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

                                    if (!string.IsNullOrEmpty(alamat))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockAlamatFrom, BlockAlamatTo,
                                                               Util.ToArrayByte64(alamat)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("alamat gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(jenisK))
                                    {
                                        if (sp.WriteBlock(Msb, BlockJenisKelamin, Util.ToArrayByte16(jenisK)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Jenis kelamin gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(id))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo,
                                                               Util.ToArrayByte32(Encryptor.MD5Hash(id))))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Password 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("Data staff berhasil disimpan.", "Informasi", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                        df.displayDataPendaftar();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Data staff gagal disimpan.", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("No. telepon harus berupa angkat.", "Peringatan", MessageBoxButton.OK,
                                    MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show("Periksa kembali data yang akan di inputkan.", "Informasi", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }

            cbJenisKelamin.SelectedIndex = 0;
            e.Handled = true;
        }
Esempio n. 4
0
        private void AddDokter_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            _mDaftarBaru = new MDokter(" ", " ", " ", " ", " ", " ");

            if (checkTextBoxValue())
            {
                var cbp      = (ComboboxPairs)cbPoliklinik.SelectedItem;
                var policode = cbp.kode_poliklinik;

                var nama         = txtNamaDokter.Text;
                var id           = txtidDokter.Text;
                var telp         = txtTelpDokter.Text;
                var alamat       = TextAlamat.Text;
                var spesialisasi = txtSpesialisai.Text;
                var jenisK       = cbJenisKelamin.Text;

                if (!Regex.IsMatch(telp, "^[A-Za-z]+$") && Regex.IsMatch(nama, @"^[a-zA-Z\s]*$"))
                {
                    if (cmd.UpdateDataDokter(id, nama, alamat, telp, spesialisasi, policode, jenisK))
                    {
                        var isPrited = false;
                        if (chkCetakKartu.IsChecked == true)
                        {
                            while (!isPrited)
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(id))
                                    {
                                        if (sp.WriteBlock(Msb, BlockId, Util.ToArrayByte16(id)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Id gagal ditulis.");
                                        }
                                    }

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

                                    if (!string.IsNullOrEmpty(nama))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockNamaFrom, BlockNamaTo,
                                                               Util.ToArrayByte48(nama)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Nama gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(telp))
                                    {
                                        if (sp.WriteBlock(Msb, BlockTelp, Util.ToArrayByte16(telp)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("telp gagal ditulis.");
                                        }
                                    }

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

                                    if (!string.IsNullOrEmpty(alamat))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockAlamatFrom, BlockAlamatTo,
                                                               Util.ToArrayByte64(alamat)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("alamat gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(jenisK))
                                    {
                                        if (sp.WriteBlock(Msb, BlockJenisKelamin, Util.ToArrayByte16(jenisK)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Jenis kelamin gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(id))
                                    {
                                        if (sp.WriteBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo,
                                                               Util.ToArrayByte32(Encryptor.MD5Hash(id))))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Password gagal ditulis.");
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(spesialisasi))
                                    {
                                        if (sp.WriteBlock(Msb, BlockSpesialisasi, Util.ToArrayByte16(spesialisasi)))
                                        {
                                        }
                                        else
                                        {
                                            MessageBox.Show("Spesialis gagal ditulis.");
                                        }
                                    }

                                    isPrited = true;
                                    if (isPrited)
                                    {
                                        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("Berhasil memperbarui data dokter", "Informasi", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                        dd.displayDataDokter();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Gagal memperbarui data dokter", "Error", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Periksa kembali data yang akan di inputkan.", "Peringatan", MessageBoxButton.OK,
                                    MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show("Periksa kembali data yang akan di inputkan.", "Informasi", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }

            //DataContext = _mDaftarBaru;
            e.Handled = true;
        }
Esempio n. 5
0
        private void Btn_cetak_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                sp.isoReaderInit();
                //card = new MifareCard(isoReader);

                var ci = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
                ci.DateTimeFormat.ShortDatePattern  = "yyyy-MM-dd";
                Thread.CurrentThread.CurrentCulture = ci;

                if (dtgDataPasien.SelectedItems.Count > 0)
                {
                    //for (var i = 0; i < dtgDataPasien.SelectedItems.Count; i++)
                    //{
                    //    normP =
                    //        (dtgDataPasien.SelectedCells[1].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    noidP =
                    //        (dtgDataPasien.SelectedCells[0].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    namaP =
                    //        (dtgDataPasien.SelectedCells[2].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    golDarah =
                    //        (dtgDataPasien.SelectedCells[3].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    jenisK =
                    //        (dtgDataPasien.SelectedCells[4].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    noTelp =
                    //        (dtgDataPasien.SelectedCells[5].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    alamat =
                    //        (dtgDataPasien.SelectedCells[6].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //    tglLahir =
                    //        (dtgDataPasien.SelectedCells[7].Column
                    //            .GetCellContent(dtgDataPasien.SelectedItems[i]) as TextBlock)
                    //        .Text;
                    //}

                    foreach (ModelPasien data in dtgDataPasien.SelectedItems)
                    {
                        normP    = data.no_rekam_medis;
                        noidP    = data.no_identitas;
                        namaP    = data.nama;
                        golDarah = data.golongan_darah;
                        jenisK   = data.jenis_kelamin;
                        noTelp   = data.no_telp;
                        alamat   = data.alamat;
                        tglLahir = data.tanggal_lahir;
                        jenisId  = data.jenis_id;
                    }

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

                    if (!string.IsNullOrEmpty(noidP))
                    {
                        if (sp.WriteBlock(Msb, blockIdPasien, Util.ToArrayByte16(noidP)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("ID pasien gagal ditulis");
                        }
                    }

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

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

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

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

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

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

                    if (!string.IsNullOrEmpty(noTelp))
                    {
                        if (sp.WriteBlock(Msb, blockNoTelp, Util.ToArrayByte16(noTelp)))
                        {
                        }
                        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)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Alamat pasien gagal ditulis");
                        }
                    }

                    MessageBox.Show("Data pasien berhasil ditulis", "Informasi", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Pilih data yang ingin dicetak", "Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Terjadi kesalahan, pastikan kartu sudah berada pada jangkauan reader.",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                sp.isoReaderInit();
            }
        }
Esempio n. 6
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;
        }
Esempio n. 7
0
        private void BtnCetakKartu_Click(object sender, RoutedEventArgs e)
        {
            sp.isoReaderInit();
            try
            {
                var id            = "";
                var nama          = "";
                var alamat        = "";
                var telp          = "";
                var jenis_kelamin = "";
                var password      = "";

                if (dtgDataKeuangan.SelectedItems.Count == 1)
                {
                    foreach (ModelKeuangan ku in dtgDataKeuangan.SelectedItems)
                    {
                        id            = ku.id;
                        nama          = ku.nama;
                        alamat        = ku.alamat;
                        telp          = ku.telp;
                        jenis_kelamin = ku.jenis_kelamin;
                        password      = Encryptor.MD5Hash(id);
                    }

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (sp.WriteBlock(Msb, BlockId, Util.ToArrayByte16(id)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Id gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(nama))
                    {
                        if (sp.WriteBlockRange(Msb, BlockNamaFrom, BlockNamaTo, Util.ToArrayByte48(nama)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Nama gagal ditulis.");
                        }
                    }

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

                    if (!string.IsNullOrEmpty(alamat))
                    {
                        if (sp.WriteBlockRange(Msb, BlockAlamatFrom, BlockAlamatTo, Util.ToArrayByte64(alamat)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Alamat gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(telp))
                    {
                        if (sp.WriteBlock(Msb, BlockTelp, Util.ToArrayByte16(telp)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Telp gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(jenis_kelamin))
                    {
                        if (sp.WriteBlock(Msb, BlockJenisKelamin, Util.ToArrayByte16(jenis_kelamin)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Jenis kelamin gagal ditulis.");
                        }
                    }

                    if (!string.IsNullOrEmpty(password))
                    {
                        if (sp.WriteBlockRange(Msb, BlockPasswordFrom, BlockPasswordTo, Util.ToArrayByte32(password)))
                        {
                        }
                        else
                        {
                            MessageBox.Show("Password gagal ditulis.");
                        }
                    }

                    MessageBox.Show("Kartu staff berhasil ditulis.", "Informasi", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Pilih data yang ingin di cetak", "Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Terjadi kesalahan, pastikan kartu sudah berada pada jangkauan reader.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                sp.isoReaderInit();
            }
        }