private void fill_product_with(string measurement) { ComboBox_product_name.Items.Clear(); try { connection.Open(); MySqlCommand comm = new MySqlCommand("SELECT `name`, `color_code` FROM `products`" + $"WHERE `measurement` = '{measurement}';", connection); MySqlDataReader data = comm.ExecuteReader(); while (data.Read()) { ComboBox_product_name.Items.Add(Shortcuts.create_color_box(data[0].ToString(), data[1].ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } }
public WindowProducts(QueryMode mode, MainWindow parent, string primary_key_value = "") { InitializeComponent(); this.mode = mode; this.parent = parent; this.primary_key_value = primary_key_value; try { connection.Open(); MySqlCommand comm = new MySqlCommand("SELECT `color_code` FROM `colors`;", connection); MySqlDataReader data = comm.ExecuteReader(); while (data.Read()) { ComboBox_color_code.Items.Add(Shortcuts.create_color_box(data[0].ToString(), data[0].ToString())); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } ComboBox_paint_type.ItemsSource = Shortcuts.get_full_column_from("paint_types", "paint_type", connection); if (mode == QueryMode.add) { Button_reset.Visibility = Visibility.Collapsed; Button_accept.Content = "Добавить"; } else { Button_accept.Content = "Изменить"; try { connection.Open(); MySqlCommand comm = new MySqlCommand($"SELECT * FROM `products` " + $"WHERE `name` = '{primary_key_value}';", connection); MySqlDataReader data = comm.ExecuteReader(); data.Read(); TextBox_name.Text = primary_key_value; for (int i = 0; i < ComboBox_color_code.Items.Count; i++) { if ((string)(ComboBox_color_code.Items[i] as ComboBoxItem).Tag == data[2].ToString()) { ComboBox_color_code.SelectedIndex = i; old_color_index = i; break; } } ComboBox_paint_type.Text = data[1].ToString(); old_values = new string[3] { data[0].ToString(), data[1].ToString(), data[2].ToString() }; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } }