private async void PrintButton_Clicked(object sender, EventArgs e)
        {
            var answer = await DisplayAlert("Print Payment", "Are you sure to print payment?", "Yes", "No");

            if (answer)
            {
                DataManager manager = new DataManager();
                DeviceInfo  info    = new DeviceInfo();
                info = await manager.GetDeviceInfo();

                if (info != null)
                {
                    if (!string.IsNullOrEmpty(info.DeviceName))
                    {
                        var signedImageStream = await CustomerSignaturePad.GetImageStreamAsync(SignatureImageFormat.Png);

                        var    signatureMemoryStream = signedImageStream as MemoryStream;
                        byte[] bytes           = signatureMemoryStream.ToArray();
                        string _signature64str = Convert.ToBase64String(bytes);

                        manager = new DataManager();
                        Dictionary <int, string> dicResult = new Dictionary <int, string>();
                        dicResult = await manager.SaveSQLite_Payment(new Payment
                        {
                            ID                = record.ID,
                            DocumentNo        = record.DocumentNo,
                            OnDate            = record.OnDate,
                            CustomerNo        = record.CustomerNo,
                            CustomerName      = record.CustomerName,
                            PaymentMethod     = record.PaymentMethod,
                            Amount            = record.Amount,
                            CustomerSignature = _signature64str,
                            SalesPersonCode   = record.SalesPersonCode,
                            Imagestr          = record.Imagestr,
                            RecStatus         = "Released",
                            RefDocumentNo     = record.RefDocumentNo,
                            SourceType        = record.SourceType
                        });

                        string retval  = string.Empty;
                        int    entryno = 0;
                        if (dicResult.Count > 0)
                        {
                            foreach (KeyValuePair <int, string> pair in dicResult)
                            {
                                entryno = pair.Key;
                                retval  = pair.Value;
                            }
                        }

                        if (retval == "Success")
                        {
                            if (!string.IsNullOrEmpty(record.RefDocumentNo))
                            {
                                List <PaymentReference> refList = new List <PaymentReference>();
                                refList = await GetReferenceData(record.CustomerNo);

                                string[] refnos = record.RefDocumentNo.Split(',');
                                foreach (string r in refnos)
                                {
                                    PaymentReference pf = new PaymentReference();
                                    pf = refList.Where(x => x.DocumentNo == r).FirstOrDefault();
                                    if (pf != null)
                                    {
                                        string retpaid = await manager.SaveSQLite_PaidReference(new PaidReference { DocumentNo = pf.DocumentNo, Amount = decimal.Parse(pf.Amount), SourceType = pf.SourceType });
                                    }
                                }
                            }
                            //DependencyService.Get<IMessage>().LongAlert(retval);
                            UserDialogs.Instance.ShowSuccess(retval, 3000);
                            App.gPaymentStatus = "Released";
                            //var navipages = Navigation.NavigationStack.ToList();
                            //if(navipages !=null)
                            //{
                            //    foreach (var pg in navipages)
                            //    {
                            //        Navigation.RemovePage(pg);
                            //    }
                            //}
                            PrintText(info.DeviceName);
                        }
                        else
                        {
                            //DependencyService.Get<IMessage>().LongAlert(retval);
                            UserDialogs.Instance.ShowError(retval, 3000);
                        }
                    }

                    else
                    {
                        UserDialogs.Instance.ShowError("Required to setup bluetooth printer!", 3000);
                    }
                }
                else
                {
                    UserDialogs.Instance.ShowError("Required to setup bluetooth printer!", 3000);
                }
            }
        }
        public SelectMultipleBasePage(List <T> items)
        {
            string[] refnos     = App.gRefDocNo.Split(',');
            bool     isSelected = false;
            //if (refnos.Contains(c.DocNo)) isSelected = true;
            int count = -1;

            foreach (var item in items)
            {
                PaymentReference r = item as PaymentReference;
                count = Array.IndexOf(refnos, r.DocumentNo);
                if (count > -1)
                {
                    isSelected = true;
                }
                else
                {
                    isSelected = false;
                }
                // if (refnos.Contains(item.)) isSelected = true;
                WrappedItems.Add(new WrappedSelection <T>()
                {
                    Item = item, IsSelected = isSelected
                });
            }

            //  WrappedItems = items.Select(item => new WrappedSelection<T>() { Item = item, IsSelected = true }).ToList();
            ListView mainList = new ListView()
            {
                ItemsSource  = WrappedItems,
                ItemTemplate = new DataTemplate(typeof(WrappedItemSelectionTemplate)),
            };

            mainList.ItemSelected += (sender, e) =>
            {
                if (e.SelectedItem == null)
                {
                    return;
                }
                var o = (WrappedSelection <T>)e.SelectedItem;
                o.IsSelected = !o.IsSelected;
                ((ListView)sender).SelectedItem = null; //de-select
            };
            //Grid grid = new Grid
            //{
            //    VerticalOptions=LayoutOptions.FillAndExpand,
            //    RowDefinitions =
            //    {
            //        new RowDefinition { Height = GridLength.Auto },
            //        new RowDefinition { Height = GridLength.Auto },
            //        new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
            //        new RowDefinition { Height = new GridLength(100, GridUnitType.Absolute) }
            //    },
            //    ColumnDefinitions =
            //    {
            //       new ColumnDefinition { Width = GridLength.Auto },
            //        new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
            //        new ColumnDefinition { Width = new GridLength(100, GridUnitType.Absolute) }
            //    }
            //};

            //grid.Children.Add(new Label
            //{
            //    Text="Doc No",
            //    Font=Font.BoldSystemFontOfSize(30),
            //    HorizontalOptions=LayoutOptions.Center
            //},0,3,0,1);

            //grid.Children.Add(new Label
            //{
            //    Text = "Autosized cell",
            //    TextColor = Color.White,
            //    BackgroundColor = Color.Blue
            //}, 0, 1);

            //grid.Children.Add(new BoxView
            //{
            //    Color = Color.Silver,
            //    HeightRequest = 0
            //}, 1, 1);

            //grid.Children.Add(new BoxView
            //{
            //    Color = Color.Teal
            //}, 0, 2);

            //grid.Children.Add(new Label
            //{
            //    Text = "Leftover space",
            //    TextColor = Color.Purple,
            //    BackgroundColor = Color.Aqua,
            //    XAlign = TextAlignment.Center,
            //    YAlign = TextAlignment.Center,
            //}, 1, 2);

            //grid.Children.Add(new Label
            //{
            //    Text = "Span two rows (or more if you want)",
            //    TextColor = Color.Yellow,
            //    BackgroundColor = Color.Navy,
            //    XAlign = TextAlignment.Center,
            //    YAlign = TextAlignment.Center
            //}, 2, 3, 1, 3);

            //grid.Children.Add(mainList, 0, 2, 3, 4);

            //grid.Children.Add(new Label
            //{
            //    Text = "Fixed 100x100",
            //    TextColor = Color.Aqua,
            //    BackgroundColor = Color.Red,
            //    XAlign = TextAlignment.Center,
            //    YAlign = TextAlignment.Center
            //}, 2, 3);

            //// Accomodate iPhone status bar.
            //this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            //// Build the page.
            //this.Content = grid;

            Content = mainList;
            if (Device.RuntimePlatform == Device.WinPhone)
            {   // fix issue where rows are badly sized (as tall as the screen) on WinPhone8.1
                mainList.RowHeight = 40;
                // also need icons for Windows app bar (other platforms can just use text)
                ToolbarItems.Add(new ToolbarItem("All", "check.png", SelectAll, ToolbarItemOrder.Primary));
                ToolbarItems.Add(new ToolbarItem("None", "cancel.png", SelectNone, ToolbarItemOrder.Primary));
            }
            else
            {
                ToolbarItems.Add(new ToolbarItem("All", null, SelectAll, ToolbarItemOrder.Primary));
                ToolbarItems.Add(new ToolbarItem("None", null, SelectNone, ToolbarItemOrder.Primary));
            }
        }