Exemplo n.º 1
0
 private async void Delete_button_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("This action is irreversible!!", "Are you sure? ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         using (var db = new Session2Entities())
         {
             try
             {
                 var list = dgvlist[dataGridView1.SelectedRows[0].Index];
                 var item = (from i in db.Packages
                             where i.packageId == list.ID
                             select i).First();
                 var booking = (from c in db.Bookings
                                where c.packageIdFK == item.packageId
                                where c.userIdFK == UserID
                                select c).First();
                 db.Bookings.Remove(booking);
                 await db.SaveChangesAsync();
             }
             catch
             {
             }
         }
         dgvlist.RemoveAt(dataGridView1.SelectedRows[0].Index);
         UpdateUI();
     }
 }
Exemplo n.º 2
0
        private void Management_Load(object sender, EventArgs e)
        {
            assetList.ColumnCount        = 6;
            assetList.Columns[0].Name    = "Asset SN";
            assetList.Columns[1].Name    = "Asset Name";
            assetList.Columns[2].Name    = "Request Date";
            assetList.Columns[3].Name    = "Employee Full Name";
            assetList.Columns[4].Name    = "Department";
            assetList.Columns[5].Name    = "Asset ID";
            assetList.Columns[5].Visible = false;
            Object[] rows = new Object[6];

            using (var context = new Session2Entities())
            {
                var queryAsset = (from x in context.EmergencyMaintenances
                                  where x.EMEndDate != null
                                  join y in context.Assets on x.AssetID equals y.ID
                                  join z in context.Employees on y.EmployeeID equals z.ID
                                  join a in context.DepartmentLocations on y.DepartmentLocationID equals a.ID
                                  join b in context.Departments on a.DepartmentID equals b.ID
                                  orderby x.PriorityID, x.EMReportDate descending
                                  select new { x, y, z, a, b });

                foreach (var item in queryAsset)
                {
                    rows[0] = item.y.AssetSN;
                    rows[1] = item.y.AssetName;
                    rows[2] = item.x.EMReportDate;
                    rows[3] = item.z.FirstName + " " + item.z.LastName;
                    rows[4] = item.b.Name;
                    rows[5] = item.y.ID;
                    assetList.Rows.Add(rows);
                }
            }
        }
Exemplo n.º 3
0
 private void sendBtn_Click(object sender, EventArgs e)
 {
     using (var context = new Session2Entities())
     {
         var findPriority = (from x in context.Priorities
                             where priorityBox.SelectedItem.Equals($"{x.Name}")
                             select x.ID).FirstOrDefault();
         if (emergencyDescription.Text == "")
         {
             MessageBox.Show("Please input emergency details", "Missing details", MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
         else
         {
             context.EmergencyMaintenances.Add(new EmergencyMaintenance()
             {
                 AssetID              = assetID,
                 PriorityID           = findPriority,
                 DescriptionEmergency = emergencyDescription.Text,
                 OtherConsiderations  = considerationBox.Text,
                 EMReportDate         = DateTime.Now
             });
             context.SaveChanges();
             this.Hide();
             (new AccountableM(employeeID)).ShowDialog();
             this.Close();
         }
     }
 }
Exemplo n.º 4
0
 private async void Approve_button_Click(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         var id      = dgvlist[dataGridView1.SelectedRows[0].Index].ID;
         var name    = dgvlist[dataGridView1.SelectedRows[0].Index].PackageName;
         var booking = (from d in db.Bookings
                        where d.bookingId == id
                        select d).First();
         var package = (from p in db.Packages
                        where p.packageName == name
                        select p).First();
         if (package.packageQuantity >= booking.quantityBooked)
         {
             package.packageQuantity -= booking.quantityBooked;
             booking.status           = "Approved";
             await db.SaveChangesAsync();
         }
         else
         {
             MessageBox.Show("Insufficient quantity");
         }
     }
     UpdateUI();
 }
        private void Reject_Click(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
                {
                    var ID = int.Parse(dr.Cells[0].Value.ToString());

                    var q = db.Bookings.Where(x => x.bookingId == ID).FirstOrDefault();

                    //Since it is rejected, the amounts will all not minus from the package quantity
                    q.status = "Rejected";
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception es)
                    {
                        MessageBox.Show(es.ToString());
                    }
                }

                var qq = db.Bookings.OrderBy(x => x.status == "Pending" ? 1 : x.status == "Approved" ? 2 : 3).ThenBy(x => x.User.name).ToList();
                dataGridView1.DataSource            = cdt(qq);
                dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.Columns["ID"].Visible = false;
            }
        }
