public ActionResult Export(CustReportModel custReportModel) { var table = _GetHtmlStr(custReportModel); return new DownloadFileActionResult(table, "ExportedRecords.xls"); }
public string _GetHtmlStr(CustReportModel custReportModel) { try { var reportDetialList = genericMgr.FindAll<CustReportDetail>("from CustReportDetail As c where c.Code=? ", custReportModel.Code); CustReportMaster CustReportMst = genericMgr.FindById<CustReportMaster>(custReportModel.Code); PropertyInfo[] myPropertyInfo = typeof(CustReportModel).GetProperties(BindingFlags.Public | BindingFlags.Instance); var dic = new Dictionary<string, string>(); for (int i = 0, j = myPropertyInfo.Length; i < j; i++) { System.Reflection.PropertyInfo pi = myPropertyInfo[i]; dic.Add(pi.Name, pi.GetValue(custReportModel, null) == null ? "" : pi.GetValue(custReportModel, null).ToString().Trim()); } string sql = CustReportMst.Sql; SqlParameter[] sqlParams = new SqlParameter[reportDetialList.Count]; for (int i = 0; i < reportDetialList.Count; i++) { sqlParams[i] = new SqlParameter("@" + reportDetialList[i].ParamKey, dic.ValueOrDefault(reportDetialList[i].ParamType)); } return GetTableHtmlBySql(sql, sqlParams); } catch (Exception e) { return "Error:"+e.Message; } }