Exemplo n.º 1
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			this.Title = "Menú";


			//Ocultamos el boton de tiendas registradas temporalmente
			//btnTiendas.Hidden = true;
			//btnInfo2.Hidden = true;

			var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
			_pathToDatabase = Path.Combine(documents, "db_sqlite-net.db");

			//Creamos la base de datos y la tabla de persona, en caso de que ya exista no hace nada.
			using (var conn= new SQLite.SQLiteConnection(_pathToDatabase))
			{
				conn.CreateTable<Person>();
			}

			//Hacemos la conexion a la bd para buscar si hay un usuario registrado
			using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
			{
				people = new List<Person> (from p in db.Table<Person> () select p);
			}

			//Establecemos las imagenes de los botones
			setButtonImages();

			//Eventos para los botones de informacion
			this.btnInfo1.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Busca productos por código de barras o nombre", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnInfo2.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Localiza todas las tiendas registradas en FIXBUY", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnInfo3.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Administra tus listas y los productos en ellas", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnInfo4.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Inicia Sesion en FIXBUY para poder acceder a tus listas y más!", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnInfo5.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Establece tu ubicación para una busqueda mas eficaz!", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnInfo6.TouchUpInside += (sender, e) => {
				ToastView view = new ToastView("Consulta los servicios que ofrece FIXBUY", 3000);
				view.SetGravity(ToastGravity.Center,0,0);
				view.Show();
			};

			this.btnCerrarSesion.TouchUpInside += (sender, e) => {
				UIAlertView alert = new UIAlertView () { 
					Title = "Te vas? =(", Message = "Estas seguro que quieres cerrar la sesión?"
				};
				alert.AddButton("Aceptar");
				alert.AddButton("Cancelar");
				alert.Clicked += (s, o) => {
					if(o.ButtonIndex == 0){
						using (var conn= new SQLite.SQLiteConnection(_pathToDatabase))
						{
							conn.DropTable<Person>();
							conn.CreateTable<Person>();
						}
						this.NavigationController.PopViewController(true);
					}
				};
				alert.Show ();
			};

			//Boton de buscar productos
			this.btnScan.TouchUpInside += (sender, e) => {
				// Configurar el escaner de codigo de barras.
				picker = new ScanditSDKRotatingBarcodePicker (MainView.appKey);
				picker.OverlayController.Delegate = new overlayControllerDelegate(picker, this);
				picker.OverlayController.ShowToolBar(true);
				picker.OverlayController.ShowSearchBar(true);
				picker.OverlayController.SetToolBarButtonCaption("Cancelar");
				picker.OverlayController.SetSearchBarKeyboardType(UIKeyboardType.Default);
				picker.OverlayController.SetSearchBarPlaceholderText("Búsqueda por nombre de producto");
				picker.OverlayController.SetCameraSwitchVisibility(SICameraSwitchVisibility.OnTablet);
				picker.OverlayController.SetTextForInitializingCamera("Iniciando la camara");
				this.PresentViewController (picker, true, null);

				picker.StartScanning ();
			};

			//Boton de tiendas Registradas
			this.btnTiendas.TouchUpInside += (sender, e) => {
				this._loadPop = new LoadingOverlay (UIScreen.MainScreen.Bounds);
				this.Add ( this._loadPop );
				mvp =  new MapViewController();
				Task.Factory.StartNew (
					() => {
						System.Threading.Thread.Sleep ( 1 * 1000 );
					}
				).ContinueWith ( 
					t => {
						this._loadPop.Hide ();
						this.NavigationController.PushViewController(mvp, true);
					}, TaskScheduler.FromCurrentSynchronizationContext()
				);
			};

			//Boton Mis listas
			this.btnListas.TouchUpInside += (sender, e) => {
				if (people.Count == 1) {
					MyListsView myLists = new MyListsView ();
					this.NavigationController.PushViewController (myLists, true);
				} else {
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas"
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				}
			};

			//Boton Iniciar Sesion
			this.btnSesion.TouchUpInside += (sender, e) => {
				if (people.Count == 1) {
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Ya has iniciado sesión"
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				} else {
					LoginView login = new LoginView ();
					this.NavigationController.PushViewController (login, true);
				}
			};

			//Boton Novedades
			this.btnNovedades.TouchUpInside += (sender, e) => {
				StatesView statesView = new StatesView();
				this.NavigationController.PushViewController(statesView, true);
			};

			//Boton Nuestros Servicios
			this.btnServicios.TouchUpInside += (sender, e) => {
				AboutUsView aboutUS = new AboutUsView ();
				this.NavigationController.PushViewController (aboutUS, true);
			};

			// creacion de la barra de herramientas
			float toolbarHeight = 44;
			toolbar = new UIToolbar (new CGRect (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(7, 129, 181);

			// boton acerca de
			UIBarButtonItem btnacercaDe = new UIBarButtonItem (UIBarButtonSystemItem.Bookmarks);
			btnacercaDe.Clicked += (s, e) => {
				UIAlertView alert = new UIAlertView () { 
					Title = "Que deseas consultar? "
				};
				alert.AddButton("Terminos y Condiciones");
				alert.AddButton("Aviso de Privacidad");
				alert.Clicked+= (sen, o) =>{
					if(o.ButtonIndex == 0)
					{
						TermsView termsView = new TermsView();
						NavigationController.PushViewController(termsView, true);
					}else{
						PrivacyNoticeView privacyNoticeView = new PrivacyNoticeView();
						NavigationController.PushViewController(privacyNoticeView, true);
					}
				};
				alert.Show ();
			};
			// fixed width
			//UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
			//fixedWidth.Width = 35;

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

			// boton fixBuy
			UIBarButtonItem btnFixBuy = new UIBarButtonItem (UIBarButtonSystemItem.Search);
			btnFixBuy.Clicked += (s, e) => { 
				NSUrl url = new NSUrl (@"http://fixbuy.mx");
				UIApplication.SharedApplication.OpenUrl (url);
			};

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

			// boton email
			UIBarButtonItem btnEmail = new UIBarButtonItem (UIBarButtonSystemItem.Compose);
			btnEmail.Clicked += (s, e) => {  
				//Añadimos las configuraciones para la vista de email
				mailController = new MFMailComposeViewController ();
				mailController.SetToRecipients (new string[]{"*****@*****.**"});
				mailController.SetSubject ("Contacto");
				mailController.SetMessageBody ("", false);
				mailController.Finished += ( object o, MFComposeResultEventArgs args) => {
					Console.WriteLine (args.Result.ToString ());
					args.Controller.DismissViewController (true, null);
				};

				this.PresentViewController (mailController, true, null);
			};

			// arreglo de botones para toolbar
			UIBarButtonItem[] items = new UIBarButtonItem[] { 
				btnacercaDe, flexibleWidth1, btnFixBuy, flexibleWidth2, btnEmail};

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

			// agregar la vista a la pantalla
			this.View.AddSubview (toolbar);
			try{
				//Leemos el servicio de los banners
				this.bannersService = new BannersService ();
				banners = bannersService.All ();
			} catch (System.Net.WebException){
				UIAlertView alert = new UIAlertView () { 
					Title = "UPS :S", Message = "Hubo un error al conectarse a internet la seccion de banners no puede mostrarse, por favor verifica tu conexión a internet"
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}

			button = new UIButton (new CGRect (0, 0, bannerImage.Bounds.Width, bannerImage.Bounds.Height));
			bannerImage.Add (button);
			button.TouchUpInside += (sender, e) => {
				try{
						if(bannerError == false){
						if(element.imagen != ""){
							NSUrl url = new NSUrl (element.link);
							UIApplication.SharedApplication.OpenUrl (url);
						}
					}
				}catch(Exception){
					//solo atrapamos la excepcion, no hacemos nada
				}
			};
		}
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.Title = "Menú";


            //Ocultamos el boton de tiendas registradas temporalmente
            //btnTiendas.Hidden = true;
            //btnInfo2.Hidden = true;

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            _pathToDatabase = Path.Combine(documents, "db_sqlite-net.db");

            //Creamos la base de datos y la tabla de persona, en caso de que ya exista no hace nada.
            using (var conn = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                conn.CreateTable <Person>();
            }

            //Hacemos la conexion a la bd para buscar si hay un usuario registrado
            using (var db = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                people = new List <Person> (from p in db.Table <Person> () select p);
            }

            //Establecemos las imagenes de los botones
            setButtonImages();

            //Eventos para los botones de informacion
            this.btnInfo1.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Busca productos por código de barras o nombre", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo2.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Localiza todas las tiendas registradas en FIXBUY", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo3.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Administra tus listas y los productos en ellas", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo4.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Inicia Sesion en FIXBUY para poder acceder a tus listas y más!", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo5.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Establece tu ubicación para una busqueda mas eficaz!", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnInfo6.TouchUpInside += (sender, e) => {
                ToastView view = new ToastView("Consulta los servicios que ofrece FIXBUY", 3000);
                view.SetGravity(ToastGravity.Center, 0, 0);
                view.Show();
            };

            this.btnCerrarSesion.TouchUpInside += (sender, e) => {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Te vas? =(", Message = "Estas seguro que quieres cerrar la sesión?"
                };
                alert.AddButton("Aceptar");
                alert.AddButton("Cancelar");
                alert.Clicked += (s, o) => {
                    if (o.ButtonIndex == 0)
                    {
                        using (var conn = new SQLite.SQLiteConnection(_pathToDatabase))
                        {
                            conn.DropTable <Person>();
                            conn.CreateTable <Person>();
                        }
                        this.NavigationController.PopViewController(true);
                    }
                };
                alert.Show();
            };

            //Boton de buscar productos
            this.btnScan.TouchUpInside += (sender, e) => {
                // Configurar el escaner de codigo de barras.
                picker = new ScanditSDKRotatingBarcodePicker(MainView.appKey);
                picker.OverlayController.Delegate = new overlayControllerDelegate(picker, this);
                picker.OverlayController.ShowToolBar(true);
                picker.OverlayController.ShowSearchBar(true);
                picker.OverlayController.SetToolBarButtonCaption("Cancelar");
                picker.OverlayController.SetSearchBarKeyboardType(UIKeyboardType.Default);
                picker.OverlayController.SetSearchBarPlaceholderText("Búsqueda por nombre de producto");
                picker.OverlayController.SetCameraSwitchVisibility(SICameraSwitchVisibility.OnTablet);
                picker.OverlayController.SetTextForInitializingCamera("Iniciando la camara");
                this.PresentViewController(picker, true, null);

                picker.StartScanning();
            };

            //Boton de tiendas Registradas
            this.btnTiendas.TouchUpInside += (sender, e) => {
                this._loadPop = new LoadingOverlay(UIScreen.MainScreen.Bounds);
                this.Add(this._loadPop);
                mvp = new MapViewController();
                Task.Factory.StartNew(
                    () => {
                    System.Threading.Thread.Sleep(1 * 1000);
                }
                    ).ContinueWith(
                    t => {
                    this._loadPop.Hide();
                    this.NavigationController.PushViewController(mvp, true);
                }, TaskScheduler.FromCurrentSynchronizationContext()
                    );
            };

            //Boton Mis listas
            this.btnListas.TouchUpInside += (sender, e) => {
                if (people.Count == 1)
                {
                    MyListsView myLists = new MyListsView();
                    this.NavigationController.PushViewController(myLists, true);
                }
                else
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            //Boton Iniciar Sesion
            this.btnSesion.TouchUpInside += (sender, e) => {
                if (people.Count == 1)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Ya has iniciado sesión"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
                else
                {
                    LoginView login = new LoginView();
                    this.NavigationController.PushViewController(login, true);
                }
            };

            //Boton Novedades
            this.btnNovedades.TouchUpInside += (sender, e) => {
                StatesView statesView = new StatesView();
                this.NavigationController.PushViewController(statesView, true);
            };

            //Boton Nuestros Servicios
            this.btnServicios.TouchUpInside += (sender, e) => {
                AboutUsView aboutUS = new AboutUsView();
                this.NavigationController.PushViewController(aboutUS, true);
            };

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

            toolbar = new UIToolbar(new CGRect(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(7, 129, 181);

            // boton acerca de
            UIBarButtonItem btnacercaDe = new UIBarButtonItem(UIBarButtonSystemItem.Bookmarks);

            btnacercaDe.Clicked += (s, e) => {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Que deseas consultar? "
                };
                alert.AddButton("Terminos y Condiciones");
                alert.AddButton("Aviso de Privacidad");
                alert.Clicked += (sen, o) => {
                    if (o.ButtonIndex == 0)
                    {
                        TermsView termsView = new TermsView();
                        NavigationController.PushViewController(termsView, true);
                    }
                    else
                    {
                        PrivacyNoticeView privacyNoticeView = new PrivacyNoticeView();
                        NavigationController.PushViewController(privacyNoticeView, true);
                    }
                };
                alert.Show();
            };
            // fixed width
            //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
            //fixedWidth.Width = 35;

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

            // boton fixBuy
            UIBarButtonItem btnFixBuy = new UIBarButtonItem(UIBarButtonSystemItem.Search);

            btnFixBuy.Clicked += (s, e) => {
                NSUrl url = new NSUrl(@"http://fixbuy.mx");
                UIApplication.SharedApplication.OpenUrl(url);
            };

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

            // boton email
            UIBarButtonItem btnEmail = new UIBarButtonItem(UIBarButtonSystemItem.Compose);

            btnEmail.Clicked += (s, e) => {
                //Añadimos las configuraciones para la vista de email
                mailController = new MFMailComposeViewController();
                mailController.SetToRecipients(new string[] { "*****@*****.**" });
                mailController.SetSubject("Contacto");
                mailController.SetMessageBody("", false);
                mailController.Finished += (object o, MFComposeResultEventArgs args) => {
                    Console.WriteLine(args.Result.ToString());
                    args.Controller.DismissViewController(true, null);
                };

                this.PresentViewController(mailController, true, null);
            };

            // arreglo de botones para toolbar
            UIBarButtonItem[] items = new UIBarButtonItem[] {
                btnacercaDe, flexibleWidth1, btnFixBuy, flexibleWidth2, btnEmail
            };

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

            // agregar la vista a la pantalla
            this.View.AddSubview(toolbar);
            try{
                //Leemos el servicio de los banners
                this.bannersService = new BannersService();
                banners             = bannersService.All();
            } catch (System.Net.WebException) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "UPS :S", Message = "Hubo un error al conectarse a internet la seccion de banners no puede mostrarse, por favor verifica tu conexión a internet"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }

            button = new UIButton(new CGRect(0, 0, bannerImage.Bounds.Width, bannerImage.Bounds.Height));
            bannerImage.Add(button);
            button.TouchUpInside += (sender, e) => {
                try{
                    if (bannerError == false)
                    {
                        if (element.imagen != "")
                        {
                            NSUrl url = new NSUrl(element.link);
                            UIApplication.SharedApplication.OpenUrl(url);
                        }
                    }
                }catch (Exception) {
                    //solo atrapamos la excepcion, no hacemos nada
                }
            };
        }