예제 #1
0
        /// <summary>
        /// Select categories linked to product, by groupref
        /// </summary>
        /// <param name="productid"></param>
        /// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
        /// <param name="cascade">get all cascade records to get all parent categories</param>
        /// <returns></returns>
        public List <GroupCategoryData> GetProductCategories(int productid, String groupref = "", Boolean cascade = false)
        {
            var objCtrl     = new NBrightBuyController();
            var catxrefList = objCtrl.GetList(-1, -1, "CATXREF", " and NB1.[ParentItemId] = " + productid);

            if (cascade)
            {
                var catcascadeList = objCtrl.GetList(-1, -1, "CATCASCADE", " and NB1.[ParentItemId] = " + productid);
                foreach (var c in catcascadeList)
                {
                    catxrefList.Add(c);
                }
            }


            var notcat = "";

            if (groupref == "!cat")
            {
                groupref = "";
                notcat   = "cat";
            }

            var joinItems = (from d1 in GrpCategoryList
                             join d2 in catxrefList on d1.categoryid equals d2.XrefItemId
                             where (d1.grouptyperef == groupref || groupref == "") && d1.grouptyperef != notcat
                             select d1).OrderBy(d1 => d1.grouptyperef).ThenBy(d1 => d1.breadcrumb).ToList <GroupCategoryData>();

            return(joinItems);
        }
예제 #2
0
        public static void CopySystemPluginsToPortal()
        {
            var objCtrl = new NBrightBuyController();
            var rtnList = objCtrl.GetList(99999, -1, "PLUGIN", "", "order by nb1.xmldata.value('(genxml/hidden/index)[1]','float')");

            foreach (var p in rtnList)
            {
                var existingrecord = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PLUGIN", p.GUIDKey);
                if (existingrecord == null)
                {
                    var filepath = HttpContext.Current.Server.MapPath(p.GetXmlProperty("genxml/textbox/path"));
                    if (File.Exists(filepath))
                    {
                        p.ItemID   = -1;
                        p.PortalId = PortalSettings.Current.PortalId;
                        objCtrl.Update(p);
                    }
                    else
                    {
                        objCtrl.Delete(p.ItemID);
                    }
                }
            }
            PluginUtils.ResequenceRecords();
        }
예제 #3
0
        public static void CreateSystemPlugins()
        {
            var cachekey = "pluginlistsystem";
            var pList    = NBrightBuyUtils.GetCache(cachekey);

            if (pList == null)
            {
                var objCtrl = new NBrightBuyController();
                var rtnList = objCtrl.GetList(99999, -1, "PLUGIN", "", "order by nb1.xmldata.value('(genxml/hidden/index)[1]','float')");
                if (rtnList.Count == 0)
                {
                    var pluginList = new List <NBrightInfo>();
                    var info       = new NBrightInfo();
                    // no menuplugin.xml exists, so must be new install, get new config
                    var pluginfoldermappath = System.Web.Hosting.HostingEnvironment.MapPath(StoreSettings.NBrightBuyPath() + "/Plugins");
                    if (pluginfoldermappath != null && Directory.Exists(pluginfoldermappath) && File.Exists(pluginfoldermappath + "\\menu.config"))
                    {
                        var menuconfig = Utils.ReadFile(pluginfoldermappath + "\\menu.config");
                        if (menuconfig != "")
                        {
                            info.XMLData  = menuconfig;
                            info.PortalId = 99999;
                            pluginList    = CalcSystemPluginList(info);
                            CreateDBrecords(pluginList, 99999);
                            CreatePortalPlugins();
                        }
                    }
                }
                NBrightBuyUtils.SetCache(cachekey, "True");
            }
        }
예제 #4
0
 public static string CalcGroupPromo(int portalId)
 {
     var objCtrl = new NBrightBuyController();
     var l = objCtrl.GetList(portalId, -1, "CATEGORYPROMO", "", "", 0, 0, 0, 0, Utils.GetCurrentCulture());
     foreach (var p in l)
     {
         CalcGroupPromoItem(p);
     }
     return "OK";
 }
예제 #5
0
        public static List <NBrightInfo> GetPluginList()
        {
            var objCtrl = new NBrightBuyController();
            var rtnList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "PLUGIN", "", "order by nb1.xmldata.value('(genxml/hidden/index)[1]','float')");

            if (rtnList.Count == 0)
            {
                rtnList = CreatePortalPlugins();
            }
            return(rtnList);
        }
예제 #6
0
        public static void DeleteFriendlyImages(int productid)
        {
            var objCtrl          = new NBrightBuyController();
            var productImgFolder = StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + productid;

            Utils.DeleteFolder(productImgFolder, true);
            var list = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "PRDLANG", " and NB1.ParentItemId = " + productid);

            foreach (var i in list)
            {
                i.RemoveXmlNode("genxml/hidden/imageurl");
                i.RemoveXmlNode("genxml/hidden/imagepath");
                objCtrl.Update(i);
            }
        }
예제 #7
0
        /// <summary>
        /// Rebuild the CATCASCADE index records for a single category
        /// </summary>
        /// <param name="categoryid"></param>
        private void ReIndexSingleCascade(int categoryid)
        {
            if (categoryid > 0)
            {
                //get all category product ids from catxref sub category records.
                var xrefList       = new List <NBrightInfo>();
                var prodItemIdList = xrefList.Select(r => r.ParentItemId).ToList();
                var catList        = new List <GroupCategoryData>();
                var subCats        = GetSubCategoryList(catList, categoryid);
                foreach (var c in subCats)
                {
                    xrefList = _objCtrl.GetList(_portalId, -1, "CATXREF", " and xrefitemid = " + c.categoryid.ToString(""));
                    prodItemIdList.AddRange(xrefList.Select(r => r.ParentItemId));
                }
                //Get the current catascade records
                xrefList = _objCtrl.GetList(_portalId, -1, "CATCASCADE", " and xrefitemid = " + categoryid.ToString(""));
                var casacdeProdItemIdList = xrefList.Select(r => r.ParentItemId).ToList();

                //Update the catcascade records.
                foreach (var prodId in prodItemIdList)
                {
                    AddCatCascadeRecord(categoryid, prodId);
                    casacdeProdItemIdList.RemoveAll(i => i == prodId);
                }
                //remove any cascade records that no longer exists
                foreach (var productid in casacdeProdItemIdList)
                {
                    var strGuid = categoryid.ToString("") + "x" + productid.ToString("");
                    var nbi     = _objCtrl.GetByGuidKey(_portalId, -1, "CATCASCADE", strGuid);
                    if (nbi != null)
                    {
                        _objCtrl.Delete(nbi.ItemID);
                    }
                }
            }
        }
예제 #8
0
        public static void CopySystemPluginsToPortal()
        {
            var objCtrl = new NBrightBuyController();
            var rtnList = objCtrl.GetList(99999, -1, "PLUGIN", "", "order by nb1.xmldata.value('(genxml/hidden/index)[1]','float')");

            foreach (var p in rtnList)
            {
                var existingrecord = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "PLUGIN", p.GUIDKey);
                if (existingrecord == null)
                {
                    p.ItemID   = -1;
                    p.PortalId = PortalSettings.Current.PortalId;
                    objCtrl.Update(p);
                }
            }
            PluginUtils.ResequenceRecords();
        }
