public void eliminarUsuario(string id) { Conexion conexion = new Conexion(); if (conexion.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("UPDATE USUARIO SET ACTIVO = 0 WHERE ID_USUARIO = \"{0}\"", id); comando.Connection = conexion.Connection; try { comando.ExecuteNonQuery(); conexion.Close(); } catch (Exception) { conexion.Close(); } } }
public void cerrarSesion(string user) { Conexion conexion = new Conexion(); if (conexion.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("UPDATE USUARIO SET ENLINEA = 0 WHERE ID_USUARIO = \"{0}\"", user); comando.Connection = conexion.Connection; try { comando.ExecuteNonQuery(); conexion.Close(); } catch (Exception) { conexion.Close(); } } }
public void eliminarCliente(string id) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("UPDATE PERSONA SET ACTIVO = 0 WHERE ID_PERSONA = \"{0}\"", id); comando.Connection = con.Connection; comando.ExecuteNonQuery(); con.Close(); } }
public void EjecutarAccion() { try { Conexion.Open(); Comando.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { Conexion.Close(); } }
public void eliminarDetallePedido(DetallePedido d) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "ELIMINAR_DETALLE_PEDIDO_PRODUCTO"; comando.Connection = con.Connection; comando.Parameters.Add("_NUM_ORDEN", MySqlDbType.Int32).Value = d.IdPedido; int check = comando.ExecuteNonQuery(); con.Close(); } }
public void registrarDetallePedido(DetallePedido d) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "REGISTRAR_DETALLE_PEDIDO_PRODUCTO"; comando.Connection = con.Connection; comando.Parameters.Add("_NUM_ORDEN", MySqlDbType.Int32).Value = d.IdPedido; comando.Parameters.Add("_CANTIDAD_PRODUCTO", MySqlDbType.Int32).Value = d.Cantidad; comando.Parameters.Add("_IMPORTE_TOTAL_PRODUCTO", MySqlDbType.Int32).Value = d.Subtotal; comando.Parameters.Add("_ID_PRODUCTO", MySqlDbType.Int32).Value = d.Producto.Id; comando.ExecuteNonQuery(); con.Close(); } }
public BindingList <Usuario> listarUsuarios() { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "LISTAR_USUARIOS"; comando.Connection = con.Connection; MySqlDataReader reader = comando.ExecuteReader(); BindingList <Usuario> usuarios = new BindingList <Usuario>(); while (reader.Read()) { Usuario u = new Usuario(); u.ApMat = reader.GetString("AP_MATERNO"); u.ApPat = reader.GetString("AP_PATERNO"); u.Direccion = reader.GetString("DIRECCION"); u.Dni = reader.GetString("DNI"); u.Email = reader.GetString("EMAIL"); u.EstadoU = reader.GetInt32("ACTIVO"); u.FechaNac = (DateTime)reader.GetMySqlDateTime("FECHA_NACIMIENTO"); u.IdPersona = reader.GetString("ID_PERSONA"); u.IdUsuario = Int32.Parse(reader.GetString("ID_USUARIO")); u.Nombre = reader.GetString("NOMBRE"); u.Password = reader.GetString("CONTRASENHA"); u.Sexo = reader.GetChar("SEXO"); u.Telefono = reader.GetString("TELEFONO"); u.TipoUsuario = reader.GetInt32("TIPO_USUARIO"); usuarios.Add(u); } con.Close(); return(usuarios); } return(null); }
public int obtenerIdOrden(int id) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("SELECT ID_ORDEN_PROD FROM ORDEN_PRODUCCION WHERE ID_PEDIDO_P = '{0}'", id); comando.Connection = con.Connection; MySqlDataReader reader = comando.ExecuteReader(); int idOrden = -1; if (reader.Read()) { OrdenProduccion orden = new OrdenProduccion(); idOrden = reader.GetInt32("ID_ORDEN_PROD"); } con.Close(); return(idOrden); } return(-1); }
public int cancelarPedido(string id) { Conexion conexion = new Conexion(); if (conexion.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("UPDATE PEDIDO_PRODUCTO SET ACTIVO = 0, ESTADO = 'CANCELADO'" + " WHERE ID_PEDIDO_P = \"{0}\"", id); comando.Connection = conexion.Connection; int rv = 0; try { rv = comando.ExecuteNonQuery(); } catch (Exception) { return(-1); } comando.CommandText = String.Format("UPDATE DETALLE_PEDIDO_PRODUCTO SET ACTIVO =0 WHERE NUM_ORDEN=\"{0}\"", id); int rv2 = 0; try { rv2 = comando.ExecuteNonQuery(); } catch (Exception) { return(-1); } conexion.Close(); } return(-1); }
public BindingList <Pedido> listarPedidos() { BindingList <Pedido> lista = new BindingList <Pedido>(); Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "LISTAR_PEDIDOS"; comando.Connection = con.Connection; MySqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { Pedido n = new Pedido(); n.IdPedido = reader.GetInt32("ID_PEDIDO_P").ToString(); n.IdUsuario = reader.GetInt32("ID_EMPLEADO").ToString(); n.IdCliente = reader.GetInt32("ID_CLIENTE").ToString(); n.FechaEntrega = reader.GetDateTime("FECHA_ENTREGA"); n.ImporteTotal = (float)reader.GetDecimal("IMPORTE_TOTAL"); n.Cuenta = (float)reader.GetDecimal("A_CUENTA_PED"); n.Saldo = (float)reader.GetDecimal("SALDO_PED"); n.Estado = reader.GetString("ESTADO"); if (reader.GetDecimal("IGV") > 0) { n.Igv = true; } else { n.Igv = false; } lista.Add(n); } con.Close(); } return(lista); }
public int registrarPedido(Pedido p, BindingList <DetallePedido> detalles) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "REGISTRAR_PEDIDO_PRODUCTO"; comando.Connection = con.Connection; comando.Parameters.Add("_ID_EMPLEADO", MySqlDbType.Int32).Value = p.IdUsuario; comando.Parameters.Add("_ID_CLIENTE", MySqlDbType.Int32).Value = p.IdCliente; comando.Parameters.Add("_FECHA_ENTREGA", MySqlDbType.Date).Value = p.FechaEntrega; comando.Parameters.Add("_IMPORTE_TOTAL", MySqlDbType.Decimal).Value = p.ImporteTotal; comando.Parameters.Add("_A_CUENTA_PED", MySqlDbType.Decimal).Value = p.Cuenta; comando.Parameters.Add("_SALDO_PED", MySqlDbType.Decimal).Value = p.Saldo; comando.Parameters.Add("_IGV", MySqlDbType.Decimal).Value = p.Igv; comando.Parameters.Add("_ID_PEDIDO", MySqlDbType.Int32).Direction = System.Data.ParameterDirection.Output; int check = comando.ExecuteNonQuery(); p.IdPedido = comando.Parameters["_ID_PEDIDO"].Value.ToString(); foreach (DetallePedido d in detalles) { d.IdPedido = p.IdPedido; this.registrarDetallePedido(d); } con.Close(); if (check == 1) { return(Int32.Parse(comando.Parameters["_ID_PEDIDO"].Value.ToString())); } else { return(0); } } return(-1); }
public Insumo buscarInsumo(string id) { Insumo p = new Insumo(); Conexion conexion = new Conexion(); if (conexion.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("SELECT * FROM PRODUCTO_GENERICO WHERE ID_PRODUCTO = \"{0}\"", id); comando.Connection = conexion.Connection; MySqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { p.Id = reader.GetInt32("ID_PRODUCTO").ToString(); p.Nombre = reader.GetString("NOMBRE"); p.Precio = reader.GetInt32("PRECIO"); p.Descripcion = reader.GetString("DESCRIPCION"); p.Color = reader.GetString("COLOR"); } conexion.Close(); } return(p); }
public void actualizarClienteJuridico(Juridica c) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "ACTUALIZAR_CLIENTE_JURIDICO"; comando.Connection = con.Connection; comando.Parameters.Add("_RAZON", MySqlDbType.VarChar).Value = c.RazonSocial; comando.Parameters.Add("_RUC", MySqlDbType.VarChar).Value = c.Ruc; comando.Parameters.Add("_NOMBRE", MySqlDbType.VarChar).Value = c.Nombre; comando.Parameters.Add("_TELEFONO", MySqlDbType.VarChar).Value = c.Telefono; comando.Parameters.Add("_EMAIL", MySqlDbType.VarChar).Value = c.Email; comando.Parameters.Add("_DIRECCION", MySqlDbType.VarChar).Value = c.Direccion; comando.Parameters.Add("_FECHA_ANIVERSARIO", MySqlDbType.Date).Value = c.FechaAniversario; comando.Parameters.Add("_ID_PERSONA", MySqlDbType.Int32).Value = c.IdPersona; int check = comando.ExecuteNonQuery(); con.Close(); } }
public void actualizarClienteNatural(Natural c) { Conexion con = new Conexion(); if (con.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.CommandText = "ACTUALIZAR_CLIENTE_NATURAL"; comando.Connection = con.Connection; comando.Parameters.Add("_NOMBRE", MySqlDbType.VarChar).Value = c.Nombre; comando.Parameters.Add("_DNI", MySqlDbType.VarChar).Value = c.Dni; comando.Parameters.Add("_AP_PATERNO", MySqlDbType.VarChar).Value = c.ApPat; comando.Parameters.Add("_AP_MATERNO", MySqlDbType.VarChar).Value = c.ApMat; comando.Parameters.Add("_SEXO", MySqlDbType.VarChar).Value = c.Sexo; comando.Parameters.Add("_FECHA_NAC", MySqlDbType.Date).Value = c.FechaNac; comando.Parameters.Add("_TELEFONO", MySqlDbType.VarChar).Value = c.Telefono; comando.Parameters.Add("_EMAIL", MySqlDbType.VarChar).Value = c.Email; comando.Parameters.Add("_DIRECCION", MySqlDbType.VarChar).Value = c.Direccion; comando.Parameters.Add("_ID_PERSONA", MySqlDbType.Int32).Value = Convert.ToInt32(c.IdPersona); comando.ExecuteNonQuery(); con.Close(); } }
public void CerrarConexion() { Conexion.Close(); }
public Persona buscarCliente(string id) { Conexion conexion = new Conexion(); if (conexion.IsConnected()) { MySqlCommand comando = new MySqlCommand(); comando.CommandText = String.Format("SELECT * FROM PERSONA_NATURAL WHERE PERSONA_NATURAL.ID_PERSONA = {0}", id); comando.Connection = conexion.Connection; int nfilas1 = 0; try { nfilas1 = int.Parse(comando.ExecuteScalar().ToString()); } catch (Exception) { } int nfilas2 = 0; comando.CommandText = String.Format("SELECT * FROM PERSONA_JURIDICA WHERE ID_PERSONA = {0}", id); try { nfilas2 = int.Parse(comando.ExecuteScalar().ToString()); } catch (Exception) { } if (nfilas2 > nfilas1) { Juridica j = new Juridica(); comando.CommandText = String.Format("SELECT * FROM PERSONA_JURIDICA INNER JOIN PERSONA WHERE PERSONA_JURIDICA.ID_PERSONA = {0}", id); MySqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { j.Nombre = reader.GetString("NOMBRE"); j.Email = reader.GetString("EMAIL"); j.Telefono = reader.GetString("TELEFONO"); } conexion.Close(); return(j); } else if (nfilas2 < nfilas1) { Natural n = new Natural(); comando.CommandText = String.Format("SELECT * FROM PERSONA_NATURAL INNER JOIN PERSONA WHERE PERSONA_NATURAL.ID_PERSONA = {0}", id); MySqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { n.Nombre = reader.GetString("NOMBRE"); n.ApPat = reader.GetString("AP_PATERNO"); n.ApMat = reader.GetString("AP_MATERNO"); n.Email = reader.GetString("EMAIL"); n.Telefono = reader.GetString("TELEFONO"); } conexion.Close(); return(n); } else { Console.WriteLine("caroxdaniela"); } } return(null); }