/// <summary>
    /// Saves form definition.
    /// </summary>
    /// <param name="oldFieldInfo">Form field info prior to the change</param>
    /// <param name="updatedFieldInfo">Form field info after the change has been made.</param>
    /// <returns>Error message if an error occurred</returns>
    protected string SaveFormDefinition(FormFieldInfo oldFieldInfo = null, FormFieldInfo updatedFieldInfo = null)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            if (RequestHelper.IsCallback())
            {
                return(GetString("formbuilder.missingeditpermission"));
            }

            RedirectToAccessDenied("cms.form", "EditForm");
        }

        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if ((mFormInfo != null) && (dci != null))
        {
            // Update database column of the changed field
            if (IsDatabaseChangeRequired(oldFieldInfo, updatedFieldInfo))
            {
                // Ensure the transaction
                using (var tr = new CMSLateBoundTransaction())
                {
                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    tr.BeginTransaction();

                    string error = UpdateDatabaseColumn(oldFieldInfo, updatedFieldInfo, tm, dci.ClassTableName);
                    if (!String.IsNullOrEmpty(error))
                    {
                        return(error);
                    }

                    // Commit the transaction
                    tr.Commit();
                }
            }

            // Update form definition
            dci.ClassFormDefinition = mFormInfo.GetXmlDefinition();

            // Save the class data
            DataClassInfoProvider.SetDataClassInfo(dci);

            // Update inherited classes with new fields
            FormHelper.UpdateInheritedClasses(dci);

            return(string.Empty);
        }
        else
        {
            return(GetString("FormBuilder.ErrorSavingForm"));
        }
    }
예제 #2
0
    /// <summary>
    /// Update form definitions of classes (especially system tables).
    /// </summary>
    private static void UpdateClasses()
    {
        var path    = Path.Combine(mWebsitePath, "App_Data\\CMSTemp\\Upgrade\\Classes");
        var classes = GetAllFiles(path);

        foreach (var classPath in classes)
        {
            var className = Path.GetFileNameWithoutExtension(classPath);
            var dataClass = DataClassInfoProvider.GetDataClassInfo(className);
            if (dataClass != null)
            {
                var newVersionDefinition = File.ReadAllText(classPath);
                var newVersionFi         = new FormInfo(newVersionDefinition);
                var oldVersionFi         = new FormInfo(dataClass.ClassFormDefinition);

                CopyCustomFields(oldVersionFi, newVersionFi);

                // Save the modified form definition
                dataClass.ClassFormDefinition = newVersionFi.GetXmlDefinition();

                // Update the scheme
                dataClass.ClassXmlSchema = new TableManager(dataClass.ClassConnectionString).GetXmlSchema(dataClass.ClassTableName);

                // Save the new definition
                dataClass.Update();
            }
        }
    }
    /// <summary>
    /// Generates default form definition.
    /// </summary>
    private void GenerateDefinition()
    {
        // Get info on the class
        var classInfo = DataClassInfoProvider.GetDataClassInfo(QueryHelper.GetInteger("classid", 0));
        if (classInfo == null)
        {
            return;
        }

        var manager = new TableManager(classInfo.ClassConnectionString);

        // Update schema and definition for existing class
        classInfo.ClassXmlSchema = manager.GetXmlSchema(classInfo.ClassTableName);

        var fi = new FormInfo();
        try
        {
            fi.LoadFromDataStructure(classInfo.ClassTableName, manager, true);
        }
        catch (Exception ex)
        {
            // Show error message if something caused unhandled exception
            LogAndShowError("ClassFields", "GenerateDefinition", ex);
            return;
        }

        classInfo.ClassFormDefinition = fi.GetXmlDefinition();
        DataClassInfoProvider.SetDataClassInfo(classInfo);

        URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "gen", "1"));
    }
예제 #4
0
    /// <summary>
    /// Generates default form definition.
    /// </summary>
    private void GenerateDefinition()
    {
        // Get info on the class
        var classInfo = DataClassInfoProvider.GetDataClassInfo(QueryHelper.GetInteger("classid", 0));

        if (classInfo == null)
        {
            return;
        }

        var manager = new TableManager(classInfo.ClassConnectionString);
        var fi      = new FormInfo();

        try
        {
            fi.LoadFromDataStructure(classInfo.ClassTableName, manager, true);
        }
        catch (Exception ex)
        {
            // Show error message if something caused unhandled exception
            LogAndShowError("ClassFields", "GenerateDefinition", ex);
            return;
        }

        classInfo.ClassFormDefinition = fi.GetXmlDefinition();
        DataClassInfoProvider.SetDataClassInfo(classInfo);

        URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "gen", "1"));
    }
예제 #5
0
        /// <inheritdoc />
        public void RemoveField(IWebPartField field)
        {
            var formInfo = new FormInfo(field.WebPart.WebPartProperties);

            formInfo.RemoveFields(x => x.Name == field.Name);

            field.WebPart.WebPartProperties = formInfo.GetXmlDefinition();

            this.SaveFormUpdates(field.WebPart);
        }
예제 #6
0
        /// <inheritdoc />
        public void Update(IWebPartField field)
        {
            var formInfo  = new FormInfo(field.WebPart.WebPartProperties);
            var fieldInfo = formInfo.GetFormField(field.Name);

            fieldInfo.AllowEmpty   = field.AllowEmpty;
            fieldInfo.Caption      = field.Caption;
            fieldInfo.DataType     = field.DataType;
            fieldInfo.DefaultValue = field.DefaultValue;
            fieldInfo.Size         = field.Size;

            formInfo.UpdateFormField(field.Name, fieldInfo);

            field.WebPart.WebPartProperties = formInfo.GetXmlDefinition();

            this.SaveFormUpdates(field.WebPart);
        }
예제 #7
0
        private void UpdateForm()
        {
            var formClassInfo = DataClassInfoProvider.GetDataClassInfo(FORM_CLASS_NAME);

            if (formClassInfo == null)
            {
                return;
            }

            var form = new FormInfo(formClassInfo.ClassFormDefinition);

            if (form.FieldExists(FORM_FIELD_NAME))
            {
                return;
            }

            // Update ClassFormDefinition
            var field = CreateFormField();

            form.AddFormItem(field);
            formClassInfo.ClassFormDefinition = form.GetXmlDefinition();
            formClassInfo.Update();

            // Update Form builder JSON
            IFormBuilderConfigurationSerializer formBuilderConfigurationSerializer = Service.Resolve <IFormBuilderConfigurationSerializer>();
            var contactUsForm            = BizFormInfoProvider.GetBizFormInfo(FORM_NAME, mSite.SiteID);
            var formBuilderConfiguration = formBuilderConfigurationSerializer.Deserialize(contactUsForm.FormBuilderLayout);

            formBuilderConfiguration.EditableAreas.LastOrDefault()
            .Sections.LastOrDefault()
            .Zones.LastOrDefault()
            .FormComponents
            .Add(new FormComponentConfiguration {
                Properties = new ConsentAgreementProperties()
                {
                    Guid = field.Guid
                }
            });
            contactUsForm.FormBuilderLayout = formBuilderConfigurationSerializer.Serialize(formBuilderConfiguration, true);
            contactUsForm.Update();
        }
예제 #8
0
        /// <inheritdoc />
        public IWebPartField AddField(IWebPartField field, IWebPart webPart)
        {
            var formInfo  = new FormInfo(webPart.WebPartProperties);
            var fieldInfo = new FormFieldInfo
            {
                AllowEmpty   = field.AllowEmpty,
                Caption      = field.Caption,
                DataType     = field.DataType,
                DefaultValue = field.DefaultValue,
                Name         = field.Name,
                Size         = field.Size,
            };

            formInfo.AddFormItem(fieldInfo);

            webPart.WebPartProperties = formInfo.GetXmlDefinition();

            this.SaveFormUpdates(webPart);

            return(this.AppendWebPart(fieldInfo, webPart).ActLike <IWebPartField>());
        }
예제 #9
0
        private void UpdateForm(string formName, string formFieldName)
        {
            var formClassInfo = DataClassInfoProvider.GetDataClassInfo($"BizForm.{formName}");

            if (formClassInfo == null)
            {
                return;
            }

            var form = new FormInfo(formClassInfo.ClassFormDefinition);

            if (form.FieldExists(formFieldName))
            {
                return;
            }

            // Update ClassFormDefinition
            var field = CreateFormField(formFieldName);

            form.AddFormItem(field);
            formClassInfo.ClassFormDefinition = form.GetXmlDefinition();
            formClassInfo.Update();

            // Update Form builder JSON
            var contactUsForm            = BizFormInfo.Provider.Get(formName, mSite.SiteID);
            var formBuilderConfiguration = mFormBuilderConfigurationSerializer.Deserialize(contactUsForm.FormBuilderLayout);

            formBuilderConfiguration.EditableAreas.LastOrDefault()
            .Sections.LastOrDefault()
            .Zones.LastOrDefault()
            .FormComponents
            .Add(new FormComponentConfiguration {
                Properties = new ConsentAgreementProperties()
                {
                    Guid = field.Guid
                }
            });
            contactUsForm.FormBuilderLayout = mFormBuilderConfigurationSerializer.Serialize(formBuilderConfiguration, true);
            contactUsForm.Update();
        }
예제 #10
0
    /// <summary>
    /// Initializes the form.
    /// </summary>
    /// <param name="basicForm">Form</param>
    /// <param name="dr">Data row with the data</param>
    /// <param name="fi">Form info</param>
    private void InitForm(BasicForm basicForm, DataRow dr, FormInfo fi)
    {
        if (basicForm != null)
        {
            basicForm.DataRow = dr;
            if (webPartInstance != null)
            {
                basicForm.MacroTable = webPartInstance.MacroTable;
            }
            else
            {
                basicForm.MacroTable = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            }

            if (!RequestHelper.IsPostBack() && (webPartInstance != null))
            {
                fi = new FormInfo(fi.GetXmlDefinition());

                // Load the collapsed/un-collapsed state of categories
                var categories = fi.GetCategoryNames();
                foreach (string category in categories)
                {
                    FormCategoryInfo fci = fi.GetFormCategory(category);
                    if (ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.Collapsible, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false))
                    {
                        fci.SetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, "false");
                    }
                }
            }

            basicForm.SubmitButton.Visible = false;
            basicForm.SiteName             = SiteContext.CurrentSiteName;
            basicForm.FormInformation      = fi;
            basicForm.ShowPrivateFields    = true;
            basicForm.OnItemValidation    += formElem_OnItemValidation;
            basicForm.ReloadData();
        }
    }
예제 #11
0
    /// <summary>
    /// Initializes the form.
    /// </summary>
    /// <param name="form">Form</param>
    /// <param name="dr">Data row with the data</param>
    /// <param name="fi">Form info</param>
    private void InitForm(BasicForm form, DataRow dr, FormInfo fi)
    {
        if (form != null)
        {
            form.DataRow = dr;
            if (webPartInstance != null)
            {
                form.MacroTable = webPartInstance.MacroTable;
            }
            else
            {
                form.MacroTable = new Hashtable();
            }

            if (!RequestHelper.IsPostBack() && (webPartInstance != null))
            {
                fi = new FormInfo(fi.GetXmlDefinition());

                // Load the collapsed/un-collapsed state of categories
                var categories = fi.GetCategoryNames();
                foreach (string category in categories)
                {
                    FormCategoryInfo fci = fi.GetFormCategory(category);
                    if (fci.CategoryCollapsible && fci.CategoryCollapsedByDefault && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false))
                    {
                        fci.CategoryCollapsedByDefault = false;
                    }
                }
            }

            form.SubmitButton.Visible = false;
            form.SiteName             = CMSContext.CurrentSiteName;
            form.FormInformation      = fi;
            form.ShowPrivateFields    = true;
            form.OnItemValidation    += formElem_OnItemValidation;
            form.ReloadData();
        }
    }
    /// <summary>
    /// Update form definitions of classes (especially system tables).
    /// </summary>
    private static void UpdateClasses()
    {
        DataSet classes = GetFormDefinitions();

        if (!DataHelper.DataSourceIsEmpty(classes))
        {
            foreach (DataRow row in classes.Tables[0].Rows)
            {
                string objectName    = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
                string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

                if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(newDefinition))
                {
                    var dataClass = DataClassInfoProvider.GetDataClassInfo(objectName);
                    if (dataClass != null)
                    {
                        var newVersionFi = new FormInfo(newDefinition);

                        // Copy custom fields only for system tables
                        if (dataClass.ClassShowAsSystemTable)
                        {
                            var oldVersionFi = new FormInfo(dataClass.ClassFormDefinition);
                            CopyCustomFields(oldVersionFi, newVersionFi, false);
                        }

                        // Save the modified form definition
                        dataClass.ClassFormDefinition = newVersionFi.GetXmlDefinition();

                        // Update the scheme
                        dataClass.ClassXmlSchema = new TableManager(dataClass.ClassConnectionString).GetXmlSchema(dataClass.ClassTableName);

                        // Save the new definition
                        dataClass.Update();
                    }
                }
            }
        }
    }
예제 #13
0
    /// <summary>
    /// Adds form field info to the form to the specified position.
    /// </summary>
    /// <param name="ffi">Form field info which will be added</param>
    /// <param name="category">Category name</param>
    /// <param name="position">Field position in the category</param>
    private string AddField(FormFieldInfo ffi, string category, int position)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            RedirectToAccessDenied("cms.form", "EditForm");
        }

        var dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if (dci != null)
        {
            RaiseBeforeDefinitionUpdate();

            // Ensure the transaction
            using (var tr = new CMSLateBoundTransaction())
            {
                string columnType = DataTypeManager.GetSqlType(ffi.DataType, ffi.Size, ffi.Precision);

                TableManager tm = new TableManager(dci.ClassConnectionString);
                tr.BeginTransaction();

                // Add new column
                tm.AddTableColumn(dci.ClassTableName, ffi.Name, columnType, true, null);

                // Add field to form
                FormInfo.AddFormItem(ffi);
                if (!String.IsNullOrEmpty(category) || position >= 0)
                {
                    FormInfo.MoveFormFieldToPositionInCategory(ffi.Name, category, position);
                }

                // Update form definition
                dci.ClassFormDefinition = FormInfo.GetXmlDefinition();

                // Update class schema
                dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);

                try
                {
                    // Save the class data
                    DataClassInfoProvider.SetDataClassInfo(dci);
                }
                catch (Exception)
                {
                    return(GetString("FormBuilder.ErrorSavingForm"));
                }

                // Generate default view
                SqlGenerator.GenerateDefaultView(dci, SiteContext.CurrentSiteName);
                QueryInfoProvider.ClearDefaultQueries(dci, true, true);

                // Hide field for alternative forms that require it
                HideFieldInAlternativeForms(ffi, dci);

                // Commit the transaction
                tr.Commit();
            }

            ClearHashtables();

            RaiseAfterDefinitionUpdate();

            // Update inherited classes with new fields
            FormHelper.UpdateInheritedClasses(dci);
        }
        else
        {
            return(GetString("FormBuilder.ErrorSavingForm"));
        }

        return(string.Empty);
    }
    public static void Update60()
    {
        EventLogProvider evp = new EventLogProvider();

        evp.LogEvent("I", DateTime.Now, "Upgrade to 6.0", "Upgrade - Start");

        DataClassInfo dci = null;


        #region "CMS.UserSettings"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.usersettings");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "UserAuthenticationGUID";
                    ffi.DataType    = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "UserBounces";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible     = false;
                    ffi.Caption     = "UserBounces";

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "UserLinkedInID";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 100;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "UserLogActivities";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "UserPasswordRequestHash";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 100;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("CMS_UserSettings");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("CMS_UserSettings");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.UserSettings - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Ecommerce - Customer"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.customer");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "CustomerSiteID";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    TableManager tm = new TableManager(dci.ClassConnectionString);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();
                    dci.ClassXmlSchema      = tm.GetXmlSchema("COM_Customer");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);

                    tm.RefreshCustomViews("COM_Customer");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Customer - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Ecommerce - Order"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.order");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "OrderCulture";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 10;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderIsPaid";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderTotalPriceInMainCurrency";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("OrderStatusID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderStatusID", ffi);
                    }

                    ffi = fi.GetFormField("OrderShippingAddressID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderShippingAddressID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_Order");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_Order");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Order - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Ecommerce - OrderItem"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.orderitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "OrderItemBundleGUID";
                    ffi.DataType    = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemIsPrivate";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemPrice";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemSendNotification";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemSKU";
                    ffi.DataType    = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemText";
                    ffi.DataType    = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemTotalPriceInMainCurrency";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "OrderItemValidTo";
                    ffi.DataType    = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_OrderItem");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_OrderItem");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.OrderItem - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Ecommerce - Shopping cart item"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.shoppingcartitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "CartItemBundleGUID";
                    ffi.DataType    = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "CartItemIsPrivate";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "CartItemPrice";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "CartItemText";
                    ffi.DataType    = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "CartItemValidTo";
                    ffi.DataType    = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("CartItemGuid");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("CartItemGuid", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_ShoppingCartSKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_ShoppingCartSKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.ShoppingCartItem - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Ecommerce - SKU"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.sku");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "SKUBundleInventoryType";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 50;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUConversionName";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 100;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUConversionValue";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 200;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUMaxDownloads";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUMaxItemsInOrder";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUMaxPrice";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUMembershipGUID";
                    ffi.DataType    = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUMinPrice";
                    ffi.DataType    = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUNeedsShipping";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUPrivateDonation";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUProductType";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 50;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUSiteID";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUValidFor";
                    ffi.DataType    = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUValidity";
                    ffi.DataType    = FormFieldDataTypeEnum.Text;
                    ffi.Size        = 50;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi             = new FormFieldInfo();
                    ffi.Name        = "SKUValidUntil";
                    ffi.DataType    = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("SKUDepartmentID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("SKUDepartmentID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_SKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_SKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.SKU - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Community - Group"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("Community.Group");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name         = "GroupLogActivity";
                    ffi.DataType     = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty   = true;
                    ffi.PublicField  = false;
                    ffi.System       = true;
                    ffi.FieldType    = FormFieldControlTypeEnum.CheckBoxControl;
                    ffi.Visible      = true;
                    ffi.DefaultValue = "true";
                    ffi.Caption      = "GroupLogActivity";

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Community_Group");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Community_Group");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Community.Group - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "Newsletter - Subscriber"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("newsletter.subscriber");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name        = "SubscriberBounces";
                    ffi.DataType    = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty  = true;
                    ffi.PublicField = false;
                    ffi.System      = true;
                    ffi.FieldType   = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible     = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Newsletter_Subscriber");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Newsletter_Subscriber");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Newsletter.Subscriber - Upgrade", "Upgrade", ex);
        }

        #endregion


        #region "CMS.Document"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.document");
            if (dci != null)
            {
                SearchSettings     ss  = dci.ClassSearchSettingsInfos;
                SearchSettingsInfo ssi = ss.GetSettingsInfo("42f446ee-9818-4596-8124-54a38f64aa05");
                if (ssi != null)
                {
                    ssi.Searchable = true;
                    ss.SetSettingsInfo(ssi);
                }

                DataClassInfoProvider.SetDataClass(dci);
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.Document - Upgrade", "Upgrade", ex);
        }

        #endregion


        // Set the path to the upgrade package
        mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/upgrade_55R2_60.zip");

        mWebsitePath = HttpContext.Current.Server.MapPath("~/");

        TableManager dtm = new TableManager(null);

        // Update all views
        dtm.RefreshDocumentViews();

        // Set data version
        ObjectHelper.SetSettingsKeyValue("CMSDataVersion", "6.0");

        // Clear hashtables
        CMSObjectHelper.ClearHashtables();

        // Clear the cache
        CacheHelper.ClearCache(null, true);

        // Drop the routes
        CMSMvcHandler.DropAllRoutes();

        // Init the Mimetype helper (required for the Import)
        MimeTypeHelper.LoadMimeTypes();

        CMSThread thread = new CMSThread(Upgrade60Import);
        thread.Start();
    }
    /// <summary>
    /// Update form definitions of classes (especially system tables).
    /// </summary>
    private static void UpdateClasses()
    {
        DataSet classes = GetFormDefinitions();
        if (!DataHelper.DataSourceIsEmpty(classes))
        {
            foreach (DataRow row in classes.Tables[0].Rows)
            {
                string objectName = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
                string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

                if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(newDefinition))
                {
                    var dataClass = DataClassInfoProvider.GetDataClassInfo(objectName);
                    if (dataClass != null)
                    {
                        var newVersionFi = new FormInfo(newDefinition);

                        // Copy custom fields only for system tables
                        if (dataClass.ClassShowAsSystemTable)
                        {
                            var oldVersionFi = new FormInfo(dataClass.ClassFormDefinition);
                            CopyCustomFields(oldVersionFi, newVersionFi, false);
                        }

                        // Save the modified form definition
                        dataClass.ClassFormDefinition = newVersionFi.GetXmlDefinition();

                        // Update the scheme
                        dataClass.ClassXmlSchema = new TableManager(dataClass.ClassConnectionString).GetXmlSchema(dataClass.ClassTableName);

                        // Save the new definition
                        dataClass.Update();
                    }
                }
            }
        }
    }
    /// <summary>
    /// Updates an existing alternative forms form definitions. Appends existing custom fields to new version definitions.
    /// </summary>
    private static void UpdateAlternativeForms()
    {
        DataSet classes = GetFormDefinitions(true);
        if (!DataHelper.DataSourceIsEmpty(classes))
        {
            foreach (DataRow row in classes.Tables[0].Rows)
            {
                string objectName = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
                string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

                if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(newDefinition))
                {
                    var altForm = AlternativeFormInfoProvider.GetAlternativeFormInfo(objectName);
                    if (altForm != null)
                    {
                        var mainDci = DataClassInfoProvider.GetDataClassInfo(altForm.FormClassID);
                        var classFormDefinition = mainDci.ClassFormDefinition;

                        if (altForm.FormCoupledClassID > 0)
                        {
                            // If coupled class is defined combine form definitions
                            var coupledDci = DataClassInfoProvider.GetDataClassInfo(altForm.FormCoupledClassID);
                            if (coupledDci != null)
                            {
                                classFormDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, coupledDci.ClassFormDefinition);
                            }
                        }

                        var oldVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, altForm.FormDefinition);
                        var newVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, newDefinition);

                        var newVersionFi = new FormInfo(newVersionDefinition);
                        var oldVersionFi = new FormInfo(oldVersionDefinition);

                        CopyCustomFields(oldVersionFi, newVersionFi, true);

                        // Save the modified form definition
                        altForm.FormDefinition = FormHelper.GetFormDefinitionDifference(classFormDefinition, newVersionFi.GetXmlDefinition(), true);
                        altForm.Update();
                    }
                }
            }
        }
    }
    /// <summary>
    /// Updates DataClassInfo and modifies database accordingly.
    /// </summary>
    /// <param name="dci">DataClassInfo</param>
    /// <param name="fi">Form info</param>
    private void UpdateDataClass(DataClassInfo dci, FormInfo fi)
    {
        // Update definition
        dci.ClassFormDefinition = fi.GetXmlDefinition();

        // Update database structure
        DataClassInfoProvider.EnsureDatabaseStructure(dci, true);

        DataClassInfoProvider.SetDataClassInfo(dci);
    }
    /// <summary>
    /// Updates an existing alternative forms form definitions. Appends existing custom fields to new version definitions.
    /// </summary>
    private static void UpdateAlternativeForms()
    {
        DataSet classes = GetFormDefinitions(true);

        if (!DataHelper.DataSourceIsEmpty(classes))
        {
            foreach (DataRow row in classes.Tables[0].Rows)
            {
                string objectName    = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
                string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

                if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(newDefinition))
                {
                    var altForm = AlternativeFormInfoProvider.GetAlternativeFormInfo(objectName);
                    if (altForm != null)
                    {
                        var mainDci             = DataClassInfoProvider.GetDataClassInfo(altForm.FormClassID);
                        var classFormDefinition = mainDci.ClassFormDefinition;

                        if (altForm.FormCoupledClassID > 0)
                        {
                            // If coupled class is defined combine form definitions
                            var coupledDci = DataClassInfoProvider.GetDataClassInfo(altForm.FormCoupledClassID);
                            if (coupledDci != null)
                            {
                                classFormDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, coupledDci.ClassFormDefinition);
                            }
                        }

                        var oldVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, altForm.FormDefinition);
                        var newVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, newDefinition);

                        var newVersionFi = new FormInfo(newVersionDefinition);
                        var oldVersionFi = new FormInfo(oldVersionDefinition);

                        CopyCustomFields(oldVersionFi, newVersionFi, true);

                        // Save the modified form definition
                        altForm.FormDefinition = FormHelper.GetFormDefinitionDifference(classFormDefinition, newVersionFi.GetXmlDefinition(), true);
                        altForm.Update();
                    }
                }
            }
        }
    }
    /// <summary>
    /// Initializes the form.
    /// </summary>
    /// <param name="form">Form</param>
    /// <param name="dr">Data row with the data</param>
    /// <param name="fi">Form info</param>
    private void InitForm(BasicForm form, DataRow dr, FormInfo fi)
    {
        if (form != null)
        {
            form.DataRow = dr;
            if (webPartInstance != null)
            {
                form.MacroTable = webPartInstance.MacroTable;
            }
            else
            {
                form.MacroTable = new Hashtable();
            }

            if (!RequestHelper.IsPostBack() && (webPartInstance != null))
            {
                fi = new FormInfo(fi.GetXmlDefinition());

                // Load the collapsed/un-collapsed state of categories
                var categories = fi.GetCategoryNames();
                foreach (string category in categories)
                {
                    FormCategoryInfo fci = fi.GetFormCategory(category);
                    if (fci.CategoryCollapsible && fci.CategoryCollapsedByDefault && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false))
                    {
                        fci.CategoryCollapsedByDefault = false;
                    }
                }
            }

            form.SubmitButton.Visible = false;
            form.SiteName = CMSContext.CurrentSiteName;
            form.FormInformation = fi;
            form.ShowPrivateFields = true;
            form.OnItemValidation += formElem_OnItemValidation;
            form.ReloadData();
        }
    }
