Beispiel #1
0
        private async Task ReadMagEncodeData()
        {
            MessageDialog insertCardDialog = null;

            viewModel.Track1Data = "";
            viewModel.Track2Data = "";
            viewModel.Track3Data = "";
            JobStatusControl.ClearLog();

            Console.SetOut(new TextBoxTextWriter(JobStatusControl.JobStatusLog));

            await printerManager.PerformAction("Reading mag encode data...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    Console.WriteLine(); // Start logging on new line after printer ready check

                    CardSource cardSource = (CardSource)Enum.Parse(typeof(CardSource), viewModel.SelectedSource);

                    Dictionary <string, string> jobSettings = new Dictionary <string, string>();
                    jobSettings.Add(ZebraCardJobSettingNames.CARD_SOURCE, cardSource.ToString());
                    jobSettings.Add(ZebraCardJobSettingNames.CARD_DESTINATION, viewModel.SelectedDestination.ToString());

                    zebraCardPrinter.SetJobSettings(jobSettings);

                    if (cardSource == CardSource.ATM)
                    {
                        insertCardDialog = DialogHelper.ShowInsertCardDialog();
                    }

                    MagTrackData magTrackData = zebraCardPrinter.ReadMagData(DataSource.Track1 | DataSource.Track2 | DataSource.Track3, true);

                    if (string.IsNullOrEmpty(magTrackData.Track1) && string.IsNullOrEmpty(magTrackData.Track2) && string.IsNullOrEmpty(magTrackData.Track3))
                    {
                        Console.WriteLine("No data read from card.");
                    }

                    Application.Current.Dispatcher.Invoke(() => {
                        viewModel.Track1Data = magTrackData.Track1;
                        viewModel.Track2Data = magTrackData.Track2;
                        viewModel.Track3Data = magTrackData.Track3;
                    });
                }
            }, (exception) => {
                string errorMessage = $"Error reading mag encode data: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                Console.WriteLine(errorMessage);
            });

            if (insertCardDialog != null)
            {
                insertCardDialog.Close();
            }

            StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput());

            streamWriter.AutoFlush = true;
            Console.SetOut(streamWriter);
        }
        private async void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            int?       jobId      = null;
            CardSource?cardSource = null;

            JobStatusControl.ClearLog();

            await printerManager.PerformAction("Sending print job to printer...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    TemplateJob templateJob = CreateTemplateJob();
                    if (templateJob.JobInfo.CardDestination.HasValue)
                    {
                        if (templateJob.JobInfo.CardDestination.Value == CardDestination.Eject && zebraCardPrinter.HasLaminator())
                        {
                            templateJob.JobInfo.CardDestination = CardDestination.LaminatorAny;
                        }
                    }

                    cardSource = templateJob.JobInfo.CardSource;
                    jobId      = zebraCardPrinter.PrintTemplate(1, templateJob);
                }
            }, (exception) => {
                string errorMessage = $"Error printing card: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
Beispiel #3
0
        private async void StartJobButton_Click(object sender, RoutedEventArgs e)
        {
            int?       jobId      = null;
            CardSource?cardSource = null;

            JobStatusControl.ClearLog();

            await printerManager.PerformAction("Starting smart card operation...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    cardSource = (CardSource)Enum.Parse(typeof(CardSource), viewModel.SelectedSource);

                    zebraCardPrinter.SetJobSetting(ZebraCardJobSettingNames.CARD_SOURCE, cardSource.ToString());
                    zebraCardPrinter.SetJobSetting(ZebraCardJobSettingNames.CARD_DESTINATION, viewModel.SelectedDestination.ToString());

                    bool isEncoderTypeContact = viewModel.SelectedEncoderType.Equals("contact", StringComparison.OrdinalIgnoreCase) || viewModel.SelectedEncoderType.Equals("contact_station", StringComparison.OrdinalIgnoreCase);
                    string settingName        = isEncoderTypeContact ? ZebraCardJobSettingNames.SMART_CARD_CONTACT : ZebraCardJobSettingNames.SMART_CARD_CONTACTLESS;
                    string settingValue       = isEncoderTypeContact ? "yes" : viewModel.SelectedEncoderType;

                    zebraCardPrinter.SetJobSetting(settingName, settingValue);
                    jobId = zebraCardPrinter.SmartCardEncode(1);
                }
            }, (exception) => {
                string errorMessage = $"Error sending smart card job: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
Beispiel #4
0
        private async void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            ZebraCardGraphics graphics = null;
            int?       jobId           = null;
            CardSource?cardSource      = null;

            JobStatusControl.ClearLog();
            await printerManager.PerformAction("Sending print job to printer...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    graphics = new ZebraCardGraphics(zebraCardPrinter);

                    List <GraphicsInfo> graphicsData = new List <GraphicsInfo>();

                    if (viewModel.PrintFrontSide)
                    {
                        byte[] frontSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, viewModel.FrontSidePrintType, System.Drawing.Color.White);
                        graphics.DrawImage(frontSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, viewModel.FrontSidePrintType));
                        graphics.Clear();
                    }

                    if (viewModel.PrintFrontSideOverlay)
                    {
                        if (viewModel.FrontSideOverlayGraphicFilename != null)
                        {
                            byte[] frontSideOverlayGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideOverlayGraphicFilename));
                            graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.Overlay, System.Drawing.Color.White);
                            graphics.DrawImage(frontSideOverlayGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                            graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                        else
                        {
                            graphicsData.Add(BuildGraphicsInfo(null, CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                    }

                    if (viewModel.PrintBackSide)
                    {
                        byte[] backSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.BackSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.MonoK, System.Drawing.Color.White);
                        graphics.DrawImage(backSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Back, PrintType.MonoK));
                        graphics.Clear();
                    }

                    cardSource = (CardSource)Enum.Parse(typeof(CardSource), zebraCardPrinter.GetJobSettingValue(ZebraCardJobSettingNames.CARD_SOURCE));

                    jobId = zebraCardPrinter.Print(viewModel.Quantity, graphicsData);
                }
            }, (exception) => {
                string errorMessage = $"Error printing card: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            }, () => {
                if (graphics != null)
                {
                    graphics.Close();
                }
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
Beispiel #5
0
        private async void SendJobsButton_Click(object sender, RoutedEventArgs e)
        {
            JobStatusControl.ClearLog();
            viewModel.IsSendJobsButtonEnabled = false;

            bool success = true;
            List <MultiJobControlViewModel> jobViewModels = new List <MultiJobControlViewModel> {
                SetSelectedFullOverlays(Job1Control.ViewModel),
                SetSelectedFullOverlays(Job2Control.ViewModel),
                SetSelectedFullOverlays(Job3Control.ViewModel),
                SetSelectedFullOverlays(Job4Control.ViewModel)
            };

            jobViewModels = jobViewModels.Where((viewModel) => {
                if (IsJobValid(viewModel))
                {
                    return(true);
                }
                else
                {
                    UpdateJobStatus(viewModel.JobNumber, "Not configured");
                    return(false);
                }
            }).ToList();

            await printerManager.PerformAction("Sending jobs...", (zebraCardPrinter, connection) => {
                if (AreAnyJobsValid(jobViewModels))
                {
                    if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                    {
                        JobStatusControl.UpdateLog("Setting up jobs...");

                        foreach (MultiJobControlViewModel jobViewModel in jobViewModels)
                        {
                            SetUpAndSendJob(zebraCardPrinter, jobViewModel);
                        }
                    }
                    else
                    {
                        success = false;
                    }
                }
                else
                {
                    throw new ZebraCardException("No jobs configured");
                }
            }, (exception) => {
                success = false;

                string errorMessage = $"Error sending jobs: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            });

            if (success)
            {
                List <JobInfo> jobInfoList = new List <JobInfo>();
                foreach (MultiJobControlViewModel jobViewModel in jobViewModels)
                {
                    if (jobViewModel.JobId.HasValue)
                    {
                        CardSource cardSource = (CardSource)Enum.Parse(typeof(CardSource), jobViewModel.SelectedSource);
                        jobInfoList.Add(new JobInfo(jobViewModel.JobNumber, jobViewModel.JobId.Value, cardSource));
                    }
                }

                await JobStatusControl.StartPolling(printerManager.Printer, jobInfoList);
            }

            viewModel.IsSendJobsButtonEnabled = true;
        }