Exemplo n.º 6
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                //checking if there is a user associated with the username and password
                var q = db.Users.Where(x => x.userId == UID.Text && x.passwd == Pass.Text).FirstOrDefault();

                //If no one then get error
                if (q == null)
                {
                    MessageBox.Show("Invalid User!");
                }
                else
                {
                    //Go to their respective menus
                    this.Hide();
                    if (q.User_Type.userTypeName == "Sponsor")
                    {
                        SponserMainMenu sponserMainMenu = new SponserMainMenu(q);
                        sponserMainMenu.Show();
                    }
                    else if (q.User_Type.userTypeName == "Manager")
                    {
                        SponderManagerMainMenu sponderManagerMainMenu = new SponderManagerMainMenu(q);
                        sponderManagerMainMenu.Show();
                    }
                }
            }
        }
Exemplo n.º 7
0
 private void login_button_Click(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         try
         {
             var user = (from u in db.Users
                         where u.userId == login_box.Text
                         where u.passwd == password_box.Text
                         select u).First();
             if (user.userTypeIdFK == 1)
             {
                 //manager
                 this.Hide();
                 var MMM = new MainMenuManager();
                 MMM.Closed += (s, args) => this.Close();
                 MMM.Show();
             }
             else
             {
                 //Sponsor
                 this.Hide();
                 var MMS = new MainMenuSponsor(login_box.Text);
                 MMS.Closed += (s, args) => this.Close();
                 MMS.Show();
             }
         }
         catch
         {
             MessageBox.Show("Invalid Login");
         }
     }
 }
Exemplo n.º 8
0
        private async Task addPackage()
        {
            using (var db = new Session2Entities())
            {
                int packageid = (from d in db.Packages
                                 orderby d.packageId descending
                                 select d.packageId).First() + 1;
                if (Online.Checked)
                {
                    var benefits = new Benefit()
                    {
                        packageIdFK = packageid,
                        benefitId   = (from d in db.Benefits
                                       orderby d.benefitId descending
                                       select d.benefitId).First() + 1,
                        benefitName = "Online"
                    };
                    db.Benefits.Add(benefits);
                }
                if (Flyers.Checked)
                {
                    var benefits = new Benefit()
                    {
                        packageIdFK = packageid,
                        benefitId   = (from d in db.Benefits
                                       orderby d.benefitId descending
                                       select d.benefitId).First() + 1,
                        benefitName = "Flyers"
                    };
                    db.Benefits.Add(benefits);
                }
                if (Banner.Checked)
                {
                    var benefits = new Benefit()
                    {
                        packageIdFK = packageid,
                        benefitId   = (from d in db.Benefits
                                       orderby d.benefitId descending
                                       select d.benefitId).First() + 1,
                        benefitName = "Banner"
                    };
                    db.Benefits.Add(benefits);
                }

                var pa = new Package()
                {
                    packageId       = packageid,
                    packageName     = package_box.Text,
                    packageQuantity = (int)quantity_updown.Value,
                    packageTier     = tier_combo.SelectedItem.ToString(),
                    packageValue    = (int)value_updown.Value
                };
                db.Packages.Add(pa);
                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 9
0
 void removeFilter()
 {
     using (var db = new Session2Entities())
     {
         var q = db.Packages.ToList();
         dataGridView1.DataSource            = CDT(q);
         dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
         dataGridView1.Columns["ID"].Visible = false;
     }
 }
 private void ApproveSponsershipPackages_Load(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         var q = db.Bookings.OrderBy(x => x.status == "Pending" ? 1 : x.status == "Approved" ? 2 : 3).ThenBy(x => x.User.name).ToList();
         dataGridView1.DataSource            = cdt(q);
         dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
         dataGridView1.Columns["ID"].Visible = false;
     }
 }
        DataTable CDT(List <Package> packages)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("ID");
            dt.Columns.Add("Tier");
            dt.Columns.Add("Name");
            dt.Columns.Add("Value ($)");
            dt.Columns.Add("Availabile Qty");
            dt.Columns.Add("Online");
            dt.Columns.Add("Flyer");
            dt.Columns.Add("Banner");
            foreach (var item in packages)
            {
                DataRow dr = dt.NewRow();
                dr["Tier"]      = item.packageTier;
                dr["Name"]      = item.packageName;
                dr["Value ($)"] = item.packageValue;

                //This table should only show available packages, except
                //those that have no quantity left for booking
                if (item.packageQuantity == 0)
                {
                    continue;
                }
                dr["Availabile Qty"] = item.packageQuantity;
                dr["ID"]             = item.packageId;

                using (var db = new Session2Entities())
                {
                    var ID = item.packageId;
                    var q  = db.Benefits.Where(x => x.packageIdFK == ID).ToList();
                    foreach (var itemss in q)
                    {
                        if (itemss.benefitName == "Online")
                        {
                            dr["Online"] = "Yes";
                        }
                        else if (itemss.benefitName == "Flyer")
                        {
                            dr["Flyer"] = "Yes";
                        }
                        else if (itemss.benefitName == "Banner")
                        {
                            dr["Banner"] = "Yes";
                        }
                    }
                }
                dt.Rows.Add(dr);
            }
            return(dt);
        }