예제 #20
0
    /// <summary>
    /// Updates an existing alternative forms form definitions. Appends existing custom fields to new version definitions.
    /// </summary>
    private static void UpdateAlternativeForms()
    {
        var path  = Path.Combine(mWebsitePath, "App_Data\\CMSTemp\\Upgrade\\AlternativeForms");
        var forms = GetAllFiles(path);

        foreach (var formPath in forms)
        {
            var form    = Path.GetFileNameWithoutExtension(formPath);
            var altForm = AlternativeFormInfoProvider.GetAlternativeFormInfo(form);
            if (altForm != null)
            {
                var mainDci             = DataClassInfoProvider.GetDataClassInfo(altForm.FormClassID);
                var classFormDefinition = mainDci.ClassFormDefinition;

                if (altForm.FormCoupledClassID > 0)
                {
                    // If coupled class is defined combine form definitions
                    var coupledDci = DataClassInfoProvider.GetDataClassInfo(altForm.FormCoupledClassID);
                    if (coupledDci != null)
                    {
                        classFormDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, coupledDci.ClassFormDefinition);
                    }
                }

                // Make sure that the false flag for extra fields is not used in future upgrades (8.0 further) since extra custom fields could be added to alternative forms since v8
                var oldVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, altForm.FormDefinition, false);
                var newVersionDefinition = FormHelper.MergeFormDefinitions(classFormDefinition, File.ReadAllText(formPath));

                var newVersionFi = new FormInfo(newVersionDefinition);
                var oldVersionFi = new FormInfo(oldVersionDefinition);

                CopyCustomFields(oldVersionFi, newVersionFi);

                // Save the modified form definition
                altForm.FormDefinition = FormHelper.GetFormDefinitionDifference(classFormDefinition, newVersionFi.GetXmlDefinition(), true);
                altForm.Update();
            }
        }
    }
    public static void Update60()
    {
        EventLogProvider evp = new EventLogProvider();
        evp.LogEvent("I", DateTime.Now, "Upgrade to 6.0", "Upgrade - Start");

        DataClassInfo dci = null;

        #region "CMS.UserSettings"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.usersettings");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "UserAuthenticationGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserBounces";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "UserBounces";

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserLinkedInID";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserLogActivities";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserPasswordRequestHash";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("CMS_UserSettings");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("CMS_UserSettings");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.UserSettings - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Customer"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.customer");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "CustomerSiteID";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    TableManager tm = new TableManager(dci.ClassConnectionString);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_Customer");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);

                    tm.RefreshCustomViews("COM_Customer");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Customer - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Order"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.order");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "OrderCulture";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 10;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderIsPaid";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderTotalPriceInMainCurrency";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("OrderStatusID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderStatusID", ffi);
                    }

                    ffi = fi.GetFormField("OrderShippingAddressID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderShippingAddressID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_Order");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_Order");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Order - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - OrderItem"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.orderitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemBundleGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemIsPrivate";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemSendNotification";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemSKU";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemText";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemTotalPriceInMainCurrency";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemValidTo";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_OrderItem");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_OrderItem");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.OrderItem - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Shopping cart item"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.shoppingcartitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "CartItemBundleGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemIsPrivate";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemText";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemValidTo";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("CartItemGuid");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("CartItemGuid", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_ShoppingCartSKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_ShoppingCartSKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.ShoppingCartItem - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - SKU"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.sku");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "SKUBundleInventoryType";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUConversionName";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUConversionValue";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 200;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxDownloads";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxItemsInOrder";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMembershipGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMinPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUNeedsShipping";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUPrivateDonation";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUProductType";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUSiteID";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidFor";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidity";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidUntil";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("SKUDepartmentID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("SKUDepartmentID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_SKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_SKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.SKU - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Community - Group"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("Community.Group");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "GroupLogActivity";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.CheckBoxControl;
                    ffi.Visible = true;
                    ffi.DefaultValue = "true";
                    ffi.Caption = "GroupLogActivity";

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Community_Group");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Community_Group");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Community.Group - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Newsletter - Subscriber"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("newsletter.subscriber");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "SubscriberBounces";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Newsletter_Subscriber");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Newsletter_Subscriber");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Newsletter.Subscriber - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "CMS.Document"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.document");
            if (dci != null)
            {
                SearchSettings ss = dci.ClassSearchSettingsInfos;
                SearchSettingsInfo ssi = ss.GetSettingsInfo("42f446ee-9818-4596-8124-54a38f64aa05");
                if (ssi != null)
                {
                    ssi.Searchable = true;
                    ss.SetSettingsInfo(ssi);
                }

                DataClassInfoProvider.SetDataClass(dci);
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.Document - Upgrade", "Upgrade", ex);
        }

        #endregion

        // Set the path to the upgrade package
        mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/upgrade_55R2_60.zip");

        mWebsitePath = HttpContext.Current.Server.MapPath("~/");

        TableManager dtm = new TableManager(null);

        // Update all views
        dtm.RefreshDocumentViews();

        // Set data version
        ObjectHelper.SetSettingsKeyValue("CMSDataVersion", "6.0");

        // Clear hashtables
        CMSObjectHelper.ClearHashtables();

        // Clear the cache
        CacheHelper.ClearCache(null, true);

        // Drop the routes
        CMSMvcHandler.DropAllRoutes();

        // Init the Mimetype helper (required for the Import)
        MimeTypeHelper.LoadMimeTypes();

        CMSThread thread = new CMSThread(Upgrade60Import);
        thread.Start();
    }
    /// <summary>
    /// Initializes the custom table
    /// </summary>
    /// <param name="dci">DataClassInfo of the custom table</param>
    /// <param name="fi">Form info</param>
    /// <param name="tm">Table manager</param>
    private void InitCustomTable(DataClassInfo dci, FormInfo fi, TableManager tm)
    {
        // Created by
        if (chkItemCreatedBy.Checked && !fi.FieldExists("ItemCreatedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Created when
        if (chkItemCreatedWhen.Checked && !fi.FieldExists("ItemCreatedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemCreatedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Created when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified by
        if (chkItemModifiedBy.Checked && !fi.FieldExists("ItemModifiedBy"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedBy";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified by");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Modified when
        if (chkItemModifiedWhen.Checked && !fi.FieldExists("ItemModifiedWhen"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemModifiedWhen";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Modified when");
            ffi.DataType = FieldDataType.DateTime;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // Item order
        if (chkItemOrder.Checked && !fi.FieldExists("ItemOrder"))
        {
            FormFieldInfo ffi = new FormFieldInfo();

            // Fill FormInfo object
            ffi.Name = "ItemOrder";
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "Order");
            ffi.DataType = FieldDataType.Integer;
            ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, string.Empty);
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, string.Empty);
            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLowerCSafe();
            ffi.PrimaryKey = false;
            ffi.System = true;
            ffi.Visible = false;
            ffi.Size = 0;
            ffi.AllowEmpty = true;

            fi.AddFormItem(ffi);
        }

        // GUID
        if (chkItemGUID.Checked && !fi.FieldExists("ItemGUID"))
        {
            var ffiGuid = CreateGuidField();

            fi.AddFormItem(ffiGuid);
        }

        // Update table structure - columns could be added
        bool old = TableManager.UpdateSystemFields;

        TableManager.UpdateSystemFields = true;

        string schema = fi.GetXmlDefinition();
        tm.UpdateTableByDefinition(dci.ClassTableName, schema);

        TableManager.UpdateSystemFields = old;

        // Update xml schema and form definition
        dci.ClassFormDefinition = schema;
        dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);

        using (CMSActionContext context = new CMSActionContext())
        {
            // Disable logging into event log
            context.LogEvents = false;

            DataClassInfoProvider.SetDataClassInfo(dci);
        }
    }
예제 #23
0
    /// <summary>
    /// Update form definitions of classes (especially system tables).
    /// </summary>
    private static void UpdateClasses()
    {
        DataSet classes = GetFormDefinitions();

        if (DataHelper.DataSourceIsEmpty(classes))
        {
            return;
        }

        foreach (DataRow row in classes.Tables[0].Rows)
        {
            string objectName    = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
            string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

            if (string.IsNullOrEmpty(objectName) || string.IsNullOrEmpty(newDefinition))
            {
                continue;
            }

            var dataClass = DataClassInfoProvider.GetDataClassInfo(objectName);
            if (dataClass == null)
            {
                continue;
            }

            try
            {
                var newVersionFi = new FormInfo(newDefinition);
                var oldVersionFi = new FormInfo(dataClass.ClassFormDefinition);

                // Get removed system fields
                var removedfields = GetRemovedSystemFields(oldVersionFi, newVersionFi);
                if (removedfields != null)
                {
                    // Remove the system fields from class's alt.forms
                    foreach (var field in removedfields)
                    {
                        FormHelper.RemoveFieldFromAlternativeForms(dataClass, field, 0);
                    }
                }

                // Copy custom fields only for system tables
                if (dataClass.ClassShowAsSystemTable)
                {
                    CopyCustomFields(oldVersionFi, newVersionFi, false);
                }

                // Save the modified form definition
                dataClass.ClassFormDefinition = newVersionFi.GetXmlDefinition();

                // Save the new definition
                dataClass.Update();
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Updating data class '" + dataClass.ClassName + "' failed.", e);
            }
        }

        // The components may have been upgraded later than the composite class
        CleanCompositeClassesSearchSettings();
    }
    /// <summary>
    /// Update form definitions of classes (especially system tables).
    /// </summary>
    private static void UpdateClasses()
    {
        DataSet classes = GetFormDefinitions();
        if (!DataHelper.DataSourceIsEmpty(classes))
        {
            foreach (DataRow row in classes.Tables[0].Rows)
            {
                string objectName = DataHelper.GetStringValue(row, FORM_DEFINITION_NAME_COLUMN);
                string newDefinition = DataHelper.GetStringValue(row, FORM_DEFINITION_VALUE_COLUMN);

                if (!string.IsNullOrEmpty(objectName) && !string.IsNullOrEmpty(newDefinition))
                {
                    var dataClass = DataClassInfoProvider.GetDataClassInfo(objectName);
                    if (dataClass != null)
                    {
                        var newVersionFi = new FormInfo(newDefinition);
                        var oldVersionFi = new FormInfo(dataClass.ClassFormDefinition);

                        // Get removed system fields
                        var removedfields = GetRemovedSystemFields(oldVersionFi, newVersionFi);
                        if (removedfields != null)
                        {
                            // Remove the system fields from class's alt.forms
                            foreach (var field in removedfields)
                            {
                                FormHelper.RemoveFieldFromAlternativeForms(dataClass, field, 0);
                            }
                        }

                        // Copy custom fields only for system tables
                        if (dataClass.ClassShowAsSystemTable)
                        {
                            CopyCustomFields(oldVersionFi, newVersionFi, false, true);
                        }

                        // Save the modified form definition
                        dataClass.ClassFormDefinition = newVersionFi.GetXmlDefinition();

                        // Update the scheme
                        dataClass.ClassXmlSchema = new TableManager(dataClass.ClassConnectionString).GetXmlSchema(dataClass.ClassTableName);

                        // Update search settings
                        dataClass.ClassSearchSettings = SearchHelper.CleanSearchSettings(dataClass);

                        // Save the new definition
                        dataClass.Update();
                    }
                }
            }
        }
    }
예제 #25
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        MacroRuleInfo info = EditForm.EditedObject as MacroRuleInfo;
        if (info != null)
        {
            // Generate automatic fields when present in UserText
            FormEngineUserControl control = EditForm.FieldControls["MacroRuleText"];
            if (control != null)
            {
                string userText = ValidationHelper.GetString(control.Value, "");
                if (!string.IsNullOrEmpty(userText))
                {
                    Regex regex = RegexHelper.GetRegex("\\{[-_a-zA-Z0-9]*\\}");
                    MatchCollection match = regex.Matches(userText);
                    if (match.Count > 0)
                    {
                        FormInfo fi = new FormInfo(info.MacroRuleParameters);
                        foreach (Match m in match)
                        {
                            foreach (Capture c in m.Captures)
                            {
                                string name = c.Value.Substring(1, c.Value.Length - 2).ToLowerCSafe();
                                FormFieldInfo ffi = fi.GetFormField(name);
                                if (ffi == null)
                                {
                                    ffi = new FormFieldInfo();
                                    ffi.Name = name;
                                    ffi.DataType = FormFieldDataTypeEnum.Text;
                                    ffi.Size = 100;
                                    ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                    ffi.Caption = "select operation";
                                    ffi.AllowEmpty = true;
                                    switch (name)
                                    {
                                        case "_is":
                                            ffi.DefaultValue = ";is";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";is\r\n!;is not";
                                            break;

                                        case "_was":
                                            ffi.DefaultValue = ";was";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";was\r\n!;was not";
                                            break;

                                        case "_will":
                                            ffi.DefaultValue = ";will";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";will\r\n!;will not";
                                            break;

                                        case "_has":
                                            ffi.DefaultValue = ";has";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";has\r\n!;does not have";
                                            break;

                                        case "_perfectum":
                                            ffi.DefaultValue = ";has";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";has\r\n!;has not";
                                            break;

                                        case "_any":
                                            ffi.DefaultValue = "false;any";
                                            ffi.Settings["controlname"] = "macro_any-all_bool_selector";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = "false;any\r\ntrue;all";
                                            break;

                                        default:
                                            ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                                            ffi.Size = 1000;
                                            ffi.Caption = "enter text";
                                            break;
                                    }

                                    fi.AddFormField(ffi);
                                }
                            }
                        }
                        info.MacroRuleParameters = fi.GetXmlDefinition();
                    }
                }
            }
        }

        if (!string.IsNullOrEmpty(ResourceName))
        {
            EditForm.EditedObject.SetValue("MacroRuleResourceName", ResourceName);
        }
        EditForm.EditedObject.SetValue("MacroRuleIsCustom", !SettingsKeyProvider.DevelopmentMode);
    }
예제 #26
0
    public static void Upgrade55R2()
    {
        EventLogProvider evp = new EventLogProvider();
        evp.LogEvent("I", DateTime.Now, "Upgrade to 5.5 R2", "Upgrade - Start");

        DataClassInfo dci = null;

        #region "CMS.UserSettings"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.usersettings");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "UserSkype";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "User Skype account";
                    ffi.DefaultValue = String.Empty;
                    ffi.Description = String.Empty;
                    ffi.RegularExpression = String.Empty;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserIM";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "User instant messenger";
                    ffi.DefaultValue = String.Empty;
                    ffi.Description = String.Empty;
                    ffi.RegularExpression = String.Empty;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserPhone";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 26;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "User phone";
                    ffi.DefaultValue = String.Empty;
                    ffi.Description = "User phone number.";
                    ffi.RegularExpression = String.Empty;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserPosition";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 200;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = false;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "Position";
                    ffi.DefaultValue = String.Empty;
                    ffi.Description = String.Empty;
                    ffi.RegularExpression = String.Empty;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();
                    dci.ClassXmlSchema = TableManager.GetXmlSchema("CMS_UserSettings");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                }
            }

        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.UserSettings - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "WebTemplate meta file"

        try
        {
            WebTemplateInfo wti = WebTemplateInfoProvider.GetWebTemplateInfo("IntranetPortal");
            if (wti != null)
            {
                string imgPath = HttpContext.Current.Server.MapPath("~/App_Data/CMSTemp/intranetportal.gif");
                if (File.Exists(imgPath))
                {
                    MetaFileInfo mfi = new MetaFileInfo(imgPath, wti.WebTemplateId, "cms.webtemplate", "Thumbnail");
                    if (mfi != null)
                    {
                        MetaFileInfoProvider.SetMetaFileInfo(mfi);
                    }
                    File.Delete(imgPath);
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Upgrade to 5.5 R2", "Upgrade", ex);
        }

        #endregion

        // Clear hashtables
        CMSObjectHelper.ClearHashtables();

        // Set the path to the upgrade package
        mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/upgrade_55_55R2.zip");

        mWebsitePath = HttpContext.Current.Server.MapPath("~/");

        // Set data version
        ObjectHelper.SetSettingsKeyValue("CMSDataVersion", "5.5R2");

        CMSThread thread = new CMSThread(Upgrade55R2Import);
        thread.Start();
    }
    /// <summary>
    /// Initializes the form.
    /// </summary>
    /// <param name="basicForm">Form</param>
    /// <param name="dr">Data row with the data</param>
    /// <param name="fi">Form info</param>
    private void InitForm(BasicForm basicForm, DataRow dr, FormInfo fi)
    {
        if (basicForm != null)
        {
            basicForm.DataRow = dr;
            if (webPartInstance != null)
            {
                basicForm.MacroTable = webPartInstance.MacroTable;
            }
            else
            {
                basicForm.MacroTable = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
            }

            if (!RequestHelper.IsPostBack() && (webPartInstance != null))
            {
                fi = new FormInfo(fi.GetXmlDefinition());

                // Load the collapsed/un-collapsed state of categories
                var categories = fi.GetCategoryNames();
                foreach (string category in categories)
                {
                    FormCategoryInfo fci = fi.GetFormCategory(category);
                    if (ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.Collapsible, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(fci.GetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, basicForm.ContextResolver), false) && ValidationHelper.GetBoolean(webPartInstance.GetValue("cat_open_" + category), false))
                    {
                        fci.SetPropertyValue(FormCategoryPropertyEnum.CollapsedByDefault, "false");
                    }
                }
            }

            basicForm.SubmitButton.Visible = false;
            basicForm.SiteName = SiteContext.CurrentSiteName;
            basicForm.FormInformation = fi;
            basicForm.ShowPrivateFields = true;
            basicForm.OnItemValidation += formElem_OnItemValidation;
            basicForm.ReloadData();
        }
    }
