public static List <CatalogBike> getCatalogBikes(List <KitTemplate> ktList) { string q = DatabaseQuery.getCatalogBike(); DataTable dt = Database.getData(q); //convert all the user into a user object List <CatalogBike> temp = new List <CatalogBike>(); for (int i = 0; i < dt.Rows.Count; i++) { int id = Convert.ToInt32(dt.Rows[i]["id"]); string name = (string)dt.Rows[i]["name"]; int PriceMul = Convert.ToInt32(dt.Rows[i]["PriceMul"]); string pic_filename = (string)dt.Rows[i]["picture"]; string query = DatabaseQuery.getKit_by_catalogBikeId(id); DataTable kdt = Database.getData(query); CatalogBike cb = new CatalogBike(id, name, PriceMul, pic_filename); for (int j = 0; j < kdt.Rows.Count; j++) { foreach (KitTemplate kt in ktList) { if (kt.getId() == Convert.ToInt32(kdt.Rows[j]["id_tKit"])) { cb.linkKitTemplate(kt); } } } temp.Add(cb); } return(temp); }
private void BT_update_Click(object sender, RoutedEventArgs e) { //get the list of all bike List <selectedBike> listCBike = (List <selectedBike>)lb_selectCompBike.ItemsSource; foreach (selectedBike scb in listCBike) { CatalogBike cb = scb.curCBike; //check if checked or not if (scb.itemChecked == true) //we want the kit //we do not have the kit (do nothing if already here { if (!cb.getKitTemplateList().Contains(kt)) { cb.linkKitTemplate(kt); tools.DatabaseClassInterface.linkKTCB(cb, kt); } } else //we don't want the kit //we have the kit -> we need to remove it (if not do nothing) { if (cb.getKitTemplateList().Contains(kt)) { cb.unlinkKitTemplate(kt); tools.DatabaseClassInterface.unlinkKTCB(cb, kt); } } } tools.UI.MessageBox.Show("Updated", "Action confirmation"); this.Close(); }