Exemplo n.º 1
0
        /// <summary>
        /// execute process
        /// - call after parameter dialog window
        /// - first save parameter for Process then execute
        /// </summary>
        /// <param name="AD_Process_ID">id of process</param>
        /// <param name="Name">name of process</param>
        /// <param name="AD_PInstance_ID">process instance id</param>
        /// <param name="AD_Table_ID">table id</param>
        /// <param name="Record_ID">record id</param>
        /// <param name="ParameterList">process parameter list</param>
        /// <returns>json result</returns>
        public JsonResult ExecuteProcess(int AD_Process_ID, string Name, int AD_PInstance_ID, int AD_Table_ID, int Record_ID, ProcessPara[] ParameterList, bool csv, bool pdf)
        {
            string retJSON  = "";
            string retError = null;

            if (Session["ctx"] != null)
            {
                ProcessReportInfo rep = (ProcessHelper.ExecuteProcess(Session["ctx"] as Ctx, AD_Process_ID, Name, AD_PInstance_ID, AD_Table_ID, Record_ID, ParameterList, csv, pdf));
                //rep.HTML=GetHtml(rep.ReportFilePath);
                if (rep.Report != null && (rep.Report.Length > 1048576 || Record_ID > 0) && !csv && !pdf)
                {
                    rep.AskForNewTab = true;
                    string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "TempDownload" + "\\temp_" + DateTime.Now.Ticks + ".pdf";
                    System.IO.File.WriteAllBytes(filePath, rep.Report);
                    rep.ReportFilePath = filePath.Substring(filePath.IndexOf("TempDownload"));
                    rep.HTML           = null;
                    rep.Report         = null;
                }
                retJSON = JsonConvert.SerializeObject(rep);
                //retJSON = JsonConvert.SerializeObject(ProcessHelper.ExecuteProcess(Session["ctx"] as Ctx, AD_Process_ID, Name, AD_PInstance_ID, AD_Table_ID, Record_ID, ParameterList));
            }
            else
            {
                retError = "SessionExpired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
 public JsonResult GeneratePrint(int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, bool csv)
 {
     if (Session["ctx"] != null)
     {
         ProcessReportInfo rep = (ProcessHelper.GeneratePrint(Session["ctx"] as Ctx, AD_Process_ID, Name, AD_Table_ID, Record_ID, WindowNo, csv));
         return(Json(JsonConvert.SerializeObject(rep), JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(JsonConvert.SerializeObject("SessionExpired"), JsonRequestBehavior.AllowGet));
     }
 }
        // vinay bhatt window id
        internal static ProcessReportInfo ExecuteProcessCommon(Ctx ctx, Dictionary <string, string> processInfo, ProcessPara[] pList)
        {
            ProcessReportInfo ret = new ProcessReportInfo();

            // Get Locks from Dictionary
            string lockedid = processInfo["Process_ID"].ToString() + "_" + processInfo["Record_ID"].ToString();
            //string lockedidlog = lockedid + " -UserID- " + ctx.GetAD_User_ID() + " -SesstionID- " + ctx.GetAD_Session_ID();

            var currentLock = GetLock(lockedid);

            lock (currentLock)
            {
                ret = ExecuteProcess(ctx, processInfo, pList);
            }
            return(ret);
        }
Exemplo n.º 4
0
 public JsonResult GenerateReport(int id, string queryInfo, Object code, bool isCreateNew, string ProcessInfo, bool pdf, bool csv)
 {
     if (Session["ctx"] != null)
     {
         List <string> qryInfo = JsonConvert.DeserializeObject <List <string> >(queryInfo);
         Dictionary <string, object> nProcessInfo = null;
         if (ProcessInfo != null)
         {
             nProcessInfo = JsonConvert.DeserializeObject <Dictionary <string, object> >(queryInfo);
         }
         ProcessReportInfo rep = (ProcessHelper.GenerateReport(Session["ctx"] as Ctx, id, qryInfo, code, isCreateNew, nProcessInfo, pdf, csv));
         return(Json(JsonConvert.SerializeObject(rep), JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(JsonConvert.SerializeObject("SessionExpired"), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 5
0
 public JsonResult GeneratePrint(int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, string filetype, string actionOrigin, string originName)
 {
     if (Session["ctx"] != null)
     {
         Ctx ctx = Session["ctx"] as Ctx;
         int pID = GetDoctypeBasedReport(ctx, AD_Table_ID, Record_ID);
         if (pID > 0)
         {
             ctx.SetContext("FetchingDocReport", "Y");
             AD_Process_ID = pID;
         }
         ProcessReportInfo rep = (ProcessHelper.GeneratePrint(Session["ctx"] as Ctx, AD_Process_ID, Name, AD_Table_ID, Record_ID, WindowNo, "", filetype, actionOrigin, originName));
         ctx.SetContext("FetchingDocReport", "N");
         return(Json(JsonConvert.SerializeObject(rep), JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(JsonConvert.SerializeObject("SessionExpired"), JsonRequestBehavior.AllowGet));
     }
 }
        // vinay bhatt window id

        /// <summary>
        /// Excecute Process
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Process_ID"></param>
        /// <param name="Name"></param>
        /// <param name="AD_Table_ID"></param>
        /// <param name="Record_ID"></param>
        /// <param name="WindowNo"></param>
        /// <param name="fileType"></param>
        /// <param name="AD_Window_ID"></param>
        /// <returns></returns>
        internal static ProcessReportInfo Process(Ctx ctx, Dictionary <string, string> processInfo)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, Util.GetValueOfInt(processInfo["Process_ID"]), Util.GetValueOfInt(processInfo["Record_ID"]));
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            //	Get Parameters (Dialog)
            //Check If Contaon Parameter

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, Util.GetValueOfInt(processInfo["Process_ID"]), Util.GetValueOfInt(processInfo["WindowNo"]));

            if (fields.Count < 1) //no Parameter
            {
                processInfo["AD_PInstance_ID"] = ret.AD_PInstance_ID.ToString();
                ret = ExecuteProcessCommon(ctx, processInfo, null);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
 /// <summary>
 /// This function executes when user select multiple records from window and click print button
 /// </summary>
 /// <param name="AD_Process_ID"></param>
 /// <param name="Name"></param>
 /// <param name="AD_Table_ID"></param>
 /// <param name="RecIDs"></param>
 /// <param name="WindowNo"></param>
 /// <param name="filetype"></param>
 /// <returns></returns>
 public JsonResult GenerateMultiPrint(int AD_Process_ID, string Name, int AD_Table_ID, string RecIDs, int WindowNo, string filetype)
 {
     if (Session["ctx"] != null)
     {
         Ctx ctx = Session["ctx"] as Ctx;
         ctx.SetContext("FetchingDocReport", "Y");
         int Record_ID = Convert.ToInt32(RecIDs.Split(',')[0]);
         int pID       = GetDoctypeBasedReport(ctx, AD_Table_ID, Record_ID);
         if (pID > 0)
         {
             AD_Process_ID = pID;
         }
         ProcessReportInfo rep = (ProcessHelper.GeneratePrint(ctx, AD_Process_ID, Name, AD_Table_ID, 0, WindowNo, RecIDs, filetype));
         ctx.SetContext("FetchingDocReport", "N");
         return(Json(JsonConvert.SerializeObject(rep), JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(JsonConvert.SerializeObject("SessionExpired"), JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// execute process
        /// - call after parameter dialog window
        /// - first save parameter for Process then execute
        /// </summary>
        /// <param name="AD_Process_ID">id of process</param>
        /// <param name="Name">name of process</param>
        /// <param name="AD_PInstance_ID">process instance id</param>
        /// <param name="AD_Table_ID">table id</param>
        /// <param name="Record_ID">record id</param>
        /// <param name="ParameterList">process parameter list</param>
        /// <returns>json result</returns>
        public JsonResult ExecuteProcess(Dictionary <string, string> processInfo, ProcessPara[] parameterList)
        {
            string retJSON  = "";
            string retError = null;

            if (Session["ctx"] != null)
            {
                //int pID = GetDoctypeBasedReport(Session["ctx"] as Ctx, Convert.ToInt32(processInfo["AD_Table_ID"]), Convert.ToInt32(processInfo["Record_ID"]));
                //if (pID > 0)
                //{
                //    processInfo["Process_ID"] = pID.ToString();
                //}
                //csv = true;
                //pdf = false;
                ProcessReportInfo rep = ProcessHelper.ExecuteProcessCommon(Session["ctx"] as Ctx, processInfo, parameterList);
                //rep.HTML=GetHtml(rep.ReportFilePath);
                //if (rep.Report != null && (rep.Report.Length > 1048576 || Record_ID > 0) && !csv && !pdf)
                if (rep.Report != null && (rep.Report.Length > 1048576 || Util.GetValueOfInt(rep.ReportProcessInfo["Record_ID"]) > 0))
                {
                    rep.AskForNewTab = true;
                    string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "TempDownload" + "\\temp_" + DateTime.Now.Ticks + ".pdf";
                    System.IO.File.WriteAllBytes(filePath, rep.Report);
                    rep.ReportFilePath = filePath.Substring(filePath.IndexOf("TempDownload"));
                    rep.HTML           = null;
                    rep.Report         = null;
                }
                //if (rep.Report != null)
                //{
                //    rep.byteString = Convert.ToBase64String(rep.Report);
                //}

                retJSON = JsonConvert.SerializeObject(rep);
                //retJSON = JsonConvert.SerializeObject(ProcessHelper.ExecuteProcess(Session["ctx"] as Ctx, AD_Process_ID, Name, AD_PInstance_ID, AD_Table_ID, Record_ID, ParameterList));
            }
            else
            {
                retError = "SessionExpired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 9
0
        internal static ProcessReportInfo Process(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, bool csv, bool pdf)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            //	Get Parameters (Dialog)
            //Check If Contaon Parameter

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, AD_Process_ID, WindowNo);

            if (fields.Count < 1) //no Parameter
            {
                ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null, csv, pdf);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Enhancement to provide facility to attacht print format directlty for selected record
        /// </summary>
        /// <param name="tableID"></param>
        /// <param name="processID"></param>
        /// <param name="recID"></param>
        /// <param name="windowNo"></param>
        /// <param name="fileType"></param>
        /// <param name="windowName"></param>
        /// <returns>details of print format file</returns>
        private ProcessReportInfo AttachPrintFormat(int tableID, int processID, string recID, int windowNo, string fileType)
        {
            string[] records   = recID.Split(',');
            int      Record_ID = Convert.ToInt32(records[0]);
            int      pID       = GetDoctypeBasedReport(tableID, Record_ID);

            if (pID > 0)
            {
                ctx.SetContext("FetchingDocReport", "Y");
                processID = pID;
            }
            ProcessReportInfo rep = null;

            if (records.Length < 2)
            {
                rep = ProcessHelper.GeneratePrint(ctx, processID, "Print", tableID, Record_ID, windowNo, "", fileType, "W", "");
            }
            else
            {
                rep = ProcessHelper.GeneratePrint(ctx, processID, "Print", tableID, 0, windowNo, recID, fileType, "W", "");
            }
            ctx.SetContext("FetchingDocReport", "N");
            return(rep);
        }
Exemplo n.º 11
0
        internal static ProcessReportInfo ExecuteProcess(Ctx ctx, int AD_Process_ID, string Name, int AD_PInstance_ID, int AD_Table_ID, int Record_ID, ProcessPara[] pList, bool csv = false, bool pdf = false)
        {
            int vala = 0;

            if (pList != null && pList.Length > 0) //we have process parameter
            {
                for (int i = 0; i < pList.Length; i++)
                {
                    var pp = pList[i];
                    //	Create Parameter
                    MPInstancePara para = new MPInstancePara(ctx, AD_PInstance_ID, i);
                    para.SetParameterName(pp.Name);

                    if (DisplayType.IsDate(pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_Date(Convert.ToDateTime(pp.Result));
                        }

                        if (pp.Result2 != null)
                        {
                            para.SetP_Date_To(Convert.ToDateTime(pp.Result2));
                        }
                    }
                    //else if (pp.Result is int || pp.Result2 is int)
                    //{
                    //    if (pp.Result != null)
                    //    {
                    //        para.SetP_Number(Convert.ToInt32(pp.Result));
                    //    }

                    //    if (pp.Result2 != null)
                    //    {
                    //        para.SetP_Number_To(Convert.ToInt32(pp.Result2));
                    //    }
                    //}
                    //else if (pp.Result is decimal || pp.Result2 is decimal)
                    //{
                    //    if (pp.Result != null)
                    //    {
                    //        para.SetP_Number(Convert.ToDecimal(pp.Result));
                    //    }
                    //    if (pp.Result2 != null)
                    //    {
                    //        para.SetP_Number_To(Convert.ToDecimal(pp.Result2));
                    //    }
                    //}
                    ////	Boolean
                    //else if (pp.Result is Boolean)
                    //{
                    //    Boolean bb = (Boolean)pp.Result;
                    //    String value = bb ? "Y" : "N";
                    //    para.SetP_String(value);
                    //    //	to does not make sense
                    //}
                    //*********
                    else if ((DisplayType.IsID(pp.DisplayType) || DisplayType.Integer == pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            if (int.TryParse(pp.Result.ToString(), out vala))
                            {
                                para.SetP_Number(Convert.ToInt32(pp.Result));
                            }
                            else
                            {
                                para.SetP_String(pp.Result.ToString());
                            }
                        }
                        if (pp.Result2 != null)
                        {
                            if (int.TryParse(pp.Result2.ToString(), out vala))
                            {
                                para.SetP_Number_To(Convert.ToInt32(pp.Result2));
                            }
                            else
                            {
                                para.SetP_String_To(pp.Result2.ToString());
                            }
                        }
                    }
                    else if (DisplayType.IsNumeric(pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_Number(Convert.ToDecimal(pp.Result));
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_Number_To(Convert.ToDecimal(pp.Result2));
                        }
                    }
                    else if (DisplayType.YesNo == pp.DisplayType)
                    {
                        Boolean bb    = (Boolean)pp.Result;
                        String  value = bb ? "Y" : "N";
                        para.SetP_String(value);
                    }
                    //*********
                    else
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_String(pp.Result.ToString());
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_String_To(pp.Result.ToString());
                        }
                    }

                    para.SetInfo(pp.Info);
                    if (pp.Info_To != null)
                    {
                        para.SetInfo_To(pp.Info_To);
                    }
                    para.Save();
                }
            }

            // ReportEngine_N re = null;

            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);


            ////////log/////
            string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
            string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");

            storedPath += clientName;
            VLogMgt.Initialize(true, storedPath);
            // VLogMgt.AddHandler(VLogFile.Get(true, storedPath, true));
            ////////////////

            byte[]            report      = null;
            string            rptFilePath = null;
            ProcessReportInfo rep         = new ProcessReportInfo();

            try
            {
                ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID);
                pi.SetAD_User_ID(ctx.GetAD_User_ID());
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                pi.SetAD_PInstance_ID(AD_PInstance_ID);

                //report = null;
                ProcessCtl ctl = new ProcessCtl();
                ctl.IsArabicReportFromOutside = false;
                ctl.SetIsPrintCsv(csv);
                if (pdf)
                {
                    ctl.SetIsPrintFormat(true);
                }
                Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                rep = new ProcessReportInfo();
                rep.ReportProcessInfo = d;
                rep.Report            = report;
                rep.ReportString      = ctl.ReportString;
                rep.ReportFilePath    = rptFilePath;
                rep.IsRCReport        = ctl.IsRCReport();
                //  rep.AD_PrintFormat_ID = ctl.GetAD_PrintFormat_ID();
                if (d.ContainsKey("AD_PrintFormat_ID"))
                {
                    rep.AD_PrintFormat_ID = Convert.ToInt32(d["AD_PrintFormat_ID"]);
                }
                ctl.ReportString = null;
                rep.HTML         = ctl.GetRptHtml();
                rep.AD_Table_ID  = ctl.GetReprortTableID();


                //Env.GetCtx().Clear();
            }
            catch (Exception e)
            {
                rep.IsError = true;
                rep.Message = e.Message;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = original;
            System.Threading.Thread.CurrentThread.CurrentUICulture = original;

            return(rep);
        }
        /// <summary>
        /// This function executes when user select record (one OR more) from window and click print button.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Process_ID"></param>
        /// <param name="Name"></param>
        /// <param name="AD_Table_ID"></param>
        /// <param name="Record_ID"></param>
        /// <param name="WindowNo"></param>
        /// <param name="recIDs"></param>
        /// <param name="fileType"></param>
        /// <returns></returns>
        public static ProcessReportInfo GeneratePrint(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, string recIDs, string fileType)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();



            //ReportEngine_N re = null;

            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);


            ////////log/////
            //string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
            //string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");
            //storedPath += clientName;
            //VLogMgt.Initialize(true, storedPath);
            ////////////////
            ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID, recIDs);

            pi.SetFileType(fileType);
            TryPrintFromDocType(pi);
            //if (ret != null)
            //{
            //    return ret;
            //}


            ret = new ProcessReportInfo();
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();
            byte[] report      = null;
            string rptFilePath = null;

            // ProcessReportInfo rep = new ProcessReportInfo();
            try
            {
                pi.SetAD_User_ID(ctx.GetAD_User_ID());
                pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                pi.SetAD_PInstance_ID(ret.AD_PInstance_ID);

                //report = null;
                ProcessCtl ctl = new ProcessCtl();
                //ctl.SetIsPrintFormat(true);
                //ctl.IsArabicReportFromOutside = false;
                //ctl.SetIsPrintCsv(csv);
                //ctl.SetFileType(fileType);
                Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                //rep = new ProcessReportInfo();
                ret.ReportProcessInfo = d;
                ret.Report            = report;
                ret.ReportString      = ctl.ReportString;
                ret.ReportFilePath    = rptFilePath;
                ret.HTML            = ctl.GetRptHtml();
                ret.IsRCReport      = ctl.IsRCReport();
                ret.TotalRecords    = pi.GetTotalRecords();
                ret.IsReportFormat  = pi.GetIsReportFormat();
                ret.IsTelerikReport = pi.GetIsTelerik();
                ctl.ReportString    = null;


                //Env.GetCtx().Clear();
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = original;
            System.Threading.Thread.CurrentThread.CurrentUICulture = original;

            //return ret;
            //ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null,true);
            // VAdvantage.Classes.CleanUp.Get().Start();
            return(ret);
        }
        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);
        }
        //[MethodImpl(MethodImplOptions.Synchronized)]
        // vinay bhatt window id
        internal static ProcessReportInfo ExecuteProcess(Ctx ctx, Dictionary <string, string> processInfo, ProcessPara[] pList)
        {
            ProcessInfo pi = new ProcessInfo().FromList(processInfo);

            pi.SetAD_User_ID(ctx.GetAD_User_ID());
            pi.SetAD_Client_ID(ctx.GetAD_Client_ID());

            int vala = 0;

            if (pList != null && pList.Length > 0) //we have process parameter
            {
                for (int i = 0; i < pList.Length; i++)
                {
                    var pp = pList[i];
                    //	Create Parameter
                    MPInstancePara para = new MPInstancePara(ctx, pi.GetAD_PInstance_ID(), i);
                    para.SetParameterName(pp.Name);

                    if (DisplayType.IsDate(pp.DisplayType))
                    {
                        if (pp.DisplayType == DisplayType.DateTime)
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Date_Time(Convert.ToDateTime(pp.Result));
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Date_Time_To(Convert.ToDateTime(pp.Result2));
                            }
                        }
                        if (pp.DisplayType == DisplayType.Time)
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Time(Convert.ToDateTime(pp.Result));
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Time_To(Convert.ToDateTime(pp.Result2));
                            }
                        }
                        else
                        {
                            if (pp.Result != null)
                            {
                                para.SetP_Date(Convert.ToDateTime(pp.Result).ToUniversalTime());
                            }

                            if (pp.Result2 != null)
                            {
                                para.SetP_Date_To(Convert.ToDateTime(pp.Result2).ToUniversalTime());
                            }
                        }
                    }

                    else if ((DisplayType.IsID(pp.DisplayType) || DisplayType.Integer == pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            if (DisplayType.IsLookup(pp.DisplayType) && pp.Result.Equals("-1"))
                            {
                                continue;
                            }

                            if (int.TryParse(pp.Result.ToString(), out vala))
                            {
                                para.SetP_Number(Convert.ToInt32(pp.Result));
                            }
                            else
                            {
                                para.SetP_String(pp.Result.ToString());
                            }
                        }
                        if (pp.Result2 != null)
                        {
                            if (DisplayType.IsLookup(pp.DisplayType) && pp.Result2.Equals("-1"))
                            {
                                continue;
                            }
                            if (int.TryParse(pp.Result2.ToString(), out vala))
                            {
                                para.SetP_Number_To(Convert.ToInt32(pp.Result2));
                            }
                            else
                            {
                                para.SetP_String_To(pp.Result2.ToString());
                            }
                        }
                    }
                    else if (DisplayType.IsNumeric(pp.DisplayType))
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_Number(Convert.ToDecimal(pp.Result));
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_Number_To(Convert.ToDecimal(pp.Result2));
                        }
                    }
                    else if (DisplayType.YesNo == pp.DisplayType)
                    {
                        Boolean bb    = (Boolean)pp.Result;
                        String  value = bb ? "Y" : "N";
                        para.SetP_String(value);
                    }

                    else
                    {
                        if (pp.Result != null)
                        {
                            para.SetP_String(pp.Result.ToString());
                        }
                        if (pp.Result2 != null)
                        {
                            para.SetP_String_To(pp.Result.ToString());
                        }
                    }
                    para.SetAD_Process_Para_ID(pp.AD_Column_ID);

                    para.SetInfo(pp.Info);

                    if (pp.Info_To != null)
                    {
                        para.SetInfo_To(pp.Info_To);
                    }
                    para.Save();
                }
            }

            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[]            report      = null;
            string            rptFilePath = null;
            ProcessReportInfo rep         = new ProcessReportInfo();

            try
            {
                //ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID);
                //pi.SetAD_User_ID(ctx.GetAD_User_ID());
                //pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                //pi.SetAD_PInstance_ID(AD_PInstance_ID);
                //pi.SetAD_Window_ID(AD_Window_ID);
                //pi.FileType = fileType;
                //report = null;

                pi.IsArabicReportFromOutside = false;
                ProcessCtl ctl = new ProcessCtl();

                //ctl.SetIsPrintCsv(csv);
                //ctl.SetFileType(fileType);
                //if (fileType == "P")
                //{
                //    ctl.SetIsPrintFormat(true);
                //}
                Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                rep = new ProcessReportInfo();
                rep.ReportProcessInfo = d;
                rep.Report            = report;

                //if (rep.Report != null)
                //{
                //    rep.byteString = Convert.ToBase64String(rep.Report);
                //}

                rep.ReportString = ctl.ReportString;
                //rep.AD_ReportView_ID = ctl.GetAD_ReportView_ID();
                rep.ReportFilePath = rptFilePath;
                // rep.IsRCReport = ctl.IsRCReport();
                // rep.TotalRecords = pi.GetTotalRecords();
                // rep.IsReportFormat = pi.GetIsReportFormat();
                // rep.IsTelerikReport = pi.GetIsTelerik();
                // rep.IsJasperReport = pi.GetIsJasperReport();
                //  rep.AD_PrintFormat_ID = ctl.GetAD_PrintFormat_ID();
                // if (d.ContainsKey("AD_PrintFormat_ID"))
                // {
                //    rep.AD_PrintFormat_ID = Convert.ToInt32(d["AD_PrintFormat_ID"]);
                // }
                ctl.ReportString = null;
                rep.HTML         = ctl.GetRptHtml();
                //rep.AD_Table_ID = ctl.GetReprortTableID();


                //Env.GetCtx().Clear();
            }
            catch (Exception e)
            {
                rep.IsError = true;
                rep.Message = e.Message;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture   = original;
            System.Threading.Thread.CurrentThread.CurrentUICulture = original;
            //VAdvantage.Classes.CleanUp.Get().Start();
            return(rep);
        }
Exemplo n.º 15
0
        /// <summary>
        /// this method actually send mail, both static and dynamic.... and save info in MailAttachment....
        /// </summary>
        /// <param name="mails"></param>
        /// <param name="AD_User_ID"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="AD_Org_ID"></param>
        /// <param name="attachment_ID"></param>
        /// <param name="fileNames"></param>
        /// <param name="fileNameForOpenFormat"></param>
        /// <param name="mailFormat"></param>
        /// <param name="notify"></param>
        /// <returns></returns>
        public string SendMailstart(List <NewMailMessage> mails, int AD_User_ID, int AD_Client_ID, int AD_Org_ID, int attachment_ID,
                                    List <string> fileNames, List <string> fileNameForOpenFormat, string mailFormat, bool notify, VAdvantage.Utility.EMail sendmails,
                                    List <int> documentID, int Ad_Process_ID, string printformatfileType)
        {
            if (ctx == null)
            {
                return(null);
            }


            UserInformation userinfo = new UserInformation();
            SMTPConfig      config   = null;

            config = MailConfigMethod.GetUSmtpConfig(AD_User_ID, ctx);
            // var config = "";
            if (config == null)
            {
                MClient client = new MClient(ctx, AD_Client_ID, null);
                userinfo.Email = client.GetRequestEMail();
            }
            else
            {
                //Add user info to list..
                userinfo.Email = config.Email;
            }

            string[] to = null;
            string[] bc = null;

            string[] cc      = null;
            string   sub     = null;
            string   message = null;
            // int _record_id = 0;
            int _table_id = 0;

            string[] records = null;

            StringBuilder res = new StringBuilder();

            List <NewMailMessage> mail = mails.GetRange(0, mails.Count);

            for (int j = 0; j < mails.Count; j++)
            {
                VAdvantage.Utility.EMail sendmail = new VAdvantage.Utility.EMail(ctx, "", "", "", "", "", "",
                                                                                 true, false);

                to = mails[j].To.Split(';');
                bc = mails[j].Bcc;
                cc = mails[j].Cc.Split(';');
                StringBuilder bcctext = new StringBuilder();
                sub     = mails[j].Subject;
                message = mailFormat;
                if (mails[j].Body != null && mails[j].Body.Count > 0)
                {
                    List <string> keysss = mails[j].Body.Keys.ToList();
                    for (int q = 0; q < keysss.Count; q++)
                    {
                        message = message.Replace(keysss[q], mails[j].Body[keysss[q]]);
                    }
                }

                if (mails[j].Recordids != null)          //in case of static mail
                {
                    records = mails[j].Recordids.Split(',');
                }

                _table_id = Convert.ToInt32(mail[j].TableID);

                VAdvantage.Model.MMailAttachment1 _mAttachment = new VAdvantage.Model.MMailAttachment1(ctx, 0, null);



                if (sub == null || sub.Length == 0 || sub == "")
                {
                    sendmail.SetSubject(".");   //	pass validation
                }
                else
                {
                    sendmail.SetSubject(sub);
                }
                sendmail.SetMessageHTML(message);


                //used to get attachments uploaded by user.....
                if (mail[j].AttachmentFolder != null && mail[j].AttachmentFolder.Trim().Length > 0)
                {
                    string storedAttachmentPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, AttachmentsUploadFolderName + "\\" + mail[j].AttachmentFolder);
                    if (Directory.Exists(storedAttachmentPath))
                    {
                        DirectoryInfo info = new DirectoryInfo(storedAttachmentPath);
                        if (info.GetFiles().Length > 0)
                        {
                            FileInfo[] files = info.GetFiles();

                            for (int a = 0; a < files.Length; a++)
                            {
                                if (fileNames.Contains(files[a].Name))
                                {
                                    FileStream   attachmentStream = File.OpenRead(files[a].FullName);
                                    BinaryReader binary           = new BinaryReader(attachmentStream);
                                    byte[]       buffer           = binary.ReadBytes((int)attachmentStream.Length);
                                    sendmail.AddAttachment(buffer, files[a].Name);
                                    _mAttachment.AddEntry(files[a].Name, buffer);
                                }
                            }
                        }
                    }
                }

                //used to get attachments of saved formats.. Currently not Supporting......
                if (attachment_ID > 0)
                {
                    VAdvantage.Model.MMailAttachment1 _mAttachment1 = new VAdvantage.Model.MMailAttachment1(ctx, attachment_ID, null);
                    if (_mAttachment1.GetEntryCount() > 0)
                    {
                        MAttachmentEntry[] entries = _mAttachment1.GetEntries();
                        for (int m = 0; m < entries.Count(); m++)
                        {
                            //if (fileNameForOpenFormat.Contains(entries[m].GetName()))
                            //{
                            byte[] buffer = entries[m].GetData();
                            sendmail.AddAttachment(buffer, entries[m].GetName());
                            _mAttachment.AddEntry(entries[m].GetName(), buffer);
                            //}
                        }
                    }
                }

                if (documentID != null || documentID.Count > 0)
                {
                    for (int i = 0; i < documentID.Count; i++)
                    {
                        try
                        {
                            int attachmentID = AttachmentID(documentID[i]);
                            //MAttachment objAttachment = new MAttachment(ctx, attachmentID, null, Common.GetPassword(), ctx.GetAD_Client_ID());
                            //objAttachment.Force = false;
                            ////objAttachment.AD_Client_ID = ctx.GetAD_Client_ID();
                            //byte[] fileByte = objAttachment.GetEntryData(0);
                            //string fileName = objAttachment.GetEntryName(0);
                            List <AttachedFileInfo> lstAttchments = GetBytes(ctx, attachmentID, "");
                            sendmail.AddAttachment(lstAttchments[0].FileBytes, lstAttchments[0].FileName);
                        }
                        catch (Exception ex)
                        {
                            res.Append(Msg.GetMsg(ctx, "VADMS_AttachmentNotFound for : " + documentID[i]) + ex.Message);
                        }
                    }
                }


                //Lakhwinder
                //AttachPrintFormat
                if (!string.IsNullOrEmpty(printformatfileType) && printformatfileType != "X")
                {
                    ProcessReportInfo rep = AttachPrintFormat(mails[j].TableID, Ad_Process_ID, mails[j].Recordids, 0, printformatfileType);
                    if (!string.IsNullOrEmpty(rep.ReportFilePath))
                    {
                        FileStream   attachmentStream = File.OpenRead(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, rep.ReportFilePath));
                        BinaryReader binary           = new BinaryReader(attachmentStream);
                        byte[]       buffer           = binary.ReadBytes((int)attachmentStream.Length);
                        sendmail.AddAttachment(buffer, rep.ReportFilePath.Substring(rep.ReportFilePath.LastIndexOf('\\') + 1));
                    }
                }

                if (to != null)
                {
                    for (int i = 0; i < to.Length; i++)
                    {
                        if (to[i].ToString() != "")
                        {
                            sendmail.AddTo(to[i].ToString(), "");
                            // totext.Append(to[i].ToString() + ",");
                        }
                    }
                }

                if (bc != null)
                {
                    for (int i = 0; i < bc.Length; i++)
                    {
                        if (bc[i].ToString() != "")
                        {
                            sendmail.AddBcc(bc[i].ToString(), "");
                            bcctext.Append(bc[i].ToString() + ",");
                        }
                    }
                }

                if (cc != null)
                {
                    for (int i = 0; i < cc.Length; i++)
                    {
                        if (cc[i].ToString() != "")
                        {
                            sendmail.AddCc(cc[i].ToString(), "");
                            ///  cctext.Append(cc[i].ToString() + ",");
                        }
                    }
                }

                string res1 = sendmail.Send();

                if (records != null && records.Length > 0)//save entery in MailAttachment......
                {
                    for (int k = 0; k < records.Length; k++)
                    {
                        if (records[k] == null || records[k] == "" || records[k] == "0")
                        {
                            continue;
                        }
                        if (res1 != "OK")
                        {
                            _mAttachment.SetIsMailSent(false);
                        }
                        else
                        {
                            _mAttachment.SetIsMailSent(true);
                        }
                        int AD_Client_Id = ctx.GetAD_Client_ID();
                        int iOrgid       = ctx.GetAD_Org_ID();

                        _mAttachment.SetAD_Client_ID(AD_Client_Id);
                        _mAttachment.SetAD_Org_ID(iOrgid);
                        _mAttachment.SetAD_Table_ID(_table_id);
                        _mAttachment.IsActive();
                        _mAttachment.SetMailAddress(bcctext.ToString());
                        _mAttachment.SetAttachmentType("M");

                        _mAttachment.SetRecord_ID(Convert.ToInt32(records[k]));

                        _mAttachment.SetTextMsg(message);
                        _mAttachment.SetTitle(sub);

                        _mAttachment.SetMailAddressBcc(bcctext.ToString());
                        _mAttachment.SetMailAddress(mails[j].To);
                        _mAttachment.SetMailAddressCc(mails[j].Cc);
                        _mAttachment.SetMailAddressFrom(userinfo.Email);
                        if (_mAttachment.GetEntries().Length > 0)
                        {
                            _mAttachment.SetIsAttachment(true);
                        }
                        else
                        {
                            _mAttachment.SetIsAttachment(false);
                        }
                        _mAttachment.NewRecord();
                        if (_mAttachment.Save())
                        {
                        }
                        else
                        {
                            // log.SaveError(Msg.GetMsg(Env.GetCtx(), "RecordNotSaved"), "");
                        }
                    }
                }

                if (res1 != "OK")           // if mail not sent....
                {
                    if (res1 == "AuthenticationFailed.")
                    {
                        res.Append("AuthenticationFailed");
                        return(res.ToString());
                    }
                    else if (res1 == "ConfigurationIncompleteOrNotFound")
                    {
                        res.Append("ConfigurationIncompleteOrNotFound");
                        return(res.ToString());
                    }
                    else
                    {
                        res.Append(" " + Msg.GetMsg(ctx, "MailNotSentTo") + ": " + mails[j].To + " " + bcctext + " " + mails[j].Cc);
                    }
                }
                else
                {
                    {
                        if (!res.ToString().Contains("MailSent"))
                        {
                            res.Append("MailSent");
                        }
                    }
                }
                bcctext = null;
            }

            if (notify)             //  make an entry in Notice window.....
            {
                MNote note = new MNote(ctx, "SentMailNotice", AD_User_ID,
                                       AD_Client_ID, AD_Org_ID, null);
                //  Reference
                note.SetReference(ToString());  //	Document
                //	Text
                note.SetTextMsg(res.ToString());
                note.Save();
            }

            userinfo = null;
            cc       = null;
            bc       = null;
            to       = null; records = null;
            sub      = null; message = null;
            records  = null;
            return(res.ToString());
        }
