示例#1
0
        /// <summary>
        /// Remove all unsed images.  (DELETE any NBS images NOT linked to Categories or Products)
        /// </summary>
        private void PurgeImages()
        {
            var pass = GenXmlFunctions.GetField(rpData, "txtclearpass");

            if (pass == StoreSettings.Current.Get("adminpin") && pass != "")
            {
                var objCtrl   = new NBrightBuyController();
                var imgdblist = new List <string>();

                // get DB filenames
                var prdlist = objCtrl.GetList(PortalId, -1, "PRD");
                foreach (var nbi in prdlist)
                {
                    var nodlist = nbi.XMLDoc.SelectNodes("genxml/imgs/*");
                    if (nodlist != null)
                    {
                        foreach (XmlNode nod in nodlist)
                        {
                            var pnod = nod.SelectSingleNode("hidden/imagepath");
                            if (pnod != null)
                            {
                                var fname = Path.GetFileName(pnod.InnerText);
                                if (fname != "" && !imgdblist.Contains(fname))
                                {
                                    imgdblist.Add(fname);
                                }
                            }
                        }
                    }
                }
                var itemlist = objCtrl.GetList(PortalId, -1, "CATEGORY");
                foreach (var nbi in itemlist)
                {
                    var p = nbi.GetXmlProperty("genxml/hidden/imagepath");
                    if (p != "")
                    {
                        imgdblist.Add(Path.GetFileName(p));
                    }
                }

                // get fileystem filenames and remove if not in DB.
                var filelist = Directory.GetFiles(StoreSettings.Current.FolderImagesMapPath);
                foreach (var f in filelist)
                {
                    if (!imgdblist.Contains(Path.GetFileName(f)))
                    {
                        // delete img
                        File.Delete(f);
                    }
                }
                NBrightBuyUtils.SetNotfiyMessage(ModuleId, "completed", NotifyCode.ok);
            }
            else
            {
                NBrightBuyUtils.SetNotfiyMessage(ModuleId, "nopin", NotifyCode.fail);
            }
        }
示例#2
0
        public override string Run(string paramdata)
        {
            // Custom Action providers are designed to run a 1 time update of data, in the DB, without the need of a UI.
            // Usually a selection of data records from the DB will be done and then an action and update performed.
            // The example below is showing the selection of products in the system and a simple alteration of data.
            // No update is done with this example.

            // The resulting dll from this project can be copied into the /bin folder of the DNN/NBS installation and then ran using the BO>Admin>Tools option.
            // e.g. for this provider name. (Alter as required)
            // assembly: OS_CustomAction
            // namespace.class: Nevoweb.OS_CustomAction.CustomAction

            // NOTE: change the namespace of "Nevoweb." and the assembly name.

            var objCtrl = new NBrightBuyController();

            var list = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "PRD");

            foreach (var nbi in list)
            {
                var data = nbi.GetXmlProperty("genxml/testdata");
                data = data + "testing";
                nbi.SetXmlProperty("genxml/testdata", data);
                //objCtrl.Update(nbi); // apply updated record back to DB.
            }

            return("");
        }
示例#3
0
        public IEncodedString HasQtyPromo(int productId, string qtypromoref = "")
        {
            var objCtrl  = new NBrightBuyController();
            var prodData = new ProductData(productId, Utils.GetCurrentCulture());

            if (qtypromoref != "")
            {
                var qtypromo = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -2, "QTYPROMO", qtypromoref);
                if (bulkBuyOn(prodData, qtypromo))
                {
                    return(new RawString("true"));
                }
            }
            else
            {
                var qtypromolist = objCtrl.GetList(PortalSettings.Current.PortalId, -2, "QTYPROMO");
                foreach (var q in qtypromolist)
                {
                    if (bulkBuyOn(prodData, q))
                    {
                        return(new RawString("true"));
                    }
                }
            }
            return(new RawString("false"));
        }
