//Method for when the user selects the control (MenuItemView) private void MenuItem_Click(object sender, MouseEventArgs e) { RestaurantMenuItemView tempItem = (RestaurantMenuItemView)sender; string id = tempItem.Tag.ToString(); SelectItemHighLight(id); }
//Method for when the user attempts to click on the control but selects the label on the control private void MenuLabel_Click(object sender, MouseEventArgs e) { Label tempLabel = (Label)sender; RestaurantMenuItemView temp = (RestaurantMenuItemView)tempLabel.Parent; MenuItem_Click(temp, e); }
// Controller for RestaurantMenuItem private void populateMenu() { flpItems.Controls.Clear(); foreach (RestaurantMenuItem item in OwnerStorage.MenuItems) { RestaurantMenuItemView newItem = new RestaurantMenuItemView(); newItem.Tag = item.objectId; newItem.Active = item.OutOfStock ? false : true; newItem.Price = item.Price; newItem.Type = item.Type; if (newItem.Active != true) { newItem.BackColor = Color.FromName("ControlDark"); } newItem.Label = item.Name; flpItems.Controls.Add(newItem); newItem.lblName.MouseClick += new MouseEventHandler(MenuLabel_Click); newItem.MouseClick += new MouseEventHandler(MenuItem_Click); } }
//Controller for RestaurantMenuItem which determines if the user wishes to add or edit a MenuItem to the restaurant private void AddOrEdit(RestaurantMenuItem temp) { AddEditMenuItem newForm = new AddEditMenuItem(temp); if (newForm.ShowDialog() == DialogResult.OK) { ShowLoading(true); AsyncCallback <RestaurantMenuItem> callback = new AsyncCallback <RestaurantMenuItem>( result => { Invoke(new Action(() => { //Means an existing item was edited if (temp != null) { OwnerStorage.MenuItems.Insert(OwnerStorage.MenuItems.IndexOf(temp), newForm.transferedItem); OwnerStorage.MenuItems.Remove(temp); foreach (RestaurantMenuItemView item in flpItems.Controls) { if (item.Tag.Equals(temp.objectId)) { item.Name = newForm.transferedItem.Name; item.Type = newForm.transferedItem.Type; item.Price = newForm.transferedItem.Price; } } populateMenu(); SortRefresh(); SelectItemHighLight(selectedItem.objectId); } //Means a new item is created else { RestaurantMenuItemView newView = new RestaurantMenuItemView(); newView.Label = result.Name; newView.Active = true; newView.Type = result.Type; newView.Tag = result.objectId; newView.Price = result.Price; OwnerStorage.MenuItems.Add(result); newView.lblName.MouseClick += new MouseEventHandler(MenuLabel_Click); newView.MouseClick += new MouseEventHandler(MenuItem_Click); flpItems.Controls.Add(newView); } ShowLoading(false); })); }, fault => { Invoke(new Action(() => { MessageBox.Show(this, "Error: " + fault.Message); ShowLoading(false); })); }); //Runs the save callback. It automatically updates objects, so no need to create multiple callbacks Backendless.Data.Of <RestaurantMenuItem>().Save(newForm.transferedItem, callback); } }