namespace REPASO_EXAMEN_1_CON_CLAVE
{
public partial class PRINCIPAL : Form
{
List<Producto> prod = new List<Producto>();
int id = 0;
public PRINCIPAL()
{
InitializeComponent();
}
private void btnGuardar_Click(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(txtNombre.Text)) | (string.IsNullOrEmpty(txtFechaInicio.Text)) | (string.IsNullOrEmpty(txtFechaFin.Text)))
{
MessageBox.Show("ingrese campos");
}
else
{
DateTime fecha = DateTime.Parse(txtFechaInicio.Text);
DateTime fecha2 = DateTime.Parse(txtFechaFin.Text);
int comparacion = DateTime.Compare(fecha, fecha2);
if (comparacion < 0)
{
id++;
lblId.Text = Convert.ToString(id);
Producto produ = new Producto(id, txtNombre.Text, Convert.ToDateTime(txtFechaInicio.Text), Convert.ToDateTime(txtFechaFin.Text));
prod.Add(produ);
foreach (var item in prod)
{
lstLista.Items.Add(item);
MessageBox.Show("Datos guardados exitosamente");
}
}
else
{
MessageBox.Show("Fechas ingresadas incorrectamente");
}
}
}
private void btnNuevo_Click(object sender, EventArgs e)
{
txtNombre.Clear();
txtFechaInicio.Clear();
txtFechaFin.Clear();
}
private void lstLista_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (Producto item in lstLista.SelectedItems)
{
lblId.Text = Convert.ToString(item.Id);
txtNombre.Text = item.Nombre;
txtFechaInicio.Text = Convert.ToString(item.FechaInicio);
txtFechaFin.Text = Convert.ToString(item.FechaFin);
}
}
}
}
---------------------
namespace REPASO_EXAMEN_1_CON_CLAVE
{
public partial class Form1 : Form
{
List<Usuario> listaUsuarios = new List<Usuario>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Usuario usu = new Usuario("mayra", "may", "may");
Usuario usu1 = new Usuario("andres", "andy", "andy");
listaUsuarios.Add(usu);
listaUsuarios.Add(usu1);
}
private void btnIngresar_Click(object sender, EventArgs e)
{
Usuario usuarios = new Usuario(txtNombre.Text, txtLogin.Text, txtPassword.Text);
listaUsuarios.Add(usuarios);
foreach (var item in listaUsuarios)
{
if (item.Login == txtLogin.Text && item.Password == txtPassword.Text)
{
MessageBox.Show("BIENVENIDO " + txtNombre.Text);
PRINCIPAL prin = new PRINCIPAL();
prin.ShowDialog();
break;
}
else
{
if (item.Login != txtLogin.Text && item.Password != txtPassword.Text)
{
MessageBox.Show("NO REGISTRADO");
break;
}
}
}
}
}
}
C# programando facil y rapido
domingo, 25 de octubre de 2015
jueves, 23 de julio de 2015
Como hacer una contraseña
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace Chat_20_07_2015
{
class MiBD: DataContext
{
public Table<Usuario> usuarios;
public Table<Conversacion> conversaciones;
public Table<Mensaje> mensajes;
public MiBD() : base(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mary\Downloads\Chat_20_07_2015\Chat_20_07_2015\PRACTICAPHV.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") { }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace Chat_20_07_2015
{
class MiBD: DataContext
{
public Table<Usuario> usuarios;
public Table<Conversacion> conversaciones;
public Table<Mensaje> mensajes;
public MiBD() : base(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mary\Downloads\Chat_20_07_2015\Chat_20_07_2015\PRACTICAPHV.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") { }
}
}
----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace Chat_20_07_2015
{
[Table(Name="conversaciones")]
class Conversacion
{
[Column(IsPrimaryKey=true, AutoSync=AutoSync.OnInsert,IsDbGenerated=true)]
public int id;
[Column]
public string tema;
public override string ToString()
{
return this.id + " " + this.tema;
}
}
}
-------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace Chat_20_07_2015
{
[Table(Name="mensajes")]
class Mensaje
{
[Column(IsPrimaryKey=true, AutoSync=AutoSync.OnInsert, IsDbGenerated=true)]
public int id;
[Column]
public string texto;
[Column]
public string id_usuarios;
[Column]
public string id_conversaciones;
public override string ToString()
{
return this.id_usuarios+" :"+this.texto;
}
}
}
--------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace Chat_20_07_2015
{
[Table(Name="usuarios")]
class Usuario
{
[Column(IsPrimaryKey=true)]
public int id;
[Column]
public string login;
[Column]
public string password;
public override string ToString()
{
return this.id + " " + this.login + " " + this.password;
}
}
}
------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Chat_20_07_2015
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int aux;
String id_user;
MiBD mibase = new MiBD();
private void btnIngresar_Click(object sender, EventArgs e)
{
validarUsuario();
if (aux == 1)
{
Temas_Conversaciones temasConver = new Temas_Conversaciones(id_user);
temasConver.Show();
}
else
{
MessageBox.Show("Acceso Denegado");
}
}
private void validarUsuario()
{
var UsuarioBuscar = from usuario in mibase.usuarios
where usuario.id > 0//usuario.login == "dchango" && usuario.password == "dchango"
select usuario;
foreach (var iterUser in UsuarioBuscar)
{
if (txtLogin.Text == iterUser.login && txtPassword.Text == iterUser.password)
{
id_user = iterUser.login;
aux = 1;
break;
}
else
{
aux = 0;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
--------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Chat_20_07_2015
{
public partial class Temas_Conversaciones : Form
{
String id_user;
public String Id_user
{
get { return id_user; }
set { id_user = value; }
}
public Temas_Conversaciones(String ini_user)
{
id_user = ini_user;
InitializeComponent();
}
public Temas_Conversaciones()
{
InitializeComponent();
}
MiBD mibase = new MiBD();
private void btnCrear_Click(object sender, EventArgs e)
{
Conversacion conver = new Conversacion();
conver.tema = txtTema.Text;
mibase.conversaciones.InsertOnSubmit(conver);
mibase.SubmitChanges();
traerConversaciones();
}
private void traerConversaciones()
{
var conversaciones = from conver in mibase.conversaciones
where conver.id > 0
select conver;
lstTemaConversaciones.Items.Clear();
foreach (var iterConversacion in conversaciones)
{
lstTemaConversaciones.Items.Add(iterConversacion);
}
}
private void Temas_Conversaciones_Load(object sender, EventArgs e)
{
traerConversaciones();
}
private void btnUnirse_Click(object sender, EventArgs e)
{
Conversacion conv = (Conversacion)lstTemaConversaciones.SelectedItem;
String id_conver = conv.id.ToString();
Mostrar_Conversaciones conver1 = new Mostrar_Conversaciones(id_user, id_conver);
conver1.Show();
}
}
}
----------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Chat_20_07_2015
{
public partial class Mostrar_Conversaciones : Form
{
MiBD mibase = new MiBD();
String id_user;
public String Id_user
{
get { return id_user; }
set { id_user = value; }
}
String id_conver;
public String Id_conver
{
get { return id_conver; }
set { id_conver = value; }
}
public Mostrar_Conversaciones(String ini_id_user, String ini_id_conver)
{
id_user = ini_id_user;
id_conver = ini_id_conver;
InitializeComponent();
}
public Mostrar_Conversaciones()
{
InitializeComponent();
}
private void Mostrar_Conversaciones_Load(object sender, EventArgs e)
{
cargarConversaciones();
}
private void cargarConversaciones()
{
var cargarMensa = from mensaje in mibase.mensajes
where mensaje.id_conversaciones == id_conver
select mensaje;
lstConversacion.Items.Clear();
foreach (var iterMe in cargarMensa)
{
lstConversacion.Items.Add(iterMe);
}
}
private void btnEnviar_Click(object sender, EventArgs e)
{
Mensaje mensajeNuevo = new Mensaje();
mensajeNuevo.texto = txtMensaje.Text;
mensajeNuevo.id_usuarios = id_user;
mensajeNuevo.id_conversaciones = id_conver;
mibase.mensajes.InsertOnSubmit(mensajeNuevo);
mibase.SubmitChanges();
cargarConversaciones();
}
}
}
sábado, 12 de noviembre de 2011
TREEVIEW C#
public partial class Form1 : Form
{
private Interes listaInteres;
internal Interes ListaInteres
{
get { return listaInteres; }
set { listaInteres = value; }
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.listaInteres = new Interes();
this.listaInteres.Id = 1;
this.listaInteres.Nombre = "Interes";
llenarArbol();
}
private void llenarArbol(){
treeInteres.Nodes.Clear();
TreeNode nodo = new TreeNode();
nodo.Text = this.listaInteres.Nombre;
nodo.Tag = this.listaInteres;
treeInteres.Nodes.Add(nodo);
imprimirRamas(this.listaInteres.Intereses, treeInteres.Nodes[0]);
}
private void imprimirRamas(List<Interes> intereses, TreeNode nodoPadre)
{
int i = 0;
foreach (Interes interes in intereses)
{
TreeNode nodoHijo = new TreeNode();
nodoHijo.Text = interes.Nombre;
nodoHijo.Tag = interes;
nodoPadre.Nodes.Add(nodoHijo);
if (interes.Intereses.Count > 0)
{
imprimirRamas(interes.Intereses, nodoPadre.Nodes[i]);
}
i++;
}
}
private void btnGuardar_Click(object sender, EventArgs e)
{
Interes interes = new Interes();
interes.Id = Convert.ToInt16(txtId.Text);
interes.Nombre = txtNombre.Text;
/*
TreeNode nuevoNodo = new TreeNode();
nuevoNodo.Text = interes.Nombre;
nuevoNodo.Tag = interes;
treeInteres.SelectedNode.Nodes.Add(nuevoNodo);
*/
Interes interesPadre = (Interes) treeInteres.SelectedNode.Tag;
if (this.listaInteres.Id == interesPadre.Id)
listaInteres.Intereses.Add(interes);
else
buscarPadre(listaInteres.Intereses, interesPadre, interes);
llenarArbol();
}
private void btnImprimir_Click(object sender, EventArgs e)
{
Interes interesPrincipal = this.listaInteres;
System.Console.WriteLine(" (Negocio) Principal " + interesPrincipal.Id + " " + interesPrincipal.Nombre + " Num Nodos: " + interesPrincipal.Intereses.Count);
interesPrincipal = (Interes) this.treeInteres.Nodes[0].Tag;
System.Console.WriteLine(" (Vista) Principal "+ interesPrincipal.Id+ " "+interesPrincipal.Nombre+" Num Nodos: " + treeInteres.Nodes[0].Nodes.Count);
imprimirRamas(interesPrincipal.Intereses);
}
private void imprimirRamas(List<Interes> intereses)
{
foreach (Interes interes in intereses)
{
System.Console.WriteLine(interes.Id+" - "+interes.Nombre);
if (interes.Intereses.Count > 0)
{
imprimirRamas(interes.Intereses);
}
}
}
private void buscarPadre(List<Interes> intereses, Interes interesPadre, Interes interesHijo)
{
foreach(Interes interes in intereses){
if (interes.Id == interesPadre.Id)
{
interes.Intereses.Add(interesHijo);
break;
}
if (interes.Intereses.Count>0)
{
buscarPadre(interes.Intereses, interesPadre, interesHijo);
}
}
}
}
}
{
private Interes listaInteres;
internal Interes ListaInteres
{
get { return listaInteres; }
set { listaInteres = value; }
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.listaInteres = new Interes();
this.listaInteres.Id = 1;
this.listaInteres.Nombre = "Interes";
llenarArbol();
}
private void llenarArbol(){
treeInteres.Nodes.Clear();
TreeNode nodo = new TreeNode();
nodo.Text = this.listaInteres.Nombre;
nodo.Tag = this.listaInteres;
treeInteres.Nodes.Add(nodo);
imprimirRamas(this.listaInteres.Intereses, treeInteres.Nodes[0]);
}
private void imprimirRamas(List<Interes> intereses, TreeNode nodoPadre)
{
int i = 0;
foreach (Interes interes in intereses)
{
TreeNode nodoHijo = new TreeNode();
nodoHijo.Text = interes.Nombre;
nodoHijo.Tag = interes;
nodoPadre.Nodes.Add(nodoHijo);
if (interes.Intereses.Count > 0)
{
imprimirRamas(interes.Intereses, nodoPadre.Nodes[i]);
}
i++;
}
}
private void btnGuardar_Click(object sender, EventArgs e)
{
Interes interes = new Interes();
interes.Id = Convert.ToInt16(txtId.Text);
interes.Nombre = txtNombre.Text;
/*
TreeNode nuevoNodo = new TreeNode();
nuevoNodo.Text = interes.Nombre;
nuevoNodo.Tag = interes;
treeInteres.SelectedNode.Nodes.Add(nuevoNodo);
*/
Interes interesPadre = (Interes) treeInteres.SelectedNode.Tag;
if (this.listaInteres.Id == interesPadre.Id)
listaInteres.Intereses.Add(interes);
else
buscarPadre(listaInteres.Intereses, interesPadre, interes);
llenarArbol();
}
private void btnImprimir_Click(object sender, EventArgs e)
{
Interes interesPrincipal = this.listaInteres;
System.Console.WriteLine(" (Negocio) Principal " + interesPrincipal.Id + " " + interesPrincipal.Nombre + " Num Nodos: " + interesPrincipal.Intereses.Count);
interesPrincipal = (Interes) this.treeInteres.Nodes[0].Tag;
System.Console.WriteLine(" (Vista) Principal "+ interesPrincipal.Id+ " "+interesPrincipal.Nombre+" Num Nodos: " + treeInteres.Nodes[0].Nodes.Count);
imprimirRamas(interesPrincipal.Intereses);
}
private void imprimirRamas(List<Interes> intereses)
{
foreach (Interes interes in intereses)
{
System.Console.WriteLine(interes.Id+" - "+interes.Nombre);
if (interes.Intereses.Count > 0)
{
imprimirRamas(interes.Intereses);
}
}
}
private void buscarPadre(List<Interes> intereses, Interes interesPadre, Interes interesHijo)
{
foreach(Interes interes in intereses){
if (interes.Id == interesPadre.Id)
{
interes.Intereses.Add(interesHijo);
break;
}
if (interes.Intereses.Count>0)
{
buscarPadre(interes.Intereses, interesPadre, interesHijo);
}
}
}
}
}
viernes, 11 de noviembre de 2011
LISTVIEW FACIL PROGRAMACION
Como se cargan los datos en un listview
foreach (Auto iterAuto in autos)
{
ListViewItem itemLV = new ListViewItem();
itemLV.Text = Convert.ToString(iterAuto.Id);
itemLV.Tag = iterAuto;
lstvAutos.Items.Add(itemLV);
itemLV.SubItems.Add(iterAuto.Marca);
itemLV.SubItems.Add(iterAuto.Modelo);
//itemLV.SubItems.Add(iterAuto.Tipo);
Seleccion de un item en el listview
private void lstvAutos_SelectedIndexChanged(object sender, EventArgs e)
{
Auto autoSel = ((Auto)(lstvAutos.SelectedItems[0].Tag));
resultado.Text = autoSel.Id + "-" + autoSel.Marca + "-" + autoSel.Modelo;
jueves, 10 de noviembre de 2011
PROGRAMACION UTILIZANDO EL TREEVIEW
public partial class Form1 : Form
{
int cont = 1;
public List<Persona> personas = new List<Persona>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Persona nuevoPersona = new Persona(1, "Personas");
personas.Add(nuevoPersona);
TreeNode nodoPersona = new TreeNode();
nodoPersona.Text = nuevoPersona.Nombre;
nodoPersona.Tag = nuevoPersona;
treeVPersonas.Nodes.Add(nodoPersona);
comboBGenero.Items.Add("Masculino");
comboBGenero.Items.Add("Femenino");
btnModificar.Enabled = false;
btnGuardar.Enabled = false;
btnEliminar.Enabled = true;
treeVPersonas.Enabled = false;
comboBGenero.Enabled = true;
txtNombre.Enabled = false;
}
private void btnGuardar_Click(object sender, EventArgs e)
{
Persona nuevoPersona = new Persona(cont++, txtNombre.Text,comboBGenero.Text);
Persona personaSeleccionada = (Persona)treeVPersonas.SelectedNode.Tag;
BuscarPadre(personas, personaSeleccionada, nuevoPersona);
lblId.Text = Convert.ToString(cont++);
txtNombre.Clear();
}
public void BuscarPadre(List<Persona> person, Persona nodoPadre, Persona nodoHijo)
{
foreach (Persona x in person)
{
if (x.Id == nodoPadre.Id)
{
x.ListaPersonas.Clear();
x.ListaPersonas.Add(nodoHijo);
TreeNode nodoSeleccionado = treeVPersonas.SelectedNode;
llenarArbol(x.ListaPersonas, nodoSeleccionado);
break;
}
if (x.ListaPersonas.Count > 0)
{
BuscarPadre(x.ListaPersonas, nodoPadre, nodoHijo);
}
}
}
public void llenarArbol(List<Persona> personlist, TreeNode nodoPadre)
{
int i = 0;
foreach (Persona x in personlist)
{
TreeNode nodoHijo = new TreeNode();
nodoHijo.Text = x.Nombre;
nodoHijo.Tag = x;
nodoPadre.Nodes.Add(nodoHijo);
if (x.ListaPersonas.Count > 0)
{
llenarArbol(x.ListaPersonas, nodoPadre.Nodes[i]);
}
i++;
}
}
private void btnEliminar_Click(object sender, EventArgs e)
{
treeVPersonas.SelectedNode.Remove();
}
private void btnNuevo_Click(object sender, EventArgs e)
{
btnNuevo.Enabled = false;
btnGuardar.Enabled = true;
btnEliminar.Enabled = true;
btnModificar.Enabled = false;
treeVPersonas.Enabled = true;
comboBGenero.Enabled = true;
txtNombre.Enabled = true;
}
}
}
{
int cont = 1;
public List<Persona> personas = new List<Persona>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Persona nuevoPersona = new Persona(1, "Personas");
personas.Add(nuevoPersona);
TreeNode nodoPersona = new TreeNode();
nodoPersona.Text = nuevoPersona.Nombre;
nodoPersona.Tag = nuevoPersona;
treeVPersonas.Nodes.Add(nodoPersona);
comboBGenero.Items.Add("Masculino");
comboBGenero.Items.Add("Femenino");
btnModificar.Enabled = false;
btnGuardar.Enabled = false;
btnEliminar.Enabled = true;
treeVPersonas.Enabled = false;
comboBGenero.Enabled = true;
txtNombre.Enabled = false;
}
private void btnGuardar_Click(object sender, EventArgs e)
{
Persona nuevoPersona = new Persona(cont++, txtNombre.Text,comboBGenero.Text);
Persona personaSeleccionada = (Persona)treeVPersonas.SelectedNode.Tag;
BuscarPadre(personas, personaSeleccionada, nuevoPersona);
lblId.Text = Convert.ToString(cont++);
txtNombre.Clear();
}
public void BuscarPadre(List<Persona> person, Persona nodoPadre, Persona nodoHijo)
{
foreach (Persona x in person)
{
if (x.Id == nodoPadre.Id)
{
x.ListaPersonas.Clear();
x.ListaPersonas.Add(nodoHijo);
TreeNode nodoSeleccionado = treeVPersonas.SelectedNode;
llenarArbol(x.ListaPersonas, nodoSeleccionado);
break;
}
if (x.ListaPersonas.Count > 0)
{
BuscarPadre(x.ListaPersonas, nodoPadre, nodoHijo);
}
}
}
public void llenarArbol(List<Persona> personlist, TreeNode nodoPadre)
{
int i = 0;
foreach (Persona x in personlist)
{
TreeNode nodoHijo = new TreeNode();
nodoHijo.Text = x.Nombre;
nodoHijo.Tag = x;
nodoPadre.Nodes.Add(nodoHijo);
if (x.ListaPersonas.Count > 0)
{
llenarArbol(x.ListaPersonas, nodoPadre.Nodes[i]);
}
i++;
}
}
private void btnEliminar_Click(object sender, EventArgs e)
{
treeVPersonas.SelectedNode.Remove();
}
private void btnNuevo_Click(object sender, EventArgs e)
{
btnNuevo.Enabled = false;
btnGuardar.Enabled = true;
btnEliminar.Enabled = true;
btnModificar.Enabled = false;
treeVPersonas.Enabled = true;
comboBGenero.Enabled = true;
txtNombre.Enabled = true;
}
}
}
Suscribirse a:
Entradas (Atom)