示例#4
0
        public IEncodedString QtyPromoDescription(int productId, string qtypromoref = "")
        {
            var qtydescritpion = "";
            var objCtrl        = new NBrightBuyController();
            var prodData       = new ProductData(productId, Utils.GetCurrentCulture());

            if (qtypromoref != "")
            {
                var qtypromo = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -2, "QTYPROMO", qtypromoref);
                if (bulkBuyOn(prodData, qtypromo))
                {
                    var qtyInfo = objCtrl.GetData(qtypromo.ItemID, "QTYPROMOLANG", Utils.GetCurrentCulture());
                    qtydescritpion = qtyInfo.GetXmlProperty("genxml/lang/genxml/textbox/description");
                }
            }
            else
            {
                var qtypromolist = objCtrl.GetList(PortalSettings.Current.PortalId, -2, "QTYPROMO");
                foreach (var q in qtypromolist)
                {
                    if (bulkBuyOn(prodData, q))
                    {
                        var qtyInfo = objCtrl.GetData(q.ItemID, "QTYPROMOLANG", Utils.GetCurrentCulture());
                        qtydescritpion = qtyInfo.GetXmlProperty("genxml/lang/genxml/textbox/description");
                        break;
                    }
                }
            }

            return(new RawString(qtydescritpion));
        }
示例#5
0
        public static string CalcMultiBuyPromo(int portalId)
        {
            var objCtrl = new NBrightBuyController();
            var l       = objCtrl.GetList(portalId, -1, "MULTIBUYPROMO", "", "", 0, 0, 0, 0, Utils.GetCurrentCulture());

            foreach (var p in l)
            {
                CalcMultiBuyPromoItem(p);
            }
            return("OK");
        }
示例#6
0
        public static string CalcGroupPromo(int portalId)
        {
            var objCtrl = new NBrightBuyController();
            var l       = objCtrl.GetList(portalId, -1, "CATEGORYPROMO", "", " order by [XMLData].value('(genxml/dropdownlist/processorder)[1]','int') ", 0, 0, 0, 0, Utils.GetCurrentCulture());

            foreach (var p in l)
            {
                CalcGroupPromoItem(p);
            }
            return("OK");
        }
        public static NBrightInfo  CalcQtyPromo(int portalId, NBrightInfo cartItemInfo)
        {
            var objCtrl = new NBrightBuyController();
            var l       = objCtrl.GetList(portalId, -1, "QtyPromo", "", "", 0, 0, 0, 0, Utils.GetCurrentCulture());

            foreach (var p in l)
            {
                cartItemInfo = CalcQtyPromoItem(p, cartItemInfo);
            }
            return(cartItemInfo);
        }
        private String GetData(HttpContext context, bool clearCache = false)
        {
            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, "config", _lang, StoreSettings.Current.Settings());
            }
            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.RazorTemplRenderList(typeCode.ToLower() + "list.cshtml", Convert.ToInt32(moduleid), _lang + editlang, l, templateControl, "config", _lang, StoreSettings.Current.Settings());
            }

            return(strOut);
        }
示例#9
0
        public static string RemoveGroupProductPromo(int portalId, int promoid)
        {
            var objCtrl = new NBrightBuyController();
            var p       = objCtrl.GetData(promoid);

            var typeselect  = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid  = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid = p.GetXmlProperty("genxml/dropdownlist/propgroupid");

            var portalsettings = NBrightDNN.DnnUtils.GetPortalSettings(p.PortalId);
            var lang           = portalsettings.DefaultLanguage;

            var prdList = new List <NBrightInfo>();

            if (typeselect == "all")
            {
                prdList = objCtrl.GetList(p.PortalId, -1, "PRD");
            }
            else
            {
                CategoryData gCat;
                var          groupid = catgroupid;
                if (typeselect != "cat")
                {
                    groupid = propgroupid;
                }
                gCat = CategoryUtils.GetCategoryData(groupid, lang);
                if (gCat != null)
                {
                    prdList = gCat.GetAllArticles();
                }
            }
            foreach (var prd in prdList)
            {
                var productid = prd.ParentItemId;
                if (typeselect == "all")
                {
                    productid = prd.ItemID;
                }

                // END Promo
                RemoveProductPromoData(portalId, productid, p.ItemID);
                ProductUtils.RemoveProductDataCache(prd.PortalId, productid);
                var productData = ProductUtils.GetProductData(productid, lang);
                productData.Save(); // recalc any new prices.
            }
            return("OK");
        }
