public static int actualizar(Cuenta pData) { int retorno = 0; MySqlConnection conexion = Connection.ObtenerConexion(); string squery = string.Format(" UPDATE cont_cuentas SET nombre = '{0}' ,descripcion = '{1}' WHERE id_cuenta = {2} ", pData.nombre, pData.descripcion, pData.id_cuenta); MySqlCommand cmd = new MySqlCommand(squery, conexion); retorno = cmd.ExecuteNonQuery(); conexion.Close(); return retorno; }
public static int agregar(Cuenta pData) { int retorno = 0; MySqlConnection conexion = Connection.ObtenerConexion(); string squery = string.Format("INSERT INTO cont_cuentas ( nombre ,descripcion) VALUES ( '{0}' ,'{1}') ", pData.nombre, pData.descripcion); MySqlCommand cmd = new MySqlCommand(squery, conexion); retorno = cmd.ExecuteNonQuery(); conexion.Close(); return retorno; }
private void btnAdd_Click(object sender, EventArgs e) { Cuenta pCliente = new Cuenta(); pCliente.nombre = txtNombre.Text.Trim(); pCliente.descripcion = txtDescripcion.Text.Trim(); int resultado = CuentaDal.agregar(pCliente); if (resultado > 0) { fLoadForm(); MessageBox.Show("Cuenta Guardada Exitosamente", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Ocurrio un Error al Guardar la Categoría", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGuardar_Click(object sender, EventArgs e) { Cuenta pCuenta = new Cuenta(); pCuenta.nombre = txtNombre.Text.Trim(); pCuenta.descripcion = txtDescripcion.Text.Trim(); pCuenta.id_cuenta = cuentaActual; int resultado = CuentaDal.actualizar(pCuenta); if (resultado > 0) { fLoadForm(); MessageBox.Show("Registro Actualizado Exitosamente", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Ocurrio un Error al Actualizar el registro", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static Cuenta obtener(Int32 pId) { MySqlConnection conexion = Connection.ObtenerConexion(); Cuenta pData = new Cuenta(); MySqlCommand cmd = new MySqlCommand(String.Format( "select id_cuenta, nombre ,descripcion from cont_cuentas where id_cuenta = {0} ", pId), conexion); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { pData.id_cuenta = reader.GetInt32(0); pData.nombre = reader.GetString(1); pData.descripcion = reader.GetString(2); } conexion.Close(); return pData; }
public static List<Cuenta> buscar(string pSearch = " ") { List<Cuenta> _lista = new List<Cuenta>(); MySqlConnection conexion = Connection.ObtenerConexion(); MySqlCommand cmd = new MySqlCommand(String.Format( "SELECT id_cuenta, nombre ,descripcion FROM cont_cuentas where nombre like '%{0}%' ", pSearch), conexion); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Cuenta pData = new Cuenta(); pData.id_cuenta = reader.GetInt32(0); pData.nombre = reader.GetString(1); pData.descripcion = reader.GetString(2); _lista.Add(pData); } conexion.Close(); return _lista; }