Exemplo n.º 12
0
 //The user can, however, choose to view this table in
 //different ways. The user can sort the table according to
 //the tier(from Gold to Silver to Bronze) or by name.The
 //user can also choose to sort the table by the value of
 //each package, either in ascending or descending order.
 private void tier_CheckedChanged(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         if (tier.Checked)
         {
             var q = db.Packages.OrderBy(x => x.packageTier == "Bronze" ? 1: x.packageTier == "Silver" ? 2: 3).ToList();
             dataGridView1.DataSource            = CDT(q);
             dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
             dataGridView1.Columns["ID"].Visible = false;
         }
     }
 }
Exemplo n.º 13
0
 private void QD_CheckedChanged(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         if (QD.Checked)
         {
             var q = db.Packages.OrderByDescending(x => x.packageQuantity).ToList();
             dataGridView1.DataSource            = CDT(q);
             dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
             dataGridView1.Columns["ID"].Visible = false;
         }
     }
 }
        private void BookBtn_Click(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                Booking booking = new Booking();
                booking.userIdFK = users.userId;
                if (dataGridView1.SelectedRows.Count == 1)
                {
                    foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
                    {
                        var ID = int.Parse(dr.Cells["ID"].Value.ToString());
                        booking.packageIdFK = ID;
                        var quan = int.Parse(dr.Cells["Availabile Qty"].Value.ToString());
                        if (quan >= DQ.Value)
                        {
                            booking.quantityBooked = (int)DQ.Value;
                        }
                        else
                        {
                            MessageBox.Show("Invalid Amount!");
                            return;
                        }
                        booking.status = "Pending";
                        db.Bookings.Add(booking);
                        try
                        {
                            db.SaveChanges();

                            //Will hendle this when the manager approves the booking
                            //var q2 = db.Packages.Where(x => x.packageId == ID).FirstOrDefault();
                            //q2.packageQuantity -= (int)DQ.Value;
                            db.SaveChanges();
                            MessageBox.Show("Success!");
                            var q = db.Packages.ToList();
                            dataGridView1.DataSource            = CDT(q);
                            dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
                            dataGridView1.Columns["ID"].Visible = false;
                        }
                        catch (Exception ES)
                        {
                            MessageBox.Show(ES.ToString());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Pick Only 1!");
                    return;
                }
            }
        }
Exemplo n.º 15
0
 private async void Reject_button_Click(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         var id      = dgvlist[dataGridView1.SelectedRows[0].Index].ID;
         var booking = (from d in db.Bookings
                        where d.bookingId == id
                        select d).First();
         db.Bookings.Remove(booking);
         booking.status = "Rejected";
         await db.SaveChangesAsync();
     }
     UpdateUI();
 }
 private void AddSponsershipPackages_Load(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         //The package tier can be Gold, Silver or Bronze only,
         //and users can choose this from a drop‐down list.
         var q = db.Packages.Select(x => x.packageTier).Distinct().OrderBy(x => x == "Bronze" ? 1 : x == "Silver" ? 2 : 3).ToList();
         foreach (var item in q)
         {
             tier.Items.Add(item);
         }
         tier.SelectedItem = 0;
     }
 }