示例#10
0
        public static void OutputTestEmail()
        {
            var objCtrl = new NBrightBuyController();
            var l       = objCtrl.GetList(PortalSettings.Current.PortalId, -1, "ORDER", " and NB1.XMLdata.value('(genxml/productlimitflag)[1]','nvarchar(max)') = 'True' ", "", 1);

            if (l.Count > 0)
            {
                var nbi          = l.First();
                var orderData    = new OrderData(nbi.ItemID);
                var passSettings = new Dictionary <string, string>();
                var emailBody    = NBrightBuyUtils.RazorTemplRender("EmailHtmlOutput.cshtml", 0, "", orderData, "/DesktopModules/NBright/OS_PurchaseNotification", "config", orderData.Lang, passSettings);
                Utils.SaveFile(PortalSettings.Current.HomeDirectoryMapPath + "\\testemail.html", emailBody);
            }
            else
            {
                Utils.SaveFile(PortalSettings.Current.HomeDirectoryMapPath + "\\testemail.html", "NO ORDERS with purchase notification");
            }
        }
示例#11
0
        /// <summary>
        /// 取得訂單清單
        /// </summary>
        /// <param name="type">訂單狀態</param>
        /// <returns></returns>
        public IEnumerable <OrderInfo> GetOrderStateList(string type)
        {
            NBrightBuyController nBrightBuy = new NBrightBuyController();
            List <OrderInfo>     orders     = new List <OrderInfo>();

            string search  = $" and ([xmldata].value('(genxml/dropdownlist/orderstatus)[1]', 'nvarchar(max)') = '{type}')   ";
            string orderby = "   order by [XMLData].value('(genxml/createddate)[1]','datetime') DESC, ModifiedDate DESC  ";

            List <NBrightInfo> orderInfo = nBrightBuy.GetList(PortalSettings.Current.PortalId, -1, "ORDER", search, orderby);

            foreach (NBrightInfo info in orderInfo)
            {
                orders.Add(new OrderInfo
                {
                    OrderId           = info.ItemID,
                    OrderNumber       = info.GetXmlProperty("genxml/ordernumber"),
                    FirstName         = info.GetXmlProperty("genxml/billaddress/genxml/textbox/firstname"),
                    LastName          = info.GetXmlProperty("genxml/billaddress/genxml/textbox/lastname"),
                    Telephone         = info.GetXmlProperty("genxml/billaddress/genxml/textbox/telephone"),
                    Email             = info.GetXmlProperty("genxml/billaddress/genxml/textbox/email"),
                    Company           = info.GetXmlProperty(""),
                    Unit              = info.GetXmlProperty("genxml/billaddress/genxml/textbox/unit"),
                    Street            = info.GetXmlProperty("genxml/billaddress/genxml/textbox/street"),
                    City              = info.GetXmlProperty("genxml/billaddress/genxml/textbox/city"),
                    PostalCode        = info.GetXmlProperty("genxml/billaddress/genxml/textbox/postalcode"),
                    Freight           = Convert.ToDecimal(info.GetXmlPropertyDouble("genxml/appliedshipping")),
                    Total             = info.GetXmlPropertyInt("genxml/appliedtotal"),
                    OrderStatus       = info.GetXmlProperty("genxml/dropdownlist/orderstatus"),
                    Shipping          = info.GetXmlProperty("genxml/extrainfo/genxml/hidden/shippingdisplayanme"),
                    LogisticsType     = info.GetXmlProperty("genxml/extrainfo/genxml/hidden/logisticstype"),
                    LogisticsSubType  = info.GetXmlProperty("genxml/extrainfo/genxml/hidden/logisticssubtype"),
                    StoreId           = info.GetXmlProperty("genxml/extrainfo/genxml/hidden/cvsstoreid"),
                    StoreName         = info.GetXmlProperty("genxml/extrainfo/genxml/textbox/cvsstorename"),
                    AllPayLogisticsID = info.GetXmlProperty("genxml/textbox/trackingcode"),
                    Print             = info.GetXmlPropertyBool("genxml/tradedocument")
                });
            }

            return(orders);
        }
