예제 #1
0
        public static NBrightInfo CalculateModels(NBrightInfo objInfo, String controlMapPath)
        {
            var objCtrl = new NBrightBuyController();
            var optList = new List <NBrightInfo>();

            // get list of active options for product models
            var xmlOptList = objInfo.XMLDoc.SelectNodes("genxml/prdopt/id");

            if (xmlOptList != null)
            {
                foreach (XmlNode xNod in xmlOptList)
                {
                    if (Utils.IsNumeric(xNod.InnerText))
                    {
                        var objOpt = objCtrl.Get(Convert.ToInt32(xNod.InnerText));
                        if (objOpt != null)
                        {
                            optList.Add(objOpt);
                        }
                    }
                }
            }

            //sort into ItemId order so we get the same modelcode created.
            optList.Sort(delegate(NBrightInfo p1, NBrightInfo p2)
            {
                return(p1.ItemID.CompareTo(p2.ItemID));
            });

            //Build modelCode list
            int lp1    = 0;
            var mcList = new List <string>();

            lp1 = 0;
            if (optList.Count == 1)
            {
                // only 1 option with stock, so no need to do a recursive build.
                var xmlNodList2 = optList[0].XMLDoc.SelectNodes("genxml/optionval/genxml");
                if (xmlNodList2 != null)
                {
                    foreach (XmlNode xNod2 in xmlNodList2)
                    {
                        var xNod = xNod2.SelectSingleNode("textbox/txtoptionvalue");
                        if (xNod != null)
                        {
                            mcList.Add(xNod.InnerText);
                        }
                    }
                }
            }
            else
            {
                // do recursive build on options.
                while (lp1 < (optList.Count - 1))
                {
                    mcList = BuildModelCodes(optList, lp1, "", "", mcList);
                    lp1++;
                }
            }


            //Merge with existing models
            var      templCtrl = new TemplateGetter(controlMapPath, controlMapPath);
            Repeater rpEntity;
            var      strTemplate = templCtrl.GetTemplateData("AdminProducts_Models.html", Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());

            // remove models no longer needed
            XmlNodeList nodes = objInfo.XMLDoc.SelectNodes("genxml/models/genxml");

            for (int i = nodes.Count - 1; i >= 0; i--)
            {
                var mCode = nodes[i].SelectSingleNode("hidden/modelcode");
                if (mCode != null)
                {
                    if (!mcList.Contains(mCode.InnerText))
                    {
                        var parentNode = nodes[i].ParentNode;
                        if (parentNode != null)
                        {
                            parentNode.RemoveChild(nodes[i]);
                        }
                    }
                }
                else
                {
                    // no modelcode, invalid, so remove
                    var parentNode = nodes[i].ParentNode;
                    if (parentNode != null)
                    {
                        parentNode.RemoveChild(nodes[i]);
                    }
                }
            }

            // save changes back to the product object
            objInfo.XMLData = objInfo.XMLDoc.OuterXml;

            // add new models
            var idx = 0;

            foreach (var modelCode in mcList)
            {
                if (objInfo.XMLDoc.SelectSingleNode("genxml/models/genxml/hidden/modelcode[.='" + modelCode + "']") == null)
                {
                    var obj = new NBrightInfo();
                    rpEntity = GenXmlFunctions.InitRepeater(obj, strTemplate);
                    GenXmlFunctions.SetHiddenField(rpEntity.Items[0], "modelcode", modelCode);
                    GenXmlFunctions.SetHiddenField(rpEntity.Items[0], "entityindex", idx.ToString(CultureInfo.InvariantCulture));
                    var strXml = GenXmlFunctions.GetGenXml(rpEntity, 0);
                    objInfo = AddEntity(objInfo, "models", 1, strXml);
                    idx    += 1;
                }
            }

            return(objInfo);
        }
