public DataView ObterListaCliente() { //instancia da classe conexao para uso dos metodos conectar e desconectar clsConexao conexao = new clsConexao(); try { conexao.Conectar(); //instancia da classe SqlCommand passando como parametros a storedProcedure SqlCommand command = new SqlCommand("sp_ListarClientesDisponiveis", conexao.conexao); command.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(command); DataTable dt = new DataTable(); da.Fill(dt); DataView dv = new DataView(dt); return(dv); } catch (Exception ex) { msg = ex.Message.ToString(); return(null); } finally { conexao.Desconectar(); } }
public bool RealizarLogin() { //instancia da classe conexao para uso dos metodos conectar e desconectar clsConexao conexao = new clsConexao(); try { conexao.Conectar(); //instancia da classe SqlCommand passando como parametros a storedProcedure SqlCommand command = new SqlCommand("sp_RealizarLogin", conexao.conexao); command.CommandType = CommandType.StoredProcedure; //passando parametros para a SP command.Parameters.AddWithValue("@pDs_login", DS_Login).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pDs_senha", DS_Senha).Direction = ParameterDirection.Input; SqlDataReader dr = command.ExecuteReader(CommandBehavior.SingleRow); if (dr.Read()) { ID_Usuario = Convert.ToInt32(dr["id_usuario"].ToString()); msg = ""; return(true); } else { msg = "Usuário/Senha invalidos!!!"; return(false); } } catch (Exception ex) { msg = ex.Message.ToString(); return(false); } finally { conexao.Desconectar(); } }
public void ObterCliente() { clsConexao conexao = new clsConexao(); try { conexao.Conectar(); //instancia da classe SqlCommand passando como parametros a storedProcedure SqlCommand command = new SqlCommand("sp_ListarCliente", conexao.conexao); command.CommandType = CommandType.StoredProcedure; //passando parametros para a SP command.Parameters.AddWithValue("@pId_cliente", ID_Cliente).Direction = ParameterDirection.Input; SqlDataReader dr = command.ExecuteReader(CommandBehavior.SingleRow); if (dr.Read()) { ID_Cliente = Convert.ToInt32(dr["id_usuario"].ToString()); NM_Cliente = dr["nm_cliente"].ToString(); NR_Cpf = dr["nr_cpf"].ToString(); DS_Rua = dr["ds_rua"].ToString(); DS_Bairro = dr["ds_bairro"].ToString(); DS_Cidade = dr["ds_cidade"].ToString(); DS_Estado = dr["ds_estado"].ToString(); NR_Cep = dr["nr_cep"].ToString(); ID_Status = Convert.ToInt32(dr["id_status"].ToString()); msg = ""; } } catch (Exception ex) { msg = ex.Message.ToString();; } finally { conexao.Desconectar(); } }
public bool Inserir() { clsConexao conexao = new clsConexao(); try { conexao.Conectar(); SqlCommand command = new SqlCommand("sp_InserirCliente", conexao.conexao); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@pNm_cliente", NM_Cliente).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pNr_cpf", NR_Cpf).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pDs_rua", DS_Rua).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pDs_bairro", DS_Bairro).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pDs_cidade", DS_Cidade).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pDs_estado", DS_Estado).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pNr_cep", NR_Cep).Direction = ParameterDirection.Input; command.Parameters.AddWithValue("@pId_status", ID_Status).Direction = ParameterDirection.Input; command.ExecuteReader(); msg = "Cliente cadastrado com sucesso!"; return(true); } catch (Exception e) { msg = "Erro ao cadastrar Cliente!" + e.Message; return(false); } finally { conexao.Desconectar(); } }