Exemplo n.º 1
0
        public static bool ImprimirCredencialVeiculo(ClasseVeiculosCredenciais.VeiculoCredencial veiculoCredencial)
        {
            try
            {
                //IEngine _sdk = Main.engine;

                Workspace m_workspace = PagePrincipalView.Workspace;

                bool _deletaCredencial = false;

                Cardholder _cardholder = _sdk.GetEntity((Guid)veiculoCredencial.CardHolderGuid) as Cardholder;

                if (_cardholder == null)
                {
                    return(false);
                }

                Credential _credencial = _sdk.GetEntity((Guid)veiculoCredencial.CredencialGuid) as Credential;

                if (_credencial == null)
                {
                    _credencial       = CriarCredencialProvisoria(_cardholder, veiculoCredencial.Validade, new Guid(veiculoCredencial.LayoutCrachaGUID));
                    _deletaCredencial = true;
                }

                Guid _CrachaGUID = new Guid(veiculoCredencial.LayoutCrachaGUID);
                Guid _CHGUID     = _credencial.CardholderGuid; // new Guid("227ee2c9-371f-408f-bf91-07cfb7ac8a74");

                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    PrintQueue printQueue = GetPrintQueue();
                    if (printQueue != null)
                    {
                        IBadgeService badgeService = m_workspace.Services.Get <IBadgeService>();
                        if (badgeService != null)
                        {
                            BadgeInformation info = new BadgeInformation(_CrachaGUID, _credencial.Guid);
                            badgeService.BeginPrint(info, printQueue, OnBadgePrinted, null);
                        }
                    }
                }));

                if (_deletaCredencial)
                {
                    _sdk.DeleteEntity(_credencial);
                }


                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }