using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Extensiones; using System.Data; using Microsoft.Reporting.WebForms; public partial class CRM_RepAcercamientos : ClsPaginas { #region "PROPIEDADES" private int CveVendedor { get { return ViewState["CveVendedor"].ToString().ToEntero(); } set { ViewState["CveVendedor"] = value; } } private DataTable DtDatos { get { return (ViewState["DtDatos"] == null ? null : (DataTable)ViewState["DtDatos"]); } set { ViewState["DtDatos"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InicializaDatos(); CargaDatos(); } } #region "CARGA DATOS" protected void BtnConsultar_Click(object sender, EventArgs e) { CargaDatos(); } protected void CargaDatos() { CveVendedor = DdlVendedor.SelectedValue.ToEntero(); string FechaInicio = TxtFechaInicio.Text == "" ? "-1" : TxtFechaInicio.Text; string FechaFin = TxtFechaFin.Text == "" ? "-1" : TxtFechaFin.Text; int CvePS = DdlPS.SelectedValue.ToEntero() == 0 ? -1 : DdlPS.SelectedValue.ToEntero(); ClsCRM ObjCRM = new ClsCRM(); if (ObjCRM.GetAcercamiento(UsuarioActual.CveEmpresa, CveVendedor: CveVendedor, FechaInicio: FechaInicio, FechaFin: FechaFin, CvePS: CvePS, CveGiroClasificacion:DdlGiroClasificacion.SelectedValue.ToEntero())) { GVDatos.DataSource = ObjCRM.DtResultados; DtDatos = ObjCRM.DtResultados; GVDatos.DataBind(); } ObjCRM.Dispose(); UPDatos.Update(); } protected void GVDatos_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataKey("CveAcercamiento").ToEntero() > 0) e.Row.FCHyperLink("HplNombreAcercamiento").NavigateUrl = String.Format("/CRM/Acercamiento.aspx?CveAcercamiento={0}", e.Row.DataKey("CveAcercamiento")); } } protected void InicializaDatos() { CveVendedor = UsuarioActual.CveVendedor; DdlVendedor.DataSource = get_GlobalDTVendedores(UsuarioActual.CveEmpresa); DdlVendedor.Items.Insert(0, new ListItem("Todos ", "-1")); DdlVendedor.DataBind(); DdlVendedor.SelectedValueExist(CveVendedor); //CALCULAMOS EL INTERVALO DE LA SEMANA ACTUAL TxtFechaInicio.Text = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek) + 1).ToShortDateString(); TxtFechaFin.Text = DateTime.Now.AddDays((7 - (int)DateTime.Now.DayOfWeek)).ToShortDateString(); DdlPS.setEsWebService(true); DdlPS.SelectedValue = "-1"; DdlPS.SelectedText = "Seleccione"; DataTable dtGiroClasificaciones = get_GlobalDTClienteClasificaciones(UsuarioActual.CveEmpresa); DdlGiroClasificacion.DataSource = dtGiroClasificaciones; DdlGiroClasificacion.DataBind(); DdlGiroClasificacion.Items.Insert(0, new ListItem("Seleccione", "-1")); } #endregion protected void LnkPDF_Click(object sender, EventArgs e) { Imprimir("PDF"); } protected void LnkExcel_Click(object sender, EventArgs e) { Imprimir("Excel"); } private void Imprimir(string formato) { string VendedorFiltro = String.Format("Vendedor: {0}    ", (DdlVendedor.SelectedValue != "-1" ? DdlVendedor.SelectedItem.Text : "Todos")); string ProductoServicioFiltro = String.Format("Producto Servicio: {0}    ", (DdlPS.SelectedValue != "-1" ? DdlPS.SelectedText : "Todos")); string GiroFiltro = String.Format("Giro: {0}    ", (DdlGiroClasificacion.SelectedValue != "-1" ? DdlGiroClasificacion.SelectedItem.Text : "Todos")); string FechaInicioFiltro = String.Format("Fecha Inicio: {0}    ", TxtFechaInicio.Text); string FechaFinFiltro = String.Format("Fecha Fin: {0}    ", TxtFechaFin.Text); string Filtros = String.Format("{0}{1}{2}{3}{4}", VendedorFiltro, FechaInicioFiltro, FechaFinFiltro, ProductoServicioFiltro, GiroFiltro); List @params = new List(); @params.Add(new ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)); @params.Add(new ReportParameter("LogoPath", new Uri(Server.MapPath(string.Format("~/Empresas/{0}/Logo.png", UsuarioActual.CveEmpresa))).AbsoluteUri)); @params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Usuario)); @params.Add(new ReportParameter("AgrupadoPor", Filtros)); ImprimirPDF("Empresas/Grales/Formatos/RepAcercamientos.rdlc", DtDatos, @params, "Reporte de Acercamientos", formato); } }