public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            BNRItem item = BNRItemStore.allItems[indexPath.Row];

            HomepwnerItemCell cell = TableView.DequeueReusableCell("HomepwnerItemCell") as HomepwnerItemCell;

            // Configure the cell
            cell.nametextField.Text = item.itemName;

            // Handle text field return key pressed
            cell.nametextField.ShouldReturn += ((textField) => {
                textField.ResignFirstResponder();
                item.itemName = textField.Text;
                BNRItemStore.updateDBItem(item);
                return(true);
            });

            cell.dateField.Text = item.dateCreated.ToShortDateString();
            // Store the index to this item in the button so we can get it in the handler
            cell.dateField.Tag = indexPath.Row;
            if (cell.dateField.InputView == null)
            {
                cell.dateField.InputView = GetDatePickerView(cell.dateField);
            }

            return(cell);
        }
        // Set up and display the date picker and handle when done picking date
        UIView GetDatePickerView(UITextField dateField)
        {
            var dpSuperView = new UIView(new RectangleF(0, 0, this.View.Frame.Width, 240));

            dpSuperView.BackgroundColor = UIColor.White;


            var dp = new UIDatePicker(new RectangleF(0, 40, 0, 0));

            dp.Mode = UIDatePickerMode.Date;
            dpSuperView.AddSubview(dp);

            var doneButton = new UIButton(new RectangleF((this.View.Frame.Size.Width / 2) - 50, 0, 100, 50));

            doneButton.SetTitle("Done", UIControlState.Normal);
            doneButton.SetTitleColor(this.View.TintColor, UIControlState.Normal);
            dpSuperView.AddSubview(doneButton);

            BNRItem item = BNRItemStore.allItems[dateField.Tag];

            dp.Date = item.dateCreated;

            dp.ValueChanged += (sender2, e2) => {
                DateTime newDate = dp.Date;
                dateField.Text   = newDate.ToLocalTime().ToShortDateString();
                item.dateCreated = newDate.ToLocalTime();
                BNRItemStore.updateDBItem(item);
            };

            doneButton.TouchUpInside += (object sender, EventArgs e) => {
                dateField.EndEditing(true);
            };

            return(dpSuperView);
        }
        public static void updateDBItem(BNRItem item)
        {
            string           dbPath = GetDBPath();
            SQLiteConnection db;

            db = new SQLiteConnection(dbPath);
            db.Update(item);
            db.Close();
        }
        public static void RemoveItem(BNRItem p)
        {
            allItems.Remove(p);
            string           dbPath = GetDBPath();
            SQLiteConnection db;

            db = new SQLiteConnection(dbPath);
            db.Delete(p);
            db.Close();
        }
 // Handles delete item
 public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
 {
     //base.CommitEditingStyle(tableView, editingStyle, indexPath);
     if (editingStyle == UITableViewCellEditingStyle.Delete)
     {
         BNRItem itemToRemove = BNRItemStore.allItems[indexPath.Row];
         BNRItemStore.RemoveItem(itemToRemove);
         NSIndexPath[] indexPaths = new NSIndexPath[] { indexPath };
         this.TableView.DeleteRows(indexPaths, UITableViewRowAnimation.Automatic);
         this.TableView.ReloadData();
     }
 }
        public static void moveItem(int fromIndex, int toIndex)
        {
            if (fromIndex == toIndex)
            {
                return;
            }
            BNRItem p = allItems[fromIndex];

            allItems.Remove(p);
            allItems.Insert(toIndex, p);

            // Computing a new ordering value for the object that was moved
            double lowerBound = 0.0;

            // Is there an objetc before it in the array?
            if (toIndex > 0)
            {
                lowerBound = allItems[toIndex - 1].orderingValue;
            }
            else
            {
                lowerBound = allItems[1].orderingValue - 2.0;
            }

            double upperBound = 0.0;

            // Is there an object after it in the array?
            if (toIndex < allItems.Count - 1)
            {
                upperBound = allItems[toIndex + 1].orderingValue;
            }
            else
            {
                upperBound = allItems[toIndex - 1].orderingValue + 2.0;
            }

            double newOrderValue = (lowerBound + upperBound) / 2.0;

            Console.WriteLine("Moving to order {0}", newOrderValue);
            p.orderingValue = newOrderValue;

            updateDBItem(p);
        }
        public static BNRItem CreateItem()
        {
            BNRItem p = new BNRItem();

            if (allItems.Count == 0)
            {
                p.orderingValue = 1;
            }
            else
            {
                p.orderingValue = allItems[allItems.Count - 1].orderingValue + 1.0;
            }
            allItems.Add(p);

            string           dbPath = GetDBPath();
            SQLiteConnection db;

            db = new SQLiteConnection(dbPath);
            db.Insert(p);
            return(p);
        }