private void loadRowData(string index)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("SELECT employees.id, firstname, surname, patronymic FROM {0}.{1} WHERE employees.id = {2}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         databaseTable,
                                         index);

            mySqlSettings.createConnection();

            using (mySqlSettings.initSqlCommand(query))
            {
                mySqlSettings.openConnection();

                using (MySqlDataReader reader = mySqlSettings.initSqlCommand(query).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        inputFirstName.Text  = (reader["firstname"].ToString());
                        inputSurName.Text    = (reader["surname"].ToString());
                        inputPatronymic.Text = (reader["patronymic"].ToString());
                    }
                }
                populateComboBox();
            }
            mySqlSettings.closeConnection();
        }
Example #2
0
        private void loadRowData(string index)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("SELECT id, name, description, technical_data FROM {0}.{1} WHERE id = {2}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         databaseTable,
                                         index);

            mySqlSettings.createConnection();

            using (mySqlSettings.initSqlCommand(query))
            {
                mySqlSettings.openConnection();

                using (MySqlDataReader reader = mySqlSettings.initSqlCommand(query).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        inputName.Text = (reader["name"].ToString());
                    }
                }
                populateComboBox();
            }
            mySqlSettings.closeConnection();
        }
        private void loadRowData(string index)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("SELECT name, price_per_unit FROM {0}.{1} WHERE id = {2}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         databaseTable,
                                         index);

            mySqlSettings.createConnection();

            using (mySqlSettings.initSqlCommand(query))
            {
                mySqlSettings.openConnection();

                using (MySqlDataReader reader = mySqlSettings.initSqlCommand(query).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        inputName.Text  = (reader["name"].ToString());
                        inputPrice.Text = (reader["price_per_unit"].ToString());
                    }
                }
            }
            mySqlSettings.closeConnection();
        }
        public void deleteMethod()
        {
            try
            {
                packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

                string query = String.Format("DELETE FROM {0}.{1} WHERE {2} = {3}",
                                             packages.mysql.mysqlSettings.dbSchema,
                                             table,
                                             "id",
                                             index);

                using (MySqlConnection mySqlConnection = new MySqlConnection(packages.mysql.mysqlSettings.connectionString))
                {
                    using (MySqlCommand mySqlCommand = new MySqlCommand(query, mySqlConnection))
                    {
                        mySqlConnection.Open();
                        dataGrid.ItemsSource = mySqlSettings.getData(query).DefaultView;
                    }
                    mySqlConnection.Close();
                }
            }
            catch (MySqlException ex)
            {
                if (ex.Number == 1451)
                {
                    MessageBox.Show("Успадковані дані неможливо видалити.", "Помилка при видаленні", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(ex.Message, ex.Source);
                }
            }
        }
        private void buttonEdit_Click(object sender, RoutedEventArgs e)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("UPDATE {0} SET name = @name, price_per_unit = @price WHERE id = {1}",
                                         databaseTable,
                                         tmpIndex);

            try
            {
                using (MySqlConnection mySqlConnection = new MySqlConnection(packages.mysql.mysqlSettings.connectionString))
                {
                    using (MySqlCommand mySqlCommand = new MySqlCommand(query, mySqlConnection))
                    {
                        mySqlConnection.Open();

                        mySqlCommand.Parameters.AddWithValue("@name", inputName.Text);
                        mySqlCommand.Parameters.AddWithValue("@price", inputPrice.Text);

                        mySqlCommand.ExecuteNonQuery();
                        mySqlConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            loadTable();
        }
        private void loadRowData(string index)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("SELECT id, quantity, client_name, completion_date, description, SERVICES_id FROM {0}.{1} WHERE id = {2}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         databaseTable,
                                         index);

            mySqlSettings.createConnection();

            using (mySqlSettings.initSqlCommand(query))
            {
                mySqlSettings.openConnection();

                using (MySqlDataReader reader = mySqlSettings.initSqlCommand(query).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        inputQuantity.Text         = (reader["quantity"].ToString());
                        inputName.Text             = (reader["client_name"].ToString());
                        inputDesc.Text             = (reader["description"].ToString());
                        inputDate.Text             = (reader["completion_date"].ToString());
                        listServices.SelectedValue = (reader["SERVICES_id"]);
                    }
                }
            }
            mySqlSettings.closeConnection();
        }
        private void buttonEdit_Click(object sender, RoutedEventArgs e)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("UPDATE {0} SET client_name = @client, description = @desc, SERVICES_id = @service, completion_date = @date_end, quantity = @quantity WHERE id = {1}",
                                         databaseTable,
                                         tmpIndex);

            try
            {
                using (MySqlConnection mySqlConnection = new MySqlConnection(packages.mysql.mysqlSettings.connectionString))
                {
                    using (MySqlCommand mySqlCommand = new MySqlCommand(query, mySqlConnection))
                    {
                        mySqlConnection.Open();

                        mySqlCommand.Parameters.AddWithValue("@client", inputName.Text);
                        mySqlCommand.Parameters.AddWithValue("@desc", inputDesc.Text);
                        mySqlCommand.Parameters.AddWithValue("@date_end", inputDate.Text);
                        mySqlCommand.Parameters.AddWithValue("@service", listServices.SelectedValue);
                        mySqlCommand.Parameters.AddWithValue("@quantity", inputQuantity.Text);
                        mySqlCommand.ExecuteNonQuery();
                        mySqlConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            loadTable();
        }
        private void dataGrid_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            var description = (dataGrid.SelectedCells[0].Column.GetCellContent(dataGrid.SelectedCells[0].Item) as TextBlock).Text;
            var id          = (dataGrid.SelectedCells[1].Column.GetCellContent(dataGrid.SelectedCells[1].Item) as TextBlock).Text;
            var quantity    = (dataGrid.SelectedCells[2].Column.GetCellContent(dataGrid.SelectedCells[2].Item) as TextBlock).Text;
            var clientName  = (dataGrid.SelectedCells[3].Column.GetCellContent(dataGrid.SelectedCells[3].Item) as TextBlock).Text;
            var service     = (dataGrid.SelectedCells[6].Column.GetCellContent(dataGrid.SelectedCells[6].Item) as TextBlock).Text;

            windows.orderPage window = new windows.orderPage();

            #region serviceParser
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();
            string query = String.Format("SELECT name, price_per_unit FROM {0}.{1} WHERE id = {2}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         "services",
                                         Convert.ToInt32(service)
                                         );

            mySqlSettings.createConnection();

            using (mySqlSettings.initSqlCommand(query))
            {
                mySqlSettings.openConnection();

                using (MySqlDataReader reader = mySqlSettings.initSqlCommand(query).ExecuteReader())
                {
                    while (reader.Read())
                    {
                        window.tbService.Text      = (reader["name"].ToString());
                        window.tbServicePrice.Text = (reader["price_per_unit"].ToString());
                    }
                }
            }

            mySqlSettings.closeConnection();
            #endregion

            int servicePrice = Convert.ToInt32(window.tbServicePrice.Text);
            int total        = servicePrice * Convert.ToInt32(quantity);

            window.Title           = "Замовлення №" + id;
            window.tbTitle.Text    = "Замовлення №" + id.ToString();
            window.tbClient.Text   = clientName;
            window.tbQuantity.Text = quantity;
            window.tbDesc.Text     = description;

            window.tbTotalPrice.Text = total.ToString();
            window.ShowDialog();
        }
        private void buttonEdit_Click(object sender, RoutedEventArgs e)
        {
            packages.mysql.mysqlSettings mySqlSettings = new packages.mysql.mysqlSettings();

            string query = String.Format("UPDATE {0} SET divisions_id = @division, firstname = @firstname, surname = @surname, patronymic = @patronymic WHERE {0}.id = {1}",
                                         databaseTable,
                                         tmpIndex);

            try
            {
                using (MySqlConnection mySqlConnection = new MySqlConnection(packages.mysql.mysqlSettings.connectionString))
                {
                    using (MySqlCommand mySqlCommand = new MySqlCommand(query, mySqlConnection))
                    {
                        mySqlConnection.Open();

                        if (inputDivision.SelectedValue == null)
                        {
                            mySqlCommand.Parameters.AddWithValue("@division", null);
                            mySqlCommand.Parameters.AddWithValue("@firstname", inputFirstName.Text);
                            mySqlCommand.Parameters.AddWithValue("@surname", inputSurName.Text);
                            mySqlCommand.Parameters.AddWithValue("@patronymic", inputPatronymic.Text);
                        }
                        else
                        {
                            mySqlCommand.Parameters.AddWithValue("@division", Convert.ToInt32(inputDivision.SelectedValue));
                            mySqlCommand.Parameters.AddWithValue("@firstname", inputFirstName.Text);
                            mySqlCommand.Parameters.AddWithValue("@surname", inputSurName.Text);
                            mySqlCommand.Parameters.AddWithValue("@patronymic", inputPatronymic.Text);
                        }

                        mySqlCommand.ExecuteNonQuery();
                        mySqlConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            loadTable();
        }
        private void populateComboBox()
        {
            packages.mysql.mysqlSettings database = new packages.mysql.mysqlSettings();
            string query = String.Format("SELECT id, name FROM {0}.{1}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         foreignTable
                                         );

            database.createConnection();

            using (database.initSqlCommand(query))
            {
                database.openConnection();

                inputDivision.DisplayMemberPath = "name";
                inputDivision.SelectedValuePath = "id";
                inputDivision.ItemsSource       = database.getData(query).DefaultView;
            }
            database.closeConnection();
        }
        private void loadServices()
        {
            packages.mysql.mysqlSettings database = new packages.mysql.mysqlSettings();

            string query = String.Format("SELECT id, name, price_per_unit FROM {0}.{1}",
                                         packages.mysql.mysqlSettings.dbSchema,
                                         "services"
                                         );

            database.createConnection();

            using (database.initSqlCommand(query))
            {
                database.openConnection();

                listServices.SelectedValuePath = "id";
                listServices.DisplayMemberPath = "name";
                listServices.ItemsSource       = database.getData(query).DefaultView;
            }
            database.closeConnection();
        }