예제 #9
0
        private List <GroupCategoryData> GetGrpCatListFromDatabase(String lang = "")
        {
            // this process seems to be creating an error on DB connection after the cache is release.
            //[TODO: re-write this code to stop DB conection failure. For now Module level caching has been increased to 2 days to stop this processing re-running]

            var          objCtrl    = new NBrightBuyController();
            const string strOrderBy = " order by [XMLData].value('(genxml/hidden/recordsortorder)[1]','decimal(10,2)') ";
            var          grpcatList = new List <GroupCategoryData>();

            var l   = objCtrl.GetList(_portalId, -1, "CATEGORY", "", strOrderBy, 0, 0, 0, 0, "", "");
            var lg  = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", "and NB1.lang = '" + lang + "'", "", 0, 0, 0, 0, "", "");
            var lx  = objCtrl.GetList(_portalId, -1, "CATCASCADE", "", "", 0, 0, 0, 0, "", "");
            var lx2 = objCtrl.GetList(_portalId, -1, "CATXREF", "", "", 0, 0, 0, 0, "", "");

            lx.AddRange(lx2);
            foreach (var i in l)
            {
                var grpcat = new GroupCategoryData();
                grpcat.categoryid      = i.ItemID;
                grpcat.recordsortorder = i.GetXmlPropertyDouble("genxml/hidden/recordsortorder");
                grpcat.imageurl        = i.GetXmlProperty("genxml/hidden/imageurl");
                grpcat.categoryref     = i.GetXmlProperty("genxml/textbox/txtcategoryref");
                grpcat.propertyref     = i.GetXmlProperty("genxml/textbox/propertyref");
                grpcat.archived        = i.GetXmlPropertyBool("genxml/checkbox/chkarchived");
                grpcat.ishidden        = i.GetXmlPropertyBool("genxml/checkbox/chkishidden");
                grpcat.disabled        = i.GetXmlPropertyBool("genxml/checkbox/chkdisable");
                grpcat.grouptyperef    = i.GetXmlProperty("genxml/dropdownlist/ddlgrouptype");
                grpcat.attributecode   = i.GetXmlProperty("genxml/dropdownlist/ddlattrcode");
                grpcat.parentcatid     = i.ParentItemId;
                grpcat.entrycount      = GetEntryCount(lx, grpcat.categoryid);
                if (GroupsDictionary.ContainsKey(grpcat.grouptyperef))
                {
                    grpcat.groupname = GroupsDictionary[grpcat.grouptyperef];
                }

                // get the language data
                var langItem = GetLangData(lg, grpcat.categoryid);
                if (langItem != null)
                {
                    grpcat.categoryname = langItem.GetXmlProperty("genxml/textbox/txtcategoryname");
                    grpcat.categorydesc = langItem.GetXmlProperty("genxml/textbox/txtcategorydesc");
                    grpcat.seoname      = langItem.GetXmlProperty("genxml/textbox/txtseoname");
                    if (grpcat.seoname == "")
                    {
                        grpcat.seoname = langItem.GetXmlProperty("genxml/textbox/txtcategoryname");
                    }
                    grpcat.metadescription    = langItem.GetXmlProperty("genxml/textbox/txtmetadescription");
                    grpcat.metakeywords       = langItem.GetXmlProperty("genxml/textbox/txtmetakeywords");
                    grpcat.seopagetitle       = langItem.GetXmlProperty("genxml/textbox/txtseopagetitle");
                    grpcat.message            = langItem.GetXmlProperty("genxml/edt/message");
                    grpcat.categoryrefGUIDKey = langItem.GUIDKey;
                }

                //get parents
                var p = GetParentList(l, grpcat.categoryid);
                foreach (var pi in p)
                {
                    grpcat.Parents.Add(pi.ItemID);
                }

                grpcatList.Add(grpcat);
            }

            // we don;t have the depth number at this point, so use recussive call to calc it.
            CalcCategoryDepthList(grpcatList, 0, 0);

            return(grpcatList);
        }
예제 #10
0
        private List<GroupCategoryData> GetGrpCatListFromDatabase(String lang = "")
        {
            // this process seems to be creating an error on DB connection after the cache is release.
            //[TODO: re-write this code to stop DB conection failure. For now Module level caching has been increased to 2 days to stop this processing re-running]

            var objCtrl = new NBrightBuyController();
            const string strOrderBy = " order by [XMLData].value('(genxml/hidden/recordsortorder)[1]','decimal(10,2)') ";
            var grpcatList = new List<GroupCategoryData>();

            var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATEGORY", "", strOrderBy, 0, 0, 0, 0, "", "");
            var lg = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATEGORYLANG", "and NB1.lang = '" + lang + "'", "", 0, 0, 0, 0, "", "");
            var lx = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", "", "", 0, 0, 0, 0, "", "");
            var lx2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATXREF", "", "", 0, 0, 0, 0, "", "");
            lx.AddRange(lx2);
            foreach (var i in l)
            {
                var grpcat = new GroupCategoryData();
                grpcat.categoryid = i.ItemID;
                grpcat.recordsortorder = i.GetXmlPropertyDouble("genxml/hidden/recordsortorder");
                grpcat.imageurl = i.GetXmlProperty("genxml/hidden/imageurl");
                grpcat.categoryref = i.GetXmlProperty("genxml/textbox/txtcategoryref");
                grpcat.propertyref = i.GetXmlProperty("genxml/textbox/propertyref");
                grpcat.archived = i.GetXmlPropertyBool("genxml/checkbox/chkarchived");
                grpcat.ishidden = i.GetXmlPropertyBool("genxml/checkbox/chkishidden");
                grpcat.disabled = i.GetXmlPropertyBool("genxml/checkbox/chkdisable");
                grpcat.grouptyperef = i.GetXmlProperty("genxml/dropdownlist/ddlgrouptype");
                grpcat.parentcatid = i.ParentItemId;
                grpcat.entrycount = GetEntryCount(lx, grpcat.categoryid);
                if (GroupsDictionary.ContainsKey(grpcat.grouptyperef)) grpcat.groupname = GroupsDictionary[grpcat.grouptyperef];

                // get the language data
                var langItem =  GetLangData(lg,grpcat.categoryid);
                if (langItem != null)
                {
                    grpcat.categoryname = langItem.GetXmlProperty("genxml/textbox/txtcategoryname");
                    grpcat.categorydesc = langItem.GetXmlProperty("genxml/textbox/txtcategorydesc");
                    grpcat.seoname = langItem.GetXmlProperty("genxml/textbox/txtseoname");
                    if (grpcat.seoname == "") grpcat.seoname = langItem.GetXmlProperty("genxml/textbox/txtcategoryname");
                    grpcat.metadescription = langItem.GetXmlProperty("genxml/textbox/txtmetadescription");
                    grpcat.metakeywords = langItem.GetXmlProperty("genxml/textbox/txtmetakeywords");
                    grpcat.seopagetitle = langItem.GetXmlProperty("genxml/textbox/txtseopagetitle");
                    grpcat.message = langItem.GetXmlProperty("genxml/edt/message");
                    grpcat.categoryrefGUIDKey = langItem.GUIDKey;
                }

                //get parents
                var p = GetParentList(l,grpcat.categoryid);
                foreach (var pi in p)
                    grpcat.Parents.Add(pi.ItemID);

                grpcatList.Add(grpcat);
            }

            // we don;t have the depth number at this point, so use recussive call to calc it.
            CalcCategoryDepthList(grpcatList, 0, 0);

            return grpcatList;
        }