示例#12
0
        private String GetData(HttpContext context, bool clearCache = false)
        {
            var objCtrl = new NBrightBuyController();
            var strOut  = "";
            //get uploaded params
            var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);

            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 = Utils.GetCurrentCulture();
            }

            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/OS_PluginTemplate";

            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("datafields.cshtml", Convert.ToInt32(moduleid), itemid + editlang + selecteditemid, obj, templateControl, "config", editlang, StoreSettings.Current.Settings());
            }
            else
            {
                var pagenumber = ajaxInfo.GetXmlPropertyInt("genxml/hidden/pagenumber");
                var pagesize   = ajaxInfo.GetXmlPropertyInt("genxml/hidden/pagesize");

                if (pagenumber == 0)
                {
                    pagenumber = 1;
                }
                if (pagesize == 0)
                {
                    pagesize = 20;
                }

                var filter     = "";
                var searchText = ajaxInfo.GetXmlProperty("genxml/hidden/searchtext");
                if (searchText != "")
                {
                    filter += " and ( ";
                    filter += " (([xmldata].value('(genxml/textbox/ref)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                    filter += " or (([xmldata].value('(genxml/lang/genxml/textbox/ref2)[1]', 'nvarchar(max)') like '%" + searchText + "%' collate sql_latin1_general_cp1_ci_ai ))";
                    filter += " ) ";
                }

                // get only entity type required
                var recordcount = objCtrl.GetListCount(PortalSettings.Current.PortalId, -1, typeCode, filter);


                // Return list of items
                var l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), typeCode, filter, " order by [XMLData].value('(genxml/textbox/ref)[1]','nvarchar(50)')", 0, pagenumber, pagesize, recordcount, editlang);
                strOut = NBrightBuyUtils.RazorTemplRenderList("datalist.cshtml", Convert.ToInt32(moduleid), editlang, l, templateControl, "config", editlang, StoreSettings.Current.Settings());

                if (recordcount > pagesize)
                {
                    var pg = new NBrightCore.controls.PagingCtrl();
                    strOut += pg.RenderPager(recordcount, pagesize, pagenumber);
                }
            }

            return(strOut);
        }
示例#13
0
        public static string CalcGroupPromoItem(NBrightInfo p)
        {
            var objCtrl        = new NBrightBuyController();
            var typeselect     = p.GetXmlProperty("genxml/radiobuttonlist/typeselect");
            var catgroupid     = p.GetXmlProperty("genxml/dropdownlist/catgroupid");
            var propgroupid    = p.GetXmlProperty("genxml/dropdownlist/propgroupid");
            var promoname      = p.GetXmlProperty("genxml/textbox/name");
            var amounttype     = p.GetXmlProperty("genxml/radiobuttonlist/amounttype");
            var amount         = p.GetXmlPropertyDouble("genxml/textbox/amount");
            var validfrom      = p.GetXmlProperty("genxml/textbox/validfrom");
            var validuntil     = p.GetXmlProperty("genxml/textbox/validuntil");
            var overwrite      = p.GetXmlPropertyBool("genxml/checkbox/overwrite");
            var disabled       = p.GetXmlPropertyBool("genxml/checkbox/disabled");
            var lastcalculated = p.GetXmlProperty("genxml/hidden/lastcalculated");
            var whichprice     = p.GetXmlPropertyInt("genxml/radiobuttonlist/whichprice");
            var runfreq        = p.GetXmlPropertyInt("genxml/radiobuttonlist/runfreq");

            if (!disabled)
            {
                var portalsettings = NBrightDNN.DnnUtils.GetPortalSettings(p.PortalId);
                var lang           = portalsettings.DefaultLanguage;

                var prdList = new List <NBrightInfo>();
                if (typeselect == "all")
                {
                    prdList = objCtrl.GetList(p.PortalId, -1, "PRD");
                }
                else
                {
                    CategoryData gCat;
                    var          groupid = catgroupid;
                    if (typeselect != "cat")
                    {
                        groupid = propgroupid;
                    }
                    gCat = CategoryUtils.GetCategoryData(groupid, lang);
                    if (gCat != null)
                    {
                        prdList = gCat.GetAllArticles();
                    }
                }

                var runcalc = true;
                if (runfreq == 1 || runfreq == 3) // run freq is date range
                {
                    if (runfreq == 3)
                    {
                        // run constantly, set end date to +100 year
                        validfrom  = DateTime.Now.AddYears(-1).ToString("s");
                        validuntil = DateTime.Now.AddYears(100).ToString("s");
                    }
                    // run date range
                    if (Utils.IsDate(lastcalculated))
                    {
                        if (Convert.ToDateTime(lastcalculated) >= p.ModifiedDate)
                        {
                            runcalc = false;                                                       // only run if changed
                        }
                        if (DateTime.Now.Date > Convert.ToDateTime(lastcalculated).Date.AddDays(1))
                        {
                            runcalc = true;                                                                         // every day just after midnight. (for site performace)
                        }
                    }
                    if (Utils.IsDate(validuntil))
                    {
                        if (DateTime.Now.Date > Convert.ToDateTime(validuntil))
                        {
                            runcalc = true;                                                     // need to disable the promo if passed date
                        }
                    }
                    if ((runcalc) && Utils.IsDate(validfrom) && Utils.IsDate(validuntil))
                    {
                        var dteF = Convert.ToDateTime(validfrom).Date;
                        var dteU = Convert.ToDateTime(validuntil).Date;

                        foreach (var prd in prdList)
                        {
                            var productid = prd.ParentItemId;
                            if (typeselect == "all")
                            {
                                productid = prd.ItemID;
                            }

                            if (DateTime.Now.Date >= dteF && DateTime.Now.Date <= dteU)
                            {
                                // CALC Promo
                                CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite);
                            }
                            if (DateTime.Now.Date > dteU)
                            {
                                // END Promo
                                RemoveProductPromoData(p.PortalId, productid, p.ItemID);
                            }
                            ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                            var productData = ProductUtils.GetProductData(productid, lang);
                            productData.Save(); // recalc any new prices.
                        }
                        if (DateTime.Now.Date > dteU)
                        {
                            // END Promo
                            p.SetXmlProperty("genxml/checkbox/disabled", "True");
                        }
                    }
                }
                if (runfreq == 2) // run Once, do update and disable promo.
                {
                    foreach (var prd in prdList)
                    {
                        var productid = prd.ParentItemId;
                        if (typeselect == "all")
                        {
                            productid = prd.ItemID;
                        }
                        // CALC Promo
                        CalcProductSalePrice(p.PortalId, productid, amounttype, amount, p.ItemID, whichprice, overwrite);
                        ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                        var productData = ProductUtils.GetProductData(productid, lang);
                        productData.Save(); // recalc any new prices.
                    }
                    p.SetXmlProperty("genxml/checkbox/disabled", "True");
                }
                if (runfreq == 4) // remove
                {
                    foreach (var prd in prdList)
                    {
                        var productid = prd.ParentItemId;
                        if (typeselect == "all")
                        {
                            productid = prd.ItemID;
                        }
                        RemoveProductPromoData(p.PortalId, productid, p.ItemID);
                        ProductUtils.RemoveProductDataCache(p.PortalId, productid);
                        var productData = ProductUtils.GetProductData(productid, lang);
                        productData.Save(); // recalc any new prices.
                    }

                    p.SetXmlProperty("genxml/checkbox/disabled", "True");
                }
                p.SetXmlProperty("genxml/hidden/lastcalculated", DateTime.Now.AddSeconds(10).ToString("O")); // Add 10 sec to time so we don't get exact clash with update time.
                objCtrl.Update(p);
            }
            return("OK");
        }
