private void UQBtn_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count == 1) { foreach (DataGridViewRow dr in dataGridView1.SelectedRows) { var ID = int.Parse(dr.Cells["ID1"].Value.ToString()); var quantity = int.Parse(dr.Cells["Quantity Booked"].Value.ToString()); using (var db = new Session2Entities()) { var q = db.Bookings.Where(x => x.bookingId == ID).FirstOrDefault(); //This feature should not allow a user to reduce the number of packages to zero. if (NQ.Value == 0) { MessageBox.Show("Invalid Quantity! IF you want, please delete it!"); return; } //the system should check to ensure that there are sufficient //packages available before the user can increase the quantity they wish to book if (q.Package.packageQuantity > NQ.Value) { q.quantityBooked = (int)NQ.Value; if ((int)NQ.Value < quantity) { q.Package.packageQuantity += quantity - (int)NQ.Value; } else { q.Package.packageQuantity -= (int)NQ.Value; } } else { //If there are insufficient packages, the system should notify the user and not process the update. MessageBox.Show("Invalid Quantity!"); return; } try { db.SaveChanges(); //This table should only include the package //bookings that the sponsor manager has Approved var q1 = db.Bookings.Where(x => x.userIdFK == users.userId && x.status == "Approved") //When the screen is loaded, the packages should //be sorted by their tier and then individual value. .OrderBy(x => x.Package.packageTier == "Bronze" ? 1 : x.Package.packageTier == "Silver" ? 2 : 3) .ThenBy(x => x.Package.packageValue) .ToList(); //Once package is updated or deleted, the table should automatically refresh to show the updated //information. dataGridView1.DataSource = cdt(q1); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.Columns["ID1"].Visible = false; TotalVal.Text = val.ToString(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } } } else { MessageBox.Show("ERROR!"); return; } }
private void createABtn_Click(object sender, EventArgs e) { using (var db = new Session2Entities()) { //Create new user object User user = new User(); var companyname = db.Users.Where(x => x.name == name.Text).FirstOrDefault(); if (companyname == null) { user.name = name.Text; } else { MessageBox.Show("Company Name Taken!"); return; } var q = db.Users.Where(x => x.userId == UID.Text).FirstOrDefault(); //Checking if UserID contains a minimum of 8 Chars if (UID.TextLength >= 8) { //Checking if userID is used alr if (q == null) { user.userId = UID.Text; } else { MessageBox.Show("User ID Taken!"); return; } } else { MessageBox.Show("User ID must be 8 characters long!"); return; } //Checking if passwords match if (Pass.Text != PassC.Text) { MessageBox.Show("Passwords Do Not Match!"); return; } else { user.passwd = Pass.Text; } user.userTypeIdFK = 2; db.Users.Add(user); try { db.SaveChanges(); MessageBox.Show("Successful!"); //Redirected back to the login screen this.Hide(); Form1 form = new Form1(); form.Show(); } catch (Exception es) { MessageBox.Show(es.ToString()); } } }
private void APBtn_Click(object sender, EventArgs e) { var tiers = tier.Text; using (var db = new Session2Entities()) { //Users cannot add a more than one package with the same name var q = db.Packages.Where(x => x.packageName == name.Text.Trim()).FirstOrDefault(); if (q != null) { MessageBox.Show("Invalid Package Name!"); return; } Package package = new Package(); package.packageTier = tiers; package.packageName = name.Text; //Gold packages must be more than or equal to //$50,000 in value if (tiers == "Gold") { if (int.Parse(val.Text) >= 50000) { package.packageValue = long.Parse(val.Text); } else { MessageBox.Show("Invalid Package Value! Value must be more then or equals to 50K!"); return; } } //Silver packages can be between $10,000 to $50,000 in value else if (tiers == "Silver") { if (int.Parse(val.Text) > 10000 && int.Parse(val.Text) < 50000) { package.packageValue = long.Parse(val.Text); } else { MessageBox.Show("Invalid Package Value! Value must be between 10K and 50K!"); return; } } //Bronze packages must be less than or equal to //$10,000 in value else if (tiers == "Bronze") { if (int.Parse(val.Text.ToString()) <= 10000) { package.packageValue = long.Parse(val.Text.ToString()); } else { MessageBox.Show("Invalid Package Value! Value must be less then or equals to 10K!"); return; } } //The starting quantity of available packages must be //greater than zero. if (quantity.Value == 0) { MessageBox.Show("Quantity must be more than 0!"); return; } else { package.packageQuantity = (int)quantity.Value; } try { db.Packages.Add(package); db.SaveChanges(); //Gold packages must include all three benefits. if (tiers == "Gold") { Benefit benefit = new Benefit(); benefit.packageIdFK = package.packageId; benefit.benefitName = "Online"; db.Benefits.Add(benefit); Benefit benefit2 = new Benefit(); benefit2.packageIdFK = package.packageId; benefit2.benefitName = "Flyer"; db.Benefits.Add(benefit2); Benefit benefit3 = new Benefit(); benefit3.packageIdFK = package.packageId; benefit3.benefitName = "Banner"; db.Benefits.Add(benefit3); } //Silver packages must have two benefits, but the //user can pick any combination of the benefits. else if (tiers == "Silver") { var count = 0; var on = 0; var fly = 0; var ban = 0; if (online.Checked) { count += 1; on = 1; } if (Flyers.Checked) { count += 1; fly = 1; } if (Banner.Checked) { count += 1; ban = 1; } if (count == 2) { if (on == 1) { Benefit benefit = new Benefit(); benefit.packageIdFK = package.packageId; benefit.benefitName = "Online"; db.Benefits.Add(benefit); } if (fly == 1) { Benefit benefit2 = new Benefit(); benefit2.packageIdFK = package.packageId; benefit2.benefitName = "Flyer"; db.Benefits.Add(benefit2); } if (ban == 1) { Benefit benefit3 = new Benefit(); benefit3.packageIdFK = package.packageId; benefit3.benefitName = "Banner"; db.Benefits.Add(benefit3); } } else { MessageBox.Show("Invalid Benefits! Silve can only have 2 benefits!"); db.Packages.Remove(package); db.SaveChanges(); return; } } //Bronze packages only have one benefit, //but the user can pick any of the benefits. else if (tiers == "Bronze") { var count = 0; if (online.Checked) { count += 1; } if (Flyers.Checked) { count += 1; } if (Banner.Checked) { count += 1; } if (count == 1) { if (online.Checked) { Benefit benefit = new Benefit(); benefit.packageIdFK = package.packageId; benefit.benefitName = "Online"; db.Benefits.Add(benefit); } else if (Flyers.Checked) { Benefit benefit2 = new Benefit(); benefit2.packageIdFK = package.packageId; benefit2.benefitName = "Flyer"; db.Benefits.Add(benefit2); } else if (Banner.Checked) { Benefit benefit3 = new Benefit(); benefit3.packageIdFK = package.packageId; benefit3.benefitName = "Banner"; db.Benefits.Add(benefit3); } } else { MessageBox.Show("Invalid Benefits! Bronze must have only 1 benefit"); db.Packages.Remove(package); db.SaveChanges(); return; } } try { db.SaveChanges(); } catch (Exception es) { MessageBox.Show(es.ToString()); } MessageBox.Show("Success!"); } catch (Exception es) { MessageBox.Show(es.ToString()); } } }