Beispiel #1
0
		internal static ListsService FromJObject(JObject jObject)
		{
			ListsService response = new ListsService();
			response.id = jObject["id"].ToString();
			response.nombre = jObject["name"].ToString();
			response.usuario_id = jObject ["user_id"].ToString ();

			return response;
		}
Beispiel #2
0
        internal static ListsService FromJObject(JObject jObject)
        {
            ListsService response = new ListsService();

            response.id         = jObject["id"].ToString();
            response.nombre     = jObject["name"].ToString();
            response.usuario_id = jObject ["user_id"].ToString();

            return(response);
        }
Beispiel #3
0
        public List <ListsService> GetResponse()
        {
            WebClient           client       = new WebClient();
            Stream              stream       = client.OpenRead(this.resultURL);
            StreamReader        reader       = new StreamReader(stream);
            JArray              responseJSON = JArray.Parse(reader.ReadLine());
            List <ListsService> responseList = new List <ListsService>();

            foreach (JObject jobject in responseJSON)
            {
                ListsService response = ListsService.FromJObject(jobject);

                responseList.Add(response);
            }

            return(responseList);
        }
Beispiel #4
0
 public UIButton getButton(int index)
 {
     botones.ElementAt(index).Frame = new CGRect(0, 0, Images.basura48.Size.Width, Images.basura48.Size.Height);
     botones.ElementAt(index).SetBackgroundImage(Images.basura48, UIControlState.Normal);
     botones.ElementAt(index).BackgroundColor = UIColor.Clear;
     botones.ElementAt(index).TouchUpInside  += (sender, e) => {
         UIAlertView alert = new UIAlertView()
         {
             Title = "Borrar?", Message = "Deseas borrar esta lista?"
         };
         alert.AddButton("Aceptar");
         alert.AddButton("Cancelar");
         alert.Clicked += (s, o) => {
             if (o.ButtonIndex == 0)
             {
                 DestroyService destroyService = new DestroyService();
                 String         respuesta      = destroyService.destroyList(tableItems[index].id);
                 if (respuesta.Equals("\"correct\""))
                 {
                     UIAlertView alert1 = new UIAlertView()
                     {
                         Title = "Lita borrada", Message = "La lista ha sido borrada =)"
                     };
                     alert1.AddButton("Aceptar");
                     alert1.Show();
                     ListsService ls = new ListsService();
                     ls.setUserId(MainView.userId.ToString());
                     List <ListsService> listas = ls.All();
                     MyListsView.tableView.Source = new ListsTableSourceIphone(listas, this.controller);
                     MyListsView.tableView.ReloadData();
                 }
                 else if (respuesta.Equals("\"error\""))
                 {
                     UIAlertView alert2 = new UIAlertView()
                     {
                         Title = "Ups :S", Message = "Algo salio mal, por favor intentalo de nuevo"
                     };
                     alert2.AddButton("Aceptar");
                     alert2.Show();
                 }
             }
         };
         alert.Show();
     };
     return(botones.ElementAt(index));
 }
