lunes, 17 de marzo de 2014

DEBERES DE C#



CONVERSIÓN DE DATOS

Dado que a C# se le asignan tipos estáticos en tiempo de compilación, después de declarar una variable, no se puede volver a declarar ni tampoco utilizar para almacenar valores de otro tipo, a menos que dicho tipo pueda convertirse en el tipo de la variable. Por ejemplo, no existe conversión de un entero a una cadena arbitraria cualquiera.





TIPOS:
Conversiones implícitas: no se requiere una sintaxis especial porque la conversión se realiza con seguridad de tipos y no se perderán datos. Entre los ejemplos se incluyen las conversiones de tipos enteros de menor a mayor y las conversiones de clases derivadas en clases base.

int num = 2147483647;


Conversiones explícitas (conversiones de tipos): las conversiones explícitas requieren un operador de conversión. La conversión se requiere cuando es posible que se pierda información en el proceso o cuando esta puede no realizarse correctamente por otras razones. Entre los ejemplos habituales se incluye la conversión en un tipo con menor precisión o un intervalo menor, y la conversión de una instancia de clase base en una clase derivada. class Test
{
static void Main()
{
double x = 1234.7;
int a;
// Cast double to int.
a = (int)x;
System.Console.WriteLine(a);
}
}

Conversiones definidas por el usuario: las conversiones definidas por el usuario se realizan a través de métodos especiales que puede definir para habilitar las conversiones explícitas e implícitas entre tipos personalizados que no tienen una relación de clase base-clase derivada.
Conversiones con clases auxiliares: para realizar conversiones entre tipos no compatibles, como los enteros y los objetos System.DateTime, o bien cadenas hexadecimales y matrices de bytes, puede utilizar la claseSystem.BitConverter, la clase System.Convert y los métodos Parse de los tipos numéricos integrados, comoInt32.Parse.






IF

Es la instrucción condicional mas usada en los diversos lenguajes de programación, su formato es:



if (condición)

{ grupo cierto de instrucciones;}

else

{ grupo falso de instrucciones; };



Operadores lógicos AND OR NOT

Los operadores lógicos comparan expresiones Boolean y devuelven un resultado Boolean. Los operadores And,Or, AndAlso, OrElse y Xor aceptan dos operandos, mientras que el operador Not sólo acepta un operando.



TIPOS DE DATOS




C# Tipo
.Net Framework (System) type
Signed?
Bytes en Ram
Rango
sbyte
System.Sbyte
Yes
1
-128 a 127
short
System.Int16
Yes
2
-32768 a 32767
int
System.Int32
Yes
4
-2147483648 a 2147483647
long
System.Int64
Yes
8
-9223372036854775808 a 9223372036854775807
byte
System.Byte
No
1
0 a 255
ushort
System.Uint16
No
2
0 a 65535
uint
System.UInt32
No
4
0 a 4294967295
ulong
System.Uint64
No
8
0 a 18446744073709551615
float
System.Single
Yes
4
Aprox. ±1.5 x 10-45 a ±3.4 x 1038 con 7 decimales
double
System.Double
Yes
8
Aprox. ±5.0 x 10-324 a ±1.7 x 10308 con 15 o 16 decimales
decimal
System.Decimal
Yes
12
Aprox. ±1.0 x 10-28 a ±7.9 x 1028 con 28 o 29 decimales
char
System.Char
N/A
2
Cualquier caracter Unicode
bool
System.Boolean
N/A
1 / 2
true o false

jueves, 30 de enero de 2014

FORMULARIO DE ULTIMOS REGISTROS

MOSTRAR DATOS

<?PHP
function correo($valor)
{
if (preg_match('{^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$}',$valor))
return true;
else
return false;
}

