Пример #1
0
        public async void Scan(Entidade_Leitura leitura)
        {
            try
            {
                string resultado = "";
                //https://julianocustodio.com/2017/11/03/scanner/
                var scanpage = new ZXingScannerPage();

                scanpage.OnScanResult += (result) =>
                {
                    // Parar de escanear
                    scanpage.IsScanning = false;
                    //Poderia fazer qualquer outra ação
                    resultado = result.Text;
                    // Alert com o código escaneado
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if ((Controle.ValidaBarcodeSN(result.Text)))
                        {
                            if (InventoryPD3.App._position != null)
                            {
                                leitura.CodigoBarras     = result.Text;
                                leitura.TimestampLeitura = DateTime.Now.ToString();
                                leitura.GPSAccuracy      = InventoryPD3.App._position.Accuracy.ToString();
                                leitura.GPSLatitude      = InventoryPD3.App._position.Latitude.ToString();
                                leitura.GPSLongitude     = InventoryPD3.App._position.Longitude.ToString();
                                leitura.GPSTimestamp     = InventoryPD3.App._position.Timestamp.ToString();
                                leitura.Synced           = false;
                                leitura.CaminhoImg       = "N/A";
                                leitura.urlImg           = "N/A";
                                leitura.Data             = "N/A";
                                leitura.TimestampFoto    = DateTime.Now.ToString();
                                //TakeCam(leitura); comentado pois desde 25/01 decidiu-se que não vamos mais armazenar a imagem do produto
                                DisplayAlert("Código Lido!", "O SN " + result.Text + " foi lido com sucesso!", "OK");
                                SendToSQLite(leitura);
                                //SendToFirebase(leitura);
                            }
                            else
                            {
                                DisplayAlert("Status GPS", "Não há sinal informações de localização", "OK");
                            }
                        }
                        else
                        {
                            Navigation.PopAsync();
                            DisplayAlert("Código inválido!", "Esse não é o código de barras do número de série do produto.", "OK");
                            Scan(leitura);
                        }
                    });
                };

                await Navigation.PushAsync(scanpage);
            }
            catch (Exception e)
            {
            }
        }
