Exemplo n.º 1
0
        public string CategoryHidden(HttpContext context)
        {
            try
            {
                var ajaxInfo     = NBrightBuyUtils.GetAjaxInfo(context);
                var parentitemid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/selectedcatid");
                if (parentitemid > 0)
                {
                    var catData = CategoryUtils.GetCategoryData(parentitemid, EditLangCurrent);

                    if (catData.DataRecord.GetXmlPropertyBool("genxml/checkbox/chkishidden"))
                    {
                        catData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", "False");
                    }
                    else
                    {
                        catData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", "True");
                    }
                    catData.Save();
                    // remove save GetData cache
                    NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
                    return("");
                }
                return("Invalid parentitemid");
            }
            catch (Exception e)
            {
                return(e.ToString());
            }
        }
Exemplo n.º 2
0
        private void Update(int productid)
        {
            if (productid > 0)
            {
                var prodData = ProductUtils.GetProductData(productid, StoreSettings.Current.EditLanguage);
                var strXml   = GenXmlFunctions.GetGenXml(rpData);
                var updInfo  = new NBrightInfo(true);
                updInfo.XMLData = strXml;

                GenXmlFunctions.UploadFile(rpData, "document", StoreSettings.Current.FolderDocumentsMapPath);
                var ctrl = ((HtmlGenericControl)rpData.Items[0].FindControl("hiddocument"));
                if (ctrl != null)
                {
                    var fName = ctrl.Attributes["value"];
                    updInfo.SetXmlProperty("genxml/hidden/hiddocument", fName);

                    var docCtrl = (FileUpload)rpData.Items[0].FindControl("document");
                    updInfo.SetXmlProperty("genxml/hidden/posteddocumentname", docCtrl.PostedFile.FileName);
                }

                prodData.Update(updInfo.XMLData);
                prodData.Save();
                prodData.FillEmptyLanguageFields();

                if (StoreSettings.Current.DebugModeFileOut)
                {
                    prodData.OutputDebugFile(PortalSettings.HomeDirectoryMapPath + "debug_productupdate.xml");
                }

                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
                ProductUtils.RemoveProductDataCache(prodData);
            }
        }
Exemplo n.º 3
0
        protected void CtrlItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var cArg  = e.CommandArgument.ToString();
            var param = new string[3];

            switch (e.CommandName.ToLower())
            {
            case "import":
                param[0] = "";
                var importXML = GenXmlFunctions.GetGenXml(rpData, "", StoreSettings.Current.FolderUploadsMapPath);
                var nbi       = new NBrightInfo(false);
                nbi.XMLData  = importXML;
                _recordXref  = new Dictionary <int, int>();
                _productList = new Dictionary <int, string>();
                DoImport(nbi);
                DoImportImages(nbi);
                DoImportDocs(nbi);

                /*
                 * Validation removed as it impact the performance of the import.
                 * A validation can be done by the store manager through the UI Admin Tools after the import.
                 */
//                    Validate();

                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
                NBrightBuyUtils.SetNotfiyMessage(ModuleId, "completed", NotifyCode.ok);
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "cancel":
                param[0] = "";
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;
            }
        }
Exemplo n.º 4
0
        public String DeleteCategory(HttpContext context, string editType = "")
        {
            var ajaxInfo      = NBrightBuyUtils.GetAjaxInfo(context);
            var selectedcatid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/selectedcatid");
            var categoryData  = CategoryUtils.GetCategoryData(selectedcatid, EditLangCurrent);

            categoryData.Delete();
            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            return(CategoryAdminList(context, editType, EditLangCurrent));
        }
Exemplo n.º 5
0
 private void Delete(String productId)
 {
     if (Utils.IsNumeric(productId) && Convert.ToInt32(productId) > 0)
     {
         var prodData = ProductUtils.GetProductData(Convert.ToInt32(productId), StoreSettings.Current.EditLanguage);
         prodData.Delete();
         NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
         ProductUtils.RemoveProductDataCache(prodData);
     }
 }
