void insertausuarios() { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("No Deje Campos Vacios", "Advertencia"); textBox1.Focus(); } else { SqlCommand comando = new SqlCommand("insert into Usuarios(Usuario, contraseña)values(@Usuario,@contraseña)", Conexion.obtenerconexion()); comando.Parameters.AddWithValue("Usuario", textBox1.Text); comando.Parameters.AddWithValue("contraseña", textBox2.Text); Conexion.obtenerconexion(); comando.ExecuteNonQuery(); MessageBox.Show("Registro Agregado Satisfactoriamente", "Sistema"); } }
private void button4_Click(object sender, EventArgs e) { //ELIMINAR DialogResult resultado = MessageBox.Show("¿Estas Seguro de Eliminar el Registro Seleccionado?", "Advertencia", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado == DialogResult.No) { return; } SqlCommand comando = new SqlCommand("delete from productos where codproducto=@codproducto", Conexion.obtenerconexion()); comando.Parameters.AddWithValue("codproducto", dataGridView1.CurrentRow.Cells["codproducto"].Value); comando.ExecuteNonQuery(); Conexion.obtenerconexion().Close(); MessageBox.Show("Registro Eliminado Satisfactoriamente", "Sistema"); mostrarproductos(); }
void insertaproductos() { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("No Deje Campos Vacios", "Advertencia"); textBox1.Focus(); } else { SqlCommand comando = new SqlCommand("insert into productos(codproducto, nombreproducto,precio)values(@codproducto,@nombreproducto,@precio)", Conexion.obtenerconexion()); comando.Parameters.AddWithValue("codproducto", textBox1.Text); comando.Parameters.AddWithValue("nombreproducto", textBox2.Text); comando.Parameters.AddWithValue("precio", textBox3.Text); Conexion.obtenerconexion(); comando.ExecuteNonQuery(); MessageBox.Show("Registro Agregado Satisfactoriamente", "Sistema Garay Ventas PC"); } }
void mostrarusuarios() { SqlCommand comando = new SqlCommand("select * from Usuarios", Conexion.obtenerconexion()); Conexion.obtenerconexion(); SqlDataReader leer = comando.ExecuteReader(); dataGridView1.Rows.Clear(); int renglon = 0; while (leer.Read()) { renglon = dataGridView1.Rows.Add(); dataGridView1.Rows[renglon].Cells["Usuario"].Value = leer.GetString(0); dataGridView1.Rows[renglon].Cells["contraseña"].Value = leer.GetString(1); } Conexion.obtenerconexion().Close(); }
void mostrarclientes() { SqlCommand comando = new SqlCommand("select * from clientes", Conexion.obtenerconexion()); Conexion.obtenerconexion(); SqlDataReader leer = comando.ExecuteReader(); dataGridView1.Rows.Clear(); int renglon = 0; while (leer.Read()) { renglon = dataGridView1.Rows.Add(); dataGridView1.Rows[renglon].Cells["codcliente"].Value = leer.GetString(0); dataGridView1.Rows[renglon].Cells["nombres"].Value = leer.GetString(1); dataGridView1.Rows[renglon].Cells["pedido"].Value = leer.GetString(2); } Conexion.obtenerconexion().Close(); }
private void button1_Click(object sender, EventArgs e) { Conexion.obtenerconexion(); SqlCommand consulta = new SqlCommand("select * from Usuarios where Usuario='" + txtusu.Text + "'and contraseña='" + txtpass.Text + "'", Conexion.obtenerconexion()); SqlDataReader ejecuta = consulta.ExecuteReader(); if (ejecuta.Read() == true) { MessageBox.Show("Bienvenido: " + txtusu.Text, "Sistema"); this.Hide(); Sistema abrir = new Sistema(); abrir.Show(); } else if (txtusu.Text == "") { MessageBox.Show("No deje Campos Vacios", "Acceso Denegado"); txtpass.Clear(); txtusu.Clear(); txtusu.Focus(); Conexion.obtenerconexion().Close(); } else if (txtpass.Text == "") { MessageBox.Show("No deje Campos Vacios", "Acceso Denegado"); txtusu.Clear(); txtpass.Clear(); txtusu.Focus(); Conexion.obtenerconexion().Close(); } else { MessageBox.Show("Usuario o Contraseña Incorrecta - Ingrese Datos Otra vez", "Acceso Denegado"); txtusu.Clear(); txtpass.Clear(); txtusu.Focus(); Conexion.obtenerconexion().Close(); } }