Beispiel #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            try{
                UIBarButtonItem home = new UIBarButtonItem();
                home.Style  = UIBarButtonItemStyle.Plain;
                home.Target = this;
                home.Image  = UIImage.FromFile("Images/home.png");
                this.NavigationItem.RightBarButtonItem = home;
                UIViewController[] vistas = NavigationController.ViewControllers;
                home.Clicked += (sender, e) => {
                    this.NavigationController.PopToViewController(vistas[0], true);
                };

                //Configuramos la vista popup de nueva lista
                NewListView.Layer.BorderWidth  = 1.0f;
                NewListView.Layer.BorderColor  = UIColor.Black.CGColor;
                NewListView.Layer.CornerRadius = 8;
                tblLists.Add(this.NewListView);
                NewListView.Hidden = true;
                //Configuramos la vista popup de cantidad
                QuantityView.Layer.BorderWidth  = 1.0f;
                QuantityView.Layer.BorderColor  = UIColor.Black.CGColor;
                QuantityView.Layer.CornerRadius = 8;
                this.Add(QuantityView);
                QuantityView.Hidden = true;

                //Configuramos la vista de popup de listas
                ListsView.Layer.BorderWidth  = 1.0f;
                ListsView.Layer.BorderColor  = UIColor.Black.CGColor;
                ListsView.Layer.CornerRadius = 8;
                this.Add(this.ListsView);
                ListsView.Hidden = true;

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    this.btnMapa.SetBackgroundImage(Images.mapa, UIControlState.Normal);
                }
                else
                {
                    this.btnMapa.SetBackgroundImage(Images.mapa, UIControlState.Normal);
                }

                this.btnMapa.TouchUpInside += (sender, e) => {
                    SecondMapViewController mapView = new SecondMapViewController();
                    mapView.setTienda(this.producto);
                    NavigationController.PushViewController(mapView, true);
                };

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

                //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);
                }

                NSUrl nsUrl = new NSUrl(producto.imagen);
                data = NSData.FromUrl(nsUrl);
                if (data != null)
                {
                    Images.imagenDetalle   = UIImage.LoadFromData(data);
                    this.imgProducto.Image = Images.imagenDetalle;
                }
                else
                {
                    this.imgProducto.Image = Images.sinImagen;
                }

                //Establecemos la informacion del producto
                this.lblNombre.Text = producto.nombre;
                double precio = Double.Parse(producto.precio);
                this.lblPrecio.Text      = precio.ToString("C2");
                this.lblDescripcion.Text = producto.descripcion;
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    this.lblDescripcion.Font = UIFont.SystemFontOfSize(10);
                }
                else
                {
                    this.lblDescripcion.Font = UIFont.SystemFontOfSize(25);
                }
                //Establecemos la informacion de la tienda
                NSUrl  nsurl = new NSUrl(producto.tienda_imagen);
                NSData data1 = NSData.FromUrl(nsurl);
                if (data1 != null)
                {
                    Images.imagenDetalleTienda = UIImage.LoadFromData(data1);
                    this.imgTienda.Image       = Images.imagenDetalleTienda;
                }
                else
                {
                    this.imgTienda.Image = Images.sinImagen;
                }
                this.lblTiendaNombre.Text    = producto.tienda_nombre;
                this.lblTiendaDireccion.Text = producto.tienda_direccion + "\n \nTeléfono: " + producto.tienda_telefono;
                if (distancia != 0)
                {
                    this.lblTiendaDistancia.Text = "A " + Math.Round(distancia, 2) + "km de tu ubicación";
                }
                else
                {
                    this.lblTiendaDistancia.Text = "Distancia no disponible";
                }
                this.lblVigencia.Text = "Vigencia del " + producto.inicio_validez + " Al " + producto.final_validez;

                this.btnLista.TouchUpInside += (sender, e) => {
                    if (people.Count > 0)
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Añadir a mi lista", Message = "¿Deseas añadir este producto a una de tus listas?"
                        };
                        alert.AddButton("Añadir");
                        alert.AddButton("Cancelar");
                        alert.Show();
                        alert.Clicked += (s, o) => {
                            if (o.ButtonIndex == 0)
                            {
                                QuantityView.Hidden = false;
                            }
                        };
                    }
                    else
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                int cantidad = 1;
                this.cmpCantidad.Text = cantidad.ToString();
                btnMas.TouchUpInside += (sender, e) => {
                    cantidad++;
                    this.cmpCantidad.Text = cantidad.ToString();
                };

                btnMenos.TouchUpInside += (sender, e) => {
                    cantidad--;
                    if (cantidad < 1)
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Espera!", Message = "La cantidad minima es 1"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                        cantidad = 1;
                        this.cmpCantidad.Text = cantidad.ToString();
                    }
                    else
                    {
                        this.cmpCantidad.Text = cantidad.ToString();
                    }
                };

                this.btnAceptarCantidad.TouchUpInside += (sender, e) => {
                    try{
                        if (cmpCantidad.Text.Equals(""))
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "Espera!", Message = "Debes ingresar la cantidad"
                            };
                            alert.AddButton("Registrar");
                            alert.AddButton("Cancelar");
                            alert.Show();
                        }
                        else
                        {
                            cmpCantidad.ResignFirstResponder();
                            QuantityView.Hidden = true;
                            ls = new ListsService();
                            Person persona = people.ElementAt(0);
                            ls.setUserId(persona.ID.ToString());
                            List <ListsService> tableItems = ls.All();
                            if (tableItems.Count > 0)
                            {
                                this.tblLists.Source = new AddToListsTableSource(tableItems, this, this.producto, int.Parse(cmpCantidad.Text));
                                ListsView.Add(this.tblLists);
                                this.tblLists.ReloadData();
                                ListsView.Hidden = false;
                                cmpCantidad.Text = "";
                            }
                            else
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "No tienes listas", Message = "No tienes listas registradas, porfavor ve a \"Mis listas\" para crear una nueva"
                                };
                                alert.AddButton("Registrar");
                                alert.AddButton("Cancelar");
                                alert.Show();
                            }
                        }
                    }catch (System.FormatException ex) {
                        Console.WriteLine(ex.ToString());
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Espera!", Message = "Debes ingresar solo números"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                        QuantityView.Hidden = false;
                    }catch (System.Net.WebException) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups :S", Message = "Algo salio mal,no se pudieron cargar tus listas, verifica tu conexión a internet e inténtalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }catch (System.Exception ext) {
                        Console.WriteLine(ext.ToString());
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups :S", Message = "Ocurrió un problema, inténtalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                btnCerrarLista.TouchUpInside += (sender, e) => {
                    ListsView.Hidden = true;
                };

                btnBadPrice.TouchUpInside += (sender, e) => {
                    if (MainView.userId != 0)
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Gracias por su reporte", Message = "Estamos revisando constantemente los precios de los productos y le agradecemos su aportación, ¿le gustaría reportar el precio de este producto para su revision?"
                        };
                        alert.AddButton("SI");
                        alert.AddButton("NO");
                        alert.Clicked += (s, o) => {
                            try{
                                if (o.ButtonIndex == 0)
                                {
                                    ReportService report    = new ReportService();
                                    String        respuesta = report.SetData(MainView.userId.ToString(), this.producto.id, this.producto.tienda_id, this.producto.precio);
                                    if (respuesta.Equals("\"correct\""))
                                    {
                                        UIAlertView alert2 = new UIAlertView()
                                        {
                                            Title = "Muchas gracias!", Message = "En FixBuy estamos comprometidos con ofrecer siempre la informacion correcta, muchas gracias por tu reporte =)"
                                        };
                                        alert2.AddButton("Aceptar");
                                        alert2.Show();
                                    }
                                    else
                                    {
                                        UIAlertView alert3 = new UIAlertView()
                                        {
                                            Title = "UPS :S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
                                        };
                                        alert3.AddButton("Aceptar");
                                        alert3.Show();
                                    }
                                }
                            }catch (System.Net.WebException) {
                                UIAlertView alerta = new UIAlertView()
                                {
                                    Title = "UPS :S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
                                };
                                alerta.AddButton("Aceptar");
                                alerta.Show();
                            }catch (Exception) {
                                UIAlertView alerta = new UIAlertView()
                                {
                                    Title = "UPS :S", Message = "Algo salio mal, por favor intentalo de nuevo"
                                };
                                alerta.AddButton("Aceptar");
                                alerta.Show();
                            }
                        };
                        alert.Show();
                    }
                    else
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Espera!", Message = "Debes iniciar sesión para poder reportar el precio incorrecto"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                btnFacebook.TouchUpInside += (sender, e) => {
                    try{
                        if (MainView.isWithFacebook == true)
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "Quieres publicar este producto?", Message = "Deseas publicar este producto en tu perfil de Facebook?"
                            };
                            alert.AddButton("Aceptar");
                            alert.AddButton("Cancelar");
                            alert.Clicked += (s, o) => {
                                if (o.ButtonIndex == 0)
                                {
                                    var post = new NSMutableDictionary();
                                    if (data != null)
                                    {
                                        post.Add(new NSString("message"), new NSString(producto.imagen + "\t" + producto.nombre + "\t(" + producto.descripcion + ")" + "\nGracias a FixBuy encontre mi producto =D"));
                                    }
                                    else
                                    {
                                        post.Add(new NSString("message"), new NSString(producto.nombre + "\t(" + producto.descripcion + ")" + "\nGracias a FixBuy encontre mi producto =D "));
                                    }
                                    // Ask for publish_actions permissions in context
                                    if (!FBSession.ActiveSession.Permissions.Contains("publish_actions"))
                                    {
                                        // No permissions found in session, ask for it
                                        FBSession.ActiveSession.RequestNewPublishPermissions(new [] { "publish_actions" }, FBSessionDefaultAudience.Friends, (session, error) => {
                                            if (error != null)
                                            {
                                                InvokeOnMainThread(() => new UIAlertView("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Aceptar", null).Show());
                                            }
                                            else
                                            {
                                                // If permissions granted, publish the story
                                                FBRequestConnection.StartWithGraphPath("me/feed", post, "POST", (connection, result, err) => {
                                                    if (err != null)
                                                    {
                                                        InvokeOnMainThread(() => new UIAlertView("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Aceptar", null).Show());
                                                    }
                                                    else
                                                    {
                                                        HelloId = (result as FBGraphObject)["id"] as NSString;
                                                        InvokeOnMainThread(() => new UIAlertView("Producto publicado =)", "El producto que FixBuy te ayudo a encontrar a sido publicado en tu biografia =)", null, "Aceptar", null).Show());
                                                    }
                                                });
                                            }
                                        });
                                    }
                                    else
                                    {
                                        // If permissions is found, publish the story
                                        FBRequestConnection.StartWithGraphPath("me/feed", post, "POST", (connection, result, err) => {
                                            if (err != null)
                                            {
                                                InvokeOnMainThread(() => new UIAlertView("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Ok", null).Show());
                                            }
                                            else
                                            {
                                                HelloId = (result as FBGraphObject)["id"] as NSString;
                                                InvokeOnMainThread(() => new UIAlertView("Producto publicado =)", "El producto que FixBuy te ayudo a encontrar a sido publicado en tu biografia =)", null, "Aceptar", null).Show());
                                            }
                                        });
                                    }
                                }
                            };
                            alert.Show();
                        }
                        else
                        {
                            InvokeOnMainThread(() => new UIAlertView("No has entrado a Facebook", "Debes iniciar sesion en Facebook para poder publicar tu producto, por favor regresa a la pantalla inicial para iniciar sesion en Facebook", null, "Aceptar", null).Show());
                        }
                    }catch (Exception exc) {
                        Console.WriteLine("UPS: " + exc.ToString());
                    }
                    //Console.WriteLine(HelloId.ToString());
                };

                btnNuevaLista.TouchUpInside += (sender, e) => {
                    this.NewListView.Hidden = false;
                };

                btnAceptarNuevaLista.TouchUpInside += (sender, e) => {
                    try{
                        if (cmpNewList.Text == "")
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
                            };
                            alert.AddButton("Aceptar");
                            alert.Show();
                        }
                        else
                        {
                            nls = new NewListService();
                            String respuesta = nls.SetListData(cmpNewList.Text, MainView.userId.ToString());
                            if (respuesta.Equals("\"lista ya existe\""))
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();
                                //cmpNewList.Hidden = true;
                                cmpNewList.Text = "";
                                cmpNewList.ResignFirstResponder();
                            }
                            else
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Lista creada", Message = "Tu nueva lista \"" + cmpNewList.Text + "\" ha sido creada =D"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();
                                ls = new ListsService();
                                ls.setUserId(MainView.userId.ToString());
                                List <ListsService> items = ls.All();
                                this.tblLists.Source = new AddToListsTableSource(items, this, producto, 1);
                                this.tblLists.ReloadData();
                                cmpNewList.Text    = "";
                                NewListView.Hidden = true;
                                cmpNewList.ResignFirstResponder();
                            }
                        }
                    }catch (System.Net.WebException) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }catch (Exception exc) {
                        Console.WriteLine(exc.ToString());
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                btnCerrarNombreNL.TouchUpInside += (sender, e) => {
                    this.NewListView.Hidden = true;
                    this.cmpNewList.ResignFirstResponder();
                };
            }catch (Exception e) {
                Console.WriteLine(e.ToString());
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }

            try{
                //Registramos la visita al producto en la aplicacion web
                RegisterVisit(producto.tienda_id, MainView.userId);
            }
            catch (Exception) {
                /*Atrapamos la excepcion en caso de que el registro de la visita no pueda hacerse
                 * sin mostrar ningun mensaje ni detener el flujo de la aplicacion*/
            }

            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
                }
            };
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			try{
				UIBarButtonItem home = new UIBarButtonItem();
				home.Style = UIBarButtonItemStyle.Plain;
				home.Target = this;
				home.Image = UIImage.FromFile("Images/home.png");
				this.NavigationItem.RightBarButtonItem = home;
				UIViewController[] vistas = NavigationController.ViewControllers;
				home.Clicked += (sender, e) => {
					this.NavigationController.PopToViewController(vistas[0], true);
				};
					
				//Configuramos la vista popup de nueva lista
				NewListView.Layer.BorderWidth = 1.0f;
				NewListView.Layer.BorderColor = UIColor.Black.CGColor;
				NewListView.Layer.CornerRadius = 8;
				tblLists.Add(this.NewListView);
				NewListView.Hidden = true;
				//Configuramos la vista popup de cantidad
				QuantityView.Layer.BorderWidth = 1.0f;
				QuantityView.Layer.BorderColor = UIColor.Black.CGColor;
				QuantityView.Layer.CornerRadius = 8;
				this.Add(QuantityView);
				QuantityView.Hidden = true;

				//Configuramos la vista de popup de listas
				ListsView.Layer.BorderWidth = 1.0f;
				ListsView.Layer.BorderColor = UIColor.Black.CGColor;
				ListsView.Layer.CornerRadius = 8;
				this.Add(this.ListsView);
				ListsView.Hidden = true;

				if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
					this.btnMapa.SetBackgroundImage(Images.mapa,UIControlState.Normal);
				}else{
					this.btnMapa.SetBackgroundImage(Images.mapa,UIControlState.Normal);
				}

				this.btnMapa.TouchUpInside += (sender, e) => {
					SecondMapViewController mapView = new SecondMapViewController();
					mapView.setTienda(this.producto);
					NavigationController.PushViewController(mapView,true);
				};

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

				//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);
				}

				NSUrl nsUrl = new NSUrl (producto.imagen);
				data = NSData.FromUrl (nsUrl);
				if(data!= null){
					Images.imagenDetalle = UIImage.LoadFromData(data);
					this.imgProducto.Image = Images.imagenDetalle;
				}else{
					this.imgProducto.Image = Images.sinImagen;
				}
					
				//Establecemos la informacion del producto
				this.lblNombre.Text = producto.nombre;
				double precio = Double.Parse(producto.precio);
				this.lblPrecio.Text = precio.ToString("C2");
				this.lblDescripcion.Text = producto.descripcion;
				if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
					this.lblDescripcion.Font = UIFont.SystemFontOfSize(10);
				}else{
					this.lblDescripcion.Font = UIFont.SystemFontOfSize(25);
				}
				//Establecemos la informacion de la tienda
				NSUrl nsurl = new NSUrl(producto.tienda_imagen);
				NSData data1 = NSData.FromUrl(nsurl);
				if(data1 != null){
					Images.imagenDetalleTienda = UIImage.LoadFromData(data1);
					this.imgTienda.Image = Images.imagenDetalleTienda;
				}else{
					this.imgTienda.Image = Images.sinImagen;
				}
				this.lblTiendaNombre.Text = producto.tienda_nombre;
				this.lblTiendaDireccion.Text = producto.tienda_direccion + "\n \nTeléfono: " + producto.tienda_telefono;
				if(distancia != 0){
					this.lblTiendaDistancia.Text = "A "+ Math.Round(distancia,2)+"km de tu ubicación";
				}else{
					this.lblTiendaDistancia.Text = "Distancia no disponible";
				}
				this.lblVigencia.Text = "Vigencia del "+ producto.inicio_validez+ " Al "+ producto.final_validez;
			
				this.btnLista.TouchUpInside += (sender, e) => {
					if(people.Count > 0){
						UIAlertView alert = new UIAlertView () { 
							Title = "Añadir a mi lista", Message = "¿Deseas añadir este producto a una de tus listas?"
						};
						alert.AddButton("Añadir");
						alert.AddButton ("Cancelar");
						alert.Show();
						alert.Clicked += (s, o) => {
							if(o.ButtonIndex == 0){
								QuantityView.Hidden = false;
							}
						};
					}else{
						UIAlertView alert = new UIAlertView () { 
							Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas"
						};
						alert.AddButton("Aceptar");
						alert.Show();
					}
				};

				int cantidad = 1;
				this.cmpCantidad.Text = cantidad.ToString();
				btnMas.TouchUpInside += (sender, e) => {
					cantidad ++;
					this.cmpCantidad.Text = cantidad.ToString();
				};

				btnMenos.TouchUpInside += (sender, e) => {
					cantidad --;
					if(cantidad < 1){
						UIAlertView alert = new UIAlertView () { 
							Title = "Espera!", Message = "La cantidad minima es 1"
						};
						alert.AddButton("Aceptar");
						alert.Show();
						cantidad = 1;
						this.cmpCantidad.Text = cantidad.ToString();
					}else{
						this.cmpCantidad.Text = cantidad.ToString();
					}
				};

				this.btnAceptarCantidad.TouchUpInside += (sender, e) => {
					try{
						if(cmpCantidad.Text.Equals("")){
							UIAlertView alert = new UIAlertView () { 
								Title = "Espera!", Message = "Debes ingresar la cantidad"
							};
							alert.AddButton("Registrar");
							alert.AddButton ("Cancelar");
							alert.Show();
						} else{
							cmpCantidad.ResignFirstResponder();
							QuantityView.Hidden = true;
							ls = new ListsService();
							Person persona = people.ElementAt(0);
							ls.setUserId (persona.ID.ToString());
							List<ListsService> tableItems = ls.All (); 
							if(tableItems.Count > 0){
								this.tblLists.Source = new AddToListsTableSource (tableItems, this,this.producto,int.Parse(cmpCantidad.Text));
								ListsView.Add(this.tblLists);
								this.tblLists.ReloadData();
								ListsView.Hidden = false;
								cmpCantidad.Text = "";
							}else{
								UIAlertView alert = new UIAlertView () { 
									Title = "No tienes listas", Message = "No tienes listas registradas, porfavor ve a \"Mis listas\" para crear una nueva"
								};
								alert.AddButton("Registrar");
								alert.AddButton ("Cancelar");
								alert.Show();
							}
						}
					}catch(System.FormatException ex ){
						Console.WriteLine(ex.ToString());
						UIAlertView alert = new UIAlertView () { 
							Title = "Espera!", Message = "Debes ingresar solo números"
						};
						alert.AddButton("Aceptar");
						alert.Show();
						QuantityView.Hidden = false;
					}catch(System.Net.WebException){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups :S", Message = "Algo salio mal,no se pudieron cargar tus listas, verifica tu conexión a internet e inténtalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show();
					}catch(System.Exception ext){
						Console.WriteLine(ext.ToString());
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups :S", Message = "Ocurrió un problema, inténtalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show();
					}
				};

				btnCerrarLista.TouchUpInside += (sender, e) => {
					ListsView.Hidden = true;
				};

				btnBadPrice.TouchUpInside += (sender, e) => {
					if (MainView.userId != 0) {
						UIAlertView alert = new UIAlertView () { 
							Title = "Gracias por su reporte", Message = "Estamos revisando constantemente los precios de los productos y le agradecemos su aportación, ¿le gustaría reportar el precio de este producto para su revision?"
						} ;
						alert.AddButton ("SI");
						alert.AddButton ("NO");
						alert.Clicked += (s , o) => {
							try{
								if(o.ButtonIndex == 0){
									ReportService report = new ReportService();
									String respuesta = report.SetData(MainView.userId.ToString(),this.producto.id,this.producto.tienda_id,this.producto.precio);
									if (respuesta.Equals("\"correct\"")){
										UIAlertView alert2 = new UIAlertView () { 
											Title = "Muchas gracias!", Message = "En FixBuy estamos comprometidos con ofrecer siempre la informacion correcta, muchas gracias por tu reporte =)"
										} ;
										alert2.AddButton ("Aceptar");
										alert2.Show ();
									}else{
										UIAlertView alert3 = new UIAlertView () { 
											Title = "UPS :S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
										} ;
										alert3.AddButton ("Aceptar");
										alert3.Show ();
									}
								}
							}catch(System.Net.WebException){
								UIAlertView alerta = new UIAlertView () { 
									Title = "UPS :S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
								} ;
								alerta.AddButton ("Aceptar");
								alerta.Show ();
							}catch(Exception){
								UIAlertView alerta = new UIAlertView () { 
									Title = "UPS :S", Message = "Algo salio mal, por favor intentalo de nuevo"
								} ;
								alerta.AddButton ("Aceptar");
								alerta.Show ();
							}
						};
						alert.Show ();
					}  else {
						UIAlertView alert = new UIAlertView () { 
							Title = "Espera!", Message = "Debes iniciar sesión para poder reportar el precio incorrecto"
						} ;
						alert.AddButton ("Aceptar");
						alert.Show ();
					}
				};

				btnFacebook.TouchUpInside += (sender, e) => {
					try{
					if(MainView.isWithFacebook == true){
						UIAlertView alert = new UIAlertView () { 
								Title = "Quieres publicar este producto?", Message = "Deseas publicar este producto en tu perfil de Facebook?"
						} ;
						alert.AddButton ("Aceptar");
						alert.AddButton("Cancelar");
							alert.Clicked += (s , o) => {
								if(o.ButtonIndex == 0){
									var post = new NSMutableDictionary ();
									if(data != null){
										post.Add (new NSString ("message"), new NSString (producto.imagen+ "\t"+producto.nombre+ "\t("+producto.descripcion+")" + "\nGracias a FixBuy encontre mi producto =D"));
									}else{
										post.Add (new NSString ("message"), new NSString (producto.nombre + "\t("+producto.descripcion+")" + "\nGracias a FixBuy encontre mi producto =D "));
									}
									// Ask for publish_actions permissions in context
									if (!FBSession.ActiveSession.Permissions.Contains ("publish_actions")) {
										// No permissions found in session, ask for it
										FBSession.ActiveSession.RequestNewPublishPermissions (new [] { "publish_actions" }, FBSessionDefaultAudience.Friends, (session, error) => {
											if (error != null) 
												InvokeOnMainThread (() => new UIAlertView ("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Aceptar", null).Show ());
											else {
												// If permissions granted, publish the story
												FBRequestConnection.StartWithGraphPath ("me/feed", post, "POST", (connection, result, err) => {
													if (err != null)
														InvokeOnMainThread (() => new UIAlertView ("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Aceptar", null).Show ());
													else {
														HelloId = (result as FBGraphObject)["id"] as NSString;
														InvokeOnMainThread (() => new UIAlertView ("Producto publicado =)", "El producto que FixBuy te ayudo a encontrar a sido publicado en tu biografia =)", null, "Aceptar", null).Show ());
													}
												});
											}
										});
									} else {
										// If permissions is found, publish the story
										FBRequestConnection.StartWithGraphPath ("me/feed", post, "POST", (connection, result, err) => {
											if (err != null)
												InvokeOnMainThread (() => new UIAlertView ("Ups =S", "Ocurrio un error intentalo de nuevo", null, "Ok", null).Show ());
											else {
												HelloId = (result as FBGraphObject)["id"] as NSString;
												InvokeOnMainThread (() => new UIAlertView ("Producto publicado =)", "El producto que FixBuy te ayudo a encontrar a sido publicado en tu biografia =)", null, "Aceptar", null).Show ());
											}
										});
									}
								}
							};
						alert.Show ();
					}else{
						InvokeOnMainThread (() => new UIAlertView ("No has entrado a Facebook", "Debes iniciar sesion en Facebook para poder publicar tu producto, por favor regresa a la pantalla inicial para iniciar sesion en Facebook", null, "Aceptar", null).Show ());
					}
					}catch(Exception exc){
						Console.WriteLine("UPS: " + exc.ToString());
					}
					//Console.WriteLine(HelloId.ToString());
				};

				btnNuevaLista.TouchUpInside += (sender, e) => {
					this.NewListView.Hidden = false;
				};

				btnAceptarNuevaLista.TouchUpInside += (sender, e) => {
					try{
						if(cmpNewList.Text == ""){
							UIAlertView alert = new UIAlertView () { 
								Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
							};
							alert.AddButton("Aceptar");
							alert.Show ();
						}else{
							nls = new NewListService();
							String respuesta = nls.SetListData(cmpNewList.Text, MainView.userId.ToString());
							if(respuesta.Equals("\"lista ya existe\"")){
								UIAlertView alert = new UIAlertView () { 
									Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
								};
								alert.AddButton("Aceptar");
								alert.Show ();
								//cmpNewList.Hidden = true;
								cmpNewList.Text = "";
								cmpNewList.ResignFirstResponder();
							}else{
								UIAlertView alert = new UIAlertView () { 
									Title = "Lista creada", Message = "Tu nueva lista \""+cmpNewList.Text+"\" ha sido creada =D"
								};
								alert.AddButton("Aceptar");
								alert.Show ();
								ls = new ListsService();
								ls.setUserId(MainView.userId.ToString());
								List<ListsService> items = ls.All ();
								this.tblLists.Source = new AddToListsTableSource(items,this,producto,1);
								this.tblLists.ReloadData();
								cmpNewList.Text = "";
								NewListView.Hidden = true;
								cmpNewList.ResignFirstResponder();
							}
						}
					}catch(System.Net.WebException){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}catch(Exception exc){
						Console.WriteLine(exc.ToString());
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}
				};

				btnCerrarNombreNL.TouchUpInside += (sender, e) => {
					this.NewListView.Hidden = true;
					this.cmpNewList.ResignFirstResponder();
				};

			}catch(Exception e){
				Console.WriteLine (e.ToString());
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}

			try{
				//Registramos la visita al producto en la aplicacion web
				RegisterVisit(producto.tienda_id,MainView.userId);
			}
			catch(Exception){
				/*Atrapamos la excepcion en caso de que el registro de la visita no pueda hacerse
				sin mostrar ningun mensaje ni detener el flujo de la aplicacion*/
			}

			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
				}
			};
		}
