public RCModelListView (bool isDataEditable)
		{

            InitializeComponent();

            vm = new RCModelViewModel();
            BindingContext = vm;

            // Load the Activity Log report into ListView class.
            vm.LoadRCModels();

            _isDataEditable = isDataEditable;
            App.selectedItemName = null;
            App.selectedItemID = 0;
            //
            if (_isDataEditable)
            {
                ToolbarItem tbi = null;
                if (Device.OS == TargetPlatform.iOS)
                {
                    tbi = new ToolbarItem("+", null, () =>
                    {
                        var RCItem = new InventoryItemList();
                        // create a new details view with the item
                        var view = new RCInventoryDetailsView(RCItem, App.ItemCategory_MODEL);
                        //// tell the navigator to show the new view
                        Navigation.PushAsync(view);
                    }, 0, 0);
                }
                if (Device.OS == TargetPlatform.Android)
                { // BUG: Android doesn't support the icon being null
                    tbi = new ToolbarItem("+", "plus", () =>
                    {
                        var RCItem = new InventoryItemList();
                    // create a new details view with the item
                    var view = new RCInventoryDetailsView(RCItem, App.ItemCategory_MODEL);
                    //// tell the navigator to show the new view
                    Navigation.PushAsync(view);
                    }, 0, 0);
                }
                //
                ToolbarItems.Add(tbi);
            }
            //
            lblNoOfModels.Text = "No. of Models: " + vm.RCModelLV.Count.ToString();
        }
        /// <summary>
        /// Initializes a new instance of class.
        /// </summary>
        /// <param name="model">Instance we want to display</param>
        public RCInventoryDetailsView(InventoryItemList model, string sItemCategory)
        {
            // Bind our BindingContext
            Model = model;

            NavigationPage.SetHasNavigationBar(this, true);

            InitializeComponent();
            // If a specific Item Category is passed into screen then set as category of item being entered.
            if (sItemCategory != "")
            { Model.ItemCategory = sItemCategory; }
            switch (sItemCategory)
            {
                case App.ItemCategory_MODEL:
                    labelItemType.Text = "Model Type";
                    IEnumerable<ActivityLog> ActivityLogs = App.Database.GetActivityRecs(Model.ID);
                    int iTotalFlightTimeInSeconds = 0;
                    foreach (ActivityLog ALog in ActivityLogs)
                    {
                        if (ALog.ActivityType == "TIME TRACKING REPORT")
                        {
                            iTotalFlightTimeInSeconds += ALog.LogTimeInSeconds;
                        }
                    }
                    labelNoOfFlights.Text = iTotalFlightTimeInSeconds.ToString();
                    lblBatteryNo.IsVisible = false;
                    EntryBatteryNo.IsVisible = false;
                    //
                    lblDefaultTime.IsVisible = true;
                    EntryMinutes.IsVisible = true;
                    lblColon.IsVisible = true;
                    EntrySeconds.IsVisible = true;
                    break;
                case App.ItemCategory_BATTERY:
                    labelItemType.IsVisible = false;
                    entryItemType.IsVisible = false;
                    lblBatteryNo.IsVisible = true;
                    EntryBatteryNo.IsVisible = true;
                    lblDefaultTime.IsVisible = false;
                    EntryMinutes.IsVisible = false;
                    lblColon.IsVisible = false;
                    EntrySeconds.IsVisible = false;
                    break;
            }

            //
            if (Model.PurchaseDate == DateTime.MinValue)
            { DTPicker.Date = DateTime.Now; }
            else { DTPicker.Date = Model.PurchaseDate; }
            //
            // Save Button
            btnSaveSC.Clicked += (sender, e) =>
            {
                //var todoItem = (TodoItem)BindingContext;
                //
                Model.PurchaseDate = DTPicker.Date;
                InventoryItem IIRec = TransferToInventoryItemRec(Model);
                Model.ID = App.Database.SaveItem(IIRec);
                Navigation.PopAsync();
            };
            //
            // Cancel Button
            btnCancelSC.Clicked += (sender, e) =>
            {
                Navigation.PopAsync();
            };
            //
            // Delete Button
            btnDeleteSC.Clicked += (sender, e) =>
            {
                App.Database.DeleteItem(Model.ID);
                Navigation.PopAsync();
            };
            //
            // No of Flights Button
            btnNoOfFlights.Clicked += (sender, e) =>
            {
                // create a new details view with the item
                var view = new ActivityLogListView(Model.ID);
                //// tell the navigator to show the new view
                Navigation.PushAsync(view);
            };
            //
            // List Media Button
            btnGallery.Clicked += (sender, e) =>
            {
                Model.PurchaseDate = DTPicker.Date;
                InventoryItem IIRec = TransferToInventoryItemRec(Model);
                Model.ID = App.Database.SaveItem(IIRec);
                // create a new details view with the item
                var view = new MediaListView(Model.ID);
                //// tell the navigator to show the new view
                Navigation.PushAsync(view);
            };
            //
            // Display Item Name list
            entryItemType.Focused += (sender, e) =>
            {
                _sCurrentListType = "ITEMTYPE";
                // create a new details view with the item
                var view = new ListDataListView(_sCurrentListType, true);
                //// tell the navigator to show the new view
                Navigation.PushAsync(view);
            };
            //
            // Display Manufacturer list
            btnListManuf.Clicked += (sender, e) =>
            {
                _sCurrentListType = "MANUFACTURER";
                // create a new details view with the item
                var view = new ListDataListView(_sCurrentListType, true);
                //// tell the navigator to show the new view
                Navigation.PushAsync(view);
            };
            //
            //LoadItemNamePicker();
        }
 private InventoryItem TransferToInventoryItemRec(InventoryItemList IIList)
 {
     InventoryItem IIRec = new InventoryItem();
     //
     IIRec.ID = IIList.ID;
     IIRec.ItemCategory = IIList.ItemCategory;
     IIRec.ItemName = IIList.ItemName;
     IIRec.ItemNumber = IIList.ItemNumber;
     IIRec.ItemType = IIList.ItemType;
     IIRec.Manufacturer = IIList.Manufacturer;
     IIRec.Notes = IIList.Notes;
     IIRec.PurchaseDate = IIList.PurchaseDate;
     IIRec.PurchasePrice = IIList.PurchasePrice;
     IIRec.RetailPrice = IIList.RetailPrice;
     //
     return IIRec;
 }
        public void LoadRCModels()
        {
            //AddActivityLogRecs();
            RCModelLV.Clear();

            IEnumerable<InventoryItem> RCModels = App.Database.GetAllItems(App.ItemCategory_MODEL);
            
            foreach (var RCModel in RCModels)
            {
                InventoryItemList MList = new InventoryItemList();
                MList.ID = RCModel.ID;
                MList.ItemCategory = RCModel.ItemCategory;
                MList.ItemType = RCModel.ItemType;
                MList.ItemName = RCModel.ItemName;
                MList.ItemNumber = RCModel.ItemNumber;
                MList.Manufacturer = RCModel.Manufacturer;
                MList.ItemFilename = null;
                if (MList.ID != 0)
                {
                    IEnumerable<InventoryMedia> IMList = App.Database.GetMediaRecs(MList.ID);
                    foreach (InventoryMedia IMRec in IMList)
                    {
                        // Load Model Name by looking up the ItemID in the InventoryItem table.
                        MList.ItemFilename = IMRec.Filename;
                        break;
                    }
                }
                IEnumerable<ActivityLog> ActivityLogs = App.Database.GetActivityRecs(MList.ID);
                MList.NoOfFlights = ActivityLogs.Count<ActivityLog>().ToString();
                //
                int iTotalFlightTimeInSeconds = 0;
                foreach (ActivityLog ALog in ActivityLogs)
                {
                    if (ALog.ActivityType == "TIME TRACKING REPORT")
                    {
                        iTotalFlightTimeInSeconds += ALog.LogTimeInSeconds;
                    }
                }
                if (iTotalFlightTimeInSeconds != 0)
                {
                    MList.TotalFlightTimeInSeconds = iTotalFlightTimeInSeconds.ToString();
                    //
                    // MM = 550 / 60 
                    int iTotalHH = 0;
                    int iTotalMM = iTotalFlightTimeInSeconds / 60;
                    int iTotalSS = iTotalFlightTimeInSeconds % 60;
                    if (iTotalMM > 60)
                    {
                        iTotalHH = iTotalMM / 60;
                        iTotalMM = iTotalMM % 60;
                    }
                    MList.TotalFlightTimeHHMMSS = "";
                    if (iTotalHH != 0) MList.TotalFlightTimeHHMMSS += iTotalHH.ToString() + ":";
                    MList.TotalFlightTimeHHMMSS += iTotalMM.ToString() + ":";
                    MList.TotalFlightTimeHHMMSS += iTotalSS.ToString();
                }
                //
                RCModelLV.Add(MList);
            }

        }