예제 #11
0
        public static string GetRelatedCats(int portalId, string parentItemId, string cultureCode, string templatePrefix, string controlMapPath, Boolean AllowCache = true)
        {
            var strOut = "";

            if (Utils.IsNumeric(parentItemId))
            {
                if (!AllowCache)
                {
                    //Remove any cache for the module -1, we don't want any cache in BO
                    //All xref records are portal wide, hence -1 in cahce key.
                    NBrightBuyUtils.RemoveModCache(-1);
                }

                var objCtrl = new NBrightBuyController();

                var templCtrl = new TemplateController(controlMapPath);

                var hTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedheader + ".html", Utils.GetCurrentCulture());
                var bTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedbody + ".html", Utils.GetCurrentCulture());
                var fTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedfooter + ".html", Utils.GetCurrentCulture());

                // replace Settings tags for ajax to work.
                hTempl = Utils.ReplaceUrlTokens(hTempl);
                bTempl = Utils.ReplaceUrlTokens(bTempl);
                fTempl = Utils.ReplaceUrlTokens(fTempl);

                var strFilter  = " and parentitemid = " + parentItemId;
                var strOrderBy = GenXmlFunctions.GetSqlOrderBy(hTempl);
                if (strOrderBy == "")
                {
                    strOrderBy = GenXmlFunctions.GetSqlOrderBy(bTempl);
                }

                var l       = objCtrl.GetList(portalId, -1, "CATXREF", strFilter, strOrderBy);
                var objList = new List <NBrightInfo>();

                foreach (var objXref in l)
                {
                    var o = objCtrl.Get(objXref.XrefItemId, "CATEGORYLANG", cultureCode);
                    if (o != null)
                    {
                        if (objXref.GetXmlProperty("genxml/hidden/defaultcat") != "")
                        {
                            // set the default flag in the category, for display in the entry only.
                            o.SetXmlProperty("genxml/hidden/defaultcat", "True");
                        }
                        o.GUIDKey  = objXref.ItemID.ToString();                              // overwrite with xref itemid for delete ajax action.
                        o.TextData = o.GetXmlProperty("genxml/lang/genxml/textbox/txtname"); // set for sort
                        o.Lang     = cultureCode;                                            // set lang so the GenXmlTemplateExt can pickup the edit langauge.
                        objList.Add(o);
                        objList.Sort(delegate(NBrightInfo p1, NBrightInfo p2) { return(p1.TextData.CompareTo(p2.TextData)); });
                    }
                }

                var obj = new NBrightInfo();
                strOut += GenXmlFunctions.RenderRepeater(obj, hTempl);
                strOut += GenXmlFunctions.RenderRepeater(objList, bTempl);
                strOut += GenXmlFunctions.RenderRepeater(obj, fTempl);
            }

            return(strOut);
        }
예제 #12
0
        /// <summary>
        /// Select categories linked to product, by groupref
        /// </summary>
        /// <param name="productid"></param>
        /// <param name="groupref">groupref for select, "" = all, "cat"= Category only, "!cat" = all non-category, "{groupref}"=this group only</param>
        /// <param name="cascade">get all cascade records to get all parent categories</param>
        /// <returns></returns>
        public List<GroupCategoryData> GetProductCategories(int productid, String groupref = "", Boolean cascade = false)
        {
            var objCtrl = new NBrightBuyController();
            var catxrefList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATXREF", " and NB1.[ParentItemId] = " + productid);

            if (cascade)
            {
                var catcascadeList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and NB1.[ParentItemId] = " + productid);
                foreach (var c in catcascadeList)
                {
                    catxrefList.Add(c);
                }
            }

            var notcat = "";
            if (groupref == "!cat")
            {
                groupref = "";
                notcat = "cat";
            }

            var joinItems = (from d1 in GrpCategoryList
                             join d2 in catxrefList on d1.categoryid equals d2.XrefItemId
                             where (d1.grouptyperef == groupref || groupref == "") && d1.grouptyperef != notcat
                             select d1).OrderBy(d1 => d1.grouptyperef).ThenBy(d1 => d1.breadcrumb).ToList<GroupCategoryData>();
            return joinItems;
        }
예제 #13
0
        private String DoProductIdx(DotNetNuke.Entities.Portals.PortalInfo portal, DateTime lastrun, Boolean debug)
        {
            if (debug)
            {
                InternalSearchController.Instance.DeleteAllDocuments(portal.PortalID, SearchHelper.Instance.GetSearchTypeByName("tab").SearchTypeId);
            }
            var searchDocs = new List<SearchDocument>();
            var culturecodeList = DnnUtils.GetCultureCodeList(portal.PortalID);
            var storeSettings = new StoreSettings(portal.PortalID);
            foreach (var lang in culturecodeList)
            {
                var strContent = "";
                // select all products
                var objCtrl = new NBrightBuyController();
                var strFilter = " and NB1.ModifiedDate > convert(datetime,'" + lastrun.ToString("s") + "') ";
                if (debug) strFilter = "";
                var l = objCtrl.GetList(portal.PortalID, -1, "PRD", strFilter);

                foreach (var p in l)
                {
                    var prodData = new ProductData(p.ItemID, lang);

                    strContent = prodData.Info.GetXmlProperty("genxml/textbox/txtproductref") + " : " + prodData.SEODescription + " " + prodData.SEOName + " " + prodData.SEOTagwords + " " + prodData.SEOTitle;

                    if (strContent != "")
                    {
                        var tags = new List<String>();
                        tags.Add("nbsproduct");

                        //Get the description string
                        string strDescription = HtmlUtils.Shorten(HtmlUtils.Clean(strContent, false), 100, "...");
                        var searchDoc = new SearchDocument();
                        // Assigns as a Search key the SearchItems'
                        searchDoc.UniqueKey = prodData.Info.ItemID.ToString("");
                        searchDoc.QueryString = "ref=" + prodData.Info.GetXmlProperty("genxml/textbox/txtproductref");
                        searchDoc.Title = prodData.ProductName;
                        searchDoc.Body = strContent;
                        searchDoc.Description = strDescription;
                        if (debug)
                            searchDoc.ModifiedTimeUtc = DateTime.Now.Date;
                        else
                            searchDoc.ModifiedTimeUtc = prodData.Info.ModifiedDate;
                        searchDoc.AuthorUserId = 1;
                        searchDoc.TabId = storeSettings.ProductDetailTabId;
                        searchDoc.PortalId = portal.PortalID;
                        searchDoc.SearchTypeId = SearchHelper.Instance.GetSearchTypeByName("tab").SearchTypeId;
                        searchDoc.CultureCode = lang;
                        searchDoc.Tags = tags;
                        //Add Module MetaData
                        searchDoc.ModuleDefId = 0;
                        searchDoc.ModuleId = 0;

                        searchDocs.Add(searchDoc);
                    }
                }
            }

            //Index
            InternalSearchController.Instance.AddSearchDocuments(searchDocs);
            InternalSearchController.Instance.Commit();

            return " - NBS-DNNIDX scheduler ACTIVATED ";
        }
