/*Logic for searching on basis * of Manufacturer Type and Cartype*/ private void btnManufacturer_Click(object sender, RoutedEventArgs e) { CIMSEntities2 entityobj = new CIMSEntities2(); string manName = cmbManufacturersearch.Text.ToString(); string typeName = cmbTypesearch.Text.ToString(); var modelname = from data in entityobj.CARs join data2 in entityobj.Manufacturers on data.ManufacturerId equals data2.ID join data3 in entityobj.CarTypes on data.TypeId equals data3.ID where manName == data2.Name && typeName == data3.Type select new { data.Model, data.Engine, data.Seat, data.Mileage, data.BHP, data.BootSpace, data.AirBagDetails, data.Price }; dgManType.ItemsSource = modelname.ToList(); }
public FinalPage() { cims = new CIMSEntities2(); InitializeComponent(); //Calling function to bind the data in combobox. BindManufacturer(cmbManufacturer); BindManufacturer(cmbManufacturersearch); BindCarType(cmbType); BindCarType(cmbTypesearch); BindTransmissionType(cmbTransmission); }
/*Logic for searching * on the basis of Model*/ private void BtnSearch_Click(object sender, RoutedEventArgs e) { try { if (!(Regex.IsMatch(txtmodel.Text, @"^\w+\s*\w*$"))) { MessageBox.Show("Please enter proper car model."); } else { string modName = txtmodel.Text; using (CIMSEntities2 entityobj = new CIMSEntities2()) { CAR carObj = entityobj.CARs.FirstOrDefault(i => i.Model == modName); txtEngine.Text = carObj.Engine; txtPrice.Text = carObj.Price.ToString(); txtBHP.Text = carObj.BHP.ToString(); cmbManufacturer.SelectedValue = carObj.ManufacturerId; txtAirbagDetails.Text = carObj.AirBagDetails; txtSeat.Text = carObj.Seat.ToString(); txtMileage.Text = carObj.Mileage.ToString(); txtBootspace.Text = carObj.BootSpace.ToString(); cmbType.SelectedValue = carObj.TypeId; cmbTransmission.SelectedValue = carObj.TransmissionId; } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
/*Logic for updating * the CAR table*/ private void BtnUpdate_Click(object sender, RoutedEventArgs e) { try { using (CIMSEntities2 entityobj = new CIMSEntities2()) { string model = txtmodel.Text; CAR carObj = entityobj.CARs.FirstOrDefault(i => i.Model == model); carObj.Engine = txtEngine.Text; carObj.BootSpace = txtBootspace.Text; carObj.AirBagDetails = txtAirbagDetails.Text; carObj.BHP = Convert.ToInt32(txtBHP.Text); carObj.Mileage = Convert.ToInt32(txtMileage.Text); carObj.Seat = Convert.ToInt32(txtSeat.Text); carObj.Price = Convert.ToDecimal(txtPrice.Text); carObj.ManufacturerId = Convert.ToInt32(cmbManufacturer.SelectedValue.ToString()); carObj.TypeId = Convert.ToInt32(cmbType.SelectedValue.ToString()); carObj.TransmissionId = Convert.ToInt32(cmbTransmission.SelectedValue.ToString()); entityobj.SaveChanges(); MessageBox.Show("1 Record updated"); } } catch (Exception) { MessageBox.Show("All details should be filled before updating."); } }
//Logic for window loaded private void Window_Loaded(object sender, RoutedEventArgs e) { CIMSEntities2 entityobj = new CIMSEntities2(); var result = from mname in entityobj.Manufacturers select mname.Name; }