Beispiel #1
0
        }  //Constructor

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            List <Kpi> rnkpi = new List <Kpi>();

            VDAGateway = new VDAGateway();

            if (neededKpi != null && relatedKpi != null)
            {
                rnkpi = neededKpi; //Sets list to all the needkPIs
            }

            //Initialize table view and its source
            TableSource = new KPITableModel(rnkpi, relatedKpi); //Passing in needed list and related kpi seperately
            _table      = new UITableView
            {
                Frame  = new CoreGraphics.CGRect(0, 0, View.Bounds.Width, View.Bounds.Height),
                Source = TableSource
            };

            //To get rid of table seperator lines
            _table.SeparatorStyle = UITableViewCellSeparatorStyle.None;

            //Set background color for the whole table
            _table.BackgroundColor = UIColor.White;
            View.AddSubview(_table);

            TableSource.NewPageEvent += KpiSelected;
        }
Beispiel #2
0
        public async void LoginRequested(object sender, EventArgs e)
        { //When login button is pressed enable alerts and transition to MainViewController if right conditions are met
            var bounds = UIScreen.MainScreen.Bounds;

            loader = new LoadingOverlay(bounds, "Checking credentials...");
            View.Add(loader);


            LoginButton.Enabled = false; //Unable to click login button two times or more while loading


            MainViewController viewcontroller = Storyboard.InstantiateViewController("MainViewController") as MainViewController;
            KPITableModel      MySender       = sender as KPITableModel;

            if (viewcontroller != null)
            { //If the view controller is null for somereason, does not transfer
                string username = UsernameTextfield.Text;
                string password = PasswordTextfield.Text;

                Task <HttpResponseMessage> TaskResponse = vdaGateway.VerifyLogin(username, password);

                var response = await TaskResponse as HttpResponseMessage;

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    //Alert for Invalid Credentials
                    var invalidcontroller = UIAlertController.Create("Invalid Credentails", "Please enter a valid Username and/or Password", UIAlertControllerStyle.Alert);
                    invalidcontroller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(invalidcontroller, true, null);
                }

                else
                {
                    string json_string = await response.Content.ReadAsStringAsync();

                    var verifiedLogin = JsonConvert.DeserializeObject <VerifyLogin>(json_string) as VerifyLogin;

                    if (verifiedLogin == null)
                    {
                        //Alert for Server Error
                        var errorcontroller = UIAlertController.Create("Server Error", "Server response unable to read, please try again later", UIAlertControllerStyle.Alert);
                        errorcontroller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                        PresentViewController(errorcontroller, true, null);
                    }

                    else
                    {
                        viewcontroller.login_info = verifiedLogin;                          //Pass dealer's name to next view
                        this.NavigationController.PushViewController(viewcontroller, true); //This code changes the view
                    }
                }
            }
            LoginButton.Enabled = true;
            loader.Hide();
        }
Beispiel #3
0
        public async void KpiSelected(object sender, EventArgs e)
        {
            _table.UserInteractionEnabled = false;

            //Transitioning to ActionsViewController
            ActionsViewController nextPage = this.Storyboard.InstantiateViewController("ActionsViewController") as ActionsViewController;
            KPITableModel         MySender = sender as KPITableModel;

            Kpi selectedKpi = MySender.getSelected();

            if (nextPage != null)
            {
                //gotta reset our list variables
                actions = new List <KpiAction>();

                //============= Calling our API ======
                string json_string; // for future use if we wanna define a threshold

                if (string.IsNullOrEmpty(selectedKpi.name))
                {
                    //Error Alert
                    var selectioncontroller = UIAlertController.Create("Selection Error", "Please select a KPI", UIAlertControllerStyle.Alert);
                    selectioncontroller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(selectioncontroller, true, null);

                    //new UIAlertView("Selection Error", "Please select a KPI", null, "OK", null).Show();
                    return;
                }

                var response = await VDAGateway.Actions(selectedKpi.name, selectedKpi.p_val);

                //if we still have internal server error
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    //Error Alert
                    var apicontroller = UIAlertController.Create("API Error", "Server under maintenance, please try again later", UIAlertControllerStyle.Alert);
                    apicontroller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(apicontroller, true, null);

                    //new UIAlertView("API Error", $"Server under maintenance, please try again later", null, "OK", null).Show();
                    return;
                }

                json_string = response.Content.ReadAsStringAsync().Result;
                actions     = JsonConvert.DeserializeObject <List <KpiAction> >(json_string);

                if (actions == null)
                {
                    //Error Alert
                    var deserializationcontroller = UIAlertController.Create("Deserialization Error", $"JSON Returned: \"{json_string}\"", UIAlertControllerStyle.Alert);
                    deserializationcontroller.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                    PresentViewController(deserializationcontroller, true, null);

                    //new UIAlertView("Deserialization Error", $"JSON Returned: \"{json_string}\"", null, "OK", null).Show();
                    return;
                }

                nextPage.actions = new List <KpiAction>();
                nextPage.actions = actions;

                this.NavigationController.PushViewController(nextPage, true); //This code changes the view
            }

            _table.UserInteractionEnabled = true;
        }