예제 #14
0
        public void RemoveCategory(int categoryid)
        {
            var objCtrl = new NBrightBuyController();
            if (Utils.IsNumeric(DataRecord.GetXmlProperty("genxml/defaultcatid")) && categoryid == Convert.ToInt32(DataRecord.GetXmlProperty("genxml/defaultcatid")))
            {
                DataRecord.SetXmlProperty("genxml/defaultcatid", "");
                objCtrl.Update(DataRecord);
            }

            var parentitemid = Info.ItemID.ToString("");
            var xrefitemid = categoryid.ToString("");
            var objQual = DotNetNuke.Data.DataProvider.Instance().ObjectQualifier;
            var dbOwner = DotNetNuke.Data.DataProvider.Instance().DatabaseOwner;
            var stmt = "delete from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATXREF' and XrefItemId = " + xrefitemid + " and parentitemid = " + parentitemid;
            objCtrl.ExecSql(stmt);
            //remove all cascade xref
            var objGrpCtrl = new GrpCatController(_lang, true);
            var parentcats = objGrpCtrl.GetCategory(Convert.ToInt32(xrefitemid));
            if (parentcats != null)
            {
                foreach (var p in parentcats.Parents)
                {
                    var xreflist = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.parentitemid = " + parentitemid);
                    if (xreflist != null)
                    {
                        var deleterecord = true;
                        foreach (var xref in xreflist)
                        {
                            var catid = xref.XrefItemId;
                            var xrefparentcats = objGrpCtrl.GetCategory(Convert.ToInt32(catid));
                            if (xrefparentcats != null && xrefparentcats.Parents.Contains(p))
                            {
                                deleterecord = false;
                                break;
                            }
                        }
                        if (deleterecord)
                        {
                            stmt = "delete from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATCASCADE' and XrefItemId = " + p.ToString("") + " and parentitemid = " + parentitemid;
                            objCtrl.ExecSql(stmt);
                        }

                    }
                }
            }
        }
예제 #15
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl    = new NBrightBuyController();

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord        = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang   = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            var defaultname = Name;

            if (defaultname == "")
            {
                // find a valid default name
                foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                {
                    var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                    if (l.Count == 1)
                    {
                        var nbi2 = (NBrightInfo)l[0];
                        if (nbi2.GetXmlProperty("genxml/textbox/groupname") != "")
                        {
                            defaultname = nbi2.GetXmlProperty("genxml/textbox/groupname");
                            Name        = defaultname;
                            Save();
                            break;
                        }
                    }
                }
            }

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
            {
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang   = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }

                if (l.Count == 1)
                {
                    var nbi2 = (NBrightInfo)l[0];
                    if (nbi2.GetXmlProperty("genxml/textbox/groupname") == "")
                    {
                        // if we have no name, use the default name we found early to update.
                        nbi2.SetXmlProperty("genxml/textbox/groupname", defaultname);
                        objCtrl.Update(nbi2);
                    }
                }

                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2)
                        {
                            objCtrl.Delete(i.ItemID);
                        }
                        lp += 1;
                    }
                }
            }

            if (Ref == "")
            {
                Ref = DataRecord.GUIDKey;
                objCtrl.Update(DataRecord);
            }

            // add required field values to make getting group easier.
            if (Ref != "" && DataRecord.GUIDKey != Ref)
            {
                DataRecord.GUIDKey = Ref;
                objCtrl.Update(DataRecord);
            }

            // check we have a groupt type, it might be missing if upgraded.
            if (Type == "")
            {
                if (Ref == "cat")
                {
                    Type = "2";
                }
                else
                {
                    Type = "1";
                }
                objCtrl.Update(DataRecord);
            }


            return(errorcount);
        }
예제 #16
0
        private string DeleteAllCatXref(HttpContext context)
        {
            var strOut = NBrightBuyUtils.GetResxMessage("general_fail");
            try
            {
                var settings = GetAjaxFields(context);

                if (settings.ContainsKey("itemid"))
                {
                    var strFilter = " and XrefItemId = {Settings:itemid} ";
                    strFilter = Utils.ReplaceSettingTokens(strFilter, settings);

                    var objCtrl = new NBrightBuyController();
                    var objList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATXREF", strFilter);

                    foreach (var obj in objList)
                    {
                        DeleteCatXref(settings["itemid"], obj.ParentItemId.ToString(""));
                    }
                    strOut = NBrightBuyUtils.GetResxMessage();
                }
            }
            catch (Exception e)
            {
                return e.ToString();
            }
            return strOut;
        }