Exemplo n.º 6
0
        private void MoveRecord(int itemId)
        {
            var selecteditemid = GenXmlFunctions.GetField(rpDataH, "selecteditemid");

            if (Utils.IsNumeric(selecteditemid))
            {
                var movData          = CategoryUtils.GetCategoryData(itemId, StoreSettings.Current.EditLanguage);
                var selData          = CategoryUtils.GetCategoryData(Convert.ToInt32(selecteditemid), StoreSettings.Current.EditLanguage);
                var fromParentItemid = selData.DataRecord.ParentItemId;
                var toParentItemid   = movData.DataRecord.ParentItemId;
                var reindex          = toParentItemid != fromParentItemid;

                var objGrpCtrl = new GrpCatController(StoreSettings.Current.EditLanguage);
                var movGrp     = objGrpCtrl.GetGrpCategory(movData.Info.ItemID);
                if (!movGrp.Parents.Contains(selData.Info.ItemID)) // cannot move a category into itself (i.e. move parent into sub-category)
                {
                    selData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", toParentItemid.ToString(""));
                    selData.DataRecord.ParentItemId = toParentItemid;
                    selData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", movData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype"));
                    var strneworder = movData.DataRecord.GetXmlProperty("genxml/hidden/recordsortorder");
                    var selorder    = selData.DataRecord.GetXmlProperty("genxml/hidden/recordsortorder");
                    if (!Utils.IsNumeric(strneworder))
                    {
                        strneworder = "1";
                    }
                    if (!Utils.IsNumeric(selorder))
                    {
                        selorder = "1";
                    }
                    var neworder = Convert.ToDouble(strneworder, CultureInfo.GetCultureInfo("en-US"));
                    if (Convert.ToDouble(strneworder, CultureInfo.GetCultureInfo("en-US")) < Convert.ToDouble(selorder, CultureInfo.GetCultureInfo("en-US")))
                    {
                        neworder = neworder - 0.5;
                    }
                    else
                    {
                        neworder = neworder + 0.5;
                    }
                    selData.DataRecord.SetXmlProperty("genxml/hidden/recordsortorder", neworder.ToString(""), TypeCode.Double);
                    ModCtrl.Update(selData.DataRecord);

                    FixRecordSortOrder(toParentItemid.ToString("")); //reindex all siblings (this is so we get a int on the recordsortorder)
                    FixRecordGroupType(selData.Info.ItemID.ToString(""), selData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype"));

                    if (reindex)
                    {
                        objGrpCtrl.ReIndexCascade(fromParentItemid);    // reindex from parent and parents.
                        objGrpCtrl.ReIndexCascade(selData.Info.ItemID); // reindex select and parents
                    }
                    NBrightBuyUtils.RemoveModCachePortalWide(PortalId); //clear any cache
                }
            }
        }
Exemplo n.º 7
0
        public String MoveCategoryAdmin(HttpContext context, string editType = "")
        {
            var ajaxInfo    = NBrightBuyUtils.GetAjaxInfo(context);
            var movecatid   = ajaxInfo.GetXmlPropertyInt("genxml/hidden/movecatid");
            var movetocatid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/movetocatid");

            if (movecatid > 0 && movetocatid > 0)
            {
                MoveRecord(movetocatid, movecatid);
            }

            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            return(CategoryAdminList(context, editType, EditLangCurrent));
        }
