Exemplo n.º 1
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            int    memberIdToDelete = (int)MemberInfoTable.SelectedRows[0].Cells[0].Value;
            Member memberToDelete   = (from x in ctx.Members where x.MemberID == memberIdToDelete select x).First();

            if (memberToDelete.Active == 0)
            {
                MessageBox.Show("Already discontinued member!");
            }
            else
            {
                if (MessageBox.Show("Are you sure you want to discontinue member?", "Confirm Member Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    memberToDelete.Active = 0;
                    ctx.SaveChanges();

                    MessageBox.Show(String.Format("Member ID: {0}\n Member Name: {1} {2} is discontinued!", memberToDelete.MemberID, memberToDelete.FirstName, memberToDelete.LastName));
                }
                else
                {
                    // user clicked no
                }
            }

            if (HideInactiveCheckbox.Checked == true)
            {
                SearchActiveMembers();
            }
            else
            {
                SearchAllMembers();
            }
        }
Exemplo n.º 2
0
        private void CancelBookingButton_Click(object sender, EventArgs e)
        {
            if (BookingMemberDataGrid.SelectedCells[7].Value.
                ToString() == "Cancelled")
            {
                MessageBox.Show("Booking has already been cancelled.");
                return;
            }

            DateTime selectedDate = (DateTime)BookingMemberDataGrid.SelectedCells[2].Value;
            DateTime compareDate  = new DateTime(selectedDate.Year, selectedDate.Month, selectedDate.Day, 0, 0, 0);

            if (compareDate.CompareTo(System.DateTime.Now) == -1)
            {
                MessageBox.Show("Cannot cancel past booking.");
                return;
            }

            int     bookingId = Int32.Parse(BookingMemberDataGrid.SelectedCells[0].Value.ToString());
            Booking b         = context.Bookings.Where(x => x.BookingID == bookingId).First();

            b.Status = 0;
            context.SaveChanges();

            LoadBookingHistoryDataGrid();
            if (parent is BookingsManager)
            {
                parent.LoadBookingDataGrid();
                parent.BookingManagerDataGrid.Rows[0].Selected = true;
                parent.parent.LoadBookingDataGrid();
            }

            MessageBox.Show("Booking has been cancelled.");
        }
Exemplo n.º 3
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            string       OldType = FacilityDataGrid.SelectedCells[0].Value.ToString();
            FacilityType f1      = ctx.FacilityTypes.Where(x => x.Name == OldType).FirstOrDefault(); //

            f1.Name = InputTypeNameTextBox.Text;
            ctx.SaveChanges();

            refresh();
            MessageBox.Show("Facility Type successfully updated.");
        }
Exemplo n.º 4
0
        private void DeleteButton_Click(object sender, EventArgs e) //delete means Deactive
        {
            //check whether related type has related record

            string OldType = FacilityDataGrid.SelectedCells[0].Value.ToString();       //selected typename

            FacilityType ft = ctx.FacilityTypes.Where(x => x.Name == OldType).First(); //selected facilityType

            List <int> fi = new List <int>();                                          //typeid related facilityid Array

            foreach (Facility f in ctx.Facilities)
            {
                if (f.TypeID == ft.TypeID)

                {
                    fi.Add(f.FacilityID);
                }
            }



            int flag = 0;

            foreach (Booking b in ctx.Bookings)
            {
                for (int i = 0; i < fi.Count(); i++)
                {
                    if (b.FacilityID == fi[i])
                    {
                        flag++;
                    }
                }
            }
            if (flag != 0)
            {
                MessageBox.Show("Unable to delete due to existing Booking Records.");
                flag = 0;
            }
            else
            {
                ElevenAlphaEntities ctx = new ElevenAlphaEntities();
                OldType = FacilityDataGrid.SelectedCells[0].Value.ToString();
                FacilityType f = ctx.FacilityTypes.Where(x => x.Name == OldType).First();
                f.Active = 0;
                ctx.SaveChanges();
                refresh();
            }
        }
