Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Console.WriteLine(MainView.user);
            this.lblUsuario.Text = MainView.user;
            ts = new TasksService();
            ts.setUser(MainView.user);

            //Escondemos el boton de regreso hacia la pagina de inicio
            this.NavigationItem.HidesBackButton = true;

            //Creamos el boton de cerrar sesion
            UIBarButtonItem cerrarSesion = new UIBarButtonItem();

            cerrarSesion.Style    = UIBarButtonItemStyle.Plain;
            cerrarSesion.Target   = this;
            cerrarSesion.Title    = "Cerrar Sesión";
            cerrarSesion.Clicked += (sender, e) => {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "¿Salir?", Message = "¿Quieres cerrar la sesión?"
                };
                alert.AddButton("Aceptar");
                alert.AddButton("Cancelar");
                alert.Clicked += (s, o) => {
                    if (o.ButtonIndex == 0)
                    {
                        //lg = new LogoutService();
                        //lg.Logout();
                        NavigationController.PopViewControllerAnimated(true);
                    }
                };
                alert.Show();
            };

            //posionamiento del boton
            this.NavigationItem.LeftBarButtonItem = cerrarSesion;

            try{
                List <TasksService> tableItems = ts.All();
                this.tblTasks.Source       = new TasksTableSource(tableItems, this);
                headerView.BackgroundColor = UIColor.Clear;
                tblTasks.TableHeaderView   = headerView;
                Add(tblTasks);
            }catch (System.Net.WebException) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }

            //Boton de nueva tarea
            btnNuevo.TouchUpInside += (sender, e) => {
                newTaskView = new NewTaskView();
                this.NavigationController.PushViewController(newTaskView, true);
            };

            //Boton de mapa
            btnMap.TouchUpInside += (sender, e) => {
                mapView = new MapViewController();
                this.NavigationController.PushViewController(mapView, true);
            };

            //Boton refrescar
            btnRefresh.TouchUpInside += (sender, e) => {
                try{
                    ts.setUser(MainView.user);
                    List <TasksService> tableItems = ts.All();
                    this.tblTasks.Source = new TasksTableSource(tableItems, this);
                    this.tblTasks.ReloadData();
                }catch (System.Net.WebException) {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            // creacion de la barra de herramientas
            float toolbarHeight = 50;

            toolbar = new UIToolbar(new RectangleF(0
                                                   , this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height
                                                   , this.View.Frame.Width, toolbarHeight));
            toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth;
            toolbar.TintColor        = UIColor.FromRGB(62, 150, 15);


            // boton Todos
            UIBarButtonItem btnTodos = new UIBarButtonItem("   Todos   ", UIBarButtonItemStyle.Bordered, null);

            btnTodos.Clicked += (s, e) => {
                try{
                    ts.setUser(MainView.user);
                    List <TasksService> tableItems = ts.All();
                    this.tblTasks.Source = new TasksTableSource(tableItems, this);
                    this.tblTasks.ReloadData();
                }catch (System.Net.WebException) {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

            // flexible width space
            UIBarButtonItem flexibleWidth0 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);


            // boton Finalizados
            UIBarButtonItem btnFinalizados = new UIBarButtonItem("En Proceso", UIBarButtonItemStyle.Bordered, null);

            btnFinalizados.Clicked += (s, e) => {
                try{
                    String status = "1";
                    ts.setUserandStatus(MainView.user, status);
                    List <TasksService> tableItems = ts.All();
                    this.tblTasks.Source = new TasksTableSource(tableItems, this);
                    this.tblTasks.ReloadData();
                }catch (System.Net.WebException) {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

            // flexible width space
            UIBarButtonItem flexibleWidth1 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);

            // boton En proceso
            UIBarButtonItem btnProceso = new UIBarButtonItem("Finalizados", UIBarButtonItemStyle.Bordered, null);

            btnProceso.Clicked += (s, e) => {
                try{
                    String status = "2";
                    ts.setUserandStatus(MainView.user, status);
                    List <TasksService> tableItems = ts.All();
                    this.tblTasks.Source = new TasksTableSource(tableItems, this);
                    this.tblTasks.ReloadData();
                } catch (System.Net.WebException) {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            // arreglo de botones para toolbar
            UIBarButtonItem[] items = new UIBarButtonItem[] { btnTodos, flexibleWidth0,
                                                              btnFinalizados, flexibleWidth1, btnProceso };

            // agregar los botones a la toolbar
            toolbar.SetItems(items, false);

            // agregar la vista a la pantalla
            this.View.AddSubview(toolbar);
        }
Пример #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Console.WriteLine (MainView.user);
            this.lblUsuario.Text = MainView.user;
            ts = new TasksService ();
            ts.setUser(MainView.user);

            //Escondemos el boton de regreso hacia la pagina de inicio
            this.NavigationItem.HidesBackButton = true;

            //Creamos el boton de cerrar sesion
            UIBarButtonItem cerrarSesion = new UIBarButtonItem();
            cerrarSesion.Style = UIBarButtonItemStyle.Plain;
            cerrarSesion.Target = this;
            cerrarSesion.Title = "Cerrar Sesión";
            cerrarSesion.Clicked += (sender, e) => {
                UIAlertView alert = new UIAlertView(){
                    Title = "¿Salir?" , Message = "¿Quieres cerrar la sesión?"
                };
                alert.AddButton("Aceptar");
                alert.AddButton("Cancelar");
                alert.Clicked += (s, o) => {
                    if(o.ButtonIndex==0){
                        //lg = new LogoutService();
                        //lg.Logout();
                        NavigationController.PopViewControllerAnimated(true);
                    }
                };
                alert.Show();
            };

            //posionamiento del boton
            this.NavigationItem.LeftBarButtonItem = cerrarSesion;

            try{
            List<TasksService> tableItems = ts.All ();
            this.tblTasks.Source = new TasksTableSource (tableItems,this);
            headerView.BackgroundColor = UIColor.Clear;
            tblTasks.TableHeaderView = headerView;
            Add(tblTasks);
            }catch(System.Net.WebException){
                UIAlertView alert = new UIAlertView(){
                    Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }

            //Boton de nueva tarea
            btnNuevo.TouchUpInside += (sender, e) => {
                newTaskView = new NewTaskView();
                this.NavigationController.PushViewController(newTaskView, true);
            };

            //Boton de mapa
            btnMap.TouchUpInside += (sender, e) => {
                mapView = new MapViewController();
                this.NavigationController.PushViewController(mapView, true);
            };

            //Boton refrescar
            btnRefresh.TouchUpInside += (sender, e) => {
                try{
                    ts.setUser(MainView.user);
                    List<TasksService> tableItems = ts.All ();
                    this.tblTasks.Source = new TasksTableSource (tableItems,this);
                    this.tblTasks.ReloadData();
                }catch(System.Net.WebException){
                    UIAlertView alert = new UIAlertView(){
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

             // creacion de la barra de herramientas
            float toolbarHeight = 50;
            toolbar = new UIToolbar (new RectangleF (0
                                                     , this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height
                                                     , this.View.Frame.Width, toolbarHeight));
            toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth;
            toolbar.TintColor = UIColor.FromRGB(62,150,15);

            // boton Todos
            UIBarButtonItem btnTodos = new UIBarButtonItem("   Todos   ",UIBarButtonItemStyle.Bordered, null);
            btnTodos.Clicked += (s, e) => {
                try{
                    ts.setUser(MainView.user);
                    List<TasksService> tableItems = ts.All ();
                    this.tblTasks.Source = new TasksTableSource (tableItems,this);
                    this.tblTasks.ReloadData();
                }catch (System.Net.WebException){
                    UIAlertView alert = new UIAlertView(){
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

            // flexible width space
            UIBarButtonItem flexibleWidth0 = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace);

            // boton Finalizados
            UIBarButtonItem btnFinalizados = new UIBarButtonItem("En Proceso",UIBarButtonItemStyle.Bordered, null);
            btnFinalizados.Clicked += (s, e) => {
                try{
                String status = "1";
                ts.setUserandStatus(MainView.user, status);
                List<TasksService> tableItems = ts.All ();
                this.tblTasks.Source = new TasksTableSource (tableItems,this);
                this.tblTasks.ReloadData();
                }catch (System.Net.WebException){
                    UIAlertView alert = new UIAlertView(){
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

            // flexible width space
            UIBarButtonItem flexibleWidth1 = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace);

            // boton En proceso
            UIBarButtonItem btnProceso = new UIBarButtonItem("Finalizados",UIBarButtonItemStyle.Bordered, null);
            btnProceso.Clicked += (s, e) => {
                try{
                String status = "2";
                ts.setUserandStatus(MainView.user, status);
                List<TasksService> tableItems = ts.All ();
                this.tblTasks.Source = new TasksTableSource (tableItems,this);
                this.tblTasks.ReloadData();
                } catch(System.Net.WebException){
                    UIAlertView alert = new UIAlertView(){
                        Title = "ERROR", Message = "No se pudo conectar al servidor, verifique su conexión a internet"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            // arreglo de botones para toolbar
            UIBarButtonItem[] items = new UIBarButtonItem[] { btnTodos,flexibleWidth0,
                btnFinalizados, flexibleWidth1, btnProceso};

            // agregar los botones a la toolbar
            toolbar.SetItems (items, false);

            // agregar la vista a la pantalla
            this.View.AddSubview (toolbar);
        }