You are on page 1of 13

using 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; MySql.Data.MySqlClient; System.Text.RegularExpressions;

namespace ROVIAN { public partial class frmClientes : Form { private MySqlConnection conexion; public frmClientes() { InitializeComponent(); } public void Conexion() //metodo de conexion { string servidor = "localhost"; string baseDatos = "rovian"; string usuario = "root"; string password = ""; string cadenadeConexion = "SERVER=" + servidor + ";" + "DATABASE=" + baseDatos + ";" + "UID=" + usuario + ";" + "PASSWORD=" + password + ";"; conexion = new MySqlConnection(cadenadeConexion); } private void frmClientes_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'rovianDataSet.cliente' table. You can move, or remove it, as needed. this.clienteTableAdapter.Fill(this.rovianDataSet.cliente); } private void btnagregar_Click(object sender, EventArgs e) { int a = 0; if (txtid.Text == "") { MessageBox.Show("Ingresa el id", "Error", MessageBoxButtons.OK); txtid.Focus(); } else { if (txtnombre.Text == "") {

MessageBox.Show("Ingresa el nombre", "Error", MessageBoxButtons.OK); txtnombre.Focus(); } else { if (txtpaterno.Text == "") { MessageBox.Show("Ingresa el apellido paterno", "Error", MessageBoxButtons.OK); txtpaterno.Focus(); } else { if (txtmaterno.Text == "") { MessageBox.Show("Ingresa el apellido materno", "Error", MessageBoxButtons.OK); txtmaterno.Focus(); } else { if (msktelefono.Text == "") { MessageBox.Show("Ingresa el telefono", "Error", MessageBoxButtons.OK); msktelefono.Focus(); } else if (txtrfc.Text == "") { MessageBox.Show("Ingresa el RFC", "Error", MessageBoxButtons.OK); txtrfc.Focus(); } else if (txtcalle.Text == "") { MessageBox.Show("Ingresa la Calle", "Error", MessageBoxButtons.OK); txtcalle.Focus(); } else if (txtnumero.Text == "") { MessageBox.Show("Ingresa el Numero", "Error", MessageBoxButtons.OK); txtnumero.Focus(); } else if (txtcolonia.Text == "") { MessageBox.Show("Ingres a la Colonia", "Error", MessageBoxButtons.OK); txtcolonia.Focus(); } else

if (txtcp.Text == "") { MessageBox.Show("In gresa el Codigo Postal", "Error", MessageBoxButtons.OK); txtcp.Focus(); } else if (txtdel.Text == "") { MessageBox.Show ("Ingresa la Delegacion", "Error", MessageBoxButtons.OK); txtdel.Focus(); } else if (txtestado.Text == "") { MessageBox. Show("Ingresa el Estado", "Error", MessageBoxButtons.OK); txtestado.F ocus(); } else { Conexion(); try { string sentencia = "select * from cliente where id_cliente='" + txtid.Text + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); MySqlDataReader dr; dr = ejecutar.ExecuteReader(); if (dr.Read()) { a = int.Parse(dr[0].ToString()); } conexion.Close(); } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } /*if (a != 0) { MessageBox.Show("El id ya existe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtid.Text = ""; txtid.Focus();

}*/ { try {

int var = int.Parse(txtid.Text); // Aqui inserto con todos los valores de la tabla cliente string sentencia = "insert into cliente(nombre, ap_paterno, ap_materno, rfc, calle, numero, colonia, cod_postal, estado, del_municipio, telefono) values('" + txtnombre.Text + "', '" + txtmaterno.Text + "','" + txtpaterno.Text + "', '" + txtrfc.Text + "', '" + txtcalle.Text + "', '" + txtnumero.Text + "', '" + txtcolonia.Text + "', '" + txtcp.Text + "', '" + txtestado.Text + "', '" + txtdel.Text + "', '" + msktelefono.Text + "')"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); ejecutar.ExecuteNonQuery(); MessageBox.Show(this, "Se realizo el registro", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); conexion.Close(); txtnombre.Text = ""; txtmaterno.Text = ""; txtpaterno.Text = ""; txtrfc.Text = ""; txtcalle.Text = ""; txtnumero.Text = ""; txtcolonia.Text = ""; txtcp.Text = ""; txtestado.Text = ""; txtdel.Text = ""; msktelefono.Text = ""; } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtnombre.Text = ""; txtmaterno.Text = ""; txtpaterno.Text = ""; txtrfc.Text = ""; txtcalle.Text = ""; txtnumero.Text = ""; txtcolonia.Text = ""; txtcp.Text = ""; txtestado.Text = ""; txtdel.Text = ""; msktelefono.Text = "";

} } } } private void btneliminar_Click(object sender, EventArgs e) { Conexion(); if (MessageBox.Show("Deseas eliminar el registro", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { try { string sentencia = "delete from cliente where id_cliente='" + comboBox6.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); ejecutar.ExecuteNonQuery(); MessageBox.Show(this, "Se elimino el registro", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); conexion.Close(); comboBox6.Text = ""; txtnombre.Text = ""; txtmaterno.Text = ""; txtpaterno.Text = ""; txtrfc.Text = ""; txtcalle.Text = ""; txtnumero.Text = ""; txtcolonia.Text = ""; txtcp.Text = ""; txtestado.Text = ""; txtdel.Text = ""; msktelefono.Text = ""; } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBox6.Text = ""; txtnombre.Text = ""; txtmaterno.Text = ""; txtpaterno.Text = ""; txtrfc.Text = ""; txtcalle.Text = ""; } }

txtnumero.Text = ""; txtcolonia.Text = ""; txtcp.Text = ""; txtestado.Text = ""; txtdel.Text = ""; msktelefono.Text = ""; } this.clienteTableAdapter.Fill(this.rovianDataSet.client e); } private void panel3_Paint(object sender, PaintEventArgs e) { } private void txtconsulta_Click(object sender, EventArgs e) { if (comboBox3.Text == "") { MessageBox.Show("Ingresa el id", "Error", MessageBoxButtons.OK); comboBox3.Focus(); } else { if (textBox21.Text == "") { MessageBox.Show("Ingresa el nombre", "Error", MessageBoxButtons.OK); textBox21.Focus(); } else { if (textBox19.Text == "") { MessageBox.Show("Ingresa el apellido paterno", "Error", MessageBoxButtons.OK); textBox19.Focus(); } else { if (textBox18.Text == "") { MessageBox.Show("Ingresa el apellido materno", "Error", MessageBoxButtons.OK); textBox18.Focus(); } else { if (maskedTextBox3.Text == "") { MessageBox.Show("Ingresa el telefono", }

"Error", MessageBoxButtons.OK); } else

maskedTextBox3.Focus(); if (textBox20.Text == "") { MessageBox.Show("Ingresa el RFC", } else textBox20.Focus();

"Error", MessageBoxButtons.OK);

if (textBox17.Text == "") { MessageBox.Show("Ingresa la Calle", "Error", MessageBoxButtons.OK); textBox17.Focus(); } else if (textBox16.Text == "") { MessageBox.Show("Ingresa el Numero", "Error", MessageBoxButtons.OK); textBox16.Focus(); } else if (textBox15.Text == "") { MessageBox.Show("Ingres a la Colonia", "Error", MessageBoxButtons.OK); textBox15.Focus(); } else if (textBox14.Text == "") { MessageBox.Show("In gresa el Codigo Postal", "Error", MessageBoxButtons.OK); textBox14.Focus(); } else if (textBox13.Text == "") { MessageBox.Show ("Ingresa la Delegacion", "Error", MessageBoxButtons.OK); textBox13.Focus (); } else if (comboBox5.Text == "") { MessageBox. Show("Ingresa el Estado", "Error", MessageBoxButtons.OK); comboBox5.F ocus(); }

else { Conexion(); try { string sentencia = "update cliente set nombre='" + textBox21.Text + "', ap_paterno='" + textBox19.Text + "', ap_materno='" + textBox18.Text + "', rfc='" + textBox20.Text + "', calle='" + textBox17.Text + "', numero='" + textBox16.Text + "', colonia='" + textBox15.Text + "', cod_postal='" + textBox14.Text + "', estado='" + comboBox5.Text + "', del_municipio='" + textBox13.Text + "', telefono='" + maskedTextBox3.Text + "' where id_cliente='" + comboBox3.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); ejecutar.ExecuteNonQuery(); MessageBox.Show(this, "Se realizo la modificacin", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); conexion.Close(); textBox21.Text = ""; textBox19.Text = ""; textBox18.Text = ""; textBox20.Text = ""; textBox17.Text = ""; textBox16.Text = ""; textBox15.Text = ""; textBox14.Text = ""; comboBox5.Text = ""; textBox13.Text = ""; maskedTextBox3.Text = ""; comboBox3.Text = ""; } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox21.Text = ""; textBox19.Text = ""; textBox18.Text = ""; textBox20.Text = ""; textBox17.Text = ""; textBox16.Text = ""; textBox15.Text = ""; textBox14.Text = ""; comboBox5.Text = ""; textBox13.Text = ""; maskedTextBox3.Text = ""; comboBox3.Text = "";

} } } } } } }

