move llamados a bd desde clase
This commit is contained in:
@@ -53,14 +53,12 @@ public partial class Nomina_Aguinaldo : ClsPaginas
|
||||
LtlUma.Text = "";
|
||||
int cveempresa = 1;
|
||||
if (UsuarioActual != null) { cveempresa = UsuarioActual.CveEmpresa; }
|
||||
using (ClsClaseBaseD objbase = new ClsClaseBaseD())
|
||||
|
||||
using (ClsNominas onom = new ClsNominas())
|
||||
{
|
||||
if (objbase.runQuerystr($"SELECT Valor UMA FROM [dbo].[RH_TablasValores] WHERE Tipo =1 AND CveEmpresa ={cveempresa} AND Fecha<'{DateTime.Now:yyyy/MM/dd}' ORDER BY Fecha DESC"))
|
||||
if (onom.UMAFechaGet(cveempresa, $"{DateTime.Now:yyyy/MM/dd}") && onom.DtResultados.Rows.Count > 0)
|
||||
{
|
||||
if (objbase.DtResultados.Rows.Count > 0)
|
||||
{
|
||||
LtlUma.Text = objbase.DtResultados.Rows[0]["UMA"].ToString();
|
||||
}
|
||||
LtlUma.Text = onom.DtResultados.Rows[0]["UMA"].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,7 +393,7 @@ public partial class Nomina_Aguinaldo : ClsPaginas
|
||||
int CvePersonal = 0;
|
||||
int CveSubProyecto = 0;
|
||||
StringBuilder str = new StringBuilder();
|
||||
using (ClsClaseBaseD objbase = new ClsClaseBaseD())
|
||||
using (ClsNominas objbase = new ClsNominas())
|
||||
{
|
||||
|
||||
foreach (GridViewRow gvrow in GVCalcularAguinaldo.Rows)
|
||||
@@ -433,10 +431,11 @@ public partial class Nomina_Aguinaldo : ClsPaginas
|
||||
{
|
||||
FraccionI = (aguinaldogravado / diasanio) * diasmes;
|
||||
FraccionII_1 = salariomensual + FraccionI;
|
||||
str.Clear();
|
||||
str.AppendFormat("SELECT dbo.Fnc_NomValues(40, 0, {2}, -1, {0}, {1}, {1}) isrFraccionII_2,", FraccionII_1, diasmes, DdlEjercicios.SelectedValue);
|
||||
str.AppendFormat(" dbo.Fnc_NomValues(40, 0, {2}, -1, {0}, {1}, {1}) isrFraccionIII_1", salariomensual, diasmes, DdlEjercicios.SelectedValue);
|
||||
if (objbase.runQuerystr(str.ToString()))
|
||||
//str.Clear();
|
||||
//str.AppendFormat("SELECT dbo.Fnc_NomValues(40, 0, {2}, -1, {0}, {1}, {1}) isrFraccionII_2,", FraccionII_1, diasmes, DdlEjercicios.SelectedValue);
|
||||
//str.AppendFormat(" dbo.Fnc_NomValues(40, 0, {2}, -1, {0}, {1}, {1}) isrFraccionIII_1", salariomensual, diasmes, DdlEjercicios.SelectedValue);
|
||||
//if (objbase.runQuerystr(str.ToString()))
|
||||
if(objbase.CalculosISRAguinaldo(FraccionII_1, salariomensual, diasmes, DdlEjercicios.SelectedValue))
|
||||
{
|
||||
DataRow drow = objbase.DtResultados.Rows[0];
|
||||
FraccionII_2 = drow["isrFraccionII_2"].ToString().ToDecimal();
|
||||
@@ -658,340 +657,3 @@ public partial class Nomina_Aguinaldo : ClsPaginas
|
||||
Response.End();
|
||||
}
|
||||
}
|
||||
|
||||
class ClsClaseBaseD : IDisposable
|
||||
{
|
||||
protected SqlConnection SqlConexion;
|
||||
protected SqlDataAdapter SqlAdapter;
|
||||
protected DataTable datos;
|
||||
protected DataSet DTSet;
|
||||
public DataTable DtResultados
|
||||
{
|
||||
get
|
||||
{
|
||||
return datos;
|
||||
}
|
||||
}
|
||||
public DataSet DTSetResultados
|
||||
{
|
||||
get
|
||||
{
|
||||
return DTSet;
|
||||
}
|
||||
}
|
||||
protected bool disposedValue = false;
|
||||
protected bool EsTransaccion = false;
|
||||
public string MyCurrentError;
|
||||
// REGISTRAR CONEXIÓN
|
||||
private int CveConexion = 0;
|
||||
|
||||
public ClsClaseBaseD(ClsClaseBaseD adsObj = null, SqlTransaction sqlTransacc = null, SqlDataAdapter sqlAdapter = null)
|
||||
{
|
||||
|
||||
|
||||
if (adsObj != null && adsObj.SqlAdapter != null && adsObj.SqlAdapter.SelectCommand != null && adsObj.SqlAdapter.SelectCommand.Transaction != null)
|
||||
{
|
||||
SqlConexion = adsObj.SqlConexion;
|
||||
SqlAdapter = adsObj.SqlAdapter;
|
||||
EsTransaccion = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sqlTransacc != null)
|
||||
{
|
||||
SqlConexion = sqlTransacc.Connection;
|
||||
SqlAdapter = sqlAdapter;
|
||||
EsTransaccion = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlConexion = new SqlConnection();
|
||||
SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
|
||||
try
|
||||
{
|
||||
SqlConexion.Open();
|
||||
SqlAdapter = new SqlDataAdapter("", SqlConexion);
|
||||
ConexionAdd();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SqlDataAdapter(string StrSQL, CommandType TipoComando = CommandType.StoredProcedure)
|
||||
{
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Clear();
|
||||
SqlAdapter.SelectCommand.CommandText = StrSQL;
|
||||
SqlAdapter.SelectCommand.CommandType = TipoComando;
|
||||
datos = new DataTable();
|
||||
DTSet = new DataSet();
|
||||
}
|
||||
}
|
||||
protected void DataAdapter(string StrSQL, CommandType TipoComando = CommandType.Text)
|
||||
{
|
||||
|
||||
// if (SqlAdapter.SelectCommand == null)
|
||||
// {
|
||||
// if ((sqlCommand != null))
|
||||
// {
|
||||
// SqlAdapter.SelectCommand = sqlCommand;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// SqlAdapter.SelectCommand = new SqlCommand();
|
||||
// }
|
||||
// SqlAdapter.SelectCommand.Connection = SqlConexion;
|
||||
// }
|
||||
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Clear();
|
||||
SqlAdapter.SelectCommand.CommandText = StrSQL;
|
||||
SqlAdapter.SelectCommand.CommandType = TipoComando;
|
||||
datos = new DataTable();
|
||||
DTSet = new DataSet();
|
||||
}
|
||||
}
|
||||
|
||||
private void ConexionAdd()
|
||||
{
|
||||
if (ConfigurationManager.AppSettings["RegistraConexion"] != null && ConfigurationManager.AppSettings["RegistraConexion"].ToString() == "1")
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlDataAdapter("PA_Sis_RegistrarConexion");
|
||||
{
|
||||
var withBlock = SqlAdapter.SelectCommand.Parameters;
|
||||
withBlock.Add("@Clase", SqlDbType.VarChar).Value = this.GetType().Name;
|
||||
withBlock.Add("@Modulo", SqlDbType.VarChar).Value = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath.ToString(), HttpContext.Current.Request.QueryString.ToString());
|
||||
withBlock.Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output;
|
||||
}
|
||||
SqlAdapter.Fill(datos);
|
||||
CveConexion = SqlAdapter.SelectCommand.Parameters["@IDConexion"].Value.ToString().ToEntero();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ConexionClose()
|
||||
{
|
||||
if (CveConexion > 0 && ConfigurationManager.AppSettings["RegistraConexion"] != null && ConfigurationManager.AppSettings["RegistraConexion"].ToString() == "1")
|
||||
{
|
||||
SqlDataAdapter(string.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text);
|
||||
|
||||
try
|
||||
{
|
||||
SqlAdapter.Fill(datos);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
|
||||
}
|
||||
CveConexion = 0;
|
||||
}
|
||||
}
|
||||
protected void addParameters(string name, SqlDbType tipo, object valor)
|
||||
{
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
SqlAdapter.SelectCommand.Parameters.Add(name, tipo).Value = valor;
|
||||
}
|
||||
|
||||
public bool runQuerystr(string Query, List<parametroQuery> Listaparametros = null, string msgError = "", bool mostrarError = true)
|
||||
{
|
||||
bool retorno = false;
|
||||
try
|
||||
{
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Clear();
|
||||
SqlAdapter.SelectCommand.CommandText = Query;
|
||||
SqlAdapter.SelectCommand.CommandType = CommandType.Text;
|
||||
datos = new DataTable();
|
||||
if (Listaparametros != null)
|
||||
{
|
||||
foreach (parametroQuery pr in Listaparametros)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Add(pr.ParameterName, pr.SqlDataType).Direction = pr.ParameterDirection;
|
||||
}
|
||||
}
|
||||
|
||||
SqlAdapter.Fill(datos);
|
||||
retorno = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string InfoAdicional = "Se intenta realizar una conexion con una conexion cerrada";
|
||||
InfoAdicional = $"{InfoAdicional}{Environment.NewLine}{msgError}{Environment.NewLine}";
|
||||
ModExtensiones.GuardaLog(InfoAdicional);
|
||||
}
|
||||
}
|
||||
catch (SqlException sqEx)
|
||||
{
|
||||
retorno = false;
|
||||
setOnError(msgError, sqEx);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retorno = false;
|
||||
setOnError(msgError, ex);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
public int ExecQuery(string Query, List<parametroQuery> Listaparametros = null, string msgError = "", bool mostrarError = true)
|
||||
{
|
||||
int retorno = -1;
|
||||
try
|
||||
{
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Clear();
|
||||
SqlAdapter.SelectCommand.CommandText = Query;
|
||||
SqlAdapter.SelectCommand.CommandType = CommandType.Text;
|
||||
if (Listaparametros != null)
|
||||
{
|
||||
foreach (parametroQuery pr in Listaparametros)
|
||||
{
|
||||
SqlAdapter.SelectCommand.Parameters.Add(pr.ParameterName, pr.SqlDataType).Direction = pr.ParameterDirection;
|
||||
}
|
||||
}
|
||||
|
||||
retorno = SqlAdapter.SelectCommand.ExecuteNonQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
string InfoAdicional = "Se intenta realizar una conexion con una conexion cerrada";
|
||||
InfoAdicional = $"{InfoAdicional}{Environment.NewLine}{msgError}{Environment.NewLine}";
|
||||
this.GuardaLog(InfoAdicional);
|
||||
}
|
||||
}
|
||||
catch (SqlException sqEx)
|
||||
{
|
||||
retorno = -1;
|
||||
setOnError(msgError, sqEx);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retorno = -1;
|
||||
setOnError(msgError, ex);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
|
||||
|
||||
protected bool RunQuery(string msgOnError)
|
||||
{
|
||||
bool retorno = false;
|
||||
|
||||
try
|
||||
{
|
||||
SqlAdapter.Fill(datos);
|
||||
retorno = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retorno = false;
|
||||
|
||||
setOnError(msgOnError, ex);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
protected bool RunQueryDS(string msgOnError)
|
||||
{
|
||||
bool retorno = false;
|
||||
|
||||
try
|
||||
{
|
||||
SqlAdapter.Fill(DTSet);
|
||||
retorno = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retorno = false;
|
||||
|
||||
setOnError(msgOnError, ex);
|
||||
}
|
||||
return retorno;
|
||||
}
|
||||
public void setOnError(string Mensaje, Exception Exeption)
|
||||
{
|
||||
string InfoAdicional = "";
|
||||
if (SqlAdapter != null && SqlAdapter.SelectCommand != null && SqlAdapter.SelectCommand.Parameters != null)
|
||||
InfoAdicional = SqlAdapter.SelectCommand.Parameters.ParametrosInfo();
|
||||
MyCurrentError = string.Format("{0} DESCRIPCIÓN DETALLADA: {1} {2} {3}", Mensaje, Exeption.ToString(), "\r\n", InfoAdicional);
|
||||
this.OnError(Mensaje, Exeption, InfoAdicional);
|
||||
}
|
||||
public void IniciaTransacSQL()
|
||||
{
|
||||
SqlAdapter.SelectCommand.Transaction = SqlConexion.BeginTransaction();
|
||||
EsTransaccion = true;
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
SqlAdapter.SelectCommand.Transaction.Commit();
|
||||
SqlConexion.Close();
|
||||
}
|
||||
|
||||
public void RollBack()
|
||||
{
|
||||
SqlAdapter.SelectCommand.Transaction.Rollback();
|
||||
SqlConexion.Close();
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
ConexionClose();
|
||||
if ((SqlConexion != null))
|
||||
{
|
||||
if (SqlConexion.State == ConnectionState.Open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((SqlAdapter != null))
|
||||
SqlAdapter.Dispose();
|
||||
|
||||
SqlConexion.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.OnError("Ocurrió un error al intentar cerrar la base de datos.", ex);
|
||||
}
|
||||
}
|
||||
SqlConexion.Dispose();
|
||||
}
|
||||
|
||||
if (datos != null)
|
||||
datos.Dispose();
|
||||
if (SqlAdapter != null)
|
||||
SqlAdapter.Dispose();
|
||||
|
||||
if (DTSet != null)
|
||||
DTSet.Dispose();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
//public class parametroQuery
|
||||
//{
|
||||
// public parametroQuery(string parameterName, object sqlValue, SqlDbType sqlDataType = default(SqlDbType), ParameterDirection parameterDirection = default(ParameterDirection))
|
||||
// {
|
||||
// this.ParameterName = parameterName;
|
||||
// this.SqlDataType = sqlDataType;
|
||||
// this.ParameterDirection = parameterDirection;
|
||||
// this.SqlValue = sqlValue;
|
||||
// }
|
||||
|
||||
// public string ParameterName { get; set; }
|
||||
// public SqlDbType SqlDataType { get; set; }
|
||||
// public ParameterDirection ParameterDirection { get; set; }
|
||||
// public object SqlValue { get; set; }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user