//posts information from the database to the text fields on the screen public void updateAllFields() { //define a dsVehicle object dsVehicle dsSwitchVehicle; string tempPath = Server.MapPath("~/HTVDatabase1.mdb"); clsDataLayer dataLayerObj = new HTV.clsDataLayer(tempPath); try { //loads the vehicle dataset with information from the Vehicle Table dsSwitchVehicle = dataLayerObj.findVehicle(Int32.Parse(ddlVehicleID.Text)); if (dsSwitchVehicle.Vehicle.Rows.Count > 0) { //uses try/catch to eliminate errors from NULL items. try { lblVIN.Text = dsSwitchVehicle.Vehicle[0].vin; } catch (Exception error) { lblVIN.Text = ""; } try { lblMSRP.Text = dsSwitchVehicle.Vehicle[0].price.ToString("$#,##0.00"); } catch (Exception error) { lblMSRP.Text = ""; } try { lblTaxes.Text = dsSwitchVehicle.Vehicle[0].taxes.ToString("$#,##0.00"); } catch (Exception error) { lblTaxes.Text = ""; } try { lblFees.Text = (dsSwitchVehicle.Vehicle[0].Licensefee.ToString("$#,##0.00")); } catch (Exception error) { lblFees.Text = ""; } try { lblLocation.Text = dsSwitchVehicle.Vehicle[0].VehicleLocation; } catch (Exception error) { lblLocation.Text = ""; } double TotalVCost = 0; try { TotalVCost = (double)dsSwitchVehicle.Vehicle[0].price + (double)dsSwitchVehicle.Vehicle[0].taxes + (double)dsSwitchVehicle.Vehicle[0].Licensefee; lblTotalCost.Text = TotalVCost.ToString("$#,##0.00"); } catch (Exception error) { Warnings.Text = "Unable to calculate total cost."; } } else { Warnings.Text = "Not Found."; } } catch (Exception error) { string message = "Error = "; Warnings.Text = message + error.Message; } }
public void updateAllFields() { //define a dataset object for all the different kinds of information this page will need dsPurchaseRequest dsFinanceDetails; dsVehicle dsVehicleInfo; dsTradeIn dsTradeInInfo; string tempPath = Server.MapPath("~/HTVDatabase1.mdb"); clsDataLayer dataLayerObj = new HTV.clsDataLayer(tempPath); try { int tPRO = (int)Session["PurchaseRequest"]; dsFinanceDetails = dataLayerObj.findPurchaseRequest(tPRO); //uses information from the Purchase Request to locate information about Vehicle and TradeIn - similar to a Table JOIN dsVehicleInfo = dataLayerObj.findVehicle(dsFinanceDetails.PurchaseRequest[0].vehicleID); dsTradeInInfo = dataLayerObj.findTradeIn(dsFinanceDetails.PurchaseRequest[0].tradeinID); if (dsFinanceDetails.PurchaseRequest.Rows.Count > 0) { double customerOffer = 0, licenseFee = 0, taxes = 0, tradeInValue = 0, downPayment = 0, amountToFinance = 0; try { //TO DO: Turn this process into a function in the business layer. //This code calculates the total cost of a vehicle (ie. adds CustomerOffer, LicenseFee, and Taxes) //TO DO: Include Add-Ons to the Total Cost customerOffer = (double)dsFinanceDetails.PurchaseRequest[0].negotiatedPrice; licenseFee = (double)dsVehicleInfo.Vehicle[0].Licensefee; taxes = (double)dsVehicleInfo.Vehicle[0].taxes; //Missing the cost of the add-ons //TO DO: Calculate the Cost of the Add-Ons in the Business Layer try { lblTotalCost.Text = (customerOffer + licenseFee + taxes).ToString("$#,##0.00"); } catch (Exception error) { lblTotalCost.Text = ""; } } catch (Exception error) { Warnings.Text = "Unable to calculate Total Cost."; } //Post Trade-In Information to the screen try { tradeInValue = (double)dsTradeInInfo.TradeIn[0].amount; try { lblTradeInValue.Text = tradeInValue.ToString("$#,##0.00"); } catch (Exception error) { lblTradeInValue.Text = ""; } } catch (Exception error) { Warnings.Text = "Unable to calculate Trade-In Value."; } //Post information about Finances to screen try { downPayment = Double.Parse(dsFinanceDetails.PurchaseRequest[0].downPayment); try { txtDownPayment.Text = string.Format("{0:C2}", dsFinanceDetails.PurchaseRequest[0].downPayment); } catch (Exception error) { txtDownPayment.Text = ""; } amountToFinance = (customerOffer + licenseFee + taxes) - tradeInValue - downPayment; try { lblAmountToFinance.Text = amountToFinance.ToString("$#,##0.00"); } catch (Exception error) { lblAmountToFinance.Text = ""; } try { lblMonthlyPayment.Text = (myBusinessLayer.calculateMonthlyPayment(dsFinanceDetails.PurchaseRequest[0].ficoScore, amountToFinance, myBusinessLayer.convertLoanLengthToInt(dsFinanceDetails.PurchaseRequest[0].financeLength))); } catch (Exception error) { lblMonthlyPayment.Text = ""; } } catch (Exception error) { Warnings.Text = "Unable to calculate Amount to Finance."; } //post APR information to the screen try { lblInterestRate.Text = myBusinessLayer.calculateAPR(dsFinanceDetails.PurchaseRequest[0].ficoScore); } catch (Exception error) { lblInterestRate.Text = ""; } //post FICO score to screen try { txtFICO.Text = dsFinanceDetails.PurchaseRequest[0].ficoScore.ToString(); } catch (Exception error) { txtFICO.Text = ""; } //post the date the FICO scored was last updated to the screen try { txtFICODate.Text = dsFinanceDetails.PurchaseRequest[0].ficoScoreDate.ToString(); } catch (Exception error) { txtFICODate.Text = ""; } //post the life-of-loan information to the screen try { ddlFinanceLength.Text = dsFinanceDetails.PurchaseRequest[0].financeLength; } catch (Exception error) { ddlFinanceLength.Text = "48-Months"; } } else { Warnings.Text = "Record Not Found."; } } catch (Exception error) { string message = "Error = "; Warnings.Text = message + error.Message; } }
public void updateAllFields() { //instantiate a dataset object for each database that will supply information dsPurchaseRequest dsPROPurchaseRequest; dsCustomer dsPROCustomer; dsEmployee dsPROEmployee; dsTradeIn dsPROTradeIn; dsVehicle dsPROVehicle; //create a general dataLayerObject that will serve to populate with datasets as needed string tempPath = Server.MapPath("~/HTVDatabase1.mdb"); clsDataLayer dataLayerObj = new HTV.clsDataLayer(tempPath); try { //populate the PurchaseRequest information. This will also help to link to other Tables using foreign keys dsPROPurchaseRequest = dataLayerObj.findPurchaseRequest(Int32.Parse(ddlPurchaseRequestID.Text)); //only proceeds if there is data in the data set if (dsPROPurchaseRequest.PurchaseRequest.Rows.Count > 0) { Session["PurchaseRequest"] = dsPROPurchaseRequest.PurchaseRequest[0].requestID; lblPR.Text = ((int)Session["PurchaseRequest"]).ToString(); //Retreive Information about the Employee using a DataSet for the Employee information try { dsPROEmployee = dataLayerObj.findEmployee(dsPROPurchaseRequest.PurchaseRequest[0].employeeID); try { lblEmployee.Text = "ID: " + dsPROPurchaseRequest.PurchaseRequest[0].employeeID.ToString() + " - " + dsPROEmployee.Employee[0].lastName + ", " + dsPROEmployee.Employee[0].firstName; } catch (Exception error) { lblEmployee.Text = ""; } } catch (Exception error) { lblEmployee.Text = "No Employee Assigned."; } //Retreive Information about the Customer using a DataSet for the Customer Informaiton try { dsPROCustomer = dataLayerObj.findCustomer(dsPROPurchaseRequest.PurchaseRequest[0].customerID); try { lblCustomer.Text = "SSN: " + dsPROCustomer.Customer[0].socialSecurity + " - " + dsPROCustomer.Customer[0].lastName + ", " + dsPROCustomer.Customer[0].firstName; } catch (Exception error) { lblCustomer.Text = ""; } try { lblCustomer.Text = "SSN: " + dsPROCustomer.Customer[0].socialSecurity + " - " + dsPROCustomer.Customer[0].lastName + ", " + dsPROCustomer.Customer[0].firstName; } catch (Exception error) { lblCustomer.Text = ""; } } catch (Exception error) { lblCustomer.Text = "No Customer Assigned."; } try { lblFICO.Text = "FICO: " + dsPROPurchaseRequest.PurchaseRequest[0].ficoScore.ToString(); } catch (Exception error) { lblFICO.Text = ""; } //Retrieve Information about the Vehicle using a DataSet for the Vehicle Database try { dsPROVehicle = dataLayerObj.findVehicle(dsPROPurchaseRequest.PurchaseRequest[0].vehicleID); try { lblVehicleID.Text = "Vehicle ID: " + dsPROPurchaseRequest.PurchaseRequest[0].vehicleID.ToString() + " - " + dsPROVehicle.Vehicle[0].vin; } catch (Exception error) { lblVehicleID.Text = ""; } try { lblMSRP.Text = string.Format("Vehicle MSRP: {0,000:C2}", dsPROVehicle.Vehicle[0].price); } catch (Exception error) { lblMSRP.Text = ""; } try { lblCustomerOffer.Text = "Customer's Offer: " + dsPROPurchaseRequest.PurchaseRequest[0].negotiatedPrice.ToString("$#,##0.00"); } catch (Exception error) { lblCustomerOffer.Text = ""; } try { lblVehicleLocation.Text = "Location: " + dsPROVehicle.Vehicle[0].VehicleLocation; } catch (Exception error) { lblVehicleLocation.Text = ""; } //This portion fills in the Financing Details of the Overview try { lblDownPayment.Text = string.Format("Total Down Payment: ${0,000:C2}", dsPROPurchaseRequest.PurchaseRequest[0].downPayment); } catch (Exception error) { lblDownPayment.Text = ""; } try { lblCreditAmount.Text = "Remaining Financing Needed: $" + dsPROPurchaseRequest.PurchaseRequest[0].creditAmount.ToString("0,000.00"); } catch (Exception error) { lblCreditAmount.Text = ""; } try { lblAPR.Text = "Credit Rate Available: " + myBusinessLayer.calculateAPR(dsPROPurchaseRequest.PurchaseRequest[0].ficoScore); } catch (Exception error) { lblDownPayment.Text = ""; } try { lblFinanceLength.Text = dsPROPurchaseRequest.PurchaseRequest[0].financeLength; } catch (Exception error) { lblFinanceLength.Text = ""; } try { lblMonthlyEstimate.Text = "Estimated Monthly Payment: " + myBusinessLayer.calculateMonthlyPayment(dsPROPurchaseRequest.PurchaseRequest[0].ficoScore, myBusinessLayer.calculateAmountToFinance((int)Session["PurchaseRequest"]), myBusinessLayer.convertLoanLengthToInt(dsPROPurchaseRequest.PurchaseRequest[0].financeLength)); } catch (Exception error) { lblMonthlyEstimate.Text = ""; } } catch (Exception error) { //clears all text fields if there is an error, otherwise previous data may stay on the page lblVehicleID.Text = "No Vehicle Assigned"; lblVehicleLocation.Text = ""; lblDownPayment.Text = ""; lblCreditAmount.Text = ""; lblAPR.Text = ""; lblFinanceLength.Text = ""; lblMonthlyEstimate.Text = ""; } //TO DO: This section is left to do. This will describe the Add-Ons for the Vehicle. try { lblAddOns.Text = dsPROPurchaseRequest.PurchaseRequest[0].requestID.ToString() + " Unfinished Code."; } catch (Exception error) { lblAddOns.Text = ""; } try { lblAddOnsCost.Text = dsPROPurchaseRequest.PurchaseRequest[0].requestID.ToString() + " Unfinished Code."; } catch (Exception error) { lblAddOnsCost.Text = ""; } //Retreive Information about the Trade In using a DataSet for the Trade In information try { dsPROTradeIn = dataLayerObj.findTradeIn(dsPROPurchaseRequest.PurchaseRequest[0].tradeinID); try { lblTradeInID.Text = "ID: " + dsPROPurchaseRequest.PurchaseRequest[0].tradeinID.ToString() + " - " + dsPROTradeIn.TradeIn[0].make + " / " + dsPROTradeIn.TradeIn[0].model + " / " + dsPROTradeIn.TradeIn[0].year; } catch (Exception error) { lblTradeInID.Text = ""; } try { lblTradeInTitle.Text = "Title is Clear. " + dsPROTradeIn.TradeIn[0].titleClear; } catch (Exception error) { lblTradeInTitle.Text = ""; } try { lblTradeInValue.Text = string.Format("Trade-In Value: {0:C2}", dsPROTradeIn.TradeIn[0].amount); } catch (Exception error) { lblTradeInValue.Text = ""; } //Retrieve the Mechanic's Name by using a DataSet that retrieves Employee Information using TradeIn Table FK dsPROEmployee = dataLayerObj.findEmployee(dsPROTradeIn.TradeIn[0].inspectedID); try { lblMechanicApproval.Text = "Approved By: ID " + dsPROTradeIn.TradeIn[0].inspectedID + " - " + dsPROEmployee.Employee[0].lastName + ", " + dsPROEmployee.Employee[0].firstName; } catch (Exception error) { lblMechanicApproval.Text = ""; } } catch (Exception error) { lblTradeInID.Text = "No Trade-In Assigned."; lblTradeInTitle.Text = ""; lblTradeInValue.Text = ""; lblMechanicApproval.Text = "No Trade-In to inspect."; } //Retrieve the Manager's Name by using a DataSet that retrieves Employee Information using the ManagerApproval Employee ID Number try { dsPROEmployee = dataLayerObj.findEmployee(dsPROPurchaseRequest.PurchaseRequest[0].managerApproval); try { lblManagerApproval.Text = dsPROPurchaseRequest.PurchaseRequest[0].approvalstatus + " by " + dsPROEmployee.Employee[0].lastName + ", " + dsPROEmployee.Employee[0].firstName; } catch (Exception error) { lblManagerApproval.Text = "Unable to retrieve Manager Approval information."; } try { lblDisapprovedDescription.Text = dsPROPurchaseRequest.PurchaseRequest[0].disapprovedDescription; } catch (Exception error) { lblDisapprovedDescription.Text = ""; } } catch (Exception error) { lblManagerApproval.Text = "Pending Manager Approval."; lblDisapprovedDescription.Text = ""; } //posts information to the Purchase Request Date field try { lblPurchaseRequestDate.Text = dsPROPurchaseRequest.PurchaseRequest[0].requestCreationDate.ToString(); } catch (Exception error) { lblPurchaseRequestDate.Text = ""; } } else { Warnings.Text = "Error Switching Purchase Requests."; } } catch (Exception error) { string message = "Error = "; Warnings.Text = message + error.Message; } }