Пример #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a booking to update!", "Update Quantity",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         var getBookingID   = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
         var getPackageName = dataGridView1.CurrentRow.Cells[2].Value.ToString();
         using (var context = new Session2Entities())
         {
             var toDelete = (from x in context.Bookings
                             where x.bookingId == getBookingID
                             select x).FirstOrDefault();
             var toAddBackPackage = (from x in context.Packages
                                     where x.packageName == getPackageName
                                     select x).FirstOrDefault();
             toAddBackPackage.packageQuantity += toDelete.quantityBooked;
             context.SaveChanges();
             context.Bookings.Remove(toDelete);
             context.SaveChanges();
             MessageBox.Show("Booking deleted!", "Delete Booking", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
             LoadData();
         }
     }
 }
Пример #2
0
        private void LoadData()
        {
            dataGridView1.Rows.Clear();
            using (var context = new Session2Entities())
            {
                var getBookings = (from x in context.Bookings
                                   where x.userIdFK == _user.userId
                                   where x.status == "Approved"
                                   select x);
                foreach (var item in getBookings)
                {
                    var newRow = new List <String>()
                    {
                        item.bookingId.ToString(), item.Package.packageTier, item.Package.packageName,
                             item.Package.packageValue.ToString(), item.quantityBooked.ToString(),
                        (item.Package.packageValue * item.quantityBooked).ToString()
                    };
                    dataGridView1.Rows.Add(newRow.ToArray());
                }

                long totalValue = 0;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    totalValue += Convert.ToInt64(dataGridView1.Rows[row.Index].Cells[5].Value);
                }
                lblTotalValue.Text = totalValue.ToString();
            }
        }