Exemplo n.º 17
0
        private async void book_button_Click(object sender, EventArgs e)
        {
            if (desired_updown.Value == 0)
            {
                MessageBox.Show("Please select a quantity greater than zero");
            }
            else
            {
                if (desired_updown.Value <= int.Parse(dataGridView1.SelectedRows[0].Cells[4].Value.ToString()))
                {
                    using (var db = new Session2Entities())
                    {
                        try
                        {
                            var booking = new Booking()
                            {
                                bookingId = (from b in db.Bookings
                                             orderby b.bookingId descending
                                             select b.bookingId).First() + 1,
                                packageIdFK    = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()),
                                userIdFK       = UserID,
                                quantityBooked = (int)desired_updown.Value,
                                status         = "Pending"
                            };
                            db.Bookings.Add(booking);
                        }
                        catch
                        {
                            var booking = new Booking()
                            {
                                bookingId      = 1,
                                packageIdFK    = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()),
                                userIdFK       = UserID,
                                quantityBooked = (int)desired_updown.Value,
                                status         = "Pending"
                            };
                            db.Bookings.Add(booking);
                        }
                        await db.SaveChangesAsync();

                        MessageBox.Show("DONE!");
                    }
                }
                else
                {
                    MessageBox.Show("Not enough stock!");
                }
            }
        }
Exemplo n.º 18
0
        private void ViewSponserPackages_Load(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                //They can see a table of all the sponsorship packages
                //for this event, including those with zero quantity.

                //When the screen is first loaded, by default, the
                //packages should be sorted by their tier and name
                var q = db.Packages.OrderBy(x => x.packageTier == "Bronze" ? 1 : x.packageTier == "Silver" ? 2 : 3).ThenBy(x => x.packageName).ToList();
                dataGridView1.DataSource            = CDT(q);
                dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.Columns["ID"].Visible = false;
            }
        }
Exemplo n.º 19
0
 private async Task AddUser()
 {
     using (var db = new Session2Entities())
     {
         var user = new User()
         {
             userId       = user_box.Text,
             name         = company_box.Text,
             passwd       = password_box.Text,
             userTypeIdFK = 2
         };
         db.Users.Add(user);
         await db.SaveChangesAsync();
     }
 }
        private void DelBtn_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 1)
            {
                foreach (DataGridViewRow dr in dataGridView1.SelectedRows)
                {
                    var ID       = int.Parse(dr.Cells["ID1"].Value.ToString());
                    var quantity = int.Parse(dr.Cells["Quantity Booked"].Value.ToString());
                    using (var db = new Session2Entities())
                    {
                        var q = db.Bookings.Where(x => x.bookingId == ID).FirstOrDefault();
                        q.Package.packageQuantity += quantity;
                        db.Bookings.Remove(q);

                        try
                        {
                            db.SaveChanges();

                            //This table should only include the package
                            //bookings that the sponsor manager has Approved
                            var q1 = db.Bookings.Where(x => x.userIdFK == users.userId && x.status == "Approved")
                                     //When the screen is loaded, the packages should
                                     //be sorted by their tier and then individual value.
                                     .OrderBy(x => x.Package.packageTier == "Bronze" ? 1 : x.Package.packageTier == "Silver" ? 2 : 3)
                                     .ThenBy(x => x.Package.packageValue)
                                     .ToList();

                            //Once package is updated or deleted, the table should automatically refresh to show the updated
                            //information.
                            dataGridView1.DataSource             = cdt(q1);
                            dataGridView1.SelectionMode          = DataGridViewSelectionMode.FullRowSelect;
                            dataGridView1.Columns["ID1"].Visible = false;
                            TotalVal.Text = val.ToString();
                        }
                        catch (Exception es)
                        {
                            MessageBox.Show(es.ToString());
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("ERROR!");
                return;
            }
        }
Exemplo n.º 21
0
        private void ViewSponsershipSummary_Load(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                var q = db.Packages.Select(x => x.packageTier).Distinct().OrderBy(x => x == "Bronze" ? 1 : x == "Silver" ? 2 : 3).ToList();
                tier.Items.Add("All Tiers");
                foreach (var item in q)
                {
                    tier.Items.Add(item);
                }
                tier.SelectedIndex = 0;

                //This screen only shows the packages that the sponsor
                var qq = db.Bookings.Where(x => x.status == "Approved").ToList();
                addchart(qq);
            }
        }
Exemplo n.º 22
0
 //When the user selects a different option from the drop‐down list,
 //the chart should automatically refresh.
 private void tier_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         List <Booking> qq = new List <Booking>();
         if (tier.Text == "All Tiers")
         {
             //This screen only shows the packages that the sponsor
             qq = db.Bookings.Where(x => x.status == "Approved").ToList();
         }
         else
         {
             //This screen only shows the packages that the sponsor
             qq = db.Bookings.Where(x => x.status == "Approved" && x.Package.packageTier == tier.Text).ToList();
         }
         addchart(qq);
     }
 }
 private void UpdateSponsershipBookings_Load(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         //This table should only include the package
         //bookings that the sponsor manager has Approved
         var q = db.Bookings.Where(x => x.userIdFK == users.userId && x.status == "Approved")
                 //When the screen is loaded, the packages should
                 //be sorted by their tier and then individual value.
                 .OrderBy(x => x.Package.packageTier == "Bronze" ? 1 : x.Package.packageTier == "Silver" ? 2 : 3)
                 .ThenBy(x => x.Package.packageValue)
                 .ToList();
         dataGridView1.DataSource             = cdt(q);
         dataGridView1.SelectionMode          = DataGridViewSelectionMode.FullRowSelect;
         dataGridView1.Columns["ID1"].Visible = false;
         TotalVal.Text = val.ToString();
     }
 }
