public Response Update(ProductOutputDetail productOutputDetail) { 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", productOutputDetail.Price); command.Parameters.AddWithValue("@QUANTIDADE", productOutputDetail.Quantity); command.Parameters.AddWithValue("@ID", productOutputDetail.IDProductOutput); 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); }
public SingleResponse <int> InsertProductOutputDetail(ProductOutputDetail productOutputDetail) { SingleResponse <int> response = new SingleResponse <int>(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConnectionHelper.GetConnectionString(); SqlCommand command = new SqlCommand(); command.CommandText = "INSERT INTO PRODUCTS_OUTPUT_DETAILS (IDPRODUCTS_OUTPUT, IDPRODUCTS, PRECO, QUANTIDADE) VALUES (@IDPRODUCTS_OUTPUT, @IDPRODUCTS, @PRECO, @QUANTIDADE) SELECT SCOPE_IDENTITY()"; command.Parameters.AddWithValue("@IDPRODUCTS_OUTPUT", productOutputDetail.IDProductOutput); command.Parameters.AddWithValue("@IDPRODUCTS", productOutputDetail.IDProduct); command.Parameters.AddWithValue("@PRECO", productOutputDetail.Price); command.Parameters.AddWithValue("@QUANTIDADE", productOutputDetail.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); }
public Response Insert(ProductOutputDetail productOutputDetail) { Response response = new Response(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConnectionHelper.GetConnectionString(); SqlCommand command = new SqlCommand(); command.CommandText = "INSERT INTO PRODUCTS_OUTPUT_DETAILS (PRECO, QUANTIDADE) VALUES(@PRECO, @QUANTIDADE)"; command.Parameters.AddWithValue("@PRECO", productOutputDetail.Price); command.Parameters.AddWithValue("@QUANTIDADE", productOutputDetail.Quantity); command.Connection = connection; try { connection.Open(); command.ExecuteNonQuery(); response.Success = true; response.Message = "Adicionado 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); }
public SingleResponse <Storage> GetQuantityByIDProductsOutput(ProductOutputDetail productOutputDetail) { 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", productOutputDetail.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> DeleteProduct(ProductOutputDetail item) { SingleResponse <Storage> singleResponse = new SingleResponse <Storage>(); Storage storage = new Storage(); storage.ProductsID = item.IDProduct; StorageDAO storageDAO = new StorageDAO(); if (storageDAO.GetQuantityByIDProductsOutput(item).Quantity == 0) { singleResponse.Message = "Estoque zerado"; singleResponse.Success = false; } else if (storageDAO.GetQuantityByIDProductsOutput(item).Quantity > 0) { item.Quantity -= storageDAO.GetQuantityByIDProductsOutput(item).Quantity; storage.Quantity = item.Quantity; singleResponse.Success = true; Update(storage); } return(singleResponse); }