public void OpenStringList(object sender, EventArgs e)
        {
            UIButton btnBankNoSearch = (UIButton)sender;
            ScreenUtils scnUtils = new ScreenUtils ();
            scnUtils.GetAbsolutePosition (btnBankNoSearch);
            float iTop = scnUtils.GetPositionTop ();
            float iLeft = scnUtils.GetPositionLeft ();
            int iBtnTagId = btnBankNoSearch.Tag;
            int iPwrIdRow = iBtnTagId / iEquipmentStringSearchTagId;
            int iStringRow = iBtnTagId - (iPwrIdRow * iEquipmentStringSearchTagId);
            int iSectionCounterTagId = iEquipmentRowSectionCounterTagId * iPwrIdRow  + iStringRow;
            UILabel hfSectionCounter = (UILabel)View.ViewWithTag (iSectionCounterTagId);
            int iSectionCounterId = Convert.ToInt32 (hfSectionCounter.Text);

            clsTabletDB.ITPValidHierarchy ITPHierarchy = new clsTabletDB.ITPValidHierarchy();
            string[] sSolarStringNos = ITPHierarchy.GetValidHierarchy(7);

            //Create a list and convert the string array to the list. Why the system cannot take a simple string array is beyond me!!!
            List<string> listStringNo = new List<string> ();
            Array.ForEach (sSolarStringNos, value => listStringNo.Add (value.ToString ()));

            TableViewSource tabdata = new TableViewSource (listStringNo, true);
            tabdata.SetFont("Verdana",10f);
            UITableView cmbStringNo = new UITableView ();

            //If the bottom of the frame would be outside the main content frame make it go upwards instead of downwards
            UILabel hfContentHeight = (UILabel)View.ViewWithTag (3);
            int iContentHeight = Convert.ToInt32 (hfContentHeight.Text);
            if (iTop + 190f > (float)iContentHeight)
            {
                cmbStringNo.Frame = new RectangleF(iLeft, iTop - 190f, 90f, 200f);
            }
            else
            {
                cmbStringNo.Frame = new RectangleF(iLeft, iTop, 90f, 200f);
            }

            tabdata.SetParent(cmbStringNo);
            tabdata.SetUpdateFieldType("UITextField");
            UITextField lblVwUpdate = (UITextField)View.ViewWithTag (iEquipmentStringTagId * (iPwrIdRow) + (iStringRow));
            tabdata.SetTextFieldToUpdate(lblVwUpdate);
            UIView vwUnsaved = (UIView)View.ViewWithTag (60);
            tabdata.SetUnsavedChangesView(vwUnsaved);
            tabdata.SetShowUnsavedOnChange(true);
            //Also set the section flag to 1 that it has changed and the overall flag that it has changed
            UILabel lblUnsavedFlag = (UILabel)View.ViewWithTag (80);
            tabdata.SetUnsavedChangesHiddenLabel(lblUnsavedFlag);
            UILabel lblUnsavedSectionFlag = (UILabel)View.ViewWithTag ((iSectionCounterId + 1) * iSectionStatusTagId);
            tabdata.SetUnsavedChangesSectionHiddenLabel(lblUnsavedSectionFlag);

            cmbStringNo.Source = tabdata;
            iUtils.SESTable thistable = new iUtils.SESTable();
            string sSelectedValue = lblVwUpdate.Text;
            thistable.SetTableSelectedText(cmbStringNo, sSelectedValue, sSolarStringNos, true);

            //Get the main scroll view
            UIScrollView scrollVw = (UIScrollView)View.ViewWithTag (2);
            scrollVw.AddSubview(cmbStringNo);
        }
        public void OpenSearchView(object sender, EventArgs e, int iSearchType)
        {
            UIButton btnSearch = (UIButton)sender;
            ScreenUtils scnUtils = new ScreenUtils ();
            scnUtils.GetAbsolutePosition (btnSearch);
            float iTop = scnUtils.GetPositionTop ();
            float iLeft = scnUtils.GetPositionLeft ();
            int iBtnTagId = btnSearch.Tag;
            int iSearchTagTypeId = -1;
            string sType = "";
            bool bBuildSearchView = false;

            switch (iSearchType)
            {
                case 1: //Floor
                    iSearchTagTypeId = iEquipmentFloorSearchTagId;
                    sType = "floor";
                    break;
                case 2: //Suite
                    iSearchTagTypeId = iEquipmentSuiteSearchTagId;
                    sType = "suite";
                    break;
                case 3: //Rack
                    iSearchTagTypeId = iEquipmentRackSearchTagId;
                    sType = "rack";
                    break;
                case 4: //SubRack
                    iSearchTagTypeId = iEquipmentSubRackSearchTagId;
                    sType = "subrack";
                    break;
                case 5: //Position
                    iSearchTagTypeId = iEquipmentPositionSearchTagId;
                    sType = "position";
                    break;
                case 7: //String
                    iSearchTagTypeId = iEquipmentStringSearchTagId;
                    sType = "solar string";
                    break;

            }
            int iPwrIdRow = iBtnTagId / iSearchTagTypeId;
            int iStringRow = iBtnTagId - (iPwrIdRow * iSearchTagTypeId);
            int iSectionCounterTagId = iEquipmentRowSectionCounterTagId * iPwrIdRow + iStringRow;
            UILabel hfSectionCounter = (UILabel)View.ViewWithTag (iSectionCounterTagId);
            int iSectionCounterId = Convert.ToInt32 (hfSectionCounter.Text);

            //Now show the search box and button
            if (m_vwSearch == null)
            {
                UIView vwSearch = new UIView ();
                m_vwSearch = vwSearch;
                bBuildSearchView = true;
            }

            //If the bottom of the frame would be outside the main content frame make it go upwards instead of downwards
            UILabel hfContentHeight = (UILabel)View.ViewWithTag (3);
            int iContentHeight = Convert.ToInt32 (hfContentHeight.Text);
            if (iTop + 190f > (float)iContentHeight)
            {
                m_vwSearch.Frame = new RectangleF (iLeft, iTop - 190f, 400f, 300f);
            }
            else
            {
                m_vwSearch.Frame = new RectangleF (iLeft, iTop, 400f, 300f);
            }
            m_vwSearch.Layer.BorderWidth = 1f;
            m_vwSearch.BackgroundColor = UIColor.FromRGBA (238, 238, 238, 255);

            if (bBuildSearchView)
            {
                UILabel lblSearch = new UILabel ();
                lblSearch.Frame = new RectangleF (2f, 2f, 396f, 40f);
                lblSearch.Text = "Show " + sType + " items containing :";
                lblSearch.BackgroundColor = UIColor.FromRGBA (238, 238, 238, 255);
                lblSearch.Tag = iSearchLabelTagId;
                m_vwSearch.AddSubview (lblSearch);

                UILabel hfSearch = new UILabel ();
                hfSearch.Text = iSearchType.ToString();
                hfSearch.Tag = iSearchHiddenLabelTagId;
                hfSearch.Hidden = true;
                m_vwSearch.AddSubview (hfSearch);

                UILabel hfPwrIdRow = new UILabel ();
                hfPwrIdRow.Text = iPwrIdRow.ToString();
                hfPwrIdRow.Tag = iPwrIdRowHiddenLabelTagId;
                hfPwrIdRow.Hidden = true;
                m_vwSearch.AddSubview (hfPwrIdRow);

                UILabel hfStringRow = new UILabel ();
                hfStringRow.Text = iStringRow.ToString();
                hfStringRow.Tag = iStringRowHiddenLabelTagId;
                hfStringRow.Hidden = true;
                m_vwSearch.AddSubview (hfStringRow);

                UITextField txtSearch = new UITextField ();
                txtSearch.Frame = new RectangleF (2f, 44f, 198f, 40f);
                txtSearch.BackgroundColor = UIColor.FromRGBA (255, 255, 255, 255);
                txtSearch.Tag = iSearchTextTagId;
                txtSearch.AutocorrectionType = UITextAutocorrectionType.No;
                txtSearch.KeyboardType = UIKeyboardType.NumbersAndPunctuation;
                m_vwSearch.AddSubview (txtSearch);

                UIButton btnSearching = UIButton.FromType (UIButtonType.RoundedRect);
                btnSearching.Frame = new RectangleF (210f, 44f, 180f, 40f);
                btnSearching.SetTitle ("Search", UIControlState.Normal);
                btnSearching.Font = UIFont.FromName ("Verdana", 12f);
                btnSearching.Layer.BorderColor = UIColor.Black.CGColor;
                btnSearching.Tag = iSearchButtonTagId;
                m_btnSearching = btnSearching;
                m_btnSearching.TouchUpInside += (sender2,e2) => {
                    OpenItemsList (sender, e, m_vwSearch,iSectionCounterId);};
            }
            else
            {
                UIButton btnSearching = (UIButton)View.ViewWithTag (iSearchButtonTagId);
                UILabel lblSearching = (UILabel)View.ViewWithTag (iSearchLabelTagId);
                lblSearching.Text = "Show " + sType + " items containing :";
                UILabel hfSearching = (UILabel)View.ViewWithTag (iSearchHiddenLabelTagId);
                hfSearching.Text = iSearchType.ToString();
                UILabel hfPwrIdRow = (UILabel)View.ViewWithTag (iPwrIdRowHiddenLabelTagId);
                hfPwrIdRow.Text = iPwrIdRow.ToString();
                UILabel hfStringRow = (UILabel)View.ViewWithTag (iStringRowHiddenLabelTagId);
                hfStringRow.Text = iStringRow.ToString();
                UITextField txtSearching = (UITextField)View.ViewWithTag (iSearchTextTagId);
                txtSearching.Text = "";
                m_btnSearching = btnSearching;
                m_cmbSearch.Hidden = true;
            }

            if (bBuildSearchView)
            {
                m_vwSearch.AddSubview (m_btnSearching);

                //Get the main scroll view
                UIScrollView scrollVw = (UIScrollView)View.ViewWithTag (2);
                scrollVw.AddSubview (m_vwSearch);
            }
            else
            {
                m_vwSearch.Hidden = false;
            }
        }
        public void OpenMakeList(object sender, EventArgs e)
        {
            UIButton btnMakeSearch = (UIButton)sender;
            ScreenUtils scnUtils = new ScreenUtils ();
            scnUtils.GetAbsolutePosition (btnMakeSearch);
            float iTop = scnUtils.GetPositionTop ();
            float iLeft = scnUtils.GetPositionLeft ();
            int iBtnTagId = btnMakeSearch.Tag;
            int iPwrIdRow = iBtnTagId / iEquipmentMakeSearchTagId;
            int iStringRow = iBtnTagId - (iPwrIdRow * iEquipmentMakeSearchTagId);
            int iSectionCounterTagId = iEquipmentRowSectionCounterTagId * iPwrIdRow + iStringRow;
            UILabel hfSectionCounter = (UILabel)View.ViewWithTag (iSectionCounterTagId);
            int iSectionCounterId = Convert.ToInt32(hfSectionCounter.Text);

            //Create a list and convert the string array to the list. Why the system cannot take a simple string arary is beyond me!!!
            UILabel lblEquipmentType = (UILabel)View.ViewWithTag (iEquipmentTypeTagId * (iPwrIdRow) + (iStringRow));
            int iEquipmentType = Convert.ToInt32(lblEquipmentType.Text);

            List<string> mylist = new List<string> ();
            clsTabletDB.ITPInventory ITPInventory = new clsTabletDB.ITPInventory ();
            string[] sMakes;
            switch(iEquipmentType)
            {
                case 3:
                    sMakes = ITPInventory.GetRackMakes ();
                    m_sRackMakes = sMakes;
                    Array.ForEach (m_sRackMakes, value => mylist.Add (value.ToString ()));
                    break;
                case 4:
                    sMakes = ITPInventory.GetSubRackMakes ();
                    m_sSubRackMakes = sMakes;
                    Array.ForEach (m_sSubRackMakes, value => mylist.Add (value.ToString ()));
                    break;
                case 5:
                    sMakes = ITPInventory.GetPositionMakes ();
                    m_sPositionMakes = sMakes;
                    Array.ForEach (m_sPositionMakes, value => mylist.Add (value.ToString ()));
                    break;
                case 7:
                    sMakes = ITPInventory.GetSolarStringMakes ();
                    m_sSolarStringMakes = sMakes;
                    Array.ForEach (m_sSolarStringMakes, value => mylist.Add (value.ToString ()));
                    break;
                default:
                    sMakes = ITPInventory.GetPositionMakes ();
                    m_sPositionMakes = sMakes;
                    Array.ForEach (m_sPositionMakes, value => mylist.Add (value.ToString ()));
                    break;
            }

            TableViewSource tabdata = new TableViewSource (mylist, true);
            tabdata.SetFont("Verdana",10f);
            UITableView cmbMake = new UITableView ();

            //If the bottom of the frame would be outside the main content frame make it go upwards instead of downwards
            UILabel hfContentHeight = (UILabel)View.ViewWithTag (3);
            int iContentHeight = Convert.ToInt32 (hfContentHeight.Text);
            if (iTop + 190f > (float)iContentHeight)
            {
                cmbMake.Frame = new RectangleF(iLeft, iTop - 190f, 290f, 200f);
            }
            else
            {
                cmbMake.Frame = new RectangleF(iLeft, iTop, 290f, 200f);
            }

            tabdata.SetParent(cmbMake);
            tabdata.SetUpdateFieldType("UILabel");
            UILabel txtVwUpdate = (UILabel)View.ViewWithTag (iEquipmentMakeTagId * (iPwrIdRow) + (iStringRow));
            tabdata.SetLabelViewToUpdate(txtVwUpdate);
            UIView vwUnsaved = (UIView)View.ViewWithTag (60);
            tabdata.SetUnsavedChangesView(vwUnsaved);
            tabdata.SetShowUnsavedOnChange(true);
            //Also set the section flag to 1 that it has changed and the overall flag that it has changed
            UILabel lblUnsavedFlag = (UILabel)View.ViewWithTag (80);
            tabdata.SetUnsavedChangesHiddenLabel(lblUnsavedFlag);
            UIButton btnSectionSave = (UIButton)View.ViewWithTag ((iSectionCounterId + 1) * iSaveSectionBtnTagId);
            tabdata.SetSectionSaveButton(btnSectionSave);
            UILabel lblUnsavedSectionFlag = (UILabel)View.ViewWithTag ((iSectionCounterId + 1) * iSectionStatusTagId);
            tabdata.SetUnsavedChangesSectionHiddenLabel(lblUnsavedSectionFlag);
            UILabel lblViewModel = (UILabel)View.ViewWithTag (iEquipmentModelTagId * (iPwrIdRow) + (iStringRow));
            tabdata.SetMakePostUpdate(1, lblViewModel);

            cmbMake.Source = tabdata;
            iUtils.SESTable thistable = new iUtils.SESTable();
            string sSelectedValue = txtVwUpdate.Text;
            switch(iEquipmentType)
            {
                case 3:
                    thistable.SetTableSelectedText(cmbMake, sSelectedValue, m_sRackMakes, true);
                    break;
                case 4:
                    thistable.SetTableSelectedText(cmbMake, sSelectedValue, m_sSubRackMakes, true);
                    break;
                case 5:
                    thistable.SetTableSelectedText(cmbMake, sSelectedValue, m_sPositionMakes, true);
                    break;
                case 7:
                    thistable.SetTableSelectedText(cmbMake, sSelectedValue, m_sSolarStringMakes, true);
                    break;
                default:
                    thistable.SetTableSelectedText(cmbMake, sSelectedValue, m_sPositionMakes, true);
                    break;
            }

            //Get the main scroll view
            UIScrollView scrollVw = (UIScrollView)View.ViewWithTag (2);
            scrollVw.AddSubview(cmbMake);
        }
        public void OpenModelList(object sender, EventArgs e)
        {
            UIButton btnModelSearch = (UIButton)sender;
            ScreenUtils scnUtils = new ScreenUtils ();
            scnUtils.GetAbsolutePosition (btnModelSearch);
            float iTop = scnUtils.GetPositionTop ();
            float iLeft = scnUtils.GetPositionLeft ();
            int iBtnTagId = btnModelSearch.Tag;
            int iPwrIdRow = iBtnTagId / iEquipmentModelSearchTagId;
            int iStringRow = iBtnTagId - (iPwrIdRow * iEquipmentModelSearchTagId);
            int iSectionCounterTagId = iEquipmentRowSectionCounterTagId * iPwrIdRow + iStringRow;
            UILabel hfSectionCounter = (UILabel)View.ViewWithTag (iSectionCounterTagId);
            int iSectionCounterId = Convert.ToInt32 (hfSectionCounter.Text);
            UILabel lblSupplier = (UILabel)View.ViewWithTag (iEquipmentMakeTagId * (iPwrIdRow) + (iStringRow));
            string sSupplier = lblSupplier.Text;

            if (sSupplier == "")
            {
                iUtils.AlertBox alert = new iUtils.AlertBox ();
                alert.CreateErrorAlertDialog ("You must select a make before you can select a model");
                return;
            }

            UILabel lblEquipmentType = (UILabel)View.ViewWithTag (iEquipmentTypeTagId * (iPwrIdRow) + (iStringRow));
            int iEquipmentType = Convert.ToInt32(lblEquipmentType.Text);

            //Create a list and convert the string array to the list. Why the system cannot take a simple string array is beyond me!!!
            List<string> listModel = new List<string> ();
            clsTabletDB.ITPInventory ITPInventory = new clsTabletDB.ITPInventory ();
            string[] sModels;
            switch(iEquipmentType)
            {
                case 3:
                    sModels = ITPInventory.GetRackModels (sSupplier);
                    m_sRackModels = sModels;
                    Array.ForEach (m_sRackModels, value => listModel.Add (value.ToString ()));
                    break;
                case 4:
                    sModels = ITPInventory.GetSubRackModels (sSupplier);
                    m_sSubRackModels = sModels;
                    Array.ForEach (m_sSubRackModels, value => listModel.Add (value.ToString ()));
                    break;
                case 5:
                    sModels = ITPInventory.GetPositionModels (sSupplier);
                    m_sPositionModels = sModels;
                    Array.ForEach (m_sPositionModels, value => listModel.Add (value.ToString ()));
                    break;
                case 7:
                    sModels = ITPInventory.GetSolarStringModels (sSupplier);
                    m_sSolarStringModels = sModels;
                    Array.ForEach (m_sSolarStringModels, value => listModel.Add (value.ToString ()));
                    break;
                default:
                    sModels = ITPInventory.GetPositionModels (sSupplier);
                    m_sPositionModels = sModels;
                    Array.ForEach (m_sPositionModels, value => listModel.Add (value.ToString ()));
                    break;
            }

            TableViewSource tabdata = new TableViewSource (listModel, true);
            tabdata.SetFont("Verdana",10f);
            UITableView cmbModel = new UITableView ();

            //If the bottom of the frame would be outside the main content frame make it go upwards instead of downwards
            UILabel hfContentHeight = (UILabel)View.ViewWithTag (3);
            int iContentHeight = Convert.ToInt32 (hfContentHeight.Text);
            if (iTop + 190f > (float)iContentHeight)
            {
                if (iLeft + 290f > 1000f)
                {
                    cmbModel.Frame = new RectangleF(iLeft - 300f, iTop - 190f, 290f, 200f);
                }
                else
                {
                    cmbModel.Frame = new RectangleF(iLeft, iTop - 190f, 290f, 200f);
                }
            }
            else
            {
                if (iLeft + 290f > 1000f)
                {
                    cmbModel.Frame = new RectangleF(iLeft - 300f, iTop, 290f, 200f);
                }
                else
                {
                    cmbModel.Frame = new RectangleF(iLeft, iTop, 290f, 200f);
                }
            }

            tabdata.SetParent(cmbModel);
            tabdata.SetUpdateFieldType("UILabel");
            UILabel lblVwUpdate = (UILabel)View.ViewWithTag (iEquipmentModelTagId * (iPwrIdRow) + (iStringRow));
            tabdata.SetLabelViewToUpdate(lblVwUpdate);
            UIView vwUnsaved = (UIView)View.ViewWithTag (60);
            tabdata.SetUnsavedChangesView(vwUnsaved);
            tabdata.SetShowUnsavedOnChange(true);
            UILabel hfRowStatus = (UILabel)View.ViewWithTag (iEquipmentRowStatusTagId * (iPwrIdRow) + (iStringRow));
            UILabel lblSPN = (UILabel)View.ViewWithTag (iEquipmentSPNHiddenTagId * (iPwrIdRow) + (iStringRow));
            tabdata.SetModelPostUpdate(6, hfRowStatus, lblSPN, sSupplier); //Here the 6 refers to the post update index and NOT batteries as the equipment type

            //Also set the section flag to 1 that it has changed and the overall flag that it has changed
            UILabel lblUnsavedFlag = (UILabel)View.ViewWithTag (80);
            tabdata.SetUnsavedChangesHiddenLabel(lblUnsavedFlag);
            UIButton btnSectionSave = (UIButton)View.ViewWithTag ((iSectionCounterId + 1) * iSaveSectionBtnTagId);
            tabdata.SetSectionSaveButton(btnSectionSave);
            UILabel lblUnsavedSectionFlag = (UILabel)View.ViewWithTag ((iSectionCounterId + 1) * iSectionStatusTagId);
            tabdata.SetUnsavedChangesSectionHiddenLabel(lblUnsavedSectionFlag);

            cmbModel.Source = tabdata;
            iUtils.SESTable thistable = new iUtils.SESTable();
            string sSelectedValue = lblVwUpdate.Text;
            switch(iEquipmentType)
            {
                case 3:
                    thistable.SetTableSelectedText(cmbModel, sSelectedValue, m_sRackModels, true);
                    break;
                case 4:
                    thistable.SetTableSelectedText(cmbModel, sSelectedValue, m_sSubRackModels, true);
                    break;
                case 5:
                    thistable.SetTableSelectedText(cmbModel, sSelectedValue, m_sPositionModels, true);
                    break;
                case 7:
                    thistable.SetTableSelectedText(cmbModel, sSelectedValue, m_sSolarStringModels, true);
                    break;
                default:
                    thistable.SetTableSelectedText(cmbModel, sSelectedValue, m_sPositionModels, true);
                    break;
            }

            //Get the main scroll view
            UIScrollView scrollVw = (UIScrollView)View.ViewWithTag (2);
            scrollVw.AddSubview(cmbModel);
        }
        public void OpenITP(object sender, EventArgs e)
        {
            //Show the progress indicator and position at top left of button
            UIButton btnOpen = (UIButton)sender;
            prog.SetActivityIndicatorTitle("Opening ITP");
            ScreenUtils scnUtils = new ScreenUtils();
            scnUtils.GetAbsolutePosition(btnOpen);
            UIScrollView scrollVw = (UIScrollView)View.ViewWithTag (2);
            PointF layoutOffset = scrollVw.ContentOffset;
            float iVertOffset = layoutOffset.Y;
            float iTop = scnUtils.GetPositionTop() - iVertOffset;
            float iLeft = scnUtils.GetPositionLeft();
            prog.SetActivityIndicatorPosition(iLeft,iTop);
            prog.ShowActivityIndicator();
            prog.StartAnimating();

            //Disable all other buttons
            DisableButtons();

            taskA = new Task (() => OpenITPTask (sender, e));
            taskA.Start ();
        }