private void agregarToolStripMenuItem_Click(object sender, EventArgs e) { label42.Visible = false; panel4.Visible = false; panel3.Visible = false; panel2.Visible = false; panel1.Visible = true; panel1.Location = new System.Drawing.Point(12, 26); this.Text = "Cliente---Agregar"; } private void eliminarToolStripMenuItem_Click(object sender, EventArgs e) { label42.Visible = false; panel4.Visible = false; panel3.Visible = false; panel2.Visible = true; panel1.Visible = false; panel2.Location = new System.Drawing.Point(12, 26); this.Text = "Cliente---Eliminar"; } private void modificarToolStripMenuItem_Click(object sender, EventArgs e) { label42.Visible = false; panel4.Visible = true; panel3.Visible = false; panel2.Visible = false; panel1.Visible = false; panel4.Location = new System.Drawing.Point(12, 26); this.Text = "Cliente---Modificar"; } private void consultarToolStripMenuItem_Click(object sender, EventArgs e) { label42.Visible = false; panel4.Visible = false; panel3.Visible = true; panel2.Visible = false; panel1.Visible = false; panel3.Location = new System.Drawing.Point(12, 26); this.Text = "Cliente---Consultar"; }

private void salirToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void regresarToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void salirToolStripMenuItem1_Click(object sender, EventArgs e) { Application.Exit(); } private void frmClientes_MouseMove(object sender, MouseEventArgs e) { //txtid.Enabled = true; } private void txtid_MouseMove(object sender, MouseEventArgs e) { //txtid.Enabled = false; } private void comboBox6_SelectedIndexChanged(object sender, EventArgs e) { string nombre = "0", ap_paterno = "0", ap_materno = "0"; Conexion(); try { string sentencia = "select * from cliente where id_cliente='" + comboBox6.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); MySqlDataReader dr; dr = ejecutar.ExecuteReader(); if (dr.Read()) { nombre = dr[1].ToString(); ap_paterno = dr[2].ToString(); ap_materno = dr[3].ToString(); textBox6.Text = dr[4].ToString(); textBox5.Text = dr[5].ToString(); textBox4.Text = dr[6].ToString(); textBox3.Text = dr[7].ToString(); textBox2.Text = dr[8].ToString(); textBox24.Text = dr[9].ToString(); textBox1.Text = dr[10].ToString();

maskedTextBox1.Text = dr[11].ToString(); } textBox22.Text = nombre + " " + ap_paterno + " " + ap_materno; conexion.Close(); } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void comboBox8_SelectedIndexChanged(object sender, EventArgs e) { Conexion(); try { string sentencia = "select * from cliente where id_cliente='" + comboBox8.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); MySqlDataReader dr; dr = ejecutar.ExecuteReader(); if (dr.Read()) { textBox12.Text = dr[4].ToString(); textBox11.Text = dr[5].ToString(); textBox10.Text = dr[6].ToString(); textBox9.Text = dr[7].ToString(); textBox8.Text = dr[8].ToString(); textBox23.Text = dr[10].ToString(); textBox7.Text = dr[9].ToString(); maskedTextBox2.Text = dr[11].ToString(); } conexion.Close(); } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void comboBox4_SelectedIndexChanged(object sender,

EventArgs e) { /* Conexion(); try { string sentencia = "select * from cliente where nombre='" + comboBox4.SelectedValue + "' ap_paterno='" + comboBox4.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion); conexion.Open(); MySqlDataReader dr; dr = ejecutar.ExecuteReader(); if (dr.Read()) { textBox12.Text = dr[4].ToString(); textBox11.Text = dr[5].ToString(); textBox10.Text = dr[6].ToString(); textBox9.Text = dr[7].ToString(); textBox8.Text = dr[8].ToString(); textBox23.Text = dr[9].ToString(); textBox7.Text = dr[10].ToString(); maskedTextBox2.Text = dr[11].ToString(); } conexion.Close(); } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }*/

private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) { } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { Conexion(); try { string sentencia = "select * from cliente where id_cliente='" + comboBox3.SelectedValue + "'"; MySqlCommand ejecutar = new MySqlCommand(sentencia, conexion);

conexion.Open(); MySqlDataReader dr; dr = ejecutar.ExecuteReader(); if (dr.Read()) { textBox21.Text = dr[1].ToString(); textBox19.Text = dr[2].ToString(); textBox18.Text = dr[3].ToString(); textBox20.Text = dr[4].ToString(); textBox17.Text = dr[5].ToString(); textBox16.Text = dr[6].ToString(); textBox15.Text = dr[7].ToString(); textBox14.Text = dr[8].ToString(); textBox13.Text = dr[9].ToString(); comboBox5.Text = dr[10].ToString(); maskedTextBox3.Text = dr[11].ToString(); } } catch (Exception er) { conexion.Close(); MessageBox.Show(this, "Ocurrio el error: " + er, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }

private void txtid_TextChanged(object sender, EventArgs e) { } private void groupBox8_Enter(object sender, EventArgs e) { } }

You might also like