Exemplo n.º 8
0
        private void MoveRecord(int movetocatid, int movecatid)
        {
            if (movecatid > 0)
            {
                var movData = CategoryUtils.GetCategoryData(movetocatid, EditLangCurrent);
                var selData = CategoryUtils.GetCategoryData(movecatid, EditLangCurrent);
                if (movData.Exists && selData.Exists)
                {
                    var fromParentItemid = selData.DataRecord.ParentItemId;
                    var toParentItemid   = movData.DataRecord.ParentItemId;
                    var reindex          = toParentItemid != fromParentItemid;
                    var objGrpCtrl       = new GrpCatController(EditLangCurrent);
                    var movGrp           = objGrpCtrl.GetGrpCategory(movData.Info.ItemID);
                    if (!movGrp.Parents.Contains(selData.Info.ItemID)) // cannot move a category into itself (i.e. move parent into sub-category)
                    {
                        selData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", toParentItemid.ToString(""));
                        selData.DataRecord.ParentItemId = toParentItemid;
                        selData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", movData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype"));
                        var strneworder = movData.DataRecord.GetXmlPropertyDouble("genxml/hidden/recordsortorder");
                        var selorder    = selData.DataRecord.GetXmlPropertyDouble("genxml/hidden/recordsortorder");
                        var neworder    = Convert.ToDouble(strneworder, CultureInfo.GetCultureInfo("en-US"));
                        if (strneworder < selorder)
                        {
                            neworder = neworder - 0.5;
                        }
                        else
                        {
                            neworder = neworder + 0.5;
                        }
                        selData.DataRecord.SetXmlProperty("genxml/hidden/recordsortorder", neworder.ToString(""), TypeCode.Double);
                        var objCtrl = new NBrightBuyController();
                        objCtrl.Update(selData.DataRecord);

                        FixRecordSortOrder(toParentItemid.ToString(""), EditLangCurrent); //reindex all siblings (this is so we get a int on the recordsortorder)
                        FixRecordGroupType(selData.Info.ItemID.ToString(""), selData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype"), EditLangCurrent);

                        if (reindex)
                        {
                            objGrpCtrl.ReIndexCascade(fromParentItemid);    // reindex from parent and parents.
                            objGrpCtrl.ReIndexCascade(selData.Info.ItemID); // reindex select and parents
                        }
                        NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public String CategoryAdminAddNew(HttpContext context, string editType = "")
        {
            var ajaxInfo     = NBrightBuyUtils.GetAjaxInfo(context);
            var categoryData = CategoryUtils.GetCategoryData(-1, EditLangCurrent);
            var selgroup     = ajaxInfo.GetXmlProperty("genxml/hidden/selectedgroup");

            if (selgroup == "")
            {
                selgroup = "cat";
            }
            categoryData.GroupType = selgroup;
            categoryData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", "True");
            categoryData.DataRecord.ParentItemId = ajaxInfo.GetXmlPropertyInt("genxml/hidden/selectedcatid");
            categoryData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", categoryData.DataRecord.ParentItemId.ToString());
            categoryData.Save();
            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            return(CategoryAdminList(context, editType, EditLangCurrent));
        }
Exemplo n.º 10
0
        private String SaveSettings(HttpContext context)
        {
            try
            {
                var objCtrl = new NBrightBuyController();

                //get uploaded params
                var ajaxInfo = NBrightBuyUtils.GetAjaxInfo(context);

                var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
                if (Utils.IsNumeric(moduleid))
                {
                    // get DB record
                    var nbi = NBrightBuyUtils.GetSettings(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid));
                    if (nbi.ModuleId == 0) // new setting record
                    {
                        nbi = CreateSettingsInfo(moduleid, nbi);
                    }
                    // get data passed back by ajax
                    var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
                    // update record with ajax data
                    nbi.UpdateAjax(strIn);


                    if (nbi.GetXmlProperty("genxml/hidden/modref") == "")
                    {
                        nbi.SetXmlProperty("genxml/hidden/modref", Utils.GetUniqueKey(10));
                    }
                    if (nbi.TextData == "")
                    {
                        nbi.TextData = "NBrightBuy";
                    }
                    objCtrl.Update(nbi);
                    NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId); // make sure all new settings are used.
                }
                return("");
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                return(ex.ToString());
            }
        }
Exemplo n.º 11
0
        public String CategoryAdminSaveList(HttpContext context)
        {
            var ajaxInfoList   = NBrightBuyUtils.GetAjaxInfoList(context);
            var strOut         = "";
            var regex          = new Regex(@"^[a-z0-9]+$");
            var isPropertyList = (context.Request.QueryString.Get("cmd") == "property_admin_savelist");

            foreach (var nbi in ajaxInfoList)
            {
                // validate property refs
                if (isPropertyList)
                {
                    var propertyRef = nbi.GetXmlProperty("genxml/textbox/propertyref");
                    if (propertyRef != "" && !regex.IsMatch(propertyRef))
                    {
                        strOut = "Error: Invalid Ref. Only use lower case alpha numeric values. No spaces. " + propertyRef;
                        break;
                    }
                    ;
                }

                if (nbi.GetXmlPropertyBool("genxml/hidden/isdirty"))
                {
                    var categoryData = CategoryUtils.GetCategoryData(nbi.GetXmlPropertyInt("genxml/hidden/itemid"), nbi.GetXmlProperty("genxml/hidden/categorylang"));
                    if (categoryData.Exists)
                    {
                        categoryData.Name = nbi.GetXmlProperty("genxml/textbox/txtcategoryname");
                        if (categoryData.DataRecord.GetXmlProperty("genxml/textbox/propertyref") == "")
                        {
                            categoryData.DataRecord.SetXmlProperty("genxml/textbox/propertyref", nbi.GetXmlProperty("genxml/textbox/propertyref"));
                        }
                        categoryData.Save();
                    }
                }
            }
            DataCache.ClearCache();
            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            return(strOut);
        }
Exemplo n.º 12
0
        public String CategoryAdminSaveList(HttpContext context)
        {
            var ajaxInfoList = NBrightBuyUtils.GetAjaxInfoList(context);

            foreach (var nbi in ajaxInfoList)
            {
                if (nbi.GetXmlPropertyBool("genxml/hidden/isdirty"))
                {
                    var categoryData = CategoryUtils.GetCategoryData(nbi.GetXmlPropertyInt("genxml/hidden/itemid"), nbi.GetXmlProperty("genxml/hidden/categorylang"));
                    if (categoryData.Exists)
                    {
                        categoryData.Name = nbi.GetXmlProperty("genxml/textbox/txtcategoryname");
                        if (categoryData.DataRecord.GetXmlProperty("genxml/textbox/propertyref") == "")
                        {
                            categoryData.DataRecord.SetXmlProperty("genxml/textbox/propertyref", nbi.GetXmlProperty("genxml/textbox/propertyref"));
                        }
                        categoryData.Save();
                    }
                }
            }
            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            return("");
        }
Exemplo n.º 13
0
        public String CategorySave(HttpContext context, string editLangCurrent)
        {
            if (NBrightBuyUtils.CheckManagerRights())
            {
                EditLangCurrent = editLangCurrent;
                var ajaxInfo     = NBrightBuyUtils.GetAjaxFields(context);
                var parentitemid = ajaxInfo.GetXmlPropertyInt("genxml/dropdownlist/ddlparentcatid");
                var catid        = ajaxInfo.GetXmlPropertyInt("genxml/hidden/itemid");
                if (catid > 0)
                {
                    if (parentitemid != catid)
                    {
                        var catData = new CategoryData(catid, EditLangCurrent);

                        // check we've not put a category under it's child
                        if (!IsParentInChildren(catData, parentitemid))
                        {
                            var catDirectList   = catData.GetDirectArticles();
                            var oldparentitemId = catData.ParentItemId;
                            if (parentitemid != oldparentitemId)
                            {
                                // remove articles for category, so we realign the cascade records.
                                foreach (var p in catDirectList)
                                {
                                    var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                    prdData.RemoveCategory(catData.CategoryId);
                                }
                            }

                            catData.Update(ajaxInfo);

                            // the base category ref cannot have language dependant refs, we therefore just use a unique key
                            var catref = catData.DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                            if (catref == "")
                            {
                                if (catData.DataRecord.GUIDKey == "")
                                {
                                    catref = Utils.GetUniqueKey().ToLower();
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                                    catData.DataRecord.GUIDKey = catref;
                                }
                                else
                                {
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catData.DataRecord.GUIDKey);
                                }
                            }
                            catData.Save();
                            CategoryUtils.ValidateLangaugeRef(PortalSettings.Current.PortalId, catid); // do validate so we update all refs and children refs
                            NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);

                            if (parentitemid != oldparentitemId)
                            {
                                // all all articles for category. so we realign the cascade records.
                                foreach (var p in catDirectList)
                                {
                                    var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                    prdData.AddCategory(catData.CategoryId);
                                }
                            }
                        }
                    }
                }
                DataCache.ClearCache();
                NBrightBuyUtils.RemoveModCachePortalWide(PortalSettings.Current.PortalId);
            }
            return("");
        }
