コード例 #1
0
        public void ConvertTemplates(int portalId)
        {
            BBStoreController          controller       = new BBStoreController();
            ModuleController           moduleController = new ModuleController();
            List <ModuleProductInfo>   moPros           = controller.GetModuleProducts(portalId);
            List <ProductTemplateInfo> templates        = controller.GetProductTemplates(portalId);

            TemplateControl templateControl = LoadControl("Controls/TemplateControl.ascx") as TemplateControl;

            if (templateControl != null)
            {
                // ModuleProducts
                templateControl.Key = "SimpleProduct";
                foreach (ModuleProductInfo moPro in moPros)
                {
                    ModuleInfo module = moduleController.GetModule(moPro.ModuleId);
                    if (moPro.Template != String.Empty)
                    {
                        string name = "Module_" + moPro.ModuleId.ToString();
                        templateControl.SaveTemplate(moPro.Template, name, BBStore.TemplateControl.TemplateEnum.Neutral);
                        moduleController.UpdateModuleSetting(moPro.ModuleId, "Template", name);
                    }
                    else
                    {
                        ProductTemplateInfo templateInfo = (from t in templates where t.ProductTemplateId == moPro.ProductTemplateId select t).FirstOrDefault();
                        if (templateInfo != null)
                        {
                            string name = templateInfo.TemplateName;
                            templateControl.SaveTemplate(templateInfo.Template, name, BBStore.TemplateControl.TemplateEnum.Neutral);
                            moduleController.UpdateModuleSetting(moPro.ModuleId, "Template", name);
                            moduleController.UpdateModuleSetting(moPro.ModuleId, "ProductId", moPro.ProductId.ToString());
                            moduleController.UpdateModuleSetting(moPro.ModuleId, "ShowNetPrice", moPro.IsTaxIncluded.ToString());
                        }
                    }
                    controller.DeleteModuleProduct(PortalId, moPro.ModuleId);
                }

                // ProductTemplates
                ArrayList allModules = moduleController.GetAllModules();
                foreach (ProductTemplateInfo template in templates)
                {
                    templateControl.Key = template.TemplateSource;
                    templateControl.SaveTemplate(template.Template, template.TemplateName, BBStore.TemplateControl.TemplateEnum.Neutral);

                    // We need to update the settings for all modules which have this ProductTemplateId as setting
                    int id = template.ProductTemplateId;

                    foreach (ModuleInfo module in allModules)
                    {
                        Hashtable settings = moduleController.GetModuleSettings(module.ModuleID);
                        if (settings["ProductTemplateId"] != null && Convert.ToInt32(settings["ProductTemplateId"]) == id)
                        {
                            moduleController.UpdateModuleSetting(module.ModuleID, "Template", template.TemplateName);
                            moduleController.DeleteModuleSetting(module.ModuleID, "ProductTemplateId");
                        }
                        if (settings["ProductGroupTemplateId"] != null && Convert.ToInt32(settings["ProductGroupTemplateId"]) == id)
                        {
                            moduleController.UpdateModuleSetting(module.ModuleID, "Template", template.TemplateName);
                            moduleController.DeleteModuleSetting(module.ModuleID, "ProductGroupTemplateId");
                        }
                    }
                    controller.DeleteProductTemplate(template.ProductTemplateId);
                }
                // DynamicPage -> ProductModulePage for Product List Modules
                foreach (ModuleInfo module in allModules)
                {
                    Hashtable settings = moduleController.GetModuleSettings(module.ModuleID);
                    if (settings["DynamicPage"] != null && settings["CssHover"] == null)
                    {
                        moduleController.UpdateModuleSetting(module.ModuleID, "ProductModulePage", (string)settings["DynamicPage"]);
                        moduleController.DeleteModuleSetting(module.ModuleID, "DynamicPage");
                    }
                }

                // Mailtemplates
                string templateContent = "";
                string templateFile    = this.PortalSettings.HomeDirectoryMapPath + @"Templates\order.html";
                if (File.Exists(templateFile))
                {
                    templateContent     = File.ReadAllText(templateFile);
                    templateControl.Key = "Order";
                    templateControl.SaveTemplate(templateContent, "Order", BBStore.TemplateControl.TemplateEnum.Portal);
                    File.Delete(templateFile);
                }
                templateFile = MapPath(ControlPath + @"\Templates\order.html");
                if (File.Exists(templateFile))
                {
                    templateContent     = File.ReadAllText(templateFile);
                    templateControl.Key = "Order";
                    templateControl.SaveTemplate(templateContent, "Order", BBStore.TemplateControl.TemplateEnum.Neutral);
                    File.Delete(templateFile);
                }
                templateFile = this.PortalSettings.HomeDirectoryMapPath + @"Templates\request.html";
                if (File.Exists(templateFile))
                {
                    templateContent     = File.ReadAllText(templateFile);
                    templateControl.Key = "Request";
                    templateControl.SaveTemplate(templateContent, "Request", BBStore.TemplateControl.TemplateEnum.Portal);
                    File.Delete(templateFile);
                }
                templateFile = MapPath(ControlPath + @"\Templates\request.html");
                if (File.Exists(templateFile))
                {
                    templateContent     = File.ReadAllText(templateFile);
                    templateControl.Key = "Request";
                    templateControl.SaveTemplate(templateContent, "Request", BBStore.TemplateControl.TemplateEnum.Neutral);
                    File.Delete(templateFile);
                }
            }
        }