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 (); } }; }
public override void ViewDidLoad () { base.ViewDidLoad (); this.Title = "Menú"; //Ocultamos el boton de tiendas registradas temporalmente //btnTiendas.Hidden = true; //btnInfo2.Hidden = true; var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal); _pathToDatabase = Path.Combine(documents, "db_sqlite-net.db"); //Creamos la base de datos y la tabla de persona, en caso de que ya exista no hace nada. using (var conn= new SQLite.SQLiteConnection(_pathToDatabase)) { conn.CreateTable<Person>(); } //Hacemos la conexion a la bd para buscar si hay un usuario registrado using (var db = new SQLite.SQLiteConnection(_pathToDatabase )) { people = new List<Person> (from p in db.Table<Person> () select p); } //Establecemos las imagenes de los botones setButtonImages(); //Eventos para los botones de informacion this.btnInfo1.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Busca productos por código de barras o nombre", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnInfo2.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Localiza todas las tiendas registradas en FIXBUY", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnInfo3.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Administra tus listas y los productos en ellas", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnInfo4.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Inicia Sesion en FIXBUY para poder acceder a tus listas y más!", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnInfo5.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Establece tu ubicación para una busqueda mas eficaz!", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnInfo6.TouchUpInside += (sender, e) => { ToastView view = new ToastView("Consulta los servicios que ofrece FIXBUY", 3000); view.SetGravity(ToastGravity.Center,0,0); view.Show(); }; this.btnCerrarSesion.TouchUpInside += (sender, e) => { UIAlertView alert = new UIAlertView () { Title = "Te vas? =(", Message = "Estas seguro que quieres cerrar la sesión?" }; alert.AddButton("Aceptar"); alert.AddButton("Cancelar"); alert.Clicked += (s, o) => { if(o.ButtonIndex == 0){ using (var conn= new SQLite.SQLiteConnection(_pathToDatabase)) { conn.DropTable<Person>(); conn.CreateTable<Person>(); } this.NavigationController.PopViewController(true); } }; alert.Show (); }; //Boton de buscar productos this.btnScan.TouchUpInside += (sender, e) => { // Configurar el escaner de codigo de barras. picker = new ScanditSDKRotatingBarcodePicker (MainView.appKey); picker.OverlayController.Delegate = new overlayControllerDelegate(picker, this); picker.OverlayController.ShowToolBar(true); picker.OverlayController.ShowSearchBar(true); picker.OverlayController.SetToolBarButtonCaption("Cancelar"); picker.OverlayController.SetSearchBarKeyboardType(UIKeyboardType.Default); picker.OverlayController.SetSearchBarPlaceholderText("Búsqueda por nombre de producto"); picker.OverlayController.SetCameraSwitchVisibility(SICameraSwitchVisibility.OnTablet); picker.OverlayController.SetTextForInitializingCamera("Iniciando la camara"); this.PresentViewController (picker, true, null); picker.StartScanning (); }; //Boton de tiendas Registradas this.btnTiendas.TouchUpInside += (sender, e) => { this._loadPop = new LoadingOverlay (UIScreen.MainScreen.Bounds); this.Add ( this._loadPop ); mvp = new MapViewController(); Task.Factory.StartNew ( () => { System.Threading.Thread.Sleep ( 1 * 1000 ); } ).ContinueWith ( t => { this._loadPop.Hide (); this.NavigationController.PushViewController(mvp, true); }, TaskScheduler.FromCurrentSynchronizationContext() ); }; //Boton Mis listas this.btnListas.TouchUpInside += (sender, e) => { if (people.Count == 1) { MyListsView myLists = new MyListsView (); this.NavigationController.PushViewController (myLists, true); } else { UIAlertView alert = new UIAlertView () { Title = "Espera!", Message = "Debes iniciar sesión para acceder a tus listas" }; alert.AddButton("Aceptar"); alert.Show (); } }; //Boton Iniciar Sesion this.btnSesion.TouchUpInside += (sender, e) => { if (people.Count == 1) { UIAlertView alert = new UIAlertView () { Title = "Espera!", Message = "Ya has iniciado sesión" }; alert.AddButton("Aceptar"); alert.Show (); } else { LoginView login = new LoginView (); this.NavigationController.PushViewController (login, true); } }; //Boton Novedades this.btnNovedades.TouchUpInside += (sender, e) => { StatesView statesView = new StatesView(); this.NavigationController.PushViewController(statesView, true); }; //Boton Nuestros Servicios this.btnServicios.TouchUpInside += (sender, e) => { AboutUsView aboutUS = new AboutUsView (); this.NavigationController.PushViewController (aboutUS, true); }; // creacion de la barra de herramientas float toolbarHeight = 44; toolbar = new UIToolbar (new CGRect (0 , this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height , this.View.Frame.Width, toolbarHeight)); toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleWidth; toolbar.TintColor = UIColor.FromRGB(7, 129, 181); // boton acerca de UIBarButtonItem btnacercaDe = new UIBarButtonItem (UIBarButtonSystemItem.Bookmarks); btnacercaDe.Clicked += (s, e) => { UIAlertView alert = new UIAlertView () { Title = "Que deseas consultar? " }; alert.AddButton("Terminos y Condiciones"); alert.AddButton("Aviso de Privacidad"); alert.Clicked+= (sen, o) =>{ if(o.ButtonIndex == 0) { TermsView termsView = new TermsView(); NavigationController.PushViewController(termsView, true); }else{ PrivacyNoticeView privacyNoticeView = new PrivacyNoticeView(); NavigationController.PushViewController(privacyNoticeView, true); } }; alert.Show (); }; // fixed width //UIBarButtonItem fixedWidth = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace); //fixedWidth.Width = 35; // flexible width space UIBarButtonItem flexibleWidth1 = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace); // boton fixBuy UIBarButtonItem btnFixBuy = new UIBarButtonItem (UIBarButtonSystemItem.Search); btnFixBuy.Clicked += (s, e) => { NSUrl url = new NSUrl (@"http://fixbuy.mx"); UIApplication.SharedApplication.OpenUrl (url); }; // flexible width space UIBarButtonItem flexibleWidth2 = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace); // boton email UIBarButtonItem btnEmail = new UIBarButtonItem (UIBarButtonSystemItem.Compose); btnEmail.Clicked += (s, e) => { //Añadimos las configuraciones para la vista de email mailController = new MFMailComposeViewController (); mailController.SetToRecipients (new string[]{"*****@*****.**"}); mailController.SetSubject ("Contacto"); mailController.SetMessageBody ("", false); mailController.Finished += ( object o, MFComposeResultEventArgs args) => { Console.WriteLine (args.Result.ToString ()); args.Controller.DismissViewController (true, null); }; this.PresentViewController (mailController, true, null); }; // arreglo de botones para toolbar UIBarButtonItem[] items = new UIBarButtonItem[] { btnacercaDe, flexibleWidth1, btnFixBuy, flexibleWidth2, btnEmail}; // agregar los botones a la toolbar toolbar.SetItems (items, false); // agregar la vista a la pantalla this.View.AddSubview (toolbar); try{ //Leemos el servicio de los banners this.bannersService = new BannersService (); banners = bannersService.All (); } catch (System.Net.WebException){ UIAlertView alert = new UIAlertView () { Title = "UPS :S", Message = "Hubo un error al conectarse a internet la seccion de banners no puede mostrarse, por favor verifica tu conexión a internet" }; alert.AddButton("Aceptar"); alert.Show (); } button = new UIButton (new CGRect (0, 0, bannerImage.Bounds.Width, bannerImage.Bounds.Height)); bannerImage.Add (button); button.TouchUpInside += (sender, e) => { try{ if(bannerError == false){ if(element.imagen != ""){ NSUrl url = new NSUrl (element.link); UIApplication.SharedApplication.OpenUrl (url); } } }catch(Exception){ //solo atrapamos la excepcion, no hacemos nada } }; }