if(isset($_POST['regis']))
{
$nom=$_POST['nom'];
$correo=$_POST['ema'];
$alias=$_POST['ali'];
$clave=$_POST['cla'];
$valcla=$_POST['confc'];
if(strlen('$clave')>=8 && $clave==$valcla  )
{
if (correo($correo))
{
echo "bien";
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
}
ECHO "<h1>REGISTRAR</H1>";
echo "<br>";
mysql_select_db("BDDAGENDA",$conexion);
if(mysql_query("INSERT INTO USUARIO (Nombre,Alias,Password,Email) VALUES ('$nom','$alias','$clave','$correo')",$conexion))
{echo "<br> Insertado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}
}

else
{
echo "CORREO NO VALIDO";
echo "<br>";
echo "<a href='usuario.php?registrar'>volver</a>";
}
}
if($clave!=$valcla)
{echo "LAS CLAVES NO COINCIDEN";
echo "<br>";
echo "<a href='usuario.php?registrar'>volver</a>";
}
}


?>

REGISTRAR USUARIO

FORMULARIO DE INGRESO

<?php
session_start();
?>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Openalfa - Formulario de validación de usuario</title>
</head>
<body>
<form action="datos.php" method="POST">
  <fieldset>
<p>
    Ingrese nombre de usuario:
    <input id="usuario"type="text" name="usuario" value="<?php if (isset($_SESSION["usuario"])){echo $_SESSION["usuario"];}?>"/><br>
</p>
<p>
  Ingrese clave:
    <input id="clave" type="password" name="clave" value="<?php if (isset($_SESSION["clave"])){echo $_SESSION["clave"];}?>"/><br>
</p>
<p>
  Ingrese correo:
    <input id="email" type="text" name="correo" value="<?php if (isset($_SESSION["email"])){echo $_SESSION["email"];}?>"/><br>
</p>
<p>
 Recordar <input type="checkbox" name="opcion">  
 <input type="submit" name='ingresar' value="ingresar">
 <input type="submit" name="registrar" value="registrar">

  </fieldset>
</form>
</body>

</html>

FORMULARIO DE REGISTRO

<html>
<head>
<title>Registrado</title>
<meta http-equiv="Content-Type" Content="text/html; charset=UTF-8">
</head>
<body>
<?php
if (isset($_POST['ingresaar'])){
session_start();
function correo($valor)
{
if (preg_match('{^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$}',$valor))
return true;
else
return false;
}
if($_POST["usuario"]=="adrian" && $_POST["clave"]=="123"){
$correo=$_POST['correo'];
/*if (correo($correo)){
echo 'El correo es valido';
if (isset($_POST['opcion'])){
$_SESSION["usuario"]='adrian';
$_SESSION['clave']=$_POST['clave'];
$_SESSION['email']=$_POST['correo'];
}else{
unset($_SESSION["usuario"]);
unset($_SESSION['clave']);
unset($_SESSION['email']);
}
*/
echo "VALIDO";
echo "<br>";
echo "usuario: ".$_SESSION["usuario"]=$_POST["usuario"];
echo "<br>";
echo "clave: ".$_SESSION['clave']=$_POST['clave'];
echo "<br>";
echo "email: ".$_SESSION['email']=$_POST['correo'];
echo "<br>";

echo "<br>";}
//}
else
echo 'no es valido';
echo "<a href='MAsTER.php'>INICIO</a>";
}


                   /*registsrar*/

if(isset($_POST['registrar']))
{
ECHO "<CENTER>";
echo "REGISTRAR";
ECHO "<BR>";
echo "<form action='REGISTRADO.php' method='POST'>";
ECHO "<BR>";
echo "NOMBRE:<input type='text' name='nom'>";
ECHO "<BR>";
echo "ALIAS:<input type='text' name='ali'>";
ECHO "<BR>";
echo "CLAVE:<input type='text' name='cla'>";
ECHO "<BR>";
echo "CONFIRMAR CLAVE:<input type='text' name='confc'>";
ECHO "<BR>";
echo "EMAIL:<input type='text' name='ema'>";
ECHO "<BR>";
echo "<input type='submit' name='regis' value='REGISTRAR'>";
echo "</form>";
}

?>
</body>
</html>
-----------------------------------------------------------------------------
<?PHP
function correo($valor)
{
if (preg_match('{^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$}',$valor))
return true;
else
return false;
}