Exemplo n.º 5
0
        private void BookButton1_Click(object sender, EventArgs e)
        {
            if (BookingManagerDataGrid.SelectedCells[0].Value.ToString() != "Vacant")
            {
                MessageBox.Show("Cannot book timeslot that has already been booked.");
                return;
            }

            if (MemberIdTextBox.Text == "")
            {
                MessageBox.Show("Member ID is a required field.");
                return;
            }

            if (FirstNameTextBox.Text == "First Name" || LastNameTextBox.Text == "Last Name")
            {
                MessageBox.Show("Member ID is invalid.");
                return;
            }

            string   facility       = BookingManagerDataGrid.SelectedCells[0].OwningColumn.HeaderText;
            int      facilityId     = context.Facilities.Where(x => x.Name == facility).FirstOrDefault().FacilityID;
            DateTime insertDateTime = new DateTime(BookingDateTimePicker.Value.Year, BookingDateTimePicker.Value.Month, BookingDateTimePicker.Value.Day, 0, 0, 0);

            Booking b = new Booking()
            {
                FacilityID    = facilityId,
                MemberID      = Int32.Parse(MemberIdTextBox.Text),
                BookingDate   = insertDateTime,
                Timeslot      = BookingManagerDataGrid.SelectedCells[0].RowIndex + 1,
                Status        = 1,
                DateRequested = System.DateTime.Now
            };

            context.Bookings.Add(b);
            context.SaveChanges();

            LoadBookingDataGrid();
            parent.LoadBookingDataGrid();
            MessageBox.Show($"Booking successful.");
            var bookingReceipt = new ViewBookingReceipt(b.BookingID);

            bookingReceipt.ShowDialog();
        }
Exemplo n.º 6
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            string inputname = InputTypeNameTextBox.Text;


            // check if the inputname already exist but deactive
            int flag = 0;

            foreach (FacilityType f1 in ctx.FacilityTypes)
            {
                if (f1.Name.ToLower() == inputname.ToLower())
                {
                    ElevenAlphaEntities ctx = new ElevenAlphaEntities();
                    FacilityType        f   = ctx.FacilityTypes.Where(x => x.Name == inputname).First();
                    //f.Active = 1;
                    flag = 1;
                    if (f.Active == 0)
                    {
                        f.Active = 1;
                        MessageBox.Show("Facility Type successfully reactivated.");
                    }
                    else
                    {
                        MessageBox.Show("Facility Type already exists!");
                    }
                    ctx.SaveChanges();
                    refresh();

                    break;
                }
            }

            if (flag == 0)
            {
                ElevenAlphaEntities ctx  = new ElevenAlphaEntities();
                FacilityType        fnew = new FacilityType();
                fnew.Active = 1;
                fnew.Name   = inputname;
                ctx.FacilityTypes.Add(fnew);
                ctx.SaveChanges();
                refresh();
                MessageBox.Show("Facility Type successfully added.");
            }
        }
Exemplo n.º 7
0
        //deactivating facilities
        private void FacilitiesTabBtnDeactivate_Click(object sender, EventArgs e)//already deactivated keeps popping out
        {
            ElevenAlphaEntities context = new ElevenAlphaEntities();
            int      q          = (int)FacilitiesdataGridView1.SelectedRows[0].Cells[0].Value;
            Facility toinactive = context.Facilities.Where(x => x.FacilityID == q).First();

            if (toinactive.Active == 0)
            {
                MessageBox.Show("Facility already deactivated");
            }
            else
            {
                toinactive.Active = 0;
                MessageBox.Show("Facility deactivated");
                context.SaveChanges();
                LoadDataSearchFilter();
                StatusFilter();
            }

            parent.bookingTab.LoadBookingDataGrid();
        }
