You are on page 1of 8

DICCIONARIO INFORMATICO

using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Data.SqlClient;

namespace Dic_informatico { public partial class Form1 : Form { private SqlConnection conexion = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=diccomp;Integrated Security=True"); private SqlDataAdapter da; private DataTable dt; private string seleccion = "SELECT * from conceptos"; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); CargarLista(); } private void txtbuscar_TextChanged(object sender, EventArgs e) { if (txtbuscar.Text != "")

{ DataRow[] filas; filas = dt.Select("palabra LIKE '%" + txtbuscar.Text + "%'"); lista.Items.Clear(); if (filas.Length > 0) { foreach (DataRow dr in filas) { lista.Items.Add(dr["palabra"].ToString()); } } } else CargarLista(); } private void txtinfo_TextChanged(object sender, EventArgs e) { double contador = txtinfo.Text.Length; double restante = 6000 - contador - 72; label3.Text = "Ha escrito " + contador.ToString() + " caracteres y le quedan: " + restante.ToString() + " caracteres."; } private void lista_SelectedIndexChanged(object sender, EventArgs e) { txtbuscar.Text = lista.SelectedItem.ToString().Trim(); CargarConceptos(); CargarLista(); } private void brnBuscar_Click(object sender, EventArgs e) { CargarConceptos(); CargarLista(); } private void CargarLista() { DataRow[] filas; filas = dt.Select("id >= '1'"); lista.Items.Clear(); if (filas.Length > 0) { foreach (DataRow dr in filas) { lista.Items.Add(dr["palabra"].ToString()); } } } private void CargarConceptos() { DataRow[] filas; filas = dt.Select("palabra LIKE '%" + txtbuscar.Text + "%'"); if (filas.Length > 0) { foreach (DataRow dr in filas) { txtinfo.Text = dr["palabra"].ToString().Trim().ToUpper(); txtinfo.Text += "\r\n\r\nConcepto 1:\r\n" + dr["concepto1"].ToString().Trim(); txtinfo.Text += "\r\n\r\nConcepto 2:\r\n" + dr["concepto2"].ToString().Trim(); txtinfo.Text += "\r\n\r\nConcepto 3:\r\n" + dr["concepto3"].ToString().Trim(); txtinfo.Text += "\r\n\r\nConcepto 4:\r\n" + dr["concepto4"].ToString().Trim(); txtinfo.Text += "\r\n\r\nConcepto 5:\r\n" + dr["concepto5"].ToString().Trim(); txtinfo.Text += "\r\n\r\nConcepto 6:\r\n" + dr["concepto6"].ToString().Trim(); } } } private void btnNuevo_Click(object sender, EventArgs e) {

mantenimiento nuevo = new mantenimiento(); nuevo.ShowDialog(); } private void label4_Click(object sender, EventArgs e) { da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); CargarLista(); } } } MODIFICACION DE DATOS

using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Data.SqlClient;

namespace Dic_informatico { public partial class mantenimiento : Form { private SqlConnection conexion = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=diccomp;Integrated Security=True"); private SqlDataAdapter da; private DataTable dt; private SqlCommand cmd; private string seleccion = "SELECT * from conceptos"; public mantenimiento() {

InitializeComponent(); } private void mantenimiento_Load(object sender, EventArgs e) { da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); palabras(); btnGuardar.Enabled = false; } //METODO QUE LIMPIA LOS TEXTBOX DE LOS DATOS DE LA BASE DE DATOS private void LimpiarControles() { //txtBuscar.Text = ""; txtId.Text = ""; txtPalabra.Text = ""; txtC1.Text = ""; txtC2.Text = ""; txtC3.Text = ""; txtC4.Text = ""; txtC5.Text = ""; txtC6.Text = ""; } //METODO QUE RELLENA LA LISTA DE LAS PALABRAS EXISTENTES EN LA TABLA CONCEPTOS private void palabras() { DataRow[] filas; filas = dt.Select("id>='0'"); lista.Items.Clear(); if (filas.Length > 0) { foreach (DataRow dr in filas) { lista.Items.Add(dr["palabra"].ToString()); } } } //METODO QUE REALIZA LA BUSQUEDA EN LA BASE DE DATOS DE TODOS SUS CAMPOS //Y LOS DATOS LOS MUESTRA EN EL TEXTBOX ESPECIFICO. private void conceptos() { DataRow[] conceptos; conceptos = dt.Select("palabra LIKE '%" + txtBuscar.Text + "%'"); if (conceptos.Length > 0) { foreach (DataRow dr in conceptos) { txtId.Text = dr["id"].ToString().Trim(); txtPalabra.Text = dr["palabra"].ToString().Trim(); txtC1.Text = dr["concepto1"].ToString().Trim(); txtC2.Text = dr["concepto2"].ToString().Trim(); txtC3.Text = dr["concepto3"].ToString().Trim(); txtC4.Text = dr["concepto4"].ToString().Trim(); txtC5.Text = dr["concepto5"].ToString().Trim(); txtC6.Text = dr["concepto6"].ToString().Trim(); } } } private void lista_SelectedIndexChanged(object sender, EventArgs e) { txtBuscar.Text = lista.SelectedItem.ToString().Trim(); conceptos(); palabras(); } private void txtBuscar_TextChanged(object sender, EventArgs e)

