protected void selectCustomer_Click(object sender, ListViewCommandEventArgs e)
        {
            MessageUserControl.TryRun(() =>
            {
                if (!phoneNumberSubmitBtn.Enabled)
                //if (!string.IsNullOrEmpty(selectedCustomerRental.Text))
                {
                    throw new Exception("A customer profile is loaded! Must cancel to re-select");
                }
                else
                {
                    RentalCustomerController mgr = new RentalCustomerController();
                    Customer customer            = mgr.selectSingleCustomer(int.Parse(e.CommandArgument.ToString()));

                    selectedCustomerRental.Text          = e.CommandArgument.ToString();
                    HIDDEN_LABEL_selectedCustomerID.Text = customer.CustomerID.ToString();
                    PhoneNumberInput.Text        = customer.ContactPhone;
                    selectedCustomerName.Text    = customer.LastName + ", " + customer.FirstName;
                    selectedCustomerAddress.Text = customer.Address;
                    selectedCustomerCity.Text    = customer.City;

                    //Actually editing database!!!
                    //RentalController RCmgr = new RentalController();
                    //Rental by its self gernerats a error, must declare entire namespace - naming coflicts
                    //eTools.Data.Entities.Rental rental = RCmgr.returnSingleRentalForm(int.Parse(e.CommandArgument.ToString()));
                    //RentalDetails
                    //DateOut.Text = rental.RentalDate.ToString();
                    //CreditCard.Text = rental.CreditCard;
                    //Subtotal.Text = rental.SubTotal.ToString();
                    //GST.Text = rental.TaxAmount.ToString();
                    //Discount.Text = rental.Coupon.CouponDiscount.ToString();
                    //Total.Text = (((rental.SubTotal) + (rental.TaxAmount)) - ((decimal)rental.Coupon.CouponDiscount)).ToString();
                    //TextBox as Input


                    RentalDetailController RDCmgr = new RentalDetailController();
                    auxReturnInfo info            = RDCmgr.getauxeturnInfo(int.Parse(e.CommandArgument.ToString()));

                    //RentalDetails
                    DateOut.Text    = info.dateout.ToString();
                    CreditCard.Text = info.creditcard;
                    Subtotal.Text   = info.subtotal.ToString();
                    GST.Text        = info.gst.ToString();
                    Discount.Text   = info.discount.ToString();
                    Total.Text      = info.total.ToString();

                    PhoneNumberInput.Enabled   = false;
                    PhoneNumberInput.ForeColor = System.Drawing.Color.LightGray;

                    //Button as Input
                    phoneNumberSubmitBtn.Enabled   = false;
                    phoneNumberSubmitBtn.ForeColor = System.Drawing.Color.LightGray;

                    //No need as the if above checks if profile is loaded
                    //selectedCustomerBtn

                    newReturn.Visible = true;
                }
            }, "Customer Found", "Profile has been successfully retrived. Must select New Return Button to Load New Profile");
        }
Пример #2
0
        public auxReturnInfo getauxeturnInfo(int rentalid, double daysOut)
        {
            using (var context = new eToolsContext())
            {
                //auxReturnInfo info = context.Rentals
                //                               .Where(x => (x.RentalID == rentalid))
                //                               .Select(x =>
                //                                     new auxReturnInfo()
                //                                     {
                //                                         rentalid = x.RentalID,
                //                                         creditcard = x.CreditCard,
                //                                         dateout = x.RentalDate,
                //                                         subtotal = context.RentalDetails
                //                                           .Where(xx => (xx.RentalID == x.RentalID))
                //                                           .Select(xx => (xx.DailyRate * (Decimal)(xx.Days)))
                //                                           .Sum(),


                //                                         discount = (x.CouponID == null) ? (Decimal)0.0 : (Decimal)(x.Coupon.CouponDiscount),

                //                                         total = ((context.RentalDetails
                //                                                             .Where(xx => (xx.RentalID == x.RentalID))
                //                                                             .Select(xx => (xx.DailyRate * (Decimal)(xx.Days)))
                //                                                             .Sum() + (context.RentalDetails
                //                                                                                   .Where(xx => (xx.RentalID == x.RentalID))
                //                                                                                   .Select(xx => (xx.DailyRate * (Decimal)(xx.Days)))
                //                                                                                   .Sum() * (Decimal)0.05 )) - ((x.CouponID == null) ? (Decimal)0.0 : (Decimal)(x.Coupon.CouponDiscount)))
                //                                                                                             }).FirstOrDefault();


                auxReturnInfo info = context.Rentals
                                     .Where(x => (x.RentalID == rentalid))
                                     .Select(x =>
                                             new auxReturnInfo()
                {
                    rentalid   = x.RentalID,
                    creditcard = x.CreditCard,
                    dateout    = x.RentalDate,

                    subtotal = context.RentalDetails
                               .Where(xx => (xx.RentalID == x.RentalID))
                               .Select(xx => ((Double)(xx.DailyRate) * daysOut)).Sum(),

                    gst = (context.RentalDetails
                           .Where(xx => (xx.RentalID == x.RentalID))
                           .Select(xx => ((Double)(xx.DailyRate) * daysOut)).Sum() * 0.05),

                    discount = (x.CouponID == null) ? 0 : (Double)(x.Coupon.CouponDiscount),

                    total = ((context.RentalDetails
                              .Where(xx => (xx.RentalID == x.RentalID))
                              .Select(xx => ((Double)(xx.DailyRate) * daysOut))
                              .Sum() + (context.RentalDetails
                                        .Where(xx => (xx.RentalID == x.RentalID))
                                        .Select(xx => (Double)xx.DailyRate * daysOut)
                                        .Sum() * 0.05)) - ((x.CouponID == null) ? 0 : (Double)(x.Coupon.CouponDiscount)))
                }).FirstOrDefault();
                return(info);
            }
        }
        private void testingOnly()
        {
            MessageUserControl.TryRun(() =>
            {
                //test case
                int testRentalId             = 234;
                RentalCustomerController mgr = new RentalCustomerController();
                Customer customer            = mgr.selectSingleCustomer(testRentalId);

                //customer = mgr.customersReturnLookUp

                selectedCustomerRental.Text          = testRentalId.ToString();
                HIDDEN_LABEL_selectedCustomerID.Text = customer.CustomerID.ToString();
                PhoneNumberInput.Text        = customer.ContactPhone;
                selectedCustomerName.Text    = customer.LastName + ", " + customer.FirstName;
                selectedCustomerAddress.Text = customer.Address;
                selectedCustomerCity.Text    = customer.City;


                RentalDetailController RDCmgr = new RentalDetailController();
                auxReturnInfo info            = RDCmgr.getauxeturnInfo(testRentalId, 5.5);

                //RentalDetails
                DateOut.Text    = info.dateout.ToString();
                CreditCard.Text = info.creditcard;
                Subtotal.Text   = info.subtotal.ToString();
                GST.Text        = info.gst.ToString();
                Discount.Text   = info.discount.ToString();
                Total.Text      = info.total.ToString();

                PhoneNumberInput.Enabled   = false;
                PhoneNumberInput.ForeColor = System.Drawing.Color.LightGray;

                //Button as Input
                phoneNumberSubmitBtn.Enabled   = false;
                phoneNumberSubmitBtn.ForeColor = System.Drawing.Color.LightGray;

                //No need as the if above checks if profile is loaded
                //selectedCustomerBtn

                newReturn.Visible = true;
            }, "Testing Error", "Testing related error");
        }