if(isset($_POST['regis']))
{
$nom=$_POST['nom'];
$correo=$_POST['ema'];
$alias=$_POST['ali'];
$clave=$_POST['cla'];
$valcla=$_POST['confc'];
if(strlen('$clave')>=8 && $clave==$valcla  )
{
if (correo($correo))
{
echo "bien";
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
}
ECHO "<h1>REGISTRAR</H1>";
echo "<br>";
mysql_select_db("BDDAGENDA",$conexion);
if(mysql_query("INSERT INTO USUARIO (Nombre,Alias,Password,Email) VALUES ('$nom','$alias','$clave','$correo')",$conexion))
{echo "<br> Insertado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}
}

else
{
echo "CORREO NO VALIDO";
echo "<br>";
echo "<a href='usuario.php?registrar'>volver</a>";
}
}
if($clave!=$valcla)
{echo "LAS CLAVES NO COINCIDEN";
echo "<br>";
echo "<a href='usuario.php?registrar'>volver</a>";
}
}

?>


miércoles, 29 de enero de 2014

EDITAR Y BORRAR DATOS MYSQL-PHP

EDITAR DATOS
<?PHP
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
echo "<br>";
}
mysql_select_db("BDDAGENDA",$conexion);
echo "<center>";
$sql=mysql_query("select * from agenda");

echo "<table bgcolor='yellow' BORDER=0 cellspacing=0 text='orange'>";
echo "<tr><td WIDTH=7%>ID</td><td WIDTH=25%>Nombre</td><td WIDTH=25%>Apellido</td><td WIDTH=25%>Direccion</td><td WIDTH=20%>Telefono </td><td>Accion</td></tr>";
echo "</table>";
echo "<form ACTION='editado.php' method='POST'>";
$con=0;
while($fila=mysql_fetch_array($sql))
{

/*$var=mysql_num_rows($sql);*/

$con=$con+1;
echo "<table BORDER=1 cellspacing=0 bgcolor='red' text='orange'>";
echo "<tr><td WIDTH=5%>$fila[IDAGENDA]</td>";
echo "<td WIDTH=26%>".$fila['Nombre']."</td>";
echo "<td WIDTH=25%>".$fila['Apellido']."</td>";
echo "<td WIDTH=25%>".$fila['Direccion']."</td>";
echo "<td WIDTH=19%>".$fila['Telefono']."</td>";
ECHO "<TD><A HREF='EDITADO.PHP?cod=$fila[IDAGENDA]'>EDITAR</A></TD>";
echo "</tr>";

echo "</table>";
}

?>
-------------------------------------------------------------------------------------------------