Пример #2
0
        public async Task SendToFirebase(Entidade_Leitura leitura)
        {
            //Firebase https://rsamorim.azurewebsites.net/2017/11/07/reagindo-a-evento-com-xamarin-forms-e-firebase/
            //doc git https://github.com/step-up-labs/firebase-database-dotnet
            var firebase = new FirebaseClient("https://inventorypd3.firebaseio.com/");

            // add new item to list of data and let the client generate new key for you (done offline)

            /*var dino = await firebase
             * .Child("inventorypd3")
             * .PostAsync("nome:rodrigo");
             */
            /*var dinos = await firebase
             * .Child("dinosaurs")
             * .OrderByKey()
             * .StartAt("pterodactyl")
             * .LimitToFirst(2)
             * .OnceAsync<Dinosaur>();
             *
             * foreach (var dino in dinos)
             * {
             *  lb_Resultado.Text = lb_Resultado.Text + $"{dino.Key} is {dino.Object.Height}m high.";
             * }*/

            //var cliente =
            await firebase
            .Child(leitura.Cliente)
            .Child(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00"))
            .Child(leitura.CodigoBarras)
            //.PostAsync(leitura);//Firebase cria a chave
            .PutAsync(leitura);// Eu crio a chave

            // note that there is another overload for the PostAsync method which delegates the new key generation to the firebase server
            //Console.WriteLine($"Key for the new dinosaur: {dino.Key}");

            // add new item directly to the specified location (this will overwrite whatever data already exists at that location)

            /* await firebase
            *  .Child("dinosaurs")
            *  .Child("t-rex")
            *  .PutAsync("com overwrite");
            *
            *  // delete given child node
            *  /*await firebase
            *  .Child("dinosaurs")
            *  .Child("t-rex")
            *  .DeleteAsync();*/
        }
Пример #3
0
        private void LerBarcode(object sender, EventArgs arg)
        {
            Entidade_Leitura leitura = new Entidade_Leitura();

            leitura.Cliente = Cliente;
            leitura.Usuario = Usuario;
            Scan(leitura);

            /*
             * Como os métodos de ler códigos de barras e tirar fotos são assíncronos, a chamada da foto está dentro do método de leitura de código de barras
             * para que os doi métodos não sejam chamados ao mesmo tempo.
             * O método Scan recebe um objeto do tipo Leitura e acrescenta a ele informações de códigos de barras e GPS e o encaminha para o método da Câmera.
             * Scan-->TakePhoto-->
             *
             * */
        }
Пример #4
0
        private void SendToSQLite(Entidade_Leitura leitura)
        {
            //Salvar informações no Banco
            DAL_Database database = new DAL_Database();
            var          _leitura = database.ObterVagaPorCodigoBarras(leitura.CodigoBarras);

            if (_leitura == null)
            {
                database.Cadastro(leitura);
            }
            else
            {
                DisplayAlert("Alerta!", "Você já leu esse Número de Série! As informações serão atualizadas!", "OK");
                database.Atualizacao(leitura);
            }
            ConsultarLeituras();
        }
Пример #5
0
        public async void SendToFirebaseStorage(MediaFile file, Entidade_Leitura leitura)
        {
            //Envio para o FirebaseStorage - está sem lógica pois foi retirado da scanpage e colocado nessa classe apenas para documentar o código para o caso do processo voltar a ter foto
            // Get any Stream - it can be FileStream, MemoryStream or any other type of Stream
            //var stream = File.Open(@"C:\Users\you\file.png", FileMode.Open);
            var stream2 = file.GetStream();

            // Constructr FirebaseStorage, path to where you want to upload the file and Put it there
            var task = new FirebaseStorage("inventorypd3.appspot.com")
                       .Child(leitura.Cliente)
                       .Child(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00"))
                       .Child(leitura.CodigoBarras + ".jpg")
                       .PutAsync(stream2);

            file.Dispose();
            // Track progress of the upload
            //task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");

            // await the task to wait until upload completes and get the download url
            //task.Progress.ProgressChanged += (s, e) => DisplayAlert("Progresso", e.Percentage.ToString("00"), "Ok");
            var downloadUrl = await task;
        }
 public void Exclusao(Entidade_Leitura leitura)
 {
     _conexao.Delete(leitura);
 }
 public void Atualizacao(Entidade_Leitura leitura)
 {
     _conexao.Update(leitura);
 }
 public void Cadastro(Entidade_Leitura leitura)
 {
     _conexao.Insert(leitura);
 }
Пример #9
0
        public async Task <IReadOnlyCollection <FirebaseObject <Entidade_Leitura> > > BuscarLeitura(Entidade_Leitura leitura)
        {
            var firebase = new FirebaseClient("https://inventorypd3.firebaseio.com/");
            var leituras = await firebase
                           .Child(leitura.Cliente)
                           .Child(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00"))
                           .OrderByKey()
                           .StartAt(leitura.CodigoBarras)
                           .LimitToFirst(1)
                           .OnceAsync <Entidade_Leitura>();

            return(leituras);
        }
Пример #10
0
        public async void TakeCam(Entidade_Leitura leitura)
        {
            //https://github.com/jamesmontemagno/MediaPlugin

            var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Plugin.Permissions.Abstractions.Permission.Camera);

            var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Plugin.Permissions.Abstractions.Permission.Storage);

            /*   if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
             * {
             *     await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
             *     return;
             * }
             */
            //Checar e pedir permissão para câmera e storage
            if (InventoryPD3.App._cameraPermissionStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });

                cameraStatus  = results[Permission.Camera];
                storageStatus = results[Permission.Storage];
            }

            if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
            {
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    SaveToAlbum = true,
                    //Directory = "Pictures",
                    Name = $"{leitura.CodigoBarras}.jpg",
                    CompressionQuality = 92, //0 é o mais comprimido. 92 é o recomendado
                    CustomPhotoSize    = 50, //50% do original
                    //PhotoSize = PhotoSize.MaxWidthHeight,
                    PhotoSize      = PhotoSize.Medium,
                    MaxWidthHeight = 2000,
                    DefaultCamera  = CameraDevice.Rear
                                     //Name = "test.jpg"
                });

                if (file == null)
                {
                    return;
                }

                //When your user takes a photo it will still store temporary data, but also if needed make a copy to the
                //public gallery (based on platform). In the MediaFile you will now see a AlbumPath that you can query as well.

                //Get the public album path
                var aPpath = file.AlbumPath;

                //Get private path
                var path = file.Path;

                leitura.CaminhoImg = path;

                await DisplayAlert("Localização do Arquivo", file.Path, "OK");



                //leitura.urlImg = downloadUrl;
                //lb_Resultado.Text = downloadUrl.ToString();
                //SendToFirebase(leitura);
            }
            else
            {
                await DisplayAlert("Permissão Negada", "Não é possível tirar fotos.", "OK");

                //On iOS you may want to send your user to the settings screen.
                //CrossPermissions.Current.OpenAppSettings();
            }
        }