示例#1
0
        public GeneratorQRCodePageViewModel()
        {
            SetQrModeTypeCommand = new Command(qrModeType =>
                                               QRCodeGenerator.SetQrModeType((QrModeType)qrModeType));
            SetErrorCorrectionLevelCommand = new Command(eccLevel =>
                                                         QRCodeGenerator.SetErrorCorrectionLevel((ErrorCorrectionLevel)eccLevel));
            SetVersionCommand = new Command(version =>
                                            QRCodeGenerator.SetVersion((int)version));

            GenerateCommand = new Command(
                () =>
            {
                try
                {
                    RefreshPage(QRCodeGenerator.Generate(inputWidth, inputHeight, inputMessage));
                    IsValid = true;
                    GenerationResultText = $"Success:";
                }
                catch (Exception e)
                {
                    IsValid = false;
                    GenerationResultText = $"Failure : {e.Message}. \nCheck QrMdoe, ECC, Version are valid or not ";
                }
            });
        }
        public ActionResult Generate()
        {
            var consignments = Db.Assignments
                               .Include(x => x.Drivers)
                               .Include(x => x.Vehicle)
                               .ToList();//.Where(x => x.CreatedBy == LoggedInUser.Id)

            List <OrderVm> orderVMs = new List <OrderVm>();

            foreach (var consignment in consignments)
            {
                var order = Db.Orders
                            .Include(x => x.PickupAddress)
                            .Include(x => x.DeliveryAddress)
                            .FirstOrDefault(x => x.Id == consignment.OrderId);

                string prefix  = "ENCORE";
                var    barcode = GeneratorHelper.GenerateBarcode(prefix, int.Parse(order.OrderNumber));
                consignment.PickupTicket = barcode;
                consignment.PickupTicketGenerationTime = DateTime.Now;
                Db.SaveChanges();

                var pickupAddress   = TinyMapper.Map <AddressVm>(order.PickupAddress).ToString;
                var deliveryAddress = TinyMapper.Map <AddressVm>(order.DeliveryAddress).ToString;

                var orderVM = new OrderVm()
                {
                    Id                    = order.Id.ToString(),
                    OrderDate             = order.CreatedAt.ToString(),
                    OrderNumber           = order.OrderNumber,
                    PickupAddressString   = pickupAddress,
                    DeliveryAddressString = deliveryAddress,
                    PickupDate            = order.PickupDate?.ToString(),
                    DeliveryDate          = order.DeliveryDate?.ToString(),
                    Customer              = order.Client != null ? order.Client.AccountCode + " " + order.Client.Name : "",
                    PickupTicket          = consignment.PickupTicket
                };

                orderVMs.Add(orderVM);
            }
            // Generate
            var filePath = QRCodeGenerator.Generate(ImagesPath, UploadsPath, orderVMs);

            return(File(filePath, "application/octet-stream", "PickupTickets.pdf"));
        }
示例#3
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private BitmapSource GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();

                desc.QRVersion    = QR_VERSION;
                desc.GeneratorApp = GENERATOR_APP;

                desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses());
                desc.Addresses         = String.Join(";", NetworkInformation.GetIPAddresses());
                desc.Name        = Configuration.Services.GetServiceName();
                desc.NetbiosName = System.Environment.MachineName;
                desc.ExternalIp  = ExternalAddress.GetAddress();

                desc.Services = new List <ServiceDescription>();
                User wifiRemoteAuth = WifiRemote.IsInstalled ? WifiRemote.GetAuthentication() : null;
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.Service.ToString(),
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        srvdesc.User     = (srv.Service == MPExtendedService.WifiRemote ? wifiRemoteAuth : auth).Username;
                        srvdesc.Password = (srv.Service == MPExtendedService.WifiRemote ? wifiRemoteAuth : auth).GetPassword();
                    }

                    desc.Services.Add(srvdesc);
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                return(bm.ToWpfBitmap());
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private void GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();
                desc.HardwareAddresses = String.Join(";", GetHardwareAddresses());
                desc.Addresses         = String.Join(";", GetIPAddresses());
                desc.Name      = GetServiceName();
                desc.QRVersion = 1;

                desc.Services = new List <ServiceDescription>();
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.ServiceName.ToString(),
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        string usernameOut, passwordOut;
                        srv.GetUsernameAndPassword(auth, out usernameOut, out passwordOut);
                        srvdesc.User     = usernameOut;
                        srvdesc.Password = passwordOut;
                    }

                    desc.Services.Add(srvdesc);
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                imgQRCode.Source = bm.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
            }
        }