//delete public string Fornecedor_Delete(DadosFornecedor DELETE) { using (var connection = GetConnection()) { connection.Open(); string rpta = ""; try { command.Connection = connection; command.CommandText = "DELETE * FROM tb_fornecedor WHERE id=@id"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id", DELETE.IDFornecedor); rpta = command.ExecuteNonQuery() == 1 ? "OK" : "erro ao deletar"; } catch (Exception ex) { rpta = ex.Message; } return(rpta); } }
//update public string Fornecedor_Update(DadosFornecedor UPDATE) { using (var connection = GetConnection()) { connection.Open(); string rpta = ""; try { command.Connection = connection; command.CommandText = "Forncedor_Update"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@id", UPDATE.IDFornecedor); command.Parameters.AddWithValue("@cnpj", UPDATE.Cnpj); command.Parameters.AddWithValue("@nome_fantasia", UPDATE.NomeFantasia); command.Parameters.AddWithValue("@razao_social", UPDATE.RazaoSocial); command.Parameters.AddWithValue("@ie", UPDATE.IE); command.Parameters.AddWithValue("@email", UPDATE.Email); command.Parameters.AddWithValue("@fone", UPDATE.Fone); command.Parameters.AddWithValue("@whatsapp", UPDATE.WhatsApp); // command.Parameters.AddWithValue("@pais", UPDATE.Pais); command.Parameters.AddWithValue("@cidade", UPDATE.Cidade); command.Parameters.AddWithValue("@uf", UPDATE.UF); command.Parameters.AddWithValue("@bairro", UPDATE.Bairro); command.Parameters.AddWithValue("@rua", UPDATE.Rua); command.Parameters.AddWithValue("@numero", UPDATE.Numero); command.Parameters.AddWithValue("@complemento", UPDATE.Complemento); command.Parameters.AddWithValue("@cep", UPDATE.CEP); command.Parameters.AddWithValue("@contato", UPDATE.Contato); // rpta = command.ExecuteNonQuery() == 2 ? "OK" : "Erro ao atualizar"; } catch (Exception ex) { rpta = ex.Message; } return(rpta); } }
//validate public bool Fornecedor_Valida(DadosFornecedor VALIDA) { using (var connection = GetConnection()) { connection.Open(); try { command.Connection = connection; command.CommandText = "SELECT * FROM tb_fornecedor WHERE cnpj=@cnpj"; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@cnpj", VALIDA.Cnpj); var result = command.ExecuteScalar(); if (result != null) { return(true); } } catch (Exception ex) { var exception = ex.Message; } return(false); } }