Exemplo n.º 8
0
        private void AddMemberButton_Click(object sender, EventArgs e)
        {
            Regex isValidEmail = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
                                           @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9A-Za-z][-\w]*[0-9A-Za-z]*\.)+[a-zA-Z0-9][\-a-zA-Z0-9]{0,22}[a-zA-Z0-9]))$");

            if (FirstNameTxtBox.Text == "")
            {
                MessageBox.Show("Please input a First Name.");
            }

            else if (GenderComboBox.SelectedIndex <= 0)
            {
                MessageBox.Show("Please input Gender.");
            }
            else if (MobileTextBox.MaskedTextProvider.AssignedEditPositionCount < 8)
            {
                MessageBox.Show("Please input a valid Mobile number.");
            }

            else if (EmailTextBox.Text == "" || !isValidEmail.IsMatch(EmailTextBox.Text))
            {
                MessageBox.Show("Please input a valid Email Address.");
            }

            else if (EmergencyNameTextBox.Text == "")
            {
                MessageBox.Show("Please input an Emergency Contact Name.");
            }
            else if (EmergencyNumberTextBox.MaskedTextProvider.AssignedEditPositionCount < 8)
            {
                MessageBox.Show("Please input a valid Emergency Contact Number.");
            }
            else
            {
                foreach (Member m in ctx.Members)
                {
                    if ((m.FirstName == FirstNameTxtBox.Text) && (m.LastName == LNameTextBox.Text) && (m.DateOfBirth == DOBPicker.Value) && (m.Email == EmailTextBox.Text))
                    {
                        MessageBox.Show("Member already exists!");
                        flag = 1;
                        break;
                    }

                    this.Close();
                }
                if (flag == 0)
                {
                    flag = 0;

                    Member newMember = new Member
                    {
                        FirstName         = FirstNameTxtBox.Text,
                        LastName          = LNameTextBox.Text,
                        Email             = EmailTextBox.Text,
                        DateOfBirth       = DOBPicker.Value,
                        Active            = 1,
                        Mobile            = MobileTextBox.Text,
                        EmergencyContact  = EmergencyNumberTextBox.Text,
                        EmergencyName     = EmergencyNameTextBox.Text,
                        EmergencyRelation = MemberRelationTextBox.Text
                    };

                    if (SalutationComboBox.SelectedItem == null)
                    {
                        newMember.Salutations = "";
                    }
                    else
                    {
                        newMember.Salutations = SalutationComboBox.SelectedItem.ToString();
                    }

                    if (GenderComboBox.SelectedItem.ToString() == "Male")
                    {
                        newMember.Gender = "M";
                    }
                    else
                    {
                        newMember.Gender = "F";
                    }

                    ctx.Members.Add(newMember);
                    ctx.SaveChanges();


                    MessageBox.Show(String.Format("New member {0} {1} with Member ID: {2} has been added!", newMember.FirstName, newMember.LastName, newMember.MemberID));

                    if (memberTab.SearchTextBox.Text != "")
                    {
                        if (memberTab.HideInactiveCheckbox.Checked == true)
                        {
                            memberTab.SearchActiveMembers();
                        }
                        else
                        {
                            memberTab.SearchAllMembers();
                        }
                    }

                    else
                    {
                        if (memberTab.HideInactiveCheckbox.Checked == true)
                        {
                            memberTab.ViewActiveMembers();
                        }
                        else
                        {
                            memberTab.ViewAllMembers();
                        }
                    }


                    int selectedIndex = memberTab.MemberInfoTable.Rows.Count - 1;

                    memberTab.MemberInfoTable.Rows[selectedIndex].Selected    = true;
                    memberTab.MemberInfoTable.FirstDisplayedScrollingRowIndex = selectedIndex;
                    this.Close();
                }
            }
        }
