public GridReportInfo GenerateReport(Ctx _ctx, int id, List <string> queryInfo, Object code, bool isCreateNew, Dictionary <string, string> nProcessInfo, int pageNo, int AD_PInstance_ID, string fileType, int?nodeID, int?treeID, bool showSummary) { GridReportInfo res = new GridReportInfo(); VIS.Models.PageSetting ps = new Models.PageSetting(); parentIDs.Clear(); ProcessReportInfo rep = null; ReportEngine_N re = null; Query _query = null; int Record_ID = 0; object AD_tab_ID = 0; // _ctx.SetContext("#TimeZoneName", "India Standard Time"); if (queryInfo.Count > 0 || AD_PInstance_ID > 0) { string tableName = queryInfo[0]; if (AD_PInstance_ID > 0) { if ((code).GetType() == typeof(int)) // Form = one record { _query = Query.GetEqualQuery(tableName, ((int)code)); } else { _query = Query.Get(_ctx, AD_PInstance_ID, tableName); } } else { string wherClause = queryInfo[1]; _query = new Query(tableName); if (!string.IsNullOrEmpty(wherClause)) { _query.AddRestriction(wherClause); } } if (_query.GetRestrictionCount() == 1 && (code).GetType() == typeof(int)) { Record_ID = ((int)code); } if (nodeID > 0) { GetChildNodesID(_ctx, Convert.ToInt32(nodeID), Convert.ToInt32(treeID)); MTree tree = new MTree(_ctx, Convert.ToInt32(treeID), null); string nodeTableName = tree.GetNodeTableName(); _query.AddRestriction(" " + tableName + "." + tableName + "_ID IN (SELECT NODE_ID FROM " + nodeTableName + " WHERE Parent_ID IN (" + parentIDs.ToString() + ") OR NODE_ID IN (" + parentIDs + ")) "); if (!showSummary) { _query.AddRestriction(" " + tableName + "." + "IsSummary= 'N'"); } } } else { if (nodeID > 0) { MTree tree = new MTree(_ctx, Convert.ToInt32(treeID), null); string tableName = MTable.GetTableName(_ctx, tree.GetAD_Table_ID()); _query = new Query(tableName); GetChildNodesID(_ctx, Convert.ToInt32(nodeID), Convert.ToInt32(treeID)); string nodeTableName = tree.GetNodeTableName(); _query.AddRestriction(" " + tableName + "." + tableName + "_ID IN (SELECT NODE_ID FROM " + nodeTableName + " WHERE Parent_ID IN (" + parentIDs.ToString() + ")) "); if (!showSummary) { _query.AddRestriction(" " + tableName + "." + "IsSummary= 'N'"); } } } if (_query == null) { _query = new Query(); _query.AddRestriction(" 1 = 1"); } if (queryInfo.Count > 2) { if (queryInfo[2] != null && queryInfo[2] != "" && Convert.ToInt32(queryInfo[2]) > 0) { AD_tab_ID = Convert.ToInt32(queryInfo[2]); } } //Context _ctx = new Context(ctxDic); //Env.SetContext(_ctx); string lang = _ctx.GetAD_Language().Replace("_", "-"); System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(lang); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang); byte[] b = null; try { MPrintFormat pf = null; if (!isCreateNew) { bool isPFExist = Util.GetValueOfInt(DB.ExecuteScalar("SELECT Count(*) FROM AD_PrintFormat WHERE AD_PrintFormat_ID=" + id)) > 0; if (isPFExist) { pf = MPrintFormat.Get(_ctx, id, true); } else { rep = new ProcessReportInfo(); rep.ErrorText = "NoDocPrintFormat"; res.repInfo = rep; return(res); } } else { // pf = MPrintFormat.CreateFromTable(_ctx, id); if (Convert.ToInt32(AD_tab_ID) > 0) { pf = MPrintFormat.CreateFromTable(_ctx, id, AD_tab_ID, true); } else { pf = MPrintFormat.CreateFromTable(_ctx, id, true); } } pf.IsGridReport = true; pf.PageNo = pageNo; rep = new ProcessReportInfo(); pf.SetName(Env.TrimModulePrefix(pf.GetName())); if (nProcessInfo == null || pageNo > 0 || (Util.GetValueOfInt(nProcessInfo["Record_ID"]) == 0 && Util.GetValueOfInt(nProcessInfo["Process_ID"]) == 0 && Util.GetValueOfInt(nProcessInfo["AD_PInstance_ID"]) == 0)) { PrintInfo info = new PrintInfo(pf.GetName(), pf.GetAD_Table_ID(), Record_ID); info.SetDescription(_query == null ? "" : _query.GetInfo()); re = new ReportEngine_N(_ctx, pf, _query, info); } else { ProcessInfo pi = new ProcessInfo().FromList(nProcessInfo); pi.Set_AD_PrintFormat_ID(id); ProcessCtl ctl = new ProcessCtl(); ctl.Process(pi, _ctx, out b, out re); re.SetPrintFormat(pf); } lock (_lock) { re.GetView(); if (fileType == ProcessCtl.ReportType_PDF) { rep.ReportFilePath = re.GetReportFilePath(true, out b); } else if (fileType == ProcessCtl.ReportType_CSV) { rep.ReportFilePath = re.GetCSVPath(_ctx); } else { rep.ReportFilePath = re.GetReportFilePath(true, out b); rep.HTML = re.GetRptHtml().ToString(); rep.AD_PrintFormat_ID = re.GetPrintFormat().GetAD_PrintFormat_ID(); rep.ReportProcessInfo = null; rep.Report = re.CreatePDF(); } } ps.TotalPage = pf.TotalPage; ps.CurrentPage = pageNo; // b = re.CreatePDF(); //rep.Report = b; //rep.HTML = re.GetRptHtml().ToString(); //rep.AD_PrintFormat_ID = re.GetPrintFormat().GetAD_PrintFormat_ID(); //rep.ReportProcessInfo = null; } catch (Exception ex) { rep.IsError = true; rep.ErrorText = ex.Message; log.Severe("ReportEngine_N_CreatePDF_" + ex.ToString()); } // VAdvantage.Classes.CleanUp.Get().Start(); res.repInfo = rep; res.pSetting = ps; return(res); }
public static ProcessReportInfo GenerateReport(Ctx _ctx, int id, List <string> queryInfo, Object code, bool isCreateNew, Dictionary <string, object> nProcessInfo, bool pdf, bool csv) { ProcessReportInfo rep = null; ReportEngine_N re = null; Query _query = null; int Record_ID = 0; object AD_tab_ID = 0; // _ctx.SetContext("#TimeZoneName", "India Standard Time"); if (queryInfo.Count > 0) { string tableName = queryInfo[0]; string wherClause = queryInfo[1]; _query = new Query(tableName); if (!string.IsNullOrEmpty(wherClause)) { _query.AddRestriction(wherClause); } if (_query.GetRestrictionCount() == 1 && (code).GetType() == typeof(int)) { Record_ID = ((int)code); } } if (queryInfo.Count > 2) { if (queryInfo[2] != null && queryInfo[2] != "" && Convert.ToInt32(queryInfo[2]) > 0) { AD_tab_ID = Convert.ToInt32(queryInfo[2]); } } //Context _ctx = new Context(ctxDic); //Env.SetContext(_ctx); string lang = _ctx.GetAD_Language().Replace("_", "-"); System.Globalization.CultureInfo original = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(lang); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang); byte[] b = null; try { MPrintFormat pf = null; if (!isCreateNew) { pf = MPrintFormat.Get(_ctx, id, true); } else { // pf = MPrintFormat.CreateFromTable(_ctx, id); if (Convert.ToInt32(AD_tab_ID) > 0) { pf = MPrintFormat.CreateFromTable(_ctx, id, AD_tab_ID); } else { pf = MPrintFormat.CreateFromTable(_ctx, id); } } rep = new ProcessReportInfo(); pf.SetName(Env.TrimModulePrefix(pf.GetName())); if (nProcessInfo == null) { PrintInfo info = new PrintInfo(pf.GetName(), pf.GetAD_Table_ID(), Record_ID); info.SetDescription(_query == null ? "" : _query.GetInfo()); re = new ReportEngine_N(_ctx, pf, _query, info); } else { ProcessInfo pi = new ProcessInfo().FromList(nProcessInfo); pi.Set_AD_PrintFormat_ID(id); ProcessCtl ctl = new ProcessCtl(); ctl.Process(pi, _ctx, out b, out re); re.SetPrintFormat(pf); } re.GetView(); if (pdf) { rep.ReportFilePath = re.GetReportFilePath(true, out b); } else if (csv) { rep.ReportFilePath = re.GetCSVPath(_ctx); } else { rep.HTML = re.GetRptHtml().ToString(); rep.AD_PrintFormat_ID = re.GetPrintFormat().GetAD_PrintFormat_ID(); rep.ReportProcessInfo = null; rep.Report = re.CreatePDF(); } // b = re.CreatePDF(); //rep.Report = b; //rep.HTML = re.GetRptHtml().ToString(); //rep.AD_PrintFormat_ID = re.GetPrintFormat().GetAD_PrintFormat_ID(); //rep.ReportProcessInfo = null; } catch (Exception ex) { rep.IsError = true; rep.ErrorText = ex.Message; } return(rep); }