Beispiel #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            try{
                //Configuramos la vista popup de cantidad
                AmountView.Layer.BorderWidth  = 1.0f;
                AmountView.Layer.BorderColor  = UIColor.Black.CGColor;
                AmountView.Layer.CornerRadius = 8;
                tblProducts.Add(AmountView);
                AmountView.Hidden           = true;
                NameSearchResultView.amount = AmountView;

                //Configuramos la vista de popup de listas
                ListsView.Layer.BorderWidth  = 1.0f;
                ListsView.Layer.BorderColor  = UIColor.Black.CGColor;
                ListsView.Layer.CornerRadius = 8;
                tblProducts.Add(this.ListsView);
                ListsView.Hidden = true;

                //Configuramos la vista popup de nueva lista
                newListView.Layer.BorderWidth  = 1.0f;
                newListView.Layer.BorderColor  = UIColor.Black.CGColor;
                newListView.Layer.CornerRadius = 8;
                tblProducts.Add(newListView);
                newListView.Hidden = true;

                ps.setProductSearchString(this.nombre);
                List <ProductSearchService> tableItems = ps.All();

                this.productImages.Clear();
                foreach (var v in tableItems)
                {
                    Images image = new Images {
                        imageUrl = v.imagen
                    };
                    this.productImages.Add(image);
                }

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    this.tblProducts.Source = new ProductsTableSourceIphone(tableItems, this, MainView.userId);
                }
                else
                {
                    this.tblProducts.Source = new ProductsTableSource(tableItems, this, MainView.userId);
                }
                this.lblSearch.Text = "Resultados para \"" + nombre + "\"";
                this.tblProducts.TableHeaderView = this.headerView;
                Add(this.tblProducts);
                if (tableItems.Count == 0)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Lo sentimos =(", Message = "La búsqueda de " + "\"" + nombre + "\"" + "\n No produjo ningun resultado."
                    };
                    alert.AddButton("Aceptar");
                    alert.Clicked += (sender, e) => {
                        NavigationController.PopViewController(true);
                    };
                    alert.Show();
                }

                this.btnAceptar.TouchUpInside += (sender, e) => {
                    try{
                        AmountView.Hidden = true;
                        ListsService ls = new ListsService();
                        ls.setUserId(MainView.userId.ToString());
                        List <ListsService> listItems = ls.All();
                        if (listItems.Count > 0)
                        {
                            this.tblLists.Source = new AddToListsTableSource(listItems, this, NameSearchResultView.product_id, int.Parse(cmpAmount.Text));
                            ListsView.Add(tblLists);
                            this.tblLists.ReloadData();
                            ListsView.Hidden = false;
                        }
                        else
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "No tienes listas", Message = "No tienes listas registradas, porfavor ve a \"Mis listas\" para crear una nueva"
                            };
                            alert.AddButton("Aceptar");
                            alert.Show();
                        }
                    }catch (System.Net.WebException) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal,no se pudieron cargar tus listas, verifica tu conexión a internet e intentalo de nuevo."
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }catch (Exception) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                btnCerrar.TouchUpInside += (sender, e) => {
                    this.ListsView.Hidden = true;
                };

                int cantidad = 1;
                this.cmpAmount.Text   = cantidad.ToString();
                btnMas.TouchUpInside += (sender, e) => {
                    cantidad++;
                    this.cmpAmount.Text = cantidad.ToString();
                };

                btnMenos.TouchUpInside += (sender, e) => {
                    cantidad--;
                    if (cantidad < 1)
                    {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Espera!", Message = "La cantidad minima es 1"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                        cantidad            = 1;
                        this.cmpAmount.Text = cantidad.ToString();
                    }
                    else
                    {
                        this.cmpAmount.Text = cantidad.ToString();
                    }
                };

                btnNuevaLista.TouchUpInside += (sender, e) => {
                    this.newListView.Hidden = false;
                };

                btnCancelarLista.TouchUpInside += (sender, e) => {
                    this.newListView.Hidden = true;
                };

                btnAceptarLista.TouchUpInside += (sender, e) => {
                    try{
                        if (cmpListName.Text == "")
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
                            };
                            alert.AddButton("Aceptar");
                            alert.Show();
                        }
                        else
                        {
                            nls = new NewListService();
                            String respuesta = nls.SetListData(cmpListName.Text, MainView.userId.ToString());
                            if (respuesta.Equals("\"lista ya existe\""))
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();
                                cmpListName.Text = "";
                            }
                            else
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Lista creada", Message = "Tu nueva lista \"" + cmpListName.Text + "\" ha sido creada =D"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();
                                ls = new ListsService();
                                ls.setUserId(MainView.userId.ToString());
                                List <ListsService> items = ls.All();
                                this.tblLists.Source = new AddToListsTableSource(items, this, NameSearchResultView.product_id, int.Parse(cmpAmount.Text));
                                this.tblLists.ReloadData();
                                cmpListName.Text   = "";
                                newListView.Hidden = true;
                                cmpListName.ResignFirstResponder();
                            }
                        }
                    }catch (System.Net.WebException) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }catch (Exception exc) {
                        Console.WriteLine(exc.ToString());
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };
            }catch (WebException) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo."
                };
                alert.AddButton("Aceptar");
                alert.Clicked += (sender, e) => {
                    NavigationController.PopViewController(true);
                };
                alert.Show();
            }catch (Exception) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
                };
                alert.AddButton("Aceptar");
                alert.Clicked += (sender, e) => {
                    NavigationController.PopViewController(true);
                };
                alert.Show();
            }
        }
