Exemple #1
0
 private void btnBook_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select your package you wish to book!");
     }
     else
     {
         using (var context = new Session2Entities())
         {
             var packageID     = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
             var checkQuantity = (from x in context.Packages
                                  where x.packageId == packageID
                                  select x).FirstOrDefault();
             if (checkQuantity.packageQuantity < nudDesiredQuantity.Value)
             {
                 MessageBox.Show("Not enough package quantity!");
             }
             else
             {
                 context.Bookings.Add(new Booking()
                 {
                     packageIdFK = packageID, quantityBooked = Convert.ToInt32(nudDesiredQuantity.Value), status = "Pending", userIdFK = _user.userId
                 });
                 context.SaveChanges();
                 MessageBox.Show("Package booked successfully!");
             }
         }
     }
 }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a booking to update!");
     }
     else
     {
         using (var context = new Session2Entities())
         {
             var getBookingID      = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
             var getBookingDetails = (from x in context.Bookings
                                      where x.bookingId == getBookingID
                                      select x).FirstOrDefault();
             if (getBookingDetails.Package.packageQuantity + getBookingDetails.quantityBooked < nudNewQuantity.Value)
             {
                 MessageBox.Show("Package will not have enough stock for new updated quantity!");
             }
             else
             {
                 var getPackage = (from x in context.Packages
                                   where x.packageId == getBookingDetails.packageIdFK
                                   select x).FirstOrDefault();
                 getPackage.packageQuantity += getBookingDetails.quantityBooked;
                 context.SaveChanges();
                 getBookingDetails.quantityBooked = Convert.ToInt32(nudNewQuantity.Value);
                 getBookingDetails.status         = "Pending";
                 context.SaveChanges();
                 MessageBox.Show("Update booking completed!");
             }
         }
     }
 }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentRow == null)
     {
         MessageBox.Show("Please select a booking to delete!");
     }
     else
     {
         var response = MessageBox.Show("Are you sure you want to delete this booking?", "Delete", MessageBoxButtons.YesNo);
         if (response == DialogResult.Yes)
         {
             var getBookingID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
             using (var context = new Session2Entities())
             {
                 var getBookingDelete = (from x in context.Bookings
                                         where x.bookingId == getBookingID
                                         select x).FirstOrDefault();
                 var updateQuantity = (from x in context.Packages
                                       where x.packageId == getBookingDelete.packageIdFK
                                       select x).FirstOrDefault();
                 updateQuantity.packageQuantity += getBookingDelete.quantityBooked;
                 context.SaveChanges();
                 context.Bookings.Remove(getBookingDelete);
                 context.SaveChanges();
                 MessageBox.Show("Booking deleted successfully!");
                 dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
             }
         }
     }
 }
Exemple #4
0
 private void LoadPicker()
 {
     cbTier.Items.Clear();
     cbTier.Items.Add("No Filter");
     using (var context = new Session2Entities())
     {
         var tierList = (from x in context.Packages
                         select x.packageTier).Distinct().ToArray();
         cbTier.Items.AddRange(tierList);
     }
 }
Exemple #5
0
        private void LoadData()
        {
            dataGridView1.Rows.Clear();
            using (var context = new Session2Entities())
            {
                var getPackages = (from x in context.Packages
                                   where x.packageQuantity != 0
                                   select x);

                foreach (var item in getPackages)
                {
                    var newRow = new List <string>()
                    {
                        item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                    };
                    var checkBenefits = (from x in context.Benefits
                                         where x.packageIdFK == item.packageId
                                         select x.benefitName).ToList();
                    if (checkBenefits.Contains("Online"))
                    {
                        newRow.Add("Yes");
                    }
                    else
                    {
                        newRow.Add("");
                    }
                    if (checkBenefits.Contains("Flyer"))
                    {
                        newRow.Add("Yes");
                    }
                    else
                    {
                        newRow.Add("");
                    }
                    if (checkBenefits.Contains("Banner"))
                    {
                        newRow.Add("Yes");
                    }
                    else
                    {
                        newRow.Add("");
                    }
                    dataGridView1.Rows.Add(newRow.ToArray());
                }
            }
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                _originalSource.Add(item);
                _modifiedSource.Clear();
            }
        }
Exemple #6
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (txtCompanyName.Text.Trim() == string.Empty || txtUserID.Text.Trim() == string.Empty || txtPassword.Text.Trim() == string.Empty || txtReEnterPassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("One of more fields are empty!");
            }
            else if (txtPassword.TextLength < 8)
            {
                MessageBox.Show("Password must be 8 characters or more!");
            }
            else if (txtPassword.Text != txtReEnterPassword.Text)
            {
                MessageBox.Show("Passwords do not match!");
            }
            else
            {
                using (var context = new Session2Entities())
                {
                    var checkUser = (from x in context.Users
                                     where x.name == txtCompanyName.Text
                                     select x).FirstOrDefault();

                    var checkUserID = (from x in context.Users
                                       where x.userId == txtUserID.Text
                                       select x).FirstOrDefault();

                    if (checkUser != null)
                    {
                        MessageBox.Show("Company sponsor account already exist!");
                    }
                    else if (checkUserID != null)
                    {
                        MessageBox.Show("User ID has been taken!");
                    }
                    else
                    {
                        context.Users.Add(new User()
                        {
                            name = txtCompanyName.Text, userId = txtUserID.Text, passwd = txtReEnterPassword.Text, userTypeIdFK = 2
                        });
                        context.SaveChanges();
                    }
                }
            }
        }
