예제 #1
0
        public string EliminarMascota(DMascota mascota)
        {
            string        rpta = "";
            string        sql  = "sp_eliminar_mascota";
            SqlConnection cn   = new SqlConnection();

            try
            {
                cn.ConnectionString = Conexion.conectar;
                cn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddWithValue("@idmascota", mascota.IdMascota);
                    cmd.CommandType = CommandType.StoredProcedure;
                    rpta            = cmd.ExecuteNonQuery() == 1 ? "Ok" : "Error al Eliminar";
                }
            }
            catch (Exception ex)
            {
                rpta = ex.Message.ToString();
                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(rpta);
        }
예제 #2
0
        public DataTable BuscarMascotaId(DMascota mascota)
        {
            string        sql   = "sp_buscar_idmascota";
            DataTable     tabla = new DataTable();
            SqlConnection cn    = new SqlConnection();

            try
            {
                cn.ConnectionString = Conexion.conectar;
                cn.Open();
                using (var da = new SqlDataAdapter(sql, cn))
                {
                    da.SelectCommand.Parameters.AddWithValue("@idmascota", mascota.IdMascota);
                    da.SelectCommand.CommandType = CommandType.StoredProcedure;
                    da.Fill(tabla);
                }
            }
            catch (Exception ex)
            {
                tabla = null;
                ex.Message.ToString();
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(tabla);
        }
예제 #3
0
        public string ActualzarMascota(DMascota mascota)
        {
            string        rpta = "";
            string        sql  = "sp_modificar_mascota";
            SqlConnection cn   = new SqlConnection();

            try
            {
                cn.ConnectionString = Conexion.conectar;
                cn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, cn))
                {
                    cmd.Parameters.AddWithValue("@idmascota", mascota.IdMascota);
                    cmd.Parameters.AddWithValue("@nombre", mascota.Nombre);
                    cmd.Parameters.AddWithValue("@edad", mascota.Edad);
                    cmd.Parameters.AddWithValue("@sexo", mascota.Sexo);
                    cmd.Parameters.AddWithValue("@peso", mascota.Peso);
                    cmd.Parameters.AddWithValue("@descripcion", mascota.Descripcion);
                    cmd.Parameters.AddWithValue("@idraza", mascota.IdRaza);
                    cmd.Parameters.AddWithValue("@idcliente", mascota.IdCliente);
                    cmd.Parameters.AddWithValue("@foto", mascota.Foto);
                    cmd.CommandType = CommandType.StoredProcedure;
                    rpta            = cmd.ExecuteNonQuery() == 1 ? "Ok" : "Error al actualizar datos de la mascota";
                }
            }
            catch (Exception ex)
            {
                rpta = ex.Message.ToString();
                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(rpta);
        }