//Adds the new lunchbox with all its attributes if the fields are filled in correctly, //clears the fields again and update all lunchbox datagrid views private void buttonAddLunchboxMyAccount_Click(object sender, EventArgs e) { string name = textBoxNameAddALunchBoxMyAccount.Text; string quantityString = textBoxQuantityAddALunchBoxMyAccount.Text; string content = textBoxContentAddALunchBox.Text; string foodCategory = comboBoxFoodCategoryMyAccount.Text; if (CheckAllAddALunchTextBoxes() && CheckLunchBoxQuantity(quantityString)) { try { int quantity = int.Parse(quantityString); LunchBox l = new LunchBox(name, content, foodCategory, quantity, member); controller.AddLunchBox(l); ClearAllMyAccountLunchBox(); dataGridViewLunchBoxesMyAccount.DataSource = controller.FindMembersLunchBoxes(member); dataGridViewMyLunchBoxesFindPage.DataSource = controller.FindMembersLunchBoxes(member); FormatLunchBoxesMyAccount(); FormatMyLunchBoxesFindPage(); dataGridViewLunchBoxesMyAccount.Rows[0].Selected = false; toolStripStatusLabelLunchSwitch.Text = "The lunchbox was added"; } catch (Exception ex) { toolStripStatusLabelLunchSwitch.Text = ExceptionHandler.HandleExceptions(ex); } } }
//Decreases the quantity of the selected lunchbox with 1 private void buttonMinusQuanityMyAccount_Click(object sender, EventArgs e) { if (dataGridViewLunchBoxesMyAccount.SelectedRows.Count == 0) { toolStripStatusLabelLunchSwitch.Text = "Please select which lunchbox you want to edit first"; } else { try { LunchBox friendLb = controller.FindLunchBox(Convert.ToInt64(lunchBoxIdMyAccount)); int quantity = friendLb.Quantity - 1; if (quantity == 0) { controller.DeleteLunchBox(friendLb.LunchBoxId); } else { controller.UpdateLunchBox(friendLb.LunchBoxId, quantity); } dataGridViewLunchBoxesMyAccount.DataSource = controller.FindMembersLunchBoxes(member); DeselectRowsMyAccountPage(); toolStripStatusLabelLunchSwitch.Text = "Quantity changed"; } catch (Exception ex) { toolStripStatusLabelLunchSwitch.Text = ExceptionHandler.HandleExceptions(ex); } } }
//Makes a switch once the "make a switch" button is pressed. //Decreases the quantity of both selected lunchboxes, and removes if there are none left //Creates a meet-up, reformats the datagridviews and informs the member if the successful switch. public void makeASwitch(LunchBox lb1, LunchBox lb2) { int quantity = lb1.Quantity - 1; int myQuantity = lb2.Quantity - 1; string information = (lb1.Member.MemberId + "'s " + lb1.Name + " for " + member.MemberId + "'s " + lb2.Name); CreateMeetUp(lb1, information); //Removes the other member's lunchbox if it was the last one, otherwise updates by decreasing in quantity if (quantity == 0) { controller.DeleteLunchBox(lb1.LunchBoxId); } else { controller.UpdateLunchBox(lb1.LunchBoxId, quantity); } //Removes the current member's lunchbox if it was the last one, otherwise updates by decreasing in quantity if (myQuantity == 0) { controller.DeleteLunchBox(lb2.LunchBoxId); } else { controller.UpdateLunchBox(lb2.LunchBoxId, myQuantity); } FillMyAccountPage(); FormatMyLunchBoxesFindPage(); }
public void AddLunchBox(LunchBox l) { try { lsa.AddLunchBox(l); } catch (Exception ex) { throw ex; } }
public void AddLunchBox(LunchBox l) { try { db.LunchBoxes.Add(l); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public void DeleteLunchBox(long lunchBoxId) { try { LunchBox l = FindLunchBox(lunchBoxId); db.LunchBoxes.Remove(l); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
//Creates a new meetup once the "make a switch" button is pressed private void CreateMeetUp(LunchBox friendLb, string information) { MeetUp mU = new MeetUp(information); controller.AddMeetup(mU); int meetUpId = mU.MeetUpId; MeetUp_Member mm = new MeetUp_Member(member, mU); MeetUp_Member mm1 = new MeetUp_Member(friendLb.Member, mU); controller.AddMeetUp_Member(mm, meetUpId); controller.AddMeetUp_Member(mm1, meetUpId); }
//Makes a switch private void buttonMakeaswitchFindpage_Click(object sender, EventArgs e) { try { //Finds the selected lunchbox of member and removes one from the quantity int myLunchboxId = Int32.Parse(lunchBoxIdMy); LunchBox myLb = controller.FindLunchBox(myLunchboxId); //if selected from searchdatagridview, finds the searched lunchbox, removes one from //quantity and creates a new meetup if (dataGridViewSearchLunchBoxesFindPage.SelectedRows.Count != 0 && myLb != null && dataGridViewFriendLunchBoxesFindPage.DataSource == null) { int lunchBoxId = Int32.Parse(lunchBoxIdSearch); LunchBox lb = controller.FindLunchBox(lunchBoxId); makeASwitch(lb, myLb); SearchLunchBoxFindPage(); FormatSearchLunchBoxesFindPage(); toolStripStatusLabelLunchSwitch.Text = "The switch is now made"; } //if selected from frienddatagridview, finds the friend's lunchbox, removes one from //quantity and creates a new meetup else if (dataGridViewFriendLunchBoxesFindPage.SelectedRows.Count != 0 && myLb != null && dataGridViewSearchLunchBoxesFindPage.DataSource == null) { int friendLunchBoxId = Int32.Parse(lunchBoxIdFriend); LunchBox friendLb = controller.FindLunchBox(friendLunchBoxId); makeASwitch(friendLb, myLb); FormatFriendLunchBoxesFindPage(); buttonSearchForAFriendFindpage_Click(null, null); toolStripStatusLabelLunchSwitch.Text = "The switch is now made"; } else { toolStripStatusLabelLunchSwitch.Text = "Please make a selection first"; } //Refresh the lists of lunchboxes and meet-ups on the current member's profile dataGridViewLunchBoxesMyAccount.DataSource = controller.FindMembersLunchBoxes(member); dataGridViewMyMeetUpsMyAccount.DataSource = controller.FindMembersMeetUps(member); } catch (Exception ex) { toolStripStatusLabelLunchSwitch.Text = ExceptionHandler.HandleExceptions(ex); } DeselectRowsFindPage(); }
public void UpdateLunchBox(long lunchBoxId, int quantity) { try { LunchBox l = db.LunchBoxes.Find(lunchBoxId); l.Quantity = quantity; db.Entry(l).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LunchBox = await _context.LunchBox .Include(l => l.Manufacturer).FirstOrDefaultAsync(m => m.Id == id); if (LunchBox == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } LunchBox = await _context.LunchBox .Include(l => l.Manufacturer).FirstOrDefaultAsync(m => m.Id == id); if (LunchBox == null) { return(NotFound()); } ViewData["ManufacturerId"] = new SelectList(_context.LunchBoxManufacturer, "Id", "Location"); return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } LunchBox = await _context.LunchBox.FindAsync(id); if (LunchBox != null) { _context.LunchBox.Remove(LunchBox); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public void Can_CreateISingleton_of_T() { LunchBox lunchbox = LunchBox.Instance; Debug.WriteLine(lunchbox.OwnerName); lunchbox.Open(); var loggerInstance = lunchbox.Get <ClientLogger>(); Assert.NotNull(loggerInstance); Assert.True(lunchbox is ISingleton); string thiefName = "Jack", originalOwner = lunchbox.OwnerName; Assert.Equal(lunchbox.OwnerName, originalOwner); lunchbox.OwnerName = thiefName; Assert.Equal(lunchbox.OwnerName, thiefName); }
public void RandomlyShowOrHideStudyMaterialsOnDesk() { int yesOrNo; if (BoxFilled != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { BoxFilled.SetActive(true); } else { BoxFilled.SetActive(false); } } if (NoteBook != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { NoteBook.SetActive(true); } else { NoteBook.SetActive(false); } } if (Tablet != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Tablet.SetActive(true); } else { Tablet.SetActive(false); } } if (Book != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Book.SetActive(true); } else { Book.SetActive(false); } } if (PencilBox != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { PencilBox.SetActive(true); } else { PencilBox.SetActive(false); } } if (Pencil != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Pencil.SetActive(true); } else { Pencil.SetActive(false); } } if (Pen != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Pen.SetActive(true); } else { Pen.SetActive(false); } } if (LunchBox != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { LunchBox.SetActive(true); } else { LunchBox.SetActive(false); } } if (MilkBottle != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { MilkBottle.SetActive(true); } else { MilkBottle.SetActive(false); } } if (Ruler != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Ruler.SetActive(true); } else { Ruler.SetActive(false); } } if (Eraser != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Eraser.SetActive(true); } else { Eraser.SetActive(false); } } if (Glue != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Glue.SetActive(true); } else { Glue.SetActive(false); } } if (Scissor != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Scissor.SetActive(true); } else { Scissor.SetActive(false); } } if (Apple != null) { yesOrNo = Random.Range(0, 11) % 2; if (yesOrNo == 1) { Apple.SetActive(true); } else { Apple.SetActive(false); } } }
public bool SetStudyMaterialVisiblityAndRetrun(StudyMaterial studyMaterial, bool visibleOrNot) { switch (studyMaterial) { case StudyMaterial.BoxFilled: if (BoxFilled != null) { BoxFilled.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.YellowPaper: if (YellowPaper != null) { YellowPaper.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.BluePaper: if (BluePaper != null) { BluePaper.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.WorkSheet: if (WorkSheet != null) { WorkSheet.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Book: if (Book != null) { Book.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Tablet: if (Tablet != null) { Tablet.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.NoteBook: if (NoteBook != null) { NoteBook.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.OpenBook: if (OpenBook != null) { OpenBook.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.PencilBox: if (PencilBox != null) { PencilBox.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Pencil: if (Pencil != null) { Pencil.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Pen: if (Pen != null) { Pen.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.LunchBox: if (LunchBox != null) { LunchBox.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.MilkBottle: if (MilkBottle != null) { MilkBottle.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Bag: if (Bag != null) { Bag.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Ruler: if (Ruler != null) { Ruler.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Eraser: if (Eraser != null) { Eraser.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Glue: if (Glue != null) { Glue.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Scissor: if (Scissor != null) { Scissor.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.RippedPaper: if (RippedPaper != null) { RippedPaper.SetActive(visibleOrNot); } else { return(false); } break; case StudyMaterial.Apple: if (Apple != null) { Apple.SetActive(visibleOrNot); } else { return(false); } break; default: if (BluePaper != null) { BluePaper.SetActive(visibleOrNot); } else { return(false); } break; } return(true); }
public void HideByDefaultStudyMaterials() { if (BoxFilled != null) { BoxFilled.SetActive(false); } if (YellowPaper != null) { YellowPaper.SetActive(false); } if (BluePaper != null) { BluePaper.SetActive(false); } if (WorkSheet != null) { WorkSheet.SetActive(false); } if (NoteBook != null) { NoteBook.SetActive(false); } if (Tablet != null) { Tablet.SetActive(false); } if (Book != null) { Book.SetActive(false); } if (OpenBook != null) { OpenBook.SetActive(false); } if (PencilBox != null) { PencilBox.SetActive(false); } if (Pencil != null) { Pencil.SetActive(false); } if (Pen != null) { Pen.SetActive(false); } if (LunchBox != null) { LunchBox.SetActive(false); } if (MilkBottle != null) { MilkBottle.SetActive(false); } if (Bag != null) { Bag.SetActive(false); } if (Ruler != null) { Ruler.SetActive(false); } if (Eraser != null) { Eraser.SetActive(false); } if (Glue != null) { Glue.SetActive(false); } if (Scissor != null) { Scissor.SetActive(false); } if (RippedPaper != null) { RippedPaper.SetActive(false); } if (Apple != null) { Apple.SetActive(false); } if (WeeklyPlan != null) { WeeklyPlan.SetActive(false); } }
public void SetStudyMaterialVisiblity(StudyMaterial studyMaterial, bool visibleOrNot) { switch (studyMaterial) { case StudyMaterial.BoxFilled: BoxFilled.SetActive(visibleOrNot); break; case StudyMaterial.YellowPaper: YellowPaper.SetActive(visibleOrNot); break; case StudyMaterial.BluePaper: BluePaper.SetActive(visibleOrNot); break; case StudyMaterial.WorkSheet: WorkSheet.SetActive(visibleOrNot); break; case StudyMaterial.Book: Book.SetActive(visibleOrNot); break; case StudyMaterial.Tablet: Tablet.SetActive(visibleOrNot); break; case StudyMaterial.NoteBook: NoteBook.SetActive(visibleOrNot); break; case StudyMaterial.OpenBook: OpenBook.SetActive(visibleOrNot); break; case StudyMaterial.PencilBox: PencilBox.SetActive(visibleOrNot); break; case StudyMaterial.Pencil: Pencil.SetActive(visibleOrNot); break; case StudyMaterial.Pen: Pen.SetActive(visibleOrNot); break; case StudyMaterial.LunchBox: LunchBox.SetActive(visibleOrNot); break; case StudyMaterial.MilkBottle: MilkBottle.SetActive(visibleOrNot); break; case StudyMaterial.Bag: Bag.SetActive(visibleOrNot); break; case StudyMaterial.Ruler: Ruler.SetActive(visibleOrNot); break; case StudyMaterial.Eraser: Eraser.SetActive(visibleOrNot); break; case StudyMaterial.Glue: Glue.SetActive(visibleOrNot); break; case StudyMaterial.Scissor: Scissor.SetActive(visibleOrNot); break; case StudyMaterial.RippedPaper: RippedPaper.SetActive(visibleOrNot); break; case StudyMaterial.Apple: Apple.SetActive(visibleOrNot); break; case StudyMaterial.WeeklyPlan: WeeklyPlan.SetActive(visibleOrNot); break; default: BluePaper.SetActive(visibleOrNot); break; } }