Exemplo n.º 24
0
        private void AccountableM_Load(object sender, EventArgs e)
        {
            assetList.ColumnCount        = 5;
            assetList.Columns[0].Name    = "Asset SN";
            assetList.Columns[1].Name    = "Asset Name";
            assetList.Columns[2].Name    = "Last Closed EM";
            assetList.Columns[3].Name    = "Number of EMs";
            assetList.Columns[4].Name    = "Asset ID";
            assetList.Columns[4].Visible = false;
            Object[] rows = new Object[5];

            using (var context = new Session2Entities())
            {
                var queryAssets = (from x in context.Employees
                                   where x.ID.Equals(employeeID)
                                   join y in context.Assets on x.ID equals y.EmployeeID
                                   select new
                {
                    x,
                    y,
                });


                foreach (var item in queryAssets)
                {
                    var queryEM = (from x in queryAssets
                                   where item.y.ID == x.y.ID
                                   join z in context.EmergencyMaintenances on x.y.ID equals z.AssetID
                                   orderby z.EMEndDate descending
                                   select z);

                    rows[0] = item.y.AssetSN;
                    rows[1] = item.y.AssetName;
                    var lastEM = queryEM.Where(x => x.EMEndDate != null).OrderByDescending(x => x.EMEndDate).Select(x => x.EMEndDate).FirstOrDefault();
                    rows[2] = lastEM;
                    var numberOfEM = queryEM.Where(x => x.EMEndDate != null && x.AssetID == item.y.ID).Select(x => x.EMEndDate).Count();
                    rows[3] = numberOfEM;
                    rows[4] = item.y.ID;
                    assetList.Rows.Add(rows);
                }
            }
        }
        private void BookSponderPackages_Load(object sender, EventArgs e)
        {
            using (var db = new Session2Entities())
            {
                //By default, when the screen is first loaded, the packages
                //should be sorted by their package name.
                var q = db.Packages.OrderBy(x => x.packageName).ToList();
                dataGridView1.DataSource            = CDT(q);
                dataGridView1.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.Columns["ID"].Visible = false;

                //Populating the package tiers
                var q2 = q.Select(x => x.packageTier).Distinct().ToList();
                tier.Items.Add("");
                foreach (var item in q2)
                {
                    tier.Items.Add(item);
                }
            }
        }
