Пример #1
0
        public List()
        {
            InitializeComponent();

            Tickets = new TicketsDataBase();
            var tickets = Tickets.GetMembers();

            listMembers.ItemsSource = tickets;
        }
        private async void Finish()
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Confirmación", "¿Desea terminar el viaje?", "Sí", "No");

            if (!answer)
            {
                return;
            }

            this.IsRunning   = true;
            this.IsEnableAct = false;

            TicketsModel = new TicketsDataBase();
            LoginModel   = new LoginDataBase();

            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", connection.Message, "Aceptar");

                this.IsRunning   = false;
                this.IsEnableAct = true;
                return;
            }

            var POS = TicketsModel.GetMembers();

            foreach (var item in POS)
            {
                var TicketsPOS = new TicketsModel
                {
                    Origen     = item.Origen,
                    Destino    = item.Destino,
                    idOrigen   = item.idOrigen,
                    idDestino  = item.idDestino,
                    NoPersonas = item.NoPersonas,
                    ValTicket  = item.ValTicket,
                    Encomienda = item.Encomienda,
                    Alert      = item.Alert,
                    Hora       = item.Hora,
                    idViaje    = item.idViaje,
                    Fecha      = item.Fecha
                };

                var url        = Application.Current.Resources["UrlAPI"].ToString();
                var prefix     = Application.Current.Resources["UrlPrefix"].ToString();
                var controller = Application.Current.Resources["UrlTicket"].ToString();
                var response   = await this.apiService.PostPrint <TicketsModel>(url, prefix, controller, TicketsPOS);

                if (!response.IsSuccess)
                {
                    await App.Current.MainPage.DisplayAlert("El servicio esta malo", "Comunicate con el administrador", "Aceptar");

                    this.IsRunning   = false;
                    this.IsEnableAct = true;
                    return;
                }
            }

            var consulta       = TicketsModel.GetMembers();
            int PersonasInt    = 0;
            int EncomiendasInt = 0;

            foreach (var item in consulta)
            {
                if (item.Encomienda)
                {
                    EncomiendasInt += item.ValTicket;
                }
                else
                {
                    PersonasInt += item.ValTicket;
                }
            }

            int    TotalInt    = PersonasInt + EncomiendasInt;
            string Total       = string.Format("{0, 0:C0}", TotalInt);
            string Personas    = string.Format("{0, 0:C0}", PersonasInt);
            string Encomiendas = string.Format("{0, 0:C0}", EncomiendasInt);

            Mensaje = "             COOTRASANA" + "\n" + "  Cooperativa de Trasportadores" + "             San Antonio" + "\n\n" + "Debes Liquidar" + "\n\n" + "Fecha: " + DateTime.Now + "\n\n" + "Por Personas: " + Personas + "\n\n" + "Por Encomiendas: " + Encomiendas + "\n\n" + "Total: " + Total + "\n\n" + "Peajes: " + "\n\n" + "Combustible: " + "\n\n" + "Viaticos: " + "\n\n" + "Otros: " + "\n\n" + "Total: " + "\n\n" + "--------------------------------\n\n";
            Imprimir(Mensaje);
            await Application.Current.MainPage.DisplayAlert("Debes Liquidar", "Por personas: " + Personas + "\n" + "Por Encomienda: " + Encomiendas + "\n" + "Total: " + Total, "Aceptar");

            Imprimir(Mensaje);
            TicketsModel.DeleteTable();
            LoginModel.DeleteTable();
            await Application.Current.MainPage.Navigation.PopAsync();

            MainViewModel.GetInstance().Login = new LoginViewModel();
            await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());

            this.IsRunning   = false;
            this.IsEnableAct = true;
        }