예제 #17
0
        public int Validate()
        {
            var errorcount = 0;

            var objCtrl = new NBrightBuyController();

            SetGuidKey();
            objCtrl.Update(DataRecord);

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                    DataLangRecord = (NBrightInfo) l[0].Clone();
                else
                    DataLangRecord = new NBrightInfo(true);

                DataLangRecord.ItemID = -1;
                DataLangRecord.ValidateXmlFormat();
                DataLangRecord.TypeCode = _typeLangCode;
                DataLangRecord.ParentItemId = Info.ItemID;
                DataLangRecord.Lang = _lang;
                objCtrl.Update(DataLangRecord);
            }

            //Fix image paths
            var lp = 1;
            foreach (var i in Imgs)
            {
                if (!File.Exists(i.GetXmlProperty("genxml/hidden/imagepath"))) // products shared across portals may have different image path.
                {
                    if (!i.GetXmlProperty("genxml/hidden/imageurl").StartsWith(_storeSettings.FolderImages))
                    {
                        var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                        DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imageurl", _storeSettings.FolderImages.TrimEnd('/') + "/" + iname);
                        errorcount += 1;
                    }
                    if (!i.GetXmlProperty("genxml/hidden/imagepath").StartsWith(_storeSettings.FolderImagesMapPath))
                    {
                        var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                        DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imagepath", _storeSettings.FolderImagesMapPath.TrimEnd('\\') + "\\" + iname);
                        errorcount += 1;
                    }
                }
                lp += 1;
            }
            //Fix document paths
            lp = 1;
            foreach (var d in Docs)
            {
                if (!File.Exists(d.GetXmlProperty("genxml/hidden/filepath"))) // products shared across portals may have different path.
                {
                    if (!d.GetXmlProperty("genxml/hidden/filepath").StartsWith(_storeSettings.FolderDocumentsMapPath))
                    {
                        var fname = d.GetXmlProperty("genxml/textbox/txtfilename");
                        if (d.GetXmlProperty("genxml/hidden/filerelpath") != "")
                        {
                            fname = Path.GetFileName("D:" + d.GetXmlProperty("genxml/hidden/filerelpath").Replace("/", "\\"));
                        }
                        DataRecord.SetXmlProperty("genxml/docs/genxml/hidden/filepath", _storeSettings.FolderDocumentsMapPath.TrimEnd('\\') + "\\" + fname);
                        errorcount += 1;
                    }
                }
                lp += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, _typeLangCode, " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp2 = 1;
                    foreach (var i in l2)
                    {
                        if (lp2 >= 2) objCtrl.Delete(i.ItemID);
                        errorcount += 1;
                        lp2 += 1;
                    }
                }
            }

            // remove duplicate category xrefs.
            var catlist = GetCategories();
            foreach (var c in catlist)
            {
                var l = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = " + c.categoryid.ToString(""));
                if (l.Count > 1)
                {
                    var catlp = 0;
                    foreach (var i in l)
                    {
                        if (catlp >= 1)
                        {
                            objCtrl.Delete(i.ItemID);
                            errorcount += 1;
                        }
                        catlp += 1;
                    }
                }
            }

            // remove duplicate catcascade records
            var cascadeList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and NB1.ParentItemId = " + Info.ItemID.ToString("") );
            foreach (var c in cascadeList)
            {
                var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and GUIDKey = '" + c.GUIDKey + "'");
                if (l2.Count > 1)
                {
                    for (int i = 1; i < l2.Count; i++)
                    {
                        objCtrl.Delete(l2[i].ItemID);
                        errorcount += 1;
                    }
                }
            }

            // remove any unlinked catacscade records
            cascadeList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATCASCADE", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.XrefItemId = 0");
            foreach (var c in cascadeList)
            {
                objCtrl.Delete(c.ItemID);
                errorcount += 1;
            }

            return errorcount;
        }
예제 #18
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl = new NBrightBuyController();

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            var defaultname = Name;
            if (defaultname == "")
            {
                // find a valid default name
                foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                {
                    var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                    if (l.Count == 1)
                    {
                        var nbi2 = (NBrightInfo) l[0];
                        if (nbi2.GetXmlProperty("genxml/textbox/groupname") != "")
                        {
                            defaultname = nbi2.GetXmlProperty("genxml/textbox/groupname");
                            Name = defaultname;
                            Save();
                            break;
                        }
                    }
                }
            }

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
            {
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }

                if (l.Count == 1)
                {
                    var nbi2 = (NBrightInfo) l[0];
                    if (nbi2.GetXmlProperty("genxml/textbox/groupname") == "")
                    {
                        // if we have no name, use the default name we found early to update.
                        nbi2.SetXmlProperty("genxml/textbox/groupname", defaultname);
                        objCtrl.Update(nbi2);
                    }
                }

                if (l.Count > 1)
                {
                    // we have more records than should exists, remove any old ones.
                    var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "GROUPLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                        if (lp >= 2) objCtrl.Delete(i.ItemID);
                        lp += 1;
                    }
                }
            }

            // add required field values to make getting group easier.
            if (DataRecord.GUIDKey != Ref)
            {
                DataRecord.GUIDKey = Ref;
                objCtrl.Update(DataRecord);
            }

            return errorcount;
        }
예제 #19
0
 public static void RemoveModCachePortalWide(int portalid)
 {
     var mCtrl = new NBrightBuyController();
     var l = mCtrl.GetList(portalid, -1, "SETTINGS");
     foreach (var obj in l)
     {
         RemoveModCache(obj.ModuleId);
     }
     RemoveModCache(-1);
 }
예제 #20
0
        public static int ValidateStore()
        {
            // clear all cache to start.
            DataCache.ClearCache();

            var objCtrl = new NBrightBuyController();
            var errcount = 0;

            // Validate Products
            var prodList = objCtrl.GetList(DotNetNuke.Entities.Portals.PortalSettings.Current.PortalId, -1, "PRD");
            foreach (var p in prodList)
            {
                var prodData = ProductUtils.GetProductData(p.ItemID, StoreSettings.Current.EditLanguage);
                errcount += prodData.Validate();
            }

            // Validate Categories
            var catList = objCtrl.GetList(DotNetNuke.Entities.Portals.PortalSettings.Current.PortalId, -1, "CATEGORY");
            foreach (var c in catList)
            {
                var catData = CategoryUtils.GetCategoryData(c.ItemID, StoreSettings.Current.EditLanguage);
                errcount += catData.Validate();
            }

            // Validate Groups
            var grpList = objCtrl.GetList(DotNetNuke.Entities.Portals.PortalSettings.Current.PortalId, -1, "GROUP");
            foreach (var c in grpList)
            {
                var grpData = new GroupData(c.ItemID, StoreSettings.Current.EditLanguage);
                errcount += grpData.Validate();
            }

            // reset catid from catref
            var l = objCtrl.GetDataList(PortalSettings.Current.PortalId, -1, "SETTINGS", "", Utils.GetCurrentCulture(), " and [XMLdata].value('(genxml/catref)[1]','nvarchar(max)') != ''","");
            foreach (var s in l)
            {
                var info = ModuleSettingsResetCatIdFromRef(s);
                objCtrl.Update(info);
            }

            return errcount;
        }
예제 #21
0
 public List<NBrightInfo> GetDirectChildren()
 {
     var objCtrl = new NBrightBuyController();
     var l = objCtrl.GetList(_portalId, -1, "CATEGORY", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
     return l;
 }
        private String GetData(HttpContext context,bool clearCache = false)
        {
            try
            {
                var objCtrl = new NBrightBuyController();
                var strOut = "";
                //get uploaded params
                var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);
                SetContextLangauge(ajaxInfo); // Ajax breaks context with DNN, so reset the context language to match the client.

                var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
                var typeCode = ajaxInfo.GetXmlProperty("genxml/hidden/typecode");
                var newitem = ajaxInfo.GetXmlProperty("genxml/hidden/newitem");
                var selecteditemid = ajaxInfo.GetXmlProperty("genxml/hidden/selecteditemid");
                var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
                var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
                if (editlang == "") editlang = _lang;

                if (!Utils.IsNumeric(moduleid)) moduleid = "-2"; // use moduleid -2 for razor

                if (clearCache) NBrightBuyUtils.RemoveModCache(Convert.ToInt32(moduleid));

                if (newitem == "new") selecteditemid = AddNew(moduleid, typeCode);

                var templateControl = "/DesktopModules/NBright/NBrightBuy/Providers/PromoProvider";

                if (Utils.IsNumeric(selecteditemid))
                {
                    // do edit field data if a itemid has been selected
                    var obj = objCtrl.Get(Convert.ToInt32(selecteditemid), "",editlang);
                    strOut = NBrightBuyUtils.RazorTemplRender(typeCode.ToLower() + "fields.cshtml", Convert.ToInt32(moduleid), _lang + itemid + editlang + selecteditemid, obj, templateControl, _lang);
                }
                else
                {
                    // Return list of items
                    var l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), typeCode, "", " order by [XMLData].value('(genxml/textbox/validuntil)[1]','nvarchar(50)'), ModifiedDate desc", 0, 0, 0, 0, editlang);
                    strOut = NBrightBuyUtils.RazorTemplRender(typeCode.ToLower() + "list.cshtml", Convert.ToInt32(moduleid), _lang + editlang, l, templateControl, _lang);
                }

                return strOut;

            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
