public Empleados_Adelantos obtener_datos(string id) { Empleados_Adelantos emp_adelanto = new Empleados_Adelantos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = @"SELECT empleados_adelantos.*, empleados.nombre, empleados.apellido FROM empleados_adelantos join empleados on empleados_adelantos.empleado_id = empleados.id where adelanto_id=@id"; cmd.Parameters.AddWithValue("@id", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { emp_adelanto.adelanto_id = Convert.ToInt32(reader["adelanto_id"].ToString()); emp_adelanto.fecha = Convert.ToDateTime(reader["fecha"]).ToShortDateString(); emp_adelanto.empleado_id = Convert.ToInt32(reader["empleado_id"]); emp_adelanto.empleado = reader["apellido"].ToString() + ", " + reader["nombre"].ToString(); emp_adelanto.descripcion = reader["descripcion"].ToString(); emp_adelanto.importe = Convert.ToDecimal(reader["importe"].ToString()); emp_adelanto.asignado_por = reader["asignado_por"].ToString(); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(emp_adelanto); }
public List <EmpleadosGrupos> obtener(string codigo = "") { string where = ""; if (codigo != "") { where += " where id=@codigo "; } List <EmpleadosGrupos> ret = new List <EmpleadosGrupos>(); UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from empleados_grupos" + where + " order by nombre"; cmd.Parameters.AddWithValue("@codigo", codigo); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { EmpleadosGrupos bar = new EmpleadosGrupos(); cargarDatos(bar, reader); ret.Add(bar); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
private List <Adelantos> crear_tmp_list(DateTime desde, DateTime hasta, List <DAL.Empleados> lista_asignados) { TimeSpan ts = hasta - desde; int dias = ts.Days; List <Adelantos> lista_adelantos = new List <Adelantos>(); List <Adelantos> lista_tmp = new List <Adelantos>(); Empleados empleados = new Empleados(); try { for (int i = 0; i <= dias; i++) { DateTime fecha = desde.AddDays(i); Adelantos adelanto = new Adelantos(); lista_adelantos = adelanto.obtener_registro_por_fecha(fecha, lista_asignados); lista_tmp.AddRange(lista_adelantos); } } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } return(lista_tmp); }
public void Guardar(int id) { UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); if (id == 0) { comando.CommandText = "INSERT INTO empleados_adelantos (fecha, empleado_id, descripcion, importe) values " + "(@fecha,@empleado_id, @descripcion,@importe)"; } else { comando.CommandText = "UPDATE empleados_adelantos SET fecha = @fecha," + " empleado_id = @empleado_id, descripcion = @descripcion, importe=@importe " + "where adelanto_id = @id"; comando.Parameters.AddWithValue("@id", id); } comando.Parameters.AddWithValue("@fecha", Convert.ToDateTime(fecha)); comando.Parameters.AddWithValue("@empleado_id", empleado_id); comando.Parameters.AddWithValue("@descripcion", descripcion); comando.Parameters.AddWithValue("@importe", Convert.ToDecimal(importe)); comando.Transaction = Database.obtenerTransaccion(); comando.Connection = conexion; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } var valor = comando.ExecuteScalar(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.StackTrace = ex.StackTrace; UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public List <Cliente> obtener() { limpiaDatos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM vw_cliente " , conexion); comando.Transaction = Database.obtenerTransaccion(); List <Cliente> cli = new List <Cliente>(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { Cliente t = new Cliente(); cargarDatos(t, dr); cli.Add(t); } return(cli); dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); return(cli); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public bool ObtenerAcceso(string codigo, string acceso) { limpiaDatos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM roles " + "WHERE rol_usuario = @rol_usuario " , conexion); comando.Parameters.AddWithValue("@rol_usuario", codigo); comando.Parameters.AddWithValue("@rol_acceso", acceso); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { string est = dr[acceso].ToString(); if (est == "1") { return(true); } else { return(false); } } return(true); dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); return(false); } }
private List <Gastos> crear_lista_gastos(string desde, string hasta) { List <Gastos> ret = new List <Gastos>(); UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = @"select * from (SELECT empleados_grupos.*, gastos.fecha, gastos.detalles, gastos.importe from empleados_grupos LEFT JOIN gastos on gastos.grupo = empleados_grupos.id) as base where (fecha BETWEEN @fecha1 AND @fecha2) or fecha IS NULL"; cmd.Parameters.AddWithValue("@fecha1", Convert.ToDateTime(desde)); cmd.Parameters.AddWithValue("@fecha2", Convert.ToDateTime(hasta)); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Gastos bar = new Gastos(); bar.fecha = Convert.ToDateTime(reader["fecha"].ToString()).ToShortDateString(); bar.grupo_nombre = reader["nombre"].ToString(); bar.importe = Convert.ToDecimal(reader["importe"].ToString()); bar.detalles = reader["detalles"].ToString(); ret.Add(bar); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
public List <ComprobanteItem> obtener(ComprobanteEncabezado comprobanteEncabezado) { limpiaDatos(); List <ComprobanteItem> ret = new List <ComprobanteItem>(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM comprobanteitem " + "WHERE cen_id = @cen_id " + "Order by cim_orden" , conexion); comando.Parameters.AddWithValue("@cen_id", comprobanteEncabezado.Id); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { ComprobanteItem ci = new ComprobanteItem(); cargarDatos(ci, dr); ret.Add(ci); } dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
public string obtener_sitio(DateTime fecha, string empleado_id) { string sitio = "NO TRABAJO"; MySqlConnection conexion = Database.obtenerConexion(true); string consulta = @" SELECT sitio_id, trabajo, sitios.Nombre as sitio_nombre from empleados_tareas left join sitios on sitio_id = sitios.CellID WHERE empleadoId=@empleado_id AND (@fecha BETWEEN fecha_inicio AND fecha_fin) AND trabajo='SI'"; MySqlCommand cmd = new MySqlCommand(consulta, conexion); cmd.Parameters.AddWithValue("@fecha", fecha); cmd.Parameters.AddWithValue("@empleado_id", empleado_id); cmd.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { sitio = reader["sitio_id"] + " - " + reader["sitio_nombre"].ToString(); } } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(sitio); }
public static string obtenerRutaOrigen() { if (ruta_origen == null) { MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM parametros " + "WHERE par_pc = @par_pc" , conexion); comando.Parameters.AddWithValue("@par_pc", Environment.MachineName); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { ruta_origen = dr["par_rutaCompartida"].ToString(); } dr.Close(); } catch (Exception ex) { LogManager.Mensaje UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; UltimoMensaje.TipoMensaje = LogManager.EMensaje.Critico; LogManager.Log.log(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } } return(ruta_origen); }
/// <summary> /// Carga en la instacia actual los atributos del Id pasado por parámetro /// </summary> public static List <IAlicuotaIva> obtenerLista(string texto) { //limpiaDatos(); List <IAlicuotaIva> retorno = new List <IAlicuotaIva>(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM " + dbTabla + " WHERE " + dbCampoNombre + " LIKE @query " , conexion); comando.Transaction = Database.obtenerTransaccion(); comando.Parameters.AddWithValue("@query", "%" + texto + "%"); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { AlicuotaIva p = new AlicuotaIva(); cargarDatos(p, dr); retorno.Add(p); } dr.Close(); } catch (Exception ex) { retorno = null; LogManager.Mensaje UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; LogManager.Log.log(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(retorno); }
public bool existe_en_otros_registros(string id) { bool ret = false; UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); comando.CommandText = "select count(*) from empleados where grupo = @id"; comando.Parameters.AddWithValue("@id", id); comando.Transaction = Database.obtenerTransaccion(); comando.Connection = conexion; int registros = 0; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } int.TryParse(comando.ExecuteScalar().ToString(), out registros); if (registros > 0) { ret = true; } } catch (Exception ex) { ret = true; UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.StackTrace = ex.StackTrace; UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
public Empleados login(string usuario, string pass) { Empleados res = new Empleados(); if (!usuario.Contains("@")) { usuario += "@telesoluciones.net"; } MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from empleados where mail=@usuario and password=@password"; cmd.Parameters.AddWithValue("@usuario", usuario); cmd.Parameters.AddWithValue("@password", pass); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cargarDatos(res, reader); } } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(res); }
public bool guardar(bool nuevo) { bool ret = false; Tipos_Gastos bar = new Tipos_Gastos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); if (nuevo) { cmd.CommandText = "insert into tipos_gastos (detalles) values (@detalles)"; } else { cmd.CommandText = "update tipos_gastos set detalles=@detalles where id=@id"; } cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@detalles", detalles); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } cmd.ExecuteNonQuery(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
} // Unsubscribe #endregion public void obtener(string usuario, string contraseña) { limpiaDatos(); MySqlConnection conexion = Database.obtenerConexion(true); ; MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM usuarios " + "WHERE usu_usuario = @usu_usuario and usu_password = @usu_password" , conexion); comando.Parameters.AddWithValue("@usu_usuario", usuario); comando.Parameters.AddWithValue("@usu_password", Comun.CryptoUtil.GetMd5Hash(contraseña)); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { cargarDatos(this, dr); } dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public Gastos obtener_gastos(string id) { Gastos tmp = new Gastos(); UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = @"select * from gastos where id=@id"; cmd.Parameters.AddWithValue("@id", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { tmp.fecha = Convert.ToDateTime(reader["fecha"].ToString()).ToShortDateString(); tmp.grupo_id = reader["grupo"].ToString(); tmp.importe = Convert.ToDecimal(reader["importe"].ToString()); tmp.detalles = reader["detalles"].ToString(); tmp.asignado_por = reader["asignado_por"].ToString(); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(tmp); }
} // Unsubscribe #endregion public List <string> accesoCliente() { List <string> acceso = new List <string>(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand("SELECT * FROM parametros WHERE parametro='acceso' ", conexion); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { acceso.Add(dr["acceso"].ToString()); } return(acceso); dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); return(acceso); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public void actualizarError(int id) { UltimoMensaje = null; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); string toFormat = "yyyy-MM-dd HH':'mm':'ss"; DateTime fecha = DateTime.Now; string fecha_conv = fecha.ToString(toFormat); comando.CommandText = "UPDATE transacciones SET tra_estado = true,tra_fechaFin='0000-00-00 00:00:00' WHERE tra_id = @id"; comando.Parameters.AddWithValue("@id", id); comando.Transaction = Database.obtenerTransaccion(); comando.Connection = conexion; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } comando.ExecuteNonQuery(); limpiaDatos(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
/// <summary> /// Carga en la instacia actual los atributos del Id pasado por parámetro /// </summary> //public static List<ILibroIvaVentas> obtener() //{ // //limpiaDatos(); // List<ILibroIvaVentas> retorno = new List<ILibroIvaVentas>(); // MySqlConnection conexion = Database.obtenerConexion(true); // MySqlCommand comando = new MySqlCommand( // "SELECT * " + // "FROM " + dbTabla // , conexion); // comando.Transaction = Database.obtenerTransaccion(); // try // { // if (Database.obtenerTransaccion() == null) // conexion.Open(); // MySqlDataReader dr = comando.ExecuteReader(); // while (dr.Read()) // { // LibroIvaVentas p = new LibroIvaVentas(); // cargarDatos(p, dr); // retorno.Add(p); // } // dr.Close(); // } // catch (Exception ex) // { // retorno = null; // LogManager.Mensaje UltimoMensaje = GestionErrores.obtenerError(ex); // UltimoMensaje.cargar( // System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), // System.Reflection.MethodBase.GetCurrentMethod().ToString(), // new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); // UltimoMensaje.EsError = true; // UltimoMensaje.StackTrace = ex.StackTrace; // LogManager.Log.log(UltimoMensaje); // } // finally // { // comando.Parameters.Clear(); // if (Database.obtenerTransaccion() == null) // if (conexion.State != ConnectionState.Closed) // conexion.Close(); // } // return retorno; //} /// <summary> /// Carga en la instacia actual los atributos del Id pasado por parámetro /// </summary> /// <param name="id">ID a buscar</param> public DataTable obtener(DateTime desde, DateTime hasta, string tableName) { limpiaDatos(); DataTable retorno = new DataTable(); retorno.TableName = tableName; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand("select * from vw_libroivaventas where cen_fecha >= @desde and cen_fecha <= @hasta", conexion); comando.Parameters.AddWithValue("desde", desde); comando.Parameters.AddWithValue("hasta", hasta); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataAdapter adapter = new MySqlDataAdapter(comando); adapter.Fill(retorno); return(retorno); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(null); }
public Tipos_Gastos obtener(string id) { Tipos_Gastos bar = new Tipos_Gastos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from tipos_gastos where id = @filtro"; cmd.Parameters.AddWithValue("@filtro", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { bar.id = Convert.ToInt32(reader["id"].ToString()); bar.detalles = reader["detalles"].ToString(); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(bar); }
/// <summary> /// Carga en la instacia actual los atributos del Id pasado por parámetro /// </summary> /// <param name="id">ID a buscar</param> public void obtener() { limpiaDatos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM parametros " + "WHERE par_pc = @par_pc" , conexion); nombre_pc = Environment.MachineName; comando.Parameters.AddWithValue("@par_pc", nombre_pc); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { cargarDatos(this, dr); } dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public string obtener_grupo_nombre(string id) { string ret = ""; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from empleados_grupos where id=@id"; cmd.Parameters.AddWithValue("@id", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ret = reader["nombre"].ToString(); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
public decimal obtener_importe(string id) { decimal ret = 0; UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from viaticos where viatico_codigo=@codigo"; cmd.Parameters.AddWithValue("@codigo", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ret = Convert.ToDecimal(reader["viatico_importe"].ToString()); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
} // Unsubscribe #endregion public decimal obtener_importe(DateTime fecha, int empleado_id) { decimal ret = 0; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select importe from empleados_adelantos where fecha=@fecha and empleado_id=@empleado_id"; cmd.Parameters.AddWithValue("@fecha", fecha); cmd.Parameters.AddWithValue("@empleado_id", empleado_id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { decimal.TryParse(reader["importe"].ToString(), out ret); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
public Empleados Obtener_por_key(string key) { Empleados ret = new Empleados(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "select * from empleados where recovery_key=@key"; cmd.Parameters.AddWithValue("@key", key); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cargarDatos(ret, reader); } reader.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(ret); }
} // Unsubscribe #endregion public void guardar() { UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "INSERT INTO empleados_logs (fecha, hora, usuario, empleado_id, accion, modulo)" + " values " + "(@fecha, @hora, @usuario, @empleado_id, @accion, @modulo);"; cmd.Parameters.AddWithValue("@fecha", DateTime.Now); cmd.Parameters.AddWithValue("@hora", DateTime.Now); cmd.Parameters.AddWithValue("@usuario", usuario); cmd.Parameters.AddWithValue("@empleado_id", empleado_id); cmd.Parameters.AddWithValue("@accion", accion); cmd.Parameters.AddWithValue("@modulo", modulo); cmd.Transaction = Database.obtenerTransaccion(); cmd.Connection = conexion; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } var valor = cmd.ExecuteScalar(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.StackTrace = ex.StackTrace; UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public bool borrar(int id) { bool resultado = true; UltimoMensaje = null; DAL.Database db = new Database(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); comando.CommandText = "Delete from empleados_adelantos where adelanto_id= @id"; comando.Parameters.AddWithValue("@id", id); comando.Transaction = Database.obtenerTransaccion(); comando.Connection = conexion; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } comando.ExecuteNonQuery(); } catch (Exception ex) { resultado = false; UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.StackTrace = ex.StackTrace; UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } return(resultado); }
public void obtenerComprobante() { //limpiaDatos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand( "SELECT * " + "FROM comprobanteencabezado " , conexion); comando.Transaction = Database.obtenerTransaccion(); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { } dr.Close(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
/// <summary> /// Elimina de la BD los datos correspondientes al ID de la instancia actual /// </summary> public void eliminar() { UltimoMensaje = null; MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand comando = new MySqlCommand(); comando.CommandText = "delete from usuarios " + "where usu_id= @usu_id"; comando.Parameters.AddWithValue("@usu_id", Id); comando.Transaction = Database.obtenerTransaccion(); comando.Connection = conexion; try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } comando.ExecuteNonQuery(); limpiaDatos(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; UltimoMensaje.StackTrace = ex.StackTrace; Notify(UltimoMensaje); } finally { comando.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }
public void borrar(string id) { Tipos_Gastos bar = new Tipos_Gastos(); MySqlConnection conexion = Database.obtenerConexion(true); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conexion; cmd.Transaction = Database.obtenerTransaccion(); cmd.CommandText = "delete from tipos_gastos where id=@id"; cmd.Parameters.AddWithValue("@id", id); try { if (Database.obtenerTransaccion() == null) { conexion.Open(); } cmd.ExecuteNonQuery(); } catch (Exception ex) { UltimoMensaje = GestionErrores.obtenerError(ex); UltimoMensaje.cargar( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), System.Reflection.MethodBase.GetCurrentMethod().ToString(), new System.Diagnostics.StackFrame(0, true).GetFileLineNumber()); UltimoMensaje.EsError = true; Notify(UltimoMensaje); } finally { cmd.Parameters.Clear(); if (Database.obtenerTransaccion() == null) { if (conexion.State != ConnectionState.Closed) { conexion.Close(); } } } }