Professional Documents
Culture Documents
V. Archivos de Instalación
Lic. Alejandro César Valencia García
MODO DE EVALUACIÓN
• Examen Práctico (40%)
• Asistencia (10%)
1. Seleccionar de Visual C#
la opción Aplicación de
Windows
2. Asignarle un
nombre y una carpeta
de almacenamiento
Vista Diseño
Ventana Propiedades
Lic. Alejandro César Valencia García
DISEÑAR UNA INTERFAZ
• Arrastra los componentes que desees al formulario,
observa que cada uno tiene un nombre y
propiedades.
Los componentes más
usados son:
-Etiquetas (label)
-Cajas de texto (textbox)
-Botones (button)
label1
Label1 (a esta le
borramos el
contenido de la
textBox1 propiedad text)
Button1
Button2
label2.Text = "";
textBox1.Text = "";
textBox1.Focus();
Control Valor
string resumen;
textBox5.Text = resumen;
string resumen;
textBox5.Text = resumen;
string resumen;
textBox5.Text = resumen;
string resumen;
textBox5.Text = resumen;
if (textBox1.Text == "")
{
MessageBox.Show("Debe introducir un
texto","Atención",MessageBoxButtons.OK,MessageBoxIcon.Error);
textBox1.Focus();
}
public Form1()
{
InitializeComponent();
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.te
xtBox1_KeyPress);
}
Lic. Alejandro César Valencia García
VALIDAR NÚMEROS
• Se agrega esta función:
Los únicos caracteres que se permitirá introducir en el TextBox serán los números
del 0 al 9 (ASCII del 48 al 57) y se permitirá también usar el Backspace (ASCII 8)
para borrar.
class variables
{
public static string resumen;
}
if (int.Parse(textBox1.Text) == numero)
{
label3.Text = "FELICIDADES, Ganaste";
}
else
{
label3.Text = "Sigue intentando";
}
switch (tipo
{
case "Magna":
precio = 7.50;
textBox1.Text = Convert.ToString(precio);
break;
▫ ID (autonumérico)
▫ Nombre (texto, 100)
▫ Apellido_p (texto, 100)
▫ Apellido_m (texto, 100)
▫ Domicilio (texto, 255)
▫ Telefono (texto, 50)
▫ E_mail (texto, 50)
• Introducir 5 registros.
OleDbConnection CANAL;
OleDbDataAdapter ORDEN;
DataSet TABLA;
dataGridView1.DataSource = TABLA;
dataGridView1.DataMember = “clientes";
Importante. Se debe agregar en las directivas using (al comienzo del código):
using System.Data.OleDb
Lic. Alejandro César Valencia García
EJEMPLO
• Debe mostrar los registros de esta forma:
OleDbConnection CANAL;
OleDbCommand ORDEN;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox1.Focus();
Lic. Alejandro César Valencia García
TIPOS DE DATO OLEDBTYPE MÁS COMUNES
• Integer
• Char
• Date
• Double
• VarWChar
using System.Data.OleDb;
namespace clientes
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
DataRow dr = TABLA.Rows[fila];
// Asignar los datos de los textbox a la fila
asignarDatos(dr);
// Guardar físicamente los datos en la base
try
{
ORDEN.Update(TABLA);
TABLA.AcceptChanges();
MessageBox.Show("El Registro ha sido modificado");
}
catch (DBConcurrencyException ex)
{
MessageBox.Show("Error de concurrencia:\n" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Lic. Alejandro César Valencia García
EJEMPLO
• Agregar esta función después del último botón:
private void mostrarDatos(int f)
{
int uf = TABLA.Rows.Count - 1;
if (f < 0 || uf < 0) return;
DataRow dr = TABLA.Rows[f];
textBox1.Text = dr["ID"].ToString();
textBox2.Text = dr["nombre"].ToString();
textBox3.Text = dr["apellido_p"].ToString();
textBox4.Text = dr["apellido_m"].ToString();
textBox5.Text = dr["domicilio"].ToString();
textBox6.Text = dr["telefono"].ToString();
textBox7.Text = dr["e_mail"].ToString();
button1.Enabled = true;
}
Lic. Alejandro César Valencia García
EJEMPLO
• Agregar esta función después de la anterior:
OleDbCommand ORDEN2;
ORDEN2.Connection.Open();
ORDEN2.ExecuteNonQuery();
ORDEN2.Connection.Close();
MessageBox.Show("Registro Eliminado");