Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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;

                        //先清除原有的字段列表
                        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);
            }
        }
        /// <summary>
        /// 设置方案项
        /// </summary>
        private Int32 SetDataItem(Int32 ArticleStatus, out DNNGo_PowerForms_Field fieldItem)
        {
            fieldItem = FieldItem;

            //权限
            fieldItem.Per_AllUsers = cbPermissionsAllUsers.Checked ? 0 : 1;

            String textStr, idStr = String.Empty;

            WebHelper.GetSelected(cblPermissionsRoles, out textStr, out idStr);
            fieldItem.Per_Roles = idStr;


            if (ddlControlType.Enabled)
            {
                fieldItem.FieldType = WebHelper.GetIntParam(Request, ddlControlType.UniqueID, (Int32)EnumViewControlType.TextBox);
            }

            fieldItem.ToolTip     = txtToolTip.Text;
            fieldItem.Alias       = txtAlias.Text;
            fieldItem.Description = txtDescription.Text;
            fieldItem.Required    = cbRequired.Checked ? 1 : 0;



            fieldItem.Options = SetItemSettings();


            if (divGroup.Visible)
            {
                SettingEntity GroupControl = new SettingEntity();
                GroupControl.Name = "GroupControl";
                Int32 GroupID = 0;
                if (int.TryParse(ControlHelper.GetWebFormValue(GroupControl, this), out GroupID))
                {
                }
                fieldItem.GroupID = GroupID;
            }

            fieldItem.FiledList = txtFTListCollection.Text;

            if (fieldItem.FieldType == (Int32)EnumViewControlType.Html || fieldItem.FieldType == (Int32)EnumViewControlType.RichTextBox)
            {
                fieldItem.DefaultValue = txtTinymceDefaultValue.Text;
            }
            else
            {
                fieldItem.DefaultValue = txtFTDefaultValue.Text;
            }
            fieldItem.Rows         = WebHelper.GetIntParam(Request, txtFTRows.UniqueID, 1);
            fieldItem.Verification = WebHelper.GetIntParam(Request, ddlVerification.UniqueID, 0);
            fieldItem.Direction    = WebHelper.GetIntParam(Request, rblFTDirection.UniqueID, 0);
            fieldItem.ListColumn   = WebHelper.GetIntParam(Request, txtFTListColumn.UniqueID, 1);

            fieldItem.Width       = WebHelper.GetIntParam(Request, txtFTWidth.UniqueID, 100);
            fieldItem.WidthSuffix = WebHelper.GetIntParam(Request, ddlFTWidth.UniqueID, 0);

            fieldItem.EqualsControl     = WebHelper.GetIntParam(Request, ddlFTEqualsControl.UniqueID, 0);
            fieldItem.AssociatedControl = WebHelper.GetIntParam(Request, ddlFTAssociatedControl.UniqueID, 0);
            fieldItem.InputLength       = WebHelper.GetIntParam(Request, txtFTInputLength.UniqueID, 2000);

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

            //发布状态和时间
            DateTime oTime = xUserTime.LocalTime();

            string[] expectedFormats = { "G", "g", "f", "F" };
            string   StartDate       = WebHelper.GetStringParam(Request, txtStartDate.UniqueID, oTime.ToString("MM/dd/yyyy"));
            string   StartTime       = WebHelper.GetStringParam(Request, txtStartTime.UniqueID, oTime.ToString("hh:mm tt"));

            if (DateTime.TryParseExact(String.Format("{0} {1}", StartDate, StartTime), "MM/dd/yyyy hh:mm tt", new CultureInfo("en-US", false), DateTimeStyles.AllowWhiteSpaces, out oTime))
            {
                fieldItem.StartTime = oTime;
            }
            //发布状态和时间
            DateTime EndTime     = xUserTime.LocalTime().AddYears(10);
            string   DisableDate = WebHelper.GetStringParam(Request, txtDisableDate.UniqueID, EndTime.ToString("MM/dd/yyyy"));
            string   DisableTime = WebHelper.GetStringParam(Request, txtDisableTime.UniqueID, EndTime.ToString("hh:mm tt"));

            if (DateTime.TryParseExact(String.Format("{0} {1}", DisableDate, DisableTime), "MM/dd/yyyy hh:mm tt", new CultureInfo("en-US", false), DateTimeStyles.AllowWhiteSpaces, out EndTime))
            {
                fieldItem.EndTime = EndTime;
            }

            if (ArticleStatus == -1)//如果没有指定状态就取控件的
            {
                fieldItem.Status = cbStatus.Checked ? (Int32)EnumStatus.Activation : (Int32)EnumStatus.Hide;
            }
            else
            {
                fieldItem.Status = ArticleStatus;
            }


            Int32 SaveResult = 0;

            if (fieldItem.ID > 0)
            {
                SaveResult = fieldItem.Update();
            }
            else
            {
                fieldItem.Name = txtName.Text;

                QueryParam qp = new QueryParam();
                qp.Where.Add(new SearchParam(DNNGo_PowerForms_Field._.ModuleId, ModuleId, SearchType.Equal));
                qp.Where.Add(new SearchParam(DNNGo_PowerForms_Field._.Name, fieldItem.Name, SearchType.Equal));
                if (DNNGo_PowerForms_Field.FindCount(qp) == 0)
                {
                    fieldItem.ModuleId = ModuleId;
                    fieldItem.PortalId = PortalId;


                    QueryParam Sqp = new QueryParam();
                    Sqp.ReturnFields = Sqp.Orderfld = DNNGo_PowerForms_Field._.Sort;
                    Sqp.OrderType    = 1;
                    Sqp.Where.Add(new SearchParam(DNNGo_PowerForms_Field._.ModuleId, ModuleId, SearchType.Equal));
                    fieldItem.Sort = Convert.ToInt32(DNNGo_PowerForms_Field.FindScalar(Sqp)) + 2;



                    //构造默认的验证方式
                    if (fieldItem.FieldType == (Int32)EnumViewControlType.DatePicker)
                    {
                        fieldItem.Verification = (Int32)EnumVerification.date;
                    }
                    else if (fieldItem.FieldType == (Int32)EnumViewControlType.FileUpload)
                    {
                    }
                    else if (fieldItem.FieldType == (Int32)EnumViewControlType.TextBox_Email)
                    {
                        fieldItem.Verification = (Int32)EnumVerification.email;
                    }


                    SaveResult = fieldItem.Insert();
                }
                else
                {
                    SaveResult = -1;
                }
            }

            return(SaveResult);
        }