using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using RLMemberDBModel;
using System.Reflection;
public partial class Reports_MemberReport : System.Web.UI.Page
{
#region Help methods
public DataTable LINQToDataTable<t>(IEnumerable<t> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null; //using System.Reflection;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
#endregion help methods
protected void Page_Load(object sender, EventArgs e)
{
//if (Session["CurrentUser"] == null)
//{
// Response.Redirect("~/LoginForm.aspx");
//}
}
protected void btnPreview_Click(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
DataTable dtable = new DataTable();
RLMemberDBEntities db = new RLMemberDBEntities();
Int32 fromid, toid;
////fromid = Convert.ToInt32(cboFromMember.SelectedValue);
////toid = Convert.ToInt32(cboToPartner.SelectedValue);
var member = from table in db.vw_MembersReport
//where (table.CUS_CARD_ID >= fromid && table.PartnerID <= toid)
//orderby
select new { table.CUS_CARD_ID, table.CU_ACNT_NUM, table.CUST_FRST_NM, table.ENC_CTZ_CORP_NUM, table.CUST_TYP_CD, table.BIRTH_DT, table.Member_Type, table.ISS_DATE,table.VLD_DATE };
DataTable dt = new DataTable();
dt = LINQToDataTable(member);
var service = from servicetable in db.CUS_SERVICE
//where (servicetable.CU_ACNT_NUM == fromid)
select new { servicetable.CUS_SRV_ACNT, servicetable.CU_ACNT_NUM, servicetable.SVR_PLAN, servicetable.ATV_DATE };
DataTable dtsub = new DataTable();
dtsub = LINQToDataTable(service);
//dtable = departmentcontroller.DepartmentListReport(cboFromDepartment.SelectedValue, cboToDepartment.SelectedValue);
rptDoc.Load(Server.MapPath("~\\Reports\\Member18Sep.rpt"));
rptDoc.SetDataSource(dt);
rptDoc.OpenSubreport("subServicePlan").SetDataSource(dtsub);
rptDoc.SetParameterValue("ReportTitle", "Members List Report");
//rptDoc.SetParameterValue("From", cboFromPartner.SelectedItem.Text);
//rptDoc.SetParameterValue("To", cboToPartner.SelectedItem.Text);
Session["Report"] = rptDoc;
//CrystalReportViewer1.ReportSource = rptDoc;
ClientScript.RegisterStartupScript(this.GetType(), "key", "window.open('LargeSizeViewer.aspx');", true);
}
}