Ejemplo n.º 1
0
        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());
        }
        /// <summary>
        /// Generate Report based on whatever type of report is selected.
        /// </summary>
        /// <param name="_pi"></param>
        public IReportEngine ReportRun(ProcessInfo _pi, Ctx p_ctx, Trx _trx)
        {
            //  start report code
            ///	Start Report	-----------------------------------------------
            ///
            IReportEngine rpe                = null;
            bool          isDocxFile         = false;
            int           AD_ReportFormat_ID = _pi.GetAD_ReportFormat_ID();

            //if("Y".Equals(DB.ExecuteScalar("SELECT IsCrystalReport FROM AD_Process WHERE AD_Process_ID = "+_pi.GetAD_Process_ID())))

            //Dynamic Report
            if (_pi.GetAD_ReportMaster_ID() > 0)
            {
                String  fqClassName = "", asmName = "";
                DataSet ds = DB.ExecuteDataset("SELECT ClassName,AssemblyName FROM AD_ReportMaster WHERE IsActive='Y' AND AD_ReportMaster_ID = " + _pi.GetAD_ReportMaster_ID());
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    fqClassName = ds.Tables[0].Rows[0]["ClassName"].ToString();
                    asmName     = ds.Tables[0].Rows[0]["AssemblyName"].ToString();
                    rpe         = VAdvanatge.Report.ReportEngine.GetReportEngine(p_ctx, _pi, _trx, asmName, fqClassName);
                }
                else
                {
                    VLogger.Get().Warning("Report Engine data not found Error -> InActive record");
                    rpe = null;
                }
            }

            else if (AD_ReportFormat_ID > 0)
            {
                try
                {
                    string lang = p_ctx.GetAD_Language().Replace("_", "-");

                    if ((AD_ReportFormat_ID > 0) && (lang == "ar-IQ"))
                    {
                        isDocxFile = true;
                        rpe        = VAdvantage.ReportFormat.ReportFormatEngine.Get(p_ctx, _pi, true);
                    }
                    else
                    {
                        rpe = VAdvantage.ReportFormat.ReportFormatEngine.Get(p_ctx, _pi, false);
                    }
                }
                catch
                {
                    rpe = null;
                }
            }

            else if (_pi.GetIsCrystal())
            {
                //_pi.SetIsCrystal(true);
                try
                {
                    rpe = new VAdvantage.CrystalReport.CrystalReportEngine(p_ctx, _pi);
                }
                catch
                {
                    rpe = null;
                }
            }
            else
            {
                //If user Choose BI Report...................
                if ("B".Equals(DB.ExecuteScalar("SELECT IsCrystalReport FROM AD_Process WHERE AD_Process_ID = " + _pi.GetAD_Process_ID())))
                {
                    rpe = VAdvanatge.Report.ReportEngine.GetReportEngine(p_ctx, _pi, _trx, "VA039", "VA039.Classes.BIReportEngine");
                }
                else if ("J".Equals(DB.ExecuteScalar("SELECT IsCrystalReport FROM AD_Process WHERE AD_Process_ID = " + _pi.GetAD_Process_ID())))
                {
                    //isJasperReport = true;
                    rpe = VAdvanatge.Report.ReportEngine.GetReportEngine(p_ctx, _pi, _trx, "VA039", "VA039.Classes.JasperReportEngine");
                }
                else
                {
                    rpe = ReportCtl.Start(p_ctx, _pi, true);
                }
            }

            _pi.SetSummary("Report", rpe != null);

            //ReportCtl.Report = re;
            return(rpe);
        }
Ejemplo n.º 3
0
        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();
            }
        }