Beispiel #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            try{
                //Configuramos la vista de popup
                modalView.BackgroundColor    = UIColor.White;
                modalView.Layer.BorderWidth  = 1.0f;
                modalView.Layer.BorderColor  = UIColor.Black.CGColor;
                modalView.Layer.CornerRadius = 8;
                modalView.Hidden             = true;

                ls = new ListsService();
                ls.setUserId(MainView.userId.ToString());
                List <ListsService> tableItems = ls.All();
                MyListsView.tableView = this.tblLists;

                if (tableItems.Count == 0)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "No tienes listas", Message = "Aun no tienes listas registradas, presiona el boton central para crear una nueva lista =)"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                    this.tblLists.Hidden      = true;
                    this.headerView.Hidden    = true;
                    this.btnNewListBig.Hidden = false;
                    this.Add(modalView);
                }
                else
                {
                    btnNewListBig.Hidden = true;
                    tblLists.Add(modalView);
                }

                //Verificamos si estamos en iphone o ipad para cargar la lista correcta
                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                {
                    this.tblLists.Source = new ListsTableSourceIphone(tableItems, this);
                }
                else
                {
                    this.tblLists.Source = new ListsTableSource(tableItems, this);
                }

                this.tblLists.TableHeaderView = this.headerView;
                this.Add(this.tblLists);

                this.btnNewListBig.TouchUpInside += (sender, e) => {
                    modalView.Hidden = false;
                    this.Add(modalView);
                };

                this.btnNewList.TouchUpInside += (sender, e) => {
                    modalView.Hidden = false;
                };

                this.btnAceptar.TouchUpInside += (sender, e) => {
                    try{
                        if (cmpLista.Text == "")
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
                            };
                            alert.AddButton("Aceptar");
                            alert.Show();
                        }
                        else
                        {
                            NewListService nls       = new NewListService();
                            String         respuesta = nls.SetListData(cmpLista.Text, MainView.userId.ToString());
                            if (respuesta.Equals("\"lista ya existe\""))
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();
                                cmpLista.Text = "";
                            }
                            else
                            {
                                UIAlertView alert = new UIAlertView()
                                {
                                    Title = "Lista creada", Message = "Tu nueva lista \"" + cmpLista.Text + "\" ha sido creada =D"
                                };
                                alert.AddButton("Aceptar");
                                alert.Show();

                                tableItems = ls.All();
                                //Verificamos si estamos en iphone o ipad para cargar la lista correcta
                                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
                                {
                                    this.tblLists.Source = new ListsTableSourceIphone(tableItems, this);
                                }
                                else
                                {
                                    this.tblLists.Source = new ListsTableSource(tableItems, this);
                                }
                                this.Add(tblLists);
                                this.tblLists.ReloadData();
                                cmpLista.Text    = "";
                                modalView.Hidden = true;
                                cmpLista.ResignFirstResponder();
                                this.tblLists.Hidden      = false;
                                this.headerView.Hidden    = false;
                                this.btnNewListBig.Hidden = true;
                                tblLists.Add(modalView);
                            }
                        }
                    }catch (System.Net.WebException) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }catch (Exception) {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
                        };
                        alert.AddButton("Aceptar");
                        alert.Show();
                    }
                };

                this.btnCancel.TouchUpInside += (sender, e) => {
                    cmpLista.Text = "";
                    cmpLista.ResignFirstResponder();
                    modalView.Hidden = true;
                };
            }catch (System.Net.WebException) {
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups :S", Message = "Algo salio mal,verifica tu conexion a internet e intentalo de nuevo"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }catch (Exception e) {
                Console.WriteLine(e.ToString());
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups :S", Message = "Algo salio mal, por favor intentalo de nuevo"
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }
        }
