Пример #1
0
 public Cliente devuelveClienteporDni(string dni)
 {
     Cliente cliente = new Cliente();
     string storedprocedure = "datosclientepordni";
     using (DbConnection con = dpf.CreateConnection())
     {
         con.ConnectionString = constr;
         using (DbCommand cmd = dpf.CreateCommand())
         {
             cmd.Connection = con;
             cmd.CommandText = storedprocedure;
             cmd.CommandType = CommandType.StoredProcedure;
             DbParameter param = cmd.CreateParameter();
             param.DbType = DbType.String;
             param.ParameterName = "dni";
             param.Value = dni;
             cmd.Parameters.Add(param);
             con.Open();
             using (DbDataReader dr = cmd.ExecuteReader())
             {
                 if (dr.Read())
                 {
                     cliente = new Cliente(
                         (string)dr["dni"],
                         (string)dr["nombres"],
                         (string)dr["apellidos"],
                         (string)dr["direccion"],
                         (string)dr["celular"]
                         );
                 }
             }
         }
     }
     return cliente;
 }
Пример #2
0
        public Cliente devuelveCliente(string correo, string contrasena)
        {
            Cliente cliente = new Cliente();
            string storedprocedure = "iniciasesion";
            using (DbConnection con= dpf.CreateConnection())
            {
                con.ConnectionString = constr;
                using (DbCommand cmd = dpf.CreateCommand())
                {
                    cmd.Connection = con;
                    cmd.CommandText = storedprocedure;
                    cmd.CommandType = CommandType.StoredProcedure;
                    DbParameter paramCorreo = cmd.CreateParameter();
                    paramCorreo.DbType = DbType.String;
                    paramCorreo.ParameterName = "correo";
                    paramCorreo.Value = correo;

                    DbParameter paramContrasena = cmd.CreateParameter();
                    paramContrasena.DbType = DbType.String;
                    paramContrasena.ParameterName = "contrasena";
                    paramContrasena.Value = contrasena;

                    cmd.Parameters.Add(paramCorreo);
                    cmd.Parameters.Add(paramContrasena);

                    con.Open();

                    using (DbDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            cliente = new Cliente( (string)dr["dni"], (string)dr["nombres"] );
                        }
                    }
                }
            }
            return cliente;
        }