Пример #3
0
 private void btnBook_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a sponsorship package to book!", "Booking", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     else
     {
         if (Convert.ToDecimal(dataGridView1.CurrentRow.Cells[4].Value) < nudQuantity.Value)
         {
             MessageBox.Show("Sponsorship booking not enough!", "Booking", MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
         else
         {
             var newBooking = new Booking()
             {
                 packageIdFK    = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value),
                 status         = "Pending",
                 userIdFK       = _user.userId,
                 quantityBooked = Convert.ToInt32(nudQuantity.Value)
             };
             using (var context = new Session2Entities())
             {
                 context.Bookings.Add(newBooking);
                 context.SaveChanges();
                 MessageBox.Show("Booking successful!", "Booking", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
Пример #4
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtCompanyName.Text) || string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRePassword.Text))
            {
                MessageBox.Show("Please check your fields!", "Empty Field(s)", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else if (txtUserID.TextLength < 8)
            {
                MessageBox.Show("User ID needs to be 8 characters long!", "Short User ID", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else if (txtPassword.Text != txtRePassword.Text)
            {
                MessageBox.Show("Passwords do not match!", "Passwords Mismatch", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                using (var context = new Session2Entities())
                {
                    var getUser = (from x in context.Users
                                   where x.userId == txtUserID.Text
                                   select x).FirstOrDefault();
                    var findCompany = (from x in context.Users
                                       where x.name == txtCompanyName.Text
                                       select x).FirstOrDefault();

                    if (getUser != null)
                    {
                        MessageBox.Show("User ID taken!", "Unvalid User ID", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else if (findCompany != null)
                    {
                        MessageBox.Show("Company has already registered for an account!", "User Account Exist", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        var newUser = new User()
                        {
                            name         = txtCompanyName.Text,
                            userId       = txtUserID.Text,
                            passwd       = txtRePassword.Text,
                            userTypeIdFK = 2
                        };
                        context.Users.Add(newUser);
                        context.SaveChanges();
                        MessageBox.Show("User account created successfully!", "Create Account", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                        Hide();
                        (new LoginForm()).ShowDialog();
                        Close();
                    }
                }
            }
        }
Пример #5
0
 private void cbTier_SelectedIndexChanged(object sender, EventArgs e)
 {
     chart1.Series.Clear();
     chart1.Series.Add("Series1");
     chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
     if (cbTier.SelectedItem.ToString() == "All Tiers")
     {
         using (var context = new Session2Entities())
         {
             var getSummary = (from x in context.Bookings
                               where x.status == "Approved"
                               group x by x.Package.packageName into y
                               select new
             {
                 key = y.Key,
                 totalAmount = context.Bookings.Where(z => z.Package.packageName == y.Key)
                               .Select(z => z.quantityBooked).Sum()
             });
             var totalValue = 0;
             foreach (var item in getSummary)
             {
                 var Idx = chart1.Series[0].Points.AddY(item.totalAmount);
                 chart1.Series[0].Points[Idx].AxisLabel = item.key;
                 totalValue += Convert.ToInt32((from x in context.Bookings
                                                where x.status == "Approved" && x.Package.packageName == item.key
                                                select x.Package.packageValue * x.quantityBooked).Sum());
                 chart1.Series[0].Points[Idx].LabelToolTip = $"{item.key}, {item.totalAmount}, #PERCENT";
             }
             lblTotalValue.Text = totalValue.ToString();
         }
     }
     else
     {
         using (var context = new Session2Entities())
         {
             var getSummary = (from x in context.Bookings
                               where x.status == "Approved" && x.Package.packageTier == cbTier.SelectedItem.ToString()
                               group x by x.Package.packageName into y
                               select new
             {
                 key = y.Key,
                 totalAmount = context.Bookings.Where(z => z.Package.packageName == y.Key)
                               .Select(z => z.quantityBooked).Sum()
             });
             var totalValue = 0;
             foreach (var item in getSummary)
             {
                 var Idx = chart1.Series[0].Points.AddY(item.totalAmount);
                 chart1.Series[0].Points[Idx].AxisLabel = item.key;
                 totalValue += Convert.ToInt32((from x in context.Bookings
                                                where x.status == "Approved" && x.Package.packageName == item.key
                                                select x.Package.packageValue * x.quantityBooked).Sum());
                 chart1.Series[0].Points[Idx].LabelToolTip = $"{item.key}, {item.totalAmount}, #PERCENT";
             }
             lblTotalValue.Text = totalValue.ToString();
         }
     }
 }
 private void btnApprove_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 0)
     {
         MessageBox.Show("Please select at least one booking to accept!", "No bookings selected",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         bool boolCheck = true;
         foreach (DataGridViewRow row in dataGridView1.SelectedRows)
         {
             if (dataGridView1.Rows[row.Index].Cells[3].Value.ToString() != "Pending")
             {
                 boolCheck = false;
             }
         }
         if (boolCheck == false)
         {
             MessageBox.Show("You can only accept pending bookings! Re-select and try again!",
                             "Invalid bookings selected",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             foreach (DataGridViewRow row in dataGridView1.SelectedRows)
             {
                 using (var context = new Session2Entities())
                 {
                     var getBookingID = Convert.ToInt32(dataGridView1.Rows[row.Index].Cells[0].Value);
                     var toAccept     = (from x in context.Bookings
                                         where x.bookingId == getBookingID
                                         select x).FirstOrDefault();
                     var checkPackageQuantity = (from x in context.Packages
                                                 where x.packageId == toAccept.packageIdFK
                                                 select x).FirstOrDefault();
                     if (checkPackageQuantity.packageQuantity - toAccept.quantityBooked >= 0)
                     {
                         toAccept.status = "Approved";
                         context.SaveChanges();
                         checkPackageQuantity.packageQuantity -= toAccept.quantityBooked;
                         context.SaveChanges();
                     }
                     else
                     {
                         MessageBox.Show($"{toAccept.User.name}'s {toAccept.Package.packageName} cannot be approved as it will cause a shortage in the werehouse!",
                                         "Unable to approve", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                         continue;
                     }
                 }
             }
             MessageBox.Show("Successfully Accepted bookings!", "Reject Bookings",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadData();
         }
     }
 }
Пример #7
0
 private void LoadComboBox()
 {
     cbTier.Items.Clear();
     using (var context = new Session2Entities())
     {
         var getTier = (from x in context.Packages
                        select x.packageTier).Distinct().ToArray();
         cbTier.Items.AddRange(getTier);
     }
 }
Пример #8
0
 private void rbQuantity_CheckedChanged(object sender, EventArgs e)
 {
     using (var context = new Session2Entities())
     {
         orderedList = (from x in context.Packages
                        orderby x.packageQuantity descending
                        select x).ToList();
         LoadData(1);
     }
 }
Пример #9
0
 private void rbTier_CheckedChanged(object sender, EventArgs e)
 {
     using (var context = new Session2Entities())
     {
         orderedList = (from x in context.Packages
                        orderby x.packageTier == "Bronze", x.packageTier == "Silver", x.packageTier == "Gold"
                        select x).ToList();
         LoadData(1);
     }
 }
Пример #10
0
 private void LoadComboBox()
 {
     cbTier.Items.Clear();
     cbTier.Items.Add("All Tiers");
     using (var context = new Session2Entities())
     {
         var getTiers = (from x in context.Packages
                         orderby x.packageTier == "Bronze", x.packageTier == "Silver", x.packageTier == "Gold"
                         select x.packageTier).Distinct().ToArray();
         cbTier.Items.AddRange(getTiers);
         cbTier.SelectedIndex = 0;
     }
 }
Пример #11
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            using (var context = new Session2Entities())
            {
                if (string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text))
                {
                    MessageBox.Show("Please check your fields and try again!", "Empty Field(s)", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    var getUser = (from x in context.Users
                                   where x.userId == txtUserID.Text
                                   select x).FirstOrDefault();

                    if (getUser == null)
                    {
                        MessageBox.Show("User does not exits!", "Invalid Login", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (getUser.passwd != txtPassword.Text)
                        {
                            MessageBox.Show("Password or User ID does not match our database!", "Invalid Login", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                        else
                        {
                            if (getUser.userTypeIdFK == 1)
                            {
                                MessageBox.Show($"Welcome {getUser.name}!", "Login", MessageBoxButtons.OK,
                                                MessageBoxIcon.Information);
                                Hide();
                                (new ManagerMain()).ShowDialog();
                                Close();
                            }
                            else if (getUser.userTypeIdFK == 2)
                            {
                                MessageBox.Show($"Welcome {getUser.name}!", "Login", MessageBoxButtons.OK,
                                                MessageBoxIcon.Information);
                                Hide();
                                (new SponsorMain(getUser)).ShowDialog();
                                Close();
                            }
                        }
                    }
                }
            }
        }
Пример #12
0
 private void LoadData()
 {
     dataGridView1.Rows.Clear();
     using (var context = new Session2Entities())
     {
         var getBookings = (from x in context.Bookings
                            orderby x.status == "Rejected", x.status == "Approved", x.status == "Pending",
                            x.User.name
                            select x);
         foreach (var item in getBookings)
         {
             var newRow = new List <string>()
             {
                 item.bookingId.ToString(), item.User.name, item.Package.packageName, item.status
             };
             dataGridView1.Rows.Add(newRow.ToArray());
         }
     }
 }
Пример #13
0
 private void btnReject_Click(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count == 0)
     {
         MessageBox.Show("Please select at least one booking to reject!", "No bookings selected",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         bool boolCheck = true;
         foreach (DataGridViewRow row in dataGridView1.SelectedRows)
         {
             if (dataGridView1.Rows[row.Index].Cells[3].Value.ToString() != "Pending")
             {
                 boolCheck = false;
             }
         }
         if (boolCheck == false)
         {
             MessageBox.Show("You can only reject pending bookings! Re-select and try again!",
                             "Invalid bookings selected",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             foreach (DataGridViewRow row in dataGridView1.SelectedRows)
             {
                 using (var context = new Session2Entities())
                 {
                     var getBookingID = Convert.ToInt32(dataGridView1.Rows[row.Index].Cells[0].Value);
                     var toReject     = (from x in context.Bookings
                                         where x.bookingId == getBookingID
                                         select x).FirstOrDefault();
                     toReject.status = "Rejected";
                     context.SaveChanges();
                 }
             }
             MessageBox.Show("Successfully rejected bookings!", "Reject Bookings",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Пример #14
0
 private void btnUpdateQuantity_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a booking to update!", "Update Quantity",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         int toUpdate   = Convert.ToInt32(nudQuantity.Value);
         var getPackage = dataGridView1.CurrentRow.Cells[2].Value.ToString();
         using (var context = new Session2Entities())
         {
             var getCurrentQuantity = (from x in context.Packages
                                       where x.packageName == getPackage
                                       select x.packageQuantity).FirstOrDefault();
             if (getCurrentQuantity - toUpdate < 0)
             {
                 MessageBox.Show("There are not enough sponsorship bookings for new quantity!",
                                 "Update Quantity", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 var getPackageToUpdate = (from x in context.Packages
                                           where x.packageName == getPackage
                                           select x).FirstOrDefault();
                 getPackageToUpdate.packageQuantity += Convert.ToInt32(dataGridView1.CurrentRow.Cells[4].Value);
                 context.SaveChanges();
                 var bookingID          = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
                 var getBookingToUpdate = (from x in context.Bookings
                                           where x.bookingId == bookingID
                                           select x).FirstOrDefault();
                 getBookingToUpdate.quantityBooked = toUpdate;
                 getBookingToUpdate.status         = "Pending";
                 context.SaveChanges();
                 MessageBox.Show("Booking updated! Please wait for manager to approve the new quantity.",
                                 "Update Quantity", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 LoadData();
             }
         }
     }
 }
Пример #15
0
        private void btnUpload_Click(object sender, EventArgs e)
        {
            var value = File.ReadAllLines(txtFilePath.Text).Skip(1);

            foreach (var item in value)
            {
                var rowValue   = item.Split(',');
                var newPackage = new Package()
                {
                    packageTier     = rowValue[0],
                    packageName     = rowValue[1],
                    packageValue    = Convert.ToInt64(rowValue[2]),
                    packageQuantity = Convert.ToInt32(rowValue[3])
                };
                using (var context = new Session2Entities())
                {
                    context.Packages.Add(newPackage);
                    context.SaveChanges();
                }
            }
            MessageBox.Show("Added all new packages", "Add Packages",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
            btnClear_Click(null, null);
        }
Пример #16
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(txtPackageName.Text) || nudValue.Value <= 0 || nudQuantity.Value <= 0 || cbTier.SelectedItem == null)
     {
         MessageBox.Show("Please check your entries! Make sure there is a package name and values are correct!",
                         "Invalid Field(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Bronze" && (nudValue.Value <= 0 || nudValue.Value > 10000))
     {
         MessageBox.Show("Bronze tier pricing is between $0 and up to $10,000!", "Invalid Value",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Silver" && (nudValue.Value <= 10000 || nudValue.Value >= 50000))
     {
         MessageBox.Show("Silver tier pricing is between $10000 inclusive, to $50,000!", "Invalid Value",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Gold" && nudValue.Value < 50000)
     {
         MessageBox.Show("Gold tier pricing is more than or equal $50,000!", "Invalid Value",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Bronze" && benefitsList.Count != 1)
     {
         MessageBox.Show("Bronze tier requires up to one benfit!", "Invalid number of benefit",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Silver" && benefitsList.Count != 2)
     {
         MessageBox.Show("Silver tier requires only two benfits!", "Invalid number of benefit",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (cbTier.SelectedItem.ToString() == "Gold" && benefitsList.Count != 3)
     {
         MessageBox.Show("Gold tier requires all benefits!", "Invalid number of benefit",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         using (var context = new Session2Entities())
         {
             var getPackageName = (from x in context.Packages
                                   where x.packageName == txtPackageName.Text
                                   select x).FirstOrDefault();
             if (getPackageName != null)
             {
                 MessageBox.Show("Unable to add package as name is used!", "Existing Package Name",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 var newPackage = new Package()
                 {
                     packageTier     = cbTier.SelectedItem.ToString(),
                     packageName     = txtPackageName.Text,
                     packageQuantity = Convert.ToInt32(nudQuantity.Value),
                     packageValue    = Convert.ToInt32(nudValue.Value)
                 };
                 context.Packages.Add(newPackage);
                 context.SaveChanges();
                 var getNewID = (from x in context.Packages
                                 where x.packageName == txtPackageName.Text
                                 select x.packageId).FirstOrDefault();
                 foreach (var item in benefitsList)
                 {
                     context.Benefits.Add(new Benefit()
                     {
                         packageIdFK = getNewID, benefitName = item
                     });
                     context.SaveChanges();
                 }
                 MessageBox.Show("Added package successfully!", "Add Package",
                                 MessageBoxButtons.OK, MessageBoxIcon.Information);
                 btnClear_Click(null, null);
             }
         }
     }
 }
Пример #17
0
 private void FilterList()
 {
     modifiedPackages.Clear();
     if ((cbTier.SelectedItem == null || cbTier.SelectedItem.ToString() == "No Filter") && nudBudget.Value == 0)
     {
         using (var context = new Session2Entities())
         {
             var temporaryPackages = (from x in context.Packages
                                      where x.packageQuantity > 0
                                      select x).ToList();
             foreach (var item in temporaryPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var boolCheck = true;
                 foreach (var benefit in benefitList)
                 {
                     if (getBenefits.Contains(benefit))
                     {
                         continue;
                     }
                     else
                     {
                         boolCheck = false;
                         break;
                     }
                 }
                 if (boolCheck)
                 {
                     modifiedPackages.Add(item);
                 }
                 else
                 {
                     continue;
                 }
             }
             LoadData(1);
         }
     }
     else if ((nudBudget.Value == 0) && (cbTier.SelectedItem != null && cbTier.SelectedItem.ToString() != "No Filter"))
     {
         using (var context = new Session2Entities())
         {
             var temporaryPackages = (from x in context.Packages
                                      where x.packageTier == cbTier.SelectedItem.ToString()
                                      where x.packageQuantity > 0
                                      select x).ToList();
             foreach (var item in temporaryPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var boolCheck = true;
                 foreach (var benefit in benefitList)
                 {
                     if (getBenefits.Contains(benefit))
                     {
                         continue;
                     }
                     else
                     {
                         boolCheck = false;
                         break;
                     }
                 }
                 if (boolCheck)
                 {
                     modifiedPackages.Add(item);
                 }
                 else
                 {
                     continue;
                 }
             }
             LoadData(1);
         }
     }
     else if ((cbTier.SelectedItem == null || cbTier.SelectedItem.ToString() == "No Filter") && nudBudget.Value > 0)
     {
         using (var context = new Session2Entities())
         {
             long budget            = Convert.ToInt64(nudBudget.Value);
             var  temporaryPackages = (from x in context.Packages
                                       where x.packageValue <= budget
                                       where x.packageQuantity > 0
                                       select x).ToList();
             foreach (var item in temporaryPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var boolCheck = true;
                 foreach (var benefit in benefitList)
                 {
                     if (getBenefits.Contains(benefit))
                     {
                         continue;
                     }
                     else
                     {
                         boolCheck = false;
                         break;
                     }
                 }
                 if (boolCheck)
                 {
                     modifiedPackages.Add(item);
                 }
                 else
                 {
                     continue;
                 }
             }
             LoadData(1);
         }
     }
     else
     {
         using (var context = new Session2Entities())
         {
             long budget            = Convert.ToInt64(nudBudget.Value);
             var  temporaryPackages = (from x in context.Packages
                                       where x.packageValue <= budget && x.packageTier == cbTier.SelectedItem.ToString()
                                       where x.packageQuantity > 0
                                       select x).ToList();
             foreach (var item in temporaryPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var boolCheck = true;
                 foreach (var benefit in benefitList)
                 {
                     if (getBenefits.Contains(benefit))
                     {
                         continue;
                     }
                     else
                     {
                         boolCheck = false;
                         break;
                     }
                 }
                 if (boolCheck)
                 {
                     modifiedPackages.Add(item);
                 }
                 else
                 {
                     continue;
                 }
             }
             LoadData(1);
         }
     }
 }
Пример #18
0
 private void LoadData(int mode)
 {
     using (var context = new Session2Entities())
     {
         dataGridView1.Rows.Clear();
         if (mode == 0)
         {
             var getPackages = (from x in context.Packages
                                where x.packageQuantity > 0
                                select x);
             foreach (var item in getPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var newRow = new List <String>()
                 {
                     item.packageId.ToString(),
                     item.packageTier, item.packageName, item.packageValue.ToString(),
                     item.packageQuantity.ToString()
                 };
                 if (getBenefits.Contains("Online"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 if (getBenefits.Contains("Flyer"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 if (getBenefits.Contains("Banner"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 dataGridView1.Rows.Add(newRow.ToArray());
             }
         }
         else
         {
             foreach (var item in modifiedPackages)
             {
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == item.packageId
                                    select x.benefitName).ToList();
                 var newRow = new List <String>()
                 {
                     item.packageId.ToString(),
                     item.packageTier, item.packageName, item.packageValue.ToString(),
                     item.packageQuantity.ToString()
                 };
                 if (getBenefits.Contains("Online"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 if (getBenefits.Contains("Flyer"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 if (getBenefits.Contains("Banner"))
                 {
                     newRow.Add("Yes");
                 }
                 else
                 {
                     newRow.Add("");
                 }
                 dataGridView1.Rows.Add(newRow.ToArray());
             }
         }
     }
 }