예제 #28
0
    /// <summary>
    /// 'Next' button is clicked.
    /// </summary>
    protected void wzdNewDocType_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        DataClassInfo dci = null;
        FormInfo fi = null;

        switch (e.CurrentStepIndex)
        {
            // Step 1
            case 0:
                {
                    // Actions after next button click

                    // Validate checkboxes first
                    string errorMessage = "";

                    // Display proper error message based on development mode wizzard setting
                    switch (this.Mode)
                    {
                        case NewClassWizardModeEnum.DocumentType:
                            errorMessage = new Validator().NotEmpty(txtDisplayName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyDisplayName")).
                            NotEmpty(txtCodeName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyCodeName")).
                            NotEmpty(txtNamespaceName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyNamespaceName")).
                            IsCodeName(txtCodeName.Text.Trim(), GetString("DocumentType_New.CodeNameIdentificator")).
                            IsIdentificator(txtNamespaceName.Text.Trim(), GetString("DocumentType_New.NamespaceNameIdentificator")).Result;
                            break;

                        case NewClassWizardModeEnum.Class:
                            errorMessage = new Validator().NotEmpty(txtDisplayName.Text.Trim(), GetString("sysdev.class_new.ErrorEmptyDisplayName")).
                            NotEmpty(txtCodeName.Text.Trim(), GetString("sysdev.class_new.ErrorEmptyCodeName")).
                            NotEmpty(txtNamespaceName.Text.Trim(), GetString("sysdev.class_new.ErrorEmptyNamespaceName")).
                            IsCodeName(txtCodeName.Text.Trim(), GetString("sysdev.class_new.CodeNameIdentificator")).
                            IsIdentificator(txtNamespaceName.Text.Trim(), GetString("sysdev.class_new.NamespaceNameIdentificator")).Result;
                            break;

                        case NewClassWizardModeEnum.CustomTable:
                            errorMessage = new Validator().NotEmpty(txtDisplayName.Text.Trim(), GetString("customtable.newwizzard.ErrorEmptyDisplayName")).
                            NotEmpty(txtCodeName.Text.Trim(), GetString("customtable.newwizzard.ErrorEmptyCodeName")).
                            NotEmpty(txtNamespaceName.Text.Trim(), GetString("customtable.newwizzard.ErrorEmptyNamespaceName")).
                            IsCodeName(txtCodeName.Text.Trim(), GetString("customtable.newwizzard.CodeNameIdentificator")).
                            IsIdentificator(txtNamespaceName.Text.Trim(), GetString("customtable.newwizzard.NamespaceNameIdentificator")).Result;
                            break;
                    }

                    if (errorMessage == "")
                    {
                        // Set new class info
                        dci = new DataClassInfo();
                        dci.ClassDisplayName = txtDisplayName.Text.Trim();
                        dci.ClassName = txtNamespaceName.Text.Trim() + "." + txtCodeName.Text.Trim();

                        // Set class type according development mode setting
                        switch (this.Mode)
                        {
                            case NewClassWizardModeEnum.DocumentType:
                                dci.ClassIsDocumentType = true;
                                dci.ClassUsePublishFromTo = true;
                                break;

                            case NewClassWizardModeEnum.Class:
                                dci.ClassShowAsSystemTable = false;
                                dci.ClassShowTemplateSelection = false;
                                dci.ClassIsDocumentType = false;
                                dci.ClassCreateSKU = false;
                                dci.ClassIsProduct = false;
                                dci.ClassIsMenuItemType = false;
                                dci.ClassUsesVersioning = false;
                                dci.ClassUsePublishFromTo = false;
                                break;

                            case NewClassWizardModeEnum.CustomTable:
                                dci.ClassShowAsSystemTable = false;
                                dci.ClassShowTemplateSelection = false;
                                dci.ClassIsDocumentType = false;
                                dci.ClassCreateSKU = false;
                                dci.ClassIsProduct = false;
                                dci.ClassIsMenuItemType = false;
                                dci.ClassUsesVersioning = false;
                                dci.ClassUsePublishFromTo = false;
                                // Sets custom table
                                dci.ClassIsCustomTable = true;
                                break;
                        }

                        try
                        {
                            // Insert new class into DB
                            DataClassInfoProvider.SetDataClass(dci);

                            // Set permissions and queries
                            switch (this.Mode)
                            {
                                case NewClassWizardModeEnum.DocumentType:
                                    // Ensure default permissions
                                    PermissionNameInfoProvider.CreateDefaultClassPermissions(dci.ClassID);

                                    // Generate special document queries, for possible premature exit from wizzard
                                    SqlGenerator.GenerateQuery(dci.ClassName, SqlGenerator.QUERYNAME_SEARCHTREE, SqlOperationTypeEnum.SearchTree, false, false);
                                    SqlGenerator.GenerateQuery(dci.ClassName, SqlGenerator.QUERYNAME_SELECTDOCUMENTS, SqlOperationTypeEnum.SelectDocuments, false, false);
                                    SqlGenerator.GenerateQuery(dci.ClassName, SqlGenerator.QUERYNAME_SELECTVERSIONS, SqlOperationTypeEnum.SelectVersions, false, false);
                                    break;

                                case NewClassWizardModeEnum.Class:
                                    break;

                                case NewClassWizardModeEnum.CustomTable:
                                    // Ensure default custom table permissions
                                    PermissionNameInfoProvider.CreateDefaultCustomTablePermissions(dci.ClassID);
                                    break;
                            }
                        }
                        catch (Exception ex)
                        {
                            // No movement to the next step
                            e.Cancel = true;

                            // Class with the same class name already exists
                            lblErrorStep1.Visible = true;
                            lblErrorStep1.Text = ex.Message;
                        }

                        // Prepare next step (2)
                        if (lblErrorStep1.Text == "")
                        {
                            // Disable previous steps' viewstates
                            DisablePreviousStepsViewStates(e.CurrentStepIndex);

                            // Enable next step's viewstate
                            EnableNextStepViewState(e.CurrentStepIndex);

                            // Save ClassName to viewstate to use in the next steps
                            ClassName = dci.ClassName;

                            // Prefill textboxes in the next step with default values
                            txtTableName.Text = txtNamespaceName.Text.Trim() + "_" + txtCodeName.Text.Trim();
                            txtPKName.Text = FirstLetterToUpper(txtCodeName.Text.Trim() + "ID");

                            wzdStep2.Title = GetString("DocumentType_New_Step2.Title");

                            // Prepare next step by mode setting
                            switch (this.Mode)
                            {
                                case NewClassWizardModeEnum.DocumentType:
                                    // Initialize other conrols
                                    lblPKName.Text = GetString("DocumentType_New.PrimaryKeyName");
                                    lblTableName.Text = GetString("DocumentType_New.TableName");
                                    radCustom.Text = GetString("DocumentType_New.Custom");

                                    // Display container option based on the development mode setting
                                    radContainer.Text = GetString("DocumentType_New.Container");
                                    radContainer.Visible = true;

                                    ucHeader.Description = GetString("DocumentType_New_Step2.Description");

                                    // Setup the inheritance selector
                                    this.plcDocTypeOptions.Visible = true;
                                    break;

                                case NewClassWizardModeEnum.Class:
                                    // Initialize other conrols
                                    lblPKName.Text = GetString("sysdev.class_new.PrimaryKeyName");
                                    lblTableName.Text = GetString("sysdev.class_new.TableName");
                                    radCustom.Text = GetString("sysdev.class_new.Custom");
                                    lblIsMNTable.Text = GetString("sysdev.class_new.MNTable");

                                    radContainer.Visible = false;
                                    if (this.SystemDevelopmentMode)
                                    {
                                        plcMNClassOptions.Visible = true;
                                    }

                                    ucHeader.Description = GetString("sysdev.class_new_Step2.Description");
                                    break;

                                case NewClassWizardModeEnum.CustomTable:

                                    lblPKName.Text = GetString("customtable.newwizzard.PrimaryKeyName");
                                    lblTableName.Text = GetString("customtable.newwizzard.TableName");

                                    radCustom.Visible = false;
                                    radContainer.Visible = false;

                                    // Custom tables have always ItemID as primary key
                                    txtPKName.Text = "ItemID";
                                    // Primary key name can't be editted
                                    txtPKName.Enabled = false;

                                    // Show custom tables columns options
                                    plcCustomTablesOptions.Visible = true;
                                    lblItemCreatedBy.Text = GetString("customtable.newwizzard.lblItemCreatedBy");
                                    lblItemCreatedWhen.Text = GetString("customtable.newwizzard.lblItemCreatedWhen");
                                    lblItemModifiedBy.Text = GetString("customtable.newwizzard.lblItemModifiedBy");
                                    lblItemModifiedWhen.Text = GetString("customtable.newwizzard.lblItemModifiedWhen");
                                    lblItemOrder.Text = GetString("customtable.newwizzard.lblItemOrder");

                                    ucHeader.Description = GetString("customtable.newwizzard.Step2Description");
                                    break;
                            }
                        }
                    }
                    else
                    {
                        // No movement to the next step
                        e.Cancel = true;

                        // Textboxes are not filled correctly
                        lblErrorStep1.Visible = true;
                        lblErrorStep1.Text = errorMessage;
                    }

                    break;
                }

            // Step 2
            case 1:
                {
                    FormFieldInfo ffiPrimaryKey = null;
                    dci = DataClassInfoProvider.GetDataClass(ClassName);

                    if (dci != null)
                    {
                        var genDci = dci.Generalized;

                        // New document type has custom attributes -> no wizard steps will be omitted
                        if (radCustom.Checked)
                        {
                            // Actions after next button click

                            // Validate checkboxes first
                            string tableNameEmpty = new Validator().NotEmpty(txtTableName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyTableName")).Result;
                            string tableNameNotIdentificator = new Validator().IsIdentificator(txtTableName.Text.Trim(), GetString("class.ErrorIdentificator")).Result;
                            string primaryKeyNameEmpty = new Validator().NotEmpty(txtPKName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyPKName")).Result;
                            bool columnExists = DocumentHelper.ColumnExistsInSystemTable(txtPKName.Text.Trim());
                            string tableNameError = (tableNameEmpty == "") ? tableNameNotIdentificator : tableNameEmpty;

                            // Textboxes are filled correctly
                            if ((tableNameError == "") && (primaryKeyNameEmpty == "") && (!columnExists))
                            {
                                string tableName = txtTableName.Text.Trim();

                                try
                                {
                                    // Create new table in DB
                                    if (this.SystemDevelopmentMode && this.Mode == NewClassWizardModeEnum.Class)
                                    {
                                        TableManager.CreateTable(tableName, txtPKName.Text.Trim(), !chbIsMNTable.Checked);
                                    }
                                    else
                                    {
                                        TableManager.CreateTable(tableName, txtPKName.Text.Trim());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    // No movement to the next step
                                    e.Cancel = true;

                                    // Table with the same name already exists
                                    lblErrorStep2.Visible = true;
                                    lblErrorStep2.Text = ex.Message;
                                }

                                if (lblErrorStep2.Text == "")
                                {
                                    // Change table owner
                                    try
                                    {
                                        string owner = "";

                                        // Get site related DB object owner setting when creating new wizzard and global otherwise
                                        switch (this.Mode)
                                        {
                                            case NewClassWizardModeEnum.DocumentType:
                                            case NewClassWizardModeEnum.Class:
                                            case NewClassWizardModeEnum.CustomTable:
                                                owner = SqlHelperClass.GetDBSchema(CMSContext.CurrentSiteName);
                                                break;
                                        }

                                        if ((owner != "") && (owner.ToLower() != "dbo"))
                                        {
                                            TableManager.ChangeDBObjectOwner(tableName, owner);
                                            tableName = DataHelper.GetSafeOwner(owner) + "." + tableName;
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    // Create empty form definition
                                    fi = new FormInfo("<form></form>");
                                    ffiPrimaryKey = new FormFieldInfo();

                                    // Fill FormInfo object
                                    ffiPrimaryKey.Name = txtPKName.Text;
                                    ffiPrimaryKey.Caption = txtPKName.Text;
                                    ffiPrimaryKey.DataType = FormFieldDataTypeEnum.Integer;
                                    ffiPrimaryKey.DefaultValue = "";
                                    ffiPrimaryKey.Description = "";
                                    ffiPrimaryKey.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                    ffiPrimaryKey.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                    ffiPrimaryKey.PrimaryKey = true;
                                    ffiPrimaryKey.System = false;
                                    ffiPrimaryKey.Visible = true;
                                    ffiPrimaryKey.Size = 0;
                                    ffiPrimaryKey.AllowEmpty = false;

                                    // Add field to form definition
                                    fi.AddFormField(ffiPrimaryKey);

                                    dci.ClassTableName = tableName;
                                    dci.ClassXmlSchema = TableManager.GetXmlSchema(dci.ClassTableName);
                                    dci.ClassFormDefinition = fi.GetXmlDefinition();
                                    dci.ClassIsCoupledClass = true;

                                    dci.ClassInheritsFromClassID = ValidationHelper.GetInteger(selInherits.Value, 0);

                                    // Update class in DB
                                    using (CMSActionContext context = new CMSActionContext())
                                    {
                                        // Disable logging into event log
                                        context.LogEvents = false;

                                        DataClassInfoProvider.SetDataClass(dci);

                                        // Ensure inherited fields
                                        if (dci.ClassInheritsFromClassID > 0)
                                        {
                                            DataClassInfo parentCi = DataClassInfoProvider.GetDataClass(dci.ClassInheritsFromClassID);
                                            if (parentCi != null)
                                            {
                                                FormHelper.UpdateInheritedClass(parentCi, dci);
                                            }
                                        }
                                    }

                                    if (this.Mode == NewClassWizardModeEnum.CustomTable)
                                    {
                                        #region "Custom tables optional columns"

                                        if (chkItemCreatedBy.Checked)
                                        {
                                            FormFieldInfo ffi = new FormFieldInfo();

                                            // Fill FormInfo object
                                            ffi.Name = "ItemCreatedBy";
                                            ffi.Caption = "Created by";
                                            ffi.DataType = FormFieldDataTypeEnum.Integer;
                                            ffi.DefaultValue = "";
                                            ffi.Description = "";
                                            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                            ffi.PrimaryKey = false;
                                            ffi.System = true;
                                            ffi.Visible = false;
                                            ffi.Size = 0;
                                            ffi.AllowEmpty = true;

                                            fi.AddFormField(ffi);
                                        }
                                        if (chkItemCreatedWhen.Checked)
                                        {
                                            FormFieldInfo ffi = new FormFieldInfo();

                                            // Fill FormInfo object
                                            ffi.Name = "ItemCreatedWhen";
                                            ffi.Caption = "Created when";
                                            ffi.DataType = FormFieldDataTypeEnum.DateTime;
                                            ffi.DefaultValue = "";
                                            ffi.Description = "";
                                            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                            ffi.PrimaryKey = false;
                                            ffi.System = true;
                                            ffi.Visible = false;
                                            ffi.Size = 0;
                                            ffi.AllowEmpty = true;

                                            fi.AddFormField(ffi);
                                        }
                                        if (chkItemModifiedBy.Checked)
                                        {
                                            FormFieldInfo ffi = new FormFieldInfo();

                                            // Fill FormInfo object
                                            ffi.Name = "ItemModifiedBy";
                                            ffi.Caption = "Modified by";
                                            ffi.DataType = FormFieldDataTypeEnum.Integer;
                                            ffi.DefaultValue = "";
                                            ffi.Description = "";
                                            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                            ffi.PrimaryKey = false;
                                            ffi.System = true;
                                            ffi.Visible = false;
                                            ffi.Size = 0;
                                            ffi.AllowEmpty = true;

                                            fi.AddFormField(ffi);
                                        }
                                        if (chkItemModifiedWhen.Checked)
                                        {
                                            FormFieldInfo ffi = new FormFieldInfo();

                                            // Fill FormInfo object
                                            ffi.Name = "ItemModifiedWhen";
                                            ffi.Caption = "Modified when";
                                            ffi.DataType = FormFieldDataTypeEnum.DateTime;
                                            ffi.DefaultValue = "";
                                            ffi.Description = "";
                                            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                            ffi.PrimaryKey = false;
                                            ffi.System = true;
                                            ffi.Visible = false;
                                            ffi.Size = 0;
                                            ffi.AllowEmpty = true;

                                            fi.AddFormField(ffi);
                                        }
                                        if (chkItemOrder.Checked)
                                        {
                                            FormFieldInfo ffi = new FormFieldInfo();

                                            // Fill FormInfo object
                                            ffi.Name = "ItemOrder";
                                            ffi.Caption = "Order";
                                            ffi.DataType = FormFieldDataTypeEnum.Integer;
                                            ffi.DefaultValue = "";
                                            ffi.Description = "";
                                            ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                            ffi.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                            ffi.PrimaryKey = false;
                                            ffi.System = true;
                                            ffi.Visible = false;
                                            ffi.Size = 0;
                                            ffi.AllowEmpty = true;

                                            fi.AddFormField(ffi);
                                        }

                                        #endregion

                                        FormFieldInfo ffiGuid = new FormFieldInfo();

                                        // Fill FormInfo object
                                        ffiGuid.Name = "ItemGUID";
                                        ffiGuid.Caption = "GUID";
                                        ffiGuid.DataType = FormFieldDataTypeEnum.GUID;
                                        ffiGuid.DefaultValue = "";
                                        ffiGuid.Description = "";
                                        ffiGuid.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                        ffiGuid.Settings["controlname"] = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                                        ffiGuid.PrimaryKey = false;
                                        ffiGuid.System = true;
                                        ffiGuid.Visible = false;
                                        ffiGuid.Size = 0;
                                        ffiGuid.AllowEmpty = false;

                                        fi.AddFormField(ffiGuid);

                                        // Update table structure - columns could be added
                                        bool old = TableManager.UpdateSystemFields;
                                        TableManager.UpdateSystemFields = true;
                                        string schema = fi.GetXmlDefinition();
                                        TableManager.UpdateTableBySchema(tableName, schema);
                                        TableManager.UpdateSystemFields = old;

                                        // Update xml schema and form definition
                                        dci.ClassFormDefinition = schema;
                                        dci.ClassXmlSchema = TableManager.GetXmlSchema(dci.ClassTableName);

                                        using (CMSActionContext context = new CMSActionContext())
                                        {
                                            // Disable logging into event log
                                            context.LogEvents = false;

                                            DataClassInfoProvider.SetDataClass(dci);
                                        }
                                    }

                                    // Remember that no steps were omitted
                                    SomeStepsOmitted = false;

                                    // Prepare next step (3)

                                    // Disable previous steps' viewstates
                                    DisablePreviousStepsViewStates(e.CurrentStepIndex);

                                    // Enable next step's viewstate
                                    EnableNextStepViewState(e.CurrentStepIndex);

                                    // Set field editor class name
                                    FieldEditor.ClassName = ClassName;

                                    // Fill field editor in the next step
                                    FieldEditor.Reload(null);

                                    wzdStep3.Title = GetString("general.fields");

                                    // Set new step header based on the development mode setting
                                    switch (this.Mode)
                                    {
                                        case NewClassWizardModeEnum.DocumentType:
                                            ucHeader.Description = GetString("DocumentType_New_Step3.Description");
                                            break;

                                        case NewClassWizardModeEnum.Class:
                                            ucHeader.Description = GetString("sysdev.class_new_Step3.Description");
                                            break;

                                        case NewClassWizardModeEnum.CustomTable:
                                            ucHeader.Description = GetString("customtable.newwizzard.Step3Description");
                                            break;
                                    }
                                }
                            }
                            // Some textboxes are not filled correctly
                            else
                            {
                                // Prepare current step (2)

                                // No movement to the next step
                                e.Cancel = true;

                                // Show errors
                                lblTableNameError.Text = tableNameError;
                                lblPKNameError.Text = primaryKeyNameEmpty;
                                if (columnExists)
                                {
                                    lblErrorStep2.Text = GetString("DocumentType_New_Step2.ErrorColumnExists");
                                    lblErrorStep2.Visible = true;
                                }

                                wzdStep2.Title = GetString("DocumentType_New_Step2.Title");

                                // Reset the header
                                switch (this.Mode)
                                {
                                    case NewClassWizardModeEnum.DocumentType:
                                        ucHeader.Description = GetString("DocumentType_New_Step2.Description");
                                        break;

                                    case NewClassWizardModeEnum.Class:
                                        ucHeader.Description = GetString("sysdev.class_new_Step2.Description");
                                        break;

                                    case NewClassWizardModeEnum.CustomTable:
                                        ucHeader.Description = GetString("customtable.newwizzard.Step2Description");
                                        break;
                                }

                            }
                        }
                        // New document type is only the container -> some wizard steps will be omitted
                        else
                        {
                            // Actions after next button click

                            dci.ClassIsCoupledClass = false;

                            // Update class in DB
                            using (CMSActionContext context = new CMSActionContext())
                            {
                                // Disable logging into event log
                                context.LogEvents = false;

                                DataClassInfoProvider.SetDataClass(dci);
                            }

                            // Remember that some steps were omitted
                            SomeStepsOmitted = true;
                            IsContainer = true;

                            // Prepare next step (5) - skip steps 3 and 4

                            // Disable previous steps' viewstates
                            DisablePreviousStepsViewStates(3);

                            // Enable next step's viewstate
                            EnableNextStepViewState(3);

                            PrepareStep5();
                            // Go to the step 5 (indexed from 0)
                            wzdNewDocType.ActiveStepIndex = 4;
                        }

                        // Create new icon if the wizzard is used to create new document type
                        if (this.Mode == NewClassWizardModeEnum.DocumentType)
                        {
                            string sourceFile = "";
                            string destFile = GetDocumentTypeIconUrl(ClassName, false);
                            string sourceLargeFile = "";
                            string destLargeFile = GetDocumentTypeIconUrl(ClassName, "48x48", false);

                            // If class is not coupled class
                            if (SomeStepsOmitted)
                            {
                                sourceFile = GetDocumentTypeIconUrl("defaultcontainer", true);
                                sourceLargeFile = GetDocumentTypeIconUrl("defaultcontainer", "48x48", true);
                            }
                            else
                            {
                                sourceFile = GetDocumentTypeIconUrl("default", true);
                                sourceLargeFile = GetDocumentTypeIconUrl("default", "48x48", true);
                            }

                            if (SettingsKeyProvider.DevelopmentMode)
                            {
                                // Ensure '.gif' image for large icon in development mode
                                sourceLargeFile = sourceLargeFile.Replace(".png", ".gif");
                            }

                            // Ensure same extension
                            if (sourceFile.ToLower().EndsWith(".gif"))
                            {
                                destFile = destFile.Replace(".png", ".gif");
                            }
                            // Ensure same extension
                            if (sourceLargeFile.ToLower().EndsWith(".gif"))
                            {
                                destLargeFile = destLargeFile.Replace(".png", ".gif");
                            }

                            if (!FileHelper.FileExists(destFile))
                            {
                                try
                                {
                                    // Create new document type icon via copying default icon
                                    File.Copy(Server.MapPath(sourceFile), Server.MapPath(destFile), false);
                                }
                                catch
                                {
                                    lblErrorStep3.Visible = true;
                                    lblErrorStep3.Text = string.Format(GetString("DocumentType_New_Step2.ErrorCopyIcon"), sourceFile, destFile);
                                }
                            }

                            // Copy large file icon
                            if (!File.Exists(Server.MapPath(destLargeFile)))
                            {
                                try
                                {
                                    // Create new document type large icon via copying default icon
                                    File.Copy(Server.MapPath(sourceLargeFile), Server.MapPath(destLargeFile), false);
                                }
                                catch
                                {
                                    lblErrorStep3.Visible = true;
                                    lblErrorStep3.Text = string.Format(GetString("DocumentType_New_Step2.ErrorCopyIcon"), sourceLargeFile, destLargeFile);
                                }
                            }
                        }
                    }
                    break;
                }

            // Step 3
            case 2:
                {
                    // Actions after next button click
                    dci = DataClassInfoProvider.GetDataClass(ClassName);

                    var genDci = dci.Generalized;

                    FormFieldInfo[] ffiVisibleFields = null;

                    // Ensure actual form info
                    FormHelper.ClearFormInfos(true);

                    // Get and load form definition
                    fi = FormHelper.GetFormInfo(dci.ClassName, false);

                    // Get all visible fields
                    ffiVisibleFields = fi.GetFields(true, false);

                    if (fi.GetFields(true, true).Length < 2)
                    {
                        e.Cancel = true;
                        lblErrorStep3.Visible = true;
                        lblErrorStep3.Text = GetString("DocumentType_New_Step3.TableMustHaveCustomField");
                    }
                    else
                    {
                        // Generate basic queries
                        SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_SELECT, SqlOperationTypeEnum.SelectQuery, false, false);
                        SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_DELETE, SqlOperationTypeEnum.DeleteQuery, false, false);
                        SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_INSERT, SqlOperationTypeEnum.InsertQuery, true, false);
                        SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_UPDATE, SqlOperationTypeEnum.UpdateQuery, false, false);
                        SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_SELECTALL, SqlOperationTypeEnum.SelectAll, false, false);

                        // Different behaviour by mode
                        switch (this.Mode)
                        {
                            case NewClassWizardModeEnum.DocumentType:
                                {
                                    // Create new view if doesn't exist
                                    string viewName = DataHelper.GetViewName(dci.ClassTableName, null);

                                    // Create view for document types
                                    if (!TableManager.ViewExists(viewName))
                                    {
                                        TableManager.CreateView(viewName, SqlGenerator.GetSqlQuery(ClassName, SqlOperationTypeEnum.SelectView, null));
                                    }

                                    // Generate additional queries when creating new document type
                                    SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_SEARCHTREE, SqlOperationTypeEnum.SearchTree, false, false);
                                    SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_SELECTDOCUMENTS, SqlOperationTypeEnum.SelectDocuments, false, false);
                                    SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_SELECTVERSIONS, SqlOperationTypeEnum.SelectVersions, false, false);

                                    // If new document type is created prepare next step otherwise skip steps 4, 5 and 6

                                    // Disable previous steps' viewstates
                                    DisablePreviousStepsViewStates(e.CurrentStepIndex);

                                    // Enable next step's viewstate
                                    EnableNextStepViewState(e.CurrentStepIndex);

                                    // Add implicit value to the list
                                    lstFields.Items.Add(new ListItem(GetString("DocumentType_New_Step4.ImplicitDocumentName"), ""));

                                    if (ffiVisibleFields != null)
                                    {
                                        // Add visible fields' names to the list except primary-key field
                                        foreach (FormFieldInfo ffi in ffiVisibleFields)
                                        {
                                            if (!ffi.PrimaryKey)
                                            {
                                                lstFields.Attributes.Add(ffi.Name, ffi.Name);
                                                lstFields.Items.Add(new ListItem(ffi.Name, ffi.Name));
                                            }
                                        }
                                    }

                                    lblSelectField.Text = GetString("DocumentType_New_Step4.DocumentName");
                                    wzdStep4.Title = GetString("DocumentType_New_Step4.Title");
                                    ucHeader.Description = GetString("DocumentType_New_Step4.Description");
                                }
                                break;

                            case NewClassWizardModeEnum.Class:
                                {
                                    // Update class in DB
                                    using (CMSActionContext context = new CMSActionContext())
                                    {
                                        // Disable logging into event log
                                        context.LogEvents = false;

                                        DataClassInfoProvider.SetDataClass(dci);
                                    }

                                    // Remember that some steps were omitted
                                    SomeStepsOmitted = true;

                                    // Prepare next step (7) - skip steps 4, 5 and 6

                                    // Disable previous steps' viewstates
                                    DisablePreviousStepsViewStates(5);

                                    // Enable next step's viewstate
                                    EnableNextStepViewState(5);

                                    PrepareStep8();
                                    // Go to the step 8 (indexed from 0)
                                    wzdNewDocType.ActiveStepIndex = 7;
                                }
                                break;

                            case NewClassWizardModeEnum.CustomTable:
                                {
                                    // Generate additional delete all query
                                    SqlGenerator.GenerateQuery(ClassName, SqlGenerator.QUERYNAME_DELETEALL, SqlOperationTypeEnum.DeleteAll, false, false);

                                    // Update class in DB
                                    using (CMSActionContext context = new CMSActionContext())
                                    {
                                        // Disable logging into event log
                                        context.LogEvents = false;

                                        DataClassInfoProvider.SetDataClass(dci);
                                    }

                                    // Remember that some steps were omitted,
                                    SomeStepsOmitted = true;

                                    // Prepare next step (6) - skip steps 4, 5

                                    // Disable previous steps' viewstates
                                    DisablePreviousStepsViewStates(4);

                                    // Enable next step's viewstate
                                    EnableNextStepViewState(4);

                                    PrepareStep6();
                                    // Go to the step 6 (indexed from 0)
                                    wzdNewDocType.ActiveStepIndex = 5;
                                }
                                break;
                        }
                    }
                    break;
                }
            // Step 4
            case 3:
                {
                    // Actions after next button click
                    dci = DataClassInfoProvider.GetDataClass(ClassName);
                    dci.ClassNodeNameSource = lstFields.SelectedValue;

                    // Update node name source in DB
                    using (CMSActionContext context = new CMSActionContext())
                    {
                        // Disable logging into event log
                        context.LogEvents = false;

                        DataClassInfoProvider.SetDataClass(dci);
                    }

                    // Prepare next step (5)

                    // Disable previous steps' viewstates
                    DisablePreviousStepsViewStates(e.CurrentStepIndex);

                    // Enable next step's viewstate
                    EnableNextStepViewState(e.CurrentStepIndex);

                    PrepareStep5();

                    break;
                }
            // Step 5
            case 4:
                {
                    // Actions after next button click

                    int parentClassID = 0;
                    int childClassID = DataClassInfoProvider.GetDataClass(ClassName).ClassID;

                    // Add parent classes
                    string selectedClasses = ValidationHelper.GetString(usParentTypes.Value, String.Empty);
                    if (!String.IsNullOrEmpty(selectedClasses))
                    {
                        string[] classes = selectedClasses.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        if (classes != null)
                        {
                            // Add all new items to site
                            foreach (string item in classes)
                            {
                                parentClassID = ValidationHelper.GetInteger(item, 0);
                                AllowedChildClassInfoProvider.AddAllowedChildClass(parentClassID, childClassID);
                            }
                        }
                    }

                    // Prepare next step (6)

                    // Disable previous steps' viewstates
                    DisablePreviousStepsViewStates(e.CurrentStepIndex);

                    // Enable next step's viewstate
                    EnableNextStepViewState(e.CurrentStepIndex);

                    PrepareStep6();

                    break;
                }

            // Step 6
            case 5:
                {
                    // Actions after next button click

                    int siteId = 0;
                    dci = DataClassInfoProvider.GetDataClass(ClassName);
                    int classId = dci.ClassID;
                    bool isCustomTable = dci.ClassIsCustomTable;
                    bool licenseCheck = true;

                    string selectedSite = ValidationHelper.GetString(usSites.Value, String.Empty);
                    if (selectedSite == "0")
                    {
                        selectedSite = "";
                    }
                    string[] sites = selectedSite.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if ((licenseCheck) && (sites != null))
                    {
                        foreach (string site in sites)
                        {
                            siteId = ValidationHelper.GetInteger(site, 0);

                            SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId);
                            if (si != null)
                            {
                                if (isCustomTable)
                                {
                                    if (!CustomTableItemProvider.LicenseVersionCheck(si.DomainName, FeatureEnum.CustomTables, VersionActionEnum.Insert))
                                    {
                                        lblErrorStep6.Visible = true;
                                        lblErrorStep6.Text = GetString("LicenseVersion.CustomTables");
                                        e.Cancel = true;
                                        licenseCheck = false;
                                    }
                                }

                                if (licenseCheck)
                                {
                                    ClassSiteInfoProvider.AddClassToSite(classId, siteId);

                                    // Clear custom tables count
                                    if (isCustomTable)
                                    {
                                        CustomTableItemProvider.ClearCustomLicHash();
                                    }
                                }
                            }
                        }
                    }

                    // If is moving to the new step
                    if (licenseCheck)
                    {
                        // Create default transformations
                        switch (this.Mode)
                        {
                            case NewClassWizardModeEnum.DocumentType:

                                if (!SomeStepsOmitted)
                                {
                                    CreateDefaultTransformations(classId, true);
                                }
                                else
                                {
                                    // Apply on if new document type was created
                                    lblTableCreated.Visible = false;
                                }
                                break;

                            case NewClassWizardModeEnum.CustomTable:
                                CreateDefaultTransformations(classId, false);
                                break;
                        }
                    }
                    else
                    {
                        PrepareStep5();
                        break;
                    }

                    if (((this.Mode == NewClassWizardModeEnum.DocumentType) && (dci.ClassIsCoupledClass)) || (this.Mode == NewClassWizardModeEnum.CustomTable))
                    {
                        PrepareStep7();
                        SearchFields.DisplayOkButton = false;
                        SearchFields.ItemID = dci.ClassID;
                        SearchFields.ReloadSearch(true);
                    }
                    else
                    {
                        DisablePreviousStepsViewStates(6);
                        EnableNextStepViewState(6);
                        PrepareStep8();
                        wzdNewDocType.ActiveStepIndex = 7;

                        // Explicitly log the synchronization with all changes
                        using (CMSActionContext context = new CMSActionContext())
                        {
                            // Disable logging into event log
                            context.LogEvents = false;

                            SynchronizationHelper.LogObjectUpdate(dci);
                        }
                    }

                    break;
                }
            // STEP 7
            case 6:
                {
                    // Prepare next step (7) - Finish step
                    dci = DataClassInfoProvider.GetDataClass(ClassName);
                    SearchFields.SaveData();

                    // Disable previous steps' viewstates
                    DisablePreviousStepsViewStates(e.CurrentStepIndex);

                    // Enable next step's viewstate
                    EnableNextStepViewState(e.CurrentStepIndex);

                    PrepareStep8();

                    // Explicitly log the synchronization with all changes
                    using (CMSActionContext context = new CMSActionContext())
                    {
                        // Disable logging into event log
                        context.LogEvents = false;

                        SynchronizationHelper.LogObjectUpdate(dci);
                    }

                    break;
                }
        }
    }
