move llamados a bd desde clase

This commit is contained in:
JORGE LUIS CAUDILLO ESPARZA
2023-03-20 13:40:56 -07:00
parent 495519c238
commit ee7902cc39
18 changed files with 879 additions and 1079 deletions

View File

@@ -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; }
//}

View File

@@ -423,15 +423,9 @@ public partial class Nomina_ChecadorAsistencia : ClsPaginas
if (continuar)
{
using (ClsClaseBase objbase = new ClsClaseBase())
using (ClsGenerales objbase = new ClsGenerales())
{
/*
INSERT INTO Gral_HistorialBitacora(CvePersonal,CveConceptoHistorialBitacora,Descripcion,Motivo,CveUsuario,CveEmpresa,Fecha,Actual)
SELECT CvePersonal, 384,'se ingreso asistencia manual','se ingreso asistencia manual',100,@CveEmpresa,MIN(CAST(Fecha AS DATE))
*/
objbase.runQuerystr(string.Format("INSERT INTO Gral_HistorialBitacora(CvePersonal,CveConceptoHistorialBitacora,Descripcion,Motivo,CveUsuario,CveEmpresa,Fecha,Actual)SELECT {0}, 384,'SE INGRESO ASISTENCIA MANUAL','SE INGRESO ASISTENCIA MANUAL',{3},{2},'{1:yyyy/MM/dd}','Asistió'",
DdlmcPersonal.SelectedValue.ToEntero(), fechaing, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario));
objbase.AddHistorialBitacora(384, -1, -1, -1, -1, -1, -1, -1, "Asistió", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa,0, "SE INGRESO ASISTENCIA MANUAL","","",CvePersonal: DdlmcPersonal.SelectedValue.ToEntero(),Fecha: $"{fechaing:yyyy/MM/dd}" ,Motivo: "SE INGRESO ASISTENCIA MANUAL");
}
Alert(string.Format("La asistencia se a agregado ({0:dd-MM-yyyy HH:mm:ss}).", fechaing), ModExtensiones.TipoMensaje.ToastInformacion);
@@ -496,9 +490,9 @@ public partial class Nomina_ChecadorAsistencia : ClsPaginas
int CvePersonal = TxtCvePersonal.Text.ToEntero();
List<RequestUpAsistenciaDetalle> registros = new List<RequestUpAsistenciaDetalle>();
int CveTurnoNEW = DdlTurno.SelectedValue.ToEntero();
using (ClsClaseBase objbase = new ClsClaseBase())
using (ClsRH objbase = new ClsRH())
{
objbase.runQuerystr(string.Format("UPDATE RH_Personal SET CveTurno={1} WHERE CvePersonal ={0}", CvePersonal, CveTurnoNEW));
objbase.PersonalTurnoUp(CveTurnoNEW,UsuarioActual.CveUsuario,UsuarioActual.CveEmpresa, CvePersonal);
}
foreach (GridViewRow row in GvAsistenciaUp.Rows)
@@ -522,11 +516,10 @@ public partial class Nomina_ChecadorAsistencia : ClsPaginas
obj.Motivo = TxtMotivo.Text.Trim();
if (CveTurno != CveTurnoNEW)
{
using (ClsClaseBase objbase = new ClsClaseBase())
using (ClsRH objbase = new ClsRH())
{
objbase.runQuerystr(string.Format("UPDATE RH_PersonalAsistenciasDetalle SET CveTurno={1} WHERE CveAsistenciaDetalle ={0}", CveAsistenciaDetalle, CveTurnoNEW));
objbase.runQuerystr(string.Format("UPDATE D SET CveTurno={1} FROM RH_PersonalAsistencias A INNER JOIN RH_PersonalAsistenciasDetalle D ON D.CveAsistencia =A.CveAsistencia AND D.CveTurno = {2} WHERE A.Fecha > '{0}' AND A.CvePersonal ={3}", Fecha, CveTurnoNEW, CveTurno, CvePersonal));
objbase.AsistenciaDetTurnoUp(CveAsistenciaDetalle, Fecha, CveTurnoNEW, CveTurno, CvePersonal, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
}
}
if (obj.Motivo.Length == 0 && CveAsistenciasInasistencias != obj.CveAsistenciasInasistencias)

View File

@@ -941,7 +941,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
}
if (dtempleados != null)
{
LnkAutorizar.Visible = (dtempleados.COUNT("CvePersonal", "CvePersonal > 0 AND NomAutorizado =0") > 0) || (Estatus < 2);
LnkAutorizar.Visible = (dtempleados.COUNT("CvePersonal", "CvePersonal > 0 AND NomAutorizado =0 AND SumaPercepciones > 0 ") > 0) || (Estatus < 2);
LnkCancelarNomina.Visible = (dtempleados.COUNT("CvePersonal", "CvePersonal > 0 AND NomAutorizado =1 AND SeTimbro=0") > 0);
}
UpDatos.Update();
@@ -1507,7 +1507,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
byte[] pdf = GeneraPDFNomina(CvePersonal, CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
if (pdf != null)
{
List<ClsSisMail.ArchivoMail> objarch = new List<ClsSisMail.ArchivoMail>();
List<ClsSisMail.ArchivoMail> objarch = new List<ClsSisMail.ArchivoMail>();
using (ClsNominas ObjNomina = new ClsNominas())
{
@@ -1614,7 +1614,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
byte[] pdf = GeneraPDFNomina(CvePersonal, CvePeriodo, UsuarioActual.CveEmpresa, UsuarioActual.Empresa.Ruta);
if (pdf != null)
{
List<ClsSisMail.ArchivoMail> objarch = new List<ClsSisMail.ArchivoMail>();
List<ClsSisMail.ArchivoMail> objarch = new List<ClsSisMail.ArchivoMail>();
using (ClsNominas ObjNomina = new ClsNominas())
{
@@ -2335,12 +2335,11 @@ public partial class Nomina_Nomina2 : ClsPaginas
{
Filesgral = TxtCargarNetos.getfiles().Archivos;
using (ClsClaseBase objbase = new ClsClaseBase())
using (ClsNominas objbase = new ClsNominas())
{
if (objbase.runQuerystr(string.Format("UPDATE C SET C.CveSistema = C.CveSistemaOLD FROM Nom_Conceptos C WHERE CveEmpresa ={0} AND CveSistema =-2; UPDATE C SET C.CveSistemaOLD = C.CveSistema FROM Nom_Conceptos C WHERE CveConcepto ={1};UPDATE C SET C.CveSistema =-2 FROM Nom_Conceptos C WHERE CveConcepto ={1};", UsuarioActual.CveEmpresa, ddlConceptocomisionNeto.SelectedValue.ToEntero())))
{
objbase.ConceptosCveSistemaUp(ddlConceptocomisionNeto.SelectedValue.ToEntero(), -2, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
}
}
}
@@ -2984,15 +2983,11 @@ public partial class Nomina_Nomina2 : ClsPaginas
if (drow != null)
{
decimal UMA = 96.22M;
using (ClsClaseBase objbase = new ClsClaseBase())
using (ClsNominas onom = new ClsNominas())
{
if (objbase.runQuerystr($"SELECT Valor UMA FROM [dbo].[RH_TablasValores] WHERE Tipo =1 AND CveEmpresa ={UsuarioActual.CveEmpresa} AND Fecha<'{DateTime.Now:yyyy/MM/dd}' ORDER BY Fecha DESC"))
if (onom.UMAFechaGet(UsuarioActual.CveEmpresa, $"{DateTime.Now:yyyy/MM/dd}") && onom.DtResultados.Rows.Count > 0)
{
if (objbase.DtResultados.Rows.Count > 0)
{
UMA = objbase.DtResultados.Rows[0]["UMA"].ToString().ToDecimal();
}
UMA = onom.DtResultados.Rows[0]["UMA"].ToString().ToDecimal();
}
}
TxtCCSysUMA.Text = $"{UMA:N2}";