private void HabilitarDeshabilitarEmpleado(string pCodigoEmpleado, bool pHabilitar) { ValidarConexion(); string sentencia = @"SELECT * FROM area_servicio.ft_mant_habilitar_deshabilitar_empleado(:pCodigoEmpleado, :pHabilitar, :pUsuario);"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("pCodigoEmpleado", PgSqlType.VarChar).Value = pCodigoEmpleado; pgComando.Parameters.Add("pHabilitar", PgSqlType.Boolean).Value = pHabilitar; pgComando.Parameters.Add("pUsuario", PgSqlType.VarChar).Value = Pro_Usuario; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); } catch (Exception Exc) { MessageBox.Show("ALGO SALIO EN EL MOMENTO DE REGISTRAR EL EMPLEADO. " + Exc.Message, "FLUCOL"); } }
private void BorrarNoticia(int pID_Cliente_Noticia) { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM area_servicio.ft_mant_inactivar_noticia (:p_id_cliente_noticia)"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_id_cliente_noticia", PgSqlType.Int).Value = pID_Cliente_Noticia; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); memoNoticia.Text = ""; CargarDatos(); } catch (Exception Exc) { MessageBox.Show("Algo salió mal en el momento de Eliminar esta noticia. " + Exc.Message, "FLUCOL"); } }
private void Button1_Click_1(object sender, EventArgs e) { int combodetalleproducto = (int)comboGrupoSeleccionado.SelectedValue; //extraer id de combobox de detalle con "Selectedvalue" string query = @"SELECT * FROM public.ft_insert_nuevo_producto_detalle ( :p_nombre_producto, :p_id_de_grupo, :p_codigo_barras )"; PgSqlCommand pg_comando = new PgSqlCommand(query, pro_conexion); pg_comando.Parameters.Add("p_id_de_grupo", PgSqlType.Int).Value = combodetalleproducto; pg_comando.Parameters.Add("p_nombre_producto", PgSqlType.VarChar).Value = txt_nombre_nuevo_producto.Text; // solo si hay parametros en la funcion sql pg_comando.Parameters.Add("p_codigo_barras", PgSqlType.VarChar).Value = txt_codigo_de_barras.Text; try { pg_comando.ExecuteNonQuery(); //executenonquery cuando no necesitamos retornar un valor MessageBox.Show("Producto guardado con exito."); txt_nombre_nuevo_producto.Clear(); txt_codigo_de_barras.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btn_aendern_Click(object sender, EventArgs e) { if (lbl_ort.Text != "" && lbl_plz.Text != "" && lbl_strasse.Text != "") { int position = int.Parse(Hauptfenster.dataGridView2.CurrentRow.Cells["Position"].Value.ToString()); MessageBox.Show(strasse); strasse = ersetzen(strasse); ort = ersetzen(ort); if (strasse != "") { string update_strasse = "update liegenschaften set strasse = '" + strasse + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_strasse = new PgSqlCommand(update_strasse, Verbindung); cmd_update_strasse.ExecuteNonQuery(); } if (plz != 0) { string update_plz = "update liegenschaften set plz = '" + plz + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_plz = new PgSqlCommand(update_plz, Verbindung); cmd_update_plz.ExecuteNonQuery(); } if (ort != "") { string update_ort = "update liegenschaften set ort = '" + ort + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_ort = new PgSqlCommand(update_ort, Verbindung); cmd_update_ort.ExecuteNonQuery(); } } else { MessageBox.Show("Keine Liegenschaft ausgewählt!"); } this.Close(); }
public UsuarioDTO Autentica(UsuarioDTO objUsuario) { PgSqlConnection conn = new PgSqlConnection("User Id=postgres;Password=root;host=localhost;database=NIVEL_ACESSO;"); PgSqlCommand cmd = new PgSqlCommand(); cmd.CommandText = string.Format("SELECT * FROM public.\"TRABALHADORES\" WHERE \"LOGIN\" ='{0}' AND \"SENHA\" = '{1}';", objUsuario.Login, objUsuario.Senha); cmd.Connection = conn; conn.Open(); int aff = cmd.ExecuteNonQuery(); PgSqlDataReader ER; UsuarioDTO usuario = new UsuarioDTO(); ER = cmd.ExecuteReader(); if (ER.Read()) { usuario.Cpf = Convert.ToString(ER["cpf_usu"]); usuario.Nome = Convert.ToString(ER["nome_usu"]); usuario.Email = Convert.ToString(ER["email_usu"]); usuario.Login = Convert.ToString(ER["login_usu"]); usuario.Senha = Convert.ToString(ER["senha_usu"]); usuario.NivelDeAcesso = Convert.ToInt16(ER["nivelAcesso_usu"]); } conn.Close(); return(usuario); }
private void button1_Click(object sender, EventArgs e) { int v_comboproveedores = (int)comboProveedor.SelectedValue; string query = @"SELECT * FROM public.ft_insert_agregar_nuevo_detalle_proveedor ( :p_nombre_contacto, :p_id_proveedor, :p_correo_electronico_proveedor, :p_numero_cel, :p_numero_tel )"; PgSqlCommand pg_comando = new PgSqlCommand(query, pro_conexion); pg_comando.Parameters.Add("p_id_proveedor", PgSqlType.Int).Value = v_comboproveedores; pg_comando.Parameters.Add("p_nombre_contacto", PgSqlType.VarChar).Value = txt_nombre_contacto.Text; pg_comando.Parameters.Add("p_correo_electronico_proveedor", PgSqlType.VarChar).Value = txt_correo_electronico.Text; pg_comando.Parameters.Add("p_numero_cel", PgSqlType.VarChar).Value = txt_numero_celular.Text; pg_comando.Parameters.Add("p_numero_tel", PgSqlType.VarChar).Value = txt_numero_telefono.Text; try { pg_comando.ExecuteNonQuery(); MessageBox.Show("NUEVO PROVEEDOR AGREGADO."); LimpiarTextboxs(); } catch (Exception ex) { MessageBox.Show(ex.Message); }; }
private void btn_einfuegen_Click(object sender, EventArgs e) { if (tbx_datenpfad.Text != "" && tbx_name.Text != "") { string name = ersetzen(tbx_name.Text); string bemerkung = ersetzen(tbx_bemerkung.Text); //Datei wird eingelesen FileInfo fi = new FileInfo(tbx_datenpfad.Text); FileStream fs = fi.OpenRead(); byte[] buffer = new Byte[fi.Length]; fs.Read(buffer, 0, buffer.Length); fs.Close(); string datei = Convert.ToBase64String(buffer); string format = tbx_datenpfad.Text.Substring(tbx_datenpfad.Text.Length - 3); string date = dtp_datum.Value.Month.ToString() + "/" + dtp_datum.Value.Day.ToString() + "/" + dtp_datum.Value.Year.ToString(); string insert = "insert into dokumente (name, string, format, datum, bemerkung, liegenschafts_nr, jahr, dok_typ) values ('" + name + "', '" + datei + "', '" + format + "', '" + date + "', '" + bemerkung + "', '" + liegenschaft + "', '" + int.Parse(Hauptfenster.nud_jahr.Value.ToString()) + "', '" + lbx_dokument_typ.Text + "' )"; PgSqlCommand cmd_insert = new PgSqlCommand(insert, Verbindung); cmd_insert.ExecuteNonQuery(); this.Close(); } else { if (tbx_datenpfad.Text == "") { MessageBox.Show("Bitte geben sie einen Datenpfad an!"); } if (tbx_name.Text == "") { MessageBox.Show("Bitte geben sie einen Namen an!"); } } }
private void RegistrarEstadoSolicitud(int p_id_colaborador_solicitud, ESTADOS_SOLICITUD p_estado_solicitud) { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM arca_tesoros.ft_mant_respuesta_solicitud ( :p_id_colaborador_solicitud, :p_usuario, :p_estado, :p_observaciones_rechazo )"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_id_colaborador_solicitud", PgSqlType.Int).Value = p_id_colaborador_solicitud; pgComando.Parameters.Add("p_usuario", PgSqlType.VarChar).Value = Pro_Usuario; pgComando.Parameters.Add("p_estado", PgSqlType.Int).Value = (int)p_estado_solicitud; pgComando.Parameters.Add("p_observaciones_rechazo", PgSqlType.VarChar).Value = memoMotivosRechazo.Text; try { pgComando.ExecuteNonQuery(); MessageBox.Show("Solicitud Aprobada"); } catch (Exception Exc) { MessageBox.Show("Algo salió mal mientras se registraba el estado de la solicitud."); } }
public event EventHandler on_ProveedorAgregado; //evento personalizado #endregion #region BOTONES private void btn_guardar_grupo_Click(object sender, EventArgs e) { string query = @"SELECT * FROM public.ft_insert_nuevo_proveedor ( :p_nombre_proveedor )"; PgSqlCommand pg_comando = new PgSqlCommand(query, pro_conexion); pg_comando.Parameters.Add("p_nombre_proveedor", PgSqlType.VarChar).Value = txt_nuevo_proveeor.Text; // solo si hay parametros en la funcion sql try { pg_comando.ExecuteNonQuery(); //executenonquery cuando no necesitamos retornar un valor MessageBox.Show("Proveedor guardado con exito."); txt_nuevo_proveeor.Clear(); on_ProveedorAgregado?.Invoke(new object(), new EventArgs()); //invocacion del evento personalizado } catch (Exception ex) { MessageBox.Show(ex.Message); } DialogResult result = MessageBox.Show("¿DESEA AGREGAR OTRO PROVEEDOR?", "SALIR", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { } else if (result == DialogResult.No) { this.Close(); } }
private void GuardarNotica() { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM area_servicio.ft_mant_registrar_noticias_cliente_servicio ( :p_id_cliente_servicio, :p_usuario_posteo, :p_texto_noticia );"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_id_cliente_servicio", PgSqlType.Int).Value = Pro_ID_Cliente; pgComando.Parameters.Add("p_usuario_posteo", PgSqlType.VarChar).Value = Pro_Usuario; pgComando.Parameters.Add("p_texto_noticia", PgSqlType.VarChar).Value = memoNoticia.Text; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); memoNoticia.Text = ""; MessageBox.Show("La noticia se registro correctamente. ", "FLUCOL"); } catch (Exception Exc) { MessageBox.Show("Algo salió mal en el momento de Ingresar esta noticia. " + Exc.Message, "FLUCOL"); } }
private void GuardarCubrirAusencia() { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM arca_tesoros.ft_proc_insertar_detalles_cubrir_ausencia ( :p_id_colaborar_asistencia_actividades, :p_id_medio_cubrir_ausencia, :p_id_colaborador_cubre_ausencia )"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_id_colaborar_asistencia_actividades", PgSqlType.Int).Value = Pro_ID_Colaborar_Actividad; pgComando.Parameters.Add("p_id_medio_cubrir_ausencia", PgSqlType.Int).Value = (int)v_tipo_cubrir_ausencia; pgComando.Parameters.Add("p_id_colaborador_cubre_ausencia", PgSqlType.Boolean).Value = v_id_colaborador_cubre_ausencia; try { pgComando.ExecuteNonQuery(); Utilidades.MostrarDialogo(FindForm(), "Confirmación de Registros", "¡La asistencia se procesó correctamente!", Utilidades.BotonesDialogo.Ok); OnCubrirAusenciaIngresada?.Invoke(new object(), new EventArgs()); } catch (Exception Exc) { Log_Excepciones.CapturadorExcepciones(Exc, this.Name, "MarcarAsistencia"); MessageBox.Show("Algo salió mal mientras se marcaba asistencia del colaborador en la lista."); } }
private void GuardarCambiosTasaCambio() { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM area_servicio.ft_mant_registra_tasa_cambio(:p_venta, :p_compra, :p_usuario);"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_venta", PgSqlType.Numeric).Value = Convert.ToDecimal(txtVenta.Text); pgComando.Parameters.Add("p_compra", PgSqlType.Numeric).Value = Convert.ToDecimal(txtCompra.Text); pgComando.Parameters.Add("p_usuario", PgSqlType.VarChar).Value = Pro_Usuario; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); pgComando = null; MessageBox.Show("La tasa de cambio se actualizó exitosamente. "); LimpiarCajasTexto(); } catch (Exception Exc) { MessageBox.Show("Algo salió mal en el momento de Gurdar cambios en la tasa de cambio. "); } }
private void TrasladarEmpleado() { if (Pro_Conexion.State != ConnectionState.Open) { Pro_Conexion.Open(); } string sentencia = @"SELECT * FROM area_servicio.ft_mant_trasladar_empleado_a_sucursal(:p_id_cliente_servicio, :p_id_agencia_servicio_destino, :p_codigoempleado, :p_usuario);"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("p_id_cliente_servicio", PgSqlType.Int).Value = Pro_ID_ClienteServicio; pgComando.Parameters.Add("p_id_agencia_servicio_destino", PgSqlType.Int).Value = Pro_ID_AgenciaServicio; pgComando.Parameters.Add("p_codigoempleado", PgSqlType.VarChar).Value = Pro_CodigoEmpleadoSelecciondo; pgComando.Parameters.Add("p_usuario", PgSqlType.VarChar).Value = Pro_Usuario; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); MessageBox.Show("El traslado se completó de manera correcta."); } catch (Exception Exc) { MessageBox.Show("Algo salió mal en el traslado del empleado. " + Exc.Message); } }
// Выполняет запрос к базе данных. protected void ExecuteNonQuery(string commandText) { var command = new PgSqlCommand(commandText, _connection); _connection.Open(); command.ExecuteNonQuery(); _connection.Close(); }
public void Numero(string numero) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = " UPDATE Numero set numero = " + numero + ""; cmd.ExecuteNonQuery(); } }
public void AgregarSocioUnico(int a, string usuarionomb, string contraseña) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = " INSERT INTO socios(administrador,nombre, contra, id) " + "VALUES( 'true','" + usuarionomb + "' , '" + contraseña + "', 1)"; cmd.ExecuteNonQuery(); } }
public void ModificarProductoIdIdStringDes(int id, string descripcion) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = " UPDATE productos set descripcion ='" + descripcion + "' WHERE id=" + id + ""; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } }
public void Venta(string cantidad) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE Caja SET total = total+" + cantidad + ""; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } }
public void ModificarProductoStringCodID(string codigoBarras, int id) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = " UPDATE productos set codigo =" + codigoBarras + " WHERE id=" + id + ""; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } }
public void ModificarInventario(int id, int entradas) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE inventario set existencias = existencias+" + entradas + " WHERE id=" + id + ""; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } }
static void ModifyDept(PgSqlConnection connection) { PgSqlCommand command = connection.CreateCommand(); command.CommandText = "UPDATE public.test SET test='test' WHERE id > 1"; // return value of ExecuteNonQuery (i) is the number of rows affected by the command int i = command.ExecuteNonQuery(); Console.WriteLine(Environment.NewLine + "Rows in DEPT updated: {0}", i + Environment.NewLine); }
private void RegistrarEmpleado() { ValidarConexion(); string sentencia = @"SELECT * FROM area_servicio.ft_mant_registrar_empleado(:pID_ClienteServicio, :pID_AgenciaServicio, :pUsuario, :pCodigoEmpleado, :pPrimerNombre, :pSegundoNombre, :pPrimerApellido, :pSegundoApellido, :pIdentidad, :pID_Cargo, :pID_AgenciaAsignacion, :pUsuarioEmpleado, :pContraseniaTemporal );"; PgSqlCommand pgComando = new PgSqlCommand(sentencia, Pro_Conexion); pgComando.Parameters.Add("pID_ClienteServicio", PgSqlType.Int).Value = Pro_ID_ClienteServicio; pgComando.Parameters.Add("pID_AgenciaServicio", PgSqlType.Int).Value = Pro_ID_AgenciaServicio; pgComando.Parameters.Add("pUsuario", PgSqlType.VarChar).Value = Pro_Usuario; pgComando.Parameters.Add("pCodigoEmpleado", PgSqlType.VarChar).Value = txtCodigoEmpleado.Text; pgComando.Parameters.Add("pPrimerNombre", PgSqlType.VarChar).Value = txtPrimerNombre.Text; pgComando.Parameters.Add("pSegundoNombre", PgSqlType.VarChar).Value = txtSegundoNombre.Text; pgComando.Parameters.Add("pPrimerApellido", PgSqlType.VarChar).Value = txtPrimerApellido.Text; pgComando.Parameters.Add("pSegundoApellido", PgSqlType.VarChar).Value = txtSegundoApellido.Text; pgComando.Parameters.Add("pIdentidad", PgSqlType.VarChar).Value = txtIdentidadEmpleado.Text; pgComando.Parameters.Add("pID_Cargo", PgSqlType.Int).Value = gridCargos.EditValue; pgComando.Parameters.Add("pID_AgenciaAsignacion", PgSqlType.Int).Value = gridAgencias.EditValue; pgComando.Parameters.Add("pUsuarioEmpleado", PgSqlType.VarChar).Value = txtUsuario.Text; pgComando.Parameters.Add("pContraseniaTemporal", PgSqlType.VarChar).Value = txtContraseniaTemporal.Text; try { pgComando.ExecuteNonQuery(); sentencia = null; pgComando.Dispose(); MessageBox.Show("EMPLEADO REGISTRADO EXITOSAMENTE", "FLUCOL"); LimpiarCajasTexto(); NavigationEmpleados.SelectedPage = pagePrimeraPagina; } catch (Exception Exc) { MessageBox.Show("ALGO SALIO EN EL MOMENTO DE REGISTRAR EL EMPLEADO. " + Exc.Message, "FLUCOL"); } }
private void button1_Click(object sender, EventArgs e) { userCLosePG = true; if (textBox1.Text != "") { HF.pw = textBox1.Text; HF.WriteLine(HF.txt_pfad, 1, textBox1.Text); } if (cbx_port.Checked && tbx_port.Text == "") { MessageBox.Show("Es wurde kein Port angegeben!"); } else if (cbx_port.Checked && tbx_port.Text != "") { HF.port = tbx_port.Text; HF.WriteLine(HF.txt_pfad, 5, tbx_port.Text); } if (cbx_host.Checked && tbx_host.Text == "") { MessageBox.Show("Es wurde kein Host angegeben!"); } else if (cbx_host.Checked && tbx_host.Text != "") { HF.host = tbx_host.Text; HF.WriteLine(HF.txt_pfad, 4, tbx_host.Text); } if (eins && tbx_port.Text != "" && tbx_host.Text != "" && textBox1.Text != "") { try { Verbindung2.ConnectionString = "user id = postgres;password = "******";host = " + tbx_host.Text + ";port = " + tbx_port.Text + ";database = postgres;pooling = true;min pool size = 0;max pool size = 100;connection lifetime = 0;"; Verbindung2.Open(); string neue_tabelle = "CREATE TABLE liegenschaften (liegenschafts_nr text primary key, strasse text, plz int, ort text)"; PgSqlCommand cmd_erzeuge = new PgSqlCommand(neue_tabelle, Verbindung2); cmd_erzeuge.ExecuteNonQuery(); string dokumente = "CREATE TABLE dokumente (position serial primary key, name text, string text, format text, datum date, bemerkung text, liegenschafts_nr text, jahr int, dok_typ text)"; PgSqlCommand cmd_erzeuge2 = new PgSqlCommand(dokumente, Verbindung2); cmd_erzeuge2.ExecuteNonQuery(); Verbindung2.Close(); } catch (Exception ex) { } } this.Close(); }
private void btn_aendern_Click(object sender, EventArgs e) { int position = int.Parse(Hauptfenster.dataGridView1.CurrentRow.Cells["Position"].Value.ToString()); if (name != "") { name = tbx_name.Text; name = ersetzen(name); string update_name = "update dokumente set name = '" + name + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_name = new PgSqlCommand(update_name, Verbindung); cmd_update_name.ExecuteNonQuery(); } if (bemerkung != "") { bemerkung = tbx_bemerkung.Text; bemerkung = ersetzen(bemerkung); string update_bemerkung = "update dokumente set bemerkung = '" + bemerkung + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_bemerkung = new PgSqlCommand(update_bemerkung, Verbindung); cmd_update_bemerkung.ExecuteNonQuery(); } if (dokument_typ != "") { dokument_typ = lbx_dokument_typ.Text; string update_dokument_typ = "update dokumente set dok_typ = '" + dokument_typ + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_dok_typ = new PgSqlCommand(update_dokument_typ, Verbindung); cmd_update_dok_typ.ExecuteNonQuery(); } if (jahr != 0) { jahr = int.Parse(nup_jahr.Text); string update_jahr = "update dokumente set jahr = '" + jahr + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_jahr = new PgSqlCommand(update_jahr, Verbindung); cmd_update_jahr.ExecuteNonQuery(); } if (datum == true) { string date = dtp_datum.Value.Month.ToString() + "/" + dtp_datum.Value.Day.ToString() + "/" + dtp_datum.Value.Year.ToString(); string update_datum = "update dokumente set datum = '" + date + "' where position = '" + position.ToString() + "'"; PgSqlCommand cmd_update_datum = new PgSqlCommand(update_datum, Verbindung); cmd_update_datum.ExecuteNonQuery(); } this.Close(); }
/// <summary> /// Utilizar para insertar, actualizar o eliminar registros /// </summary> /// <param name="consulta">Insert, Update o Delete</param> /// <returns>Cantidad de registros afectados</returns> public int NonQuery(string consulta) { int registrosAfectados = 0; try { using (PgSqlConnection connection = new PgSqlConnection(this.sConexion)) { PgSqlCommand command = new PgSqlCommand(consulta, connection); command.Connection.Open(); registrosAfectados = command.ExecuteNonQuery(); } } catch (Exception) { throw; } return(registrosAfectados); }
public void AgregarProducto2(int a, string Nombre_producto, string CodigoDeBarra, string precio) { using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = " INSERT INTO productos(id, codigo, descripcion, precio) " + "VALUES( " + a + ",'" + CodigoDeBarra + "' , '" + Nombre_producto + "', " + precio + ")"; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } using (PgSqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO inventario (id, existencias) VALUES (" + a + ", 0);"; ///// INSERT INTO productos(id, codigo, descripcion,precio) VALUES (1,123456, 'chococrispis 750g', 58.5); cmd.ExecuteNonQuery(); } }
public int IncluirUsuario(UsuarioDTO objUsuarioDTO) { PgSqlConnection conn = new PgSqlConnection("User Id=postgres;Password=1254;host=localhost;database=Cadastro;"); PgSqlCommand cmd = new PgSqlCommand(); cmd.CommandText = string.Format("INSERT INTO public.\"tbUsuario\"(\"cpf_usu\", \"senha_usu\", \"nome_usu\",\"login_usu\", \"email_usu\", \"nivelAcesso_usu\") " + "VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", objUsuarioDTO.Cpf, objUsuarioDTO.Senha, objUsuarioDTO.Nome, objUsuarioDTO.Login, objUsuarioDTO.Email, objUsuarioDTO.NivelDeAcesso); cmd.Connection = conn; conn.Open(); int aff = cmd.ExecuteNonQuery(); conn.Close(); return(aff); }
public IList <UsuarioDTO> CarregarUsuario() { PgSqlConnection conn = new PgSqlConnection("User Id=postgres;Password=root;host=localhost;database=NIVEL_ACESSO;"); PgSqlCommand cmd = new PgSqlCommand(); cmd.CommandText = "SELECT * FROM public.\"TRABALHADORES\""; cmd.Connection = conn; conn.Open(); int aff = cmd.ExecuteNonQuery(); PgSqlDataReader ER; IList <UsuarioDTO> listaUsuarioDTO = new List <UsuarioDTO>(); ER = cmd.ExecuteReader(); if (ER.HasRows) { while (ER.Read()) { UsuarioDTO usuario = new UsuarioDTO(); usuario.Cpf = Convert.ToString(ER["CPF"]); usuario.Nome = Convert.ToString(ER["NOME"]); usuario.Email = Convert.ToString(ER["EMAIL"]); usuario.Login = Convert.ToString(ER["LOGIN"]); usuario.Status = Convert.ToChar(ER["STATUS"]); usuario.Senha = Convert.ToString(ER["SENHA"]); usuario.NivelDeAcesso = Convert.ToInt16(ER["NIVEL_DE_ACESSO"]); listaUsuarioDTO.Add(usuario); } } conn.Close(); return(listaUsuarioDTO); }
public int GuardaImagenBytesPosgres(string nombre, byte[] imagen) { int registrosAfectados = 0; try { using (PgSqlConnection connection = new PgSqlConnection(this.sConexion)) { PgSqlCommand command = new PgSqlCommand("INSERT INTO ctl_imagenesBytes (nom_imagen,arr_bytes) values (@nombre,@imagen)", connection); command.Parameters.Add("@nombre", PgSqlType.VarChar, nombre.Length).Value = nombre; command.Parameters.Add("@imagen", PgSqlType.ByteA, imagen.Length).Value = imagen; command.Connection.Open(); registrosAfectados = command.ExecuteNonQuery(); } } catch (Exception) { throw; } return(registrosAfectados); }
public static bool ConexionActiva(ref PgSqlConnection pConexion) { if (pConexion.State == ConnectionState.Open) { return(true); } pConexion.Open(); string sentencia_prueba = "SELECT 1"; PgSqlCommand pgComando = new PgSqlCommand(sentencia_prueba, pConexion); try { pgComando.ExecuteNonQuery(); return(true); } catch (Exception) { PgSqlConnection v_conexion_temporal = new PgSqlConnection(pConexion.ConnectionString); v_conexion_temporal.Password = pConexion.Password; int v_intentos = 0; while (v_intentos++ <= 30) { v_conexion_temporal = new PgSqlConnection(pConexion.ConnectionString); v_conexion_temporal.Password = pConexion.Password; try { v_conexion_temporal.Open(); pConexion = v_conexion_temporal; return(true); } catch (Exception) { } } } return(false); }