//this method copies data fields from the Customer Database Table to the screen public void updateAllFields() { //define a dsCustomer object dsCustomer dsSwitchCustomer; string tempPath = Server.MapPath("~/HTVDatabase1.mdb"); clsDataLayer dataLayerObj = new HTV.clsDataLayer(tempPath); try { //populates the dsSwitchCustome dataset with customer information dsSwitchCustomer = dataLayerObj.findCustomer(Int32.Parse(ddlCustomerID.Text)); if (dsSwitchCustomer.Customer.Rows.Count > 0) { //post information about the customer to the text boxes on the screen //try/catch is used to prevent NULL errors try { txtSocial.Text = dsSwitchCustomer.Customer[0].socialSecurity; } catch (Exception error) { txtSocial.Text = ""; } try { txtLicense.Text = dsSwitchCustomer.Customer[0].driversLicense; } catch (Exception error) { txtLicense.Text = ""; } try { txtFirst.Text = dsSwitchCustomer.Customer[0].firstName; } catch (Exception error) { txtFirst.Text = ""; } try { txtLast.Text = dsSwitchCustomer.Customer[0].lastName; } catch (Exception error) { txtLast.Text = ""; } try { txtAddress1.Text = dsSwitchCustomer.Customer[0].addressLine1; } catch (Exception error) { txtAddress1.Text = ""; } try { txtAddress2.Text = dsSwitchCustomer.Customer[0].addressLine2; } catch (Exception error) { txtAddress2.Text = ""; } try { txtCity.Text = dsSwitchCustomer.Customer[0].city; } catch (Exception error) { txtCity.Text = ""; } try { txtState.Text = dsSwitchCustomer.Customer[0].state; } catch (Exception error) { txtState.Text = ""; } try { txtZip.Text = dsSwitchCustomer.Customer[0].zipCode; } catch (Exception error) { txtZip.Text = ""; } try { txtEmail.Text = dsSwitchCustomer.Customer[0].email; } catch (Exception error) { txtEmail.Text = ""; } try { txtPhone.Text = dsSwitchCustomer.Customer[0].phoneNumber; } catch (Exception error) { txtPhone.Text = ""; } } else { Warnings.Text = "Not Found."; } } catch (Exception error) { string message = "Error = "; Warnings.Text = message + error.Message; } //validateRequired highlights any fields that contain erros that will not allow for a re-save if (validateRequired()) { } else { Warnings.Text = "Errors on Page."; } }
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; } }