示例#1
0
        public Response Update(ProductIncomeDetail productIncomeDetail)
        {
            Response response = new Response();

            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText =
                "UPDATE PRODUCTS_INCOME_DETAILS SET PRECO = @PRECO, QUANTIDADE = @QUANTIDADE WHERE ID = @ID";
            command.Parameters.AddWithValue("@PRECO", productIncomeDetail.Price);
            command.Parameters.AddWithValue("@QUANTIDADE", productIncomeDetail.Quantity);
            command.Parameters.AddWithValue("@ID", productIncomeDetail.IDProductIncome);

            command.Connection = connection;

            try {
                connection.Open();
                command.ExecuteNonQuery();
                response.Success = true;
                response.Message = "Atualizado com sucesso.";
            } catch (Exception ex) {
                response.Success        = false;
                response.Message        = "Erro no banco de dados, contate o administrador.";
                response.StackTrace     = ex.StackTrace;
                response.ExceptionError = ex.Message;
            } finally {
                connection.Close();
            }
            return(response);
        }
示例#2
0
        public SingleResponse <int> InsertProductIncomeDetail(ProductIncomeDetail productIncomeDetail)
        {
            SingleResponse <int> response = new SingleResponse <int>();

            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText =
                "INSERT INTO PRODUCTS_INCOME_DETAILS (IDPRODUCTS_INCOME, IDPRODUCTS, PRECO, QUANTIDADE) VALUES (@IDPRODUCTS_INCOME, @IDPRODUCTS, @PRECO, @QUANTIDADE) SELECT SCOPE_IDENTITY()";
            command.Parameters.AddWithValue("@IDPRODUCTS_INCOME", productIncomeDetail.IDProductIncome);
            command.Parameters.AddWithValue("@IDPRODUCTS", productIncomeDetail.IDProduct);
            command.Parameters.AddWithValue("@PRECO", productIncomeDetail.Price);
            command.Parameters.AddWithValue("@QUANTIDADE", productIncomeDetail.Quantity);

            command.Connection = connection;

            try {
                connection.Open();
                int idGerado = Convert.ToInt32(command.ExecuteScalar());
                response.Success = true;
                response.Message = "Cadastrado com sucesso.";
                response.Data    = idGerado;
            } catch (Exception ex) {
                response.Success        = false;
                response.Message        = "Erro no banco de dados, contate o administrador.";
                response.StackTrace     = ex.StackTrace;
                response.ExceptionError = ex.Message;
            } finally {
                connection.Close();
            }
            return(response);
        }
        private void ProductPriceAtt(ProductIncomeDetail item)
        {
            ProductBLL productBLL = new ProductBLL();
            Storage    storage    = new Storage();

            storage.ProductsID = item.IDProduct;

            double qtdProductsStorage = Convert.ToDouble(storageDAO.GetQuantityByIDProducts(item).Data);
            double productPrice       = Convert.ToDouble(productBLL.GetPriceByID(item.IDProduct));
            double qtdProductsEntry   = item.Quantity;
            double products           = ((qtdProductsStorage * productPrice) +
                                         (qtdProductsEntry * item.Price)) / qtdProductsStorage + qtdProductsEntry;

            productBLL.UpdatePrice(item.IDProduct, products);
        }
        private void btnInsertProductsIncomeDetail_Click(object sender, EventArgs e)
        {
            ProductIncomeDetail productIncomeDetail = new ProductIncomeDetail();

            productIncomeDetail.IDProduct = product.ID;
            productIncomeDetail.Price     = Convert.ToDouble(txtPrice.Text);
            productIncomeDetail.Quantity  = Convert.ToDouble(txtQuantity.Text);

            productIncome.Items.Add(productIncomeDetail);
            MessageBox.Show("Produto vinculado com sucesso!");

            if (productIncome.Items.Count == 0)
            {
                MessageBox.Show("É necessário vincular produtos.");
            }
        }
        public SingleResponse <Storage> GetQuantityByIDProducts(ProductIncomeDetail productIncomeDetail)
        {
            SingleResponse <Storage> response   = new SingleResponse <Storage>();
            SqlConnection            connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText = "SELECT QUANTIDADE FROM STORAGE WHERE IDPRODUCTS = @IDPRODUCTS";
            command.Parameters.AddWithValue("@IDPRODUCTS", productIncomeDetail.IDProduct);

            command.Connection = connection;

            try
            {
                connection.Open();

                SqlDataReader reader  = command.ExecuteReader();
                Storage       storage = new Storage();
                if (!reader.Read())
                {
                    response.Quantity = 0;
                    return(response);
                }
                while (reader.Read())
                {
                    response.Quantity = (double)reader["QUANTIDADE"];
                }
                response.Success = true;
                response.Message = "Dados selecionados com sucesso.";
                return(response);
            }
            catch (Exception ex)
            {
                response.Success        = false;
                response.Message        = "Erro no banco de dados contate o adm.";
                response.ExceptionError = ex.Message;
                response.StackTrace     = ex.StackTrace;
                return(response);
            }
            finally
            {
                connection.Close();
            }
        }
        public SingleResponse <Storage> AddProduct(ProductIncomeDetail item)
        {
            SingleResponse <Storage> singleResponse = new SingleResponse <Storage>();
            Storage storage = new Storage();

            storage.ProductsID = item.IDProduct;

            StorageDAO storageDAO = new StorageDAO();

            if (storageDAO.GetQuantityByIDProducts(item).Quantity == 0)
            {
                item.Quantity    = storageDAO.GetQuantityByIDProducts(item).Quantity;
                storage.Quantity = item.Quantity;
                Update(storage);
            }
            else if (storageDAO.GetQuantityByIDProducts(item).Quantity > 0)
            {
                ProductPriceAtt(item);
                item.Quantity   += storageDAO.GetQuantityByIDProducts(item).Quantity;
                storage.Quantity = item.Quantity;
                Update(storage);
            }
            return(singleResponse);
        }