public static List <DatosEquipo> consultaEquipo(string a) { List <DatosEquipo> equipo = new List <DatosEquipo>(); using (SqlConnection conexion = Conectar.conexion()) { SqlCommand consulta = new SqlCommand(string.Format("Select * from equipo as p where p.id_equipo like '%{0}%' or p.nombre like '%{1}%' or p.tecnico like '%{2}%' or p.num_jugadores like '%{3}%' or p.fecha_creacion like '%{4}%' or p.liga like '%{5}%' ", a, a, a, a, a, a), conexion); SqlDataReader Read = consulta.ExecuteReader(); while (Read.Read()) { DatosEquipo dato = new DatosEquipo(); dato.id_equipo = Read.GetString(0); dato.nombre = Read.GetString(1); dato.tecnico = Read.GetString(2); dato.num_jugadores = Read.GetString(3); dato.fecha_creacion = Read.GetString(4); dato.liga = Read.GetString(5); equipo.Add(dato); } conexion.Close(); return(equipo); } }
public static List <DatosJugador> consultaJugador(string a) { List <DatosJugador> jugador = new List <DatosJugador>(); using (SqlConnection conexion = Conectar.conexion()) { SqlCommand consulta1 = new SqlCommand(string.Format("Select * from jugador as p where p.id_jugador like '%{0}%' or p.nombre like '%{1}%' or p.apellido like '%{2}%' or p.posicion like '%{3}%' or p.edad like '%{4}%' or p.altura like '%{5}%'or p.peso like '%{6}%' or p.equipo like '%{7}%' ", a, a, a, a, a, a, a, a), conexion); SqlDataReader Read = consulta1.ExecuteReader(); while (Read.Read()) { DatosJugador dato = new DatosJugador(); dato.id_jugador = Read.GetString(0); dato.nombre = Read.GetString(1); dato.apellido = Read.GetString(2); dato.posicion = Read.GetString(3); dato.edad = Read.GetString(4); dato.altura = Read.GetString(5); dato.peso = Read.GetString(6); dato.equipo = Read.GetString(7); jugador.Add(dato); } conexion.Close(); return(jugador); } }
public static List <DatosPartido> consultaPartido(string a) { List <DatosPartido> partido = new List <DatosPartido>(); using (SqlConnection conexion = Conectar.conexion()) { SqlCommand consulta = new SqlCommand(string.Format("Select * from partido as p where p.id_partido like '{0}' or p.asistentes like '%{1}%' or p.e_local like '%{2}%' or p.e_visitante like '%{3}%' or p.estadio like '%{4}%' or p.arbitro like '%{5}%'or p.marcador like '%{6}%' or p.liga like '%{7}%' ", a, a, a, a, a, a, a, a), conexion); SqlDataReader Read = consulta.ExecuteReader(); while (Read.Read()) { DatosPartido dato = new DatosPartido(); dato.id_partido = Read.GetString(0); dato.asistentes = Read.GetString(2); dato.e_local = Read.GetString(3); dato.e_visitante = Read.GetString(4); dato.estadio = Read.GetString(5); dato.arbitro = Read.GetString(1); dato.marcador = Read.GetString(6); dato.liga = Read.GetString(7); partido.Add(dato); } conexion.Close(); return(partido); } }
public void agregarCategoriasP(String nombre) { Conectar con = new Conectar(); if (nombre != String.Empty) { dr = con.getSqlQuery("Select * From Categoria_Productos where nombreCategoria ='" + nombre + "'"); if (dr.Read()) { MessageBox.Show("El nombre de la categoria ya existe!."); } else { String cadena = "Insert Into Categoria_Productos(nombreCategoria)"; cadena += "Values('" + nombre + "')"; con.Query(cadena); con.Desconectar(); } } else { MessageBox.Show("Por favor rellene el campo Nombre!."); } }
private void dgvClientes_MouseClick(object sender, MouseEventArgs e) { Conectar cn = new Conectar(); if (e.Button == MouseButtons.Right) { // generamos objeto contextmenu ContextMenu y = new ContextMenu(); // añadimos opcion al menu y.MenuItems.Add("Eliminar Cliente").Name = "del"; int currentMouseOverRow = dgvClientes.HitTest(e.X, e.Y).RowIndex; y.Show(dgvClientes, new Point(e.X, e.Y)); // Verificamos si es la opcion que queremos if (y.MenuItems[0].Text.ToString() == "Eliminar Cliente") { if (MessageBox.Show("Esta seguro que desea eliminar los registros de este cliente?", "Eliminar registros?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string id = dgvClientes.CurrentRow.Cells[0].Value.ToString(); // MessageBox.Show("" + id); cn.BorrarCategoriaP("DELETE from Ventas where id_cliente = '" + id + "'"); cn.BorrarCategoriaP("DELETE from Clientes where id_cliente = '" + id + "'"); MessageBox.Show("Datos modificados!"); this.actualizarGrilla(); } } } }
public void insertarProducto(int Categoria, String nombre, int precio, int stock, PictureBox pic) { Conectar cn = new Conectar(); cn.Conectarx(); if (nombre == String.Empty) { MessageBox.Show("Debe rellenar el campo nombre"); return; } else if (precio.ToString() == String.Empty) { MessageBox.Show("Debe rellenar el campo precio"); return; } else if (stock.ToString() == String.Empty) { MessageBox.Show("Debe rellenar el campo nombre"); return; } else { String cadena = "INSERT INTO Productos(id_CatProducto,Nombre,Precio,Stock,Imagen)"; cadena += "VALUES(@id,@nombre,@precio,@stock,@imagen)"; SqlCommand cmd = new SqlCommand(cadena, cn.conexion); cmd.Parameters.Add("@id", SqlDbType.Int); cmd.Parameters.Add("@nombre", SqlDbType.VarChar); cmd.Parameters.Add("@precio", SqlDbType.Int); cmd.Parameters.Add("@stock", SqlDbType.Int); cmd.Parameters.Add("@imagen", SqlDbType.Image); cmd.Parameters["@id"].Value = Categoria; cmd.Parameters["@nombre"].Value = nombre; cmd.Parameters["@precio"].Value = precio; cmd.Parameters["@stock"].Value = stock; System.IO.MemoryStream ms = new System.IO.MemoryStream(); pic.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); cmd.Parameters["@imagen"].Value = ms.GetBuffer(); int c = cmd.ExecuteNonQuery(); if (c > 0) { MessageBox.Show("Producto insertado correctamente"); } else { MessageBox.Show("No se insertaron datos"); return; } cn.Desconectar(); } }
public void insertarVenta(String idProductos, int idCliente, int MedioPago, String fecha, String PrecioVenta) { Conectar cn = new Conectar(); MessageBox.Show(idProductos + "-" + idCliente + "-" + MedioPago + "-" + fecha + "-" + PrecioVenta); string cadena = "INSERT INTO Ventas"; cadena += "(id_producto,id_cliente,id_MedioPago,fecha_Venta,PrecioVenta)"; cadena += "Values('" + idProductos + "'," + idCliente + "," + MedioPago + ",'" + fecha + "','" + PrecioVenta + "')"; cn.Query(cadena); }
public int capturarIdCategoria(String nombre) { Conectar cn = new Conectar(); id = cn.getSqlQuery("Select id_CatProducto from Categoria_Productos where nombreCategoria ='" + nombre + "'"); if (id.Read()) { idCategoria = Convert.ToInt32(id["id_CatProducto"]); } return(this.idCategoria); }
public static List <DatosLiga> consultaLiga(string a) { List <DatosLiga> liga = new List <DatosLiga>(); using (SqlConnection conexion = Conectar.conexion()) { SqlCommand consulta1 = new SqlCommand(string.Format("Select * from liga as p where p.id_liga like '%{0}%' or p.nombre like '%{1}%' or p.partidos like '%{2}%' or p.num_equipos like '%{3}%' or p.deporte like '%{4}%' ", a, a, a, a, a), conexion); SqlDataReader Read = consulta1.ExecuteReader(); while (Read.Read()) { DatosLiga dato = new DatosLiga(); dato.id_liga = Read.GetString(0); dato.nombre = Read.GetString(1); dato.partidos = Read.GetString(2); dato.num_equipos = Read.GetString(3); dato.deporte = Read.GetString(4); liga.Add(dato); } conexion.Close(); return(liga); } }
public void modi() { Conectar.conexion(); dataGridView1.CellBeginEdit += dataGridView1_CellBeginEdit; Agregar f*g = new Agregar(); if (bandera == "Liga") { f*g.textBox7.Enabled = false; string val = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id_liga"].Value.ToString(); SqlCommand recorrer = new SqlCommand(string.Format("Select * from liga where id_liga = '{0}'", val), Conectar.conexion()); SqlDataReader leer = recorrer.ExecuteReader(); while (leer.Read()) { f*g.textBox7.Text = leer.GetString(0); f*g.textBox1.Text = leer.GetString(1); f*g.textBox2.Text = leer.GetString(2); f*g.textBox3.Text = leer.GetString(3); f*g.comboBox1.Text = leer.GetString(4); } leer.Close(); f*g.bandera = bandera; modif = true; f*g.modif = modif; f*g.BackgroundImage = global :: WindowsFormsApplication1.Properties.Resources.mlb_logo_wide; f*g.Text = bandera.ToString(); f*g.Show(); this.Hide(); } else if (bandera == "Jugador") { f*g.textBox7.Enabled = false; string val = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id_jugador"].Value.ToString(); SqlCommand recorrer = new SqlCommand(string.Format("Select * from jugador where id_jugador = '{0}'", val), Conectar.conexion()); SqlDataReader leer = recorrer.ExecuteReader(); while (leer.Read()) { f*g.textBox7.Text = leer.GetString(0); f*g.textBox1.Text = leer.GetString(1); f*g.textBox2.Text = leer.GetString(2); f*g.textBox6.Text = leer.GetString(3); f*g.textBox3.Text = leer.GetString(4); f*g.textBox4.Text = leer.GetString(5); f*g.textBox5.Text = leer.GetString(6); f*g.comboBox1.Text = leer.GetString(7); } leer.Close(); f*g.bandera = bandera; modif = true; f*g.modif = modif; f*g.BackgroundImage = global :: WindowsFormsApplication1.Properties.Resources.imagen; f*g.Text = bandera.ToString();; f*g.Show(); this.Hide(); } else if (bandera == "Partido") { f*g.textBox7.Enabled = false; string val = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id_partido"].Value.ToString(); SqlCommand recorrer = new SqlCommand(string.Format("Select * from partido where id_partido = '{0}'", val), Conectar.conexion()); SqlDataReader leer = recorrer.ExecuteReader(); while (leer.Read()) { f*g.textBox7.Text = leer.GetString(0); f*g.textBox3.Text = leer.GetString(1); f*g.textBox2.Text = leer.GetString(2); f*g.comboBox2.Text = leer.GetString(3); f*g.comboBox3.Text = leer.GetString(4); f*g.textBox1.Text = leer.GetString(5); f*g.textBox4.Text = leer.GetString(6); f*g.comboBox1.Text = leer.GetString(7); } leer.Close(); f*g.bandera = bandera; modif = true; f*g.modif = modif; f*g.Text = bandera.ToString();; f*g.Show(); this.Hide(); } else if (bandera == "Equipo") { f*g.textBox7.Enabled = false; string val = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id_equipo"].Value.ToString(); SqlCommand recorrer = new SqlCommand(string.Format("Select * from equipo where id_equipo = '{0}'", val), Conectar.conexion()); SqlDataReader leer = recorrer.ExecuteReader(); while (leer.Read()) { f*g.textBox7.Text = leer.GetString(0); f*g.textBox1.Text = leer.GetString(1); f*g.textBox3.Text = leer.GetString(2); f*g.textBox2.Text = leer.GetString(3); f*g.maskedTextBox1.Text = leer.GetString(4); f*g.comboBox1.Text = leer.GetString(5); } leer.Close(); f*g.bandera = bandera; modif = true; f*g.modif = modif; f*g.BackgroundImage = global ::WindowsFormsApplication1.Properties.Resources.dallas_cowboys; f*g.Text = bandera.ToString();; f*g.Show(); this.Hide(); } else { MessageBox.Show("ERROR"); } Conectar.conexion().Close(); }
public string bajas(string a) { string arg = "Ingrese id para eliminar " + bandera.ToString(); SqlConnection conectar = new SqlConnection(); conectar = Conectar.conexion(); if (textBox1.Text != "") { try { if (bandera == "Liga") { string baja = "DELETE FROM liga WHERE id_liga = @Liga or nombre = @Liga or partidos = @Liga or num_equipos = @Liga or deporte = @Liga"; SqlCommand cmdins = new SqlCommand(baja, conectar); cmdins.Parameters.AddWithValue("Liga", a); cmdins.ExecuteNonQuery(); cmdins.Dispose(); cmdins = null; arg = "Liga eliminada"; } else if (bandera == "Jugador") { string baja = "DELETE FROM jugador WHERE id_jugador = @Jugador or nombre = @Jugador or apellido = @Jugador or posicion = @Jugador or edad = @Jugador or altura = @Jugador or peso = @Jugador or equipo = @Jugador"; SqlCommand cmdins = new SqlCommand(baja, conectar); cmdins.Parameters.AddWithValue("Jugador", a); cmdins.ExecuteNonQuery(); cmdins.Dispose(); cmdins = null; arg = "Jugador eliminada"; } else if (bandera == "Equipo") { string baja = "DELETE FROM equipo WHERE id_equipo = @Equipo or nombre = @Equipo or num_jugadores = @Equipo or tecnico = @Equipo or fecha_creacion = @Equipo or liga = @Equipo"; SqlCommand cmdins = new SqlCommand(baja, conectar); cmdins.Parameters.AddWithValue("Equipo", a); cmdins.ExecuteNonQuery(); cmdins.Dispose(); cmdins = null; arg = "Equipo eliminado"; } else if (bandera == "Partido") { string baja = "DELETE FROM partido WHERE id_partido = @Partido or arbitro = @Partido or asistentes = @Partido or e_local = @Partido or e_visitante = @Partido or estadio = @Partido or marcador = @Partido or liga = @Partido"; SqlCommand cmdins = new SqlCommand(baja, conectar); cmdins.Parameters.AddWithValue("Partido", a); cmdins.ExecuteNonQuery(); cmdins.Dispose(); cmdins = null; arg = "Partido eliminada"; } else { MessageBox.Show("ERROR"); } } catch (System.FormatException) { MessageBox.Show("ERROR"); } } conectar.Close(); return(arg); }
private void Agregar_Load(object sender, EventArgs e) { Conectar.conexion(); if (bandera == "Partido" || modif == true) { this.Text = "Agregar " + bandera; SqlCommand c = new SqlCommand("Select nombre from liga", conexion); SqlDataReader read = c.ExecuteReader(); while (read.Read()) { comboBox1.Items.Add(read.GetString(0)); comboBox1.DisplayMember = "nombre"; } read.Close(); conexion.Close(); } else if (bandera == "Equipo" || modif == true) { this.BackgroundImage = global ::WindowsFormsApplication1.Properties.Resources.dallas_cowboys; this.Text = "Agregar " + bandera; SqlCommand c = new SqlCommand("Select nombre from liga", conexion); SqlDataReader read = c.ExecuteReader(); while (read.Read()) { comboBox1.Items.Add(read.GetString(0)); comboBox1.DisplayMember = "nombre"; } read.Close(); } else if (bandera == "Jugador" || modif == true) { this.BackgroundImage = global :: WindowsFormsApplication1.Properties.Resources.imagen; this.Text = "Agregar " + bandera; SqlCommand c = new SqlCommand("Select nombre from equipo", conexion); SqlDataReader read = c.ExecuteReader(); while (read.Read()) { comboBox1.Items.Add(read.GetString(0)); comboBox1.DisplayMember = "nombre"; } read.Close(); } else if (bandera == "Liga" || modif == true) { this.BackgroundImage = global :: WindowsFormsApplication1.Properties.Resources.mlb_logo_wide; this.Text = "Agregar " + bandera; comboBox1.Items.Add("Futbol"); comboBox1.Items.Add("Beisbol"); comboBox1.Items.Add("Futbol americano"); comboBox1.Items.Add("Basquetbol"); } else { MessageBox.Show("ERROR"); } conexion.Close(); mostrar(); }