<?PHP
$cod=$_GET['cod'];
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
}
ECHO "<h1>EDITAR</H1>";
echo "<FORM ACTION='' method='POST'>";
mysql_select_db("BDDAGENDA",$conexion);
$sql=mysql_query("select * from agenda
WHERE IDAGENDA=$cod");
$fila=mysql_fetch_array($sql);
echo "<input type='text' name='cod' value='$fila[IDAGENDA]'>";
ECHO "</BR>";
echo "<input type='text' name='nom' value='$fila[Nombre]'>";
ECHO "</BR>";
echo "<input type='text' name='ape' value='$fila[Apellido]'>";
ECHO "</BR>";
echo "<input type='text' name='dir' value='$fila[Direccion]'>";
ECHO "</BR>";
echo "<input type='SUBMIT' NAME='env' value='GUARDAR'>";
echo "</form>";
mysql_select_db("BDDAGENDA",$conexion);

$cod=$_POST['cod'];
$nom=$_POST['nom'];
$ape=$_POST['ape'];
$dir=$_POST['dir'];
if(mysql_query("UPDATE agenda set Nombre='$nom',Apellido='$ape',Direccion='$dir'
where IDAGENDA=$cod",$conexion))
{echo "<br> Insertado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}
}
?>


ELIMINAR DATOS
<?PHP
echo "<br>";
ECHO "<h1>ELIMINAR</H1>";
ECHO "<BR>";

$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
echo "<br>";
}
mysql_select_db("BDDAGENDA",$conexion);
echo "<center>";
$sql=mysql_query("select * from agenda");

echo "<table bgcolor='yellow' BORDER=0 cellspacing=0 text='orange'>";
echo "<tr><td WIDTH=7%>ID</td><td WIDTH=25%>Nombre</td><td WIDTH=25%>Apellido</td><td WIDTH=25%>Direccion</td><td WIDTH=20%>Telefono </td><td>Accion</td></tr>";
echo "</table>";
while($fila=mysql_fetch_array($sql))
{
echo "<table BORDER=1 cellspacing=0 bgcolor='red' text='orange'>";
echo "<tr><td WIDTH=5%>$fila[IDAGENDA]</td>";
echo "<td WIDTH=26%>".$fila['Nombre']."</td>";
echo "<td WIDTH=25%>".$fila['Apellido']."</td>";
echo "<td WIDTH=25%>".$fila['Direccion']."</td>";
echo "<td WIDTH=19%>".$fila['Telefono']."</td>";
ECHO "<TD><A HREF='ELIMINADO.PHP?cod=$fila[IDAGENDA]'>ELIMINAR</A></TD>";
echo "</tr>";

echo "</table>";
}


?>
--------------------------------------------------------------------------------------------







<?PHP
$cod=$_GET['cod'];
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
}
ECHO "<h1>ELIMINAR</H1>";
mysql_select_db("BDDAGENDA",$conexion);
if(mysql_query("delete from agenda where IDAGENDA=$cod",$conexion))
{echo "<br> Eliminado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}

?>


miércoles, 22 de enero de 2014

MANIPULACIÓN DE DATOS MYSQL

CONSULTAS-FILTRAR DATOS


<?PHP
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
echo "<br>";
}
mysql_select_db("BDDAGENDA",$conexion);
/*
if(mysql_query("insert into agenda values(5,'Marian','Cabrera',20,'0992341232','Cañar','Cañar','Femenino')",$conexion))
{echo "<br> Insertado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}
*/
/*
if(mysql_query("update agenda set Telefono='2450144' where Nombre='Diana'",$conexion))
{echo "<br> EXELENTE";
}
else{
echo "<br> se produjo un esrror".mysql_error();
}
*/
/*
if(mysql_query("ALTER TABLE agenda add column Sexo enum('Masulino','Femenino')",$conexion))
{echo "<br> EXELENTE";
}
else{
echo "<br> se produjo un esrror".mysql_error();
}
*/
echo "<center>";
$sql=mysql_query("select * from agenda");
echo "<table bgcolor='yellow' BORDER=0 cellspacing=0 text='orange'>";
echo "<tr><td WIDTH=7%>ID</td><td WIDTH=25%>Nombre</td><td WIDTH=25%>Apellido</td><td WIDTH=25%>Direccion</td><td WIDTH=20%>Telefono </td></tr>";
echo "</table>";
while($fila=mysql_fetch_array($sql))
{
echo "<table BORDER=1 cellspacing=0 bgcolor='red' text='orange'>";
echo "<tr><td WIDTH=5%>".$fila['IDAGENDA']."</td>";
echo "<td WIDTH=26%>".$fila['Nombre']."</td>";
echo "<td WIDTH=25%>".$fila['Apellido']."</td>";
echo "<td WIDTH=25%>".$fila['Direccion']."</td>";
echo "<td WIDTH=19%>".$fila['Telefono']."</td></tr>";
echo "</table>";
}
?>
LISTAR DATOS

<?php
ECHO "<CENTER>";
echo "<FORM ACTION='consulta.php' method='POST'>";
echo "<input type='submit' value='LISTAR TODO' name='LISTAR'>";
echo "</form>";
ECHO "<H1>FILTRAR POR:";
ECHO "<BR>";
echo "<FORM ACTION='filtrado.php' method='POST'>";
echo "<input type='SUBMIT' value='NOMBRE: ' name='NOMBRE'>";
echo "<input type='TEXT'  name='NOM'>";
ECHO "<BR>";
echo "<input type='submit' value='APELLIDO' name='APELLIDO'>";
echo "<input type='TEXT'  name='APE'>";
ECHO "<BR>";
echo "<input type='submit' value='DIRECCION' name='DIRECCION'>";
echo "<input type='TEXT'  name='DIR'>";
ECHO "<BR>";
echo "<input type='submit' value='TELEFONO' name='TELEFONO'>";
echo "<input type='TEXT'  name='TEL'>";
ECHO "<BR>";
ECHO "<BR>";
echo "<input type='submit' value='FILTRAR' name='FILTRAR'>";
ECHO "<BR>";
echo "<input type='submit' value='ORDENAR' name='ORD'>";
echo "</form>";


INSERTAR DATOS


<?php
ECHO "<CENTER>";
echo "<FORM ACTION='INGRESO.php' method='POST'>";
echo "NOMBRE:<input type='TEXT'  name='NOMB'>";
ECHO "<BR>";
echo "APELLIDO: <input type='TEXT'  name='APE'>";
ECHO "<BR>";
echo "DIRECCION:<input type='TEXT'  name='DIR'>";
ECHO "<BR>";
echo "TELEFONO:<input type='TEXT'  name='TEL'>";
ECHO "<BR>";
ECHO "CIUDAD: <SELECT NAME='CIUDAD'>";
echo "<option>Azogues";
echo "<option>Biblian";
echo "<option>Cañar";
ECHO "</SELECT>";
ECHO "<BR>";
ECHO "<INPUT TYPE='RADIO'NAME='S' VALUE='M'>M";
ECHO "<INPUT TYPE='RADIO'NAME='S' VALUE='F'>F";
ECHO "<BR>";
ECHO "<BR>";
ECHO "<BR>";
echo "<input type='submit' value='REGISTRAR' name='REGISTRAR'>";
echo "</form>";



if(isset($_POST['REGISTRAR']))
{
if(isset($_POST['S'])!='M' OR (isset($_POST['S'])!='F'))
{ECHO "<BR>";
ECHO "ELIJA SEXO";
ECHO "<BR>";}
if(isset($_POST['S'])=='M')
{$sex='Masulino';
}
if(isset($_POST['S'])=='F')
{$sex='Femenino';
}
$conexion=mysql_connect("localhost","CONEXIONBDD","ADMIN");
if(!$conexion){
die('no se establecio la conexion'.mysql_error());
}
else
{
echo("Conexion Satisfactoria");
}
mysql_select_db("BDDAGENDA",$conexion);
$nom=$_POST['NOMB'];
$ape=$_POST['APE'];
$dir=$_POST['DIR'];
$tel=$_POST['TEL'];
$ciu=$_POST['CIUDAD'];
if($nom=='' OR $ape=='' or $dir=='' or $tel==''  )
{ECHO "<BR>";
ECHO "FALTAN DATOS";
}
ELSE
{

if(mysql_query("insert into agenda values(8,'$nom','$ape',23,$tel,'$dir','$ciu','$sex')",$conexion))
{echo "<br> Insertado correctamente";}
else{
echo "<br> se produjo un esrror".mysql_error();
}
}
}






miércoles, 18 de diciembre de 2013

COMANDOS MYSQL


INSERT
inserta nuevos registros en una tabla existente NSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]