예제 #23
0
        public static string GetRelatedCats(int portalId, string parentItemId, string cultureCode, string templatePrefix, string controlMapPath, Boolean AllowCache = true)
        {
            var strOut = "";
            if (Utils.IsNumeric(parentItemId))
            {
                if (!AllowCache)
                {
                    //Remove any cache for the module -1, we don't want any cache in BO
                    //All xref records are portal wide, hence -1 in cahce key.
                    NBrightBuyUtils.RemoveModCache(-1);
                }

                var objCtrl = new NBrightBuyController();

                var templCtrl = new TemplateController(controlMapPath);

                var hTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedheader + ".html", Utils.GetCurrentCulture());
                var bTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedbody + ".html", Utils.GetCurrentCulture());
                var fTempl = templCtrl.GetTemplateData(templatePrefix + "_" + ModuleEventCodes.selectedfooter + ".html", Utils.GetCurrentCulture());

                // replace Settings tags for ajax to work.
                hTempl = Utils.ReplaceUrlTokens(hTempl);
                bTempl = Utils.ReplaceUrlTokens(bTempl);
                fTempl = Utils.ReplaceUrlTokens(fTempl);

                var strFilter = " and parentitemid = " + parentItemId;
                var strOrderBy = GenXmlFunctions.GetSqlOrderBy(hTempl);
                if (strOrderBy == "")
                {
                    strOrderBy = GenXmlFunctions.GetSqlOrderBy(bTempl);
                }

                var l = objCtrl.GetList(portalId, -1, "CATXREF", strFilter, strOrderBy);
                var objList = new List<NBrightInfo>();

                foreach (var objXref in l)
                {
                    var o = objCtrl.Get(objXref.XrefItemId, "CATEGORYLANG", cultureCode);
                    if (o != null)
                    {
                        if (objXref.GetXmlProperty("genxml/hidden/defaultcat") != "")
                        {
                            // set the default flag in the category, for display in the entry only.
                            o.SetXmlProperty("genxml/hidden/defaultcat", "True");
                        }
                        o.GUIDKey = objXref.ItemID.ToString(); // overwrite with xref itemid for delete ajax action.
                        o.TextData = o.GetXmlProperty("genxml/lang/genxml/textbox/txtname"); // set for sort
                        o.Lang = cultureCode; // set lang so the GenXmlTemplateExt can pickup the edit langauge.
                        objList.Add(o);
                        objList.Sort(delegate(NBrightInfo p1, NBrightInfo p2) { return p1.TextData.CompareTo(p2.TextData); });
                    }
                }

                var obj = new NBrightInfo();
                strOut += GenXmlFunctions.RenderRepeater(obj, hTempl);
                strOut += GenXmlFunctions.RenderRepeater(objList, bTempl);
                strOut += GenXmlFunctions.RenderRepeater(obj, fTempl);

            }

            return strOut;
        }
예제 #24
0
        public List <NBrightInfo> GetDirectChildren()
        {
            var l = _objCtrl.GetList(_portalId, -1, "CATEGORY", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));

            return(l);
        }
예제 #25
0
        public int Copy()
        {
            var objCtrl = new NBrightBuyController();

            //Copy Base record
            var dr = (NBrightInfo)DataRecord.Clone();
            dr.ItemID = -1;
            dr.SetXmlProperty("genxml/importref", Utils.GetUniqueKey());
            var newid = objCtrl.Update(dr);

            // copy all language records
            var l = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
            foreach (var dlr in l)
            {
                dlr.ParentItemId = newid;
                dlr.ItemID = -1;
                objCtrl.Update(dlr);
            }

            // copy CATXREF records
            l = objCtrl.GetList(_portalId, -1, "CATXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
            foreach (var dr1 in l)
            {
                dr1.ParentItemId = newid;
                dr1.ItemID = -1;
                dr1.GUIDKey = dr1.GUIDKey.Replace("x" + Info.ItemID.ToString(""), "x" + newid.ToString(""));
                objCtrl.Update(dr1);
            }

            // copy CATCASCADE records
            l = objCtrl.GetList(_portalId, -1, "CATCASCADE", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
            foreach (var dr2 in l)
            {
                dr2.ParentItemId = newid;
                dr2.ItemID = -1;
                dr2.GUIDKey = dr2.GUIDKey.Replace("x" + Info.ItemID.ToString(""), "x" + newid.ToString(""));
                objCtrl.Update(dr2);
            }

            // copy PRDXREF records
            l = objCtrl.GetList(_portalId, -1, "PRDXREF", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
            foreach (var dr3 in l)
            {
                dr3.ParentItemId = newid;
                dr3.ItemID = -1;
                dr3.GUIDKey = dr3.GUIDKey.Replace("x" + Info.ItemID.ToString(""), "x" + newid.ToString(""));
                objCtrl.Update(dr);
            }

            return newid;
        }
예제 #26
0
        private String CopyAllCatXref(HttpContext context,Boolean moverecords = false)
        {
            var strOut = NBrightBuyUtils.GetResxMessage("general_fail");
            try
            {
                var settings = GetAjaxFields(context);
                var strFilter = " and XrefItemId = {Settings:itemid} ";

                strFilter = Utils.ReplaceSettingTokens(strFilter, settings);

                var newcatid = "";
                if (settings.ContainsKey("selectedcatid")) newcatid = settings["selectedcatid"];

                if (Utils.IsNumeric(newcatid) && settings.ContainsKey("itemid"))
                {
                    var objCtrl = new NBrightBuyController();
                    var objList = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "CATXREF", strFilter);

                    foreach (var obj in objList)
                    {
                        var strGuid = newcatid + "x" + obj.ParentItemId.ToString("");
                        var nbi = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "CATXREF", strGuid);
                        if (nbi == null)
                        {
                            if (!moverecords) obj.ItemID = -1;
                            obj.XrefItemId = Convert.ToInt32(newcatid);
                            obj.GUIDKey = strGuid;
                            obj.XMLData = null;
                            obj.TextData = null;
                            obj.Lang = null;
                            objCtrl.Update(obj);
                            //add all cascade xref
                            var objGrpCtrl = new GrpCatController(_lang, true);
                            var parentcats = objGrpCtrl.GetCategory(Convert.ToInt32(newcatid));
                            foreach (var p in parentcats.Parents)
                            {
                                strGuid = p.ToString("") + "x" + obj.ParentItemId.ToString("");
                                nbi = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "CATCASCADE", strGuid);
                                if (nbi == null)
                                {
                                    obj.XrefItemId = p;
                                    obj.TypeCode = "CATCASCADE";
                                    obj.GUIDKey = strGuid;
                                    objCtrl.Update(obj);
                                }
                            }
                        }
                    }

                    if (moverecords) DeleteAllCatXref(context);

                    strOut = NBrightBuyUtils.GetResxMessage();
                }

            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            return strOut;
        }
예제 #27
0
 public List<NBrightInfo> GetRelatedProducts()
 {
     var objCtrl = new NBrightBuyController();
     var strSelectedIds = "";
     var arylist = objCtrl.GetList(_portalId, -1, "PRDXREF", " and NB1.parentitemid = " + Info.ItemID.ToString(""));
     foreach (var obj in arylist)
     {
         strSelectedIds += obj.XrefItemId.ToString("") + ",";
     }
     var relList = new List<NBrightInfo>();
     if (strSelectedIds.TrimEnd(',') != "")
     {
         var strFilter = " and NB1.[ItemId] in (" + strSelectedIds.TrimEnd(',') + ") ";
         relList = objCtrl.GetDataList(_portalId, -1, "PRD", "PRDLANG", _lang, strFilter, "");
     }
     return relList;
 }
예제 #28
0
        public int Validate()
        {
            var errorcount = 0;

            var objCtrl = new NBrightBuyController();

            SetGuidKey();
            objCtrl.Update(DataRecord);

            DataRecord.ValidateXmlFormat();
            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                    DataLangRecord = (NBrightInfo) l[0].Clone();
                else
                    DataLangRecord = new NBrightInfo(true);

                DataLangRecord.ItemID = -1;
                DataLangRecord.ValidateXmlFormat();
                DataLangRecord.TypeCode = "PRDLANG";
                DataLangRecord.ParentItemId = Info.ItemID;
                DataLangRecord.Lang = _lang;
                objCtrl.Update(DataLangRecord);
            }

            //Fix image paths
            var lp = 1;
            foreach (var i in Imgs)
            {
                if (!i.GetXmlProperty("genxml/hidden/imageurl").StartsWith(_storeSettings.FolderImages))
                {
                    var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                    DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imageurl", _storeSettings.FolderImages.TrimEnd('/') + "/" + iname);
                    errorcount += 1;
                }
                if (!i.GetXmlProperty("genxml/hidden/imagepath").StartsWith(_storeSettings.FolderImagesMapPath))
                {
                    var iname = Path.GetFileName(i.GetXmlProperty("genxml/hidden/imagepath"));
                    DataRecord.SetXmlProperty("genxml/imgs/genxml[" + lp + "]/hidden/imagepath", _storeSettings.FolderImagesMapPath.TrimEnd('\\') + "\\" + iname);
                    errorcount += 1;
                }
                lp += 1;
            }
            //Fix document paths
            lp = 1;
            foreach (var d in Docs)
            {
                if (!d.GetXmlProperty("genxml/hidden/filepath").StartsWith(_storeSettings.FolderDocumentsMapPath))
                {
                    DataRecord.SetXmlProperty("genxml/docs/genxml/hidden/filepath", _storeSettings.FolderDocumentsMapPath.TrimEnd('\\') + "\\" + d.GetXmlProperty("genxml/textbox/txtfilename"));
                    errorcount += 1;
                }
                lp += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, "PRDLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp2 = 1;
                    foreach (var i in l2)
                    {
                        if (lp2 >= 2) objCtrl.Delete(i.ItemID);
                        lp2 += 1;
                    }
                }
            }

            return errorcount;
        }