示例#14
0
        private static String GetOrderListData(Dictionary <String, String> settings, bool paging = true)
        {
            if (UserController.Instance.GetCurrentUserInfo().UserID <= 0)
            {
                return("");
            }

            var strOut = "";

            if (!settings.ContainsKey("selecteduserid"))
            {
                settings.Add("selecteduserid", "");
            }

            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 selecteduserid = settings["selecteduserid"];

            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 (Utils.IsNumeric(selecteduserid))
            {
                filter += " and (NB1.UserId = " + selecteduserid + ")   ";
            }

            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())
            {
                filter += " and ( userid = " + UserController.Instance.GetCurrentUserInfo().UserID + ")   ";
            }

            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]','datetime') 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, Utils.GetCurrentCulture(), passSettings);

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

            return(strOut);
        }
        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 ");
        }
示例#16
0
        public static List <UrlRule> GetRules(int portalId)
        {
            object padlock = new object();

            lock (padlock)
            {
                List <UrlRule> rules    = new List <UrlRule>();
                List <UrlRule> catrules = new List <UrlRule>();

                #if DEBUG
                decimal speed;
                string  mess;
                var     stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();
                #endif

                var purgeResult    = UrlRulesCaching.PurgeExpiredItems(portalId);
                var portalCacheKey = UrlRulesCaching.GeneratePortalCacheKey(portalId, null);
                var portalRules    = UrlRulesCaching.GetCache(portalId, portalCacheKey, purgeResult.ValidCacheItems);
                if (portalRules != null && portalRules.Count > 0)
                {
                    #if DEBUG
                    stopwatch.Stop();
                    speed = stopwatch.Elapsed.Milliseconds;
                    mess  = $"PortalId: {portalId}. Time elapsed: {stopwatch.Elapsed.Milliseconds}ms. All Cached. PurgedItems: {purgeResult.PurgedItemCount}. Speed: {speed}";
                    Logger.Error(mess);
                    #endif
                    return(portalRules);
                }

                Dictionary <string, Locale> dicLocales = LocaleController.Instance.GetLocales(portalId);

                var objCtrl = new NBrightBuyController();

                var storesettings = new StoreSettings(portalId);

                ModuleController mc  = new ModuleController();
                var modules          = mc.GetModulesByDefinition(portalId, "NBS_ProductDisplay").OfType <ModuleInfo>();
                var modulesOldModule = mc.GetModulesByDefinition(portalId, "NBS_ProductView").OfType <ModuleInfo>();
                modules = modules.Concat(modulesOldModule);

                // ------- Category URL ---------------

                #region "Category Url"

                // Not using the module loop!!
                // becuase tabs that are defined in the url are dealt with by open url rewriter, so we only need use the default tab which is defined by the store settings.

                foreach (KeyValuePair <string, Locale> key in dicLocales)
                {
                    try
                    {
                        string cultureCode     = key.Value.Code;
                        string ruleCultureCode = (dicLocales.Count > 1 ? cultureCode : null);

                        var grpCatCtrl = new GrpCatController(cultureCode, portalId);

                        // get all products in portal, with lang data
                        var catitems = objCtrl.GetList(portalId, -1, "CATEGORY");

                        foreach (var catData in catitems)
                        {
                            var catDataLang = objCtrl.GetDataLang(catData.ItemID, cultureCode);

                            if (catDataLang != null && !catData.GetXmlPropertyBool("genxml/checkbox/chkishidden"))
                            {
                                var            catCacheKey   = portalCacheKey + "_" + catDataLang.ItemID + "_" + cultureCode;
                                List <UrlRule> categoryRules = UrlRulesCaching.GetCache(portalId, catCacheKey, purgeResult.ValidCacheItems);
                                if (categoryRules != null && categoryRules.Count > 0)
                                {
                                    rules.AddRange(categoryRules);
                                }
                                else
                                {
                                    catrules = new List <UrlRule>();

                                    var caturlname   = catDataLang.GUIDKey;
                                    var SEOName      = catDataLang.GetXmlProperty("genxml/textbox/txtseoname");
                                    var categoryName = catDataLang.GetXmlProperty("genxml/textbox/txtcategoryname");

                                    var newcatUrl = grpCatCtrl.GetBreadCrumb(catData.ItemID, 0, "/", false);

                                    var url = newcatUrl;
                                    if (!string.IsNullOrEmpty(url))
                                    {
                                        // ------- Category URL ---------------

                                        var rule = new UrlRule
                                        {
                                            CultureCode = ruleCultureCode,
                                            TabId       = storesettings.ProductListTabId,
                                            Parameters  = "catref=" + caturlname,
                                            Url         = url
                                        };
                                        var reducedRules =
                                            rules.Where(r => r.CultureCode == rule.CultureCode && r.TabId == rule.TabId)
                                            .ToList();
                                        bool ruleExist = reducedRules.Any(r => r.Parameters == rule.Parameters);
                                        if (!ruleExist)
                                        {
                                            if (reducedRules.Any(r => r.Url == rule.Url)) // if duplicate url
                                            {
                                                rule.Url = catData.ItemID + "-" + url;
                                            }
                                            rules.Add(rule);
                                            catrules.Add(rule);
                                        }

                                        var proditems = objCtrl.GetList(catData.PortalId, -1, "CATXREF", " and NB1.XRefItemId = " + catData.ItemID.ToString(""));
                                        var l2        = objCtrl.GetList(catData.PortalId, -1, "CATCASCADE", " and NB1.XRefItemId = " + catData.ItemID.ToString(""));
                                        proditems.AddRange(l2);

                                        var pageurl  = "";
                                        var pageurl1 = rule.Url;
                                        // do paging for category (on all product modules.)
                                        foreach (var module in modules)
                                        {
                                            // ------- Paging URL ---------------
                                            var modsetting        = NBrightBuyUtils.GetSettings(portalId, module.ModuleID);
                                            var pagesize          = modsetting.GetXmlPropertyInt("genxml/textbox/pagesize");
                                            var staticlist        = modsetting.GetXmlPropertyBool("genxml/checkbox/staticlist");
                                            var defaultcatid      = modsetting.GetXmlPropertyBool("genxml/dropdownlist/defaultpropertyid");
                                            var defaultpropertyid = modsetting.GetXmlPropertyBool("genxml/dropdownlist/defaultcatid");
                                            if (pagesize > 0)
                                            {
                                                if (module.TabID != storesettings.ProductListTabId || staticlist)
                                                {
                                                    // on the non-default product list tab, add the moduleid, so we dont; get duplicates.
                                                    // NOTE: this only supports defaut paging url for 1 module on the defaut product list page. Other modules will have moduleid added to the url.

                                                    //pageurl = module.ModuleID + "-" + pageurl1;

                                                    //IGNORE NON DEFAULT MODULES.
                                                }
                                                else
                                                {
                                                    pageurl = pageurl1;


                                                    var pagetotal = Convert.ToInt32((proditems.Count / pagesize) + 1);
                                                    for (int i = 1; i <= pagetotal; i++)
                                                    {
                                                        rule = new UrlRule
                                                        {
                                                            CultureCode = ruleCultureCode,
                                                            TabId       = module.TabID,
                                                            Parameters  = "catref=" + caturlname + "&page=" + i + "&pagemid=" + module.ModuleID,
                                                            Url         = pageurl + "-" + i
                                                        };
                                                        ruleExist = reducedRules.Any(r => r.Parameters == rule.Parameters);
                                                        if (!ruleExist)
                                                        {
                                                            if (reducedRules.Any(r => r.Url == rule.Url)) // if duplicate url
                                                            {
                                                                rule.Url = module.ModuleID + "-" + rule.Url;
                                                            }
                                                            rules.Add(rule);
                                                            catrules.Add(rule);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        // ------- Product URL ---------------
                                        foreach (var xrefData in proditems)
                                        {
                                            //var product = new ProductData(xrefData.ParentItemId, cultureCode, false);
                                            var prdData = objCtrl.GetData(xrefData.ParentItemId, cultureCode);

                                            var pref = prdData.GetXmlProperty("genxml/textbox/txtproductref");

                                            string produrl = prdData.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                            ;
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = prdData.GetXmlProperty("genxml/lang/genxml/textbox/txtproductname");
                                            }
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = pref;
                                            }
                                            if (string.IsNullOrEmpty(produrl))
                                            {
                                                produrl = prdData.ItemID.ToString("");
                                            }
                                            //if (catref != "") produrl = catref + "-" + produrl;
                                            //if (catref != "") produrl = catref + "-" + produrl;
                                            produrl = newcatUrl + "/" + Utils.UrlFriendly(produrl);
                                            var prodrule = new UrlRule
                                            {
                                                CultureCode = ruleCultureCode,
                                                TabId       = storesettings.ProductDetailTabId,
                                                Parameters  = "catref=" + catDataLang.GUIDKey + "&ref=" + prdData.GUIDKey,
                                                Url         = produrl
                                            };
                                            reducedRules =
                                                rules.Where(
                                                    r => r.CultureCode == prodrule.CultureCode && r.TabId == prodrule.TabId)
                                                .ToList();
                                            ruleExist = reducedRules.Any(r => r.Parameters == prodrule.Parameters);
                                            if (!ruleExist)
                                            {
                                                if (reducedRules.Any(r => r.Url == prodrule.Url)) // if duplicate url
                                                {
                                                    prodrule.Url = prdData.ItemID + "-" + produrl;
                                                }
                                                rules.Add(prodrule);
                                                catrules.Add(prodrule);
                                            }
                                        }
                                    }
                                    UrlRulesCaching.SetCache(portalId, catCacheKey, new TimeSpan(1, 0, 0, 0), catrules);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Failed to generate url for module NBS", ex);
                    }
                }

                #endregion


                UrlRulesCaching.SetCache(portalId, portalCacheKey, new TimeSpan(1, 0, 0, 0), rules);


                #if DEBUG
                stopwatch.Stop();
                mess = $"PortalId: {portalId}. Time elapsed: {stopwatch.Elapsed.Milliseconds}ms. Module Count: {modules.Count()}. PurgedItems: {purgeResult.PurgedItemCount}";
                Logger.Error(mess);
                Console.WriteLine(mess);
                #endif


                return(rules);
            }
        }