Exemplo n.º 14
0
        private void UpdateRecord()
        {
            var xmlData = GenXmlFunctions.GetGenXml(rpData, "", StoreSettings.Current.FolderImagesMapPath);
            var objInfo = new NBrightInfo();

            objInfo.ItemID   = -1;
            objInfo.TypeCode = "POSTDATA";
            objInfo.XMLData  = xmlData;
            var settings = objInfo.ToDictionary(); // put the fieds into a dictionary, so we can get them easy.

            // check we don't have an invalid parentitemid
            var parentitemid = objInfo.GetXmlPropertyInt("genxml/dropdownlist/ddlparentcatid");
            var strOut       = "No Category ID ('itemid' hidden fields needed on input form)";

            if (settings.ContainsKey("itemid"))
            {
                if (parentitemid != Convert.ToInt32(settings["itemid"]))
                {
                    var catData = CategoryUtils.GetCategoryData(Convert.ToInt32(settings["itemid"]), StoreSettings.Current.EditLanguage);

                    // check we've not put a category under it's child
                    if (IsParentInChildren(catData, parentitemid))
                    {
                        NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.fail);
                    }
                    else
                    {
                        var catDirectList   = catData.GetDirectArticles();
                        var oldparentitemId = catData.ParentItemId;
                        if (parentitemid != oldparentitemId)
                        {
                            // remove articles for category, so we realign the cascade records.
                            foreach (var p in catDirectList)
                            {
                                var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                prdData.RemoveCategory(catData.CategoryId);
                            }
                        }

                        catData.Update(objInfo);

                        if (!String.IsNullOrEmpty(Edittype) && Edittype.ToLower() == "group")
                        {
                            var grptype = objInfo.GetXmlProperty("genxml/dropdownlist/ddlparentcatid");
                            var grp     = ModCtrl.GetByGuidKey(PortalSettings.PortalId, -1, "GROUP", grptype);
                            if (grp != null)
                            {
                                var newGuidKey = objInfo.GetXmlProperty("genxml/textbox/propertyref");
                                if (newGuidKey != "")
                                {
                                    newGuidKey = GetUniqueGuidKey(catData.CategoryId, Utils.UrlFriendly(newGuidKey));
                                }
                                catData.DataRecord.GUIDKey = newGuidKey;
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", newGuidKey);
                                catData.DataRecord.ParentItemId = grp.ItemID;
                                // list done using ddlgrouptype, in  GetCatList
                                catData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlgrouptype", grptype);
                                catData.Save();
                                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
                            }
                        }
                        else
                        {
                            // the base category ref cannot have language dependant refs, we therefore just use a unique key
                            var catref = catData.DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                            if (catref == "")
                            {
                                if (catData.DataRecord.GUIDKey == "")
                                {
                                    catref = Utils.GetUniqueKey().ToLower();
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                                    catData.DataRecord.GUIDKey = catref;
                                }
                                else
                                {
                                    catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catData.DataRecord.GUIDKey);
                                }
                            }
                            catData.Save();
                            CategoryUtils.ValidateLangaugeRef(PortalId, Convert.ToInt32(settings["itemid"])); // do validate so we update all refs and children refs
                            NBrightBuyUtils.RemoveModCachePortalWide(PortalId);
                        }

                        if (parentitemid != oldparentitemId)
                        {
                            // all all articles for category. so we realign the cascade records.
                            foreach (var p in catDirectList)
                            {
                                var prdData = new ProductData(p.ParentItemId, p.PortalId, p.Lang);
                                prdData.AddCategory(catData.CategoryId);
                            }
                        }

                        NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.ok);
                    }
                }
                else
                {
                    NBrightBuyUtils.SetNotfiyMessage(ModuleId, "categoryactionsave", NotifyCode.fail);
                }
            }
            NBrightBuyUtils.RemoveModCachePortalWide(PortalId); //clear any cache
        }
