/// <summary>
    /// Adds GUID field to form definition.
    /// </summary>
    private void CreateGUID()
    {
        try
        {
            // Create GUID field
            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;

            FormInfo.AddFormField(ffiGuid);

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

            TableManager tm = new TableManager(null);
            tm.UpdateTableBySchema(dci.ClassTableName, schema);

            TableManager.UpdateSystemFields = old;

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

            dci.Generalized.LogEvents = false;

            // Save the data
            DataClassInfoProvider.SetDataClass(dci);

            dci.Generalized.LogEvents = true;

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

            // Clear cached data
            CMSObjectHelper.RemoveReadOnlyObjects(CustomTableItemProvider.GetObjectType(className), true);
            CustomTableItemProvider.Remove(className, true);

            // Clear the object type hashtable
            ProviderStringDictionary.ReloadDictionaries(className, true);

            // Clear the classes hashtable
            ProviderStringDictionary.ReloadDictionaries("cms.class", true);

            // Clear class strucures
            ClassStructureInfo.Remove(className, true);

            // Ensure GUIDs for all items
            CustomTableItemProvider tableProvider = new CustomTableItemProvider();
            tableProvider.UpdateSystemFields = false;
            tableProvider.LogSynchronization = false;
            DataSet dsItems = tableProvider.GetItems(className, null, null);
            if (!DataHelper.DataSourceIsEmpty(dsItems))
            {
                foreach (DataRow dr in dsItems.Tables[0].Rows)
                {
                    CustomTableItem item = CustomTableItem.New(dr, className, tableProvider);
                    item.ItemGUID = Guid.NewGuid();
                    item.Update();
                }
            }

            // Log event
            UserInfo currentUser = CMSContext.CurrentUser;
            EventLog.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Custom table", "GENERATEGUID", currentUser.UserID, currentUser.UserName, 0, null, null, string.Format(ResHelper.GetAPIString("customtable.GUIDGenerated", "Field 'ItemGUID' for custom table '{0}' was created and GUID values were generated."), dci.ClassName), 0, null);

            URLHelper.Redirect(URLHelper.AddParameterToUrl(URLRewriter.CurrentURL, "gen", "1"));
        }
        catch (Exception ex)
        {
            FieldEditor.ShowError(GetString("customtable.ErrorGUID") + ex.Message);

            // Log event
            EventLog.LogEvent("Custom table", "GENERATEGUID", ex);
        }
    }