private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            if (TextBox_color_code.Text != "" && TextBox_description.Text != "" &&
                TextBox_color_code.Text.Length == 6)
            {
                bool success = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.add("colors", new string[] { "color_code", "description" },
                                            new string[] { TextBox_color_code.Text, TextBox_description.Text },
                                            connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("colors", new string[] { "color_code", "description" },
                                               new string[] { TextBox_color_code.Text, TextBox_description.Text },
                                               primary_key_value,
                                               connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    parent.fill_table();
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните все пустые поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#2
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();
                }
            }
        }
示例#4
0
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            int dot_count1 = TextBox_product_amount.Text.Split('.').Length - 1;
            int dot_count2 = TextBox_average_purchase_price.Text.Split('.').Length - 1;

            if (ComboBox_product_name.Text != "" && TextBox_product_amount.Text != "" &&
                ComboBox_supplier.Text != "" && TextBox_average_purchase_price.Text != "" &&
                dot_count1 <= 1 && dot_count2 <= 1)
            {
                string count = Shortcuts.get_one_string_data_from($"SELECT count(*) FROM " +
                                                                  $"`storage` WHERE `product_name` = '{ComboBox_product_name.Text}' AND " +
                                                                  $"`supplier` = '{ComboBox_supplier.Text}';", connection);
                if (int.Parse(count) >= 1 && mode == QueryMode.add)
                {
                    MessageBox.Show("Уже существует запись с такой краской и поставщиком!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                bool   success     = true;
                string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement` FROM `products` where `name` = '{ComboBox_product_name.Text}';", connection);
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.execute_command($"INSERT INTO `storage` (`id`, `product_name`, `product_amount`, `measurement`, `supplier`, `average_purchase_price`) " +
                                                        $"VALUES (DEFAULT, '{ComboBox_product_name.Text}', {TextBox_product_amount.Text}, '{measurement}', " +
                                                        $"'{ComboBox_supplier.Text}', {TextBox_average_purchase_price.Text});", connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("storage", new string[] { "id", "product_name", "product_amount", "measurement", "supplier", "average_purchase_price" },
                                               new string[] { primary_key_value, ComboBox_product_name.Text, TextBox_product_amount.Text, measurement,
                                                              ComboBox_supplier.Text, TextBox_average_purchase_price.Text },
                                               primary_key_value,
                                               connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    if (parent is MainWindow)
                    {
                        ((MainWindow)parent).fill_table();
                    }
                    if (parent is SupplyManagerWindow)
                    {
                        ((SupplyManagerWindow)parent).fill_table();
                    }
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните корректно все числовые поля и поля с выбором!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
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);
     }
 }
 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]);
 }
示例#7
0
        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);
            }
        }
示例#8
0
        public WindowCars(QueryMode mode, Window parent, string primary_key_value = "")
        {
            InitializeComponent();
            this.mode              = mode;
            this.parent            = parent;
            this.primary_key_value = primary_key_value;

            List <string> mails = Shortcuts.get_full_column_from("clients", "mail", connection);

            ComboBox_owner_mail.ItemsSource = mails;

            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 `cars` " +
                                                         $"WHERE `vin` = '{primary_key_value}';", connection);
                    MySqlDataReader data = comm.ExecuteReader();
                    data.Read();
                    TextBox_vin.Text         = primary_key_value;
                    TextBox_number.Text      = data[1].ToString();
                    ComboBox_owner_mail.Text = data[2].ToString();
                    TextBox_color.Text       = data[3].ToString();
                    TextBox_model.Text       = data[4].ToString();
                    old_values = new string[5] {
                        data[0].ToString(),
                        data[1].ToString(),
                        data[2].ToString(),
                        data[3].ToString(),
                        data[4].ToString()
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
        public WindowClients(QueryMode mode, Window parent, string primary_key_value = "")
        {
            InitializeComponent();
            this.mode              = mode;
            this.parent            = parent;
            this.primary_key_value = primary_key_value;

            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 = "Изменить";
                try
                {
                    connection.Open();
                    MySqlCommand comm = new MySqlCommand($"SELECT * FROM `clients` " +
                                                         $"WHERE `mail` = '{primary_key_value}';", connection);
                    MySqlDataReader data = comm.ExecuteReader();
                    data.Read();
                    TextBox_mail.Text        = primary_key_value;
                    TextBox_phone.Text       = data[1].ToString();
                    TextBox_surname.Text     = data[2].ToString();
                    TextBox_first_name.Text  = data[3].ToString();
                    TextBox_second_name.Text = data[4].ToString();
                    ComboBox_gender.Text     = data[5].ToString();
                    old_values = new string[6] {
                        data[0].ToString(),
                        data[1].ToString(),
                        data[2].ToString(),
                        data[3].ToString(),
                        data[4].ToString(),
                        data[5].ToString()
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
示例#10
0
        public WindowStorage(QueryMode mode, Window parent, string primary_key_value = "")
        {
            InitializeComponent();
            this.mode              = mode;
            this.parent            = parent;
            this.primary_key_value = primary_key_value;

            ComboBox_product_name.ItemsSource = Shortcuts.get_full_column_from("products", "name", connection);
            ComboBox_supplier.ItemsSource     = Shortcuts.get_full_column_from("suppliers", "name", 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 `storage` " +
                                                         $"WHERE `id` = '{primary_key_value}';", connection);
                    MySqlDataReader data = comm.ExecuteReader();
                    data.Read();
                    ComboBox_product_name.Text          = data[1].ToString();
                    TextBox_product_amount.Text         = float.Parse(data[2].ToString()).ToString();
                    TextBox_product_amount.Text         = TextBox_product_amount.Text.Replace(",", ".");
                    ComboBox_supplier.Text              = data[4].ToString();
                    TextBox_average_purchase_price.Text = float.Parse(data[5].ToString()).ToString();
                    TextBox_average_purchase_price.Text = TextBox_average_purchase_price.Text.Replace(",", ".");
                    old_values = new string[4] {
                        data[1].ToString(),
                        data[2].ToString(),
                        data[4].ToString(),
                        data[5].ToString()
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
示例#11
0
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            if (TextBox_vin.Text != "" && TextBox_number.Text != "" && ComboBox_owner_mail.Text != "" && TextBox_color.Text != "" && TextBox_model.Text != "")
            {
                bool success = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.add("cars", new string[] { "vin", "number", "owner_mail", "color", "model" },
                                            new string[] { TextBox_vin.Text.ToUpper(),
                                                           TextBox_number.Text,
                                                           ComboBox_owner_mail.Text,
                                                           TextBox_color.Text,
                                                           TextBox_model.Text },
                                            connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("cars", new string[] { "vin", "number", "owner_mail", "color", "model" },
                                               new string[] { TextBox_vin.Text.ToUpper(),
                                                              TextBox_number.Text,
                                                              ComboBox_owner_mail.Text,
                                                              TextBox_color.Text,
                                                              TextBox_model.Text },
                                               primary_key_value, connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    if (parent is MainWindow)
                    {
                        ((MainWindow)parent).fill_table();
                    }
                    if (parent is RequestManagerWindow)
                    {
                        ((RequestManagerWindow)parent).fill_table();
                    }
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните все пустые поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#12
0
        //Удаление выбранной записи
        private void Button_delete_Click(object sender, RoutedEventArgs e)
        {
            object item = DataGrid.SelectedItem;

            if (item != null)
            {
                switch (current_table)
                {
                case Tables.requests:
                    if (((Request)item).request_status == "Обработано")
                    {
                        MessageBox.Show("Нельзя удалить обработанную заявку!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    if (confirm_action("Вы хотите удалить текущий объект?", "Удаление"))
                    {
                        Shortcuts.execute_command($@"DELETE FROM `requests` where `id` = '{((Request)item).id}';", connection);

                        fill_table();
                    }
                    break;

                case Tables.cars:
                    if (confirm_action("Вы хотите удалить текущий объект?", "Удаление"))
                    {
                        Shortcuts.execute_command($@"DELETE FROM `cars` where `vin` = '{((Car)item).vin}';", connection);
                        fill_table();
                    }
                    break;

                case Tables.clients:
                    if (confirm_action("Вы хотите удалить текущий объект?", "Удаление"))
                    {
                        Shortcuts.execute_command($@"DELETE FROM `clients` where `mail` = '{((Client)item).mail}';", connection);
                        fill_table();
                    }
                    break;
                }
                TextBox_search.Text = "";
                fill_table();
            }
            else
            {
                MessageBox.Show("Выберите мышью запись перед удалением.");
            }
        }
 private void Button_accept_Click(object sender, RoutedEventArgs e)
 {
     if (TextBox_surface_size.Text != "" && TextBox_cost.Text != "")
     {
         if (Shortcuts.change("car_parts", new string[] { "id", "name", "surface_size", "cost" },
                              new string[] { primary_key_value, Label_name.Content.ToString(), TextBox_surface_size.Text, TextBox_cost.Text },
                              primary_key_value, connection))
         {
             parent.Focus();
             parent.fill_table();
             Close();
         }
     }
     else
     {
         MessageBox.Show("Введите правильные значения и не оставляйте пустых полей!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
示例#14
0
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            if (TextBox_name.Text != "" && ComboBox_city.Text != "" && TextBox_address.Text != "" && TextBox_phone.Text != "")
            {
                bool success = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.add("suppliers", new string[] { "name", "city", "address", "phone" },
                                            new string[] { TextBox_name.Text,
                                                           ComboBox_city.Text,
                                                           TextBox_address.Text,
                                                           TextBox_phone.Text },
                                            connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("suppliers", new string[] { "name", "city", "address", "phone" },
                                               new string[] { TextBox_name.Text,
                                                              ComboBox_city.Text,
                                                              TextBox_address.Text,
                                                              TextBox_phone.Text },
                                               primary_key_value, connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    if (parent is MainWindow)
                    {
                        ((MainWindow)parent).fill_table();
                    }
                    if (parent is SupplyManagerWindow)
                    {
                        ((SupplyManagerWindow)parent).fill_table();
                    }
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните все пустые поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Button_action_Click(object sender, RoutedEventArgs e)
        {
            bool success = true;

            if (mode == QueryMode.change)
            {
                success = Shortcuts.change(table_name, new string[] { field_name },
                                           new string[] { Textbox_item_value.Text },
                                           old_value,
                                           connection);
            }
            else
            {
                success = Shortcuts.add(table_name, new string[] { field_name }, new string[] { Textbox_item_value.Text }, connection);
            }
            if (success)
            {
                Close();
                parent_window.fill_table();
                parent_window.Focus();
            }
        }
示例#16
0
 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();
     }
 }
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            if (TextBox_name.Text != "" && ComboBox_paint_type.Text != "" &&
                ComboBox_color_code.SelectedIndex != -1)
            {
                bool success = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.add("products", new string[] { "name", "paint_type", "color_code", "measurement" },
                                            new string[] { TextBox_name.Text, ComboBox_paint_type.Text,
                                                           (string)(ComboBox_color_code.Items[ComboBox_color_code.SelectedIndex] as ComboBoxItem).Tag,
                                                           (ComboBox_paint_type.Text == "Плёнка")? "рулон": "литр" },
                                            connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("products", new string[] { "name", "paint_type", "color_code", "measurement" },
                                               new string[] { TextBox_name.Text, ComboBox_paint_type.Text,
                                                              (string)(ComboBox_color_code.Items[ComboBox_color_code.SelectedIndex] as ComboBoxItem).Tag,
                                                              (ComboBox_paint_type.Text == "Плёнка")? "рулон": "литр" },
                                               primary_key_value,
                                               connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    parent.fill_table();
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните все пустые поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        //Удаление выбранной записи
        private void Button_delete_Click(object sender, RoutedEventArgs e)
        {
            object item = DataGrid.SelectedItem;

            if (item != null)
            {
                string item_name = "";
                switch (current_table)
                {
                case Tables.suppliers: item_name = ((Supplier)item).name; break;

                case Tables.supplies:
                    if (((Supply)item).user_mail != current_user.mail)
                    {
                        MessageBox.Show("Вы не можете удалять чужие поставки!", "Запрещено", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    if (((Supply)item).delivery_date != "")
                    {
                        MessageBox.Show("Нельзя удалить зачисленную поставку!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    item_name = ((Supply)item).id.ToString(); break;
                }
                if (confirm_action("Вы хотите удалить текущий объект?", "Удаление"))
                {
                    Shortcuts.execute_command($@"DELETE FROM `{tables[(int)current_table]}` where `{current_primary_key_name}` = '{item_name}';", connection);
                    TextBox_search.Text = "";
                    fill_table();
                }
            }
            else
            {
                MessageBox.Show("Выберите мышью запись перед удалением.");
            }
        }
        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DataGrid.SelectedItem != null)
            {
                switch (current_table)
                {
                case Tables.supplies:
                    Border_color.Visibility = Visibility.Visible;
                    Supply sup = (Supply)DataGrid.SelectedItem;
                    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.storage:
                    Border_color.Visibility = Visibility.Visible;
                    Storage st = (Storage)DataGrid.SelectedItem;
                    Border_color.Visibility = Visibility.Visible;
                    string st_color_code = Shortcuts.get_one_string_data_from($"SELECT `color_code` FROM `products` WHERE `name` = '{st.product_name}';", connection);
                    Border_color.Background = new SolidColorBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString("#" + st_color_code));
                    break;
                }
            }
        }
示例#20
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;
                }
            }
        }
示例#21
0
        //Удаление выбранной записи
        private void Button_delete_Click(object sender, RoutedEventArgs e)
        {
            object item = DataGrid.SelectedItem;

            if (item != null)
            {
                string item_name = primary_key_values[DataGrid.Items.IndexOf(item)];
                if (current_table == Tables.users && item_name == current_user.mail)
                {
                    MessageBox.Show("Вы не можете удалить свой аккаунт.");
                    return;
                }
                if (current_table == Tables.measurements)
                {
                    switch (((Measurement)item).measurement)
                    {
                    case "литр":
                    case "рулон":
                        MessageBox.Show("Вы не можете удалять записи, используемые в системе.");
                        return;
                    }
                }
                if (current_table == Tables.request_statuses)
                {
                    switch (((Request_status)item).request_status)
                    {
                    case "Обработано":
                    case "Ожидает обработки":
                        MessageBox.Show("Вы не можете удалять записи, используемые в системе.");
                        return;
                    }
                }
                if (current_table == Tables.roles)
                {
                    switch (((Role)item).role)
                    {
                    case "администратор":
                    case "менеджер по заявкам":
                    case "менеджер по поставкам":
                        MessageBox.Show("Вы не можете удалять записи, используемые в системе.");
                        return;
                    }
                }
                if (current_table == Tables.service_types)
                {
                    switch (((Service_type)item).service_type)
                    {
                    case "Аэрография":
                    case "Детальная":
                    case "Оклейка плёнкой":
                    case "Полная":
                        MessageBox.Show("Вы не можете удалять записи, используемые в системе.");
                        return;
                    }
                }
                if (confirm_action("Вы хотите удалить текущий объект?", "Удаление"))
                {
                    string primary_key_value = DataGrid.SelectedItem.ToString().Split(' ')[0];
                    switch (current_table)
                    {
                    case Tables.cars: primary_key_value = ((Car)item).vin; break;

                    case Tables.cities: primary_key_value = ((City)item).city; break;

                    case Tables.clients: primary_key_value = ((Client)item).mail; break;

                    case Tables.colors: primary_key_value = ((Color)item).color_code; break;

                    case Tables.genders: primary_key_value = ((Gender)item).gender; break;

                    case Tables.measurements: primary_key_value = ((Measurement)item).measurement; break;

                    case Tables.paint_types: primary_key_value = ((Paint_type)item).paint_type; break;

                    case Tables.pictures: primary_key_value = ((Picture)item).name; break;

                    case Tables.products: primary_key_value = ((Product)item).name; break;

                    case Tables.requests: primary_key_value = ((Request)item).id.ToString(); break;

                    case Tables.request_statuses: primary_key_value = ((Request_status)item).request_status; break;

                    case Tables.roles: primary_key_value = ((Role)item).role; break;

                    case Tables.service_types: primary_key_value = ((Service_type)item).service_type; break;

                    case Tables.storage: primary_key_value = ((Storage)item).id.ToString(); break;

                    case Tables.suppliers: primary_key_value = ((Supplier)item).name; break;

                    case Tables.supplies: primary_key_value = ((Supply)item).id.ToString(); break;

                    case Tables.users: primary_key_value = ((User)item).mail; break;
                    }
                    Shortcuts.execute_command($@"DELETE FROM `{tables[(int)current_table]}` where `{current_primary_key_name}` = '{primary_key_value}';", connection);
                    TextBox_search.Text = "";
                    fill_table();
                }
            }
            else
            {
                MessageBox.Show("Выберите мышью запись перед удалением.");
            }
        }
        private void button_delivery_supply_Click(object sender, RoutedEventArgs e)
        {
            if (DataGrid.SelectedItem == null)
            {
                MessageBox.Show("Выберите мышью запись перед совершением поставки.");
            }
            else
            {
                bool   success = true;
                Supply sup     = (Supply)DataGrid.SelectedItem;
                if (sup.delivery_date != "")
                {
                    MessageBox.Show("Данная поставка уже зачислена!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                int product_storage_count = int.Parse(Shortcuts.get_one_string_data_from($"SELECT count(*) FROM " +
                                                                                         $"`storage` WHERE `product_name` = '{sup.product_name}' AND " +
                                                                                         $"`supplier` = '{sup.supplier}';", connection));
                if (product_storage_count == 1)
                {
                    //Записать в существующего поставщика
                    Storage st = new Storage();
                    try
                    {
                        connection.Open();
                        MySqlCommand comm = new MySqlCommand("SELECT * FROM " +
                                                             $"`storage` WHERE `product_name` = '{sup.product_name}' AND " +
                                                             $"`supplier` = '{sup.supplier}';", connection);
                        MySqlDataReader data = comm.ExecuteReader();
                        data.Read();
                        string[] values = new string[data.FieldCount];
                        for (int i = 0; i < data.FieldCount; i++)
                        {
                            values[i] = data[i].ToString();
                        }
                        st = (Storage)Container_controller.Create_struct(Tables.storage, values);
                    }
                    catch (Exception ex)
                    {
                        success = false;
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                    decimal new_prod_amount = st.product_amount + sup.product_amount;
                    decimal new_price       = ((st.average_purchase_price * st.product_amount) + sup.price * sup.product_amount) / (new_prod_amount);
                    success = Shortcuts.execute_command("UPDATE `storage` SET " +
                                                        $"`average_purchase_price` = {new_price.ToString().Replace(',', '.')}, " +
                                                        $"`product_amount` = {new_prod_amount.ToString().Replace(',', '.')} " +
                                                        $"WHERE `product_name` = '{sup.product_name.ToString().Replace(',', '.')}' AND " +
                                                        $"`supplier` = '{sup.supplier}';", connection);

                    success = Shortcuts.execute_command("UPDATE `supplies` SET " +
                                                        $"`delivery_date` = '{DateTime.Now:yyyy-MM-dd}' " +
                                                        $"WHERE `id` = {sup.id};", connection);
                    if (success)
                    {
                        MessageBox.Show("Поставка на склад произведена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Поставка не произведена!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else if (product_storage_count == 0)
                {
                    success = Shortcuts.execute_command("INSERT INTO `storage` " +
                                                        "(`product_name`, `product_amount`, " +
                                                        "`measurement`, `supplier`, `average_purchase_price`) VALUES " +
                                                        $"('{sup.product_name}', {sup.product_amount.ToString().Replace(',','.')}, " +
                                                        $"'{sup.measurement}', '{sup.supplier}', {(sup.price).ToString().Replace(',', '.')});", connection);
                    success = Shortcuts.execute_command("UPDATE `supplies` SET " +
                                                        $"`delivery_date` = '{DateTime.Now:yyyy-MM-dd}' " +
                                                        $"WHERE `id` = {sup.id};", connection);
                    if (success)
                    {
                        MessageBox.Show("Поставка на склад произведена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Поставка не произведена!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Произошла ошибка в базе!\nПовторяющиеся записи продукта на одного поставщика. " +
                                    "Обратитесь к администратору", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                fill_table();
            }
        }
示例#23
0
        private void button_write_check_Click(object sender, RoutedEventArgs e)
        {
            if (DataGrid.SelectedItem == null)
            {
                MessageBox.Show("Выберите мышью запись перед созданием чека!");
                return;
            }
            else if (((Request)DataGrid.SelectedItem).paint_date == "")
            {
                MessageBox.Show("Нельзя выписать чек необработанной заявки!");
                return;
            }

            SaveFileDialog SFDialog = new SaveFileDialog();

            SFDialog.Filter = "Microsoft Word Document (*.docx)|*.docx";
            if (SFDialog.ShowDialog() == true)
            {
                Request req            = (Request)DataGrid.SelectedItem;
                string  cashier_name   = current_user.surname + " " + current_user.first_name[0] + ". " + current_user.second_name[0] + ".";
                string  parts_to_paint = "";
                decimal price          = 0;
                //Определение цены услуги и списка покрашенных деталей
                if (req.parts_to_paint == 8191)
                {
                    parts_to_paint = "Полностью";
                    //количество краски на всю машину
                    decimal paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from("SELECT SUM(surface_size) FROM `car_parts`;", connection)) / 1000;

                    if (req.product_name == "")
                    {
                        //стоимость за аэрографию
                        price = decimal.Parse(Shortcuts.get_one_string_data_from("SELECT `price` " +
                                                                                 $"FROM `pictures` WHERE `name` = '{req.picture_name}';", connection));
                    }
                    else
                    {
                        try
                        {
                            //стоимость покраски всей машины без учёта краски
                            price = decimal.Parse(Shortcuts.get_one_string_data_from("SELECT SUM(cost) FROM `car_parts`;", connection));
                            //стоимость использованной краски
                            decimal paint_price = decimal.Parse(Shortcuts.get_one_string_data_from("SELECT `average_purchase_price` " +
                                                                                                   $"FROM `storage` WHERE `supplier` = '{req.supplier}' AND `product_name` = '{req.product_name}';", connection));
                            //надбавка цены на краску
                            price = price + paint_price * paint_amount;
                        }
                        catch
                        {
                            MessageBox.Show("Невозможно оформить чек. Отсутствуют данные о цене краски.");
                            return;
                        }
                    }
                }
                else                //детальная покраска
                {
                    //перечисление частей на покраску
                    List <string> parts = Shortcuts.get_full_column_from("car_parts", "name", $"`id` & {req.parts_to_paint}", connection);
                    for (int i = 0; i < parts.Count; i++)
                    {
                        parts_to_paint += parts[i];
                        if (i != parts.Count - 1)
                        {
                            parts_to_paint += "; ";
                        }
                        else
                        {
                            parts_to_paint += ".";
                        }
                    }
                    try
                    {
                        //стоимость за покраску частей без учёта краски
                        price = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(cost) FROM `car_parts` WHERE `id` & {req.parts_to_paint};", connection));
                        decimal paint_price = decimal.Parse(Shortcuts.get_one_string_data_from("SELECT `average_purchase_price` " +
                                                                                               $"FROM `storage` WHERE `supplier` = '{req.supplier}' AND `product_name` = '{req.product_name}';", connection));
                        //общая цена за услугу
                        decimal paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(surface_size) FROM `car_parts` WHERE `id` & {req.parts_to_paint};", connection)) / 1000;
                        //надбавка цены на краску
                        price = price + paint_price * paint_amount;
                    }
                    catch
                    {
                        MessageBox.Show("Невозможно оформить чек. Отсутствуют данные о цене краски.");
                        return;
                    }
                }
                try
                {
                    Word.Application WordApp = new Word.Application();
                    WordApp.Visible = false;
                    string price_in_doc = price.ToString().Replace(',', '.');
                    int    dot_pos      = price_in_doc.IndexOf('.');
                    if (dot_pos > 0)
                    {
                        price_in_doc = price_in_doc.Substring(0, dot_pos + 3);
                    }

                    Document word_doc = WordApp.Documents.Open(Directory.GetCurrentDirectory() + $@"\check.docx");
                    Shortcuts.replace_word("{vin}", req.vin, word_doc);
                    Shortcuts.replace_word("{service_type}", req.service_type, word_doc);
                    Shortcuts.replace_word("{color}", req.product_name, word_doc);
                    Shortcuts.replace_word("{parts_to_paint}", parts_to_paint, word_doc);
                    Shortcuts.replace_word("{picture}", req.picture_name, word_doc);
                    Shortcuts.replace_word("{price}", price_in_doc, word_doc);
                    Shortcuts.replace_word("{cashier_name}", cashier_name, word_doc);
                    Shortcuts.replace_word("{current_date}", req.paint_date, word_doc);
                    word_doc.SaveAs2(FileName: SFDialog.FileName);
                    word_doc.Close();
                    MessageBox.Show("Файл успешно сохранён!");
                }
                catch
                {
                    MessageBox.Show("При сохранении чека возникла ошибка. Документ не сохранён.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
示例#24
0
        private void button_accept_request_Click(object sender, RoutedEventArgs e)
        {
            bool success = true;

            if (DataGrid.SelectedItem != null)
            {
                Request req = (Request)DataGrid.SelectedItem;
                if (req.request_status == "Обработано")
                {
                    MessageBox.Show("Данная заявка уже обработана!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (req.service_type == "Аэрография")
                {
                    success = Shortcuts.execute_command("UPDATE `requests` " +
                                                        "SET `request_status` = 'Обработано', " +
                                                        $"`paint_date` = '{DateTime.Now:yyyy-MM-dd HH:mm:ss}' " +
                                                        $"WHERE `id` = {req.id};", connection);
                    fill_table();
                    if (success)
                    {
                        MessageBox.Show("Заявка успешно обработана!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    int    parts       = req.parts_to_paint;
                    string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement`" +
                                                                            $"FROM `storage` WHERE `product_name` = '{req.product_name}'", connection);
                    decimal paint_amount;
                    if (req.service_type == "Детальная")
                    {
                        paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(`surface_size`) FROM `car_parts` " +
                                                                                        $"WHERE `id` & {parts};", connection)) / 1000;
                    }
                    else
                    {
                        paint_amount = decimal.Parse(Shortcuts.get_one_string_data_from($"SELECT SUM(`surface_size`) FROM `car_parts`;", connection)) / 1000;
                    }
                    int prod_available = int.Parse(Shortcuts.get_one_string_data_from($"SELECT count(*) FROM `storage` " +
                                                                                      $"WHERE `product_name` = '{req.product_name}' AND `supplier` = '{req.supplier}';", connection));
                    decimal paint_cost;
                    switch (prod_available)
                    {
                    case 1:
                        paint_cost = paint_amount * decimal.Parse(Shortcuts.get_one_string_data_from("SELECT `average_purchase_price` " +
                                                                                                     $"FROM `storage` WHERE `product_name` = '{req.product_name}';", connection));
                        //Всё норм
                        success = Shortcuts.execute_command("UPDATE `storage` " +
                                                            $"SET `product_amount` = (`product_amount` - {paint_amount.ToString().Replace(',','.')}) " +
                                                            $"WHERE `product_name` = '{req.product_name}' AND `supplier` = '{req.supplier}';", connection);
                        success = Shortcuts.execute_command("UPDATE `requests` " +
                                                            $"SET `request_status` = 'Обработано', " +
                                                            $"`paint_amount` = {paint_amount.ToString().Replace(',','.')}, " +
                                                            $"`measurement` = '{measurement}', " +
                                                            $"`paint_cost` = {paint_cost.ToString().Replace(',', '.')}, " +
                                                            $"`paint_date` = '{DateTime.Now:yyyy-MM-dd HH:mm:ss}' " +
                                                            $"WHERE `id` = {req.id};", connection);
                        fill_table();
                        if (success)
                        {
                            MessageBox.Show("Заявка успешно обработана!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        break;

                    case 0:
                        MessageBox.Show("На складе отсутствует краска соответствующего поставщика!", "Нет краски", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        break;

                    default:
                        MessageBox.Show("Произошла ошибка в базе!\nПовторяющиеся записи продукта на одного поставщика. " +
                                        "Обратитесь к администратору", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Выберите мышью запись перед изменением.");
            }
        }
示例#25
0
        public WindowSupplies(QueryMode mode, Window parent, string primary_key_value = "")
        {
            InitializeComponent();
            this.mode              = mode;
            this.parent            = parent;
            this.primary_key_value = primary_key_value;

            DatePicker_order.DisplayDateStart = DateTime.Today;
            DatePicker_order.DisplayDateEnd   = DateTime.Today.AddDays(90);

            ComboBox_supplier.ItemsSource = Shortcuts.get_full_column_from("suppliers", "name", 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 `supplies` " +
                                                         $"WHERE `id` = '{primary_key_value}';", connection);
                    MySqlDataReader data = comm.ExecuteReader();
                    data.Read();
                    ComboBox_supplier.Text = data[2].ToString();

                    TextBox_product_amount.Text = float.Parse(data[4].ToString()).ToString();
                    TextBox_product_amount.Text = TextBox_product_amount.Text.Replace(",", ".");

                    TextBox_price.Text = float.Parse(data[6].ToString()).ToString();
                    TextBox_price.Text = TextBox_price.Text.Replace(",", ".");

                    DatePicker_order.SelectedDate = (DateTime)data[7];
                    //data[5] - невидимая пользователю единица измерения
                    old_values = new object[6] {
                        /*0*/ data[2].ToString(),
                        /*1*/ data[3].ToString(),
                        /*2*/ data[4].ToString(),
                        /*3*/ data[5].ToString(),                       //measurement
                        /*4*/ data[6].ToString(),
                        /*5*/ data[7]
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
                ComboBox_paint_type.SelectedIndex = (old_values[3].ToString() == "литр") ? 0 : 1;
                for (int i = 0; i < ComboBox_product_name.Items.Count; i++)
                {
                    if ((string)(ComboBox_product_name.Items[i] as ComboBoxItem).Tag == old_values[1].ToString())
                    {
                        ComboBox_product_name.SelectedIndex = i;
                        old_color_index = i;
                        break;
                    }
                }
            }
        }
示例#26
0
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            //Количество точек в введённых числах
            int dot_count1 = TextBox_product_amount.Text.Split('.').Length - 1;
            int dot_count2 = TextBox_price.Text.Split('.').Length - 1;

            if (ComboBox_supplier.Text != "" && (string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag != "" &&
                TextBox_product_amount.Text != "" && TextBox_price.Text != "" && DatePicker_order.SelectedDate.HasValue &&
                dot_count1 <= 1 && dot_count2 <= 1)
            {
                string mail = "";
                if (parent is MainWindow)
                {
                    mail = ((MainWindow)parent).current_user.mail;
                }
                else if (parent is SupplyManagerWindow)
                {
                    mail = ((SupplyManagerWindow)parent).current_user.mail;
                }
                string measurement = Shortcuts.get_one_string_data_from($"SELECT `measurement` FROM `products` where `name` = '{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}';", connection);
                bool   success     = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.execute_command($"INSERT INTO `supplies` (`id`, `user_mail`, `supplier`, " +
                                                        $"`product_name`, `product_amount`, `measurement`, `price`, " +
                                                        $"`order_date`, `delivery_date`) " +
                                                        $"VALUES (DEFAULT, '{mail}', '{ComboBox_supplier.Text}', " +
                                                        $"'{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}', {TextBox_product_amount.Text}, '{measurement}', {TextBox_price.Text}, " +
                                                        $"'{DatePicker_order.SelectedDate.Value:yyyy-MM-dd}', " +
                                                        $"NULL);", connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.execute_command($"UPDATE `supplies` " +
                                                        $"SET " +
                                                        $"`user_mail` = '{mail}', " +
                                                        $"`supplier` = '{ComboBox_supplier.Text}', " +
                                                        $"`product_name` = '{(string)(ComboBox_product_name.Items[ComboBox_product_name.SelectedIndex] as ComboBoxItem).Tag}', " +
                                                        $"`product_amount` = '{TextBox_product_amount.Text}'," +
                                                        $"`measurement` = '{measurement}', " +
                                                        $"`price` = '{TextBox_price.Text}', " +
                                                        $"`order_date` = '{DatePicker_order.SelectedDate.Value:yyyy-MM-dd}' " +
                                                        $"WHERE `id` = {primary_key_value}", connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    if (parent is MainWindow)
                    {
                        ((MainWindow)parent).fill_table();
                    }
                    if (parent is SupplyManagerWindow)
                    {
                        ((SupplyManagerWindow)parent).fill_table();
                    }
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните корректно все числовые поля, поля с выбором и даты!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Button_accept_Click(object sender, RoutedEventArgs e)
        {
            if (TextBox_mail.Text != "" && TextBox_phone.Text != "" &&
                TextBox_surname.Text != "" && TextBox_first_name.Text != "" &&
                TextBox_second_name.Text != "" && ComboBox_gender.Text != "")
            {
                string m = TextBox_mail.Text.ToLower();
                if (m.Split('@').Length != 2)
                {
                    MessageBox.Show("Неправильный ввод почты!");
                    return;
                }
                if (!(m.Contains('.') && m.Split('@')[1].Split('.')[1].Length >= 2 &&
                      m.Split('@')[1].Split('.')[1].Length <= 4))
                {
                    MessageBox.Show("Неправильный ввод почты!");
                    return;
                }
                if (m.LastIndexOf('.') - m.IndexOf('@') <= 1)
                {
                    MessageBox.Show("Неправильный ввод почты!");
                    return;
                }
                if (m.IndexOf('@') == 0)
                {
                    MessageBox.Show("Неправильный ввод почты!");
                    return;
                }

                /*Regex reg = new Regex("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$");
                 * if (!reg.IsMatch(TextBox_mail.Text.ToLower()))
                 * {
                 *      MessageBox.Show("Неправильный ввод почты!");
                 *      return;
                 * }*/
                bool success = true;
                switch (mode)
                {
                case QueryMode.add:
                    success = Shortcuts.add("clients", new string[] { "mail", "phone", "surname", "first_name", "second_name", "gender" },
                                            new string[] { TextBox_mail.Text.ToLower(), TextBox_phone.Text,
                                                           TextBox_surname.Text, TextBox_first_name.Text,
                                                           TextBox_second_name.Text, ComboBox_gender.Text },
                                            connection);
                    break;

                case QueryMode.change:
                    success = Shortcuts.change("clients", new string[] { "mail", "phone", "surname", "first_name", "second_name", "gender" },
                                               new string[] { TextBox_mail.Text.ToLower(), TextBox_phone.Text,
                                                              TextBox_surname.Text, TextBox_first_name.Text,
                                                              TextBox_second_name.Text, ComboBox_gender.Text },
                                               primary_key_value,
                                               connection);
                    break;
                }
                if (success)
                {
                    parent.Focus();
                    if (parent is MainWindow)
                    {
                        ((MainWindow)parent).fill_table();
                    }
                    if (parent is RequestManagerWindow)
                    {
                        ((RequestManagerWindow)parent).fill_table();
                    }
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Заполните все пустые поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        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();
                }
            }
        }
示例#29
0
 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]);
 }
示例#30
0
        public WindowRequests(QueryMode mode, Window parent, string primary_key_value = "")
        {
            InitializeComponent();
            checks = new CheckBox[]
            {
                check_lpk,
                check_lzk,
                check_ppk,
                check_pzk,
                check_lpd,
                check_lzd,
                check_ppd,
                check_pzd,
                check_roof,
                check_hood,
                check_kb,
                check_pb,
                check_zb
            };

            ids = new List <int>();
            for (int i = 1; i <= 4096; i *= 2)
            {
                ids.Add(i);
            }
            this.mode              = mode;
            this.parent            = parent;
            this.primary_key_value = primary_key_value;

            ComboBox_vin.ItemsSource          = Shortcuts.get_full_column_from("cars", "vin", connection);
            ComboBox_service_type.ItemsSource = Shortcuts.get_full_column_from("service_types", "service_type", connection);
            ComboBox_picture.ItemsSource      = Shortcuts.get_full_column_from("pictures", "name", connection);
            ComboBox_supplier.ItemsSource     = Shortcuts.get_full_column_from("suppliers", "name", connection);

            if (mode == QueryMode.add)
            {
                Button_reset.Visibility = Visibility.Collapsed;
                initialized             = true;
                Button_accept.Content   = "Добавить";
                change_checkbox_ability(false);
            }
            else
            {
                Button_accept.Content = "Изменить";
                try
                {
                    connection.Open();
                    MySqlCommand comm = new MySqlCommand($"SELECT * FROM `requests` " +
                                                         $"WHERE `id` = '{primary_key_value}';", connection);
                    MySqlDataReader data = comm.ExecuteReader();
                    data.Read();
                    ComboBox_vin.Text          = data[1].ToString();
                    request_date               = (DateTime)data[3];
                    ComboBox_service_type.Text = data[4].ToString();
                    ComboBox_supplier.Text     = data[8].ToString();
                    old_values = new object[8] {
                        /*0*/ data[1].ToString(),            //VIN
                        /*1*/ data[2].ToString(),            //Product_name
                        /*2*/ data[3],                       //DateTime
                        /*3*/ data[4].ToString(),            //service_type
                        /*4*/ data[5],                       //int parts_to_paint
                        /*5*/ data[6].ToString(),            //pic_name
                        /*6*/ data[7].ToString(),            //request_status
                        /*7*/ data[8].ToString()
                    };
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                finally
                {
                    connection.Close();
                    initialized = true;
                    ComboBox_service_type.Text = ComboBox_service_type.Text;
                    if (ComboBox_service_type.Text == "Оклейка плёнкой")
                    {
                        fill_product_with("рулон");
                    }
                    else
                    {
                        fill_product_with("литр");
                    }

                    if (ComboBox_service_type.Text != "Аэрография")
                    {
                        ComboBox_product_name.IsEnabled = true;
                        ComboBox_supplier.IsEnabled     = true;
                        for (int i = 0; i < ComboBox_product_name.Items.Count; i++)
                        {
                            if ((string)(ComboBox_product_name.Items[i] as ComboBoxItem).Tag == (string)old_values[1])
                            {
                                ComboBox_product_name.SelectedIndex = i;
                                old_color_index = i;
                                break;
                            }
                        }
                    }
                    else
                    {
                        ComboBox_picture.IsEnabled = true;
                        ComboBox_picture.Text      = (string)old_values[5];
                    }
                    change_checkbox_ability(ComboBox_service_type.Text == "Детальная");
                    if (ComboBox_service_type.Text == "Детальная")
                    {
                        set_checkbox_value((int)old_values[4]);
                    }
                    else
                    {
                        change_checkbox_value(false);
                        change_checkbox_ability(false);
                    }
                }
            }
        }