Exemplo n.º 26
0
 private async void Update_button_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("This action is irreversible!!", "Are you sure? ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         using (var db = new Session2Entities())
         {
             if (quantity_updown.Value > 0)
             {
                 try
                 {
                     var list = dgvlist[dataGridView1.SelectedRows[0].Index];
                     var item = (from i in db.Packages
                                 where i.packageId == list.ID
                                 select i).First();
                     if (item.packageQuantity < list.QuantityBooked)
                     {
                         MessageBox.Show("Insufficient Quantity!!!");
                     }
                     else
                     {
                         dgvlist[dataGridView1.SelectedRows[0].Index].QuantityBooked = (int)quantity_updown.Value;
                         UpdateUI();
                         var booking = (from c in db.Bookings
                                        where c.packageIdFK == item.packageId
                                        where c.userIdFK == UserID
                                        select c).First();
                         booking.quantityBooked = (int)quantity_updown.Value;
                         await db.SaveChangesAsync();
                     }
                 }
                 catch
                 {
                 }
             }
             else
             {
                 MessageBox.Show("Please choose a value greater than zero!!");
             }
         }
     }
 }
Exemplo n.º 27
0
        private async void create_button_Click(object sender, EventArgs e)
        {
            if (!(string.IsNullOrWhiteSpace(company_box.Text) && string.IsNullOrWhiteSpace(user_box.Text) && string.IsNullOrWhiteSpace(password_box.Text)))
            {
                if (user_box.Text.Length > 8)
                {
                    using (var db = new Session2Entities())
                    {
                        try
                        {
                            var u = (from us in db.Users
                                     where us.userId == user_box.Text
                                     select us).First();
                            MessageBox.Show("Error, cannot have the same userid as anyone else");
                        }
                        catch {
                            if (password_box.Text == password_again_box.Text)
                            {
                                await AddUser();

                                MessageBox.Show("DONE!");
                                cancel_button_Click(null, null);
                            }
                            else
                            {
                                MessageBox.Show("Passwords do not match!");
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("UserID must be 8 characters or longer!");
                }
            }
            else
            {
                MessageBox.Show("One or more fields are empty");
            }
        }
Exemplo n.º 28
0
        public async Task <List <BookingApprove> > GetBookingApproves()
        {
            var returnlist = new List <BookingApprove>();

            using (var db = new Session2Entities())
            {
                var query = (from b in db.Bookings
                             select b);
                foreach (var item in query)
                {
                    var ba = new BookingApprove()
                    {
                        ID          = item.bookingId,
                        CompanyName = item.User.name,
                        PackageName = item.Package.packageName,
                        Status      = item.status
                    };
                    returnlist.Add(ba);
                }
            }
            return(returnlist);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "Text files | *.csv";  // file types, that will be allowed to upload
            dialog.Multiselect = false;                 // allow/deny user to upload more than one file at a time
            if (dialog.ShowDialog() == DialogResult.OK) // if user clicked OK
            {
                path.Text = dialog.FileName;            // get name of file
                try
                {
                    using (var db = new Session2Entities())
                    {
                        string[] Lines  = File.ReadAllLines(dialog.FileName);
                        string[] Fields = Lines[0].Split(new char[] { ',' });
                        //The system should then append the
                        //information from this CSV file to the
                        //database
                        for (int i = 1; i < Lines.GetLength(0); i++)
                        {
                            Fields = Lines[i].Split(new char[] { ',' });
                            Package package = new Package();
                            package.packageTier     = Fields[0];
                            package.packageName     = Fields[1];
                            package.packageValue    = long.Parse(Fields[2]);
                            package.packageQuantity = int.Parse(Fields[3]);

                            db.Packages.Add(package);
                        }
                        db.SaveChanges();
                        MessageBox.Show("Successfully added to DB!");
                    }
                }
                catch (Exception es)
                {
                    MessageBox.Show(es.ToString());
                }
            }
        }
Exemplo n.º 30
0
        private void upload_button_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Filter          = "csv files (*.csv)|*.csv",
                FilterIndex     = 1,
                CheckFileExists = true,
                CheckPathExists = true
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var list = File.ReadAllLines(ofd.FileName)
                           .Skip(1)
                           .Select(a => a.Split(','))
                           .Select(a => new Package()
                {
                    packageTier     = a[0].Trim(),
                    packageName     = a[1].Trim(),
                    packageValue    = int.Parse(a[2]),
                    packageQuantity = int.Parse(a[3])
                }
                                   ).ToList();
                using (var db = new Session2Entities())
                {
                    foreach (var item in list)
                    {
                        db.Packages.Add(item);
                    }
                    db.SaveChanges();
                    MessageBox.Show("Done!");
                }
            }
            else
            {
                MessageBox.Show("No file was selected, Aborting!");
            }
        }