/// <summary>
    /// Processes the step 2 of the wizard
    /// </summary>
    private void ProcessStep2(WizardNavigationEventArgs e)
    {
        var dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if (dci != null)
        {
            var tm = new TableManager(null);

            using (var tr = new CMSTransactionScope())
            {
                // New document type has custom attributes -> no wizard steps will be omitted
                if (radCustom.Checked)
                {
                    // Actions after next button click
                    bool fromExisting = (Mode == NewClassWizardModeEnum.CustomTable) && radExistingTable.Checked;

                    string tableName = (fromExisting) ? drpExistingTables.SelectedValue : txtTableName.Text.Trim();

                    // Validate checkboxes first
                    string tableNameError = new Validator()
                        .NotEmpty(tableName, GetString("DocumentType_New.ErrorEmptyTableName"))
                        .IsIdentifier(tableName, GetString("class.ErrorIdentifier"))
                        .Result;

                    string primaryKeyNameEmpty = new Validator().NotEmpty(txtPKName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyPKName")).Result;

                    bool columnExists = DocumentHelper.ColumnExistsInDocumentView(txtPKName.Text.Trim());

                    // Textboxes are filled correctly
                    if ((tableNameError == "") && (primaryKeyNameEmpty == "") && (!columnExists))
                    {
                        try
                        {
                            bool tableExists = tm.TableExists(tableName);
                            if (fromExisting)
                            {
                                // Custom table from existing table - validate the table name
                                if (!tableExists)
                                {
                                    e.Cancel = true;

                                    // Table with the same name already exists
                                    ShowError(GetString("customtable.newwizard.tablenotexists"));
                                }

                                // Check primary key
                                List<string> primaryKeys = tm.GetPrimaryKeyColumns(tableName);
                                if ((primaryKeys == null) || (primaryKeys.Count != 1))
                                {
                                    e.Cancel = true;

                                    ShowError(GetString("customtable.newwizard.musthaveprimarykey"));
                                }
                                else if (!IsIdentityColumn(tableName, primaryKeys.First()))
                                {
                                    e.Cancel = true;
                                    ShowError(GetString("customtable.newwizard.mustbeidentitypk"));
                                }
                            }
                            else if (tableExists)
                            {
                                // Check if given table name already exists in database
                                e.Cancel = true;
                                ShowError(GetString("sysdev.class_edit_gen.tablenameunique"));
                            }
                            else if (Mode == NewClassWizardModeEnum.Class)
                            {
                                // Standard class in development mode
                                tm.CreateTable(tableName, txtPKName.Text.Trim(), !chbIsMNTable.Checked);
                            }
                            else
                            {
                                tm.CreateTable(tableName, txtPKName.Text.Trim());
                            }
                        }
                        catch (Exception ex)
                        {
                            // No movement to the next step
                            e.Cancel = true;

                            // Show error message if something caused unhandled exception
                            ShowError(ex.Message);
                        }

                        if ((pnlMessages2.ErrorLabel.Text == "") && !e.Cancel)
                        {
                            // Change table owner
                            try
                            {
                                string owner = "";

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

                                if ((owner != "") && (owner.ToLowerCSafe() != "dbo"))
                                {
                                    tm.ChangeDBObjectOwner(tableName, owner);
                                    tableName = SqlHelper.GetSafeOwner(owner) + "." + tableName;
                                }
                            }
                            catch
                            {
                                // Suppress error
                            }

                            FormInfo fi;
                            if (fromExisting)
                            {
                                // From existing DB table
                                dci.ClassXmlSchema = tm.GetXmlSchema(tableName);

                                string formDef = FormHelper.GetXmlFormDefinitionFromXmlSchema(dci.ClassXmlSchema, false);
                                fi = new FormInfo(formDef);
                            }
                            else
                            {
                                // Create empty form info
                                fi = CreateEmptyFormInfo();

                                dci.ClassXmlSchema = tm.GetXmlSchema(tableName);
                            }

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

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

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

                                DataClassInfoProvider.SetDataClassInfo(dci);

                                UpdateInheritedClass(dci);
                            }

                            if (Mode == NewClassWizardModeEnum.CustomTable)
                            {
                                try
                                {
                                    InitCustomTable(dci, fi, tm);
                                }
                                catch (Exception ex)
                                {
                                    // Do not move to next step.
                                    e.Cancel = true;

                                    EventLogProvider.LogException("NewClassWizard", "CREATE", ex);

                                    string message = null;
                                    if (ex is MissingSQLTypeException)
                                    {
                                        var missingSqlType = (MissingSQLTypeException) ex;
                                        message = String.Format(GetString("customtable.sqltypenotsupported"), missingSqlType.UnsupportedType, missingSqlType.ColumnName, missingSqlType.RecommendedType);
                                    }
                                    else
                                    {
                                        message = ex.Message;
                                    }

                                    pnlMessages2.ShowError(message);
                                    pnlMessages2.Visible = true;
                                }
                            }

                            if (!e.Cancel)
                            {
                                // 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 (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
                        if (!String.IsNullOrEmpty(tableNameError))
                        {
                            lblTableNameError.Text = tableNameError;
                            lblTableNameError.Visible = true;
                        }
                        else
                        {
                            lblTableNameError.Visible = false;
                        }

                        if (!String.IsNullOrEmpty(primaryKeyNameEmpty))
                        {
                            lblPKNameError.Visible = true;
                            lblPKNameError.Text = primaryKeyNameEmpty;
                        }
                        else
                        {
                            lblPKNameError.Visible = false;
                        }

                        if (columnExists)
                        {
                            pnlMessages2.ShowError(GetString("DocumentType_New_Step2.ErrorColumnExists"));
                            pnlMessages2.Visible = true;
                        }

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

                        // Reset the header
                        switch (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.SetDataClassInfo(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 wizard is used to create new document type
                if (Mode == NewClassWizardModeEnum.DocumentType)
                {
                    // Setup icon class for new doc. type
                    string iconClass = (SomeStepsOmitted) ? DEFAULT_CLASS_ICON : DEFAULT_COUPLED_CLASS_ICON;
                    dci.SetValue("ClassIconClass", iconClass);
                }

                if (!e.Cancel)
                {
                    tr.Commit();
                }
            }
        }
    }
    /// <summary>
    /// Processes the step 2 of the wizard
    /// </summary>
    private void ProcessStep2(WizardNavigationEventArgs e)
    {
        FormFieldInfo ffiPrimaryKey = null;
        DataClassInfo dci = DataClassInfoProvider.GetDataClass(ClassName);
        FormInfo fi = null;

        if (dci != null)
        {
            TableManager tm = new TableManager(null);

            using (var tr = new CMSTransactionScope())
            {
                var genDci = dci.Generalized;

                // New document type has custom attributes -> no wizard steps will be omitted
                if (radCustom.Checked)
                {
                    // Actions after next button click
                    bool fromExisting = (Mode == NewClassWizardModeEnum.CustomTable) && radExistingTable.Checked;

                    string tableName = txtTableName.Text.Trim();
                    if (fromExisting)
                    {
                        tableName = drpExistingTables.SelectedValue;
                    }

                    // Validate checkboxes first
                    string tableNameError = new Validator()
                        .NotEmpty(tableName, GetString("DocumentType_New.ErrorEmptyTableName"))
                        .IsIdentifier(tableName, GetString("class.ErrorIdentifier"))
                        .Result;

                    string primaryKeyNameEmpty = new Validator().NotEmpty(txtPKName.Text.Trim(), GetString("DocumentType_New.ErrorEmptyPKName")).Result;

                    bool columnExists = DocumentHelper.ColumnExistsInSystemTable(txtPKName.Text.Trim());

                    // Textboxes are filled correctly
                    if ((tableNameError == "") && (primaryKeyNameEmpty == "") && (!columnExists))
                    {
                        try
                        {
                            if (fromExisting)
                            {
                                // Custom table from existing table - validate the table name
                                if (!tm.TableExists(tableName))
                                {
                                    e.Cancel = true;

                                    // Table with the same name already exists
                                    ShowError(GetString("customtable.newwizard.tablenotexists"));
                                }

                                // Check primary key
                                List<string> primaryKeys = tm.GetPrimaryKeyColumns(tableName);
                                if ((primaryKeys == null) || (primaryKeys.Count != 1))
                                {
                                    e.Cancel = true;

                                    ShowError(GetString("customtable.newwizard.musthaveprimarykey"));
                                }
                            }
                            else if (SystemDevelopmentMode && (Mode == NewClassWizardModeEnum.Class))
                            {
                                // Standard class in development mode
                                tm.CreateTable(tableName, txtPKName.Text.Trim(), !chbIsMNTable.Checked);
                            }
                            else
                            {
                                tm.CreateTable(tableName, txtPKName.Text.Trim());
                            }
                        }
                        catch (Exception ex)
                        {
                            // No movement to the next step
                            e.Cancel = true;

                            // Table with the same name already exists
                            ShowError(ex.Message);
                        }

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

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

                                if ((owner != "") && (owner.ToLowerCSafe() != "dbo"))
                                {
                                    tm.ChangeDBObjectOwner(tableName, owner);
                                    tableName = DataHelper.GetSafeOwner(owner) + "." + tableName;
                                }
                            }
                            catch
                            {
                            }

                            if (fromExisting)
                            {
                                // From existing DB table
                                dci.ClassXmlSchema = tm.GetXmlSchema(tableName);

                                string formDef = FormHelper.GetXmlFormDefinitionFromXmlSchema(dci.ClassXmlSchema, false);
                                fi = new FormInfo(formDef);
                            }
                            else
                            {
                                // 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).ToLowerCSafe();
                                ffiPrimaryKey.PrimaryKey = true;
                                ffiPrimaryKey.System = false;
                                ffiPrimaryKey.Visible = false;
                                ffiPrimaryKey.Size = 0;
                                ffiPrimaryKey.AllowEmpty = false;

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

                                dci.ClassXmlSchema = tm.GetXmlSchema(tableName);
                            }

                            dci.ClassTableName = tableName;
                            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 (Mode == NewClassWizardModeEnum.CustomTable)
                            {
                                #region "Custom tables optional columns"

                                // Created by
                                if (chkItemCreatedBy.Checked && !fi.FieldExists("ItemCreatedBy"))
                                {
                                    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).ToLowerCSafe();
                                    ffi.PrimaryKey = false;
                                    ffi.System = true;
                                    ffi.Visible = false;
                                    ffi.Size = 0;
                                    ffi.AllowEmpty = true;

                                    fi.AddFormField(ffi);
                                }

                                // Created when
                                if (chkItemCreatedWhen.Checked && !fi.FieldExists("ItemCreatedWhen"))
                                {
                                    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).ToLowerCSafe();
                                    ffi.PrimaryKey = false;
                                    ffi.System = true;
                                    ffi.Visible = false;
                                    ffi.Size = 0;
                                    ffi.AllowEmpty = true;

                                    fi.AddFormField(ffi);
                                }

                                // Modified by
                                if (chkItemModifiedBy.Checked && !fi.FieldExists("ItemModifiedBy"))
                                {
                                    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).ToLowerCSafe();
                                    ffi.PrimaryKey = false;
                                    ffi.System = true;
                                    ffi.Visible = false;
                                    ffi.Size = 0;
                                    ffi.AllowEmpty = true;

                                    fi.AddFormField(ffi);
                                }

                                // Modified when
                                if (chkItemModifiedWhen.Checked && !fi.FieldExists("ItemModifiedWhen"))
                                {
                                    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).ToLowerCSafe();
                                    ffi.PrimaryKey = false;
                                    ffi.System = true;
                                    ffi.Visible = false;
                                    ffi.Size = 0;
                                    ffi.AllowEmpty = true;

                                    fi.AddFormField(ffi);
                                }

                                // Item order
                                if (chkItemOrder.Checked && !fi.FieldExists("ItemOrder"))
                                {
                                    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).ToLowerCSafe();
                                    ffi.PrimaryKey = false;
                                    ffi.System = true;
                                    ffi.Visible = false;
                                    ffi.Size = 0;
                                    ffi.AllowEmpty = true;

                                    fi.AddFormField(ffi);
                                }

                                #endregion

                                if (chkItemGUID.Checked && !fi.FieldExists("ItemGUID"))
                                {
                                    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).ToLowerCSafe();
                                    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();
                                tm.UpdateTableBySchema(tableName, 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.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 (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 (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 wizard is used to create new document type
                if (Mode == NewClassWizardModeEnum.DocumentType)
                {
                    string sourceFile = "";
                    string destFile = GetDocumentTypeIconUrl(ClassName, false);
                    string sourceLargeFile = "";
                    string destLargeFile = GetDocumentTypeIconPath(ClassName, "48x48", false);

                    // If class is not coupled class
                    if (SomeStepsOmitted)
                    {
                        sourceFile = GetDocumentTypeIconPath("defaultcontainer", "", true);
                        sourceLargeFile = GetDocumentTypeIconPath("defaultcontainer", "48x48", true);
                    }
                    else
                    {
                        sourceFile = GetDocumentTypeIconPath("default", "", true);
                        sourceLargeFile = GetDocumentTypeIconPath("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.ToLowerCSafe().EndsWithCSafe(".gif"))
                    {
                        destFile = destFile.Replace(".png", ".gif");
                    }
                    // Ensure same extension
                    if (sourceLargeFile.ToLowerCSafe().EndsWithCSafe(".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
                        {
                            FieldEditor.ShowError(string.Format(GetString("DocumentType_New_Step2.ErrorCopyIcon"), sourceFile, destFile));
                        }
                    }

                    // Copy large file icon
                    if (!FileHelper.FileExists(destLargeFile))
                    {
                        try
                        {
                            // Create new document type large icon via copying default icon
                            File.Copy(Server.MapPath(sourceLargeFile), Server.MapPath(destLargeFile), false);
                        }
                        catch
                        {
                            FieldEditor.ShowError(string.Format(GetString("DocumentType_New_Step2.ErrorCopyIcon"), sourceLargeFile, destLargeFile));
                        }
                    }
                }

                if (!e.Cancel)
                {
                    tr.Commit();
                }
            }
        }
    }