예제 #29
0
        public int Validate()
        {
            var errorcount = 0;
            var objCtrl = new NBrightBuyController();

            // default any undefined group type as category (I think quickcategory v1.0.0 plugin causes this)
            if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype") == "")
            {
                DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", "cat");
                objCtrl.Update(DataRecord);
            }

            if (GroupType == "cat")
            {
                // the base category ref cannot have language dependant refs, we therefore just use a unique key
                var catref = DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                if (catref == "" || DataRecord.GUIDKey == "")
                {
                    catref = Utils.GetUniqueKey().ToLower();
                    DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                    DataRecord.GUIDKey = catref;
                    errorcount += 1;
                }

                if (DataRecord.GetXmlProperty("genxml/dropdownlist/ddlparentcatid") != DataRecord.ParentItemId.ToString())
                {
                    DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", DataRecord.ParentItemId.ToString());
                }

            }

            DataRecord.ValidateXmlFormat();

            if (DataLangRecord == null)
            {
                // we have no datalang record for this language, so get an existing one and save it.
                var l = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString(""));
                if (l.Count > 0)
                {
                    DataLangRecord = (NBrightInfo)l[0].Clone();
                    DataLangRecord.ItemID = -1;
                    DataLangRecord.Lang = _lang;
                    DataLangRecord.ValidateXmlFormat();
                    objCtrl.Update(DataLangRecord);
                }
            }

            // fix image
            var imgpath = DataRecord.GetXmlProperty("genxml/hidden/imagepath");
            var imgurl = DataRecord.GetXmlProperty("genxml/hidden/imageurl");
            var imagefilename = Path.GetFileName(imgpath);
            if (!imgpath.StartsWith(StoreSettings.Current.FolderImagesMapPath))
            {
                    DataRecord.SetXmlProperty("genxml/hidden/imagepath", StoreSettings.Current.FolderImagesMapPath.TrimEnd('\\') + "\\" + imagefilename);
                errorcount += 1;
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imagepath", "");
                errorcount += 1;
            }
            if (!imgurl.StartsWith(StoreSettings.Current.FolderImages))
            {
                    DataRecord.SetXmlProperty("genxml/hidden/imageurl", StoreSettings.Current.FolderImages.TrimEnd('/') + "/" + imagefilename);
                errorcount += 1;
            }
            if (imagefilename == "")
            {
                DataRecord.SetXmlProperty("genxml/hidden/imageurl", "");
                errorcount += 1;
            }

            // check guidkey is correct
            if (DataRecord.GUIDKey != CategoryRef)
            {
                DataRecord.GUIDKey = CategoryRef;
                errorcount += 1;
            }

            if (errorcount > 0) objCtrl.Update(DataRecord); // update if we find a error

            // fix langauge records
            foreach (var lang in DnnUtils.GetCultureCodeList(_portalId))
            {
                var l = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'");
                if (l.Count == 0 && DataLangRecord != null)
                {
                    var nbi = (NBrightInfo)DataLangRecord.Clone();
                    nbi.ItemID = -1;
                    nbi.Lang = lang;
                    objCtrl.Update(nbi);
                    errorcount += 1;
                }
                if (l.Count > 1)
                {
                    // we have more records than shoudl exists, remove any old ones.
                    var l2 = objCtrl.GetList(_portalId, -1, "CATEGORYLANG", " and NB1.ParentItemId = " + Info.ItemID.ToString("") + " and NB1.Lang = '" + lang + "'", "order by Modifieddate desc");
                    var lp = 1;
                    foreach (var i in l2)
                    {
                      if (lp >=2) objCtrl.Delete(i.ItemID);
                      lp += 1;
                    }
                }
            }

            // Build langauge refs
            if (GroupType == "cat")
            {
                var updaterequired = CategoryUtils.ValidateLangaugeRef(_portalId,CategoryId);
                if (updaterequired)
                {
                    // the catref has been updated, so reload the datarecord
                    DataLangRecord = objCtrl.GetDataLang(CategoryId, _lang);
                }
            }

            // fix groups with mismatching ddlgrouptype
            if (GroupType != "cat")
            {
                var grp = objCtrl.Get(DataRecord.ParentItemId, "GROUP");
                if (grp != null)
                {
                    if (grp.GUIDKey != GroupType)
                    {
                        DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grp.GUIDKey);
                        objCtrl.Update(DataRecord);
                        errorcount += 1;
                    }
                }
            }

            return errorcount;
        }
