public StateKunde(VCBaseDetails vcDetails, CustomUITableViewController viewController)
        {
            // The data
            _viewController = viewController;
            _vcDetails = vcDetails;
            _person = BusinessLayer.Kunde.Create();
            _fragmentState =  new StateFragmentGeneral (_vcDetails, _viewController, Application._user,this);

            // Set the UI
            ResetControls ();
            _fragmentState.ResetControls ();
        }
        async public override System.Threading.Tasks.Task BtnAnsprechpartnerFragmentClickAsync ( CustomUITableViewController viewController)
        {
            // If we are in the fragment, don't load it again
            if (_fragmentState.GetType () == typeof(StateFragmentAnsprechpartner))
                return;

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton();
            }

            // First check if a Kunde is selected
            if (this._person.ID == null)
                return;

//            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
//                return;

            // First set the appropriate FragmentState
            _viewController = viewController;
            this._fragmentState = new   StateFragmentAnsprechpartner (_vcDetails,  _viewController, Application._user,   this);
            await this._fragmentState.BtnAnsprechpartnerFragmentClickAsync ();

        }
        public void BtnZubehoerFragmentClick(CustomUITableViewController viewController)
        {
            _currentClassState.BtnZubehoerFragmentClick (ref viewController);

        }
        public void BtnVerfuegbarkeitFragmentClick(CustomUITableViewController viewController)
        {
            _currentClassState.BtnVerfuegbarkeitFragmentClick (ref viewController);

        }
 public void InteressentenTabClick(VCBaseDetails vcDetails, CustomUITableViewController viewController)
 {
     _currentClassState = new StateInteressenten (vcDetails,viewController);
 }
 public void LieferantenTabClick(VCBaseDetails vcDetails, CustomUITableViewController viewController)
 {
     _currentClassState = new StateLieferant (vcDetails,viewController);
 }
		public UIManager(VCBaseDetails vcDetails, CustomUITableViewController viewController)
		{
            _currentClassState = new StateKunde (vcDetails,viewController);			

		}
 public void BtnChartFragmentClick(CustomUITableViewController viewController)
 {
     _currentClassState.BtnChartFragmentClick (ref viewController);
     //_currentState = new StateChartFragment ();
 }
        public StateFragmentArtikelVerfuegbarkeit(VCBaseDetails vcDetails, CustomUITableViewController viewController, BusinessLayer.User user,  StateClass stateClass )
        {
            // Just set the main properties which we need later
            _viewController = (TBVerfuegbarkeitArtikel)viewController;
            _stateClass = stateClass;


        }
        public override void BtnVerfuegbarkeitFragmentClick(ref CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentArtikelVerfuegbarkeit))
                return;

            // First set the appropriate FragmentState
            _viewController = viewController;
            this._fragmentState = new   StateFragmentArtikelVerfuegbarkeit (_vcDetails,  _viewController, Application._user,   this);

            // First check if a artike is selected
            if (this._artikel.ID == null)
                return;

            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                return;

            this._fragmentState.BtnVerfuegbarkeitFragmentClick ();


        }
        public override async Task BtnZubehoerFragmentClickAsync(CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentZubehoer))
                return;

            // First set the appropriate FragmentState
            _viewController = viewController;
            this._fragmentState = new   StateFragmentZubehoer (_vcDetails,  _viewController, Application._user,   this);

            // First check if a artike is selected
            if (this._artikel.ID == null)
                return;

            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                return;

            await this._fragmentState.BtnCrossSellingFragmentClickAsync ();
        }
        async public override Task BtnGeneralFragmentClickAsync( CustomUITableViewController viewController)
        {
            // If we are in the fragment, don't load it again
            if (_fragmentState.GetType () == typeof(StateFragmentArtikelGeneral))
                return;

            _viewController = viewController;
            _fragmentState = new StateFragmentArtikelGeneral (_vcDetails,  _viewController, Application._user, this);
            await _fragmentState.BtnGeneralFragmentClickAsync  ();

        }
        public StateArtikel(VCBaseDetails vcDetails, CustomUITableViewController viewController)
        {


            // The date
            _viewController = viewController;
            _vcDetails = vcDetails;
            _artikel = BusinessLayer.Artikel.Create();
            _fragmentState =  new StateFragmentArtikelGeneral (_vcDetails, _viewController, Application._user,this);

            // Set the UI
            ResetControls ();
            //          _fragmentState.ResetControls ();

        }
        public override void BtnGeneralFragmentClick(ref CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentGeneral))
                return;

            _viewController = viewController;
            _fragmentState = new StateFragmentGeneral ( _vcDetails,  _viewController,Application._user , this);

            _fragmentState.BtnGeneralFragmentClick ();

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


        }
        async public override Task BtnGeneralFragmentClickAsync( CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentGeneral))
                return;

            _viewController = viewController;
            _fragmentState = new StateFragmentGeneral ( _vcDetails,  _viewController,Application._user , this);

            await _fragmentState.BtnGeneralFragmentClickAsync ();

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton();
            }

        }
 public void BtnAnsprechpartnerFragmentClick(CustomUITableViewController viewController)
 {
     _currentClassState.BtnAnsprechpartnerFragmentClick (ref  viewController);
 }
        public StateFragmentBestellung(VCBaseDetails vcDetails, CustomUITableViewController viewController, BusinessLayer.User user,  StateClass stateClass )
        {
            // Just set the main properties which we need later
            _viewController =(TBAuftrag) viewController;
            _stateClass = stateClass;


        }           
 async public System.Threading.Tasks.Task BtnChartFragmentClickAsync(CustomUITableViewController viewController)
 {
     await _currentClassState.BtnChartFragmentClickAsync ( viewController);
     //_currentState = new StateChartFragment ();
 }
        async public override Task BtnChartFragmentClickAsync(CustomUITableViewController viewController)
        {
            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(false);
                _vcDetails.CreateMenuButton();
            }

            _viewController = viewController;
            this._fragmentState = new   StateFragmentChart (_vcDetails,  _viewController, Application._user,   this);

            // First check if a Kunde is selected
            if (this._person.ID == null)
                return;