Exemplo n.º 9
0
        private void UpdateMemberButton_Click(object sender, EventArgs e)
        {
            Regex isValidEmail = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
                                           @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-z]*\.)+[a-zA-Z0-9][\-a-zA-Z0-9]{0,22}[a-zA-Z0-9]))$");

            if (FirstNameTxtBox.Text == "")
            {
                MessageBox.Show("Please input First Name.");
            }

            else if (GenderComboBox.SelectedIndex <= 0)
            {
                MessageBox.Show("Please input Gender.");
            }
            else if (MobileTextBox.MaskedTextProvider.AssignedEditPositionCount < 8)
            {
                MessageBox.Show("Please input a valid Mobile Number.");
            }

            else if (EmailTextBox.Text == "" || !isValidEmail.IsMatch(EmailTextBox.Text))
            {
                MessageBox.Show("Please input a valid Email Address.");
            }

            else if (EmergencyNameTextBox.Text == "")
            {
                MessageBox.Show("Please input an Emergency Contact Name.");
            }
            else if (EmergencyNumberTextBox.MaskedTextProvider.AssignedEditPositionCount < 8)
            {
                MessageBox.Show("Please input a valid Emergency Contact Number.");
            }
            else
            {
                Member memberToEdit = (Member)(from x in ctx.Members where x.MemberID == memberId select x).First();

                memberToEdit.FirstName         = FirstNameTxtBox.Text;
                memberToEdit.LastName          = LNameTextBox.Text;
                memberToEdit.Email             = EmailTextBox.Text;
                memberToEdit.DateOfBirth       = DOBPicker.Value;
                memberToEdit.Mobile            = MobileTextBox.Text;
                memberToEdit.EmergencyContact  = EmergencyNumberTextBox.Text;
                memberToEdit.EmergencyName     = EmergencyNameTextBox.Text;
                memberToEdit.EmergencyRelation = MemberRelationTextBox.Text;

                if (SalutationComboBox.SelectedItem == null)
                {
                    memberToEdit.Salutations = "";
                }
                else
                {
                    memberToEdit.Salutations = SalutationComboBox.SelectedItem.ToString();
                }

                if (GenderComboBox.SelectedItem.ToString() == "Male")
                {
                    memberToEdit.Gender = "M";
                }
                else
                {
                    memberToEdit.Gender = "F";
                }

                ctx.SaveChanges();
                MessageBox.Show(String.Format("The details of {0} {1} with Member ID: {2} has been updated!", memberToEdit.FirstName, memberToEdit.LastName, memberToEdit.MemberID));

                if (memberTab.SearchTextBox.Text != "")
                {
                    if (memberTab.HideInactiveCheckbox.Checked == true)
                    {
                        memberTab.SearchActiveMembers();
                    }
                    else
                    {
                        memberTab.SearchAllMembers();
                    }
                }

                else
                {
                    if (memberTab.HideInactiveCheckbox.Checked == true)
                    {
                        memberTab.ViewActiveMembers();
                    }
                    else
                    {
                        memberTab.ViewAllMembers();
                    }
                }

                memberTab.MemberInfoTable.Rows[selectedIndex].Selected = true;
                this.Close();
            }
        }
