Example #1
0
        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();
                }
            }
        }
Example #3
0
 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);
     }
 }
Example #4
0
        //Отображение изображения или цвета из некоторых таблиц
        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;
                }
            }
        }