Beispiel #9
0
		public UIButton getButton(int index){
			botones.ElementAt(index).Frame = new CGRect (0, 0, Images.basura48.Size.Width, Images.basura48.Size.Height);
			botones.ElementAt(index).SetBackgroundImage(Images.basura48,UIControlState.Normal);
			botones.ElementAt(index).BackgroundColor = UIColor.Clear;
			botones.ElementAt(index).TouchUpInside += (sender, e) => {
				UIAlertView alert = new UIAlertView () { 
					Title = "Borrar?", Message = "Deseas borrar esta lista?"
				};
				alert.AddButton ("Aceptar");
				alert.AddButton ("Cancelar");
				alert.Clicked += (s, o) => {
					if(o.ButtonIndex == 0){
						DestroyService destroyService = new DestroyService ();
						String respuesta = destroyService.destroyList (tableItems[index].id);
						if (respuesta.Equals ("\"correct\"")) {
							UIAlertView alert1 = new UIAlertView () { 
								Title = "Lita borrada", Message = "La lista ha sido borrada =)"
							};
							alert1.AddButton("Aceptar");
							alert1.Show ();
							ListsService ls = new ListsService();
							ls.setUserId(MainView.userId.ToString());
							List<ListsService> listas = ls.All();
							MyListsView.tableView.Source = new ListsTableSourceIphone(listas,this.controller);
							MyListsView.tableView.ReloadData ();
						}else if(respuesta.Equals("\"error\"")){
							UIAlertView alert2 = new UIAlertView () { 
								Title = "Ups :S", Message = "Algo salio mal, por favor intentalo de nuevo"
							};
							alert2.AddButton("Aceptar");
							alert2.Show ();
						}
					}
				};
				alert.Show ();
			};
			return botones.ElementAt(index);
		}