예제 #2
0
        public static NBrightInfo CalculateModels(NBrightInfo objInfo,String controlMapPath)
        {
            var objCtrl = new NBrightBuyController();
            var optList = new List<NBrightInfo>();

            // get list of active options for product models
            var xmlOptList = objInfo.XMLDoc.SelectNodes("genxml/prdopt/id");
            if (xmlOptList != null)
            {
                foreach (XmlNode xNod in xmlOptList)
                {
                    if (Utils.IsNumeric(xNod.InnerText))
                    {
                        var objOpt = objCtrl.Get(Convert.ToInt32(xNod.InnerText));
                        if (objOpt != null) optList.Add(objOpt);
                    }
                }
            }

            //sort into ItemId order so we get the same modelcode created.
            optList.Sort(delegate(NBrightInfo p1, NBrightInfo p2)
            {
                return p1.ItemID.CompareTo(p2.ItemID);
            });

            //Build modelCode list
            int lp1 = 0;
            var mcList = new List<string>();
            lp1 = 0;
            if (optList.Count == 1)
            {
                // only 1 option with stock, so no need to do a recursive build.
                var xmlNodList2 = optList[0].XMLDoc.SelectNodes("genxml/optionval/genxml");
                if (xmlNodList2 != null)
                    foreach (XmlNode xNod2 in xmlNodList2)
                    {
                        var xNod = xNod2.SelectSingleNode("textbox/txtoptionvalue");
                        if (xNod != null) mcList.Add(xNod.InnerText);
                    }
            }
            else
            {
                // do recursive build on options.
                while (lp1 < (optList.Count - 1))
                {
                    mcList = BuildModelCodes(optList, lp1, "", "", mcList);
                    lp1++;
                }
            }

            //Merge with existing models
            var templCtrl = new TemplateGetter(controlMapPath,controlMapPath);
            Repeater rpEntity;
            var strTemplate = templCtrl.GetTemplateData("AdminProducts_Models.html", Utils.GetCurrentCulture(), true, true, true, StoreSettings.Current.Settings());

            // remove models no longer needed
            XmlNodeList nodes = objInfo.XMLDoc.SelectNodes("genxml/models/genxml");
            for (int i = nodes.Count - 1; i >= 0; i--)
            {
                var mCode = nodes[i].SelectSingleNode("hidden/modelcode");
                if (mCode != null)
                {
                    if (!mcList.Contains(mCode.InnerText))
                    {
                        var parentNode = nodes[i].ParentNode;
                        if (parentNode != null) parentNode.RemoveChild(nodes[i]);
                    }
                }
                else
                {
                    // no modelcode, invalid, so remove
                    var parentNode = nodes[i].ParentNode;
                    if (parentNode != null) parentNode.RemoveChild(nodes[i]);
                }
            }

            // save changes back to the product object
            objInfo.XMLData = objInfo.XMLDoc.OuterXml;

            // add new models
            var idx = 0;
            foreach (var modelCode in mcList)
            {
                if (objInfo.XMLDoc.SelectSingleNode("genxml/models/genxml/hidden/modelcode[.='" + modelCode + "']") == null)
                {
                    var obj = new NBrightInfo();
                    rpEntity = GenXmlFunctions.InitRepeater(obj, strTemplate);
                    GenXmlFunctions.SetHiddenField(rpEntity.Items[0], "modelcode", modelCode);
                    GenXmlFunctions.SetHiddenField(rpEntity.Items[0], "entityindex", idx.ToString(CultureInfo.InvariantCulture));
                    var strXml = GenXmlFunctions.GetGenXml(rpEntity, 0);
                    objInfo = AddEntity(objInfo, "models", 1, strXml);
                    idx += 1;
                }
            }

            return objInfo;
        }
예제 #3
0
 /// <summary>
 /// Helper function to help plugins get a theme template from their local theme folder.
 /// This function will get the template, replace settings tokens, replace url tokens
 /// </summary>
 /// <param name="templatename">name of template</param>
 /// <param name="templateControlPath">Relative Control path of plugin e.g."/DesktopModules/NBright/NBrightBuyPluginTempl"</param>
 /// <param name="themeFolder">Theme folder to use e.g. "config"</param>
 /// <param name="settings">Settings to use, default to storesettings</param>
 /// <param name="lang">culture code</param>
 /// <returns></returns>
 public static String GetTemplateData(String templatename, String templateControlPath, String themeFolder = "config", Dictionary<String, String> settings = null,String lang = "")
 {
     themeFolder = "Themes\\" + themeFolder;
     if (settings == null) settings = StoreSettings.Current.Settings();
     var controlMapPath = HttpContext.Current.Server.MapPath(templateControlPath);
     var templCtrl = new TemplateGetter(PortalSettings.Current.HomeDirectoryMapPath, controlMapPath, themeFolder, StoreSettings.Current.ThemeFolder);
     if (lang == "") lang = Utils.GetCurrentCulture();
     var templ = templCtrl.GetTemplateData(templatename, lang);
     templ = Utils.ReplaceSettingTokens(templ, settings);
     templ = Utils.ReplaceUrlTokens(templ);
     return templ;
 }
예제 #4
0
 public static string GetRazorTemplateData(string templatename, string templateControlPath, string themeFolder = "config", string lang = "")
 {
     var controlMapPath = HttpContext.Current.Server.MapPath(templateControlPath);
     var templCtrl = new TemplateGetter(PortalSettings.Current.HomeDirectoryMapPath, controlMapPath, "Themes\\" + StoreSettings.Current.ThemeFolder, "Themes\\" + themeFolder );
     if (lang == "") lang = Utils.GetCurrentCulture();
     var templ = templCtrl.GetTemplateData(templatename, lang);
     return templ;
 }