//Event-Handler: When user click a vehicle private void gridCarSelect_CellClick(object sender, DataGridViewCellEventArgs e) { if (gridCarSelect.SelectedRows.Count > 0) { OilChangeInfo oci = parseObjToOilChangeInfo(gridCarSelect.SelectedRows[0].DataBoundItem); makeTextBox.Text = oci.Car.Make; modelTextBox.Text = oci.Car.Model; yearTextBox.Text = oci.Car.Year.ToString(); weightTextBox.Text = oci.Oil.Weight; brandTextBox.Text = oci.Oil.Brand; qtyTextBox.Text = oci.Oil.Quantity.ToString(); oPriceTextBox.Text = oci.Oil.OilPrice.ToString(); fPriceTextBox.Text = oci.Oil.FPrice.ToString(); fBrandTextBox.Text = oci.Oil.FBrand; laborHourTextBox.Text = oci.LaborHours.ToString(); dateTimePicker1.Value = oci.ServicedDate; dateTimePicker2.Value = oci.NextService; sMileageTxtbox.Text = oci.ServicedMileage.ToString(); nextSMileageTxtbox.Text = oci.NextServiceMileage.ToString(); } }
private OilChangeInfo parseObjToOilChangeInfo(object obj) { var props = obj.GetType().GetProperties(); int id = 1000000; string make = "Unknown"; string model = "Unknown"; int year = 9999; string weight = "Unknown"; string brand = "Unknown"; string fbrand = "Unknown"; double fprice = 0; double qty = 0; double oprice = 0; double labor = 0; DateTime sd = DateTime.Now; int mileage = 0; DateTime nextDate = DateTime.Now; int nm = 0; foreach (var prop in props) { if (prop.Name == "Id") { id = (int)prop.GetValue(obj); } if (prop.Name == "Make") { make = prop.GetValue(obj) as string; } if (prop.Name == "Model") { model = prop.GetValue(obj) as string; } if (prop.Name == "Year") { year = (int)prop.GetValue(obj); } if (prop.Name == "Weight") { weight = prop.GetValue(obj) as string; } if (prop.Name == "Brand") { brand = prop.GetValue(obj) as string; } if (prop.Name == "FBrand") { fbrand = prop.GetValue(obj) as string; } if (prop.Name == "Quantity") { qty = (double)prop.GetValue(obj); } if (prop.Name == "FPrice") { fprice = double.Parse(prop.GetValue(obj) as string, NumberStyles.Currency); } if (prop.Name == "OilPrice") { oprice = double.Parse(prop.GetValue(obj) as string, NumberStyles.Currency); } if (prop.Name == "LaborHour") { labor = (double)prop.GetValue(obj); } if (prop.Name == "ServicedDate") { sd = (DateTime)prop.GetValue(obj); } if (prop.Name == "ServicedMileage") { mileage = (int)prop.GetValue(obj); } if (prop.Name == "NextMileage") { nm = (int)prop.GetValue(obj); } if (prop.Name == "NextServiceDate") { nextDate = (DateTime)prop.GetValue(obj); } } OilChangeInfo oci = new OilChangeInfo(id, make, model, year, weight, brand, qty, oprice, fbrand, fprice, labor, sd, mileage, nextDate, nm); return(oci); }