private void AppSettingsPage_SettingsSaved(object sender, EventArgs e) { Database.CreateGlobalTables(); TechnicianListPageViewModel viewModel = new TechnicianListPageViewModel(); viewModel.PropertyChanged += TechnicianListPageViewModel_PropertyChanged; MainPage = new TechnicianListPage(viewModel); }
public TechnicianListPage() { InitializeComponent(); _vm = new TechnicianListPageViewModel(); gridTechnician.ItemsSource = _vm.TechnicianList; gridTechnician.MouseDoubleClick += GridTechnician_MouseDown; bw.WorkerReportsProgress = true; bw.DoWork += Bw_DoWork; bw.ProgressChanged += Bw_ProgressChanged; bw.RunWorkerCompleted += Bw_RunWorkerCompleted; }
public void LogOff() { if (CurrentTechnician != null) { // puke... log off current tech } TechnicianListPageViewModel vm = new TechnicianListPageViewModel(); MainPage = new TechnicianListPage(vm); }
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e) { MainMenuItem item = e.SelectedItem as MainMenuItem; if (item != null) { if (item.Title.ToLower() == "exit") { // puke... close app await DisplayAlert("Log off", "Normally, this would log the user off.", "OK", "Cancel"); return; } if (item.Title.ToLower() == "log out") { App_Settings appSettings = App.Database.GetApplicationSettings(); appSettings.LoggedInTechnicianNo = ""; appSettings.LoggedInTechnicianDeptNo = ""; App.Database.SaveAppSettings(appSettings); TechnicianListPageViewModel viewModel = new TechnicianListPageViewModel(); viewModel.PropertyChanged += TechnicianListPageViewModel_PropertyChanged; //await Navigation.PushAsync(new TechnicianListPage(viewModel)); //Detail = new NavigationPage(new TechnicianListPage(viewModel)); Application.Current.MainPage = new TechnicianListPage(viewModel); //new NavigationPage(new TechnicianListPage(viewModel)); return; } _masterPage.ListView.SelectedItem = null; // so the item doesn't stay highlighted if (item.Title.ToLower() == "settings") { AppSettingsPage page = (AppSettingsPage)Activator.CreateInstance(item.TargetType); page.SettingsSaved += AppSettingsPage_SettingsSaved; await Detail.Navigation.PushAsync(page); } else { await Detail.Navigation.PushAsync((Page)Activator.CreateInstance(item.TargetType)); } IsPresented = false; } }
public void TechnicianListPageViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { TechnicianListPageViewModel vm = sender as TechnicianListPageViewModel; switch (e.PropertyName) { case "IsLoading": IHud hud = DependencyService.Get <IHud>(); if (vm.IsLoading) { //XHUD.HUD.Show("Loading data...", -1, XHUD.MaskType.Black); hud.Show("Loading data..."); } else { hud.Dismiss(); } break; case "IsSignedIn": if (vm.IsSignedIn) { Device.BeginInvokeOnMainThread(() => MainPage = new MainDashboard()); //MainPage = new MainDashboard(this); } else { if (!(MainPage is TechnicianListPage)) { MainPage = new TechnicianListPage(vm); } } break; default: break; } }
protected async override void OnStart() { // Handle when your app starts bool hasValidSetup = false; App_Settings appSettings = App.Database.GetApplicationSettings(); string loggiedintechnicianno; JT_Technician technician = null; bool tableExists = false; try { hasValidSetup = await Database.HasValidSetup(appSettings); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); await MainPage.DisplayAlert("Error!", ex.Message, "OK"); throw; } tableExists = App.Database.TableExists <JT_Technician>(); // Are the settings valid? if (hasValidSetup) { // Yes, so move on to the technician login //App_Settings appSettings = App.Database.GetApplicatioinSettings(); loggiedintechnicianno = (appSettings.LoggedInTechnicianNo != null) ? appSettings.LoggedInTechnicianNo : ""; if (tableExists && loggiedintechnicianno.Length > 0) // we've already established we do && Database.HasDataConnection()) { technician = App.Database.GetTechnician(appSettings.LoggedInTechnicianDeptNo, appSettings.LoggedInTechnicianNo); if (technician != null) { App.Database.SaveTechnicianAsCurrent(technician); App.Database.CreateDependentTables(technician); MainPage = new MainDashboard(); } else { if (Database.HasDataConnection()) { Database.CreateGlobalTables(); } Thread.Sleep(5000); TechnicianListPageViewModel viewModel = new TechnicianListPageViewModel(); viewModel.PropertyChanged += TechnicianListPageViewModel_PropertyChanged; MainPage = new TechnicianListPage(viewModel); } } else { if (Database.HasDataConnection()) { Database.CreateGlobalTables(); } Thread.Sleep(5000); TechnicianListPageViewModel viewModel = new TechnicianListPageViewModel(); viewModel.PropertyChanged += TechnicianListPageViewModel_PropertyChanged; MainPage = new TechnicianListPage(viewModel); } } else { // Invalid settings, so show the settings page. // Otherwise, data calls will never work. AppSettingsPage settingsPage = new AppSettingsPage(); settingsPage.SettingsSaved += AppSettingsPage_SettingsSaved; MainPage = settingsPage; return; } }
public TechnicianListPage(TechnicianListPageViewModel viewModel) { hud.Show(); hud.Dismiss(); // Set the page title. NavigationPage.SetHasNavigationBar(this, true); Title = "Technican Dashboard"; _activityIndicator = new ActivityIndicator() { Color = Color.Red }; _activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsLoading"); _activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsLoading"); _activityIndicator.BindingContext = _vm; BackgroundColor = Color.White; // Create the view model for this page _vm = viewModel; //new TechnicianListPageViewModel(); // Set the binding context for this page BindingContext = _vm.TechnicianList; // Create our screen objects // Create a label for the technician list _labelTitle = new Xamarin.Forms.Label(); _labelTitle.Text = "SELECT TECHNICIAN"; _labelTitle.FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null); _labelTitle.FontSize = 22; _labelTitle.TextColor = Color.White; _labelTitle.HorizontalTextAlignment = TextAlignment.Center; _labelTitle.VerticalTextAlignment = TextAlignment.Center; Grid titleLayout = new Grid() { BackgroundColor = Color.FromHex("#2980b9"), HorizontalOptions = LayoutOptions.FillAndExpand, HeightRequest = 80 }; titleLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); titleLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); titleLayout.Children.Add(_labelTitle, 0, 0); // Create a template to display each technician in the list var dataTemplateItem = new DataTemplate(typeof(TechnicialDataCell)); // Create the actual list _listViewTechnicians = new ListView() { HasUnevenRows = true, HorizontalOptions = LayoutOptions.Fill, SeparatorVisibility = SeparatorVisibility.None, BackgroundColor = Color.White, ItemsSource = _vm.TechnicianList, ItemTemplate = dataTemplateItem }; _listViewTechnicians.ItemTapped += ListViewTechnicians_ItemTapped; StackLayout layout = new StackLayout { BackgroundColor = Color.FromHex("#2980b9"), Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, Children = { titleLayout, _activityIndicator, _listViewTechnicians } }; if (Device.OS == TargetPlatform.iOS) { // move layout under the status bar layout.Padding = new Thickness(0, 40, 0, 0); } Content = layout; }