public void EditRecord(Product product)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(queryUpdate, connection))
                {
                    command.Parameters.AddWithValue("Id", product.Id);
                    command.Parameters.AddWithValue("Name", product.Name);
                    command.Parameters.AddWithValue("Article", product.Article);
                    command.Parameters.AddWithValue("Description", product.Description);

                    command.ExecuteNonQuery();
                }
            }
        }
        public Product AddRecord(Product product)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(queryInsert, connection))
                {
                    //command.Parameters.AddWithValue("Id", myListProduct.Id);
                    command.Parameters.AddWithValue("Name", product.Name);
                    command.Parameters.AddWithValue("Article", product.Article);
                    command.Parameters.AddWithValue("Description", product.Description);

                    int connectId = (int)command.ExecuteScalar();
                    product.Id = connectId;

                    return product;
                }
            }
        }
示例#3
0
 private void btnCopy_Click(object sender, RoutedEventArgs e)
 {
     int numRecord = ListRecord.SelectedIndex + 1;
     if (numRecord == 0)
     {
         MessageBox.Show("Виберіть рядок для операції 'По зразку'");
     }
     else
     {
         SqlProductRepository idRecord = new SqlProductRepository();
         int _idRecord = idRecord.GetId(numRecord);
         Product product = new Product();
         product = idRecord.GetRowById(_idRecord);
         AddEditRecord addEditRecord = new AddEditRecord();
         addEditRecord.NumberOperation = 5;
         addEditRecord._Id = product.Id;
         addEditRecord.txtName.Text = product.Name;
         addEditRecord.txtArticle.Text = product.Article;
         addEditRecord.txtDescription.Text = product.Description;
         addEditRecord.Show();
     }
 }
示例#4
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     int numRecord = ListRecord.SelectedIndex + 1;
     if (numRecord == 0)
     {
         MessageBox.Show("Виберіть рядок для операції 'Видалення'");
     }
     else
     {
         SqlProductRepository idRecord = new SqlProductRepository();
         int _idRecord = idRecord.GetId(numRecord);
         Product product = new Product();
         product = idRecord.GetRowById(_idRecord);
         AddEditRecord addEditRecord = new AddEditRecord();
         string __name = product.Name;
         string __article = product.Article;
         string __description = product.Description;
         string message = string.Format("Ви дійсно бажаєте видалити запис? \nНазва: {0} \nАртикул: {1} \nОпис: {2}", __name, __article, __description);
         if (MessageBox.Show(message, "Видалення запису", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             idRecord.DeleteRecord(_idRecord);
         }
     }
 }
示例#5
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            SqlProductRepository sqlProductRepository = new SqlProductRepository();

            if (NumberOperation == 7)
            {
                _Name = txtName.Text;
                _Article = txtArticle.Text;
                _Description = txtDescription.Text;

                Product newProduct = new Product();
                newProduct.Name = _Name;
                newProduct.Article = _Article;
                newProduct.Description = _Description;

                sqlProductRepository.AddRecord(newProduct);
            }
            if (NumberOperation == 4)
            {
                Product editProduct = new Product();
                _Name = txtName.Text;
                _Article = txtArticle.Text;
                _Description = txtDescription.Text;
                editProduct.Id = _Id;
                editProduct.Name = _Name;
                editProduct.Article = _Article;
                editProduct.Description = _Description;

                sqlProductRepository.EditRecord(editProduct);
            }
            if (NumberOperation == 5)
            {
                Product copyProduct = new Product();
                _Name = txtName.Text;
                _Article = txtArticle.Text;
                _Description = txtDescription.Text;
                //copyProduct.Id = _Id;
                copyProduct.Name = _Name;
                copyProduct.Article = _Article;
                copyProduct.Description = _Description;

                sqlProductRepository.AddRecord(copyProduct);
            }

            Close();
        }
        public Product GetRowById(int id)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(queryGetAllId, connection))
                {
                    command.Parameters.AddWithValue("id", id);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        Product product = new Product();
                        if (reader.Read())
                        {
                            product = (new Product()
                            {
                                Id = (int)reader["id"],
                                Name = (string)reader["Name"],
                                Article = (object.Equals(reader["Article"], DBNull.Value) == false
                                                            ? (string)reader["Article"]
                                                            : default(string)),
                                Description = (object.Equals(reader["Description"], DBNull.Value) == false
                                                            ? (string)reader["Description"]
                                                            : default(string))
                            });
                            return product;
                        }
                        else
                        {
                            return null;
                        }

                    }
                }
            }
        }