/// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The ID of the Module being imported</param>
        /// <param name="Content">The Content being imported</param>
        /// <param name="Version">The Version of the Module Content being imported</param>
        /// <param name="UserID">The UserID of the User importing the Content</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------

        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            ImportExportHelper ieHelper = new ImportExportHelper();

            ieHelper.ModuleID = ModuleID;
            ieHelper.UserId   = UserId;

            if (!String.IsNullOrEmpty(Content))
            {
                //将XML转换为实体
                XmlFormat xf = new XmlFormat();
                xf.XmlDoc.LoadXml(Content);
                List <GalleryContentEntity>  XmlContentList = xf.ToList <GalleryContentEntity>();
                List <GallerySettingsEntity> XmlSettingList = xf.ToList <GallerySettingsEntity>();


                //插入成功的数量
                Int32 InsertResult = 0;



                //插入内容的记录
                foreach (GalleryContentEntity XmlContentItem in XmlContentList)
                {
                    DNNGo_LayerGallery_Content ContentItem = ieHelper.XmlToEntity(XmlContentItem);

                    if (ContentItem.Insert() > 0)
                    {
                        //导入项
                        ieHelper.ImportItem(ContentItem, XmlContentItem.ItemList);

                        InsertResult++;
                    }
                }

                //插入设置的记录
                foreach (GallerySettingsEntity XmlSettingItem in XmlSettingList)
                {
                    if (XmlSettingItem != null && !String.IsNullOrEmpty(XmlSettingItem.SettingName) && XmlSettingItem.SettingName.IndexOf("Global_") >= 0 && XmlSettingItem.SettingValue != null)
                    {
                        ieHelper.UpdateModuleSetting(ModuleID, XmlSettingItem.SettingName, XmlSettingItem.SettingValue);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 从XML导入数据
        /// </summary>
        protected void cmdImportFormXml_Click(object sender, EventArgs e)
        {
            try
            {
                HttpPostedFile hpfile = fuImportFormXml.PostedFile;

                if (hpfile.ContentLength > 0)
                {
                    if (Path.GetExtension(hpfile.FileName).IndexOf(".xml", StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        ImportExportHelper ieHelper = new ImportExportHelper();
                        ieHelper.ModuleID = ModuleId;
                        ieHelper.UserId   = UserId;

                        //构造需要上传的路径
                        String   XmlFilePath = String.Format("{0}LayerGallery\\Import\\{1}_{2}", PortalSettings.HomeDirectoryMapPath, xUserTime.UtcTime().ToString("yyyyMMddHHmmssffff"), fuImportFormXml.FileName);
                        FileInfo XmlFile     = new FileInfo(XmlFilePath);
                        //判断文件夹是否存在
                        if (!XmlFile.Directory.Exists)
                        {
                            XmlFile.Directory.Create();
                        }
                        //保存文件
                        fuImportFormXml.SaveAs(XmlFilePath);
                        //将XML转换为实体
                        XmlFormat xf = new XmlFormat(XmlFilePath);
                        List <GalleryContentEntity>  XmlContentList = xf.ToList <GalleryContentEntity>();
                        List <GallerySettingsEntity> XmlSettingList = xf.ToList <GallerySettingsEntity>();


                        //插入成功的数量
                        Int32 InsertResult = 0;
                        //插入内容的记录
                        foreach (GalleryContentEntity XmlContentItem in XmlContentList)
                        {
                            DNNGo_LayerGallery_Content ContentItem = ieHelper.XmlToEntity(XmlContentItem);

                            if (ContentItem.Insert() > 0)
                            {
                                InsertResult++;

                                //导入项
                                ieHelper.ImportItem(ContentItem, XmlContentItem.ItemList);

                                //删除临时上传的文件
                                if (XmlFile.Exists)
                                {
                                    XmlFile.Delete();
                                }
                            }
                        }

                        //插入设置的记录
                        foreach (GallerySettingsEntity XmlSettingItem in XmlSettingList)
                        {
                            if (XmlSettingItem != null && !String.IsNullOrEmpty(XmlSettingItem.SettingName) && XmlSettingItem.SettingName.IndexOf("Global_") >= 0 && XmlSettingItem.SettingValue != null)
                            {
                                ieHelper.UpdateModuleSetting(ModuleId, XmlSettingItem.SettingName, XmlSettingItem.SettingValue);
                            }
                        }

                        //删除临时上传的文件
                        if (XmlFile.Exists)
                        {
                            XmlFile.Delete();
                        }

                        //提示
                        mTips.LoadMessage("ImportContentSuccess", EnumTips.Success, this, new String[] { InsertResult.ToString() });

                        //跳转
                        Response.Redirect(xUrl("Sliders"));
                    }
                    else
                    {
                        //上传文件的后缀名错误
                        mTips.IsPostBack = true;
                        mTips.LoadMessage("ImportContentExtensionError", EnumTips.Success, this, new String[] { "" });
                    }
                }
                else
                {
                    //为上传任何数据
                    mTips.IsPostBack = true;
                    mTips.LoadMessage("ImportContentNullError", EnumTips.Success, this, new String[] { "" });
                }
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        /// <summary>
        /// 更新单个Slider设置
        /// </summary>
        /// <param name="Slider_Items"></param>
        /// <returns></returns>
        public Int32 UpdateSliderItem(Dictionary <String, object> Slider_Items, int Slider_Index)
        {
            List <KeyValueEntity> tempSlider = ConvertTo.ToList(Slider_Items);


            DNNGo_LayerGallery_Content Slider = new DNNGo_LayerGallery_Content();

            //取出编号
            Slider.ID = ConvertTo.GetValue <Int32>(tempSlider, "id", 0);

            if (Slider.ID > 0)
            {
                Slider = DNNGo_LayerGallery_Content.FindByKeyForEdit(Slider.ID);
            }

            //移除层的定义,将Slider项的定义序列化后存储
            Slider_Items.Remove("layers");
            Slider.Options = jsSerializer.Serialize(Slider_Items);

            //取出排序编号
            Slider.Sort = ConvertTo.GetValue <Int32>(tempSlider, "sort", Slider_Index + 1);

            //取出标题
            Slider.Title = ConvertTo.GetValue <String>(tempSlider, "title", "");

            //开始时间
            DateTime oTime = xUserTime.LocalTime();

            string[] expectedFormats = { "G", "g", "f", "F" };
            string   StartTime       = ConvertTo.GetValue <String>(tempSlider, "StartTime", oTime.ToString("MM/dd/yyyy HH:mm", new CultureInfo("en-US", false)));

            if (DateTime.TryParseExact(StartTime, "MM/dd/yyyy HH:mm", new CultureInfo("en-US", false), DateTimeStyles.AllowWhiteSpaces, out oTime))
            {
                if (oTime.Second == 0)
                {
                    oTime = oTime.AddSeconds(xUserTime.LocalTime().Second);                   //补秒
                }
                Slider.StartTime = oTime;
            }


            //结束时间
            DateTime EndTime  = xUserTime.LocalTime().AddYears(10);
            string   sEndTime = ConvertTo.GetValue <String>(tempSlider, "EndTime", EndTime.ToString("MM/dd/yyyy HH:mm", new CultureInfo("en-US", false)));

            if (DateTime.TryParseExact(sEndTime, "MM/dd/yyyy HH:mm", new CultureInfo("en-US", false), DateTimeStyles.AllowWhiteSpaces, out EndTime))
            {
                if (EndTime.Second == 0)
                {
                    EndTime = EndTime.AddSeconds(xUserTime.LocalTime().Second);                     //补秒
                }
                Slider.EndTime = EndTime;
            }


            Slider.LastTime = xUserTime.UtcTime();
            Slider.LastIP   = WebHelper.UserHost;
            Slider.LastUser = UserId;

            if (Slider.ID > 0)
            {
                //更新
                Slider.Update();
            }
            else
            {
                //新增
                Slider.ModuleId = ModuleId;
                Slider.PortalId = PortalId;
                Slider.Status   = (Int32)EnumStatus.Published;


                Slider.ID = Slider.Insert();
            }



            return(Slider.ID);
        }