{ LimpiarControles(); if (txtBuscar.Text != "") { DataRow[] conceptos; conceptos = dt.Select("palabra LIKE '%" + txtBuscar.Text + "%'"); lista.Items.Clear(); if (conceptos.Length > 0) { foreach (DataRow dr in conceptos) { lista.Items.Add(dr["palabra"]).ToString(); } } } else palabras(); } //CUANDO EL TEXTO ES MAYOR QUE LA CANDIDAD INDICADA PARA CADA CASILLA //ESTA SE VUELVE ROJA DE LO CONTRARIO REGRESA A SU COLOR NORMAL. private void txtId_TextChanged(object sender, EventArgs e) { double id = txtId.Text.Length; lbid.Text = id.ToString() + " de 5"; if(id>5) this.txtId.BackColor = System.Drawing.Color.Red; else this.txtId.BackColor = System.Drawing.SystemColors.Window; } private void txtPalabra_TextChanged(object sender, EventArgs e) { double palabra = txtPalabra.Text.Length; lbpalabra.Text = palabra.ToString() + " de 40"; if (palabra > 40) this.txtPalabra.BackColor = System.Drawing.Color.Red; else this.txtPalabra.BackColor = System.Drawing.SystemColors.Window; } private void txtC1_TextChanged(object sender, EventArgs e) { double c1 = txtC1.Text.Length; lbc1.Text = c1.ToString() + " de 1000"; if (c1 > 1000) this.txtC1.BackColor = System.Drawing.Color.Red; else this.txtC1.BackColor = System.Drawing.SystemColors.Window; } private void txtC2_TextChanged(object sender, EventArgs e) { double c2 = txtC2.Text.Length; lbc2.Text = c2.ToString() + " de 1000"; if (c2 > 1000) this.txtC2.BackColor = System.Drawing.Color.Red; else this.txtC2.BackColor = System.Drawing.SystemColors.Window; } private void txtC3_TextChanged(object sender, EventArgs e) { double c3 = txtC3.Text.Length; lbc3.Text = c3.ToString() + " de 1000"; if (c3 > 1000) this.txtC3.BackColor = System.Drawing.Color.Red; else this.txtC3.BackColor = System.Drawing.SystemColors.Window;

} private void txtC4_TextChanged(object sender, EventArgs e) { double c4 = txtC4.Text.Length; lbc4.Text = c4.ToString() + " de 1000"; if (c4 > 1000) this.txtC4.BackColor = System.Drawing.Color.Red; else this.txtC4.BackColor = System.Drawing.SystemColors.Window; } private void txtC5_TextChanged(object sender, EventArgs e) { double c5 = txtC5.Text.Length; lbc5.Text = c5.ToString() + " de 1000"; if (c5 > 1000) this.txtC5.BackColor = System.Drawing.Color.Red; else this.txtC5.BackColor = System.Drawing.SystemColors.Window; } private void txtC6_TextChanged(object sender, EventArgs e) { double c6 = txtC6.Text.Length; lbc6.Text = c6.ToString() + " de 1000"; if (c6 > 1000) this.txtC6.BackColor = System.Drawing.Color.Red; else this.txtC6.BackColor = System.Drawing.SystemColors.Window; } private void btnNuevo_Click(object sender, EventArgs e) { btnGuardar.Enabled = true; txtBuscar.Text = ""; txtBuscar.Focus(); LimpiarControles(); lbMantenimiento.Text = "NUEVO"; } private void btnGuardar_Click(object sender, EventArgs e) { //GUARDAR DATOS if (lbMantenimiento.Text == "NUEVO") { if (txtId.Text != "" && txtPalabra.Text != "") { string guardar = "insert into conceptos(id, palabra, concepto1, concepto2, concepto3, concepto4, concepto5, concepto6) values(@id, @palabra, @c1, @c2, @c3, @c4, @c5, @c6)"; cmd = new SqlCommand(guardar, conexion); cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int)); cmd.Parameters["@id"].Value = double.Parse(txtId.Text); cmd.Parameters.Add(new SqlParameter("@palabra", SqlDbType.VarChar)); cmd.Parameters["@palabra"].Value = txtPalabra.Text; cmd.Parameters.Add(new SqlParameter("@c1", SqlDbType.VarChar)); cmd.Parameters["@c1"].Value = txtC1.Text; cmd.Parameters.Add(new SqlParameter("@c2", SqlDbType.VarChar)); cmd.Parameters["@c2"].Value = txtC2.Text; cmd.Parameters.Add(new SqlParameter("@c3", SqlDbType.VarChar)); cmd.Parameters["@c3"].Value = txtC3.Text;

cmd.Parameters.Add(new SqlParameter("@c4", SqlDbType.VarChar)); cmd.Parameters["@c4"].Value = txtC4.Text; cmd.Parameters.Add(new SqlParameter("@c5", SqlDbType.VarChar)); cmd.Parameters["@c5"].Value = txtC5.Text; cmd.Parameters.Add(new SqlParameter("@c6", SqlDbType.VarChar)); cmd.Parameters["@c6"].Value = txtC6.Text; cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); palabras(); lbMantenimiento.Text = "Datos Guardados"; } else { palabras(); lbMantenimiento.Text = "Faltan datos"; } } //MODIFICAR DATOS if (lbMantenimiento.Text == "MODIFICAR") { if (txtId.Text != "" && txtPalabra.Text != "") { string guardar = "update conceptos set palabra=@palabra, concepto1=@c1, concepto2=@c2, concepto3=@c3, concepto4=@c4, concepto5=@c5, concepto6=@c6 WHERE id=" + txtId.Text; cmd = new SqlCommand(guardar, conexion); cmd.Parameters.Add(new SqlParameter("@palabra", SqlDbType.VarChar)); cmd.Parameters["@palabra"].Value = txtPalabra.Text; cmd.Parameters.Add(new SqlParameter("@c1", SqlDbType.VarChar)); cmd.Parameters["@c1"].Value = txtC1.Text; cmd.Parameters.Add(new SqlParameter("@c2", SqlDbType.VarChar)); cmd.Parameters["@c2"].Value = txtC2.Text; cmd.Parameters.Add(new SqlParameter("@c3", SqlDbType.VarChar)); cmd.Parameters["@c3"].Value = txtC3.Text; cmd.Parameters.Add(new SqlParameter("@c4", SqlDbType.VarChar)); cmd.Parameters["@c4"].Value = txtC4.Text; cmd.Parameters.Add(new SqlParameter("@c5", SqlDbType.VarChar)); cmd.Parameters["@c5"].Value = txtC5.Text; cmd.Parameters.Add(new SqlParameter("@c6", SqlDbType.VarChar)); cmd.Parameters["@c6"].Value = txtC6.Text; cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); palabras();

lbMantenimiento.Text = "Datos modificados"; } else { palabras(); lbMantenimiento.Text = "Faltan datos..."; } } } private void btnEliminar_Click(object sender, EventArgs e) { if (txtId.Text != "") { string elim = "delete from conceptos where id=@id"; cmd = new SqlCommand(elim, conexion); cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.VarChar)); cmd.Parameters["@id"].Value = txtId.Text; cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); da = new SqlDataAdapter(seleccion, conexion); dt = new DataTable(); da.Fill(dt); palabras(); lbMantenimiento.Text = "dato eliminado" + txtId.Text; LimpiarControles(); } else { lbMantenimiento.Text = "dato no eliminado" + txtId.Text; } } private void btnModificar_Click(object sender, EventArgs e) { btnGuardar.Enabled = true; txtBuscar.Text = ""; txtBuscar.Focus(); lbMantenimiento.Text = "MODIFICAR"; } private void btnCancelar_Click(object sender, EventArgs e) { cmd.Connection.Close(); LimpiarControles(); btnGuardar.Enabled = false; lbMantenimiento.Text = "Accion cancelada"; } } }

You might also like