//            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
//                return;

            await this._fragmentState.BtnChartFragmentClickAsync ();

        }
		public void KundenTabClick(VCBaseDetails vcDetails, CustomUITableViewController viewController)
		{
            _currentClassState = new StateKunde (vcDetails,viewController);


		}
        public override void BtnMapFragmentClick(ref CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentMap))
                return;

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(false);
                _vcDetails.CreateMenuButton();
            }

            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                return;

            _viewController = viewController;
            _fragmentState = new StateFragmentMap (_vcDetails,  _viewController,  Application._user, this);

            _fragmentState.BtnMapFragmentClick ();


        }
		public void OnTabItemSelected(string tabName,VCBaseDetails vcDetails, CustomUITableViewController viewController)
		{
			switch(tabName)
			{
    			case "Kunden":
    				{
    					KundenTabClick (vcDetails,viewController);
    					break;
    				}
    			case "Lieferanten":
    				{
    					LieferantenTabClick (vcDetails,viewController);
    					break;
    				}
                case "Interessenten":
                    {
                        InteressentenTabClick(vcDetails, viewController);
                        break;
                    }
    			case "Full Screen":
    				{
    					break;
    				}
    			case "Settings":
    				{
    					//(typeof(SettingsActivity));
    					break;
    				}
			}

		}
        public override void BtnTaskFragmentClick (ref CustomUITableViewController viewController)
        {

            if (_fragmentState.GetType () == typeof(StateFragmentTask))
                return;

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton();
            }
            else
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton();
            }

            // First set the appropriate FragmentState
            _viewController = viewController;
            this._fragmentState = new   StateFragmentTask (_vcDetails,  _viewController, Application._user,   this);

            // First check if a Person is selected
            if (this._person.ID == null)
                return;

