Exemple #1
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.Add (faceBookView);
			this.Add (facebookView2);

			iPhoneLocationManager = new CLLocationManager ();
			iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
			iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {

			};
				
			iPhoneLocationManager.RequestAlwaysAuthorization ();
			if (CLLocationManager.LocationServicesEnabled) {
				iPhoneLocationManager.StartUpdatingLocation ();
			}
			#region observadores del teclado
			// Keyboard popup
			NSNotificationCenter.DefaultCenter.AddObserver
			(UIKeyboard.DidShowNotification,KeyBoardUpNotification);

			// Keyboard Down
			NSNotificationCenter.DefaultCenter.AddObserver
			(UIKeyboard.WillHideNotification,KeyBoardDownNotification);
			#endregion

			#region declaracion de vista de Facebook
			// Create the Facebook LogIn View with the needed Permissions
			// https://developers.facebook.com/ios/login-ui-control/
			loginView = new FBLoginView (ExtendedPermissions) {
				Frame = new CGRect (0,0,45, 45)
			};

			// Create view that will display user's profile picture
			// https://developers.facebook.com/ios/profilepicture-ui-control/

			pictureView = new FBProfilePictureView () {
				Frame = new CGRect (0, 0, 45, 45)
			};
			pictureView.UserInteractionEnabled = true;
			// Hook up to FetchedUserInfo event, so you know when
			// you have the user information available
			loginView.FetchedUserInfo += (sender, e) => {
				user = e.User;
				pictureView.ProfileID = user.GetId ();
				MainView.isWithFacebook = true;
				loginView.Alpha = 0.1f;
				pictureView.Hidden = false;
			};

			// Clean user Picture and label when Logged Out
			loginView.ShowingLoggedOutUser += (sender, e) => {
				pictureView.ProfileID = null;
				pictureView.Hidden = true;
				lblUserName.Text = string.Empty;
				loginView.Alpha = 1f;
				MainView.isWithFacebook = false;
			};
		
			this.faceBookView.Add(pictureView);
			this.faceBookView.Add(loginView);
			#endregion

			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
			using (var conn= new SQLite.SQLiteConnection(_pathToDatabase))
			{
				conn.CreateTable<Person>();
				conn.CreateTable<State> ();
				conn.CreateTable<Terms> ();
				conn.CreateTable<PrivacyNotice> ();
			}

			using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
			{
				people = new List<Person> (from p in db.Table<Person> () select p);
				states = new List<State> (from s in db.Table<State> () select s);
				terms = new List<Terms> (from t in db.Table<Terms> ()select t);
				privacyNotices = new List<PrivacyNotice> (from pr in db.Table<PrivacyNotice> () select pr);
			}

			if(people.Count > 0){
				Person user = people.ElementAt(0);
				MainView.userId = user.ID;
				Console.WriteLine ("El Id de usuario es: "+ user.ID);
			}

			if(states.Count > 0){
				State estado = states.ElementAt(0);
				MainView.localityId = estado.localityId;
				Console.WriteLine ("El Id de localidad es: "+ estado.stateId);
			}
				
			//Boton para entrar al menu de la aplicacion.
			this.btnEntrar.TouchUpInside += (sender, e) => {
				scanView = new ScanView();
				this.NavigationController.PushViewController(scanView, true);
			};

			this.btnListas.TouchUpInside += (sender, e) => {
				using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
				{
					people = new List<Person> (from p in db.Table<Person> () select p);
				}
				if(people.Count > 0){
					MyListsView mylists = new MyListsView();
					this.NavigationController.PushViewController(mylists,true);
				}else{
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes iniciar sesion para acceder a tus listas"
					};
					alert.AddButton ("Aceptar");
					alert.Show ();
				}
			};

			//Boton para hacer busqueda por nombre de producto
			this.btnBuscar.TouchUpInside += (sender, e) => {
				if(this.cmpNombre.Text == ""){
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes ingresar el nombre del producto a buscar"
					};
					alert.AddButton ("Aceptar");
					alert.Show ();
				}
				else if (states.Count < 1){
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
							"Al menu de opciones para establecerla"
					};
					alert.AddButton ("Aceptar");
					alert.Clicked += (s, o) => {
						StatesView statesView = new StatesView();
						this.NavigationController.PushViewController(statesView, true);
					};
					alert.Show ();
				}
				else{
					this._loadPop = new LoadingOverlay (UIScreen.MainScreen.Bounds);
					this.View.Add ( this._loadPop );
					this.cmpNombre.ResignFirstResponder();
					Task.Factory.StartNew (
						() => {
							System.Threading.Thread.Sleep ( 1 * 1000 );
						}
					).ContinueWith ( 
						t => {
							nsr = new NameSearchResultView();
							nsr.setProductName(this.cmpNombre.Text.Trim());
							this.NavigationController.PushViewController(nsr,true);
							this._loadPop.Hide ();
						}, TaskScheduler.FromCurrentSynchronizationContext()
					);
				}
			};

			this.cmpNombre.ShouldReturn += (textField) => {
				if(this.cmpNombre.Text == ""){
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes ingresar el nombre del producto a buscar"
					};
					alert.AddButton ("Aceptar");
					alert.Show ();
				}
				else if (states.Count < 1){
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
							"Al menu de opciones para establecerla"
					};
					alert.AddButton ("Aceptar");
					alert.Clicked += (s, o) => {
						StatesView statesView = new StatesView();
						this.NavigationController.PushViewController(statesView, true);
					};
					alert.Show ();
				}
				else{
					this._loadPop = new LoadingOverlay (UIScreen.MainScreen.Bounds);
					this.View.Add ( this._loadPop );
					this.cmpNombre.ResignFirstResponder();
					Task.Factory.StartNew (
						() => {
							System.Threading.Thread.Sleep ( 1 * 1000 );
						}
					).ContinueWith ( 
						t => {
							nsr = new NameSearchResultView();
							nsr.setProductName(this.cmpNombre.Text.Trim());
							this.NavigationController.PushViewController(nsr,true);
							this._loadPop.Hide ();
						}, TaskScheduler.FromCurrentSynchronizationContext()
					);
				} 
				return true; 
			};

			//Boton para iniciar el escaner de codigo de barras
			this.btnCodigo.TouchUpInside += (sender, e) => {
				if(states.Count > 0){
					// Configurar el escaner de codigo de barras.
					picker = new ScanditSDKRotatingBarcodePicker (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 ();
				}else{
					UIAlertView alert = new UIAlertView () { 
						Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
							"Al menu de opciones para establecerla"
					};
					alert.AddButton ("Aceptar");
					alert.Clicked += (s, o) => {
						StatesView statesView = new StatesView();
						this.NavigationController.PushViewController(statesView, true);
					};
					alert.Show ();
				}
			};
		}
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.Add(faceBookView);
            this.Add(facebookView2);

            iPhoneLocationManager = new CLLocationManager();
            iPhoneLocationManager.DesiredAccuracy   = CLLocation.AccuracyNearestTenMeters;
            iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
            };

            iPhoneLocationManager.RequestAlwaysAuthorization();
            if (CLLocationManager.LocationServicesEnabled)
            {
                iPhoneLocationManager.StartUpdatingLocation();
            }
            #region observadores del teclado
            // Keyboard popup
            NSNotificationCenter.DefaultCenter.AddObserver
                (UIKeyboard.DidShowNotification, KeyBoardUpNotification);

            // Keyboard Down
            NSNotificationCenter.DefaultCenter.AddObserver
                (UIKeyboard.WillHideNotification, KeyBoardDownNotification);
            #endregion

            #region declaracion de vista de Facebook
            // Create the Facebook LogIn View with the needed Permissions
            // https://developers.facebook.com/ios/login-ui-control/
            loginView = new FBLoginView(ExtendedPermissions)
            {
                Frame = new CGRect(0, 0, 45, 45)
            };

            // Create view that will display user's profile picture
            // https://developers.facebook.com/ios/profilepicture-ui-control/

            pictureView = new FBProfilePictureView()
            {
                Frame = new CGRect(0, 0, 45, 45)
            };
            pictureView.UserInteractionEnabled = true;
            // Hook up to FetchedUserInfo event, so you know when
            // you have the user information available
            loginView.FetchedUserInfo += (sender, e) => {
                user = e.User;
                pictureView.ProfileID   = user.GetId();
                MainView.isWithFacebook = true;
                loginView.Alpha         = 0.1f;
                pictureView.Hidden      = false;
            };

            // Clean user Picture and label when Logged Out
            loginView.ShowingLoggedOutUser += (sender, e) => {
                pictureView.ProfileID   = null;
                pictureView.Hidden      = true;
                lblUserName.Text        = string.Empty;
                loginView.Alpha         = 1f;
                MainView.isWithFacebook = false;
            };

            this.faceBookView.Add(pictureView);
            this.faceBookView.Add(loginView);
            #endregion

            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
            using (var conn = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                conn.CreateTable <Person>();
                conn.CreateTable <State> ();
                conn.CreateTable <Terms> ();
                conn.CreateTable <PrivacyNotice> ();
            }

            using (var db = new SQLite.SQLiteConnection(_pathToDatabase))
            {
                people         = new List <Person> (from p in db.Table <Person> () select p);
                states         = new List <State> (from s in db.Table <State> () select s);
                terms          = new List <Terms> (from t in db.Table <Terms> () select t);
                privacyNotices = new List <PrivacyNotice> (from pr in db.Table <PrivacyNotice> () select pr);
            }

            if (people.Count > 0)
            {
                Person user = people.ElementAt(0);
                MainView.userId = user.ID;
                Console.WriteLine("El Id de usuario es: " + user.ID);
            }

            if (states.Count > 0)
            {
                State estado = states.ElementAt(0);
                MainView.localityId = estado.localityId;
                Console.WriteLine("El Id de localidad es: " + estado.stateId);
            }

            //Boton para entrar al menu de la aplicacion.
            this.btnEntrar.TouchUpInside += (sender, e) => {
                scanView = new ScanView();
                this.NavigationController.PushViewController(scanView, true);
            };

            this.btnListas.TouchUpInside += (sender, e) => {
                using (var db = new SQLite.SQLiteConnection(_pathToDatabase))
                {
                    people = new List <Person> (from p in db.Table <Person> () select p);
                }
                if (people.Count > 0)
                {
                    MyListsView mylists = new MyListsView();
                    this.NavigationController.PushViewController(mylists, true);
                }
                else
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes iniciar sesion para acceder a tus listas"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
            };

            //Boton para hacer busqueda por nombre de producto
            this.btnBuscar.TouchUpInside += (sender, e) => {
                if (this.cmpNombre.Text == "")
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes ingresar el nombre del producto a buscar"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
                else if (states.Count < 1)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
                                                     "Al menu de opciones para establecerla"
                    };
                    alert.AddButton("Aceptar");
                    alert.Clicked += (s, o) => {
                        StatesView statesView = new StatesView();
                        this.NavigationController.PushViewController(statesView, true);
                    };
                    alert.Show();
                }
                else
                {
                    this._loadPop = new LoadingOverlay(UIScreen.MainScreen.Bounds);
                    this.View.Add(this._loadPop);
                    this.cmpNombre.ResignFirstResponder();
                    Task.Factory.StartNew(
                        () => {
                        System.Threading.Thread.Sleep(1 * 1000);
                    }
                        ).ContinueWith(
                        t => {
                        nsr = new NameSearchResultView();
                        nsr.setProductName(this.cmpNombre.Text.Trim());
                        this.NavigationController.PushViewController(nsr, true);
                        this._loadPop.Hide();
                    }, TaskScheduler.FromCurrentSynchronizationContext()
                        );
                }
            };

            this.cmpNombre.ShouldReturn += (textField) => {
                if (this.cmpNombre.Text == "")
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes ingresar el nombre del producto a buscar"
                    };
                    alert.AddButton("Aceptar");
                    alert.Show();
                }
                else if (states.Count < 1)
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
                                                     "Al menu de opciones para establecerla"
                    };
                    alert.AddButton("Aceptar");
                    alert.Clicked += (s, o) => {
                        StatesView statesView = new StatesView();
                        this.NavigationController.PushViewController(statesView, true);
                    };
                    alert.Show();
                }
                else
                {
                    this._loadPop = new LoadingOverlay(UIScreen.MainScreen.Bounds);
                    this.View.Add(this._loadPop);
                    this.cmpNombre.ResignFirstResponder();
                    Task.Factory.StartNew(
                        () => {
                        System.Threading.Thread.Sleep(1 * 1000);
                    }
                        ).ContinueWith(
                        t => {
                        nsr = new NameSearchResultView();
                        nsr.setProductName(this.cmpNombre.Text.Trim());
                        this.NavigationController.PushViewController(nsr, true);
                        this._loadPop.Hide();
                    }, TaskScheduler.FromCurrentSynchronizationContext()
                        );
                }
                return(true);
            };

            //Boton para iniciar el escaner de codigo de barras
            this.btnCodigo.TouchUpInside += (sender, e) => {
                if (states.Count > 0)
                {
                    // Configurar el escaner de codigo de barras.
                    picker = new ScanditSDKRotatingBarcodePicker(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();
                }
                else
                {
                    UIAlertView alert = new UIAlertView()
                    {
                        Title = "Espera!", Message = "Debes seleccionar tu ubicacion antes de comenzar a usar FixBuy, por favor ingresa " +
                                                     "Al menu de opciones para establecerla"
                    };
                    alert.AddButton("Aceptar");
                    alert.Clicked += (s, o) => {
                        StatesView statesView = new StatesView();
                        this.NavigationController.PushViewController(statesView, true);
                    };
                    alert.Show();
                }
            };
        }