protected void btnAdd_Car_Click(object sender, EventArgs e) { bool error = false; bool image = false; decimal invoice; decimal listPrice; string path = " "; Car_Option newOption; if (tbVin.Text.Length != 17) { error = true; lblVin.ForeColor = System.Drawing.Color.Red; } if (ddlModel.SelectedValue == "") { error = true; lblModel.ForeColor = System.Drawing.Color.Red; } if (ddlTrim.SelectedValue == "") { error = true; lblTrim.ForeColor = System.Drawing.Color.Red; } if (ddlColor.SelectedValue == "") { error = true; lblColor.ForeColor = System.Drawing.Color.Red; } if (ddlTransmission.SelectedValue == "") { error = true; lblTransmission.ForeColor = System.Drawing.Color.Red; } if (tbLocation.Text == "") { error = true; lblLocation.ForeColor = System.Drawing.Color.Red; } if (!decimal.TryParse(tbInvoice.Text, out invoice)) { error = true; lblInvoice.ForeColor = System.Drawing.Color.Red; } if (!decimal.TryParse(tbListPrice.Text, out listPrice)) { error = true; lblListPrice.ForeColor = System.Drawing.Color.Red; } if (error) { return; } if (uploadPhoto.PostedFile.ContentLength > 0 && uploadPhoto.FileName != "") { path = "~\\images\\" + uploadPhoto.FileName; imageUpload.ImageUrl = path; image = true; } using (VWCTSDataContext db = new VWCTSDataContext()) { Car newCar = new Car(); newCar.Model = ddlModel.SelectedValue; newCar.Trim = ddlTrim.SelectedValue; newCar.VIN = tbVin.Text; newCar.Color = ddlColor.SelectedValue; newCar.Transmission = ddlTransmission.SelectedValue; newCar.Invoice = decimal.Parse(tbInvoice.Text); newCar.Price = decimal.Parse(tbListPrice.Text); newCar.Location = tbLocation.Text; newCar.Status = "On Lot"; newCar.Miles = 0; if (image) { newCar.Picture = path; } db.Cars.InsertOnSubmit(newCar); db.SubmitChanges(); int id = (from n in db.Cars select n.Car_ID).Max(); foreach (ListItem n in cblPackages.Items) { if (n is ListItem) { newOption = new Car_Option(); newOption.Car_ID = id; newOption.Package_ID = int.Parse(n.Value); db.Car_Options.InsertOnSubmit(newOption); } } db.SubmitChanges(); lblCarSubmitted.Text = "Car " + id + " Added Successfully"; btnAddCar.Enabled = false; btnAddAnother.Visible = true; } }
protected void btnAdd_Car_Click(object sender, EventArgs e) { bool error = false; bool image = false; decimal invoice; decimal listPrice; string path = " "; Car_Option newOption; if (tbVin.Text.Length != 17) { error = true; lblVin.ForeColor = System.Drawing.Color.Red; } if (ddlModel.SelectedValue == "") { error = true; lblModel.ForeColor = System.Drawing.Color.Red; } if (ddlTrim.SelectedValue == "") { error = true; lblTrim.ForeColor = System.Drawing.Color.Red; } if(ddlColor.SelectedValue == "") { error = true; lblColor.ForeColor = System.Drawing.Color.Red; } if(ddlTransmission.SelectedValue == "") { error = true; lblTransmission.ForeColor = System.Drawing.Color.Red; } if (tbLocation.Text == "") { error = true; lblLocation.ForeColor = System.Drawing.Color.Red; } if (!decimal.TryParse(tbInvoice.Text, out invoice)) { error = true; lblInvoice.ForeColor = System.Drawing.Color.Red; } if (!decimal.TryParse(tbListPrice.Text, out listPrice)) { error = true; lblListPrice.ForeColor = System.Drawing.Color.Red; } if (error) return; if(uploadPhoto.PostedFile.ContentLength > 0 && uploadPhoto.FileName != ""){ path = "~\\images\\" + uploadPhoto.FileName; imageUpload.ImageUrl = path; image = true; } using (VWCTSDataContext db = new VWCTSDataContext()) { Car newCar = new Car(); newCar.Model = ddlModel.SelectedValue; newCar.Trim = ddlTrim.SelectedValue; newCar.VIN = tbVin.Text; newCar.Color = ddlColor.SelectedValue; newCar.Transmission = ddlTransmission.SelectedValue; newCar.Invoice = decimal.Parse(tbInvoice.Text); newCar.Price = decimal.Parse(tbListPrice.Text); newCar.Location = tbLocation.Text; newCar.Status = "On Lot"; newCar.Miles = 0; if(image) newCar.Picture = path; db.Cars.InsertOnSubmit(newCar); db.SubmitChanges(); int id = (from n in db.Cars select n.Car_ID).Max(); foreach (ListItem n in cblPackages.Items) { if(n is ListItem){ newOption = new Car_Option(); newOption.Car_ID = id; newOption.Package_ID = int.Parse(n.Value); db.Car_Options.InsertOnSubmit(newOption); } } db.SubmitChanges(); lblCarSubmitted.Text = "Car " + id + " Added Successfully"; btnAddCar.Enabled = false; btnAddAnother.Visible = true; } }