Files
SIG/Nomina/RepInversiondeNomina.aspx.cs
2023-02-15 09:34:52 -07:00

459 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Extensiones;
using Microsoft.VisualBasic;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.Reporting.WebForms;
public partial class Nomina_RepInversiondeNomina : ClsPaginas
{
#region Propiedades
private string RfechaInicio
{
get { return (ViewState["RfechaInicio"] == null) ? "" : Convert.ToString(ViewState["RfechaInicio"]); }
set { ViewState["RfechaInicio"] = value; }
}
private string RfechaFin
{
get { return (ViewState["RfechaFin"] == null) ? "" : Convert.ToString(ViewState["RfechaFin"]); }
set { ViewState["RfechaFin"] = value; }
}
private int RcveProyecto
{
get { return (ViewState["RcveProyecto"] == null) ? 0 : Convert.ToInt32(ViewState["RcveProyecto"]); }
set { ViewState["RcveProyecto"] = value; }
}
private int RcveSubProyecto
{
get { return (ViewState["RcveSubProyecto"] == null) ? 0 : Convert.ToInt32(ViewState["RcveSubProyecto"]); }
set { ViewState["RcveSubProyecto"] = value; }
}
private int Ragrupador
{
get { return (ViewState["Ragrupador"] == null) ? 0 : Convert.ToInt32(ViewState["Ragrupador"]); }
set { ViewState["Ragrupador"] = value; }
}
private int RCveDepartamento
{
get { return (ViewState["RCveDepartamento"] == null) ? 0 : Convert.ToInt32(ViewState["RCveDepartamento"]); }
set { ViewState["RCveDepartamento"] = value; }
}
private string RcveStr1
{
get { return (ViewState["RcveStr1"] == null) ? "" : Convert.ToString(ViewState["RcveStr1"]); }
set { ViewState["RcveStr1"] = value; }
}
private string RcveStr2
{
get { return (ViewState["RcveStr2"] == null) ? "" : Convert.ToString(ViewState["RcveStr2"]); }
set { ViewState["RcveStr2"] = value; }
}
#endregion
protected override void Page_PreInit(object sender, EventArgs e)
{
if (!User.Identity.IsAuthenticated || UsuarioActual == null)
{
bool AuthorizeRequest = false;
var statusCode = 200;
AuthorizeRequest = false;
Response.StatusCode = statusCode;
if (!AuthorizeRequest)
{
Usuario.CerrarSession();
Response.End();
}
}
else
{
if (!Page.IsPostBack)
{
CveModulo = 906;
if (!UsuarioActual.TienePermisoPagina(CveModulo))
Response.Redirect(System.Web.Security.FormsAuthentication.DefaultUrl);
}
if (UsuarioActual.CveEmpresa == 42)
this.MasterPageFile = "~/Masters/Site42.master";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DdlSubProyecto.DataSource = get_GlobalDTSubProyectos(-1, -1, UsuarioActual.CveEmpresa, 1);
DdlSubProyecto.DataBind();
DdlSubProyecto.Items.Insert(0, new ListItem("Todos", "-1"));
DdlDepartamento.DataSource =get_GlobalDTDepartamentos(UsuarioActual.CveEmpresa).FiltraParametros(" Departamento <> 'Seleccione' " );
DdlDepartamento.DataBind();
DdlDepartamento.Items.Insert(0, new ListItem("Todos", "-1"));
TxtFechaInicio.Text = Request["fechaInicio"] == null ? DateTime.Now.ToString("01/MM/yyyy") : Request["fechaInicio"].ToString().ToDateTime().ToString("dd/MM/yyyy");
TxtFechaFin.Text = Request["fechaFin"] == null ? "" : Request["fechaFin"].ToString().ToDateTime().ToString("dd/MM/yyyy");
RfechaFin = TxtFechaFin.Text.Length > 9 ? TxtFechaFin.Text.ToDate().ToString("yyyyMMdd") : "";
RfechaInicio = TxtFechaInicio.Text.Length > 9 ? TxtFechaInicio.Text.ToDate().ToString("yyyyMMdd") : "";
RcveProyecto = Request["cveProyecto"] == null ? 0 : Request["cveProyecto"].ToString().ToEntero();
RcveSubProyecto = Request["cveSubProyecto"] == null ? -1 : Request["cveSubProyecto"].ToString().ToEntero();
Ragrupador = Request["agrupador"] == null ? 0 : Request["agrupador"].ToString().ToEntero();
RCveDepartamento = Request["CveDepartamento"] == null ? -1 : Request["CveDepartamento"].ToString().ToEntero();
RcveStr1 = Request["cveStr1"] == null ? "0" : Request["cveStr1"].ToString();
RcveStr2 = Request["cveStr2"] == null ? "0" : Request["cveStr2"].ToString();
//TxtFiltrocveProyecto.Text = RcveProyecto.ToString();
DdlSubProyecto.SelectedValueExist(RcveSubProyecto.ToString());
//TxtFiltroagrupador.Text = Ragrupador.ToString();
CargaInversionNominaGET();
}
}
protected void CargaInversionNominaGET()
{
using (ClsNominas ObjPA_N = new ClsNominas())
{
ObjPA_N.GetInversionNomina(UsuarioActual.CveEmpresa, RfechaInicio, RfechaFin, RcveProyecto, RcveSubProyecto, Ragrupador, RCveDepartamento, RcveStr1, RcveStr2);
GVInversionNomina.DataSource = ObjPA_N.DtResultados;
if (ObjPA_N.DTSetResultados.Tables.Count > 1 && 0 == 1)
{
DataTable dtConceptos = ObjPA_N.DTSetResultados.Tables[1];
int CurrentColumn = 4;
BoundField bf;
foreach (DataRow row in dtConceptos.Rows)
{
int CveConcepto = row["CveConcepto"].ToString().ToEntero();
string Concepto = row["Concepto"].ToString();
GVInversionNomina.Columns[CurrentColumn].ItemStyle.BackColor = System.Drawing.Color.Transparent;
GVInversionNomina.Columns[CurrentColumn].Visible = true;
bf = (BoundField)GVInversionNomina.Columns[CurrentColumn];
bf.DataField = string.Format("C_{0}", CveConcepto);
bf.HeaderText = Concepto;
CurrentColumn++;
}
while (CurrentColumn < 34)
{
bf = (BoundField)GVInversionNomina.Columns[CurrentColumn];
bf.DataField = "";
GVInversionNomina.Columns[CurrentColumn].Visible = false;
CurrentColumn++;
}
}
ObjPA_N.Dispose();
}
GVInversionNomina.DataBind();
upDatosPA_N.Update();
}
protected void GVInversionNomina_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string tipo = e.Row.DBCampo("Tipo").ToString();
e.Row.CssClass = string.Format("Tipo{0}", tipo);
}
}
protected void BtnConsultar_Click(object sender, EventArgs e)
{
RfechaFin = TxtFechaFin.Text.Length > 9 ? TxtFechaFin.Text.ToDate().ToString("yyyyMMdd") : "";
RfechaInicio = TxtFechaInicio.Text.Length > 9 ? TxtFechaInicio.Text.ToDate().ToString("yyyyMMdd") : "";
RCveDepartamento = DdlDepartamento.SelectedValue.ToEntero();
RcveSubProyecto = DdlSubProyecto.SelectedValue.ToEntero();
CargaInversionNominaGET();
}
protected void LnkExportarEXcel_Click(object sender, EventArgs e)
{
DataTable DtMovimientos = new DataTable();
List<ReportParameter> parametross = new List<ReportParameter>();
parametross.Add(new ReportParameter("Empresa", UsuarioActual.Empresa.Empresa));
using (ClsNominas ObjPA_N = new ClsNominas())
{
ObjPA_N.GetInversionNomina(UsuarioActual.CveEmpresa, RfechaInicio, RfechaFin, RcveProyecto, RcveSubProyecto, Ragrupador, RCveDepartamento, RcveStr1, RcveStr2);
DtMovimientos = ObjPA_N.DtResultados;
}
ImprimirPDF("Empresas/Grales/RepInversionNomina.rdlc", DtMovimientos, parametross, String.Format("Reporte de Inversión de Nómina {0}", ""), "Excel", "DsInventarios", null);
}
protected void LnkExportarPDF_Click(object sender, EventArgs e)
{
DataTable DtMovimientos = new DataTable();
List<ReportParameter> parametross = new List<ReportParameter>();
parametross.Add(new ReportParameter("Empresa", UsuarioActual.Empresa.Empresa));
using (ClsNominas ObjPA_N = new ClsNominas())
{
ObjPA_N.GetInversionNomina(UsuarioActual.CveEmpresa, RfechaInicio, RfechaFin, RcveProyecto, RcveSubProyecto, Ragrupador, RCveDepartamento, RcveStr1, RcveStr2);
DtMovimientos = ObjPA_N.DtResultados;
}
ImprimirPDF("Empresas/Grales/RepInversionNomina.rdlc", DtMovimientos, parametross, String.Format("Reporte de Inversión de Nómina {0}", ""), "PDF", "DsInventarios", null);
}
}
//public class ClsNominasZ : IDisposable
//{
// #region CLASE
// // SQL ClsNominas_Nominas
// private SqlConnection SqlConexion;
// private SqlDataAdapter SqlAdapter;
// private SqlCommand SqlCommand;
// private SqlTransaction SqlTransacc;
// private DataTable Data;
// private bool disposedValue = false; // Para detectar llamadas redundantes
// protected DataSet DTSet;
// public DataSet DTSetResultados
// {
// get
// {
// return DTSet;
// }
// } // REGISTRAR CONEXIONES ABIERTAS
// private int CveConexion = 0;
// public int CveNomina { get; set; }
// public int CveNominaTipo { get; set; }
// public string FolioFiscal { get; set; }
// public string Serie { get; set; }
// public int Folio { get; set; }
// public string RegistroPatronal { get; set; }
// public string SerieFolio { get; set; }
// public string NominaFolio { get; set; }
// public double DiasPagados { get; set; }
// public double SubTotal { get; set; }
// public double Descuento { get; set; }
// public double RetISR { get; set; }
// public double Total { get; set; }
// public string FormaPago { get; set; }
// public DateTime Fecha { get; set; }
// public string MotivoDescuento { get; set; }
// public string EnvioMail { get; set; }
// public string SeTimbro { get; set; }
// public int CvePeriodo { get; set; }
// // Public Property TipoPeriodo As String
// public int CvePersonal { get; set; }
// public string Codigo { get; set; }
// public string Nombre { get; set; }
// public string RFC { get; set; }
// public int CveMetodoPago { get; set; }
// public string MetodoPago { get; set; }
// public int CveEstatusCFDi { get; set; }
// public string EstatusCFDi { get; set; }
// public int CveUsuario { get; set; }
// public string Usuario { get; set; }
// public int CveEmpresa { get; set; }
// public DataTable DtResultados
// {
// get
// {
// return Data;
// }
// }
// public int CveTipoPeriodo { get; set; }
// public string TipoPeriodo { get; set; }
// public int Ejercicio { get; set; }
// public int Mes { get; set; }
// public int Numero { get; set; }
// public DateTime FechaInicio { get; set; }
// public DateTime FechaFin { get; set; }
// public bool EsInicioMes { get; set; }
// public bool EsFinMes { get; set; }
// public bool EsInicioSS { get; set; }
// public bool EsFinSS { get; set; }
// public bool EsInicioAño { get; set; }
// public bool EsFinAño { get; set; }
// public bool FueCalculado { get; set; }
// public int Estatus { get; set; }
// public int NumPeriodo { get; set; }
// public DateTime FechaIng { get; set; }
// public DateTime FechaPago { get; set; }
// public void IniciaTransacSQL()
// {
// SqlTransacc = SqlConexion.BeginTransaction();
// }
// public void Commit()
// {
// SqlTransacc.Commit();
// }
// public void RollBack()
// {
// SqlTransacc.Rollback();
// }
// public ClsNominasZ()
// {
// SqlConexion = new SqlConnection();
// SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
// SqlAdapter = new SqlDataAdapter("", SqlConexion);
// try
// {
// SqlConexion.Open();
// }
// catch (Exception ex)
// {
// this.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex);
// }
// ConexionAdd();
// }
// public ClsNominasZ(SqlTransaction TransaccionCompartida = null)
// {
// if (TransaccionCompartida == null)
// {
// SqlConexion = new SqlConnection();
// SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
// try
// {
// SqlConexion.Open();
// }
// catch (Exception ex)
// {
// this.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex);
// }
// }
// else
// {
// SqlConexion = TransaccionCompartida.Connection;
// SqlTransacc = TransaccionCompartida;
// }
// SqlAdapter = new SqlDataAdapter("", SqlConexion);
// ConexionAdd();
// }
// private void DataAdapter(string pStrSQL, CommandType TipoComando = CommandType.StoredProcedure)
// {
// {
// var withBlock = SqlAdapter.SelectCommand;
// withBlock.Parameters.Clear();
// withBlock.CommandText = pStrSQL;
// withBlock.CommandType = TipoComando;
// }
// Data = new DataTable();
// if (SqlTransacc != null)
// SqlAdapter.SelectCommand.Transaction = SqlTransacc;
// }
// private void ConexionAdd()
// {
// if (ConfigurationManager.AppSettings["RegistraConexion"] != null && ConfigurationManager.AppSettings["RegistraConexion"].ToString() == "1")
// {
// try
// {
// DataAdapter("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(Data);
// 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")
// {
// DataAdapter(string.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text);
// try
// {
// SqlAdapter.Fill(Data);
// }
// catch (Exception ex)
// {
// this.OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
// }
// CveConexion = 0;
// }
// }
// #endregion
// public bool GetInversionNomina(int CveEmpresa, string FechaInicio = "", string FechaFin = "", int CveProyecto = -1, int CveSubProyecto = -1, int Agrupador = -1, int CveDepartamento = -1, string CveStr1 = "-1", string CveStr2 = "-1")
// {
// bool Retorno = false;
// DataAdapter("PA_Nom_InversionNominaGET");
// {
// var withBlock = SqlAdapter.SelectCommand.Parameters;
// withBlock.Add("FechaInicio", SqlDbType.VarChar).Value = FechaInicio;
// withBlock.Add("FechaFin", SqlDbType.VarChar).Value = FechaFin;
// withBlock.Add("CveProyecto", SqlDbType.Int).Value = CveProyecto;
// withBlock.Add("CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto;
// withBlock.Add("Agrupador", SqlDbType.Int).Value = Agrupador;
// withBlock.Add("CveDepartamento", SqlDbType.Int).Value = CveDepartamento;
// withBlock.Add("CveStr1", SqlDbType.VarChar).Value = CveStr1;
// withBlock.Add("CveStr2", SqlDbType.VarChar).Value = CveStr2;
// withBlock.Add("CveEmpresa", SqlDbType.Int).Value = CveEmpresa;
// }
// try
// {
// DTSet = new DataSet();
// SqlAdapter.Fill(DTSet);
// Data = DTSet.Tables[0];
// Retorno = true;
// }
// catch (SqlException Ex1)
// {
// this.OnError("Ocurrió un error al obtener el reporte de inversión de nomina.", Ex1, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
// }
// return Retorno;
// }
// // IDisposable
// protected virtual void Dispose(bool disposing)
// {
// if (!disposedValue)
// {
// if (disposing)
// {
// SqlConexion.Close();
// SqlConexion.Dispose();
// if (Data != null)
// Data.Dispose();
// if (SqlAdapter != null)
// SqlAdapter.Dispose();
// if (SqlTransacc != null)
// SqlTransacc.Dispose();
// }
// }
// disposedValue = true;
// }
// public void Dispose()
// {
// ConexionClose();
// Dispose(true);
// GC.SuppressFinalize(this);
// }
//}