예제 #29
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            // Generate automatic fields when present in UserText
            FormEngineUserControl control = Control.FieldControls["MacroRuleText"];
            if (control != null)
            {
                string userText = ValidationHelper.GetString(control.Value, String.Empty);
                if (!string.IsNullOrEmpty(userText))
                {
                    Regex           regex = RegexHelper.GetRegex("\\{[-_a-zA-Z0-9]*\\}");
                    MatchCollection match = regex.Matches(userText);
                    if (match.Count > 0)
                    {
                        FormInfo fi = new FormInfo(info.MacroRuleParameters);
                        foreach (Match m in match)
                        {
                            foreach (Capture c in m.Captures)
                            {
                                string        name = c.Value.Substring(1, c.Value.Length - 2).ToLowerCSafe();
                                FormFieldInfo ffi  = fi.GetFormField(name);
                                if (ffi == null)
                                {
                                    ffi           = new FormFieldInfo();
                                    ffi.Name      = name;
                                    ffi.DataType  = FieldDataType.Text;
                                    ffi.Size      = 100;
                                    ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                    ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "select operation");
                                    ffi.AllowEmpty = true;
                                    switch (name)
                                    {
                                    case "_is":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";is");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";is\r\n!;is not";
                                        break;

                                    case "_was":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";was");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";was\r\n!;was not";
                                        break;

                                    case "_will":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";will");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";will\r\n!;will not";
                                        break;

                                    case "_has":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";has\r\n!;does not have";
                                        break;

                                    case "_perfectum":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.Settings["controlname"] = "MacroNegationOperator";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = ";has\r\n!;has not";
                                        break;

                                    case "_any":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, "false;any");
                                        ffi.Settings["controlname"] = "macro_any-all_bool_selector";
                                        ffi.Settings["EditText"]    = "false";
                                        ffi.Settings["Options"]     = "false;any\r\ntrue;all";
                                        break;

                                    default:
                                        ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                                        ffi.Size      = 1000;
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "enter text");
                                        break;
                                    }

                                    fi.AddFormItem(ffi);
                                }
                            }
                        }
                        info.MacroRuleParameters = fi.GetXmlDefinition();
                    }
                }
            }
        }

        Control.EditedObject.SetValue("MacroRuleIsCustom", !SystemContext.DevelopmentMode);
    }
