public static ModelAddState Add(UserGroupInfo model) { int num = UserGroup.ExistsUserGroup(model.GroupName, model.TableName); ModelAddState result; if (num > 0) { result = (ModelAddState)num; } else { string tableName = "dbo." + model.TableName; int num2 = BizBase.dbo.InsertModel <UserGroupInfo>(model); if (num2 > 0) { try { TableManager.CreateTable(tableName, "AutoID"); TableManager.AddTableColumn(tableName, "UserID", "INT", false, "0"); UserGroup.AddDefaultField(num2); CacheUtils.Del("JsonLeeCMS_CacheForGetUserGroup"); result = ModelAddState.Success; return(result); } catch { result = ModelAddState.CreateTableError; return(result); } } CacheUtils.Del("JsonLeeCMS_CacheForGetUserGroup"); result = ModelAddState.Error; } return(result); }
public void CanGetTableInfoInDifferentTableManager() { var tableMetadataStorageFilename = RandomFilename; var fieldMetadataStorageFilename = RandomFilename; tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var schema = new Schema(); schema.AddIntField("field1"); schema.AddBlobField("field2", 40); tableManager.CreateTable("table1", schema, _transaction); _transaction.Commit(); _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); tableManager = new TableManager(false, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var tableInfo = tableManager.GetTableInfo("table1", _transaction); Assert.AreEqual("table1.tbl", tableInfo.Filename); Assert.AreEqual(2, tableInfo.Schema.Fields.Count); Assert.AreEqual(48, tableInfo.RecordLength); var field1 = tableInfo.Schema.Fields["field1"]; var field2 = tableInfo.Schema.Fields["field2"]; Assert.AreEqual(FieldType.Integer, field1.Type); Assert.AreEqual(FieldType.Blob, field2.Type); Assert.AreEqual(40, field2.Length); }
public void Setup() { _logName = RandomFilename; _fileManager = new FileManager("temp", "DBs", 1024); _logManager = new LogManager(_fileManager, _logName); _bufferManager = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 1000)); _dispatcher = new TransactionNumberDispatcher(10); _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); var schema = new Schema(); schema.AddIntField("Id"); tableCatalogName = RandomFilename; fieldCatalogName = RandomFilename; viewCatalogName = RandomFilename; tableName = RandomFilename; tableManager = new TableManager(true, _transaction, tableCatalogName, fieldCatalogName); tableInfo = new TableInfo(tableName, schema); tableManager.CreateTable(tableName, schema, _transaction); viewManager = new ViewManager(true, tableManager, _transaction, viewCatalogName); statisticsManager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 0); }
public static ModelAddState Add(ProductModelInfo model) { int num = ProductModel.ExistsModel(model.ModelName, model.TableName); ModelAddState result; if (num > 0) { result = (ModelAddState)num; } else { string tableName = "dbo." + model.TableName; int num2 = BizBase.dbo.InsertModel <ProductModelInfo>(model); if (num2 > 0) { try { TableManager.CreateTable(tableName, "AutoID"); TableManager.AddTableColumn(tableName, "ProID", "INT", false, "0"); ProductModel.AddDefaultField(num2); CacheUtils.Del("JsonLeeCMS_CacheForPROMODEL"); result = ModelAddState.Success; return(result); } catch { result = ModelAddState.CreateTableError; return(result); } } CacheUtils.Del("JsonLeeCMS_CacheForPROMODEL"); result = ModelAddState.Error; } return(result); }
public void CanGetTableInfoWhileItWasUncommited() { var tableMetadataStorageFilename = RandomFilename; var fieldMetadataStorageFilename = RandomFilename; tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var schema = new Schema(); schema.AddIntField("field1"); schema.AddBlobField("field2", 40); tableManager.CreateTable("table1", schema, _transaction); var tableInfo = tableManager.GetTableInfo("table1", _transaction); Assert.AreEqual("table1.tbl", tableInfo.Filename); Assert.AreEqual(2, tableInfo.Schema.Fields.Count); Assert.AreEqual(48, tableInfo.RecordLength); var field1 = tableInfo.Schema.Fields["field1"]; var field2 = tableInfo.Schema.Fields["field2"]; Assert.AreEqual(FieldType.Integer, field1.Type); Assert.AreEqual(FieldType.Blob, field2.Type); Assert.AreEqual(40, field2.Length); }
public void CanGetStatisticsFromNewTable() { manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1); var data = manager.GetStatisticalInfo(tableName, _transaction); var newTableName = RandomFilename; var schema = new Schema(); schema.AddIntField("Id"); schema.AddStringField("Guid", 40); var newTableInfo = new TableInfo(newTableName, schema); tableManager.CreateTable(newTableName, schema, _transaction); var recordFile = new RecordFile(newTableInfo, _transaction); recordFile.BeforeFirst(); for (int i = 0; i < 50; ++i) { recordFile.Insert(); recordFile.SetInt("Id", i + 10); recordFile.SetString("Guid", Guid.NewGuid().ToString()); } _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); //Before update Assert.AreEqual(1, data.BlocksAccessed); Assert.AreEqual(0, data.RecordsOutput); Assert.AreEqual(1, data.DistinctValues("Id")); _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); //After update var updatedData = manager.GetStatisticalInfo(newTableName, _transaction); Assert.AreEqual(50, updatedData.RecordsOutput); Assert.AreEqual(3, updatedData.BlocksAccessed); Assert.AreEqual(17, updatedData.DistinctValues("Id")); }
public ActionResult Create(Table table) { if (!ModelState.IsValid) { return(View(table)); } table.RestaurantId = User.Identity.GetUserId(); db.CreateTable(table); return(RedirectToAction("ManagerIndex")); }
public void WouldGetNullIfTableWasNotFound() { var tableMetadataStorageFilename = RandomFilename; var fieldMetadataStorageFilename = RandomFilename; tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var schema = new Schema(); schema.AddIntField("field1"); schema.AddBlobField("field2", 40); tableManager.CreateTable("table1", schema, _transaction); _transaction.Commit(); _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); tableManager = new TableManager(false, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var tableInfo = tableManager.GetTableInfo("table2", _transaction); Assert.IsNull(tableInfo); }
public void CanCreateIntegerIndex() { var indexTableName = RandomFilename; var schema = new Schema(); schema.AddIntField("Field"); tableInfo = new TableInfo(indexTableName, schema); tableManager.CreateTable(indexTableName, schema, _transaction); indexInfo = new IndexInfo("index", indexTableName, "Field", tableManager, statisticsManager, _transaction, 1024); // Todo check them out var indexSchema = indexInfo.Open(); Assert.Pass(); }
/// <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(); } } } }
public bool Test() { bool ret = false; try { TableResponse m_TResponse; TableManager m_TManager = new TableManager(); //CreateDatabaseTest Message m_createDatabase = new Message(); m_TResponse = m_TManager.CreateDatabase("TestDatabase"); m_createDatabase.Passed = m_TResponse.GetResponse; m_createDatabase.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_createDatabase.TestID = 1; m_msg.Add(m_createDatabase.ToString()); //Generate columns to be added to table Dictionary<string, bool> m_Dict = new Dictionary<string, bool>(); m_Dict.Add("ID", true); m_Dict.Add("Name", false); m_Dict.Add("Dept", true); //Adding the typenames for the columns List<string> m_colTypelist = new List<string>(); m_colTypelist.Add("int"); m_colTypelist.Add("float"); m_colTypelist.Add("varchar(10)"); //CreateTable Test Message m_createTable = new Message(); m_TResponse = m_TManager.CreateTable("TestDatabase", "TestTable", m_Dict, m_colTypelist); m_createTable.Passed = m_TResponse.GetResponse; m_createTable.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_createTable.TestID = 2; m_msg.Add(m_createTable.ToString()); //create List for the columnnames to add row List<string> ListColumnName = new List<string>(); ListColumnName.Add("ID"); ListColumnName.Add("Name"); ListColumnName.Add("Dept"); //generate arraylist for data to be add row ArrayList AlColVal = new ArrayList(); AlColVal.Add(11); AlColVal.Add(11.1f); AlColVal.Add("test"); //Add Row Test m_TResponse = m_TManager.InsertRow("TestDatabase", "TestTable", ListColumnName, AlColVal); Message m_InsertRow = new Message(); m_InsertRow.Passed = m_TResponse.GetResponse; m_InsertRow.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_InsertRow.TestID = 3; m_msg.Add(m_InsertRow.ToString()); //AddColumn Test m_TResponse = m_TManager.AddColumn("TestDatabase", "TestTable", false, "str", "varchar(8)"); Message m_AddColumn = new Message(); m_AddColumn.Passed = m_TResponse.GetResponse; m_AddColumn.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_AddColumn.TestID = 4; m_msg.Add(m_AddColumn.ToString()); //rename column Test m_TResponse = m_TManager.RenameColumn("TestDatabase", "TestTable", "str", "newStr"); Message m_RenameColumn = new Message(); m_RenameColumn.Passed = m_TResponse.GetResponse; m_RenameColumn.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_RenameColumn.TestID = 5; m_msg.Add(m_RenameColumn.ToString()); //renameTable Test m_TResponse = m_TManager.RenameTable("TestDatabase", "TestTable", "NewTestTable"); Message m_RenameTable = new Message(); m_RenameTable.Passed = m_TResponse.GetResponse; m_RenameTable.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_RenameTable.TestID = 6; m_msg.Add(m_RenameTable.ToString()); //Emptytable Test m_TResponse = m_TManager.EmptyTable("TestDatabase", "NewTestTable"); Message m_EmptyTable = new Message(); m_EmptyTable.Passed = m_TResponse.GetResponse; m_EmptyTable.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_EmptyTable.TestID = 7; m_msg.Add(m_EmptyTable.ToString()); //deletetable Test m_TResponse = m_TManager.DeleteTable("TestDatabase", "NewTestTable"); Message m_DeleteTable = new Message(); m_DeleteTable.Passed = m_TResponse.GetResponse; m_DeleteTable.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_DeleteTable.TestID = 8; m_msg.Add(m_DeleteTable.ToString()); //deletedatabase Test m_TResponse = m_TManager.DeleteDatabase("TestDatabase"); Message m_DeleteDatabase = new Message(); m_DeleteDatabase.Passed = m_TResponse.GetResponse; m_DeleteDatabase.Msg = m_TResponse.GetMessage + " for " + m_TResponse.GetId; m_DeleteDatabase.TestID = 9; m_msg.Add(m_DeleteDatabase.ToString()); ret = true; } catch(Exception ex) { throw ex; } return ret; }
public void CanCreateTable() { var tableMetadataStorageFilename = RandomFilename; var fieldMetadataStorageFilename = RandomFilename; tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename); var schema = new Schema(); schema.AddIntField("field1"); schema.AddBlobField("field2", 40); tableManager.CreateTable("table1", schema, _transaction); _transaction.Commit(); _concurrencyManager = new ConcurrencyManager(); _transaction = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager); var tableCatalogSchema = new Schema(); tableCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH); tableCatalogSchema.AddIntField("reclength"); var tableCatalogInfo = new TableInfo(tableMetadataStorageFilename, tableCatalogSchema); var tableCatalogRecordPage = new RecordFile(tableCatalogInfo, _transaction); tableCatalogRecordPage.BeforeFirst(); tableCatalogRecordPage.Next(); // skip all tables definition and all fields definition tables tableCatalogRecordPage.Next(); tableCatalogRecordPage.Next(); var tableName = tableCatalogRecordPage.GetString("tblname"); var recordLength = tableCatalogRecordPage.GetInt("reclength"); Assert.AreEqual("table1", tableName); Assert.AreEqual(new TableInfo("table1", schema).RecordLength, recordLength); var fieldCatalogSchema = new Schema(); fieldCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH); fieldCatalogSchema.AddStringField("fldname", TableManager.MAX_NAME_LENGTH); fieldCatalogSchema.AddIntField("type"); fieldCatalogSchema.AddIntField("length"); fieldCatalogSchema.AddIntField("offset"); var fieldCatalogInfo = new TableInfo(fieldMetadataStorageFilename, fieldCatalogSchema); var fieldCatalogRecordPage = new RecordFile(fieldCatalogInfo, _transaction); fieldCatalogRecordPage.BeforeFirst(); fieldCatalogRecordPage.Next(); // 2 field for table metadata table, 5 fields for field metadata table fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); fieldCatalogRecordPage.Next(); var field1Table = fieldCatalogRecordPage.GetString("tblname"); var field1Name = fieldCatalogRecordPage.GetString("fldname"); var field1Type = fieldCatalogRecordPage.GetInt("type"); var field1Length = fieldCatalogRecordPage.GetInt("length"); var field1Offset = fieldCatalogRecordPage.GetInt("offset"); Assert.AreEqual("table1", field1Table); Assert.AreEqual("field1", field1Name); Assert.AreEqual(2, field1Type); Assert.AreEqual(sizeof(int), field1Length); Assert.AreEqual(0, field1Offset); fieldCatalogRecordPage.Next(); var field2Table = fieldCatalogRecordPage.GetString("tblname"); var field2Name = fieldCatalogRecordPage.GetString("fldname"); var field2Type = fieldCatalogRecordPage.GetInt("type"); var field2Length = fieldCatalogRecordPage.GetInt("length"); var field2Offset = fieldCatalogRecordPage.GetInt("offset"); Assert.AreEqual("table1", field2Table); Assert.AreEqual("field2", field2Name); Assert.AreEqual(4, field2Type); Assert.AreEqual(40, field2Length); Assert.AreEqual(4, field2Offset); }
/// <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; } }
private void TestConstructor() { try { _logger.Message("Testing Constructor"); List <Column> cols = new List <Column>(); cols.Add(new Column(Column.DataType.Int, "Int", 100)); cols.Add(new Column(Column.DataType.Double, "Double", 1)); cols.Add(new Column(Column.DataType.Char, "String", 20)); List <Column> indices = new List <Column>(); manager.CreateTable(dbName, tableName, cols); TableManager tm = new TableManager(dbName, tableName); Assert.AreEqual(dbName, tm.table.DbName); Assert.AreEqual(tableName, tm.table.Name); Assert.AreEqual(manager.table.IndexColumns.Count, tm.table.IndexColumns.Count); Assert.AreEqual(manager.table.Columns.Count, tm.table.Columns.Count); } catch (Exception e) { _logger.Error(e.Message); } finally { manager.DropTable(dbName, tableName); } }