// This returns all items by sql query private List <GroceriesItem> SelectItems(string sql) { General.DB.ConnectSafe(); DataTable t = General.DB.Query(sql); if (t != null) { List <GroceriesItem> list = new List <GroceriesItem>(t.Count); foreach (DataTableRow r in t) { list.Add(GroceriesItem.FromDataRow(r)); } General.DB.Disconnect(); return(list); } else { // Failed! General.DB.Disconnect(); return(null); } }
// Accept pressed private void acceptbutton_Click(object sender, EventArgs e) { GroceriesItem newitem = new GroceriesItem(); if(itemname.Text.Length == 0) { PlayFailSound(); itemname.Focus(); return; } newitem.name = itemname.Text; newitem.list = selectedlist; if(long.TryParse(itemcount.Text, out newitem.count)) { General.Groceries.AddOrUpdateItem(newitem, true); General.MainWindow.GroceriesPanel.SelectedList = selectedlist; General.MainWindow.ShowTaggedPanel("groceries"); } else { PlayFailSound(); itemcount.Focus(); } }
// Accept pressed private void acceptbutton_Click(object sender, EventArgs e) { GroceriesItem newitem = new GroceriesItem(); if (itemname.Text.Length == 0) { PlayFailSound(); itemname.Focus(); return; } newitem.name = itemname.Text; newitem.list = selectedlist; if (long.TryParse(itemcount.Text, out newitem.count)) { General.Groceries.AddOrUpdateItem(newitem, true); General.MainWindow.GroceriesPanel.SelectedList = selectedlist; General.MainWindow.ShowTaggedPanel("groceries"); } else { PlayFailSound(); itemcount.Focus(); } }
// This reads from a data row public static GroceriesItem FromDataRow(DataTableRow r) { GroceriesItem i = new GroceriesItem(); i.name = r.GetString("name"); i.count = r.GetLong("count"); i.list = r.GetInt("list"); return i; }
// This reads from a data row public static GroceriesItem FromDataRow(DataTableRow r) { GroceriesItem i = new GroceriesItem(); i.name = r.GetString("name"); i.count = r.GetLong("count"); i.list = r.GetInt("list"); return(i); }
// A quick item is clicked private void quickitem_Click(object sender, EventArgs e) { DisplayButton quickitembutton = (DisplayButton)sender; int index = GetIndexByName(quickitembutton.Text); if (index > -1) { items[index].count++; items[index].SqlUpdateOrInsert(false); } else { GroceriesItem newitem = new GroceriesItem(); newitem.name = quickitembutton.Text; newitem.count = 1; newitem.list = selectedlist; newitem.SqlUpdateOrInsert(true); items = General.Groceries.GetAllItems(selectedlist).ToArray(); } RefreshMainItems(); }
// A quick item is clicked private void quickitem_Click(object sender, EventArgs e) { DisplayButton quickitembutton = (DisplayButton)sender; int index = GetIndexByName(quickitembutton.Text); if(index > -1) { items[index].count++; items[index].SqlUpdateOrInsert(false); } else { GroceriesItem newitem = new GroceriesItem(); newitem.name = quickitembutton.Text; newitem.count = 1; newitem.list = selectedlist; newitem.SqlUpdateOrInsert(true); items = General.Groceries.GetAllItems(selectedlist).ToArray(); } RefreshMainItems(); }
// This adds or updates an item in the main list public void AddOrUpdateItem(GroceriesItem item, bool increasecount) { item.SqlUpdateOrInsert(increasecount); }