//            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
//                return;

            this._fragmentState.BtnTaskFragmentClick ();


        }
        public void ArtikelTabClick(VCBaseDetails vcDetails, CustomUITableViewController viewController)
		{
            _currentClassState = new StateArtikel(vcDetails, viewController);
			;
		}
        async public override Task BtnAuftragFragmentClickAsync(CustomUITableViewController viewController)
        {
            if (_fragmentState.GetType () == typeof(StateFragmentAuftrag))
                return;

            // First set the appropriate FragmentState
            _viewController = viewController;
            this._fragmentState = new   StateFragmentAuftrag (_vcDetails,  _viewController, Application._user,   this);

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton(true, false, false, true, false);
            }

            // First check if a Person is selected
            if (this._person.ID == null)
                return;

//            if  (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
//                return;

            await this._fragmentState.BtnAuftragFragmentClickAsync ();

        }
        public void BtnCrossSellingFragmentClick(CustomUITableViewController viewController)
        {
            _currentClassState.BtnCrossSellingFragmentClick (ref viewController);

        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///
        /// Events of the class
        ///
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region Events

        /// <summary>
        /// Set the captions of the controls
        /// </summary>
        /// <param name="animated">If set to <c>true</c> animated.</param>
        public override void ViewWillAppear(bool animated)
        {
            Console.WriteLine("VCLieferantenDetails ViewWillAppear called " + this.ToString());
            base.ViewWillAppear(animated);

            // Set labels of the controls
            SetControlCaptions();

            // Set the network icon
            UpdateNetwork((AppDelegate.currentInternetStatus == NetworkStatus.ReachableViaWiFiNetwork || AppDelegate.currentInternetStatus == NetworkStatus.ReachableViaCarrierDataNetwork) && Application._user.NetworkStatus != DataAccessLayer.NetworkState.Disconnected);

            // Reset the controls
            ResetControls();

            if (this.childController.GetType() != typeof(UI.TBGeneral))
            {
                UIViewController oldViewController = childController;
                childController = _Storyboard.InstantiateViewController("TBGeneral") as TBGeneral;
                DisplayContentController(childController);
                CycleFromViewControllerToViewController(oldViewController, childController);
                Application._UIManager.BtnGeneralFragmentClick(childController);
            }

            // Run the UIManager for TabClick
            // set the caption of the Tabcontroller
            this.Title = LocalString.GetString(this.RestorationIdentifier);
            switch (IOS_Utilities.GetCategory(this.RestorationIdentifier))
            {
                case IOS_Utilities.Categories.Kunden:
                    {
                        Application._UIManager.KundenTabClick(this, this.childController);
                        break;
                    }
                case IOS_Utilities.Categories.Lieferanten:
                    {
                        Application._UIManager.LieferantenTabClick(this, this.childController);
                        break;
                    }
                case IOS_Utilities.Categories.Interessenten:
                    {
                        Application._UIManager.InteressentenTabClick(this, this.childController);
                        break;
                    }
                default:
                    {
                        break;
                    }
            }

        }
        async public System.Threading.Tasks.Task BtnZubehoerFragmentClickAsync(CustomUITableViewController viewController)
        {
            await _currentClassState.BtnZubehoerFragmentClickAsync ( viewController);

        }
        public override void BtnGeneralFragmentClick(ref CustomUITableViewController viewController)
        {
            // If we are in the fragment, don't load it again
            if (_fragmentState.GetType () == typeof(StateFragmentGeneral))
                return;

            _viewController = viewController;
            _fragmentState = new StateFragmentGeneral (_vcDetails,  _viewController, Application._user, this);
            _fragmentState.BtnGeneralFragmentClick ();

            // Configure the buttons
            if (Application._user.NetworkStatus == DataAccessLayer.NetworkState.Disconnected)
                _vcDetails.ConfigureMenuButton(false);
            else
            {
                _vcDetails.ConfigureMenuButton(true);
                _vcDetails.CreateMenuButton();
            }

        }