public WindowPictures(QueryMode mode, MainWindow parent, string primary_key_value = "") { InitializeComponent(); this.mode = mode; this.parent = parent; this.primary_key_value = primary_key_value; if (mode == QueryMode.add) { Button_reset.Visibility = Visibility.Collapsed; Button_accept.Content = "Добавить"; } else { Button_accept.Content = "Изменить"; TextBox_name.Text = primary_key_value; byte[] image_bytes = Shortcuts.get_image("pictures", "name", primary_key_value, connection); new_image = image_bytes; Shortcuts.set_image(Image, image_bytes); TextBox_price.Text = Shortcuts.get_one_string_data_from($"select `price` from `pictures` where `name` = '{primary_key_value}'", connection); TextBox_price.Text = TextBox_price.Text.Replace(",", "."); old_values = new object[2] { primary_key_value, image_bytes }; } }
public WindowUsers(QueryMode mode, MainWindow parent, string primary_key_value = "") { InitializeComponent(); this.mode = mode; this.parent = parent; this.primary_key_value = primary_key_value; ComboBox_role.ItemsSource = Shortcuts.get_full_column_from("roles", "role", connection); ComboBox_gender.ItemsSource = Shortcuts.get_full_column_from("genders", "gender", connection); if (mode == QueryMode.add) { Button_reset.Visibility = Visibility.Collapsed; Button_accept.Content = "Добавить"; } else { Button_accept.Content = "Изменить"; byte[] image_bytes = Shortcuts.get_image("users", "mail", primary_key_value, connection); new_image = image_bytes; Shortcuts.set_image(Image, image_bytes); try { connection.Open(); MySqlCommand comm = new MySqlCommand($"SELECT * FROM `users` WHERE `mail` = '{primary_key_value}'", connection); MySqlDataReader data = comm.ExecuteReader(); data.Read(); TextBox_mail.Text = primary_key_value; TextBox_password.Text = data[1].ToString(); TextBox_surname.Text = data[2].ToString(); TextBox_first_name.Text = data[3].ToString(); TextBox_second_name.Text = data[4].ToString(); TextBox_phone.Text = data[5].ToString(); ComboBox_role.Text = data[6].ToString(); ComboBox_gender.Text = data[7].ToString(); old_values = new object[9] { primary_key_value, data[1].ToString(), data[2].ToString(), data[3].ToString(), data[4].ToString(), data[5].ToString(), data[6].ToString(), data[7].ToString(), image_bytes }; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } }
private void ComboBox_picture_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ComboBox_picture.SelectedItem == null) { Image_pic.Source = null; return; } else { byte[] byte_image = Shortcuts.get_image("pictures", "name", (string)ComboBox_picture.SelectedItem, connection); Shortcuts.set_image(Image_pic, byte_image); } }
private void Button_reset_Click(object sender, RoutedEventArgs e) { TextBox_mail.Text = (string)old_values[0]; TextBox_password.Text = (string)old_values[1]; TextBox_surname.Text = (string)old_values[2]; TextBox_first_name.Text = (string)old_values[3]; TextBox_second_name.Text = (string)old_values[4]; TextBox_phone.Text = (string)old_values[5]; ComboBox_role.Text = (string)old_values[6]; ComboBox_gender.Text = (string)old_values[7]; new_image = (byte[])old_values[8]; Shortcuts.set_image(Image, (byte[])old_values[8]); }
private void Button_choose_image_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Изображения(*.BMP;*.JPG;*.JPEG;*.PNG)|*.BMP;*.JPG;*.JPEG;*.PNG"; if (ofd.ShowDialog() == true) { string image_path = ofd.FileName; FileStream fs = new FileStream(image_path, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); new_image = br.ReadBytes((int)fs.Length); Shortcuts.set_image(Image, new_image); } }
//Отображение изображения или цвета из некоторых таблиц private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { TextBlock_car_parts.Text = ""; object item = DataGrid.SelectedItem; if (item != null) { switch (current_table) { case Tables.users: Button_image_change.Visibility = Visibility.Visible; Shortcuts.set_image(DataImage, Shortcuts.get_image(tables[(int)current_table], current_primary_key_name, ((User)item).mail, connection)); break; case Tables.pictures: Button_image_change.Visibility = Visibility.Visible; Shortcuts.set_image(DataImage, Shortcuts.get_image(tables[(int)current_table], current_primary_key_name, ((Picture)item).name, connection)); break; case Tables.colors: Border_color.Visibility = Visibility.Visible; string color_code = "#" + ((Color)item).color_code; Border_color.Background = new SolidColorBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString(color_code)); break; case Tables.products: Border_color.Visibility = Visibility.Visible; string color = "#" + ((Product)item).color_code; Border_color.Background = new SolidColorBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString(color)); break; case Tables.supplies: Supply sup = (Supply)item; Border_color.Visibility = Visibility.Visible; string supply_color_code = Shortcuts.get_one_string_data_from($"SELECT `color_code` FROM `products` WHERE `name` = '{sup.product_name}';", connection); Border_color.Background = new SolidColorBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString("#" + supply_color_code)); break; case Tables.requests: int numb = ((Request)item).parts_to_paint; TextBlock_car_parts.Text = "Части на покраску:\n"; if (numb == 8191) { TextBlock_car_parts.Text += "Все"; } else { try { connection.Open(); MySqlCommand comm = new MySqlCommand($"SELECT `name` FROM `car_parts` WHERE `id` & {numb};", connection); MySqlDataReader data = comm.ExecuteReader(); while (data.Read()) { TextBlock_car_parts.Text += data[0].ToString() + "\n"; } /* * if (TextBlock_car_parts.Text == "Части на покраску:\n") * { * TextBlock_car_parts.Text += "Все"; * }*/ } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } break; } } }
private void Button_reset_Click(object sender, RoutedEventArgs e) { new_image = (byte[])old_values[1]; TextBox_name.Text = (string)old_values[0]; Shortcuts.set_image(Image, (byte[])old_values[1]); }