using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using Extensiones; using Microsoft.Reporting.WebForms; using System.Text; using System.Globalization; using System.IO; public partial class Compras_RepGastosFijos : ClsPaginas { #region "PROPIEDADES" private DataTable DTDatos { get { return (DataTable)ViewState["DTDatos"]; } set { ViewState["DTDatos"] = value; } } private String FechaInicio { get { return ViewState["FechaInicio"].ToString(); } set { ViewState["FechaInicio"] = value; } } private String FechaFin { get { return ViewState["FechaFin"].ToString(); } set { ViewState["FechaFin"] = value; } } private int CveEvento { get { return ViewState["CveEvento"].ToString().ToEntero(); } set { ViewState["CveEvento"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InicializaDatos(); CargaDatos(); } } #region "CARGA DATOS" protected void CargaDatos() { FechaInicio = TxtFechaI.Text; FechaFin = TxtFechaF.Text; ClsOIEventos ObjEventos = new ClsOIEventos(); if (ObjEventos.GetGastoMensual(FechaInicio, FechaFin, UsuarioActual.CveEmpresa, -1, -1, -1)) { DTDatos = ObjEventos.DtResultados; GVDatos.DataSource = DTDatos; } GVDatos.DataBind(); ObjEventos.Dispose(); UPDatos.Update(); } protected void InicializaDatos() { DateTime FI = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime FF = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); FechaInicio = FI.ToShortDateString(); FechaFin = FF.ToShortDateString(); TxtFechaI.Text = FechaInicio; TxtFechaF.Text = FechaFin; } protected void BtnConsultar_Click(object sender, EventArgs e) { CargaDatos(); } protected void GVDatos_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataKey("CveEvento") == "") { e.Row.CssClass = "SubTotales"; e.Row.FCLinkButton("LnkEditar").Visible = false; } } } #endregion #region "AGREGAR / EDITAR GASTO" protected void BtnGuardarGasto_Click(object sender, EventArgs e) { ClsOIEventos ObjEventos = new ClsOIEventos(); int CveTipoEvento = 10; DateTime FechaInicio = string.Format("{2}/{1}/{0} 12:00:00 AM", (TxtFechaInicio.Text.ToDateTime()).Year, (TxtFechaInicio.Text.ToDateTime()).Month, (TxtFechaInicio.Text.ToDateTime()).Day).ToDateTime(); DateTime FechaFin = string.Format("{2}/{1}/{0} 13:00:00 PM", (TxtFechaInicio.Text.ToDateTime()).Year, (TxtFechaInicio.Text.ToDateTime()).Month, (TxtFechaInicio.Text.ToDateTime()).Day).ToDateTime(); //Recurrencia 4 = Mensual int RecurrenciaTipo = 4; int Frecuencia = 1; var Mes = 1; DateTime RecurrenciaFin = TxtFechaFinRecurrencia.Text.ToDate(); double Importe = TxtGastoImporte.Text.ToDouble(); if (CveEvento == -1) { if (ObjEventos.AddEventoAgenda(5, TxtAsunto.Text, TxtDescripcion.Text, DdlPrioridad.SelectedValue.ToEntero(), FechaInicio, FechaFin, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, RecurrenciaTipo: RecurrenciaTipo, Frecuencia: Frecuencia, Mes: Mes, RecurrenciaFin: RecurrenciaFin.ToString(), CveTipoEvento: CveTipoEvento, Importe: Importe)) { LimpiaModal(); this.RegistraScript("$('#DvModalGasto').modal('hide');"); Alert("El Evento Gasto Mensual se guardó correctamente", ModExtensiones.TipoMensaje.MsgInformacion); } } else { if (ObjEventos.UpdateEvento( TxtAsunto.Text, TxtDescripcion.Text, DdlPrioridad.SelectedValue.ToEntero(), 5,-1, FechaInicio, FechaFin, -1, "-1", CveEvento, RecurrenciaTipo: RecurrenciaTipo, Frecuencia: Frecuencia, Mes: Mes, RecurrenciaFin: RecurrenciaFin.ToString(), Importe: Importe)) { LimpiaModal(); this.RegistraScript("$('#DvModalGasto').modal('hide');"); Alert("El Evento Gasto Mensual se ha Actualizado correctamente", ModExtensiones.TipoMensaje.MsgInformacion); } } ObjEventos.Dispose(); CargaDatos(); } protected void LimpiaModal() { CveEvento = -1; TxtAsunto.Text = ""; TxtDescripcion.Text = ""; TxtFechaInicio.Text = ""; DdlPrioridad.SelectedValueExist("1"); TxtFechaFinRecurrencia.Text = ""; TxtGastoImporte.Text = ""; } protected void LnkAgregarGasto_Click(object sender, EventArgs e) { LimpiaModal(); UPModalGasto.Update(); this.RegistraScript("$('#DvModalGasto').modal();"); } protected void LnkEditar_Click(object sender, EventArgs e) { GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); CveEvento = GvRow.DataKey("CveEvento").ToEntero(); TxtAsunto.Text = GvRow.DataKey("Asunto"); TxtFechaInicio.Text = GvRow.DataKey("FechaInicio"); TxtDescripcion.Text = GvRow.DataKey("Descripcion"); DdlPrioridad.SelectedValueExist("Prioridad"); TxtFechaFinRecurrencia.Text = GvRow.DataKey("FechaFinRecurrencia"); String ImporteString = String.Format("{0:c}", GvRow.DataKey("Importe").ToDouble()); TxtGastoImporte.Text = ImporteString; UPModalGasto.Update(); this.RegistraScript("$('#DvModalGasto').modal();"); } #endregion #region "REPORTE" protected void LnkImprimirPDF_Click(object sender, EventArgs e) { ImprimiReporte(); } protected void ImprimiReporte(string Formato = "PDF") { string FechaInicio = DateTime.Parse(TxtFechaI.Text).ToShortDateString(); string FechaFinal = DateTime.Parse(TxtFechaF.Text).ToShortDateString(); string Ruta = string.Format("{0}Empresas/{1}/", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa); string RutaPDF = string.Format("{0}/Formatos/RepGastosFijos.rdlc", Ruta); if (!File.Exists(RutaPDF)) { RutaPDF = "Empresas/Grales/Formatos/RepGastosFijos.rdlc"; } var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa); System.IO.FileInfo Imagen = new System.IO.FileInfo(string.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)); List @params = new List(); @params.Add(new ReportParameter("pImg", new Uri(Server.MapPath(string.Format("~/Empresas/{0}/Logo.png", UsuarioActual.CveEmpresa))).AbsoluteUri)); @params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)); @params.Add(new ReportParameter("FechaInicio", FechaInicio)); @params.Add(new ReportParameter("FechaFin", FechaFinal)); @params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)); @params.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString())); if (Imagen.Exists) { @params.Add(new ReportParameter("LogoPath", logouri)); } else { @params.Add(new ReportParameter("LogoPath", "")); } ImprimirPDF(RutaPDF, DTDatos, @params, "RepGastosFijos " + DateTime.Now.ToString("yyyy-MM-dd"), Formato); } #endregion }