Пример #1
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            if (cbProgrammes.Text != "")
            {

                // create a new membership and fill it with data
                DataLayer.Membership membership = new DataLayer.Membership();
                membership.MemberId = this.id;                                      // member's id
                membership.Plan = (int) cbProgrammes.SelectedValue;                 // id of the selected plan
                membership.start = datePickerStart.Value;                           // when the membership starts
                membership.end = datePickerEnd.Value;                               // when the membership expires

                if (DataLayer.Memberships.NewMembership(membership) >0 )
                {
                    MessageBox.Show("Membership added successfully!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //reload memberships datagridview in main form
                    DataTable table = DataLayer.Memberships.GetMembershipByMemberId(id);
                    this.mydg.DataSource = table;
                }
                else
                {
                    MessageBox.Show("Failed to add new membership. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please Select a Programme!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            if (cbProgrammes.Text != "" && cbProgrammes.SelectedIndex != 0)
            {
                // create a new membership and fill it with data
                DataLayer.Membership membership = new DataLayer.Membership();
                membership.MemberId = this.id;                                      // member's id
                membership.Plan     = (int)cbProgrammes.SelectedValue;              // id of the selected plan
                membership.start    = datePickerStart.Value;                        // when the membership starts
                membership.end      = datePickerEnd.Value;                          // when the membership expires


                if (DataLayer.Memberships.NewMembership(membership) > 0)
                {
                    MessageBox.Show("Membership added successfully!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //reload memberships datagridview in main form
                    DataTable table = DataLayer.Memberships.GetMembershipByMemberId(id);
                    this.mydg.DataSource = table;
                }
                else
                {
                    MessageBox.Show("Failed to add new membership. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Please Select a Programme!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #3
0
        private void wizard1_FinishButtonClick(object sender, CancelEventArgs e)
        {
            //////////////// CREATE A NEW MEMBER //////////////

            // create a new member
            DataLayer.Member member = new DataLayer.Member();

            // fill member properties from textboxes
            member.CardNumber = Int32.Parse(txtWizardCardNumber.Text);
            member.LName = txtWizardLastName.Text;
            member.FName = txtWizardFirstName.Text;
            if (rbWizardMale.Checked)
            {
                member.Sex = "male";
            }
            else if (rbWizardFemale.Checked)
            {
                member.Sex = "female";
            }
            member.DateOfBirth = dtpWizardDOB.Value;
            member.Street = txtWizardStreet.Text;
            member.Suburb = txtWizardSuburb.Text;
            member.City = txtWizardCity.Text;
            if (txtPostalCode.Text.Length > 0)
            {
                member.PostalCode = Int32.Parse(txtWizardPostalCode.Text);
            }
            member.HomePhone = txtWizardHomePhone.Text;
            member.CellPhone = txtWizardCellPhone.Text;
            member.Email = txtWizardEmail.Text;
            member.Occupation = txtWizardOccupation.Text;
            member.Notes = txtWizardNotes.Text;

            // holds the member's picture
            //byte[] imageBt = null;
            if (picWizard.ImageLocation != null)
            {
                FileStream fstream = new FileStream(picWizard.ImageLocation, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fstream);
                member.Image = br.ReadBytes((int)fstream.Length);
            }
            else
            {
                byte[] empty_array = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
                member.Image = empty_array;
            }

            //add member to db
            if (DataLayer.Members.AddNewMember(member) > 0)
            {
                //a new member has been added without any membership
                //MessageBox.Show("A New Member has been added. You can add a membership at any time from Member Manager", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Failed to add new member. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ////////////// CREATE A NEW MEMBERSHIP FOR THE SAME MEMBER //////////////

            if (cbWizardPlans.Text != "None")
            {
                // create a new membership and fill with data
                DataLayer.Membership membership = new DataLayer.Membership();

                //to find member's id we get the last inserted id and increment by 1 because we haven't inserted the new member yet
                membership.MemberId = DataLayer.Members.GetLastInsertedMember();        // member's id
                //membership.MemberId++;
                membership.Plan = (int)cbWizardPlans.SelectedValue;                 // id of the selected plan
                membership.start = dtpWizardStartPlan.Value;                           // when the membership starts
                membership.end = dtpWizardEndPlan.Value;                               // when the membership expires

                if (DataLayer.Memberships.NewMembership(membership) > 0)
                {
                    MessageBox.Show("A New Member has been added successfully!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Failed to add new membership. Please add manually from Member Manager", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            RefreshAllMembersDataGrid();            // refresh AllMembers datagridview
            panelNewMemberWizard.Visible = false;
            panelAllMembers.Visible = true;         // show all members datagrid view
        }
Пример #4
0
        public bool AddNewMember()
        {
            // Create a new Member
            var member = new DataLayer.Member()
            {
                CardNumber  = view.CardNumber,
                LName       = view.LastName,
                FName       = view.FirstName,
                Sex         = view.IsMaleChecked ? "Male" : "Female",
                DateOfBirth = view.DateOfBirth,
                Street      = view.Street,
                Suburb      = view.Suburb,
                City        = view.City,
                PostalCode  = view.PostalCode,
                HomePhone   = view.HomePhone,
                CellPhone   = view.CellPhone,
                Email       = view.Email,
                Occupation  = view.Occupation,
                Notes       = view.Notes
            };

            // Check if Card Number is valid
            if (DataLayer.Members.CardNumberExists(member.CardNumber))
            {
                MessageBox.Show("This Card Number already exists!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            //Check if Last Name is empty
            if (String.IsNullOrWhiteSpace(member.LName))
            {
                MessageBox.Show("The Last Name cannot be empty!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // holds the member's picture
            //byte[] imageBt = null;
            if (view.ImageLocation != null)
            {
                FileStream   fstream = new FileStream(view.ImageLocation, FileMode.Open, FileAccess.Read);
                BinaryReader br      = new BinaryReader(fstream);
                member.Image = br.ReadBytes((int)fstream.Length);
            }
            else
            {
                byte[] empty_array = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
                member.Image = empty_array;
            }


            // Save Member to db
            if (DataLayer.Members.AddNewMember(member) == 0)
            {
                MessageBox.Show("Failed to add new member. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClearTextBoxes();
                return(false);
            }

            // Create Membership for the same member
            if (view.SelectedPlanName != "None")
            {
                // create a new membership and fill with data
                var membership = new DataLayer.Membership()
                {
                    //to find member's id we get the last inserted id and increment by 1 because we haven't inserted the new member yet
                    MemberId = DataLayer.Members.GetLastInsertedMember(), // member's id
                                                                          //membership.MemberId++;
                    Plan  = view.PlanId,                                  // id of the selected plan
                    start = view.MembershipStart,                         // when the membership starts
                    end   = view.MembershipEnd                            // when the membership expires
                };

                // Save Membership to db
                if (DataLayer.Memberships.NewMembership(membership) > 0)
                {
                    MessageBox.Show("A New Member has been added successfully!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Failed to add new membership. Please add manually from Member Manager", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("A New Member has been added successfully!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            view.NewMemberWizard.NavigateCancel();
            ClearTextBoxes();
            return(true);
        }