Beispiel #10
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			try{

				//Configuramos la vista de popup
				modalView.BackgroundColor = UIColor.White;
				modalView.Layer.BorderWidth = 1.0f;
				modalView.Layer.BorderColor = UIColor.Black.CGColor;
				modalView.Layer.CornerRadius = 8;
				modalView.Hidden = true;

				ls = new ListsService ();
				ls.setUserId (MainView.userId.ToString());
				List<ListsService> tableItems = ls.All ();
				MyListsView.tableView = this.tblLists;

				if(tableItems.Count == 0){
					UIAlertView alert = new UIAlertView () { 
						Title = "No tienes listas", Message = "Aun no tienes listas registradas, presiona el boton central para crear una nueva lista =)"
					};
					alert.AddButton("Aceptar");
					alert.Show ();
					this.tblLists.Hidden = true;
					this.headerView.Hidden = true;
					this.btnNewListBig.Hidden = false;
					this.Add(modalView);
				}else{
					btnNewListBig.Hidden = true;
					tblLists.Add(modalView);
				}
		
				//Verificamos si estamos en iphone o ipad para cargar la lista correcta
				if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
					this.tblLists.Source = new ListsTableSourceIphone (tableItems, this);
				}else{
					this.tblLists.Source = new ListsTableSource (tableItems, this);
				}

				this.tblLists.TableHeaderView = this.headerView;
				this.Add (this.tblLists);

				this.btnNewListBig.TouchUpInside += (sender, e) => {
					modalView.Hidden = false;
					this.Add(modalView);
				};

				this.btnNewList.TouchUpInside += (sender, e) => {
					modalView.Hidden = false;
				};

				this.btnAceptar.TouchUpInside += (sender, e) => {
					try{
						if(cmpLista.Text == ""){
							UIAlertView alert = new UIAlertView () { 
								Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
							};
							alert.AddButton("Aceptar");
							alert.Show ();
						}else{
							NewListService nls = new NewListService();
							String respuesta = nls.SetListData(cmpLista.Text, MainView.userId.ToString());
							if(respuesta.Equals("\"lista ya existe\"")){
								UIAlertView alert = new UIAlertView () { 
									Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
								};
								alert.AddButton("Aceptar");
								alert.Show ();
								cmpLista.Text = "";
							}else{
								UIAlertView alert = new UIAlertView () { 
									Title = "Lista creada", Message = "Tu nueva lista \""+cmpLista.Text+"\" ha sido creada =D"
								};
								alert.AddButton("Aceptar");
								alert.Show ();

								tableItems = ls.All ();
								//Verificamos si estamos en iphone o ipad para cargar la lista correcta
								if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
									this.tblLists.Source = new ListsTableSourceIphone (tableItems, this);
								}else{
									this.tblLists.Source = new ListsTableSource (tableItems, this);
								}
								this.Add(tblLists);
								this.tblLists.ReloadData();
								cmpLista.Text = "";
								modalView.Hidden = true;
								cmpLista.ResignFirstResponder();
								this.tblLists.Hidden = false;
								this.headerView.Hidden = false;
								this.btnNewListBig.Hidden = true;
								tblLists.Add(modalView);
							}
						}
					}catch(System.Net.WebException){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}catch(Exception){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}
				};

				this.btnCancel.TouchUpInside += (sender, e) => {
					cmpLista.Text = "";
					cmpLista.ResignFirstResponder();
					modalView.Hidden = true;
				};
			}catch(System.Net.WebException){
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups :S", Message = "Algo salio mal,verifica tu conexion a internet e intentalo de nuevo"
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}catch(Exception e){
				Console.WriteLine (e.ToString());
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups :S", Message = "Algo salio mal, por favor intentalo de nuevo"
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			// Perform any additional setup after loading the view, typically from a nib.
			try{
				//Configuramos la vista popup de cantidad
				AmountView.Layer.BorderWidth = 1.0f;
				AmountView.Layer.BorderColor = UIColor.Black.CGColor;
				AmountView.Layer.CornerRadius = 8;
				tblProducts.Add(AmountView);
				AmountView.Hidden = true;
				NameSearchResultView.amount = AmountView;

				//Configuramos la vista de popup de listas
				ListsView.Layer.BorderWidth = 1.0f;
				ListsView.Layer.BorderColor = UIColor.Black.CGColor;
				ListsView.Layer.CornerRadius = 8;
				tblProducts.Add(this.ListsView);
				ListsView.Hidden = true;

				//Configuramos la vista popup de nueva lista
				newListView.Layer.BorderWidth = 1.0f;
				newListView.Layer.BorderColor = UIColor.Black.CGColor;
				newListView.Layer.CornerRadius = 8;
				tblProducts.Add(newListView);
				newListView.Hidden = true;

				ps.setProductSearchString (this.nombre);
				List<ProductSearchService> tableItems = ps.All ();

				this.productImages.Clear();
				foreach (var v in tableItems){
					Images image = new Images{ imageUrl = v.imagen};
					this.productImages.Add(image);
				}

				if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
					this.tblProducts.Source = new ProductsTableSourceIphone(tableItems, this, MainView.userId);
				}else {
					this.tblProducts.Source = new ProductsTableSource(tableItems, this, MainView.userId);
				}
				this.lblSearch.Text = "Resultados para \"" + nombre +"\"";
				this.tblProducts.TableHeaderView = this.headerView;
				Add (this.tblProducts);
				if (tableItems.Count == 0) {
					UIAlertView alert = new UIAlertView () { 
						Title = "Lo sentimos =(", Message = "La búsqueda de "+ "\""+nombre+"\""+"\n No produjo ningun resultado."
					};
					alert.AddButton("Aceptar");
					alert.Clicked += (sender, e) => {
						NavigationController.PopViewController(true);
					};
					alert.Show ();
				}

				this.btnAceptar.TouchUpInside += (sender, e) => {
					try{
						AmountView.Hidden = true;
						ListsService ls = new ListsService();
						ls.setUserId(MainView.userId.ToString());
						List<ListsService> listItems = ls.All();
						if(listItems.Count > 0){
							this.tblLists.Source = new AddToListsTableSource(listItems,this,NameSearchResultView.product_id,int.Parse(cmpAmount.Text));
							ListsView.Add(tblLists);
							this.tblLists.ReloadData();
							ListsView.Hidden = false;
						}else{
							UIAlertView alert = new UIAlertView () { 
								Title = "No tienes listas", Message = "No tienes listas registradas, porfavor ve a \"Mis listas\" para crear una nueva"
							};
							alert.AddButton("Aceptar");
							alert.Show ();
						}
					}catch(System.Net.WebException){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal,no se pudieron cargar tus listas, verifica tu conexión a internet e intentalo de nuevo."
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}catch(Exception){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}
				};

				btnCerrar.TouchUpInside += (sender, e) => {
					this.ListsView.Hidden = true;
				};

				int cantidad = 1;
				this.cmpAmount.Text = cantidad.ToString();
				btnMas.TouchUpInside += (sender, e) => {
					cantidad ++;
					this.cmpAmount.Text = cantidad.ToString();
				};

				btnMenos.TouchUpInside += (sender, e) => {
					cantidad --;
					if(cantidad < 1){
						UIAlertView alert = new UIAlertView () { 
							Title = "Espera!", Message = "La cantidad minima es 1"
						};
						alert.AddButton("Aceptar");
						alert.Show();
						cantidad = 1;
						this.cmpAmount.Text = cantidad.ToString();
					}else{
						this.cmpAmount.Text = cantidad.ToString();
					}
				};

				btnNuevaLista.TouchUpInside += (sender, e) => {
					this.newListView.Hidden = false;
				};

				btnCancelarLista.TouchUpInside += (sender, e) => {
					this.newListView.Hidden = true;
				};

				btnAceptarLista.TouchUpInside += (sender, e) => {
					try{
						if(cmpListName.Text == ""){
							UIAlertView alert = new UIAlertView () { 
								Title = "Espera!", Message = "Debes ingresar el nombre de la lista"
							};
							alert.AddButton("Aceptar");
							alert.Show ();
						}else{
							nls = new NewListService();
							String respuesta = nls.SetListData(cmpListName.Text, MainView.userId.ToString());
							if(respuesta.Equals("\"lista ya existe\"")){
								UIAlertView alert = new UIAlertView () { 
									Title = "Ups :S", Message = "Ese nombre de lista ya se encuentra registrado"
								};
								alert.AddButton("Aceptar");
								alert.Show ();
								cmpListName.Text = "";
							}else{
								UIAlertView alert = new UIAlertView () { 
									Title = "Lista creada", Message = "Tu nueva lista \""+cmpListName.Text+"\" ha sido creada =D"
								};
								alert.AddButton("Aceptar");
								alert.Show ();
								ls = new ListsService();
								ls.setUserId(MainView.userId.ToString());
								List<ListsService> items = ls.All ();
								this.tblLists.Source = new AddToListsTableSource(items,this,NameSearchResultView.product_id,int.Parse(cmpAmount.Text));
								this.tblLists.ReloadData();
								cmpListName.Text = "";
								newListView.Hidden = true;
								cmpListName.ResignFirstResponder();
							}
						}
					}catch(System.Net.WebException){
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}catch(Exception exc){
						Console.WriteLine(exc.ToString());
						UIAlertView alert = new UIAlertView () { 
							Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo"
						};
						alert.AddButton("Aceptar");
						alert.Show ();
					}
				};

			}catch(WebException){
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =S", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Clicked += (sender, e) => {
					NavigationController.PopViewController(true);
				};
				alert.Show ();
			}catch(Exception){
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Clicked += (sender, e) => {
					NavigationController.PopViewController(true);
				};
				alert.Show ();
			}
		}