예제 #30
0
 public void AddProperty(String propertyref)
 {
     var objCtrl = new NBrightBuyController();
     var pinfo = objCtrl.GetByGuidKey(_portalId, -1,"CATEGORY",propertyref);
     if (pinfo == null)
     {
         // not using the unique ref, look for the friendly propertyref name.
         var l = objCtrl.GetList(_portalId, -1, "CATEGORY", " and [XMLData].value('(genxml/textbox/propertyref)[1]','nvarchar(max)') = '" + propertyref + "' ", "", 1);
         if (l.Any()) pinfo = l[0];
     }
     if (pinfo != null && Utils.IsNumeric(pinfo.ItemID) && pinfo.ItemID > 0) AddCategory(pinfo.ItemID);
 }
예제 #31
0
        private String GetOrderListData(Dictionary<String, String> settings, bool paging = true)
        {
            var strOut = "";

            if (!settings.ContainsKey("themefolder")) settings.Add("themefolder", "");
            if (!settings.ContainsKey("userid")) settings.Add("userid", "-1");
            if (!settings.ContainsKey("razortemplate")) settings.Add("razortemplate", "");
            if (!settings.ContainsKey("returnlimit")) settings.Add("returnlimit", "0");
            if (!settings.ContainsKey("pagenumber")) settings.Add("pagenumber", "0");
            if (!settings.ContainsKey("pagesize")) settings.Add("pagesize", "0");
            if (!settings.ContainsKey("searchtext")) settings.Add("searchtext", "");
            if (!settings.ContainsKey("dtesearchdatefrom")) settings.Add("dtesearchdatefrom", "");
            if (!settings.ContainsKey("dtesearchdateto")) settings.Add("dtesearchdateto", "");
            if (!settings.ContainsKey("searchorderstatus")) settings.Add("searchorderstatus", "");
            if (!settings.ContainsKey("portalid")) settings.Add("portalid", PortalSettings.Current.PortalId.ToString("")); // aways make sure we have portalid in settings

            if (!Utils.IsNumeric(settings["userid"])) settings["pagenumber"] = "1";
            if (!Utils.IsNumeric(settings["pagenumber"])) settings["pagenumber"] = "1";
            if (!Utils.IsNumeric(settings["pagesize"])) settings["pagesize"] = "20";
            if (!Utils.IsNumeric(settings["returnlimit"])) settings["returnlimit"] = "50";

            var themeFolder = settings["themefolder"];
            var razortemplate = settings["razortemplate"];
            var returnLimit = Convert.ToInt32(settings["returnlimit"]);
            var pageNumber = Convert.ToInt32(settings["pagenumber"]);
            var pageSize = Convert.ToInt32(settings["pagesize"]);
            var portalId = Convert.ToInt32(settings["portalid"]);
            var userid = settings["userid"];

            var searchText = settings["searchtext"];
            var searchdatefrom = settings["dtesearchdatefrom"];
            var searchdateto = settings["dtesearchdateto"];
            var searchorderstatus = settings["searchorderstatus"];

            var filter = "";
            if (searchText != "")
            {
                filter += " and (    (([xmldata].value('(genxml/billaddress/genxml/textbox/firstname)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/billaddress/genxml/textbox/lastname)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/billaddress/genxml/textbox/unit)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/billaddress/genxml/textbox/street)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/billaddress/genxml/textbox/postalcode)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/billaddress/genxml/textbox/email)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/firstname)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/lastname)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/unit)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/street)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/postalcode)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/shipaddress/genxml/textbox/email)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/productrefs)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                filter += " or (([xmldata].value('(genxml/ordernumber)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))  ) ";
            }

            if (searchdateto != "" && searchdatefrom != "")
            {
                filter += " and  ( ([xmldata].value('(genxml/createddate)[1]', 'datetime') >= convert(datetime,'" + searchdatefrom + "') ) and ([xmldata].value('(genxml/createddate)[1]', 'datetime') <= convert(datetime,'" + searchdateto + "') ) )  ";
            }
            if (searchdateto == "" && searchdatefrom != "")
            {
                filter += " and  ([xmldata].value('(genxml/createddate)[1]', 'datetime') >= convert(datetime,'" + searchdatefrom + "') ) ";
            }
            if (searchdateto != "" && searchdatefrom == "")
            {
                filter += " and ([xmldata].value('(genxml/createddate)[1]', 'datetime') <= convert(datetime,'" + searchdateto + "') ) ";
            }

            if (searchorderstatus != "")
            {
                filter += " and ([xmldata].value('(genxml/dropdownlist/orderstatus)[1]', 'nvarchar(max)') = '" + searchorderstatus + "')   ";
            }

            // check for user or manager.
            if (!NBrightBuyUtils.CheckRights())
            {
                if (Utils.IsNumeric(userid) && UserController.Instance.GetCurrentUserInfo().UserID == Convert.ToInt32(userid))
                {
                    filter += " and ( userid = " + userid + ")   ";
                }
                else
                {
                    return "";
                }
            }

            var recordCount = 0;

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

            var objCtrl = new NBrightBuyController();

            if (paging) // get record count for paging
            {
                if (pageNumber == 0) pageNumber = 1;
                if (pageSize == 0) pageSize = 20;

                // get only entity type required
                recordCount = objCtrl.GetListCount(PortalSettings.Current.PortalId, -1, "ORDER", filter);

            }

            var orderby = "   order by [XMLData].value('(genxml/createddate)[1]','nvarchar(20)') DESC, ModifiedDate DESC  ";
            var list = objCtrl.GetList(portalId, -1, "ORDER", filter, orderby, 0, pageNumber, pageSize, recordCount);

            var passSettings = settings;
            foreach (var s in StoreSettings.Current.Settings()) // copy store setting, otherwise we get a byRef assignement
            {
                if (passSettings.ContainsKey(s.Key))
                    passSettings[s.Key] = s.Value;
                else
                    passSettings.Add(s.Key, s.Value);
            }

            strOut = NBrightBuyUtils.RazorTemplRenderList(razortemplate, 0, "", list, "/DesktopModules/NBright/NBrightBuy", themeFolder, _lang, passSettings);

            // add paging if needed
            if (paging && (recordCount > pageSize))
            {
                var pg = new NBrightCore.controls.PagingCtrl();
                strOut += pg.RenderPager(recordCount, pageSize, pageNumber);
            }

            return strOut;
        }