Пример #1
0
        private void Print_ActivityReport()
        {
            try
            {
                string      retmsg  = string.Empty;
                DataManager manager = new DataManager();
                ObservableCollection <SalesHeader> head = new ObservableCollection <SalesHeader>();
                DeviceInfo info = new DeviceInfo();

                Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.ShowLoading("Loading", MaskType.Black));
                Task.Run(async() =>
                {
                    info = await manager.GetDeviceInfo();
                    if (info != null)
                    {
                        if (!string.IsNullOrEmpty(info.DeviceName))
                        {
                            manager = new DataManager();
                            head    = await manager.GetSQLite_SalesHeaderByDocDate(App.gOnDate);
                            if (head != null)
                            {
                                if (head.Count > 0)
                                {
                                    retmsg = "Success";
                                }
                                else
                                {
                                    retmsg = "No Data";
                                }
                            }
                            else
                            {
                                retmsg = "No Data";
                            }
                        }
                        else
                        {
                            retmsg = "Required to setup bluetooth printer!";
                        }
                        //UserDialogs.Instance.ShowError("Required to setup bluetooth printer!", 3000);
                    }
                    else
                    {
                        retmsg = "Required to setup bluetooth printer!";
                    }
                    //UserDialogs.Instance.ShowError("Required to setup bluetooth printer!", 3000);
                }).ContinueWith(result => Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                    if (retmsg == "Success")
                    {
                        var a = Utils.Print_Activity(info.DeviceName, head, App.gCompanyName, App.gSalesPersonCode, App.gSalesPersonName);
                        UserDialogs.Instance.Alert(a);
                    }
                    else
                    {
                        // UserDialogs.Instance.ShowError(retmsg, 3000);
                        UserDialogs.Instance.Alert(retmsg, "Alert", "OK");
                    }
                }));
            }
            catch (OperationCanceledException ex)
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading(); //IsLoading = false;
                //UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                UserDialogs.Instance.Alert(ex.Message.ToString(), "Alert", "OK");
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading(); //IsLoading = false;
                //UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                UserDialogs.Instance.Alert(ex.Message.ToString(), "Alert", "OK");
            }
        }
Пример #2
0
        private async void PrintButton_Clicked(object sender, EventArgs e)
        {
            if (_isEnablePrintBtn)
            {
                _isEnablePrintBtn = false;

                var item = (Button)sender;
                //item.CommandParameter.ToString()
                string        retval  = string.Empty;
                string        retmsg  = string.Empty;
                DataManager   manager = new DataManager();
                RequestHeader head    = new RequestHeader();
                ObservableCollection <RequestLine> recs = new ObservableCollection <RequestLine>();
                DeviceInfo info     = new DeviceInfo();
                bool       canPrint = false;
                try
                {
                    var answer = await DisplayAlert("Print", "Are you sure to print Check In Report?", "Yes", "No");

                    UserDialogs.Instance.ShowLoading("Loading", MaskType.Black);
                    if (answer)
                    {
                        canPrint = true;
                        //var devices = await _bluetoothClient.GetPairedDevices();
                        //if (devices != null)
                        //{
                        //    if (devices.Count > 0)
                        //    {
                        //        canPrint = true;
                        //    }
                        //    else
                        //    {
                        //        UserDialogs.Instance.AlertAsync("Not found bluetooth device!", "Alert");
                        //        return;
                        //    }
                        //}
                        //else
                        //{
                        //    UserDialogs.Instance.AlertAsync("Not found bluetooth device!", "Alert");
                        //    return;
                        //}
                    }
                    else
                    {
                        UserDialogs.Instance.HideLoading();
                        _isEnablePrintBtn = true;
                        return;
                    }

                    if (canPrint)
                    {
                        info = await manager.GetDeviceInfo();

                        if (info != null)
                        {
                            if (!string.IsNullOrEmpty(info.DeviceName))
                            {
                                try
                                {
                                    manager = new DataManager();
                                    head    = await manager.GetRequestHeaderbyID(int.Parse(item.CommandParameter.ToString())); //GetRequestLinesbyRequestNo

                                    if (head != null)
                                    {
                                        recs = await manager.GetRequestLinesbyRequestNo(head.RequestNo);

                                        if (recs != null)
                                        {
                                            if (recs.Count > 0)
                                            {
                                                retmsg = "Success";
                                            }
                                            else
                                            {
                                                retmsg = "No request lines";
                                            }
                                        }
                                        else
                                        {
                                            retmsg = "No request lines";
                                        }
                                    }
                                    else
                                    {
                                        retmsg = "No request document";
                                    }
                                }
                                catch (Exception ex)
                                {
                                    retmsg = ex.Message.ToString();
                                }
                            }
                            else
                            {
                                retmsg = "Required to setup bluetooth printer!";
                            }
                        }
                        else
                        {
                            retmsg = "Required to setup bluetooth printer!";
                        }
                    }

                    UserDialogs.Instance.HideLoading();
                    if (retmsg == "Success")
                    {
                        bool isBeforeConfirm = true;
                        if (App.gCurStatus == "loaded")
                        {
                            isBeforeConfirm = false;
                        }
                        var a = Utils.Print_CheckIn(info.DeviceName, head, recs, App.gCompanyName, App.gSalesPersonCode + "/" + App.gSalesPersonName, isBeforeConfirm); //head, recs, customer, sellTo, App.gSalesPersonCode + "/" + App.gSalesPersonName);
                        UserDialogs.Instance.Alert(a);
                        //  Navigation.PopAsync();
                    }
                    else
                    {
                        UserDialogs.Instance.ShowError(retmsg, 3000);
                        _isEnablePrintBtn = true;
                    }
                }
                catch (OperationCanceledException ex)
                {
                    Acr.UserDialogs.UserDialogs.Instance.HideLoading(); //IsLoading = false;
                    UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                    _isEnablePrintBtn = true;
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading(); //IsLoading = false;
                    UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                    _isEnablePrintBtn = true;
                }
            }
        }