/// <summary>
        /// All the configurations and event settings are handled here
        /// !!! This must be checked when the setting view controller is implemented !!!
        /// </summary>
        public override void ViewDidLoad()
        {
            Console.WriteLine("VCLieferantenDetails ViewDidLoad called " + this.ToString());

            base.ViewDidLoad();

            // Any additional setup after loading the view, typically from a nib.
            ConfigureView();


            // Set the childcontroller that is selected according to the button that was selected
            // By default the GENERAL Button is clicked
            childController = _Storyboard.InstantiateViewController("TBGeneral") as TBGeneral;
            DisplayContentController(childController);

            // Create the UIManager
            Application._UIManager = new UIManager(this, childController);


            // Set it as an observer to the main Tableview, so that it is notified when a new row is clicked 
            // and it is able to display the person's info in its title bar
            Application._mainModulePersonTableView.RegisterObserver(this);

            // Here the event of the button is managed
            MainSegmentedButtons.ValueChanged += async(object sender, EventArgs e) =>
            {

                try
                {
                    // Run the progressbar

                    hud = new MTMBProgressHUD(this.TabBarController.View){ DimBackground = true, LabelText = LocalString.GetString("Loading") };
                    this.TabBarController.View.AddSubview(hud);
                    hud.Show(true);


                    UIViewController oldViewController = childController;
                    switch ((int)MainSegmentedButtons.SelectedSegment)
                    {
                        case (int)IOS_Utilities.ViewButtons.General:
                            {
                                // General Button is clicked
                                // First set the childcontroller
                                // Then display it
                                // Then manage the acions via UIManager
                                childController = _Storyboard.InstantiateViewController("TBGeneral") as TBGeneral;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnGeneralFragmentClickAsync(childController);
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Ansprechpartner:
                            {
                                // Ansprechpartner Button is clicked
                                // First set the childcontroller
                                // Then display the childcontroller
                                // Then manage the actions via UIManager
                                childController = _Storyboard.InstantiateViewController("TBAnsprechpartner") as TBAnsprechpartner;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnAnsprechpartnerFragmentClickAsync(childController);
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Chart:
                            {
                                // Chart Button is clicked
                                childController = _Storyboard.InstantiateViewController("TBChart") as TBChart;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnChartFragmentClickAsync(childController);
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Map:
                            {
                                childController = _Storyboard.InstantiateViewController("TBMap") as TBMap;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnMapClickAsync(childController);
                                // Map
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Task:
                            {
                                // Tasks
                                childController = _Storyboard.InstantiateViewController("TBTask") as TBTask;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                Console.WriteLine("Running Task Async");
                                await Application._UIManager.BtnTaskFragmentClickAsync(childController);
                                Console.WriteLine("Finished Async");
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Angebot:
                            {
                                // Tasks
                                childController = _Storyboard.InstantiateViewController("TBAngebot") as TBAngebot;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                Console.WriteLine("Running Angebot Async");
                                await Application._UIManager.BtnAngebotFragmentClickAsync(childController);
                                Console.WriteLine("Finished Async");
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Auftrag:
                            {
                                // Tasks
                                childController = _Storyboard.InstantiateViewController("TBAuftrag") as TBAuftrag;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                Console.WriteLine("Running Auftrag Async");
                                await Application._UIManager.BtnAuftragFragmentClickAsync(childController);
                                Console.WriteLine("Finished Async");
                                break;
                            }


                        default:
                            {
                                return;
                            }
                    }

                }
                catch (Exception ex)
                {
                    DataAccessLayer.ExceptionWriter.WriteLogFile(ex);

                }
                finally
                {
                    // finallize the progressbar
                    hud.RemoveFromSuperview();
                    hud = null;
                }




            };

            // Create the satellite buttons that are visible on all views
            var temp = CreateMenuButton();
            this.ButtonContainerView.Add(temp);


        }
Ejemplo n.º 2
0
		void ShowUsingHandlers ()
		{
			// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
			hud = new MTMBProgressHUD (this.navController.View);
			navController.View.AddSubview (hud);

			// Add information to your HUD
			hud.LabelText = "With a handler";

			// We show the hud while executing MyTask, and then we clean up
			hud.Show (true, () => { 
				MyTask(); 
			}, () => {
				hud.RemoveFromSuperview();
				hud = null;
			});
		}
        /// <summary>
        /// Get the lieferanten according to the search text -> set it as the source for the tableview -> hide the keyboard
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">EventArgs.</param>
        private async  void MainSearchBarClicked (object sender, EventArgs e )
        {
            try
            {
                // Run the progressbar

                MainSearchBar.ResignFirstResponder();
                hud = new MTMBProgressHUD (this.TabBarController.View){DimBackground = true, LabelText = LocalString.GetString("Loading")};
                this.TabBarController.View.AddSubview (hud);
                hud.Show(true);

                // First let the UIManager manager the story and get the values
                _lieferanten = await Application._UIManager.BtnSearchLieferantenClickAsync (MainSearchBar.Text.Trim());

                // Then fill the datasource and tableview
                dataSource.SetSource(_lieferanten);
                TableView.ReloadData();

                // hide the keyboard
                MainSearchBar.ResignFirstResponder();

            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }
            finally
            {
                // finallize the progressbar
                hud.RemoveFromSuperview();
                hud = null;
            }


        }
        /// <summary>
        /// Create the satellite buttons of the main view and assign the events to them
        /// Sets also the events for every menu button
        /// </summary>
        /// <returns>The menu button.</returns>
        public override SatelliteMenuButton CreateMenuButton()
        {
            int tag;
            var frame = new CGRect(10, 156, 44, 44);
            button1 = new SatelliteMenuButtonItem(UIImage.FromFile("Images/NewPage.png"), tag = 0, "New");
            button2 = new SatelliteMenuButtonItem(UIImage.FromFile("Images/EditPage.png"), ++tag, "Edit");
            button3 = new SatelliteMenuButtonItem(UIImage.FromFile("Images/DeletePage.png"), ++tag, "Delete");
            button4 = new SatelliteMenuButtonItem(UIImage.FromFile("Images/DownloadPage.png"), ++tag, "Offline");
            button5 = new SatelliteMenuButtonItem(UIImage.FromFile("Images/SavePage.png"), ++tag, "Save");

            // Reset the MenuButton if there is something inside of it
            if (menu == null)
                menu = new SatelliteMenuButton(this.ButtonContainerView, UIImage.FromFile("Image/menu.png"), frame);
            else if (menu.Items.Length != 5)
            {
                foreach (SatelliteMenuButtonItem item in menu.Items)
                {
                    menu.RemoveItem(item);
                }
            }

            //var frame = new RectangleF (MARGIN, View.Frame.Height - MARGIN - BUTTON_SIZE, BUTTON_SIZE, BUTTON_SIZE);
            menu = new SatelliteMenuButton(this.ButtonContainerView, UIImage.FromFile("Images/menu.png"), new []
                { 
                    button1, 
                    button2,
                    button3,
                    button4,
                    button5
                }, frame);

            menu.Radius = 120;
            menu.RotateToSide = false;

            menu.MenuItemClick += async (_, args) =>
            {
                bool result = false;
                try
                {
                    // Run the progressbar


                    switch (args.MenuItem.Name)
                    {
                        case "New":
                            hud = new MTMBProgressHUD(this.TabBarController.View){ DimBackground = true, LabelText = LocalString.GetString("SavingData") };
                            this.TabBarController.View.AddSubview(hud);
                            hud.Show(true);
                            Application._UIManager.BtnNewClick();
                            break;

                        case "Edit":
                            hud = new MTMBProgressHUD(this.TabBarController.View){ DimBackground = true, LabelText = LocalString.GetString("SavingData") };
                            this.TabBarController.View.AddSubview(hud);
                            hud.Show(true);
                            Application._UIManager.BtnEditClick();
                            break;

                        case "Delete":
                            hud = new MTMBProgressHUD(this.TabBarController.View){ DimBackground = true, LabelText = LocalString.GetString("SavingData") };
                            this.TabBarController.View.AddSubview(hud);
                            hud.Show(true);
                            result = await Application._UIManager.BtnDeleteClickAsync();
                            if (result == true)
                                MessageBox.ShowSavedSuccessfully(this.TabBarController.View, LocalString.GetString("DeletedSuccessfully"));
                            break;

                        case "Offline":
                            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                                return;
                            progress = 0;
                            hud = new MTMBProgressHUD(this.TabBarController.View)
                                { Mode = MBProgressHUDMode.DeterminateHorizontalBar, LabelText = LocalString.GetString("DownloadingOffline") };
                            this.TabBarController.View.AddSubview(hud);
                            hud.Progress = 0;
                            hud.Show(true, MyProgressTask);

                            result = await Application._UIManager.BtnOfflineClickAsync();
                            hud.Progress = 0.99f;
                            await System.Threading.Tasks.Task.Delay(500);
                            hud.Progress = 1.1f;


                            if (result == true)
                                MessageBox.ShowSavedSuccessfully(this.TabBarController.View, LocalString.GetString("SavedOfflineSuccessfully"));

                            break;

                        case "Save":

                            result = await Application._UIManager.BtnSaveClickAsync();
                            if (result == true)
                                MessageBox.ShowSavedSuccessfully(this.TabBarController.View, LocalString.GetString("SavedSuccessfully"));
                            break;

                        default:
                            break;
                    }
                }
                catch (Exception ex)
                {
                    DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
                }
                finally
                {
                    Console.WriteLine("finally entered");
                    // finallize the progressbar
                    if (hud != null)
                    {
                        hud.RemoveFromSuperview();
                        hud = null;
                    }
                    Console.WriteLine("finally finished");
                }


            };

            this.ButtonContainerView.Add(menu);

            return menu;
        }
        async void MainSearchBar_Clicked(object sender, EventArgs e)
        {
            MainSearchBar.ResignFirstResponder();
            TxtDummy.BecomeFirstResponder();
            TxtDummy.ResignFirstResponder();

            try
            {
                // Run the progressbar

                MainSearchBar.ResignFirstResponder();
                hud = new MTMBProgressHUD (this.View){DimBackground = true, LabelText = LocalString.GetString("Loading")};
                this.View.AddSubview (hud);
                hud.Show(true);

                // First let the UIManager manager the story and get the values
                _artikeln = await BusinessLayer.Artikel.GetArtikelnAsync (MainSearchBar.Text,Language.GetLanguageCode(), Application._user);

                // Then fill the datasource and tableview
                dataSource.SetSource(_artikeln);
                tableView.ReloadData();

                // hide the keyboard
                MainSearchBar.ResignFirstResponder();
                TxtDummy.BecomeFirstResponder();
                TxtDummy.ResignFirstResponder();

            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }
            finally
            {
                // finallize the progressbar
                hud.RemoveFromSuperview();
                hud = null;
            }
        }
        /// <summary>
        /// All the configurations and event settings are handled here
        /// !!! This must be checked when the setting view controller is implemented !!!
        /// </summary>
        public override void ViewDidLoad ()
        {
            Console.WriteLine("VCArtikelDetails ViewDidLoad called " + this.ToString());

            base.ViewDidLoad ();

            // Any additional setup after loading the view, typically from a nib.
            ConfigureView ();


            // Set the childcontroller that is selected according to the button that was selected
            // By default the GENERAL Button is clicked
            childController = _Storyboard.InstantiateViewController ("TBGeneral") as TBGeneral;
            DisplayContentController(childController);

            // Create the UIManager
            Application._UIManager.ArtikelTabClick(this,(CustomUITableViewController)childController);


            // Set it as an observer to the main Tableview, so that it is notified when a new row is clicked 
            // and it is able to display the person's info in its title bar
            Application._mainModuleArtikelTableView.RegisterObserver(this);

            // Here the event of the button is managed
            MainSegmentedButtons.ValueChanged += async(object sender, EventArgs e) => {
                try
                {
                    // Run the progressbar
                    hud = new MTMBProgressHUD (this.TabBarController.View){DimBackground = true, LabelText = LocalString.GetString("Loading")};
                    this.TabBarController.View.AddSubview (hud);
                    hud.Show(true);
                    UIViewController oldViewController = childController;
                    switch((int) MainSegmentedButtons.SelectedSegment)
                    {
                        case (int)IOS_Utilities.ViewButtons.General:
                            {
                                // General Button is clicked
                                // First set the childcontroller
                                // Then display it
                                // Then manage the acions via UIManager
                                childController = _Storyboard.InstantiateViewController ("TBGeneralArtikel") as TBGeneralArtikel;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnGeneralFragmentClickAsync((CustomUITableViewController)childController);
                                break;
                            }
                        case (int)IOS_Utilities.ViewButtons.Ansprechpartner:
                            {
                                childController = _Storyboard.InstantiateViewController ("TBVerfuegbarkeitArtikel") as TBVerfuegbarkeitArtikel;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnVerfuegbarkeitFragmentClickAsync((CustomUITableViewController)childController);
                                break;

                            }
                        case (int)IOS_Utilities.ViewButtons.Chart:
                            {
                                childController = _Storyboard.InstantiateViewController ("VCArtikelPreisInfo") as VCArtikelPreisInfo;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnPreisInfoFragmentClickAsync((VCArtikelPreisInfo)childController);
                                break;

                            }
                        case (int)IOS_Utilities.ViewButtons.Map :
                            {
                                childController = _Storyboard.InstantiateViewController ("TBCrossSelling") as TBCrossSelling;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnCrossSellingFragmentClickAsync((CustomUITableViewController)childController);
                                break;

                            }
                        case (int)IOS_Utilities.ViewButtons.Task :
                            {
                                childController = _Storyboard.InstantiateViewController ("TBZubehoer") as TBZubehoer;
                                DisplayContentController(childController);
                                CycleFromViewControllerToViewController(oldViewController, childController);
                                await Application._UIManager.BtnZubehoerFragmentClickAsync((CustomUITableViewController)childController);
                                break;

                            }
                        // Here I have to declare different segmented buttons
                        default:
                            break;
                    }

                }
                catch (Exception ex)
                {
                    DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
                }
                finally
                {
                    // finallize the progressbar
                    hud.RemoveFromSuperview();
                    hud = null;
                }
            };
        }
        async private Task<bool> TestConnection()
        {
            bool result = false;

            try
            {
                // Run the progressbar
                hud = new MTMBProgressHUD (this.TabBarController.View){DimBackground = true, LabelText = LocalString.GetString("Loading")};
                this.TabBarController.View.AddSubview (hud);
                hud.Show(true);
                result = await Application._user.TestConnectionAsync();

            }
            catch(Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }
            finally
            {
                hud.RemoveFromSuperview();
                hud = null;
            }
            return result;
        }
        /// <summary>
        /// Purpose : Validate -> Authenticate -> Save Url -> if successfull -> Run the main control
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private async void Login (object sender , EventArgs e)
        {
            try
            {


                // Run the progressbar
                hud = new MTMBProgressHUD (this.View){DimBackground = true, LabelText = LocalString.GetString("Authenticating")};
                this.View.AddSubview (hud);
                hud.Show(true);

                // First dismiss the keyboard
                TfUsername.ResignFirstResponder();
                TfPassword.ResignFirstResponder();
                TfServerIP.ResignFirstResponder();
                TfMandant.ResignFirstResponder();

                // First Validate the controls
                if (Validate() == false)
                    return ;

                // First get the URL and set it to the main URL
                DataAccessLayer.Utilities.ServerIP = TfServerIP.Text;
                BusinessLayer.User.SetUrl(TfServerIP.Text);

                // Check the Network status
                networkStatus = GetNetworkStatus();

                // Then authenticate the user by the values of the controls
                if (await Authenticate(TfUsername.Text, TfPassword.Text, TfMandant.Text,networkStatus,  SwitchOffline.On ) == false)
                    return ;
                
                // if authenticated and the user online, save the user in the offline database
                // the offline user is only saved in the offline database anyway
                if (SwitchOffline.On == false)
                    Application._user.SaveOnlineUserData();

                // Now check if this device has a license to use the app
                if (await this.ValidateLicenseAsync() == false)
                    return ;

                if (_vcSettings != null)
                {
                    _loggedSuccessfully = true;
                    DismissViewController(true,null);
                    return ;
                }

                if (tabController == null)
                    tabController = Storyboard.InstantiateViewController<MainTabController>();

                Theme.TransitionController(tabController);

            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLine(ex.Message, ex.StackTrace);
            }
            finally
            {
                // finallize the progressbar
                hud.RemoveFromSuperview();
                hud = null;


            }

        }
         /// <summary>
        /// Purpose : Validate -> Authenticate -> Save Url -> if successfull -> Run the main control
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void Login (object sender , EventArgs e)
        {
            try
            {
                // Run the progressbar
                hud = new MTMBProgressHUD (this.View){DimBackground = true, LabelText = LocalString.GetString("Authenticating")};
                this.View.AddSubview (hud);
                hud.Show(true);

                // First dismiss the keyboard
                TxtUsername.ResignFirstResponder();
                TxtNewPassword.ResignFirstResponder();
                TxtConfirmPassword.ResignFirstResponder();
                TxtNewPassword.ResignFirstResponder();

                // First Validate the controls
                if (Validate() == false)
                    return ;

                // Set the new password
                BusinessLayer.User.SetOfflineUser(TxtUsername.Text,TxtNewPassword.Text);

                //BusinessLayer.User.SetOfflinePassword(TxtNewPassword.Text);
                MessageBox.ShowSavedSuccessfully(this.View,LocalString.GetString("SavedSuccessfully"));
                this.DismissViewController(true,null);

            }
            catch (Exception ex)
            {
                DataAccessLayer.ExceptionWriter.WriteLogFile(ex);
            }
            finally
            {
                // finallize the progressbar
                hud.RemoveFromSuperview();
                hud = null;


            }

        }