public void HandleNewItemCaching() { CarProduct car = new CarProduct { unique_id = ThisUniqueID, category_id = "", category_name = "", title = TextTitle.Text, description = TextDescription.Text, price = TextPrice.Value ?? 0, amount = 0, taken = 0, color = "N/A", StoragePlace = "", photo = "", conditions = TextCondition.Text, isParent = "ΝΑΙ", update_interval = 1, make = "", make_name = "", model = "", model_name = "", yearfrom = 0, yearto = 0, AdId = "", manufacturer_number = "none", aftermarket_number = "none" }; caching.CachedCar = car; }
private void Button_Click_SaveAD(object sender, RoutedEventArgs e) { try { CarProduct temp = (CarProduct)TextUnique_id_Ads.SelectedItem; //AdTitleIDPair tempad = new AdTitleIDPair(temp.title, temp.unique_id); bool flag = true; foreach (CarProduct g in adlist) { if (g.unique_id == temp.unique_id) { flag = false; break; } } if (flag) { adlist.Add(temp); ListBoxAd.ItemsSource = null; ListBoxAd.ItemsSource = adlist; } } catch (Exception) { return; } }
private void Button_Click_4(object sender, RoutedEventArgs e) { try { if (CheckConditions()) { return; } CarProduct car = new CarProduct { category_id = buffer.Text, unique_id = TextUnique_id.Text, title = TextTitle.Text, description = TextDescription.Text, price = TextPrice.Value ?? 0, photo = TextPhoto.Text, conditions = TextCondition.Text, isParent = TextisParent.Text, update_interval = TextInterval.Value ?? 0, make = TextMake.SelectedValue.ToString(), model = TextModel.SelectedValue.ToString(), yearfrom = Int32.Parse(TextYearfrom.Text), yearto = Int32.Parse(TextYearTo.Text), }; List <CarProduct> lst = new List <CarProduct>(); lst.Add(car); dts.CreateCarProduct(Properties.Settings.Default.DBName, lst); System.Windows.MessageBox.Show("Αποθηκεύτηκε με Επιτυχία!"); } catch (Exception ex) { System.Windows.MessageBox.Show("Παρουσιάστηκε πρόβλημα. Δεν αποθηκεύτηκε το προϊόν. " + ex.ToString()); } }
private void CheckParent_Child() { try { if (caching.CachedCar.isParent == "ΝΑΙ") { IsParent = true; } else { IsParent = false; } HandleChildParentChange(); if (IsParent) { TextUnique_id_Parent.Text = caching.CachedCar.unique_id; int index = -1; for (int i = 0; i < TextUnique_id_Child_Primary.Items.Count; i++) { CarProduct temp = (CarProduct)TextUnique_id_Child_Primary.Items[i]; if (temp.unique_id == caching.CachedCar.unique_id.Split('-')[0]) { index = i; break; } } TextUnique_id_Child_Primary.SelectedIndex = index; } else { TextisParent.IsReadOnly = true; int index = -1; for (int i = 0; i < TextUnique_id_Child_Primary.Items.Count; i++) { CarProduct temp = (CarProduct)TextUnique_id_Child_Primary.Items[i]; if (temp.unique_id == caching.CachedCar.unique_id.Split('-')[0]) { index = i; break; } } TextUnique_id_Child_Primary.SelectedIndex = index; TextUnique_id_Child_Secondary.Text = caching.CachedCar.unique_id.Split('-')[1]; } } catch (Exception) { return; } }
private void ListBoxAd_MouseDoubleClick(object sender, MouseButtonEventArgs e) { CarProduct temp = (CarProduct)ListBoxAd.SelectedItem; if (temp == null) { return; } caching.CachedCar = null; caching.CachedCar = temp; caching.CloseAd = 1; }
private void Button_Click_RemoveProductFromAd(object sender, RoutedEventArgs e) { try { CarProduct temp = (CarProduct)ListBoxAd.SelectedItem; if (temp == null) { return; } List <string> adlist = new List <string>(); foreach (string id in temp.AdId.Split(new string[] { "!#!" }, StringSplitOptions.None).ToList()) { if (id == "") { continue; } adlist.Add(id); } //if (!adlist.Contains(ThisUniqueID)) adlist.Add(ThisUniqueID); adlist.Remove(ThisUniqueID); string final = ""; if (adlist.Count > 0) { foreach (string ad in adlist) { final = final + "!#!" + ad; } final = final.Remove(0, 3); } temp.AdId = final; List <CarProduct> carlist = new List <CarProduct>(); carlist.Add(temp); dts.UpdateCarPoduct(Properties.Settings.Default.DBName, carlist); DropdownAds.IsOpen = false; if (caching.CachedCar == null) { HandleNewItemCaching(); } EndProcedure(); LoadProcedure(); } catch (Exception) { return; } }
public CarProduct(CarProduct c) { unique_id = c.unique_id; title = c.title; description = c.description; category_id = c.category_id; price = c.price; photo = c.photo; conditions = c.conditions; update_interval = c.update_interval; make = c.make; model = c.model; yearfrom = c.yearfrom; yearto = c.yearto; amount = c.amount; isParent = c.isParent; category_name = c.category_name; make_name = c.make_name; model_name = c.model_name; color = c.color; manufacturer_number = c.manufacturer_number; aftermarket_number = c.aftermarket_number; StoragePlace = c.StoragePlace; }
private void Button_Click_AddProductToAD(object sender, RoutedEventArgs e) { //handle non existing one yet and save if (!IsSaved) { //saveit CarProduct car = new CarProduct { unique_id = ThisUniqueID, category_id = "", category_name = "", title = TextTitle.Text == "" ? "no title" : TextTitle.Text, description = TextDescription.Text == "" ? "no description" : TextDescription.Text, price = TextPrice.Value ?? 0, amount = 0, taken = 0, color = "N/A", StoragePlace = "", photo = "", conditions = TextCondition.Text, isParent = "ΝΑΙ", update_interval = 1, make = "", make_name = "", model = "", model_name = "", yearfrom = 0, yearto = 0, AdId = "", manufacturer_number = "none", aftermarket_number = "none" }; List <CarProduct> carlist = new List <CarProduct>(); carlist.Add(car); dts.CreateCarProduct(Properties.Settings.Default.DBName, carlist); } //IsSaved = true; try { CarProduct temp = (CarProduct)Gridproducts.SelectedItem; if (temp == null) { return; } List <string> adlist = new List <string>(); foreach (string id in temp.AdId.Split(new string[] { "!#!" }, StringSplitOptions.None).ToList()) { if (id == "") { continue; } adlist.Add(id); } if (!adlist.Contains(ThisUniqueID)) { adlist.Add(ThisUniqueID); } string final = ""; if (adlist.Count > 0) { foreach (string ad in adlist) { final = final + "!#!" + ad; } final = final.Remove(0, 3); } temp.AdId = final; List <CarProduct> carlist = new List <CarProduct>(); carlist.Add(temp); dts.UpdateCarPoduct(Properties.Settings.Default.DBName, carlist); DropdownAds.IsOpen = false; if (caching.CachedCar == null) { HandleNewItemCaching(); } EndProcedure(); LoadProcedure(); } catch (Exception) { return; } }
private void Button_Click_Update(object sender, RoutedEventArgs e) { try { if (CheckConditions()) { return; } Cars.Clear(); Cars.AddRange(dts.ReadCarProduct(Properties.Settings.Default.DBName)); //VehicleStorages.Clear(); //VehicleStorages.AddRange(dts.ReadVehicleStorage(Properties.Settings.Default.DBName)); string Cat_names = ""; string Cat_IDs = ""; try { foreach (CatNameIDPair cat in catlist) { Cat_names = Cat_names + ",,," + cat.name; Cat_IDs = Cat_IDs + "!#!" + cat.id; } Cat_names = Cat_names.Remove(0, 3); Cat_IDs = Cat_IDs.Remove(0, 3); } catch (Exception) { Cat_names = ""; Cat_IDs = ""; } //List<string> MakeIDStrings = new List<string>(); //List<string> MakeNameStrings = new List<string>(); //List<string> ModelIDStrings = new List<string>(); //List<string> ModelNameStrings = new List<string>(); //int yearFromStrings = 0; //int yearToStrings = 0; //foreach (VehicleStorage v in vehiclestorageList) //{ // if (!MakeIDStrings.Contains(v.make_id)) MakeIDStrings.Add(v.make_id); // if (!MakeNameStrings.Contains(v.make_name)) MakeNameStrings.Add(v.make_name); // if (!ModelIDStrings.Contains(v.model_id)) ModelIDStrings.Add(v.model_id); // if (!ModelNameStrings.Contains(v.model_name)) ModelNameStrings.Add(v.model_name); // yearFromStrings = v.yearfrom; // yearToStrings = v.yearto; //} string adIDStrings = ""; //if (adlist.Count > 0) //{ // foreach (AdTitleIDPair ad in adlist) // { // adIDStrings = adIDStrings + "!#!" + ad.id; // } // adIDStrings = adIDStrings.Remove(0, 3); //} CarProduct car = new CarProduct { unique_id = ThisUniqueID, category_id = Cat_IDs, category_name = Cat_names, title = TextTitle.Text, description = TextDescription.Text, price = TextPrice.Value ?? 0, amount = 0, taken = 0, color = "N/A", StoragePlace = "", photo = "", conditions = TextCondition.Text, isParent = "ΝΑΙ", update_interval = 1, make = " ", make_name = " ", model = " ", model_name = " ", yearfrom = 0, yearto = 0, AdId = adIDStrings, manufacturer_number = "none", aftermarket_number = "none", info = "", Public = CheckBoxPublish.IsChecked ?? false }; //if (Combo_Aftermarket_Manufacturer.Text == "Aftermarket" && !String.IsNullOrEmpty(Text_Aftermarket_Manufacturer.Text)) car.aftermarket_number = Text_Aftermarket_Manufacturer.Text; //else if (Combo_Aftermarket_Manufacturer.Text == "Manufacturer" && !String.IsNullOrEmpty(Text_Aftermarket_Manufacturer.Text)) car.manufacturer_number = Text_Aftermarket_Manufacturer.Text; List <CarProduct> lst = new List <CarProduct>(); lst.Add(car); //If exists update it if (dts.CheckIfCarProductExists(Properties.Settings.Default.DBName, car.unique_id)) { dts.UpdateCarPoduct(Properties.Settings.Default.DBName, lst); } ////Does not exist and is a parent //else if (car.isParent == "ΝΑΙ") //{ // dts.CreateCarProduct(Properties.Settings.Default.DBName, lst); //} //Does not exist and is a child else { //If parent exists //string temp2 = car.unique_id.Split('-')[0]; //if (!dts.CheckIfCarProductExists(Properties.Settings.Default.DBName, car.unique_id.Split('-')[0])) //{ // System.Windows.MessageBox.Show("Δεν υπάρχει πατέρας για αυτο το αντικειμενο. Κάτι έχει πάει στραβά!"); // return; //} dts.CreateCarProduct(Properties.Settings.Default.DBName, lst); } //Create/Update vehicle storages and //Remove existing vehicle storages from vehiclestoragelist //List<VehicleStorage> vlist = new List<VehicleStorage>(); //foreach (VehicleStorage v in VehicleStorages) //{ // if (v.unique_id == ThisUniqueID) // { // vlist.Add(v); // } //} //dts.DeleteVehicleStorage(Properties.Settings.Default.DBName, vlist); //dts.CreateVehicleStorage(Properties.Settings.Default.DBName, vehiclestorageList); //Update Parent quantity //if (!IsParent) //{ // //Search all items of parent and add the quantities. Add them to parent // List<CarProduct> temp = new List<CarProduct>(); // temp.AddRange(dts.ReadCarProductLike(Properties.Settings.Default.DBName, car.unique_id.Split('-')[0])); // int count = 0; // lst.Clear(); // foreach (CarProduct tempcar in temp) // { // if (tempcar.isParent == "ΟΧΙ") // { // count += tempcar.amount; // } // if (tempcar.isParent == "ΝΑΙ") // { // lst.Add(tempcar); // } // } // lst[0].amount = count; // dts.UpdateCarPoduct(Properties.Settings.Default.DBName, lst); //} IsSaved = true; System.Windows.MessageBox.Show("Αποθηκεύτηκε με Επιτυχία!"); } catch (Exception ex) { System.Windows.MessageBox.Show("Παρουσιάστηκε πρόβλημα. Δεν αποθηκεύτηκε η Αγγελία. " + ex.ToString()); } }
private void Button_Click_Upadate(object sender, RoutedEventArgs e) { try { if (CheckConditions()) { return; } CarProduct car = new CarProduct { //unique_id = caching.CachedCar.unique_id, category_id = cat.Text, category_name = Textcategory_id.Content.ToString(), title = TextTitle.Text, description = TextDescription.Text, price = TextPrice.Value ?? 0, photo = TextPhoto.Text, conditions = TextCondition.Text, isParent = TextisParent.Text, update_interval = TextInterval.Value ?? 0, make = TextMake.SelectedValue.ToString(), make_name = TextMake.Text, model = TextModel.SelectedValue.ToString(), model_name = TextModel.Text, yearfrom = Int32.Parse(TextYearfrom.Text), yearto = Int32.Parse(TextYearTo.Text), amount = TextAmount.Value ?? 0, color = TextColor.Text ?? "none", manufacturer_number = "none", aftermarket_number = "none", StoragePlace = StoragePlaceTextBox.Text }; if (IsParent) { car.unique_id = TextUnique_id_Parent.Text; } else { car.unique_id = TextUnique_id_Child_Primary.Text + "-" + TextUnique_id_Child_Secondary.Text; } if (Combo_Aftermarket_Manufacturer.Text == "Aftermarket" && !String.IsNullOrEmpty(Text_Aftermarket_Manufacturer.Text)) { car.aftermarket_number = Text_Aftermarket_Manufacturer.Text; } else if (Combo_Aftermarket_Manufacturer.Text == "Manufacturer" && !String.IsNullOrEmpty(Text_Aftermarket_Manufacturer.Text)) { car.manufacturer_number = Text_Aftermarket_Manufacturer.Text; } List <CarProduct> lst = new List <CarProduct>(); lst.Add(car); //If exists update it if (dts.CheckIfCarProductExists(Properties.Settings.Default.DBName, car.unique_id)) { dts.UpdateCarPoduct(Properties.Settings.Default.DBName, lst); } //Does not exist and is a parent else if (car.isParent == "ΝΑΙ") { dts.CreateCarProduct(Properties.Settings.Default.DBName, lst); } //Does not exist and is a child else { //If parent exists string temp2 = car.unique_id.Split('-')[0]; if (!dts.CheckIfCarProductExists(Properties.Settings.Default.DBName, car.unique_id.Split('-')[0])) { System.Windows.MessageBox.Show("Δεν υπάρχει πατέρας για αυτο το αντικειμενο. Κάτι έχει πάει στραβά!"); return; } dts.CreateCarProduct(Properties.Settings.Default.DBName, lst); } //Update Parent quantity if (!IsParent) { //Search all items of parent and add the quantities. Add them to parent List <CarProduct> temp = new List <CarProduct>(); temp.AddRange(dts.ReadCarProductLike(Properties.Settings.Default.DBName, car.unique_id.Split('-')[0])); int count = 0; lst.Clear(); foreach (CarProduct tempcar in temp) { if (tempcar.isParent == "ΟΧΙ") { count += tempcar.amount; } if (tempcar.isParent == "ΝΑΙ") { lst.Add(tempcar); } } lst[0].amount = count; dts.UpdateCarPoduct(Properties.Settings.Default.DBName, lst); } System.Windows.MessageBox.Show("Αποθηκεύτηκε με Επιτυχία!"); } catch (Exception ex) { System.Windows.MessageBox.Show("Παρουσιάστηκε πρόβλημα. Δεν αποθηκεύτηκε το προϊόν. " + ex.ToString()); } }
private void Button_Click_Remove(object sender, RoutedEventArgs e) { List <CarProduct> tempcar = new List <CarProduct>(); tempcar.Clear(); try { tempcar.AddRange(DataGrid_1.SelectedItems.Cast <CarProduct>().ToList()); } catch (Exception) { return; } int amount = -TextAmount.Value ?? 0; if (amount == 0) { return; } bool exists = false; foreach (CarProduct RawItem in tempcar) { foreach (CarProduct CartItem in CarProductsCart) { if (CartItem.unique_id == RawItem.unique_id) { if (CartItem.amount + amount <= RawItem.amount && CartItem.amount + amount > 0) { CartItem.amount += amount; exists = true; break; } else if (CartItem.amount + amount <= 0) { CarProductsCart.Remove(CartItem); exists = true; break; } else { CartItem.amount = RawItem.amount; exists = true; break; } } } if (!exists) { if (amount <= 0) { continue; } CarProduct tempCarProduct = new CarProduct(RawItem); tempCarProduct.amount = (RawItem.amount < amount) ? RawItem.amount : amount; CarProductsCart.Add(tempCarProduct); } } DataGrid_2.ItemsSource = null; try { DataGrid_2.ItemsSource = CarProductsCart; } catch (Exception) { DataGrid_2.ItemsSource = CarProductsCart; } }