Exemple #7
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserID.Text.Trim() == string.Empty || txtPassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("One or more fields are empty!");
            }
            else
            {
                using (var context = new Session2Entities())
                {
                    var user = (from x in context.Users
                                where x.userId == txtUserID.Text
                                select x).FirstOrDefault();

                    if (user == null)
                    {
                        MessageBox.Show("User does not exit!");
                    }
                    else if (user.passwd != txtPassword.Text)
                    {
                        MessageBox.Show("Password incorrect!");
                    }
                    else
                    {
                        MessageBox.Show("Login successful!");
                        if (user.userTypeIdFK == 1)
                        {
                            this.Hide();
                            (new SponsorManagerMain()).ShowDialog();
                            this.Close();
                        }
                        else
                        {
                            this.Hide();
                            (new SponsorMain(user)).ShowDialog();
                            this.Close();
                        }
                    }
                }
            }
        }
 private void LoadBookings()
 {
     using (var context = new Session2Entities())
     {
         var getBookingsUser = (from x in context.Bookings
                                where x.userIdFK == _user.userId
                                where x.status != "Pending"
                                select x);
         foreach (var item in getBookingsUser)
         {
             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());
         }
         int total = 0;
         foreach (DataGridViewRow item in dataGridView1.Rows)
         {
             total += Convert.ToInt32(item.Cells[5].Value);
         }
         lblTotalValue.Text = total.ToString();
     }
 }
Exemple #9
0
        private void ViewPackages_Load(object sender, EventArgs e)
        {
            using (var context = new Session2Entities())
            {
                dataGridView1.Rows.Clear();
                var getPackages = (from x in context.Packages
                                   select x);
                if (rbTier.Checked)
                {
                    var sortedTiers = getPackages.OrderByDescending(x => x.packageTier == "Gold").ThenByDescending(x => x.packageTier == "Silver").ThenByDescending(x => x.packageTier == "Bronze");

                    foreach (var item in sortedTiers)
                    {
                        var newRow = new List <string>()
                        {
                            item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                        };
                        var checkBenefits = (from x in context.Benefits
                                             where x.packageIdFK == item.packageId
                                             select x.benefitName).ToList();
                        if (checkBenefits.Contains("Online"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Flyer"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Banner"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
                else if (rbName.Checked)
                {
                    var sortedName = getPackages.OrderBy(x => x.packageName);

                    foreach (var item in sortedName)
                    {
                        var newRow = new List <string>()
                        {
                            item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                        };
                        var checkBenefits = (from x in context.Benefits
                                             where x.packageIdFK == item.packageId
                                             select x.benefitName).ToList();
                        if (checkBenefits.Contains("Online"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Flyer"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Banner"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
                else if (rbvalue.Checked)
                {
                    var sortedValue = getPackages.OrderBy(x => x.packageValue);

                    foreach (var item in sortedValue)
                    {
                        var newRow = new List <string>()
                        {
                            item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                        };
                        var checkBenefits = (from x in context.Benefits
                                             where x.packageIdFK == item.packageId
                                             select x.benefitName).ToList();
                        if (checkBenefits.Contains("Online"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Flyer"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Banner"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
                else if (rbQuantity.Checked)
                {
                    var sortedQuantity = getPackages.OrderByDescending(x => x.packageQuantity);

                    foreach (var item in sortedQuantity)
                    {
                        var newRow = new List <string>()
                        {
                            item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                        };
                        var checkBenefits = (from x in context.Benefits
                                             where x.packageIdFK == item.packageId
                                             select x.benefitName).ToList();
                        if (checkBenefits.Contains("Online"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Flyer"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Banner"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
                else
                {
                    foreach (var item in getPackages)
                    {
                        var newRow = new List <string>()
                        {
                            item.packageId.ToString(), item.packageTier, item.packageName, item.packageValue.ToString(), item.packageQuantity.ToString()
                        };
                        var checkBenefits = (from x in context.Benefits
                                             where x.packageIdFK == item.packageId
                                             select x.benefitName).ToList();
                        if (checkBenefits.Contains("Online"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Flyer"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        if (checkBenefits.Contains("Banner"))
                        {
                            newRow.Add("Yes");
                        }
                        else
                        {
                            newRow.Add("");
                        }
                        dataGridView1.Rows.Add(newRow.ToArray());
                    }
                }
            }
        }