public Dictionary <string, object> Process(ProcessInfo pi, Ctx ctx, out byte[] report, out string reportFilePath) { reportFilePath = null; _ctx = ctx; _pi = pi; report = null; MPInstance instance = null; if (_pi.GetAD_PInstance_ID() < 1) { try { instance = new MPInstance(ctx, _pi.GetAD_Process_ID(), _pi.GetRecord_ID()); } catch (Exception e) { _pi.SetSummary(e.Message); _pi.SetError(true); return(_pi.ToList()); } if (!instance.Save()) { _pi.SetSummary(Msg.GetMsg(ctx, "ProcessNoInstance", true)); _pi.SetError(true); return(_pi.ToList()); } _pi.SetAD_PInstance_ID(instance.Get_ID()); } String procedureName = ""; int AD_ReportView_ID = 0; int AD_ReportFormat_ID = 0; int AD_Workflow_ID = 0; bool IsReport = false; bool IsDirectPrint = false; bool IsCrystalReport = false; String sql = "SELECT p.Name, p.procedureName,p.Classname, p.AD_Process_ID," // 1..4 + " p.IsReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8 + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END," //9 + " p.IsServerProcess, " //10 + " p.IsCrystalReport, " // crystal 11...12 + " p.AD_ReportFormat_ID " //12 + " FROM AD_Process p" + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) " + " WHERE p.IsActive='Y'" + " AND i.AD_PInstance_ID=@pinstanceid"; IDataReader dr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@pinstanceid", _pi.GetAD_PInstance_ID()); dr = SqlExec.ExecuteQuery.ExecuteReader(sql, param); while (dr.Read()) { _pi.SetTitle(dr[0].ToString()); //if (m_waiting != null) // m_waiting.setTitle(_pi.getTitle()); procedureName = dr[1].ToString(); _pi.SetClassName(dr[2].ToString()); _pi.SetAD_Process_ID(Utility.Util.GetValueOfInt(dr[3].ToString())); // Report if ("Y".Equals(dr[4].ToString())) { IsReport = true; IsCrystalReport = "Y".Equals(dr[10].ToString()); AD_ReportFormat_ID = dr[11].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[11].ToString()); //later } AD_ReportView_ID = dr[6].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[6].ToString()); AD_Workflow_ID = dr[7].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[7].ToString()); // //_IsServerProcess = "Y".Equals(dr[9].ToString()); } dr.Close(); } catch (Exception ex) { if (dr != null) { dr.Close(); } _pi.SetSummary(Msg.GetMsg(ctx, "ProcessNoProcedure") + " " + ex.Message, true); Unlock(); } if (procedureName == null) { procedureName = ""; } if (AD_Workflow_ID > 0) { StartWorkflow(AD_Workflow_ID); //Updated by raghu to open reports from work flow byte[] repByt = null; re = ReportCtl.Report; if (re != null) { int reportTable_ID = 0; if (re is IReportView) { IReportView irv = re as IReportView; reportTable_ID = irv.GetPrintFormat().GetAD_Table_ID(); irv.GetView(); _pi.Set_AD_PrintFormat_Table_ID(irv.GetPrintFormat().GetAD_Table_ID()); } _pi.SetSummary("Report", re != null); Unlock(); if (re != null) { reportFilePath = re.GetReportFilePath(true, out repByt); } } else { repByt = null; } report = repByt; return(_pi.ToList()); } if (_pi.GetClassName() != null) { if (!StartProcess()) { report = null; return(_pi.ToList()); } if (!IsReport && procedureName.Length == 0) { report = null; return(_pi.ToList()); } } report = null; if (IsReport) { if (procedureName.Length > 0) { if (!StartDBProcess(procedureName)) { } } if (AD_ReportFormat_ID > 0) // For Report Formats { _pi.SetIsReportFormat(true); int totalRecords = 0; re = VAdvantage.ReportFormat.ReportFormatEngine.Get(_ctx, _pi, out totalRecords, IsArabicReportFromOutside); Unlock(); _pi.SetSummary("Report", re != null); _pi.SetTotalRecords(totalRecords); if (re != null) { //isRCReport = true; if (GetIsPrintCsv()) { string s = ""; reportFilePath = re.GetCsvReportFilePath(s); } else { report = re.GetReportBytes(); reportFilePath = re.GetReportFilePath(true, out report); } ReportString = re.GetReportString(); } } else if (!IsCrystalReport) { //start report code // Start Report ----------------------------------------------- re = ReportCtl.Start(_ctx, _pi, IsDirectPrint); ReportEngine_N _rep = (ReportEngine_N)re; //null check Implemented by raghu 22-May-2015 if (_rep != null) { reportTable_ID = _rep.GetPrintFormat().GetAD_Table_ID(); _rep.GetView(); _pi.Set_AD_PrintFormat_Table_ID(_rep.GetPrintFormat().GetAD_Table_ID()); _pi.Set_AD_PrintFormat_ID(_rep.GetPrintFormat().GetAD_PrintFormat_ID()); _pi.SetSummary("Report", re != null); Unlock(); if (GetIsPrintFormat() && re != null && !GetIsPrintCsv()) { reportFilePath = re.GetReportFilePath(true, out report); } else if (GetIsPrintCsv() && re != null) { report = _rep.CreateCSV(_ctx); string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "TempDownload"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } filePath = filePath + "\\temp_" + CommonFunctions.CurrentTimeMillis() + ".csv"; File.WriteAllBytes(filePath, report); reportFilePath = filePath.Substring(filePath.IndexOf("TempDownload")); } else { rptHtml = _rep.GetRptHtml().ToString(); } report = _rep.CreatePDF(); } } else { _pi.SetIsCrystal(true); string errorMsg = null; CrystalReportEngine en = null; try { en = new CrystalReportEngine(_ctx, _pi); reportFilePath = en.GetReportFilePath(true, out report);// .GenerateCrystalReport(); } catch (Exception err) { errorMsg = err.Message; } _pi.SetSummary(errorMsg ?? "Done", errorMsg != null); } } else { if (!StartDBProcess(procedureName)) { _pi.SetSummary("procedure ERROR"); return(_pi.ToList()); } ProcessInfoUtil.SetSummaryFromDB(_pi); } return(_pi.ToList()); }
public void Run() { log.Fine("AD_PInstance_ID=" + _pi.GetAD_PInstance_ID() + ", Record_ID=" + _pi.GetRecord_ID()); Lock(); // Get Process Information: Name, Procedure Name, ClassName, IsReport, IsDirectPrint String procedureName = ""; int AD_ReportView_ID = 0; int AD_Workflow_ID = 0; bool IsReport = false; bool IsDirectPrint = false; // String sql = "SELECT p.Name, p.procedureName,p.Classname, p.AD_Process_ID," // 1..4 + " p.IsReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8 + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END," + " p.IsServerProcess " + "FROM AD_Process p" + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) " + "WHERE p.IsActive='Y'" + " AND i.AD_PInstance_ID=@pinstanceid"; if (!Utility.Env.IsBaseLanguage(_ctx, "AD_Process")) // GlobalVariable.IsBaseLanguage()) { sql = "SELECT t.Name, p.procedureName,p.Classname, p.AD_Process_ID," // 1..4 + " p.IsReport, p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8 + " CASE WHEN COALESCE(p.Statistic_Count,0)=0 THEN 0 ELSE p.Statistic_Seconds/p.Statistic_Count END CASE," + " p.IsServerProcess " + "FROM AD_Process p" + " INNER JOIN AD_PInstance i ON (p.AD_Process_ID=i.AD_Process_ID) " + " INNER JOIN AD_Process_Trl t ON (p.AD_Process_ID=t.AD_Process_ID" + " AND t.AD_Language='" + Utility.Env.GetAD_Language(_ctx) + "') " + "WHERE p.IsActive='Y'" + " AND i.AD_PInstance_ID=@pinstanceid"; } // IDataReader dr = null; try { SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@pinstanceid", _pi.GetAD_PInstance_ID()); dr = SqlExec.ExecuteQuery.ExecuteReader(sql, param); while (dr.Read()) { _pi.SetTitle(dr[0].ToString()); //if (m_waiting != null) // m_waiting.setTitle(_pi.getTitle()); procedureName = dr[1].ToString(); _pi.SetClassName(dr[2].ToString()); _pi.SetAD_Process_ID(Utility.Util.GetValueOfInt(dr[3].ToString())); // Report if ("Y".Equals(dr[4].ToString())) { IsReport = true; if ("Y".Equals(dr[5].ToString()) && !Ini.IsPropertyBool(Ini.P_PRINTPREVIEW)) { IsDirectPrint = true; } } AD_ReportView_ID = dr[6].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[6].ToString()); AD_Workflow_ID = dr[7].ToString() == "" ? 0 : Utility.Util.GetValueOfInt(dr[7].ToString()); // _IsServerProcess = "Y".Equals(dr[9].ToString()); } dr.Close(); } catch (SqlException ex) { if (dr != null) { dr.Close(); } _pi.SetSummary(Msg.GetMsg(_ctx, "ProcessNoProcedure") + " " + ex.Message, true); Unlock(); log.Log(Level.SEVERE, "run", ex); return; } finally { if (dr != null) { dr.Close(); } } if (procedureName == null) { procedureName = ""; } if (AD_Workflow_ID > 0) { StartWorkflow(AD_Workflow_ID); re = ReportCtl.Report; Unlock(); return; } if (_pi.GetClassName() != null) { if (!StartProcess()) { Unlock(); return; } if (!IsReport && procedureName.Length == 0) { Unlock(); return; } if (IsReport && AD_ReportView_ID == 0) { Unlock(); return; } } // If not a report, we need a prodedure name if (!IsReport && procedureName.Length == 0) { _pi.SetSummary(Msg.GetMsg(_ctx, "ProcessNoProcedure", true)); Unlock(); return; } if (IsReport) { if (procedureName.Length > 0) { if (!StartDBProcess(procedureName)) { Unlock(); return; } } //start report code // Start Report ----------------------------------------------- re = ReportCtl.Start(_ctx, _pi, IsDirectPrint); _pi.SetSummary("Report", re != null); Unlock(); if (re != null && IsDirectPrint) { re = null; //ve = new Viewer(re); //new ReportDialog(re); } } else { if (!StartDBProcess(procedureName)) { Unlock(); return; } ProcessInfoUtil.SetSummaryFromDB(_pi); Unlock(); } }