/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!BizFormInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.BizForms, ObjectActionEnum.Insert)) { ShowError(GetString("LicenseVersion.BizForm")); return; } DataClassInfo dci = null; BizFormInfo bizFormObj = null; string errorMessage = new Validator().NotEmpty(txtFormDisplayName.Text, rfvFormDisplayName.ErrorMessage). NotEmpty(txtFormName.Text, rfvFormName.ErrorMessage). NotEmpty(txtTableName.Text, rfvTableName.ErrorMessage). IsIdentifier(txtFormName.Text, GetString("bizform_edit.errorformnameinidentifierformat")). IsIdentifier(txtTableName.Text, GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")).Result; if (String.IsNullOrEmpty(errorMessage)) { using (var tr = new CMSTransactionScope()) { // Prepare the values string formDisplayName = txtFormDisplayName.Text.Trim(); bizFormObj = new BizFormInfo(); bizFormObj.FormDisplayName = formDisplayName; bizFormObj.FormName = txtFormName.Text.Trim(); bizFormObj.FormSiteID = SiteContext.CurrentSiteID; bizFormObj.FormEmailAttachUploadedDocs = true; bizFormObj.FormItems = 0; bizFormObj.FormClearAfterSave = false; bizFormObj.FormLogActivity = true; // Ensure the code name bizFormObj.Generalized.EnsureCodeName(); // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name string safeFormName = ValidationHelper.GetIdentifier(bizFormObj.FormName); bizFormObj.FormName = safeFormName; string className = bizFormNamespace + "." + safeFormName; // Generate the table name string tableName = txtTableName.Text.Trim(); if (String.IsNullOrEmpty(tableName) || (tableName == InfoHelper.CODENAME_AUTOMATIC)) { tableName = safeFormName; } tableName = FormTablePrefix + tableName; TableManager tm = new TableManager(null); // TableName wont be longer than 60 letters and will be unique if (tableName.Length > 60) { int x = 1; while (tm.TableExists(tableName.Substring(0, 59) + x.ToString())) { x++; } tableName = tableName.Substring(0, 59) + x.ToString(); } // If first letter of safeFormName is digit, add "PK" to beginning string primaryKey = BizFormInfoProvider.GenerateFormPrimaryKeyName(bizFormObj.FormName); try { // Create new table in DB tm.CreateTable(tableName, primaryKey); } catch (Exception ex) { errorMessage = ex.Message; // Table with the same name already exists ShowError(string.Format(GetString("bizform_edit.errortableexists"), tableName)); return; } // Change table owner try { string owner = SqlHelper.GetDBSchema(SiteContext.CurrentSiteName); if ((!String.IsNullOrEmpty(owner)) && (owner.ToLowerCSafe() != "dbo")) { tm.ChangeDBObjectOwner(tableName, owner); tableName = owner + "." + tableName; } } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", "E", ex); } // Convert default datetime to string in english format string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat); try { // Add FormInserted and FormUpdated columns to the table tm.AddTableColumn(tableName, "FormInserted", "datetime", false, defaultDateTime); tm.AddTableColumn(tableName, "FormUpdated", "datetime", false, defaultDateTime); } catch (Exception ex) { errorMessage = ex.Message; // Column wasn't added successfully ShowError(errorMessage); return; } // Create the BizForm class dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey); try { // Create new bizform dataclass using (CMSActionContext context = new CMSActionContext()) { // Disable logging of tasks context.DisableLogging(); // Set default search settings dci.ClassSearchEnabled = true; DataClassInfoProvider.SetDataClassInfo(dci); // Create default search settings dci.ClassSearchSettings = SearchHelper.GetDefaultSearchSettings(dci); dci.ClassSearchCreationDateColumn = "FormInserted"; DataClassInfoProvider.SetDataClassInfo(dci); } } catch (Exception ex) { errorMessage = ex.Message; // Class with the same name already exists ShowError(errorMessage); return; } // Create new bizform bizFormObj.FormClassID = dci.ClassID; try { // Create new bizform BizFormInfoProvider.SetBizFormInfo(bizFormObj); } catch (Exception ex) { errorMessage = ex.Message; ShowError(errorMessage); return; } tr.Commit(); if (String.IsNullOrEmpty(errorMessage)) { // Redirect to Form builder tab string url = UIContextHelper.GetElementUrl("CMS.Form", "Forms.Properties", false, bizFormObj.FormID); url = URLHelper.AddParameterToUrl(url, "tabname", "Forms.FormBuldier"); URLHelper.Redirect(url); } } } else { ShowError(errorMessage); } }
/// <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> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!BizFormInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.BizForms, ObjectActionEnum.Insert)) { ShowError(GetString("LicenseVersion.BizForm")); return; } string formDisplayName = txtFormDisplayName.Text.Trim(); string formName = txtFormName.Text.Trim(); string tableName = txtTableName.Text.Trim(); string errorMessage = new Validator().NotEmpty(formDisplayName, rfvFormDisplayName.ErrorMessage). NotEmpty(formName, rfvFormName.ErrorMessage). NotEmpty(tableName, rfvTableName.ErrorMessage). IsIdentifier(formName, GetString("bizform_edit.errorformnameinidentifierformat")). IsIdentifier(tableName, GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")).Result; if (!String.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); return; } var bizFormObj = new BizFormInfo { FormDisplayName = formDisplayName, FormName = formName, FormSiteID = SiteContext.CurrentSiteID, FormEmailAttachUploadedDocs = true, FormItems = 0, FormClearAfterSave = false, FormLogActivity = true }; // Ensure the code name bizFormObj.Generalized.EnsureCodeName(); // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name string safeFormName = ValidationHelper.GetIdentifier(bizFormObj.FormName); bizFormObj.FormName = safeFormName; string className = bizFormNamespace + "." + safeFormName; // Generate the table name if (String.IsNullOrEmpty(tableName) || (tableName == InfoHelper.CODENAME_AUTOMATIC)) { tableName = safeFormName; } tableName = FormTablePrefix + tableName; TableManager tm = new TableManager(null); // TableName wont be longer than 60 letters and will be unique if (tableName.Length > 60) { string tmpTableName = tableName.Substring(0, 59); int x = 1; do { tableName = tmpTableName + x; x++; } while (tm.TableExists(tableName)); } // TableName should be unique if (tm.TableExists(tableName)) { ShowError(string.Format(GetString("bizform_edit.errortableexists"), tableName)); return; } // If first letter of safeFormName is digit, add "PK" to beginning string primaryKey = BizFormInfoProvider.GenerateFormPrimaryKeyName(bizFormObj.FormName); try { // Create new table in DB tm.CreateTable(tableName, primaryKey); } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", EventType.ERROR, ex); ShowError(string.Format(GetString("bizform_edit.createtableerror"), tableName)); return; } // Change table owner try { string owner = SqlHelper.GetDBSchema(SiteContext.CurrentSiteName); if (!String.IsNullOrEmpty(owner) && (owner.ToLowerCSafe() != "dbo")) { tm.ChangeDBObjectOwner(tableName, owner); tableName = owner + "." + tableName; } } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", EventType.ERROR, ex); } // Create the BizForm class DataClassInfo dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey); try { // Create new bizform dataclass using (CMSActionContext context = new CMSActionContext()) { // Disable logging of tasks context.DisableLogging(); DataClassInfoProvider.SetDataClassInfo(dci); } } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", EventType.ERROR, ex); ShowError(ex.Message); CleanUpOnError(tableName, tm, dci); return; } // Create new bizform bizFormObj.FormClassID = dci.ClassID; try { BizFormInfoProvider.SetBizFormInfo(bizFormObj); } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", EventType.ERROR, ex); ShowError(ex.Message); CleanUpOnError(tableName, tm, dci, bizFormObj); return; } // Redirect to Form builder tab string url = UIContextHelper.GetElementUrl("CMS.Form", "Forms.Properties", false, bizFormObj.FormID); url = URLHelper.AddParameterToUrl(url, "tabname", "Forms.FormBuldier"); URLHelper.Redirect(url); }
/// <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(); } } } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (!BizFormInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.BizForms, ObjectActionEnum.Insert)) { ShowError(GetString("LicenseVersion.BizForm")); return; } DataClassInfo dci = null; BizFormInfo bizFormObj = null; string errorMessage = new Validator().NotEmpty(txtFormDisplayName.Text, rfvFormDisplayName.ErrorMessage). NotEmpty(txtFormName.Text, rfvFormName.ErrorMessage). NotEmpty(txtTableName.Text, rfvTableName.ErrorMessage). IsIdentifier(txtFormName.Text, GetString("bizform_edit.errorformnameinidentifierformat")). IsIdentifier(txtTableName.Text, GetString("BizForm_Edit.ErrorFormTableNameInIdentifierFormat")).Result; if (String.IsNullOrEmpty(errorMessage)) { using (var tr = new CMSTransactionScope()) { // Prepare the values string formDisplayName = txtFormDisplayName.Text.Trim(); bizFormObj = new BizFormInfo(); bizFormObj.FormDisplayName = formDisplayName; bizFormObj.FormName = txtFormName.Text.Trim(); bizFormObj.FormSiteID = SiteContext.CurrentSiteID; bizFormObj.FormEmailAttachUploadedDocs = true; bizFormObj.FormItems = 0; bizFormObj.FormClearAfterSave = false; bizFormObj.FormLogActivity = true; // Ensure the code name bizFormObj.Generalized.EnsureCodeName(); // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name string safeFormName = ValidationHelper.GetIdentifier(bizFormObj.FormName); bizFormObj.FormName = safeFormName; string className = bizFormNamespace + "." + safeFormName; // Generate the table name string tableName = txtTableName.Text.Trim(); if (String.IsNullOrEmpty(tableName) || (tableName == InfoHelper.CODENAME_AUTOMATIC)) { tableName = safeFormName; } tableName = FormTablePrefix + tableName; TableManager tm = new TableManager(null); // TableName wont be longer than 60 letters and will be unique if (tableName.Length > 60) { int x = 1; while (tm.TableExists(tableName.Substring(0, 59) + x.ToString())) { x++; } tableName = tableName.Substring(0, 59) + x.ToString(); } // If first letter of safeFormName is digit, add "PK" to beginning string primaryKey = BizFormInfoProvider.GenerateFormPrimaryKeyName(bizFormObj.FormName); try { // Create new table in DB tm.CreateTable(tableName, primaryKey); } catch (Exception ex) { errorMessage = ex.Message; // Table with the same name already exists ShowError(string.Format(GetString("bizform_edit.errortableexists"), tableName)); return; } // Change table owner try { string owner = SqlHelper.GetDBSchema(SiteContext.CurrentSiteName); if ((!String.IsNullOrEmpty(owner)) && (owner.ToLowerCSafe() != "dbo")) { tm.ChangeDBObjectOwner(tableName, owner); tableName = owner + "." + tableName; } } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", "E", ex); } // Convert default datetime to string in english format string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat); try { // Add FormInserted and FormUpdated columns to the table tm.AddTableColumn(tableName, "FormInserted", "datetime", false, defaultDateTime); tm.AddTableColumn(tableName, "FormUpdated", "datetime", false, defaultDateTime); } catch (Exception ex) { errorMessage = ex.Message; // Column wasn't added successfully ShowError(errorMessage); return; } // Create the BizForm class dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey); try { // Create new bizform dataclass using (CMSActionContext context = new CMSActionContext()) { // Disable logging of tasks context.DisableLogging(); // Set default search settings dci.ClassSearchEnabled = true; DataClassInfoProvider.SetDataClassInfo(dci); // Create default search settings dci.ClassSearchSettings = SearchHelper.GetDefaultSearchSettings(dci); dci.ClassSearchCreationDateColumn = "FormInserted"; DataClassInfoProvider.SetDataClassInfo(dci); } } catch (Exception ex) { errorMessage = ex.Message; // Class with the same name already exists ShowError(errorMessage); return; } // Create new bizform bizFormObj.FormClassID = dci.ClassID; try { // Create new bizform BizFormInfoProvider.SetBizFormInfo(bizFormObj); } catch (Exception ex) { errorMessage = ex.Message; ShowError(errorMessage); return; } tr.Commit(); if (String.IsNullOrEmpty(errorMessage)) { // Redirect to Form builder tab string url = UIContextHelper.GetElementUrl("CMS.Form", "Forms.Properties", false, bizFormObj.FormID); url = URLHelper.AddParameterToUrl(url, "tabname", "Forms.FormBuldier"); URLHelper.Redirect(url); } } } else { ShowError(errorMessage); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { DataClassInfo dci = null; BizFormInfo bizFormObj = null; string errorMessage = new Validator().NotEmpty(txtFormDisplayName.Text, rfvFormDisplayName.ErrorMessage). NotEmpty(txtFormName.Text, rfvFormName.ErrorMessage). NotEmpty(txtTableName.Text, rfvTableName.ErrorMessage). IsIdentificator(txtFormName.Text, GetString("BizForm_Edit.ErrorFormNameInIdentificatorFormat")). IsIdentificator(txtTableName.Text, GetString("BizForm_Edit.ErrorFormTableNameInIdentificatorFormat")).Result; if (String.IsNullOrEmpty(errorMessage)) { string formCodeName = txtFormName.Text.Trim(); // Form name must be unique BizFormInfo testObj = BizFormInfoProvider.GetBizFormInfo(formCodeName, CMSContext.CurrentSiteName); // If formName value is unique... if (testObj == null) { string primaryKey = formCodeName + "ID"; string formDisplayName = txtFormDisplayName.Text.Trim(); string className = bizFormNamespace + "." + formCodeName; // Table name is combined from prefix ('BizForm_<sitename>_') and custom table name string tableName = FormTablePrefix + txtTableName.Text.Trim(); if (!BizFormInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.BizForms, VersionActionEnum.Insert)) { lblError.Visible = true; lblError.Text = GetString("LicenseVersion.BizForm"); } if (!lblError.Visible) { try { // Create new table in DB TableManager.CreateTable(tableName, primaryKey); } catch (Exception ex) { errorMessage = ex.Message; // Table with the same name already exists lblError.Visible = true; lblError.Text = string.Format(GetString("bizform_edit.errortableexists"), tableName); } if (String.IsNullOrEmpty(errorMessage)) { // Change table owner try { string owner = SqlHelperClass.GetDBSchema(CMSContext.CurrentSiteName); if ((!String.IsNullOrEmpty(owner)) && (owner.ToLower() != "dbo")) { TableManager.ChangeDBObjectOwner(tableName, owner); tableName = owner + "." + tableName; } } catch (Exception ex) { EventLogProvider.LogException("BIZFORM_NEW", "E", ex); } // Convert default datetime to string in english format string defaultDateTime = DateTime.Now.ToString(CultureHelper.EnglishCulture.DateTimeFormat); try { // Add FormInserted and FormUpdated columns to the table TableManager.AddTableColumn(tableName, "FormInserted", "datetime", false, defaultDateTime); TableManager.AddTableColumn(tableName, "FormUpdated", "datetime", false, defaultDateTime); } catch (Exception ex) { errorMessage = ex.Message; // Column wasnt added successfuly lblError.Visible = true; lblError.Text = errorMessage; // Delete created table TableManager.DropTable(tableName); } } if (String.IsNullOrEmpty(errorMessage)) { dci = BizFormInfoProvider.CreateBizFormDataClass(className, formDisplayName, tableName, primaryKey); try { // Create new bizform dataclass using (CMSActionContext context = new CMSActionContext()) { // Disable logging of tasks context.DisableLogging(); DataClassInfoProvider.SetDataClass(dci); } } catch (Exception ex) { errorMessage = ex.Message; // Class with the same name already exists lblError.Visible = true; lblError.Text = errorMessage; // Delete created table TableManager.DropTable(tableName); } } if (String.IsNullOrEmpty(errorMessage)) { // Create new bizform bizFormObj = new BizFormInfo(); bizFormObj.FormDisplayName = formDisplayName; bizFormObj.FormName = formCodeName; bizFormObj.FormClassID = dci.ClassID; bizFormObj.FormSiteID = CMSContext.CurrentSiteID; bizFormObj.FormEmailAttachUploadedDocs = true; bizFormObj.FormItems = 0; bizFormObj.FormClearAfterSave = false; bizFormObj.FormLogActivity = true; try { // Create new bizform BizFormInfoProvider.SetBizFormInfo(bizFormObj); // Generate basic queries SqlGenerator.GenerateQuery(className, "selectall", SqlOperationTypeEnum.SelectAll, false); SqlGenerator.GenerateQuery(className, "delete", SqlOperationTypeEnum.DeleteQuery, false); SqlGenerator.GenerateQuery(className, "insert", SqlOperationTypeEnum.InsertQuery, true); SqlGenerator.GenerateQuery(className, "update", SqlOperationTypeEnum.UpdateQuery, false); SqlGenerator.GenerateQuery(className, "select", SqlOperationTypeEnum.SelectQuery, false); } catch (Exception ex) { errorMessage = ex.Message; lblError.Visible = true; lblError.Text = errorMessage; // Delete created class (includes deleting its table) if (dci != null) { using (CMSActionContext context = new CMSActionContext()) { // Disable logging of tasks context.DisableLogging(); DataClassInfoProvider.DeleteDataClass(dci); } } } if (String.IsNullOrEmpty(errorMessage)) { // Redirect to edit dialog URLHelper.Redirect(string.Format("BizForm_Frameset.aspx?formId={0}&newform=1", bizFormObj.FormID)); } } } } else { lblError.Visible = true; lblError.Text = GetString("BizForm_Edit.FormNameExists"); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }