Example #1
0
        private async Task OnSubmit()
        {
            try
            {
                IsBusy = true;

                var signatureStream = await _signatureView.GetImageStreamAsync(SignatureImageFormat.Jpeg, Color.Black);

                var imageData = new byte[signatureStream.Length];
                await signatureStream.WriteAsync(imageData, 0, (int)signatureStream.Length);

                var signatureData = Convert.ToBase64String(imageData);
                foreach (var packingSlip in _packingSlips)
                {
                    var context = new SignatureQueryContext
                    {
                        CustomerInfo    = Api.GetCustomerContext(),
                        Branch          = packingSlip.Branch.Code,
                        Email           = _email,
                        PackingSlipId   = packingSlip.Key,
                        PackingSlipDate = packingSlip.PackingSlipDate,
                        PrintedName     = _printedName,
                        SalesOrderId    = packingSlip.CustomerPurchaseOrderNo,
                        SignatureBase64 = signatureData,
                        Images          = new List <SignatureImage>(_pictureList)
                    };

                    var response = await Api.PostSignature(context);

                    if (!response.Successful.GetValueOrDefault())
                    {
                        await Alert.DisplayApiCallError(response.ExceptionMessage, response.ValidationErrors,
                                                        Translate.Get(nameof(AppResources.DrvSignPageError1)));
                    }
                }

                IsBusy = false;
                await ShowToast();
                await NavigateTo(new DrvSurveyPage(_packingSlips), true);
            }
            catch (Exception e)
            {
                await Alert.DisplayError(e, Translate.Get(nameof(AppResources.ServerError)));
            }
            finally
            {
                IsBusy = false;
            }
        }
        /// <summary>
        /// Save signature
        /// </summary>
        /// <returns>The signature.</returns>
        async Task SaveSignatureToDiskAsync()
        {
            var path          = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath;
            var signaturePath = System.IO.Path.Combine(path, $"{_docketId}.png");

            using (var bitmap = await _signatureView.GetImageStreamAsync(SignatureImageFormat.Png,
                                                                         Color.Black, Color.White, 1f))
            {
                using (var dest = File.OpenWrite(signaturePath))
                {
                    await bitmap.CopyToAsync(dest);

                    var docket = _repository.DeliveryDockets.Find(_docketId);
                    docket.SignaturePath = signaturePath;
                    _repository.SaveChanges();
                }
            }
        }
Example #3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SignaturePadView sigView = null;

            if (value is SignaturePadView)
            {
                sigView = value as SignaturePadView;
            }
            else
            {
                sigView = parameter as SignaturePadView;
            }

            if (sigView == null)
            {
                throw new ArgumentOutOfRangeException("value or parameter should act as SignaturePadView", innerException: null);
            }

            return(sigView.GetImageStreamAsync(SignatureImageFormat.Png).Result);
        }
Example #4
0
        private async Task SaveButtonPressed(SignaturePadView signaturePad)
        {
            Stream signatureStream = await signaturePad.GetImageStreamAsync(SignatureImageFormat.Png);


            if (!(signatureStream is MemoryStream signatureMemoryStream))
            {
                signatureMemoryStream = new MemoryStream();
                signatureStream.CopyTo(signatureMemoryStream);
            }

            //Adding memorystream into a byte array
            var byteArray = signatureMemoryStream.ToArray();

            //Converting byte array into Base64 string
            var base64String = Convert.ToBase64String(byteArray);

            if (base64String != null)
            {
                var res = await Application.Current.MainPage.DisplayAlert("Thank you!", "You have signed to the agreement successfully.", "OK", "Cancel");

                if (res)
                {
                    if (!Constants.SignaturesList.Any(x => x.GuestNumber == Constants.SelectedGuestSignature.GuestNumber && x.IsSignatureAdded == true))
                    {
                        Constants.SignaturesList.Add(new GuestSignatureModel
                        {
                            GuestNumber         = Constants.SelectedGuestSignature.GuestNumber,
                            GuestName           = Constants.SelectedGuestSignature.GuestName,
                            GuestNameColor      = "White",
                            GuestSignatureImage = ImageSource.FromStream(() => new MemoryStream(byteArray)),
                            IsSignatureAdded    = true,
                            CellColor           = "#6D2276"
                        });
                    }

                    await this.Navigation.PopAsync();
                }
            }
        }
Example #5
0
        public async Task SaveSig(SignaturePadView whichSignature, Result result)
        {
            Stream bitmap = await whichSignature.GetImageStreamAsync(SignatureImageFormat.Png);

            string sigOwner = whichSignature.CaptionText;

            string tempSigFileName = result.Name + " " + sigOwner + " " + result.DateCreated;

            byte[] sigBit = ReadFully(bitmap);
            SaveToDisk(tempSigFileName, sigBit);

            if (sigOwner == "Conducting")
            {
                result.ConductingSig = tempSigFileName;
            }
            else if (sigOwner == "Supervising")
            {
                result.SupervisingSig = tempSigFileName;
            }
            else if (sigOwner == "Neutral")
            {
                result.NeutralSig = tempSigFileName;
            }
        }
Example #6
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            SetContentView(Resource.Layout.activity_signature_pad);

            SignaturePadView signatureView = FindViewById <SignaturePadView>(Resource.Id.signatureView);

            Button btnCancel = FindViewById <Button>(Resource.Id.btnCancel);

            Button btnComplete = FindViewById <Button>(Resource.Id.btnComplete);

            EditText SignatureText = FindViewById <EditText>(Resource.Id.txtSignature);

            /*
             * SignatureText.TextChanged += delegate {
             *
             *      if (SignatureText.Length() > 0)
             *      {
             *          btnComplete.Enabled = true;
             *      }
             *      else
             *      {
             *          btnComplete.Enabled = true;
             *      }
             *  };
             */

            btnCancel.Click += delegate
            {
                StartActivity(typeof(MainActivity));
            };


            btnComplete.Click += async delegate
            {
                string path = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath;
                if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) == (int)Permission.Granted ||
                    ContextCompat.CheckSelfPermission(this, Manifest.Permission.ReadExternalStorage) == (int)Permission.Granted)
                {
                    Context        mContext = Application.Context;
                    AppPreferences applicationPreferences = new AppPreferences(mContext);
                    string         batch  = applicationPreferences.GetAccessKey("batchnumber");
                    string         file   = System.IO.Path.Combine(path, batch + ".jpg");
                    string         result = "";
                    try
                    {
                        using (var bitmap = await signatureView.GetImageStreamAsync(SignatureImageFormat.Jpeg, Color.Black, Color.White, 1f))
                            using (var dest = File.OpenWrite(file))
                            {
                                await bitmap.CopyToAsync(dest);
                            }



                        byte[] data = File.ReadAllBytes(file);
                        // ... Convert byte array to Base64 string.
                        result = Convert.ToBase64String(data);
                        // ... Write Base64 string.
                        Console.WriteLine("ENCODED: " + result);
                    }
                    catch { }
                    PushDataToEndPoint(result, SignatureText.Text);
                }
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            signatureView = FindViewById <SignaturePadView>(Resource.Id.signatureView);

            var btnSave      = FindViewById <Button>(Resource.Id.btnSave);
            var btnLoad      = FindViewById <Button>(Resource.Id.btnLoad);
            var btnSaveImage = FindViewById <Button>(Resource.Id.btnSaveImage);

            btnSaveImage.Click += BtnCamera_Click;;
            // signatureView.SetBackgroundResource(Resource.Drawable.splash_logo);

            //btnSave.Click += delegate
            //{
            //    points = signatureView.Points;

            //    Toast.MakeText(this, "Vector signature saved to memory.", ToastLength.Short).Show();
            //};
            btnSave.Click += async delegate
            {
                points = signatureView.Points;

                Toast.MakeText(this, "Vector signature saved to memory.", ToastLength.Short).Show();

                var path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
                var file = System.IO.Path.Combine(path, "signature.png");

                using (var bitmap = await signatureView.GetImageStreamAsync(SignatureImageFormat.Png, Android.Graphics.Color.Black, Android.Graphics.Color.White, 1f))
                    using (var dest = File.OpenWrite(file))
                    {
                        await bitmap.CopyToAsync(dest);
                    }

                Toast.MakeText(this, "Raster signature saved to the photo gallery.", ToastLength.Short).Show();
            };

            btnLoad.Click += delegate
            {
                if (points != null)
                {
                    signatureView.LoadPoints(points);
                }
            };

            //btnSaveImage.Click += async delegate
            //{
            //    var path = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath;
            //    var file = System.IO.Path.Combine(path, "signature.png");

            //    using (var bitmap = await signatureView.GetImageStreamAsync(SignatureImageFormat.Png, Color.Black, Color.White, 1f))
            //    using (var dest = File.OpenWrite(file))
            //    {
            //        await bitmap.CopyToAsync(dest);
            //    }

            //    Toast.MakeText(this, "Raster signature saved to the photo gallery.", ToastLength.Short).Show();
            //};
        }