private void PrintPreview(bool preview, PatientRegistration pr)
        {
            string BranchName    = ConfigurationManager.AppSettings["Name"].ToString();
            string BranchAddress = ConfigurationManager.AppSettings["Address"].ToString();

            prt = new DsPatientRegistration.PatientRegistrationDataTable();
            object[] values = { 0, pr.TokenDate, pr.TokenMonthYear, pr.TokenNumber, pr.Patient.FirstName, pr.Patient.LastName, pr.Patient.NIC, pr.Patient.Address, pr.TokenType, pr.CashReceived, pr.Room.Name, pr.Patient.RegistrationNumber, pr.Patient.RegistrationDate };
            prt.LoadDataRow(values, true);
            rptTokenReceipt crp = new rptTokenReceipt();

            crp.SetDataSource((DataTable)prt);
            crp.SetParameterValue("Duplicate", PrintDuplicate);
            crp.SetParameterValue("Name", BranchName);
            crp.SetParameterValue("Address", BranchAddress);
            FrmReportViewer frmViewer = new FrmReportViewer();

            frmViewer.crystalReportViewer1.ReportSource = crp;
            if (preview)
            {
                frmViewer.ShowDialog();
            }
            else
            {
                //frmViewer.crystalReportViewer1.RefreshReport();
                frmViewer.crystalReportViewer1.PrintReport();
            }
            PrintDuplicate = false;
        }
        private void PrintPreview(bool preview, PatientRegistration pr)
        {
            string BranchName    = ConfigurationManager.AppSettings["Name"].ToString();
            string BranchAddress = ConfigurationManager.AppSettings["Address"].ToString();
            string CompNo        = ConfigurationManager.AppSettings["ComplaintNo"].ToString();

            prt        = new DsPatientRegistration.PatientRegistrationDataTable();///////// Token By Name Added
            pr.TokenBy = IsLoginUser;
            //object[] values = { 0, pr.TokenDate, pr.TokenMonthYear, pr.TokenNumber, pr.Patient.FirstName, pr.Patient.LastName, pr.Patient.NIC, pr.Patient.Mobile, pr.Patient.Address, pr.TokenType, pr.CashReceived, pr.Room.Name, pr.Patient.RegistrationNumber, pr.Patient.RegistrationDate, 0, pr.TokenBy.UserName };
            object[] values = { 0, pr.TokenDate, pr.TokenMonthYear, pr.TokenNumber, pr.Patient.FirstName + ' ' + pr.Patient.LastName, pr.Patient.LastName, pr.Patient.NIC, pr.Patient.Age, pr.Patient.Mobile, pr.Patient.Address, pr.TokenType, pr.CashReceived, pr.Room.Name + '-' + pr.Room.LabelName, pr.Patient.RegistrationNumber, pr.Patient.RegistrationDate, 0, pr.TokenBy.UserName };
            prt.LoadDataRow(values, true);
            rptTokenReceipt crp = new rptTokenReceipt();

            crp.SetDataSource((DataTable)prt);
            crp.SetParameterValue("Duplicate", PrintDuplicate);
            crp.SetParameterValue("Name", BranchName);
            crp.SetParameterValue("Address", BranchAddress);
            crp.SetParameterValue("ComplaintNo", "Complaint #: " + CompNo);
            FrmReportViewer frmViewer = new FrmReportViewer();

            frmViewer.crystalReportViewer1.ReportSource = crp;
            if (preview)
            {
                frmViewer.ShowDialog();
            }
            else
            {
                //frmViewer.crystalReportViewer1.RefreshReport();
                crp.PrintToPrinter(1, false, 0, 0);                 ////    -------- Asif -- 02-06-19   ----- Print Without Showing Print Dialog (Disallow Multiple Copies)
                //frmViewer.crystalReportViewer1.PrintReport();     ////    -------- Asif -- 02-06-19
            }


            //var dialog = new PrintDialog();

            //Nullable<bool> print = dialog.ShowDialog() == System.Windows.Forms.DialogResult.Yes ? true : false; ;
            //// if (print.HasValue && print.Value)
            //{
            //    var rd = new ReportDocument();

            //    //rd.ReportClientDocument
            //    rd.Load(Application.StartupPath + "\\Reports\\rptTokenReceipt.rpt");
            //    rd.SetParameterValue("Duplicate", PrintDuplicate);
            //    rd.SetParameterValue("Name", BranchName);
            //    rd.SetParameterValue("Address", BranchAddress);
            //    rd.SetDataSource((DataTable)prt);
            //    dialog.PrinterSettings.Copies = 1;
            //    rd.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName;
            //    MessageBox.Show("Printing");
            //    //rd.PrintToPrinter(dialog.PrinterSettings.PrinterName, false, 0, 0);
            //    try
            //    {

            //        rd.PrintToPrinter(1, true, 0, 1);
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }
            //    try
            //    {

            //        rd.PrintToPrinter(1, true, 0, 0);
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }


            //    // rd.PrintToPrinter(1, false, 0, 0);

            //    {

            //        //   System.Drawing.Printing.PrintDocument pDoc = new PrintDocument();
            //        CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();
            //        System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
            //        printerSettings.PrinterName = dialog.PrinterSettings.PrinterName;
            //        System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);
            //        rd.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
            //        rd.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Simplex;

            //        //   OnMessageLogged(TraceEventType.Information, "PrePrint " + crReportDocument.PrintOptions.PrinterName);

            //        System.Security.Principal.WindowsImpersonationContext ctx = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
            //        try
            //        {
            //            rd.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
            //            //   OnMessageLogged(TraceEventType.Information, "Printed " + pq.printerName);
            //        }
            //        catch (Exception eprint)
            //        {
            //            MessageBox.Show("Error" + eprint.Message);
            //            //OnMessageLogged(TraceEventType.Information, "****Failed to Print** to printer " + pq.printerName + " Exception " + eprint.ToString());
            //        }
            //        finally
            //        {
            //            // Resume impersonation
            //            ctx.Undo();
            //            //   OnMessageLogged(TraceEventType.Information, "Success Printing to " + pq.printerName);
            //        }
            // }

            //}

            PrintDuplicate = false;
        }