Exemplo n.º 16
0
        public static ProcessReportInfo GeneratePrint(Ctx ctx, int AD_Process_ID, string Name, int AD_Table_ID, int Record_ID, int WindowNo, bool csv)
        {
            ProcessReportInfo ret      = new ProcessReportInfo();
            MPInstance        instance = null;

            try
            {
                instance = new MPInstance(ctx, AD_Process_ID, Record_ID);
            }
            catch (Exception e)
            {
                ret.IsError = true;
                ret.Message = e.Message;
                return(ret);
            }

            if (!instance.Save())
            {
                ret.IsError = true;
                ret.Message = Msg.GetMsg(ctx, "ProcessNoInstance");
                return(ret);
            }
            ret.AD_PInstance_ID = instance.GetAD_PInstance_ID();

            List <GridField> fields = ProcessParameter.GetParametersList(ctx, AD_Process_ID, WindowNo);

            if (fields.Count < 1) //no Parameter
            {
                //ReportEngine_N re = null;

                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);


                ////////log/////
                string clientName = ctx.GetAD_Org_Name() + "_" + ctx.GetAD_User_Name();
                string storedPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "");
                storedPath += clientName;
                VLogMgt.Initialize(true, storedPath);
                ////////////////

                byte[] report      = null;
                string rptFilePath = null;
                // ProcessReportInfo rep = new ProcessReportInfo();
                try
                {
                    ProcessInfo pi = new ProcessInfo(Name, AD_Process_ID, AD_Table_ID, Record_ID);
                    pi.SetAD_User_ID(ctx.GetAD_User_ID());
                    pi.SetAD_Client_ID(ctx.GetAD_Client_ID());
                    pi.SetAD_PInstance_ID(ret.AD_PInstance_ID);

                    //report = null;
                    ProcessCtl ctl = new ProcessCtl();
                    ctl.SetIsPrintFormat(true);
                    ctl.IsArabicReportFromOutside = false;
                    ctl.SetIsPrintCsv(csv);
                    Dictionary <string, object> d = ctl.Process(pi, ctx, out report, out rptFilePath);
                    //rep = new ProcessReportInfo();
                    ret.ReportProcessInfo = d;
                    ret.Report            = report;
                    ret.ReportString      = ctl.ReportString;
                    ret.ReportFilePath    = rptFilePath;
                    ret.HTML         = ctl.GetRptHtml();
                    ret.IsRCReport   = ctl.IsRCReport();
                    ctl.ReportString = null;


                    //Env.GetCtx().Clear();
                }
                catch (Exception e)
                {
                    ret.IsError = true;
                    ret.Message = e.Message;
                }

                System.Threading.Thread.CurrentThread.CurrentCulture   = original;
                System.Threading.Thread.CurrentThread.CurrentUICulture = original;

                //return ret;
                //ret = ExecuteProcess(ctx, AD_Process_ID, Name, ret.AD_PInstance_ID, AD_Table_ID, Record_ID, null,true);
            }
            else
            {
                ret.ShowParameter = true;
                ret.ProcessFields = fields;
            }
            return(ret);
        }
Exemplo n.º 17
0
        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);
        }