Exemplo n.º 10
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            // faciliytid from another form
            Facility f = ctx.Facilities.Where(x => x.FacilityID == facilityid).FirstOrDefault();
            // the facility select

            int    flag      = 0;
            string inputname = FacilityNameTextB.Text;

            if (inputname == "")
            {
                MessageBox.Show("Please input the Facility Name.");
            }
            else
            {
                foreach (Facility f1 in ctx.Facilities)
                {
                    if (f1.Name == inputname)
                    {
                        flag++; break;
                    }
                }
                if (flag > 0 && inputname.ToLower() != f.Name.ToLower())
                {
                    MessageBox.Show("This Facility Name already exists. Please input a different one."); flag = 0;
                }
                else
                {
                    f.Name = inputname;
                    if (OpenTimeMaskT.MaskedTextProvider.AssignedEditPositionCount == 0)
                    {
                        MessageBox.Show("Please input the Opening Time.");
                    }
                    else if (Convert.ToDateTime(OpenTimeMaskT.Text.ToString()) >= Convert.ToDateTime(CloseTimeMaskT.Text.ToString()))
                    {
                        MessageBox.Show("Please input a closing time later than opening time!");
                    }

                    else
                    {
                        DateTime d1 = Convert.ToDateTime(OpenTimeMaskT.Text.ToString());
                        opentime = new DateTime(1900, 1, 1, d1.Hour, d1.Minute, d1.Second);//


                        if (CloseTimeMaskT.MaskedTextProvider.AssignedEditPositionCount == 0)
                        {
                            MessageBox.Show("Please input the Closing Time.");
                        }
                        else
                        {
                            DateTime d2 = Convert.ToDateTime(CloseTimeMaskT.Text.ToString());

                            closetime = new DateTime(1900, 01, 01, d2.Hour, d2.Minute, d2.Second);//


                            f.Location    = LocationTextB.Text;
                            f.Description = DescriptionTextB.Text;
                            f.Active      = 1;
                            f.OpeningTime = opentime;
                            f.ClosingTime = closetime;
                            ctx.SaveChanges();
                            MessageBox.Show("Successfully updated Facility.");
                        }
                    }
                }
            }
        }
        private void AddFacilityButton_Click(object sender, EventArgs e)
        {
            Facility f    = new Facility();
            int      flag = 0;
            DateTime opentime;
            DateTime closetime;

            string inputname = FacilityNameTxtB.Text;

            if (inputname == "")
            {
                MessageBox.Show("Please input the Facility Name.");
            }

            else
            {
                foreach (Facility f1 in ctx.Facilities)
                {
                    if (f1.Name.ToLower() == inputname.ToLower())
                    {
                        flag++; break;
                    }
                }
                if (flag > 0)
                {
                    MessageBox.Show("This Facility Name already exists. Please input a different one."); flag = 0;
                }
                else
                {
                    f.Name = inputname;

                    if (typename == "")
                    {
                        MessageBox.Show("Please choose a Facility Type.");
                    }
                    else
                    {
                        FacilityType ft = ctx.FacilityTypes.Where(x => x.Name == typename).FirstOrDefault(); //found selected facilitytype
                        f.TypeID = ft.TypeID;                                                                // set facility typeid

                        if (OpenHrsMskTxB.MaskedTextProvider.AssignedEditPositionCount == 0)
                        {
                            MessageBox.Show("Please input the Opening Time.");
                        }
                        else if (Convert.ToDateTime(OpenHrsMskTxB.Text.ToString()) >= Convert.ToDateTime(CloseHrsMskTxB.Text.ToString()))
                        {
                            MessageBox.Show("Please input a closing time later than opening time!");
                        }

                        else
                        {
                            DateTime d1 = Convert.ToDateTime(OpenHrsMskTxB.Text.ToString());

                            //OpenHrsMskTxB.value.hour
                            opentime = new DateTime(1900, 1, 1, d1.Hour, d1.Minute, d1.Second);//

                            if (CloseHrsMskTxB.MaskedTextProvider.AssignedEditPositionCount == 0)
                            {
                                MessageBox.Show("Please input the Closing Time.");
                            }
                            else
                            {
                                DateTime d2 = Convert.ToDateTime(CloseHrsMskTxB.Text.ToString());

                                closetime = new DateTime(1900, 01, 01, d2.Hour, d2.Minute, d2.Second);//

                                f.Location    = LocationTexB.Text;
                                f.Description = DescriptionTexB.Text;
                                f.Active      = 1;
                                f.OpeningTime = opentime;
                                f.ClosingTime = closetime;

                                ctx.Facilities.Add(f);
                                ctx.SaveChanges();
                                MessageBox.Show("Successfully added Facility.");
                            }
                        }
                    }
                }
            }
        }