private void AddPackage_Load(object sender, EventArgs e)
        {
            using (var context = new Session2Entities1())
            {
                #region Populating the Tier Combo box
                var getTier = (from x in context.Packages
                               select x.packageTier);
                var tiers = new HashSet <string>();
                foreach (var item in getTier)
                {
                    tiers.Add(item);
                }
                cbTier.Items.AddRange(tiers.ToArray());
                #endregion

                #region Populating the Benefits Checklist Box
                var getBenefits = (from x in context.Benefits
                                   select x.benefitName);
                var benefits = new HashSet <string>();
                foreach (var item in getBenefits)
                {
                    benefits.Add(item);
                }
                clbBenefits.Items.AddRange(benefits.ToArray());
                #endregion
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method refreshes the DGV
        /// </summary>
        private void GridRefresh()
        {
            dataGridView1.ColumnCount        = 6;
            dataGridView1.Columns[0].Name    = "Tier";
            dataGridView1.Columns[1].Name    = "Name";
            dataGridView1.Columns[2].Name    = "Individual Value ($)";
            dataGridView1.Columns[3].Name    = "Quantity Booked";
            dataGridView1.Columns[4].Name    = "Sub-Total Value ($)";
            dataGridView1.Columns[5].Name    = "Booking ID";
            dataGridView1.Columns[5].Visible = false;

            using (var context = new Session2Entities1())
            {
                var getBookings = (from x in context.Bookings
                                   where x.userIdFK == _userID
                                   where x.status == "Accepted"
                                   select x);
                foreach (var item in getBookings)
                {
                    List <string> rows = new List <string>()
                    {
                        item.Package.packageTier, item.Package.packageName,
                        item.Package.packageValue.ToString(), item.quantityBooked.ToString(),
                        (item.quantityBooked * item.Package.packageValue).ToString(), item.bookingId.ToString()
                    };
                    dataGridView1.Rows.Add(rows.ToArray());
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// This method is triggered when the delete button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void deleteBtn_Click(object sender, EventArgs e)
 {
     //Checks if there is any row selected at all
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a booking to delete!", "No booking selected",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         //Prompts user with warning message. If yes, then proceeds to delete records of bookings
         var dl = MessageBox.Show("Are you sure you want to delete this booking?", "Delete",
                                  MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (DialogResult.Yes == dl)
         {
             var getBookingId   = Convert.ToInt32(dataGridView1.CurrentRow.Cells[5].Value);
             var getQuantity    = Convert.ToInt32(dataGridView1.CurrentRow.Cells[3].Value);
             var getPackageName = dataGridView1.CurrentRow.Cells[1].Value.ToString();
             using (var context = new Session2Entities1())
             {
                 var getBookingToDelete = (from x in context.Bookings
                                           where x.bookingId == getBookingId
                                           select x).First();
                 var updatePackage = (from x in context.Packages
                                      where x.packageName == getPackageName
                                      select x).First();
                 updatePackage.packageQuantity += getQuantity;
                 context.SaveChanges();
                 context.Bookings.Remove(getBookingToDelete);
                 dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
                 context.SaveChanges();
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// When the reject button is clicked, runs through VadCheck for all selected rows. Also prompts user before
        /// it actually rejects. Then refreshes DGV once anything was rejected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReject_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select at least one row", "No rows selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                foreach (DataGridViewRow item in dataGridView1.SelectedRows)
                {
                    var getBookingID = Convert.ToInt32(item.Cells[3].Value);
                    using (var context = new Session2Entities1())
                    {
                        var getBooking = (from x in context.Bookings
                                          where x.bookingId == getBookingID
                                          select x).First();
                        var dl = MessageBox.Show("Are you sure you want to reject the booking(s)?", "Reject",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                        if (dl == DialogResult.Yes)
                        {
                            getBooking.status = "Rejected";
                            context.SaveChanges();
                        }
                    }
                }
                dataGridView1.Rows.Clear();
                GridRefresh();
            }
        }
Beispiel #5
0
 /// <summary>
 /// This method is resposible for filling up the DGV with the relevant details and also
 /// the ordering of Pending, Approve then Rejected.
 /// </summary>
 private void GridRefresh()
 {
     dataGridView1.ReadOnly           = true;
     dataGridView1.ColumnCount        = 4;
     dataGridView1.Columns[0].Name    = "Company Name";
     dataGridView1.Columns[1].Name    = "Package Name";
     dataGridView1.Columns[2].Name    = "Status";
     dataGridView1.Columns[3].Name    = "Booking ID";
     dataGridView1.Columns[3].Visible = false;
     using (var context = new Session2Entities1())
     {
         var sort = new Dictionary <string, int>()
         {
             { "Pending", 1 }, { "Accepted", 2 }, { "Rejected", 3 }
         };
         var getRows = (from x in context.Bookings
                        orderby x.User.name
                        select x).ToList();
         var results = getRows.OrderBy(x => sort[x.status]).AsQueryable();
         foreach (var item in results)
         {
             var rows = new List <string>()
             {
                 item.User.name, item.Package.packageName, item.status, item.bookingId.ToString()
             };
             dataGridView1.Rows.Add(rows.ToArray());
         }
     }
 }
        /// <summary>
        /// Upon loading this form, load the default DGV layout and order of data of Sponsorship package
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ViewPackage_Load(object sender, EventArgs e)
        {
            dataGridView1.ColumnCount     = 7;
            dataGridView1.Columns[0].Name = "Tier";
            dataGridView1.Columns[1].Name = "Name";
            dataGridView1.Columns[2].Name = "Value ($)";
            dataGridView1.Columns[3].Name = "Available Qty";
            dataGridView1.Columns[4].Name = "Online";
            dataGridView1.Columns[5].Name = "Flyers";
            dataGridView1.Columns[6].Name = "Banner";
            using (var context = new Session2Entities1())
            {
                var getPackages = (from x in context.Packages
                                   select new { x });
                foreach (var item in getPackages.Select(x => x.x.packageName).Distinct())
                {
                    var getPackageInfo = (from x in context.Packages
                                          where x.packageName == item
                                          select x).First();
                    List <string> rows = new List <string>()
                    {
                        getPackageInfo.packageTier, getPackageInfo.packageName, getPackageInfo.packageValue.ToString(),
                        getPackageInfo.packageQuantity.ToString()
                    };

                    var getBenefits = (from x in context.Benefits
                                       where x.packageIdFK == getPackageInfo.packageId
                                       select x.benefitName).ToList();

                    if (getBenefits.FirstOrDefault() == "Online")
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    if (getBenefits.Contains("Flyer"))
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    if (getBenefits.Contains("Banner"))
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    dataGridView1.Rows.Add(rows.ToArray());
                }
            }
        }
        /// <summary>
        /// This method is responsible for loading details and data to Pie Chart, based on selected Tiers
        /// </summary>
        private void loadPie()
        {
            chart1.Series[0].Points.Clear();

            if (cbTier.SelectedItem != null && cbTier.SelectedItem.ToString() != "No Filter")
            {
                var selectedTier = cbTier.SelectedItem.ToString();
                using (var context = new Session2Entities1())
                {
                    var getPoints = (from x in context.Bookings
                                     where x.status == "Accepted"
                                     where x.Package.packageTier == selectedTier
                                     group new { amount = x.Package.packageValue * x.quantityBooked, quantityBooked = x.quantityBooked } by x.Package.packageName into q
                                     select new
                    {
                        Package = q.Key,
                        Amount = q.Sum(y => y.amount),
                        ApprovedQuantity = q.Sum(y => y.quantityBooked)
                    });
                    var total = 0;
                    var List  = new List <string>();
                    foreach (var item in getPoints)
                    {
                        var Idx = chart1.Series[0].Points.AddY(item.ApprovedQuantity);
                        chart1.Series[0].Points[Idx].AxisLabel = item.Package;
                        total += Convert.ToInt32(item.Amount);
                        List.Add(item.Package);
                    }
                    lblTotalValue.Text = total.ToString();
                }
            }
            else
            {
                using (var context = new Session2Entities1())
                {
                    var getPoints = (from x in context.Bookings
                                     where x.status == "Accepted"
                                     group new { amount = x.Package.packageValue * x.quantityBooked, quantityBooked = x.quantityBooked } by x.Package.packageName into q
                                     select new
                    {
                        Package = q.Key,
                        Amount = q.Sum(y => y.amount),
                        ApprovedQuantity = q.Sum(y => y.quantityBooked)
                    });
                    var total = 0;
                    var List  = new List <string>();
                    foreach (var item in getPoints)
                    {
                        var Idx = chart1.Series[0].Points.AddY(item.ApprovedQuantity);
                        chart1.Series[0].Points[Idx].AxisLabel = item.Package;
                        total += Convert.ToInt32(item.Amount);
                        List.Add(item.Package);
                    }
                    lblTotalValue.Text = total.ToString();
                }
            }
        }
        //When the Tier radio button is checked, refresh the DGV again accord to Tier Gold, Silver then Bronze order
        private void tierBtn_CheckedChanged_1(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            var order = new Dictionary <string, int>()
            {
                { "Gold", 1 },
                { "Silver", 2 }, { "Bronze", 3 }
            };

            using (var context = new Session2Entities1())
            {
                var getPackages = (from x in context.Packages
                                   select new { x }).ToList();

                var results = getPackages.OrderBy(x => order[x.x.packageTier]).AsQueryable();
                foreach (var item in results)
                {
                    List <string> rows = new List <string>()
                    {
                        item.x.packageTier, item.x.packageName, item.x.packageValue.ToString(),
                        item.x.packageQuantity.ToString()
                    };

                    var getBenefits = (from x in context.Benefits
                                       where x.packageIdFK == item.x.packageId
                                       select x.benefitName).ToList();

                    if (getBenefits.FirstOrDefault() == "Online")
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    if (getBenefits.Contains("Flyer"))
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    if (getBenefits.Contains("Banner"))
                    {
                        rows.Add("Yes");
                    }
                    else
                    {
                        rows.Add("");
                    }
                    dataGridView1.Rows.Add(rows.ToArray());
                }
            }
        }
        //When the Quantity radio button is checked, refresh the DGV again by descending quantity of packages order
        private void quantityBtn_CheckedChanged(object sender, EventArgs e)
        {
            if (quantityBtn.Checked)
            {
                dataGridView1.Rows.Clear();
                using (var context = new Session2Entities1())
                {
                    var getPackages = (from x in context.Packages
                                       orderby x.packageValue
                                       select x).ToList();

                    var results = getPackages.OrderByDescending(x => x.packageQuantity).AsQueryable();
                    foreach (var item in results)
                    {
                        List <string> rows = new List <string>()
                        {
                            item.packageTier, item.packageName, item.packageValue.ToString(),
                            item.packageQuantity.ToString()
                        };

                        var getBenefits = (from x in context.Benefits
                                           where x.packageIdFK == item.packageId
                                           select x.benefitName).ToList();

                        if (getBenefits.FirstOrDefault() == "Online")
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Flyer"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Banner"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        dataGridView1.Rows.Add(rows.ToArray());
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Triggered when the Book button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bookBtn_Click(object sender, EventArgs e)
        {
            //Check if any row is selected at all
            if (dataGridView1.CurrentRow == null)
            {
                MessageBox.Show("Please select a package to book!",
                                "No Package selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //Check if user keyed in any invalid amount of packages (0 or less)
                if (Int32.Parse(quantityBox.Text) <= 0)
                {
                    MessageBox.Show("Please key in a valid amount", "Invalid amount", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                var getValueAfterBooking = Convert.ToInt32(dataGridView1.CurrentRow.Cells[3].Value);

                //Check with DB if amount to book is available for the User
                if (getValueAfterBooking - Int32.Parse(quantityBox.Text) < 0)
                {
                    MessageBox.Show("Unable to book more than current available quantity!", "Invalid amount", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                else
                {
                    //Else, add details of booking to DB
                    using (var context = new Session2Entities1())
                    {
                        var packageName  = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                        var getPackageID = (from x in context.Packages
                                            where x.packageName == packageName
                                            select x.packageId).FirstOrDefault();
                        context.Bookings.Add(new Booking()
                        {
                            packageIdFK    = getPackageID,
                            userIdFK       = _userID,
                            quantityBooked = Int32.Parse(quantityBox.Text),
                            status         = "Pending"
                        });
                        context.SaveChanges();
                        dataGridView1.Rows.Clear();
                        GridRefresh();
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Triggered when update button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void updateBtn_Click(object sender, EventArgs e)
        {
            //Check if quantity to update is valid
            if (Int32.Parse(quantityBox.Text) <= 0)
            {
                MessageBox.Show("Quantity cannot be less than or equals to 0!", "Invalid Amount!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (var context = new Session2Entities1())
                {
                    //For each selected rows...
                    foreach (DataGridViewRow item in dataGridView1.SelectedRows)
                    {
                        var getBookingId = Convert.ToInt32(item.Cells[5].Value);
                        var checkPackage = (from x in context.Bookings
                                            where x.bookingId == getBookingId
                                            join y in context.Packages on x.packageIdFK equals y.packageId
                                            select y.packageQuantity).First();

                        //Check if the DB still have enough packages for update
                        if ((checkPackage - Int32.Parse(quantityBox.Text)) < 0)
                        {
                            MessageBox.Show("Cannot update quantity as Package quantity will hit negative!",
                                            "Not enough packages", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        //Else proceed with update and change status back to "Pending" for Manager to approve again
                        else
                        {
                            var UpdateBooking = (from x in context.Bookings
                                                 where x.bookingId == getBookingId
                                                 select x).First();
                            UpdateBooking.quantityBooked = Int32.Parse(quantityBox.Text);
                            UpdateBooking.status         = "Pending";
                            context.SaveChanges();
                        }
                        dataGridView1.Rows.Clear();
                        GridRefresh();
                    }
                }
            }
        }
Beispiel #12
0
        private void Book_Load(object sender, EventArgs e)
        {
            #region Populating Tier Combo box for filtering
            HashSet <string> Tiers = new HashSet <string>();
            tierBox.Items.Add("No Sorting");
            using (var context = new Session2Entities1())
            {
                var getTiers = (from x in context.Packages
                                select x.packageTier).Distinct();
                foreach (var item in getTiers)
                {
                    Tiers.Add(item);
                }
                tierBox.Items.AddRange(Tiers.ToArray());
            }
            #endregion

            //Initial DGV loading with no filter yet selected
            GridRefresh();
        }
        private void ViewSummary_Load(object sender, EventArgs e)
        {
            #region Loading Tier Combo box for filtering
            cbTier.Items.Add("No Filter");
            using (var context = new Session2Entities1())
            {
                var getTiers = (from x in context.Packages
                                select x.packageTier);
                var tiers = new HashSet <string>();
                foreach (var item in getTiers)
                {
                    tiers.Add(item);
                }
                cbTier.Items.AddRange(tiers.ToArray());
            }
            #endregion

            //Loads initial Pie Chart with no filtering
            loadPie();
        }
Beispiel #14
0
 /// <summary>
 /// When clicked, reads CSV file and relatively assign them to DB in the correct
 /// fields. Also checks if Package exist. If it does, it will skip the package and go on to the next
 /// record in the CSV file
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnUpload_Click(object sender, EventArgs e)
 {
     if (txtFilePath.Text.Trim() != "")
     {
         string[] lines = File.ReadAllLines(txtFilePath.Text);
         for (int i = 1; i < lines.Count(); i++)
         {
             var values = lines[i].Split(',');
             using (var context = new Session2Entities1())
             {
                 var name         = values[1];
                 var checkIfExist = (from x in context.Packages
                                     where x.packageName == name
                                     select x).FirstOrDefault();
                 if (checkIfExist == null)
                 {
                     context.Packages.Add(new Package()
                     {
                         packageTier     = values[0],
                         packageName     = values[1],
                         packageValue    = Int32.Parse(values[2]),
                         packageQuantity = Int32.Parse(values[3])
                     });
                     context.SaveChanges();
                     MessageBox.Show("Packages added!", "Successful upload",
                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
                     txtFilePath.Text = "";
                 }
                 else
                 {
                     continue;
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Please input a file path!", "No file detected",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #15
0
        /// <summary>
        /// When Accept button is clicked, VadChecks run through all selected rows check if approving
        /// the packages will make value in DB negative. Else, it will approve bookings and increases quantity booked for the packages in DB.
        /// Once accepted, refreshes DGV
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("Please select at least one row", "No rows selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                foreach (DataGridViewRow item in dataGridView1.SelectedRows)
                {
                    var getBookingID = Convert.ToInt32(item.Cells[3].Value);
                    using (var context = new Session2Entities1())
                    {
                        var getUpdate = (from x in context.Bookings
                                         where x.bookingId == getBookingID
                                         select x).First();

                        var checkQuantity = (from x in context.Bookings
                                             where x.bookingId == getBookingID
                                             join y in context.Packages on x.packageIdFK equals y.packageId
                                             select y).First();

                        if ((checkQuantity.packageQuantity - getUpdate.quantityBooked) < 0)
                        {
                            MessageBox.Show($"{checkQuantity.packageName} amount will be negative if this is approved!",
                                            "Unable to approve", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            checkQuantity.packageQuantity -= getUpdate.quantityBooked;
                            getUpdate.status = "Accepted";
                            context.SaveChanges();
                        }
                    }
                }
                dataGridView1.Rows.Clear();
                GridRefresh();
            }
        }
Beispiel #16
0
 /// <summary>
 /// Triggered when Banner Checkbox is checked, then remove rows of irrelevant information that doesn't have Online as a benefit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void bannerBox_CheckedChanged(object sender, EventArgs e)
 {
     if (bannerBox.Checked)
     {
         var index = new List <DataGridViewRow>();
         foreach (DataGridViewRow item in dataGridView1.Rows)
         {
             using (var context = new Session2Entities1())
             {
                 var packageName   = item.Cells[1].Value.ToString();
                 var checkBenefits = (from x in context.Packages
                                      where x.packageName == packageName
                                      select x.packageId).First();
                 var getBenefits = (from x in context.Benefits
                                    where x.packageIdFK == checkBenefits
                                    select x.benefitName).ToList();
                 if (getBenefits.Contains("Banner"))
                 {
                     continue;
                 }
                 else
                 {
                     index.Add(item);
                 }
             }
         }
         foreach (var item in index)
         {
             dataGridView1.Rows.Remove(item);
         }
     }
     else if (!flyersBox.Checked && !onlineBox.Checked)
     {
         dataGridView1.Rows.Clear();
         GridRefresh();
     }
 }
Beispiel #17
0
        private void createBtn_Click(object sender, EventArgs e)
        {
            //Checks if company name field is empty
            if (companyNameBox.Text.Trim() == "")
            {
                MessageBox.Show("Company Name is required!", "Missing Company Name",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Checks if User ID is empty
            else if (userIDBox.TextLength < 8)
            {
                MessageBox.Show("User ID must have a minimum of 8 characters!", "User ID too short",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Checks if both password field or re-enter password field is empty
            else if (passwordBox.Text.Trim() == "" || rePasswordBox.Text.Trim() == "")
            {
                MessageBox.Show("Please check your password fields!", "Empty password field(s)",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Checks if both password field and re-enter field is the same
            else if (rePasswordBox.Text != passwordBox.Text)
            {
                MessageBox.Show("Password does not match!", "Mismatched passwords",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                using (var context = new Session2Entities1())
                {
                    var checkForPossibleAccount = (from x in context.Users
                                                   where x.name == companyNameBox.Text.Trim()
                                                   select x).FirstOrDefault();
                    var checkUserID = (from x in context.Users
                                       where x.userId == userIDBox.Text
                                       select x).FirstOrDefault();

                    //Check if company already has an account
                    if (checkForPossibleAccount != null)
                    {
                        MessageBox.Show("Your current company already has a sponsor account!", "Unable to create an account",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    //Check if User ID has been used
                    else if (checkUserID != null)
                    {
                        MessageBox.Show("User ID has been used!", "Unable to create an account",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    //Else if all checks passed, add details of new account to DB
                    else
                    {
                        context.Users.Add(new User()
                        {
                            name         = companyNameBox.Text.Trim(),
                            passwd       = passwordBox.Text,
                            userId       = userIDBox.Text,
                            userTypeIdFK = 2
                        });
                        context.SaveChanges();
                        this.Hide();
                        (new Login()).ShowDialog();
                        this.Close();
                    }
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// Whenever User keys in an amount, filter through DGV to get relevant prices that suits budget
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void budgetBox_TextChanged(object sender, EventArgs e)
        {
            if (budgetBox.Text.Trim() != "")
            {
                dataGridView1.Rows.Clear();
                using (var context = new Session2Entities1())
                {
                    var getValue    = Int32.Parse(budgetBox.Text);
                    var getRelevant = (from x in context.Packages
                                       where x.packageValue <= getValue
                                       where x.packageQuantity >= 0
                                       select x.packageName).Distinct();
                    foreach (var item in getRelevant)
                    {
                        var checkBenefits = (from x in context.Benefits
                                             where x.Package.packageName == item
                                             select x).FirstOrDefault();
                        if (checkBenefits != null)
                        {
                            var getPackages1 = (from x in context.Packages
                                                join y in context.Benefits on x.packageId equals y.packageIdFK
                                                where x.packageName == item
                                                select x).FirstOrDefault();
                            List <string> rows = new List <string>()
                            {
                                getPackages1.packageTier, getPackages1.packageName, getPackages1.packageValue.ToString(),
                                getPackages1.packageQuantity.ToString()
                            };
                            List <string> vs = new List <string>();
                            foreach (var item1 in getPackages1.Benefits.Where(x => x.packageIdFK == getPackages1.packageId).Select(x => x.benefitName))
                            {
                                vs.Add(item1);
                            }
                            if (vs[0] == "Online")
                            {
                                rows.Add("Yes");
                            }
                            else
                            {
                                rows.Add("");
                            }
                            if (vs.Contains("Flyer"))
                            {
                                rows.Add("Yes");
                            }
                            else
                            {
                                rows.Add("");
                            }
                            if (vs.Contains("Banner"))
                            {
                                rows.Add("Yes");
                            }
                            else
                            {
                                rows.Add("");
                            }

                            dataGridView1.Rows.Add(rows.ToArray());
                            if (onlineBox.Checked)
                            {
                                onlineBox_CheckedChanged(null, null);
                            }
                            else if (flyersBox.Checked)
                            {
                                flyersBox_CheckedChanged(null, null);
                            }
                            else if (bannerBox.Checked)
                            {
                                bannerBox_CheckedChanged(null, null);
                            }
                        }
                        else
                        {
                            var getPackages1 = (from x in context.Packages
                                                where x.packageName == item
                                                select x).FirstOrDefault();
                            List <string> rows = new List <string>()
                            {
                                getPackages1.packageTier, getPackages1.packageName, getPackages1.packageValue.ToString(),
                                getPackages1.packageQuantity.ToString()
                            };

                            rows.Add("");
                            rows.Add("");
                            rows.Add("");

                            dataGridView1.Rows.Add(rows.ToArray());
                            if (onlineBox.Checked)
                            {
                                onlineBox_CheckedChanged(null, null);
                            }
                            else if (flyersBox.Checked)
                            {
                                flyersBox_CheckedChanged(null, null);
                            }
                            else if (bannerBox.Checked)
                            {
                                bannerBox_CheckedChanged(null, null);
                            }
                        }
                    }
                }
            }
            else
            {
                dataGridView1.Rows.Clear();
                GridRefresh();
            }
        }
Beispiel #19
0
        private void GridRefresh()
        {
            #region Main DGV settings and column additions
            dataGridView1.ReadOnly        = true;
            dataGridView1.ColumnCount     = 7;
            dataGridView1.Columns[0].Name = "Tier";
            dataGridView1.Columns[1].Name = "Name";
            dataGridView1.Columns[2].Name = "Value ($)";
            dataGridView1.Columns[3].Name = "Available Qty";
            dataGridView1.Columns[4].Name = "Online";
            dataGridView1.Columns[5].Name = "Flyers";
            dataGridView1.Columns[6].Name = "Banner";
            #endregion

            using (var context = new Session2Entities1())
            {
                if (tierBox.SelectedItem != null && tierBox.SelectedItem.ToString() != "No Sorting")
                {
                    var getSelectedTier = tierBox.SelectedItem.ToString();
                    var getPackages     = (from x in context.Packages
                                           where x.packageQuantity > 0
                                           where x.packageTier == getSelectedTier
                                           select new { x });

                    //For every distinct package name...
                    foreach (var item in getPackages.Select(x => x.x.packageName).Distinct())
                    {
                        var getPackageInfo = (from x in context.Packages
                                              where x.packageName == item
                                              select x).First();
                        List <string> rows = new List <string>()
                        {
                            getPackageInfo.packageTier, getPackageInfo.packageName, getPackageInfo.packageValue.ToString(),
                            getPackageInfo.packageQuantity.ToString()
                        };

                        //Getting benefits of current queried package and putting all benefits to list
                        var getBenefits = (from x in context.Benefits
                                           where x.packageIdFK == getPackageInfo.packageId
                                           select x.benefitName).ToList();

                        ///Since Online Benefits comes first followed by Flyer then Banner.
                        ///getBenefits.FirstOrDefault to check if Online as a benefit exist, then check if the list contains
                        ///Flyer first, then Banner
                        if (getBenefits.FirstOrDefault() == "Online")
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Flyer"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Banner"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        dataGridView1.Rows.Add(rows.ToArray());
                    }
                }

                else
                {
                    var getPackages = (from x in context.Packages
                                       where x.packageQuantity > 0
                                       select new { x });

                    //For every distinct package name...
                    foreach (var item in getPackages.Select(x => x.x.packageName).Distinct())
                    {
                        var getPackageInfo = (from x in context.Packages
                                              where x.packageName == item
                                              select x).First();
                        List <string> rows = new List <string>()
                        {
                            getPackageInfo.packageTier, getPackageInfo.packageName, getPackageInfo.packageValue.ToString(),
                            getPackageInfo.packageQuantity.ToString()
                        };

                        //Getting benefits of current queried package and putting all benefits to list
                        var getBenefits = (from x in context.Benefits
                                           where x.packageIdFK == getPackageInfo.packageId
                                           select x.benefitName).ToList();

                        ///Since Online Benefits comes first followed by Flyer then Banner.
                        ///getBenefits.FirstOrDefault to check if Online as a benefit exist, then check if the list contains
                        ///Flyer first, then Banner
                        if (getBenefits.FirstOrDefault() == "Online")
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Flyer"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        if (getBenefits.Contains("Banner"))
                        {
                            rows.Add("Yes");
                        }
                        else
                        {
                            rows.Add("");
                        }
                        dataGridView1.Rows.Add(rows.ToArray());
                    }
                }
            }
        }
Beispiel #20
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            using (var context = new Session2Entities1())
            {
                //Checks if User ID field is empty
                if (userIDBox.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter your User ID!", "Empty User ID",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //Checks if password field is empty
                else if (passwordBox.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter your Password!", "Empty password",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var getUser = (from x in context.Users
                                   where x.userId.Equals(userIDBox.Text)
                                   select x).FirstOrDefault();

                    //Check if User even exist in DB
                    if (getUser == null)
                    {
                        MessageBox.Show("User does not exist!", "Invalid Login details",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    //Check if entered password matches the intended account's password
                    else if (getUser.passwd != passwordBox.Text)
                    {
                        MessageBox.Show("Password is incorrect!", "Invalid Login details",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        var getUserType   = getUser.userTypeIdFK;
                        var findManagerID = (from x in context.User_Type
                                             where x.userTypeName == "Manager"
                                             select x.userTypeId).First();

                        var findSponsorID = (from x in context.User_Type
                                             where x.userTypeName == "Sponsor"
                                             select x.userTypeId).First();

                        //Check if account type is "Manager" and redirect to the Manager's Main Menu - 2.4
                        if (getUser.userTypeIdFK == findManagerID)
                        {
                            MessageBox.Show($"Welcome {getUser.name}!", "Successful login",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                            (new ManagerMain()).ShowDialog();
                            this.Close();
                        }

                        //Else redirect to Sponsor's Main Menu - 2.3
                        else
                        {
                            MessageBox.Show($"Welcome {getUser.name}!", "Successful login",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                            (new SponsorMain(getUser.userId)).ShowDialog();
                            this.Close();
                        }
                    }
                }
            }
        }
Beispiel #21
0
 /// <summary>
 /// When clicked, runs the appropiate VadChecks like empty fields,
 /// invalid data entry, checking with DB to make sure no duplicates. When all VadChecks are passed,
 /// then add the new package(s) to DB
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtPackageName.Text.Trim() == "" || txtValue.Text.Trim() == "" || txtAvailabeQuantity.Text.Trim() == "" || cbTier.SelectedItem == null)
         {
             MessageBox.Show("Please check your entries!", "Empty Field(s)", MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
         else
         {
             using (var context = new Session2Entities1())
             {
                 var checkName = (from x in context.Packages
                                  where x.packageName == txtPackageName.Text
                                  select x).FirstOrDefault();
                 if (checkName != null)
                 {
                     MessageBox.Show("Package name has been used!", "Used Package Name", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
                 }
                 else
                 {
                     if (cbTier.SelectedItem.ToString() == "Bronze" && (Int32.Parse(txtValue.Text) > 10000 || Int32.Parse(txtValue.Text) <= 0))
                     {
                         MessageBox.Show("Invalid value for Bronze Tier! Valid value ranges from > $0 and less than or equals to $10,000", "Invalid Value for Package Tier", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
                     }
                     else if (cbTier.SelectedItem.ToString() == "Silver" && (Int32.Parse(txtValue.Text) <= 10000 || Int32.Parse(txtValue.Text) > 50000 || Int32.Parse(txtValue.Text) <= 0))
                     {
                         MessageBox.Show("Invalid value for Silver Tier! Valid value ranges from > $10,000 and less than or equals to $50,000", "Invalid Value for Package Tier", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
                     }
                     else if (cbTier.SelectedItem.ToString() == "Gold" && (Int32.Parse(txtValue.Text) <= 50000 || Int32.Parse(txtValue.Text) <= 0))
                     {
                         MessageBox.Show("Invalid value for Gold Tier! Valid value ranges from > $50,000", "Invalid Value for Package Tier", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
                     }
                     else if (Int32.Parse(txtAvailabeQuantity.Text) <= 0)
                     {
                         MessageBox.Show("Package quantity must be more than 0!", "Invalid amount", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
                     }
                     else if (cbTier.SelectedItem.ToString() == "Bronze" && clbBenefits.CheckedItems.Count != 1)
                     {
                         MessageBox.Show("Bronze Tier packages should have only 1 benefit!", "Invalid number of benefits",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     else if (cbTier.SelectedItem.ToString() == "Silver" && clbBenefits.CheckedItems.Count != 2)
                     {
                         MessageBox.Show("Silver Tier packages should have only 2 benefits!", "Invalid number of benefits",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     else if (cbTier.SelectedItem.ToString() == "Gold" && clbBenefits.CheckedItems.Count != 3)
                     {
                         MessageBox.Show("Gold Tier packages should have only 3 benefits!", "Invalid number of benefits",
                                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                     else
                     {
                         var getNewID = (from x in context.Packages
                                         orderby x.packageId descending
                                         select x.packageId).First() + 1;
                         context.Packages.Add(new Package()
                         {
                             packageId       = getNewID,
                             packageName     = txtPackageName.Text,
                             packageTier     = cbTier.SelectedItem.ToString(),
                             packageQuantity = Int32.Parse(txtAvailabeQuantity.Text),
                             packageValue    = Int32.Parse(txtValue.Text)
                         });
                         foreach (var item in _list)
                         {
                             context.Benefits.Add(new Benefit()
                             {
                                 packageIdFK = getNewID,
                                 benefitName = item
                             });
                         }
                         context.SaveChanges();
                         MessageBox.Show("Package has been added successfully!", "Successful addition of package",
                                         MessageBoxButtons.OK, MessageBoxIcon.Information);
                         this.Hide();
                         (new ManagerMain()).ShowDialog();
                         this.Close();
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Please check your entries!", "Invalid input detected", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }