protected void btnSubmit_Click(object sender, EventArgs e) { bool error = false; int carID = 0, customerID = 0, areaCode = 0, phoneNumber = 0, zipCode = 0; decimal downPayment = 0, amountFinanced = 0, tradeValue = 0, salesPrice = 0; if (tbFirstName.Text == "") { error = true; lblFirstName.ForeColor = System.Drawing.Color.Red; } if (tbLastName.Text == "") { error = true; lblLastName.ForeColor = System.Drawing.Color.Red; } if (tbAddress.Text == "") { error = true; lblAddress.ForeColor = System.Drawing.Color.Red; } if (tbCity.Text == "") { error = true; lblCity.ForeColor = System.Drawing.Color.Red; } if (tbState.Text == "") { error = true; lblState.ForeColor = System.Drawing.Color.Red; } if (tbZipCode.Text == "") { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbZipCode.Text, out zipCode)) { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } } if (tbPhoneNumber.Text == "" || tbAreaCode.Text == "" || tbPhoneNumber.Text.Length < 7 || tbAreaCode.Text.Length < 3) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbPhoneNumber.Text, out phoneNumber)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } if (!int.TryParse(tbAreaCode.Text, out areaCode)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } } if (tbCarID.Text == "") { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbCarID.Text, out carID)) { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } } if (tbAmountFinanced.Text == "") { amountFinanced = 0; } else { if (!decimal.TryParse(tbAmountFinanced.Text, out amountFinanced)) { error = true; lblAmountFinanced.ForeColor = System.Drawing.Color.Red; } } if (tbDownPayment.Text == "") { downPayment = 0; } else { if (!decimal.TryParse(tbDownPayment.Text, out downPayment)) { error = true; lblDownPayment.ForeColor = System.Drawing.Color.Red; } } if (tbTradeValue.Text == "") { tradeValue = 0; } else { if (!decimal.TryParse(tbTradeValue.Text, out tradeValue)) { error = true; lblTradeValue.ForeColor = System.Drawing.Color.Red; } } if (tbSalesPrice.Text == "") { error = true; lblSalesPrice.ForeColor = System.Drawing.Color.Red; } else { if (!decimal.TryParse(tbSalesPrice.Text, out salesPrice)) { error = true; lblSalesPrice.ForeColor = System.Drawing.Color.Red; } } if (salesPrice != (tradeValue + downPayment + amountFinanced)) { error = true; lblTradeValue.ForeColor = System.Drawing.Color.Red; lblDownPayment.ForeColor = System.Drawing.Color.Red; lblAmountFinanced.ForeColor = System.Drawing.Color.Red; } if (error) { return; } //LINQ TO SQL CODE TO SUBMIT TRANSACTION AND CUSTOMER IF NEW using (VWCTSDataContext db = new VWCTSDataContext()) { if (Session["Customer_ID"] == null) { Customer newCustomer = new Customer(); newCustomer.First_Name = tbFirstName.Text; newCustomer.Last_Name = tbLastName.Text; newCustomer.Street_Number = tbAddress.Text; newCustomer.City = tbCity.Text; newCustomer.State = tbState.Text; newCustomer.Zip_Code = zipCode; newCustomer.Area_Code = areaCode; newCustomer.Phone_Number = phoneNumber; db.Customers.InsertOnSubmit(newCustomer); db.SubmitChanges(); customerID = (from n in db.Customers select n.Customer_ID).Max(); } else { customerID = (int)Session["Customer_ID"]; db.Update_Customer(customerID, tbFirstName.Text, tbLastName.Text, areaCode, phoneNumber, tbAddress.Text, tbCity.Text, tbState.Text, zipCode); } int employeeID = 0; if (Session["Employee_ID"] == null) { employeeID = 1; } else { employeeID = (int)Session["Employee_ID"]; } Transaction newTransaction = new Transaction(); newTransaction.Car_ID = carID; newTransaction.Customer_ID = customerID; newTransaction.Amount_Financed = amountFinanced; newTransaction.Date = System.DateTime.Today; newTransaction.Down_Payment = downPayment; newTransaction.Employee_ID = employeeID; newTransaction.Sales_Price = salesPrice; newTransaction.Trade_Value = tradeValue; db.Transactions.InsertOnSubmit(newTransaction); History newHistory = new History(); newHistory.Car_ID = carID; newHistory.Customer_ID = customerID; newHistory.Type = "Initial Delivery"; newHistory.Date = DateTime.Today; db.Histories.InsertOnSubmit(newHistory); var update = (from n in db.Cars where n.Car_ID == carID select n).Single(); update.Price = decimal.Parse(tbSalesPrice.Text); update.Status = "Sold"; db.SubmitChanges(); } Session["Car_ID"] = null; Session["Sales_Price"] = null; Session["Customer_ID"] = null; Session["PreviousPage"] = null; Session["Last"] = null; Session["First"] = null; Session["Address"] = null; Session["City"] = null; Session["State"] = null; Session["City"] = null; Session["Area"] = null; Session["Phone"] = null; btnSubmit.Enabled = false; btnCancel.Enabled = false; btnFind.Enabled = false; btnFindCar.Enabled = false; Label2.Text = "Order Processed"; Label2.ForeColor = System.Drawing.Color.Red; }
protected void btnSubmit_Click(object sender, EventArgs e) { bool error = false; int carID = 0; int customerID = 0; int areaCode = 0; int phoneNumber = 0; int zipCode = 0; int miles = 11111; string serviceType = " "; if (tbFirstName.Text == "") { error = true; lblFirstName.ForeColor = System.Drawing.Color.Red; } if (tbLastName.Text == "") { error = true; lblLastName.ForeColor = System.Drawing.Color.Red; } if (tbAddress.Text == "") { error = true; lblAddress.ForeColor = System.Drawing.Color.Red; } if (tbCity.Text == "") { error = true; lblCity.ForeColor = System.Drawing.Color.Red; } if (tbState.Text == "") { error = true; lblState.ForeColor = System.Drawing.Color.Red; } if (tbZipCode.Text == "") { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbZipCode.Text, out zipCode)) { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } } if (tbPhoneNumber.Text == "" || tbAreaCode.Text == "" || tbPhoneNumber.Text.Length < 7 || tbAreaCode.Text.Length < 3) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbPhoneNumber.Text, out phoneNumber)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } if (!int.TryParse(tbAreaCode.Text, out areaCode)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } } if (tbCarID.Text == "") { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbCarID.Text, out carID)) { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } } if (tbVin.Text == "") { error = true; lblVin.ForeColor = System.Drawing.Color.Red; } if (tbModel.Text == "") { error = true; lblModel.ForeColor = System.Drawing.Color.Red; } if (tbTrim.Text == "") { error = true; lblTrim.ForeColor = System.Drawing.Color.Red; } if (tbMiles.Text == "") { error = true; lblMiles.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbMiles.Text, out miles)) { error = true; lblMiles.ForeColor = System.Drawing.Color.Red; } } if (cbOilChange.Checked) { serviceType = "Oil Change"; } else if (cbBrakeInspection.Checked) { serviceType = "Brake Inspection"; } else if (cbCoolingSystem.Checked) { serviceType = "Cooling System"; } else if (cbSuspension.Checked) { serviceType = "Suspension"; } else if (cbTransmission.Checked) { serviceType = "Transmission"; } else if (cbTireRotation.Checked) { serviceType = "Tire Rotation"; } else if (cbAirConditioner.Checked) { serviceType = "Air Conditioner"; } else if (cbScheduledMaintenance.Checked) { serviceType = "Scheduled Maintenance"; } else if (cbOther.Checked) { serviceType = "Other"; } else { error = true; } if (serviceType == "Other") { if (tbAdditionalInfo.Text == "") { error = true; lblAdditionalInfo.ForeColor = System.Drawing.Color.Red; } } if (error) { return; } using (VWCTSDataContext db = new VWCTSDataContext()) { if (Session["Customer_ID"] == null) { Customer newCustomer = new Customer(); newCustomer.Area_Code = areaCode; newCustomer.City = tbCity.Text; newCustomer.First_Name = tbFirstName.Text; newCustomer.Last_Name = tbLastName.Text; newCustomer.Phone_Number = phoneNumber; newCustomer.State = tbState.Text; newCustomer.Street_Number = tbAddress.Text; newCustomer.Zip_Code = zipCode; db.Customers.InsertOnSubmit(newCustomer); } else { customerID = (int)Session["Customer_ID"]; db.Update_Customer(customerID, tbFirstName.Text, tbLastName.Text, areaCode, phoneNumber, tbAddress.Text, tbCity.Text, tbState.Text, zipCode); } string time = ddlHour.SelectedValue + ":" + ddlMinute.SelectedValue + ddl12Hour.SelectedValue; History newHistory = new History(); newHistory.Car_ID = carID; newHistory.Customer_ID = customerID; newHistory.Date = DateTime.Today; newHistory.Type = serviceType; newHistory.Description = time + " - " + tbAdditionalInfo.Text; db.Histories.InsertOnSubmit(newHistory); db.Update_Miles(carID, miles); db.SubmitChanges(); } Session["Car_ID"] = null; Session["PreviousPage"] = null; Session["Customer_ID"] = null; Session["Last"] = null; Session["First"] = null; Session["Address"] = null; Session["City"] = null; Session["State"] = null; Session["City"] = null; Session["Area"] = null; Session["Phone"] = null; btnFind.Enabled = false; btnFindCar.Enabled = false; btnSubmit.Enabled = false; btnCancel.Enabled = false; Label1.Text = "Service Processed"; Label1.ForeColor = System.Drawing.Color.Red; }
protected void btnSubmit_Click(object sender, EventArgs e) { bool error = false; int carID = 0; int customerID = 0; int areaCode = 0; int phoneNumber = 0; int zipCode = 0; int miles = 11111; string serviceType = " "; if (tbFirstName.Text == "") { error = true; lblFirstName.ForeColor = System.Drawing.Color.Red; } if (tbLastName.Text == "") { error = true; lblLastName.ForeColor = System.Drawing.Color.Red; } if (tbAddress.Text == "") { error = true; lblAddress.ForeColor = System.Drawing.Color.Red; } if (tbCity.Text == "") { error = true; lblCity.ForeColor = System.Drawing.Color.Red; } if (tbState.Text == "") { error = true; lblState.ForeColor = System.Drawing.Color.Red; } if (tbZipCode.Text == "") { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbZipCode.Text, out zipCode)) { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } } if (tbPhoneNumber.Text == "" || tbAreaCode.Text == "" || tbPhoneNumber.Text.Length < 7 || tbAreaCode.Text.Length < 3) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbPhoneNumber.Text, out phoneNumber)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } if (!int.TryParse(tbAreaCode.Text, out areaCode)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } } if (tbCarID.Text == "") { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } else { if (!int.TryParse(tbCarID.Text, out carID)) { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } } if(tbVin.Text == ""){ error = true; lblVin.ForeColor = System.Drawing.Color.Red; } if(tbModel.Text == ""){ error = true; lblModel.ForeColor = System.Drawing.Color.Red; } if(tbTrim.Text == ""){ error = true; lblTrim.ForeColor = System.Drawing.Color.Red; } if(tbMiles.Text == ""){ error = true; lblMiles.ForeColor = System.Drawing.Color.Red; } else{ if(!int.TryParse(tbMiles.Text, out miles)){ error = true; lblMiles.ForeColor = System.Drawing.Color.Red; } } if (cbOilChange.Checked) serviceType = "Oil Change"; else if (cbBrakeInspection.Checked) serviceType = "Brake Inspection"; else if (cbCoolingSystem.Checked) serviceType = "Cooling System"; else if (cbSuspension.Checked) serviceType = "Suspension"; else if (cbTransmission.Checked) serviceType = "Transmission"; else if (cbTireRotation.Checked) serviceType = "Tire Rotation"; else if (cbAirConditioner.Checked) serviceType = "Air Conditioner"; else if (cbScheduledMaintenance.Checked) serviceType = "Scheduled Maintenance"; else if (cbOther.Checked) serviceType = "Other"; else error = true; if (serviceType == "Other") { if (tbAdditionalInfo.Text == "") { error = true; lblAdditionalInfo.ForeColor = System.Drawing.Color.Red; } } if (error) return; using (VWCTSDataContext db = new VWCTSDataContext()) { if (Session["Customer_ID"] == null) { Customer newCustomer = new Customer(); newCustomer.Area_Code = areaCode; newCustomer.City = tbCity.Text; newCustomer.First_Name = tbFirstName.Text; newCustomer.Last_Name = tbLastName.Text; newCustomer.Phone_Number = phoneNumber; newCustomer.State = tbState.Text; newCustomer.Street_Number = tbAddress.Text; newCustomer.Zip_Code = zipCode; db.Customers.InsertOnSubmit(newCustomer); } else{ customerID = (int)Session["Customer_ID"]; db.Update_Customer(customerID, tbFirstName.Text, tbLastName.Text, areaCode, phoneNumber, tbAddress.Text, tbCity.Text, tbState.Text, zipCode); } string time = ddlHour.SelectedValue + ":" + ddlMinute.SelectedValue + ddl12Hour.SelectedValue; History newHistory = new History(); newHistory.Car_ID = carID; newHistory.Customer_ID = customerID; newHistory.Date = DateTime.Today; newHistory.Type = serviceType; newHistory.Description = time + " - " + tbAdditionalInfo.Text; db.Histories.InsertOnSubmit(newHistory); db.Update_Miles(carID, miles); db.SubmitChanges(); } Session["Car_ID"] = null; Session["PreviousPage"] = null; Session["Customer_ID"] = null; Session["Last"] = null; Session["First"] = null; Session["Address"] = null; Session["City"] = null; Session["State"] = null; Session["City"] = null; Session["Area"] = null; Session["Phone"] = null; btnFind.Enabled = false; btnFindCar.Enabled = false; btnSubmit.Enabled = false; btnCancel.Enabled = false; Label1.Text = "Service Processed"; Label1.ForeColor = System.Drawing.Color.Red; }
protected void btnSubmit_Click(object sender, EventArgs e) { bool error = false; int carID = 0, customerID = 0, areaCode = 0, phoneNumber = 0, zipCode = 0; decimal downPayment = 0, amountFinanced = 0, tradeValue = 0, salesPrice = 0; if (tbFirstName.Text == "") { error = true; lblFirstName.ForeColor = System.Drawing.Color.Red; } if (tbLastName.Text == "") { error = true; lblLastName.ForeColor = System.Drawing.Color.Red; } if (tbAddress.Text == "") { error = true; lblAddress.ForeColor = System.Drawing.Color.Red; } if (tbCity.Text == "") { error = true; lblCity.ForeColor = System.Drawing.Color.Red; } if (tbState.Text == "") { error = true; lblState.ForeColor = System.Drawing.Color.Red; } if (tbZipCode.Text == "") { error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } else{ if(!int.TryParse(tbZipCode.Text, out zipCode)){ error = true; lblZipCode.ForeColor = System.Drawing.Color.Red; } } if (tbPhoneNumber.Text == "" || tbAreaCode.Text == "" || tbPhoneNumber.Text.Length < 7 || tbAreaCode.Text.Length < 3) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } else{ if (!int.TryParse(tbPhoneNumber.Text, out phoneNumber)) { error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } if(!int.TryParse(tbAreaCode.Text, out areaCode)){ error = true; lblPhoneNumber.ForeColor = System.Drawing.Color.Red; } } if (tbCarID.Text == "") { error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } else { if(!int.TryParse(tbCarID.Text, out carID)){ error = true; lblCarID.ForeColor = System.Drawing.Color.Red; } } if (tbAmountFinanced.Text == "") amountFinanced = 0; else { if(!decimal.TryParse(tbAmountFinanced.Text, out amountFinanced)){ error = true; lblAmountFinanced.ForeColor = System.Drawing.Color.Red; } } if (tbDownPayment.Text == "") downPayment = 0; else{ if(!decimal.TryParse(tbDownPayment.Text, out downPayment)){ error = true; lblDownPayment.ForeColor = System.Drawing.Color.Red; } } if (tbTradeValue.Text == "") tradeValue = 0; else{ if(!decimal.TryParse(tbTradeValue.Text, out tradeValue)){ error = true; lblTradeValue.ForeColor = System.Drawing.Color.Red; } } if(tbSalesPrice.Text == ""){ error = true; lblSalesPrice.ForeColor = System.Drawing.Color.Red; } else{ if(!decimal.TryParse(tbSalesPrice.Text, out salesPrice)){ error = true; lblSalesPrice.ForeColor = System.Drawing.Color.Red; } } if (salesPrice != (tradeValue + downPayment + amountFinanced)) { error = true; lblTradeValue.ForeColor = System.Drawing.Color.Red; lblDownPayment.ForeColor = System.Drawing.Color.Red; lblAmountFinanced.ForeColor = System.Drawing.Color.Red; } if (error) return; //LINQ TO SQL CODE TO SUBMIT TRANSACTION AND CUSTOMER IF NEW using (VWCTSDataContext db = new VWCTSDataContext()) { if (Session["Customer_ID"] == null) { Customer newCustomer = new Customer(); newCustomer.First_Name = tbFirstName.Text; newCustomer.Last_Name = tbLastName.Text; newCustomer.Street_Number = tbAddress.Text; newCustomer.City = tbCity.Text; newCustomer.State = tbState.Text; newCustomer.Zip_Code = zipCode; newCustomer.Area_Code = areaCode; newCustomer.Phone_Number = phoneNumber; db.Customers.InsertOnSubmit(newCustomer); db.SubmitChanges(); customerID = (from n in db.Customers select n.Customer_ID).Max(); } else { customerID = (int)Session["Customer_ID"]; db.Update_Customer(customerID, tbFirstName.Text, tbLastName.Text, areaCode, phoneNumber, tbAddress.Text, tbCity.Text, tbState.Text, zipCode); } int employeeID = 0; if (Session["Employee_ID"] == null) employeeID = 1; else employeeID = (int)Session["Employee_ID"]; Transaction newTransaction = new Transaction(); newTransaction.Car_ID = carID; newTransaction.Customer_ID = customerID; newTransaction.Amount_Financed = amountFinanced; newTransaction.Date = System.DateTime.Today; newTransaction.Down_Payment = downPayment; newTransaction.Employee_ID = employeeID; newTransaction.Sales_Price = salesPrice; newTransaction.Trade_Value = tradeValue; db.Transactions.InsertOnSubmit(newTransaction); History newHistory = new History(); newHistory.Car_ID = carID; newHistory.Customer_ID = customerID; newHistory.Type = "Initial Delivery"; newHistory.Date = DateTime.Today; db.Histories.InsertOnSubmit(newHistory); var update = (from n in db.Cars where n.Car_ID == carID select n).Single(); update.Price = decimal.Parse(tbSalesPrice.Text); update.Status = "Sold"; db.SubmitChanges(); } Session["Car_ID"] = null; Session["Sales_Price"] = null; Session["Customer_ID"] = null; Session["PreviousPage"] = null; Session["Last"] = null; Session["First"] = null; Session["Address"] = null; Session["City"] = null; Session["State"] = null; Session["City"] = null; Session["Area"] = null; Session["Phone"] = null; btnSubmit.Enabled = false; btnCancel.Enabled = false; btnFind.Enabled = false; btnFindCar.Enabled = false; Label2.Text = "Order Processed"; Label2.ForeColor = System.Drawing.Color.Red; }