示例#1
0
        public MembershipQuote(Quote info)
        {
            InitializeComponent();

            //assigning the property from the member info class that was passed into this overridden constructor
            InfoFromPrevWindow = info;

            //declare variables
            string strStartDate, strEndDate, strMembershipType, strMembershipTypeTrim, strCost, strMonthlyCost, strSubtotal;
            double dblCost, dblMonthlyCost, dblSubtotal;

            //get raw membership type information from previous window
            strMembershipTypeTrim = InfoFromPrevWindow.MembershipType.ToString().Trim();
            strMembershipType     = InfoFromPrevWindow.MembershipType.ToString();

            //extract the relevant substrings from the imported string
            //membership type
            strMembershipTypeTrim = strMembershipTypeTrim.Substring(0, strMembershipTypeTrim.IndexOf(":"));
            //monthly cost
            strCost = strMembershipType.Substring(strMembershipType.IndexOf(":") + 1).Trim();

            //convert monthly cost from previous window to double
            dblCost = Convert.ToDouble(strCost);

            //format monthly cost to currency
            strCost = dblCost.ToString("C2");

            //get raw start date info from previous window
            strStartDate = InfoFromPrevWindow.StartDate;

            //decalre DateTime variable
            DateTime datStartDate;

            //parse string start date data into DateTime format
            datStartDate = DateTime.Parse(strStartDate);

            dblSubtotal    = 0;
            dblMonthlyCost = 0;

            //if statements used to return end dates, monthly cost and subtotals based on the duration of the member
            if (strMembershipTypeTrim == "Individual 1 Month")
            {
                datStartDate   = datStartDate.AddMonths(1);
                dblMonthlyCost = dblCost;
                dblSubtotal    = dblCost;
            }
            else if (strMembershipTypeTrim == "Individual 12 Month")
            {
                datStartDate   = datStartDate.AddYears(1);
                dblMonthlyCost = dblCost / 12;
                dblSubtotal    = dblCost;
            }
            else if (strMembershipTypeTrim == "Two Person 1 Month")
            {
                datStartDate   = datStartDate.AddMonths(1);
                dblMonthlyCost = dblCost;
                dblSubtotal    = dblCost;
            }
            else if (strMembershipTypeTrim == "Two Person 12 Month")
            {
                datStartDate   = datStartDate.AddYears(1);
                dblMonthlyCost = dblCost / 12;
                dblSubtotal    = dblCost;
            }
            else if (strMembershipTypeTrim == "Family 1 Month")
            {
                datStartDate   = datStartDate.AddMonths(1);
                dblMonthlyCost = dblCost;
                dblSubtotal    = dblCost;
            }
            else if (strMembershipTypeTrim == "Family 12 Month")
            {
                datStartDate   = datStartDate.AddYears(1);
                dblMonthlyCost = dblCost / 12;
                dblSubtotal    = dblCost;
            }

            //convert subtotal and monthly cost to string
            strSubtotal    = dblSubtotal.ToString("C2");
            strMonthlyCost = dblMonthlyCost.ToString("C2");

            //format end date
            strEndDate = string.Format("{0:MM/dd/yyyy}", datStartDate);

            string strTraining, strLocker, strTotal;
            double dblTraining, dblLocker, dblTotal;

            //fetch training and locker info from previous window
            strTraining = InfoFromPrevWindow.PersonalTraining;
            strLocker   = InfoFromPrevWindow.LockerRental;

            //assign values to varaibles
            dblTraining = 5;
            dblLocker   = 1;
            dblTotal    = 0;

            //if statements were used to determine how much it would cost when training and locker costs are factored in
            if (strMembershipTypeTrim == "Individual 1 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblTraining) + (1 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Individual 1 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (1 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Individual 1 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblLocker);
            }

            else if (strMembershipTypeTrim == "Individual 12 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblTraining) + (12 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Individual 12 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (12 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Individual 12 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblLocker);
            }


            else if (strMembershipTypeTrim == "Two Person 1 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblTraining) + (1 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Two Person 1 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (1 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Two Person 1 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblLocker);
            }

            else if (strMembershipTypeTrim == "Two Person 12 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblTraining) + (12 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Two Person 12 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (12 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Two Person 12 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblLocker);
            }


            else if (strMembershipTypeTrim == "Family 1 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblTraining) + (1 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Family 1 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (1 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Family 1 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (1 * dblLocker);
            }

            else if (strMembershipTypeTrim == "Family 12 Month" && strTraining == "Yes" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblTraining) + (12 * dblLocker);
            }
            else if (strMembershipTypeTrim == "Family 12 Month" && strTraining == "Yes" && strLocker == "No")
            {
                dblTotal = dblSubtotal + (12 * dblTraining);
            }
            else if (strMembershipTypeTrim == "Family 12 Month" && strTraining == "No" && strLocker == "Yes")
            {
                dblTotal = dblSubtotal + (12 * dblLocker);
            }

            else
            {
                dblTotal = dblSubtotal;
            }

            //convert total to string
            strTotal = dblTotal.ToString("C2");

            //display output
            txtMembershipType.Text       = strMembershipTypeTrim;
            txtStartDate.Text            = InfoFromPrevWindow.StartDate;
            txtEndDate.Text              = strEndDate;
            txtPersonalTrainingPlan.Text = strTraining;
            txtLockerRental.Text         = strLocker;
            txtMembershipCost.Text       = strMonthlyCost;
            txtSubtotal.Text             = strSubtotal;
            txtTotal.Text = strTotal;

            //data to be sent to MembershipSignUp
            SignUp signup = new SignUp(strMembershipTypeTrim, strStartDate, strEndDate, strMonthlyCost, strSubtotal, strTraining, strLocker, strTotal);

            //instantiate the next window and use the overridden constructor that allows sending information in as an argument
            MembershipSignUp memberSignUp = new MembershipSignUp(signup);
        }
        public void btnSaveQuota_Click(object sender, RoutedEventArgs e)
        {
            //7. Initalize variables that must be prefaced before further validation
            DatePicker dtStartDate = dtStart;

            //8. Validate that a combobox item was selected
            if (cboMembershipType.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a Membership Plan.");
                return;
            }

            //9. Grab the boolean to see if a date has been selected
            bool isDateNull = isStartDateSelect(dtStartDate);

            //10. Check if a date has been select
            if (isDateNull == false)
            {
                MessageBox.Show("Please select a valid start date.");
                return;
            }

            //11. Once date is selected, declare variables that will calculate the end date
            DateTime dtToday            = DateTime.Today;
            DateTime dtConvertStartDate = ConvertPickerToDate(dtStartDate);
            DateTime dtConvertedEndDate = dtToday;

            //12. Determine if a user picked an date in the past
            if (dtConvertStartDate < dtToday)
            {
                MessageBox.Show("Please select a valid start date.");
                return;
            }

            //13. Determine the end date based on the drop down selected
            if ((cboMembershipType.SelectedIndex == 1 || cboMembershipType.SelectedIndex == 3 || cboMembershipType.SelectedIndex == 5))
            {
                dtConvertedEndDate = dtConvertStartDate.AddYears(1);
            }
            else
            {
                dtConvertedEndDate = dtConvertStartDate.AddMonths(1);
            }

            //14. Set selected item to string for query
            string strMembershipSelection = cboMembershipType.SelectedItem.ToString();

            //15. Query corresponding price from drop down menu
            var priceQuery =
                from p in priceList
                where (p.Membership.Trim() == strMembershipSelection.Trim())
                select p.Price;

            //16. Convert list to string
            string strMembershipPrice = String.Join(",", priceQuery);

            //17. Convert price to double for subtotal calculation
            double dblMembershipPrice = Convert.ToDouble(strMembershipPrice);
            double dblSubCost         = GetAdditionalFeatureCost(lstFeatures, cboMembershipType);
            double dblTotalCost       = dblSubCost + dblMembershipPrice;

            //18. String formula for output text box
            string strOutput = Environment.NewLine + "Membership Price:".PadRight(30) + dblMembershipPrice.ToString("C2") + Environment.NewLine + Environment.NewLine + "Addtional Feature Costs:".PadRight(30) + dblSubCost.ToString("C2") + Environment.NewLine + "________________________________________" + Environment.NewLine + "Total Cost:".PadRight(30) + dblTotalCost.ToString("C2");

            //19. Split datetime for enddate
            string strConvertedEndDate    = dtConvertedEndDate.ToString();
            int    strSpace               = strConvertedEndDate.IndexOf(" ");
            string strSubConvertedEndDate = strConvertedEndDate.Substring(0, strSpace);

            //20. Set additional features to string
            StringBuilder strFeatures = new StringBuilder();

            foreach (ListBoxItem selectedItem in lstFeatures.SelectedItems)
            {
                strFeatures.AppendLine(selectedItem.Content.ToString());
            }

            //21. Set output to corresponding text boxes
            txtFeatures.Text          = strFeatures.ToString();
            txtPrice.Text             = dblMembershipPrice.ToString("C2");
            txtMemberQuotaOutput.Text = strOutput;
            txtEndDate.Text           = strSubConvertedEndDate;
            txtMemberQuotaOutput.Text = strOutput;
            txtTotalPrice.Text        = dblTotalCost.ToString("C2");

            //22. create some info to send to the next window
            CustomerPaymentInfo info = new CustomerPaymentInfo(cboMembershipType.Text.Trim(), dtStart.Text.Trim(), txtEndDate.Text.Trim(), txtFeatures.Text.Trim(), txtPrice.Text.Trim(), txtTotalPrice.Text.Trim());

            MessageBoxResult messageBoxResult = MessageBox.Show("Create new member?"
                                                                + Environment.NewLine + Environment.NewLine + info
                                                                , "Membership Quote"
                                                                , MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                //instantiate the next window and use the overridden constructor that allows sending information in as an argument
                MembershipSignUp next = new MembershipSignUp(info);
                next.Show();
                this.Close();
            }
        }