예제 #30
0
        private void EnsureCmsUserAzureCustomField()
        {
            var cmsUserDataClass = DataClassInfoProvider.GetDataClassInfo("cms.user");

            if (cmsUserDataClass == null)
            {
                return;
            }

            var formInfo = new FormInfo(cmsUserDataClass.ClassFormDefinition);

            if (formInfo.FieldExists("AzureADUsername"))
            {
                EventLogProvider.LogInformation("AzureADAuthentication", "Skip Create Field", "AzureADUsername");
                return;
            }

            // Create "AzureADUsername" field if it doesn't exist
            EventLogProvider.LogInformation("AzureADAuthentication", "Create Field", "AzureADUsername");

            var azureAdUsernameTextField = new FormFieldInfo
            {
                Name         = "AzureADUsername",
                DataType     = "text",
                Size         = 200,
                Precision    = -1,
                AllowEmpty   = true,
                DefaultValue = string.Empty,
                System       = false,
                FieldType    = FormFieldControlTypeEnum.TextBoxControl,
                Visible      = true,
                Caption      = "Azure AD Username",
                Enabled      = true
            };

            using (var tr = new CMSLateBoundTransaction())
            {
                var tm = new TableManager(cmsUserDataClass.ClassConnectionString);
                tr.BeginTransaction();

                var newFieldHandler = (AbstractAdvancedHandler)null;
                try
                {
                    newFieldHandler =
                        DataDefinitionItemEvents.AddItem.StartEvent(cmsUserDataClass, azureAdUsernameTextField);

                    var sqlType = DataTypeManager.GetSqlType(azureAdUsernameTextField.DataType,
                                                             azureAdUsernameTextField.Size, azureAdUsernameTextField.Precision);
                    tm.AddTableColumn(cmsUserDataClass.ClassTableName, azureAdUsernameTextField.Name, sqlType,
                                      azureAdUsernameTextField.AllowEmpty, azureAdUsernameTextField.DefaultValue);

                    formInfo.AddFormItem(azureAdUsernameTextField);

                    cmsUserDataClass.ClassFormDefinition = formInfo.GetXmlDefinition();
                    cmsUserDataClass.ClassXmlSchema      = tm.GetXmlSchema(cmsUserDataClass.ClassTableName);
                    DataClassInfoProvider.SetDataClassInfo(cmsUserDataClass);
                    FormHelper.UpdateInheritedClasses(cmsUserDataClass);

                    QueryInfoProvider.ClearDefaultQueries(cmsUserDataClass, true, true);
                    newFieldHandler.FinishEvent();

                    tr.Commit();

                    ClearHashtables("cms.user");
                }
                catch (Exception ex)
                {
                    EventLogProvider.LogException("AzureADAuthentication", "Create Field", ex);
                }
                finally
                {
                    newFieldHandler?.Dispose();
                }
            }
        }