UPDATE

El comando UPDATE actualiza columnas en registros de tabla existentes con nuevos valores. La cláusula SET indica qué columna modificar y los valores que puede recibir.
UPDATE [LOW_PRIORITY] [IGNORE] table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]


DELETE
DELETE borra los registros de una tabla que satisfacen la condición dada por el predicado, y retorna el número de registros borrados.
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [WHERE where_definition] [ORDER BY ...] [LIMIT row_count]


SELECT

se usa para recibir registros seleccionados desde una o más tablas. MySQL 5.0 incluye soporte para comandos UNION y subconsultas.
SELECT college, region, seed FROM tournament ORDER BY region, seed;
 
 

lunes, 16 de diciembre de 2013

MYSQL


mysql_select_db

Seleccionar una base de datos MySQL

$enlace = mysql_connect('localhost', 'usuario', 'contraseña');



mysql_query

Enviar una consulta MySQL

$resultado = mysql_query('SELECT * WHERE 1=1');



mysql_close

Cierra una conexión de MySQL

mysql_close($enlace);



mysql_connect
Abre una conexión al servidor MySQL

resource mysql_connect ([ string $server = ini_get("mysql.default_host") [,string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int$client_flags = 0 ]]]]] )



die
Devuelve el texto del mensaje de error de la operación MySQL anterior

$enlace = mysql_connect("localhost", "usuario", "contraseña");

mysql_select_db("bd_inexistente", $enlace);
echo mysql_errno($enlace) . ": " . mysql_error($enlace). "no conexion";