Beispiel #1
0
        private string GetReturnData(HttpContext context)
        {
            try
            {
                var strOut = "";

                var strIn   = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
                var xmlData = GenXmlFunctions.GetGenXmlByAjax(strIn, "");
                var objInfo = new NBrightInfo();

                objInfo.ItemID   = -1;
                objInfo.TypeCode = "AJAXDATA";
                objInfo.XMLData  = xmlData;
                var settings = objInfo.ToDictionary();

                var themeFolder = StoreSettings.Current.ThemeFolder;
                if (settings.ContainsKey("themefolder"))
                {
                    themeFolder = settings["themefolder"];
                }
                var templCtrl = NBrightBuyUtils.GetTemplateGetter(themeFolder);

                if (!settings.ContainsKey("portalid"))
                {
                    settings.Add("portalid", PortalSettings.Current.PortalId.ToString(""));                                    // aways make sure we have portalid in settings
                }
                var objCtrl = new NBrightBuyController();

                // run SQL and template to return html
                if (settings.ContainsKey("sqltpl") && settings.ContainsKey("xsltpl"))
                {
                    var strSql  = templCtrl.GetTemplateData(settings["sqltpl"], _uilang, true, true, true, StoreSettings.Current.Settings());
                    var xslTemp = templCtrl.GetTemplateData(settings["xsltpl"], _uilang, true, true, true, StoreSettings.Current.Settings());

                    // replace any settings tokens (This is used to place the form data into the SQL)
                    strSql = Utils.ReplaceSettingTokens(strSql, settings);
                    strSql = Utils.ReplaceUrlTokens(strSql);

                    strSql = GenXmlFunctions.StripSqlCommands(strSql); // don't allow anything to update through here.

                    strOut = objCtrl.GetSqlxml(strSql);
                    if (!strOut.StartsWith("<root>"))
                    {
                        strOut = "<root>" + strOut + "</root>";                               // always wrap with root node.
                    }
                    strOut = XslUtils.XslTransInMemory(strOut, xslTemp);
                }

                return(strOut);
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
        private NBrightInfo GetStats(int portalId, bool forceRefresh = false)
        {
            var cachekey  = "nbrightbuydashboard*" + PortalId.ToString("");
            var statsInfo = (NBrightInfo)Utils.GetCache(cachekey);

            if (statsInfo == null || StoreSettings.Current.DebugMode || forceRefresh)
            {
                var objCtrl = new NBrightBuyController();
                statsInfo = new NBrightInfo(true);

                var objQual = DotNetNuke.Data.DataProvider.Instance().ObjectQualifier;
                var dbOwner = DotNetNuke.Data.DataProvider.Instance().DatabaseOwner;

                var statsXml = objCtrl.GetSqlxml("exec " + dbOwner + objQual + "NBrightBuy_DashboardStats " + portalId);
                statsInfo.XMLData = statsXml;
                Utils.SetCache(cachekey, statsInfo);
            }
            return(statsInfo);
        }
Beispiel #3
0
        private string RunReport(HttpContext context)
        {
            var strOut = "- No Data Returned -";
            var strSql = "";

            try
            {
                var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
                //var itemid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/itemid");
                var razortemplate = ajaxInfo.GetXmlProperty("genxml/hidden/razortemplate");
                var portalid      = PortalSettings.Current.PortalId.ToString("");

                var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
                if (editlang == "")
                {
                    editlang = Utils.GetCurrentCulture();
                }
                var selecteditemid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/selecteditemid");

                if (selecteditemid > 0)
                {
                    var objCtrl = new NBrightBuyController();
                    var obj     = objCtrl.Get(selecteditemid);
                    if (obj != null)
                    {
                        var inline = obj.GetXmlPropertyBool("genxml/checkbox/inline");
                        strSql = obj.GetXmlProperty("genxml/textbox/sql");
                        // replace any settings tokens (This is used to place the form data into the SQL)
                        strSql = Utils.ReplaceSettingTokens(strSql, ajaxInfo.ToDictionary());
                        strSql = Utils.ReplaceUrlTokens((strSql));

                        strSql = GenXmlFunctions.StripSqlCommands(strSql); // don't allow anything to update through here.

                        // add FOR XML if not there, this function will only output XML results.
                        if (!strSql.ToLower().Contains("for xml"))
                        {
                            strSql += " FOR XML PATH ('item'), ROOT ('root')";
                        }

                        var strXmlResults = objCtrl.GetSqlxml(strSql);
                        if (strXmlResults != "")
                        {
                            var xdoc       = XDocument.Parse(strXmlResults);
                            var headerInfo = new NBrightInfo(false);
                            headerInfo.XMLData = "<item></item>";
                            var elementsList = xdoc.XPathSelectElements("root/item[1]/*");
                            var xmlList      = new List <NBrightInfo>();

                            if (obj.GetXmlProperty("genxml/radiobuttonlist/reportformat") == "csv")
                            {
                                var lp = 1;
                                foreach (XElement xmlitem in elementsList)
                                {
                                    headerInfo.SetXmlProperty("item/header" + lp, xmlitem.Name.ToString());
                                    lp += 1;
                                }
                                xmlList.Add(headerInfo);
                            }

                            foreach (XElement xmlitem in xdoc.XPathSelectElements("root/item"))
                            {
                                var nbi = new NBrightInfo(false);
                                nbi.XMLData = xmlitem.ToString();
                                xmlList.Add(nbi);
                            }

                            var templateControl = "/DesktopModules/NBright/OS_Reports";

                            if (obj.GetXmlProperty("genxml/radiobuttonlist/reportformat") == "html")
                            {
                                if (inline)
                                {
                                    razortemplate = "reporthtmlinline.cshtml";
                                }
                                else
                                {
                                    razortemplate = "reporthtml.cshtml";
                                }
                            }
                            if (obj.GetXmlProperty("genxml/radiobuttonlist/reportformat") == "csv")
                            {
                                inline        = false;
                                razortemplate = "reportcsv.cshtml";
                            }
                            //project
                            if (obj.GetXmlProperty("genxml/radiobuttonlist/reportformat") == "barchart")
                            {
                                inline        = true;
                                razortemplate = "reportbar.cshtml";
                            }

                            strOut = NBrightBuyUtils.RazorTemplRenderList(razortemplate, -1, "", xmlList, templateControl, "config", editlang, StoreSettings.Current.Settings());

                            if (!inline)
                            {
                                var outfile = StoreSettings.Current.FolderTempMapPath + "\\" + selecteditemid + "." + obj.GetXmlProperty("genxml/radiobuttonlist/reportformat");
                                Utils.SaveFile(outfile, strOut);
                                strOut = "<br/><h1>Completed: <a target='_blank' href='" + StoreSettings.Current.FolderTemp + "/" + selecteditemid + "."
                                         + obj.GetXmlProperty("genxml/radiobuttonlist/reportformat") + "?key=" + Utils.GetUniqueKey() + "' >View</a></h1>";
                            }
                        }
                        return(strOut);
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString() + " <hr/> " + strSql);
            }
            return(strOut);
        }