Exemplo n.º 15
0
        private void SaveAll()
        {
            foreach (RepeaterItem rtnItem in rpData.Items)
            {
                var isdirty = GenXmlFunctions.GetField(rtnItem, "isdirty");
                var itemid  = GenXmlFunctions.GetField(rtnItem, "itemid");
                if (isdirty == "true" && Utils.IsNumeric(itemid))
                {
                    var catData = CategoryUtils.GetCategoryData(Convert.ToInt32(itemid), StoreSettings.Current.EditLanguage);
                    if (catData.Exists)
                    {
                        var chkishidden = GenXmlFunctions.GetField(rtnItem, "chkishidden");
                        var catname     = GenXmlFunctions.GetField(rtnItem, "txtcategoryname");
                        catData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", chkishidden);

                        if (!String.IsNullOrEmpty(Edittype) && Edittype.ToLower() == "group")
                        {
                            var propertyref = GenXmlFunctions.GetField(rtnItem, "propertyref");
                            if (propertyref != "")
                            {
                                catData.DataRecord.SetXmlProperty("genxml/textbox/propertyref", propertyref);
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", propertyref);
                            }
                            var grptype = catData.DataRecord.GetXmlProperty("genxml/dropdownlist/ddlgrouptype");
                            var grp     = ModCtrl.GetByGuidKey(PortalSettings.PortalId, -1, "GROUP", grptype);
                            if (grp != null)
                            {
                                catData.ParentItemId = grp.ItemID;
                                ModCtrl.Update(catData.DataRecord);
                            }
                        }
                        else
                        {
                            // the base category ref cannot have language dependant refs, we therefore just use a unique key
                            var catref = catData.DataRecord.GetXmlProperty("genxml/textbox/txtcategoryref");
                            if (catref == "")
                            {
                                catref = Utils.GetUniqueKey().ToLower();
                                catData.DataRecord.SetXmlProperty("genxml/textbox/txtcategoryref", catref);
                                catData.DataRecord.GUIDKey = catref;
                            }
                            ModCtrl.Update(catData.DataRecord);
                        }

                        catData.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategoryname", catname);
                        ModCtrl.Update(catData.DataLangRecord);
                        if (catname != "")
                        {
                            // update all language records that have no name
                            foreach (var lang in DnnUtils.GetCultureCodeList(PortalSettings.Current.PortalId))
                            {
                                var catLangUpd = CategoryUtils.GetCategoryData(Convert.ToInt32(itemid), lang);
                                if (catLangUpd.DataLangRecord != null && catLangUpd.Info.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname") == "")
                                {
                                    catLangUpd.DataLangRecord.SetXmlProperty("genxml/textbox/txtcategoryname", catname);
                                    ModCtrl.Update(catLangUpd.DataLangRecord);
                                }
                            }
                        }

                        catData.Save();
                        NBrightBuyUtils.RemoveModCachePortalWide(PortalId);                   // clear cache before validate lang, so we pickup new changes to name.
                        CategoryUtils.ValidateLangaugeRef(PortalId, Convert.ToInt32(itemid)); // do validate so we update all refs and children refs
                    }
                }
            }
        }
Exemplo n.º 16
0
        protected void CtrlItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var cArg  = e.CommandArgument.ToString();
            var param = new string[3];

            var navigationData = new NavigationData(PortalId, "CategoryAdmin");

            switch (e.CommandName.ToLower())
            {
            case "entrydetail":
                SaveAll();
                param[1] = "eid=" + cArg;
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "return":
                param[1] = "";
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "search":
                var strXml = GenXmlFunctions.GetGenXml(rpSearch, "", "");
                navigationData.XmlData = strXml;
                if (StoreSettings.Current.DebugModeFileOut)
                {
                    strXml = "<root><sql><![CDATA[" + navigationData.Criteria + "]]></sql>" + strXml + "</root>";
                    var xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(strXml);
                    xmlDoc.Save(PortalSettings.HomeDirectoryMapPath + "debug_search.xml");
                }
                navigationData.Save();
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "resetsearch":
                // clear cookie info
                navigationData.Delete();
                param[2] = "catid=0";
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "addnew":
                var strXml2 = GenXmlFunctions.GetGenXml(rpSearch, "", "");
                navigationData.XmlData = strXml2;
                navigationData.Save();
                var categoryData = CategoryUtils.GetCategoryData(-1, EditLanguage);
                if (!String.IsNullOrEmpty(Edittype) && Edittype.ToLower() == "group")
                {
                    categoryData.GroupType = GenXmlFunctions.GetGenXmlValue(navigationData.XmlData, "genxml/dropdownlist/groupsel");
                    if (categoryData.GroupType == "")
                    {
                        categoryData.GroupType = "cat";
                    }
                    var grpCtrl = new GrpCatController(Utils.GetCurrentCulture());
                    var grp     = grpCtrl.GetGrpCategoryByRef(categoryData.GroupType);
                    if (grp != null)
                    {
                        categoryData.DataRecord.SetXmlProperty("genxml/dropdownlist/ddlparentcatid", grp.categoryid.ToString(""));
                    }
                    categoryData.DataRecord.SetXmlProperty("genxml/checkbox/chkishidden", "False");     // don't hide property groups by default
                }
                categoryData.ParentItemId = _openid;
                categoryData.Save();
                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);

                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "delete":
                if (Utils.IsNumeric(cArg))
                {
                    var catid = Convert.ToInt32(cArg);
                    if (catid > 0)
                    {
                        var delCatData = CategoryUtils.GetCategoryData(catid, EditLanguage);
                        if (delCatData.Exists && delCatData.GetDirectChildren().Count == 0)     // only delete end leaf
                        {
                            var productidlist = new ArrayList();
                            foreach (var dc in delCatData.GetDirectArticles())
                            {
                                productidlist.Add(dc.ParentItemId);
                            }

                            var parentCatList = new List <CategoryData>();
                            var loopCat       = CategoryUtils.GetCategoryData(catid, EditLanguage);
                            while (loopCat.Exists && loopCat.ParentItemId > 0)
                            {
                                loopCat = CategoryUtils.GetCategoryData(loopCat.ParentItemId, EditLanguage);
                                parentCatList.Add(loopCat);
                            }

                            foreach (var pCat in parentCatList)
                            {
                                foreach (var prodxref in pCat.GetCascadeArticles())
                                {
                                    if (productidlist.Contains(prodxref.ParentItemId))
                                    {
                                        // delete CATCASCADE record
                                        if (prodxref.TypeCode == "CATCASCADE")     // just check we have correct record. (stop nasty surprises)
                                        {
                                            ModCtrl.Delete(prodxref.ItemID);
                                        }
                                    }
                                }
                            }

                            foreach (var dc in delCatData.GetDirectArticles())
                            {
                                // delete CATXREF record
                                if (dc.TypeCode == "CATXREF")     // just check we have correct record. (stop nasty surprises)
                                {
                                    ModCtrl.Delete(dc.ItemID);
                                }
                            }
                            // delete CATEGORY record (constrants remove LANG records.)
                            ModCtrl.Delete(catid);
                        }
                        else
                        {
                            NBrightBuyUtils.SetNotfiyMessage(ModuleId, "onlyleafcat", NotifyCode.fail);
                        }
                    }
                }
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "saveall":
                SaveAll();
                NBrightBuyUtils.RemoveModCachePortalWide(PortalId);     //clear any cache
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "move":
                SaveAll();
                if (Utils.IsNumeric(cArg))
                {
                    MoveRecord(Convert.ToInt32(cArg));
                }
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "open":
                param[1] = "catid=" + cArg;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "close":
                var catData = CategoryUtils.GetCategoryData(_openid, EditLanguage);
                if (catData.DataRecord == null)
                {
                    param[1] = "catid=0";
                }
                else
                {
                    param[1] = "catid=" + catData.DataRecord.ParentItemId.ToString("");
                }
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "save":
                UpdateRecord();
                param[1] = "eid=" + cArg;
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;

            case "saveexit":
                UpdateRecord();
                param[2] = "catid=" + _openid;
                Response.Redirect(NBrightBuyUtils.AdminUrl(TabId, param), true);
                break;
            }
        }