Exemple #1
0
        /// -----------------------------------------------------------------------------
        /// <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)
        {
            //先清除原有的字段列表
            QueryParam qp          = new QueryParam();
            Int32      RecordCount = 0;

            qp.Where.Add(new SearchParam("ModuleId", ModuleID, SearchType.Equal));
            List <DNNGo_PowerForms_Field> fieldList = DNNGo_PowerForms_Field.FindAll(qp, out RecordCount);

            foreach (DNNGo_PowerForms_Field fieldItem in fieldList)
            {
                fieldItem.Delete();
            }


            ImportExportHelper ieHelper = new ImportExportHelper();

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

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

                Int32 InsertResult = 0;
                foreach (FieldEntity XmlField in XmlFieldList)
                {
                    DNNGo_PowerForms_Field FieldItem = ieHelper.XmlToEntity(XmlField);

                    FieldItem.CreateUser = UserId;
                    FieldItem.CreateTime = DateTime.Now;

                    FieldItem.LastIP   = WebHelper.UserHost;
                    FieldItem.LastTime = DateTime.Now;
                    FieldItem.LastUser = UserId;

                    if (FieldItem.Insert() > 0)
                    {
                        InsertResult++;
                    }
                }

                //插入设置的记录
                foreach (GallerySettingsEntity XmlSettingItem in XmlSettingList)
                {
                    if (!String.IsNullOrEmpty(XmlSettingItem.SettingName) && !String.IsNullOrEmpty(XmlSettingItem.SettingValue))
                    {
                        ieHelper.UpdateModuleSetting(XmlSettingItem.SettingName, XmlSettingItem.SettingValue);
                    }
                }
            }
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="FieldItem"></param>
        /// <param name="ControlName"></param>
        /// <returns></returns>
        public String ViewCreateIconPicker(SettingEntity FieldItem, String ControlName, String ControlID)
        {
            StringBuilder ControlHtml = new StringBuilder();//控件的HTML


            ControlHtml.AppendFormat("<select id=\"{0}\" name=\"{1}\" class=\"form-control search-select search-select-auto {2}\" ", ControlID, ControlName, ViewVerification(FieldItem));


            ControlHtml.AppendFormat(" style=\"width:{0}px;\" >", FieldItem.Width);


            List <OptionItem> Optins = new List <OptionItem>();

            if (String.IsNullOrEmpty(FieldItem.ListContent))//没有列表项的时候,需要加载默认的字体
            {
                String    xml_url = BaseModule.Server.MapPath(String.Format("{0}Resource/xml/SelectIcons.xml", BaseModule.ModulePath));
                XmlFormat xf      = new XmlFormat(xml_url);

                Optins = xf.ToList <OptionItem>();
            }
            else if (!String.IsNullOrEmpty(FieldItem.ListContent))
            {
                List <String> list = Common.GetList(FieldItem.ListContent.Replace(",", "|").Replace("\r\n", "|").Replace("\r", "|"), "|");

                for (Int32 i = 0; i < list.Count; i++)
                {
                    if (!String.IsNullOrEmpty(list[i]))
                    {
                        OptionItem Optin = new OptionItem();
                        Optin.Text  = list[i];
                        Optin.Value = list[i];
                        //判断是否包含有键值对,将键值对分离开
                        if (list[i].IndexOf(":") >= 0)
                        {
                            List <String> ItemKeyValue = Common.GetList(list[i], ":");
                            Optin.Text  = ItemKeyValue[0];
                            Optin.Value = ItemKeyValue[1];
                        }
                        Optins.Add(Optin);
                    }
                }
            }


            foreach (var Optin in Optins)
            {
                String DisabledStr = String.IsNullOrEmpty(Optin.Value) ? "disabled=\"disabled\"" : "";
                String CheckedStr  = !String.IsNullOrEmpty(Optin.Value) && FieldItem.DefaultValue.IndexOf(Optin.Value, StringComparison.CurrentCultureIgnoreCase) >= 0 ? "selected=\"selected\"" : "";
                ControlHtml.AppendFormat("<option value=\"{0}\" {2} {3}> {1}</option>", Optin.Value, Optin.Text, CheckedStr, DisabledStr).AppendLine();
            }

            ControlHtml.Append("</select>");

            return(ControlHtml.ToString());
        }
Exemple #3
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;

                        //先清除原有的字段列表
                        QueryParam qp          = new QueryParam();
                        Int32      RecordCount = 0;
                        qp.Where.Add(new SearchParam("ModuleId", ModuleId, SearchType.Equal));
                        List <DNNGo_PowerForms_Field> fieldList = DNNGo_PowerForms_Field.FindAll(qp, out RecordCount);
                        foreach (DNNGo_PowerForms_Field fieldItem in fieldList)
                        {
                            fieldItem.Delete();
                        }

                        //构造需要上传的路径
                        String   XmlFilePath = String.Format("{0}PowerForms\\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);

                        XmlFormat xf = new XmlFormat(XmlFilePath);

                        List <FieldEntity> XmlFieldList = xf.ToList <FieldEntity>();


                        Int32 InsertResult = 0;
                        foreach (FieldEntity XmlField in XmlFieldList)
                        {
                            DNNGo_PowerForms_Field FieldItem = ieHelper.XmlToEntity(XmlField);


                            FieldItem.CreateUser = UserId;
                            FieldItem.CreateTime = xUserTime.UtcTime();

                            FieldItem.ModuleId = ModuleId;
                            FieldItem.PortalId = PortalId;

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

                            if (FieldItem.Insert() > 0)
                            {
                                InsertResult++;
                            }
                        }

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

                        //跳转
                        Response.Redirect(xUrl("FieldList"));
                    }
                    else
                    {
                        //上传文件的后缀名错误
                        mTips.IsPostBack = true;
                        mTips.LoadMessage("UploadFieldExtensionError", EnumTips.Warning, this, new String[] { "xml" });
                    }
                }
                else
                {
                    //为上传任何数据
                    mTips.IsPostBack = true;
                    mTips.LoadMessage("ImportFieldNullError", EnumTips.Success, this, new String[] { "" });
                }
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
            }
        }