protected override void PostCreateInsideTransaction(BusinessContext context) { // Call Base method base.PostCreateInsideTransaction(context); #region Create a new Document Card PrimaryKeyId pkDocumentType = ((CreateResponse)context.Response).PrimaryKeyId; // Create a new Document Card using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { // TODO: Check Card Name string cardName = context.Request.Target["Name"].ToString(); string cardFriendlyName = context.Request.Target["FriendlyName"].ToString(); string cardPluralName = cardFriendlyName; string tableName = "cls_Document_" + context.Request.Target["Name"].ToString(); MetaClass newCard = DataContext.Current.MetaModel.CreateCardMetaClass(DataContext.Current.GetMetaClass(DocumentEntity.GetAssignedMetaClassName()), cardName, cardFriendlyName, cardPluralName, tableName); scope.SaveChanges(); } #endregion }
/// <summary> /// Handles the ServerClick event of the imbtnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void imbtnSave_ServerClick(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } if (TypeName == string.Empty) { string typeName = String.Empty; using (MetaClassManagerEditScope editScope = DataContext.Current.MetaModel.BeginEdit()) { DataTable dt = (DataTable)ViewState["DT_Source"]; List <MultiReferenceItem> mas = new List <MultiReferenceItem>(); foreach (DataRow dr in dt.Rows) { mas.Add(new MultiReferenceItem(dr["Name"].ToString(), dr["Name"].ToString(), dr["FriendlyName"].ToString())); } MetaFieldType type = MultiReferenceType.Create(txtMRTName.Text, txtFriendlyName.Text, mas.ToArray()); typeName = type.Name; editScope.SaveChanges(); } //if (typeName != String.Empty) // Response.Redirect(String.Format("~/Apps/MetaDataBase/Pages/Admin/MultiReferenceTypeView.aspx?type={0}", typeName)); //else Response.Redirect("~/Apps/MetaDataBase/Pages/Admin/MultiReferenceTypeList.aspx"); } else { MetaFieldType type = MetaDataWrapper.GetTypeByName(TypeName); type.FriendlyName = txtFriendlyName.Text; Response.Redirect(String.Format("~/Apps/MetaDataBase/Pages/Admin/MultiReferenceTypeView.aspx?type={0}", TypeName)); } }
static void TestCreateFields() { DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;"); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass mc = DataContext.Current.GetMetaClass(WorkflowDefinitionEntity.ClassName); // Create Enum MetaFieldType enumType = MetaEnum.Create("SupportedIbnObjectType", "Supported Ibn Object Type", true); MetaEnum.AddItem(enumType, 16, "Document", 1); MetaEnum.AddItem(enumType, 5, "Task", 2); MetaEnum.AddItem(enumType, 6, "Todo", 3); MetaEnum.AddItem(enumType, 7, "Incident", 4); // Create Project Field using (MetaFieldBuilder bulder = new MetaFieldBuilder(mc)) { bulder.CreateReference("Project", "Project", true, "Project", true); bulder.CreateEnumField("SupportedIbnObjectTypes", "Supported Ibn Object Types", "SupportedIbnObjectType", true, "16", false); bulder.SaveChanges(); } scope.SaveChanges(); } }
static void CreateMetaField2009_06_03() { using (DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;")) { MetaClass workflowClass = DataContext.Current.GetMetaClass(WorkflowDefinitionEntity.ClassName); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { workflowClass.DeleteMetaField("PlanDuration"); using (MetaFieldBuilder mfb = new MetaFieldBuilder(workflowClass)) { //PlanFinishDate: DateTime mfb.CreateDateTime("PlanFinishDate", "Plan Finish Date", true, true); //PlanDuration: Duration mfb.CreateDuration("PlanDuration", "Plan Duration", true, 60); //PlanFinishTimeType: Enum (None, DateTime, Duration) mfb.CreateEnumField("PlanFinishTimeType", "Plan Finish Time Type", "TimeType", false, "1", false); mfb.SaveChanges(); } scope.SaveChanges(); } } }
internal static void CreateCustomPageMetaClass() { DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;"); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass googleGadget = DataContext.Current.MetaModel.CreateMetaClass("CustomPage", "Custom Page", "Custom Pages", "cls_CustomPage", PrimaryKeyId.ValueType.Guid); using (MetaFieldBuilder builder = new MetaFieldBuilder(googleGadget)) { builder.CreateText("Title", "Title", false, 255, false); builder.CreateLongText("Description", "Description", true); builder.CreateFile("Icon", "Icon", true, string.Empty); builder.CreateLongText("JsonData", "Json Data", false); builder.CreateGuid("TemplateId", "Template Id", false); builder.CreateGuid("Uid", "Uid", false); builder.CreateReference("Profile", "Profile", true, CustomizationProfileEntity.ClassName, true); builder.CreateReference("User", "User", true, "Principal", true); builder.SaveChanges(); } googleGadget.TitleFieldName = "Title"; BusinessObjectServiceManager.InstallService(googleGadget, ChangeDetectionService.ServiceName); scope.SaveChanges(); } }
internal static void CreateGoogleGadgetMetaClass() { DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;"); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass googleGadget = DataContext.Current.MetaModel.CreateMetaClass("GoogleGadget", "Google Gadget", "Google Gadgets", "cls_GoogleGadget", PrimaryKeyId.ValueType.Guid); using (MetaFieldBuilder builder = new MetaFieldBuilder(googleGadget)) { builder.CreateText("Title", "Title", false, 255, false); builder.CreateLongText("Description", "Description", true); builder.CreateUrl("Link", "Link", false, 1024, false, string.Empty); builder.SaveChanges(); } googleGadget.TitleFieldName = "Title"; BusinessObjectServiceManager.InstallService(googleGadget, ChangeDetectionService.ServiceName); scope.SaveChanges(); } }
protected override void PreDeleteInsideTransaction(BusinessContext context) { // Call Base method base.PreDeleteInsideTransaction(context); #region Load Document Type // Load Document Type DocumentTypeEntity docType = (DocumentTypeEntity)BusinessManager.Load(DocumentTypeEntity.GetAssignedMetaClassName(), context.GetTargetPrimaryKeyId().Value); if (docType != null) { // Read Card Name string cardName = docType.Name; // Delete meta class using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { DataContext.Current.MetaModel.DeleteMetaClass(cardName); scope.SaveChanges(); } } #endregion }
protected void imbtnSave_ServerClick(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } if (ddOwnerFields.SelectedItem == null) { return; } using (MetaClassManagerEditScope editScope = DataContext.Current.MetaModel.BeginEdit()) { MetaField newLinkField = _mf; MetaField field = _mc.Fields[ddOwnerFields.SelectedValue]; if (newLinkField != null) { newLinkField.LinkInformation.AssignedMetaClassList.Clear(); newLinkField.LinkInformation.MappingList.Clear(); newLinkField.FriendlyName = txtFriendlyName.Text; } string sValues = hidField.Value; string[] mas = sValues.Split(';'); if (mas.Length > 0) { for (int i = 0; i < mas.Length; i++) { string sValue = mas[i]; if (sValue.Length > 0) { string[] mas_in = sValue.Split(':'); string sClass = mas_in[0]; string sField = mas_in[1]; if (newLinkField == null) { newLinkField = _mc.CreateMetaField(field.Name + "Link", field.FriendlyName + " Link", "Link", new Mediachase.Ibn.Data.Meta.Management.AttributeCollection()); newLinkField.LinkInformation.LinkedFieldReadonly = true; newLinkField.LinkInformation.TitleIndex = 0; newLinkField.LinkInformation.LinkedFieldList.Add(field.Name); } newLinkField.LinkInformation.AssignedMetaClassList.Add(sClass); newLinkField.LinkInformation.MappingList.Add(new MetaFieldMapping( DataContext.Current.MetaModel.MetaClasses[sClass].Fields[sField] , field)); } } } editScope.SaveChanges(); } Response.Redirect(String.Format(CultureInfo.InvariantCulture, "{0}?class={1}", CHelper.MetaClassAdminPage, _mc.Name), true); }
static void CreateMetaField2009_06_03() { using (DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;")) { MetaClass workflowClass = DataContext.Current.GetMetaClass(WorkflowInstanceEntity.ClassName); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { // WorkflowInstanceTimeStatus MetaFieldType workflowInstanceTimeStatus = MetaEnum.Create("WorkflowInstanceTimeStatus", "Workflow Instance Time Status", false); MetaEnum.AddItem(workflowInstanceTimeStatus, "OverStart", 1); MetaEnum.AddItem(workflowInstanceTimeStatus, "OverDue", 2); // FinishTimeType MetaFieldType timeType = MetaEnum.Create("TimeType", "Time Type", false); MetaEnum.AddItem(timeType, "NotSet", 1); MetaEnum.AddItem(timeType, "DateTime", 2); MetaEnum.AddItem(timeType, "Duration", 3); using (MetaFieldBuilder mfb = new MetaFieldBuilder(workflowClass)) { //ActualStartDate: DateTime mfb.CreateDateTime("ActualStartDate", "Actual Start Date", true, true); //ActualFinishDate: DateTime mfb.CreateDateTime("ActualFinishDate", "Actual Finish Date", true, true); //TimeStatus: DateTime mfb.CreateEnumField("TimeStatus", "Time Status", "WorkflowInstanceTimeStatus", true, "", false); //PlanFinishDate: DateTime mfb.CreateDateTime("PlanFinishDate", "Plan Finish Date", true, true); //PlanDuration: Duration mfb.CreateDuration("PlanDuration", "Plan Duration", true, 60); //PlanFinishTimeType: Enum (None, DateTime, Duration) mfb.CreateEnumField("PlanFinishTimeType", "Plan Finish Time Type", "TimeType", false, "1", false); mfb.SaveChanges(); } scope.SaveChanges(); } } }
/// <summary> /// Handles the Click event of the SaveButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param> protected void SaveButton_Click(object sender, ImageClickEventArgs e) { using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { mc.TitleFieldName = FieldsList.SelectedValue; scope.SaveChanges(); } DefaultFieldButton.Visible = true; FieldsList.Visible = false; SaveButton.Visible = false; CancelButton.Visible = false; CHelper.RequireDataBind(); }
public ActionResult CreateClubCardClass() { var viewModel = new BisFoundViewModel(); using (MetaClassManagerEditScope metaEdit = DataContext.Current.MetaModel.BeginEdit()) { MetaClass clubCard = DataContext.Current.MetaModel.CreateMetaClass("ClubCard", "Club Card", "ClubCards", "demoClub_Cards", PrimaryKeyIdValueType.Integer); clubCard.AccessLevel = AccessLevel.Customization; metaEdit.SaveChanges(); } MetaFieldType cardEnum = DataContext.Current.MetaModel.RegisteredTypes["CardType"]; if (cardEnum == null) { using (MetaClassManagerEditScope metaEdit = DataContext.Current.MetaModel.BeginEdit()) { cardEnum = MetaEnum.Create("CardType", "Club Card Type", false); cardEnum.AccessLevel = AccessLevel.Customization; metaEdit.SaveChanges(); MetaEnum.AddItem(cardEnum, "Gold", 1); MetaEnum.AddItem(cardEnum, "Silver", 2); MetaEnum.AddItem(cardEnum, "Bronze", 3); } } using (MetaFieldBuilder fieldBuilder = new MetaFieldBuilder(DataContext.Current.GetMetaClass("ClubCard"))) { MetaField titleField = fieldBuilder.CreateText("TitleField", "Title Field", false, 100, false); fieldBuilder.MetaClass.TitleFieldName = titleField.Name; fieldBuilder.CreateText("CardOwnerName", "Card Owner Name", false, 100, false); fieldBuilder.CreateEmail("Email", "Email", false, 100, true); fieldBuilder.CreateInteger("Balance", "Balance", true, 0); var mf = fieldBuilder.CreateEnumField("CardTypeEnum", "Card Type", cardEnum.Name, true, String.Empty, true); mf.AccessLevel = AccessLevel.Customization; fieldBuilder.SaveChanges(); MetaDataWrapper.CreateReference("Contact", "ClubCard", "ContactRef", "Contact References", false, "InfoBlock", "ClubCard", "10"); } FillModel(viewModel); return(View("Index", viewModel)); }
public static void AddStateFriendlyNameMetaFieldToAllMetaView() { using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass(); MetaField mf = timeTrackingEntry.Fields["StateFriendlyName"]; foreach (MetaView mv in DataContext.Current.MetaModel.MetaViews.GetByMetaClass(timeTrackingEntry)) { mv.AvailableFields.Add(mf); } scope.SaveChanges(); } }
static void CreatePropertyJsonDataField() { DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;"); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass metaClass = DataContext.Current.GetMetaClass(CustomPageEntity.ClassName); using (MetaFieldBuilder builder = new MetaFieldBuilder(metaClass)) { builder.CreateLongText("PropertyJsonData", "Property Json Data", true); builder.SaveChanges(); } scope.SaveChanges(); } }
private static void CreateMetaField() { DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;"); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass metaClass = DataContext.Current.GetMetaClass(AssignmentEntity.ClassName); using (MetaFieldBuilder builder = new MetaFieldBuilder(metaClass)) { builder.CreateInteger("ClosedBy", "Closed By", true, 0); builder.SaveChanges(); } scope.SaveChanges(); } }
static void CreateMetaField2009_06_05() { using (DataContext.Current = new DataContext("Data source=S2;Initial catalog=ibn48portal;Integrated Security=SSPI;")) { MetaClass workflowClass = DataContext.Current.GetMetaClass(WorkflowDefinitionEntity.ClassName); using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { using (MetaFieldBuilder mfb = new MetaFieldBuilder(workflowClass)) { mfb.CreateLongText("XSParameters", "Xml Serialized Parameters", true); mfb.SaveChanges(); } scope.SaveChanges(); } } }
private void CreateRelation(string primaryClassName, string relatedClassName) { MetaClass relatedMetaClass = DataContext.Current.GetMetaClass(relatedClassName); MetaClass primaryMetaClass = DataContext.Current.GetMetaClass(primaryClassName); if (relatedMetaClass.Fields[MetaClassManager.GetPrimaryKeyName(primaryClassName)] != null) { return; } using (MetaClassManagerEditScope managerEditScope = DataContext.Current.MetaModel.BeginEdit()) { var metaField = relatedMetaClass.CreateReference(primaryMetaClass, primaryClassName, primaryClassName, true); metaField.AccessLevel = AccessLevel.Customization; metaField.Attributes.Add(Constants.Attributes.DisplayBlock, Constants.SectionName); metaField.Attributes.Add(Constants.Attributes.DisplayText, relatedClassName); metaField.Attributes.Add(Constants.Attributes.DisplayOrder, Constants.DefaultDisplayOrder); XmlBuilder.ClearCache(); managerEditScope.SaveChanges(); } }
public static void CreateStateFriendlyNameMetaField() { using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass(); AttributeCollection attr = new AttributeCollection(); attr.Add(McDataTypeAttribute.StringMaxLength, 255); attr.Add(McDataTypeAttribute.StringIsUnique, false); attr.Add(McDataTypeAttribute.Expression, @"SELECT TOP 1 TTBS.FriendlyName FROM cls_TimeTrackingBlock_State TTBS" + Environment.NewLine + @" JOIN cls_TimeTrackingBlock TTB ON " + Environment.NewLine + @" TTB.mc_StateId = TTBS.TimeTrackingBlock_StateId" + Environment.NewLine + @" AND" + Environment.NewLine + @" TTB.[TimeTrackingBlockId] = AAA.[ParentBlockId]"); MetaField retVal = timeTrackingEntry.CreateMetaField("StateFriendlyName", "State", MetaFieldType.Text, true, "''", attr); scope.SaveChanges(); } }
protected void grdMain_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName == "NewItem") { DataTable dt = GetDataTable(); DataRow dr = dt.NewRow(); dr["Id"] = -1; dr["OrderId"] = dt.Rows.Count + 1; dr["Name"] = ""; dr["DisplayName"] = ""; dr["IsDefault"] = false; dt.Rows.Add(dr); grdMain.EditItemIndex = dt.Rows.Count - 1; BindGrid(dt); } if (e.CommandName == "Asc") { MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[ViewState[this.ClientID + "_TypeName"].ToString()]; if (mft == null) { DataTable dt = ((DataTable)ViewState[this.ClientID + "_DataSource"]).Copy(); DataView dv = dt.DefaultView; dv.Sort = "Name"; for (int i = 0; i < dv.Count; i++) { dv[i]["OrderId"] = i + 1; } ViewState[this.ClientID + "_DataSource"] = dt; } else { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Id", typeof(int))); dt.Columns.Add(new DataColumn("OrderId", typeof(int))); dt.Columns.Add(new DataColumn("Name", typeof(string))); DataRow dr; foreach (MetaEnumItem item in MetaEnum.GetItems(mft)) { dr = dt.NewRow(); dr["Id"] = item.Handle; dr["OrderId"] = item.OrderId; dr["Name"] = item.Name; dt.Rows.Add(dr); } DataView dv = dt.DefaultView; dv.Sort = "Name"; using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { for (int i = 0; i < dv.Count; i++) { MetaEnum.UpdateItem(mft, (int)dv[i]["Id"], dv[i]["Name"].ToString(), i + 1); } scope.SaveChanges(); } } BindGrid(GetDataTable()); } if (e.CommandName == "Desc") { MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[ViewState[this.ClientID + "_TypeName"].ToString()]; if (mft == null) { DataTable dt = ((DataTable)ViewState[this.ClientID + "_DataSource"]).Copy(); DataView dv = dt.DefaultView; dv.Sort = "Name DESC"; for (int i = 0; i < dv.Count; i++) { dv[i]["OrderId"] = i + 1; } ViewState[this.ClientID + "_DataSource"] = dt; } else { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Id", typeof(int))); dt.Columns.Add(new DataColumn("OrderId", typeof(int))); dt.Columns.Add(new DataColumn("Name", typeof(string))); DataRow dr; foreach (MetaEnumItem item in MetaEnum.GetItems(mft)) { dr = dt.NewRow(); dr["Id"] = item.Handle; dr["OrderId"] = item.OrderId; dr["Name"] = item.Name; dt.Rows.Add(dr); } DataView dv = dt.DefaultView; dv.Sort = "Name DESC"; using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { for (int i = 0; i < dv.Count; i++) { MetaEnum.UpdateItem(mft, (int)dv[i]["Id"], dv[i]["Name"].ToString(), i + 1); } scope.SaveChanges(); } } BindGrid(GetDataTable()); } }
/// <summary> /// Handles the ServerClick event of the SaveButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveButton_ServerClick(object sender, EventArgs e) { if (FormatList.Items.Count < 0) { throw new Exception("Format is not specified"); } Page.Validate(); if (!Page.IsValid) { return; } Mediachase.Ibn.Data.Meta.Management.AttributeCollection attr = new Mediachase.Ibn.Data.Meta.Management.AttributeCollection(); string sDefaultValue = String.Empty; IManageControl control = MainPlaceHolder.Controls[0] as IManageControl; if (control != null) { sDefaultValue = control.GetDefaultValue(AllowNullsCheckBox.Checked); attr = control.FieldAttributes; } if (!AllowNullsCheckBox.Checked && sDefaultValue == String.Empty) { ErrorMessage.Text = GetGlobalResourceObject("GlobalMetaInfo", "ErrorMessage_AllowNulls").ToString(); return; } if (sDefaultValue == null) { sDefaultValue = String.Empty; } string sFriendlyName = FriendlyNameTextBox.Text.Trim(); if (mf == null) { string sName; if (!AutogenerateSystemNames) { sName = NameTextBox.Text.Trim(); } else { // Generate the field name as the number of seconds elapsed since 2000-01-01 sName = String.Format(CultureInfo.InvariantCulture, "Field{0}", CHelper.GetDateDiffInSeconds(DateTime.UtcNow, new DateTime(2000, 1, 1))); } try { string typeName = FormatList.SelectedValue; //NewEnum if (attr.ContainsKey("NewEnum")) { string name = attr["EnumName"].ToString(); string friendlyname = attr["EnumFriendlyName"].ToString(); bool isPrivate = (bool)attr["EnumPrivate"]; DataTable dt = (DataTable)attr["EnumDataSource"]; attr.Remove("NewEnum"); attr.Remove("EnumName"); attr.Remove("EnumFriendlyName"); attr.Remove("EnumPrivate"); attr.Remove("EnumDataSource"); MetaFieldType type = MetaEnum.Create(name, friendlyname, false); if (isPrivate) { type.Attributes.Add(McDataTypeAttribute.EnumPrivate, mc.Name); } SortedList sl = new SortedList(); foreach (DataRow dr in dt.Rows) { sl.Add((int)dr["OrderId"], dr["Name"].ToString().Trim()); } foreach (int i in sl.Keys) { MetaEnum.AddItem(type, sl[i].ToString(), i); } typeName = type.Name; } //NewMultiEnum if (attr.ContainsKey("NewMultiEnum")) { string name = attr["EnumName"].ToString(); string friendlyname = attr["EnumFriendlyName"].ToString(); bool isPrivate = (bool)attr["EnumPrivate"]; DataTable dt = (DataTable)attr["EnumDataSource"]; attr.Remove("NewMultiEnum"); attr.Remove("EnumName"); attr.Remove("EnumFriendlyName"); attr.Remove("EnumPrivate"); attr.Remove("EnumDataSource"); MetaFieldType type = MetaEnum.Create(name, friendlyname, true); if (isPrivate) { type.Attributes.Add(McDataTypeAttribute.EnumPrivate, mc.Name); } SortedList sl = new SortedList(); foreach (DataRow dr in dt.Rows) { sl.Add((int)dr["OrderId"], dr["Name"].ToString().Trim()); } foreach (int i in sl.Keys) { MetaEnum.AddItem(type, sl[i].ToString(), i); } typeName = type.Name; } MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[FormatList.SelectedValue]; if (mft != null && mft.McDataType == McDataType.Enum && attr.ContainsKey("EnumFriendlyName")) { mft.FriendlyName = attr["EnumFriendlyName"].ToString(); attr.Remove("EnumFriendlyName"); } MetaField newField = null; if (FieldTypeList.SelectedValue == McDataType.Reference.ToString()) { newField = MetaDataWrapper.CreateReference(mc, attr, sName, sFriendlyName, AllowNullsCheckBox.Checked); if (attr.ContainsKey(McDataTypeAttribute.ReferenceUseSecurity)) { Mediachase.Ibn.Data.Services.Security.AddObjectRolesFromReference(newField); } } else if (FieldTypeList.SelectedValue == McDataType.ReferencedField.ToString()) { newField = MetaDataWrapper.CreateReferencedField(mc, attr, sName, sFriendlyName); } else if (FieldTypeList.SelectedValue == McDataType.BackReference.ToString()) { newField = MetaDataWrapper.CreateBackReference(mc, attr, sName, sFriendlyName); } else { newField = MetaDataWrapper.CreateMetaField(mc, attr, sName, sFriendlyName, typeName, AllowNullsCheckBox.Checked, sDefaultValue); } //add to the forms if (newField != null) { List <FormDocument> metaForms = mfs.MetaForms; foreach (FormDocument fd in metaForms) { if (HistoryManager.MetaClassIsHistory(fd.MetaClassName) && !HistoryManager.IsSupportedField(fd.MetaClassName, newField.Name)) { continue; } FormController.AddMetaPrimitive(fd.MetaClassName, fd.Name, newField.Name); } using (MetaClassManagerEditScope editScope = DataContext.Current.MetaModel.BeginEdit()) { List <string> metaViews = mfs.MetaViews; foreach (string viewName in metaViews) { MetaView metaView = DataContext.Current.MetaModel.MetaViews[viewName]; if (HistoryManager.MetaClassIsHistory(metaView.MetaClassName) && !HistoryManager.IsSupportedField(metaView.MetaClassName, newField.Name)) { continue; } McMetaViewPreference pref = UserMetaViewPreference.Load(metaView, (int)DataContext.Current.CurrentUserId); if (pref == null || pref.Attributes.Count == 0) { McMetaViewPreference.CreateDefaultUserPreference(metaView); pref = UserMetaViewPreference.Load(metaView, (int)DataContext.Current.CurrentUserId); } int counter = metaView.AvailableFields.Count; metaView.AvailableFields.Add(metaView.MetaClass.Fields[newField.Name]); pref.SetAttribute <int>(newField.Name, McMetaViewPreference.AttrIndex, counter); pref.SetAttribute <int>(newField.Name, McMetaViewPreference.AttrWidth, 100); } editScope.SaveChanges(); } } Response.Redirect(String.Format("{0}?class={1}", ReturnUrl, mc.Name), true); } catch (MetaFieldAlreadyExistsException) { ErrorLabel.Text = String.Format(GetGlobalResourceObject("GlobalMetaInfo", "FieldExistsErrorMessage").ToString(), "'" + sName + "'"); ErrorLabel.Visible = true; } /* catch (SqlException sqlException) * { * if (sqlException.Number == 1505) // Duplication key * ErrorLabel.Text = ex.Message; * else * ErrorLabel.Text = ex.Message; * ErrorLabel.Visible = true; * } */ } else // Update { MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[FormatList.SelectedValue]; if (mft.McDataType == McDataType.Enum && attr.ContainsKey("EnumFriendlyName")) { mft.FriendlyName = attr["EnumFriendlyName"].ToString(); attr.Remove("EnumFriendlyName"); } if (FieldTypeList.SelectedValue == McDataType.Reference.ToString() || FieldTypeList.SelectedValue == McDataType.BackReference.ToString() || FieldTypeList.SelectedValue == McDataType.ReferencedField.ToString()) { MetaDataWrapper.UpdateMetaFieldFriendlyName(mf, sFriendlyName); } else { MetaDataWrapper.UpdateMetaField(mf, attr, sFriendlyName, sDefaultValue); } Response.Redirect(String.Format("{0}?class={1}", ReturnUrl, mc.Name), true); } }
protected void btnSave_Click(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } using (MetaClassManagerEditScope editScope = DataContext.Current.MetaModel.BeginEdit()) { Trigger trigger; if (TriggerName != String.Empty) { trigger = TriggerManager.GetTrigger(ClassName, TriggerName); } else { trigger = new Trigger(); trigger.Name = txtName.Text.Trim(); } trigger.ActionName = ddlAction.SelectedValue; trigger.ConditionName = ddlCondition.SelectedValue; trigger.Create = chkInsert.Checked; trigger.Delete = chkDelete.Checked; trigger.Update = chkUpdate.Checked; trigger.Description = txtDescription.Text; List <string> conditionInParameters = new List <string>(); for (int i = 0; i < tblCondition.Rows.Count; i++) { TextBox txt = (TextBox)tblCondition.Rows[i].Cells[1].Controls[0]; conditionInParameters.Add(txt.Text.Trim()); } trigger.ConditionInParameters = conditionInParameters; List <string> actionInParameters = new List <string>(); for (int i = 0; i < tblAction.Rows.Count; i++) { TextBox txt = (TextBox)tblAction.Rows[i].Cells[1].Controls[0]; actionInParameters.Add(txt.Text.Trim()); } trigger.ActionInParameters = actionInParameters; if (TriggerName == String.Empty) { TriggerManager.AddTrigger(ClassName, trigger); } editScope.SaveChanges(); } // Closing window if (RefreshButton == String.Empty) { CHelper.CloseItAndRefresh(Response); } else // Dialog Mode { CHelper.CloseItAndRefresh(Response, RefreshButton); } }
public void CreateBusinessFoundation() { var clubCard = DataContext.Current.GetMetaClass("ClubCard"); if (clubCard == null) { using (MetaClassManagerEditScope metaEdit = DataContext.Current.MetaModel.BeginEdit()) { clubCard = DataContext.Current .MetaModel .CreateMetaClass("ClubCard", "Club Card", "ClubCards", "demoClub_Cards", PrimaryKeyIdValueType.Integer); clubCard.AccessLevel = AccessLevel.Customization; metaEdit.SaveChanges(); } } MetaFieldType cardEnum = DataContext.Current.MetaModel.RegisteredTypes["CardType"]; if (cardEnum == null) { using (MetaClassManagerEditScope metaEdit = DataContext.Current.MetaModel.BeginEdit()) { cardEnum = MetaEnum.Create("CardType", "Club Card Type", false); cardEnum.AccessLevel = AccessLevel.Customization; metaEdit.SaveChanges(); MetaEnum.AddItem(cardEnum, "Gold", 1); MetaEnum.AddItem(cardEnum, "Silver", 2); MetaEnum.AddItem(cardEnum, "Bronze", 3); } } using (MetaFieldBuilder fieldBuilder = new MetaFieldBuilder(DataContext.Current.GetMetaClass("ClubCard"))) { MetaField titleField = fieldBuilder.CreateText("TitleField", "Title Field", false, 100, false); fieldBuilder.MetaClass.TitleFieldName = titleField.Name; fieldBuilder.CreateText("CardOwnerName", "Card Owner Name", false, 100, false); fieldBuilder.CreateEmail("Email", "Email", false, 100, true); fieldBuilder.CreateInteger("Balance", "Balance", true, 0); var mf = fieldBuilder.CreateEnumField("CardTypeEnum", "Card Type", cardEnum.Name, true, string.Empty, true); mf.AccessLevel = AccessLevel.Customization; fieldBuilder.SaveChanges(); MetaDataWrapper.CreateReference("Contact", "ClubCard", "ContactRef", "Contact Reference", false, "InfoBlock", "ClubCard", "10"); } //set data EntityObject cardObjSet = true ? BusinessManager.InitializeEntity("ClubCard") : BusinessManager.Load("ClubCard", 12); cardObjSet["TitleField"] = "test"; if (true) { BusinessManager.Create(cardObjSet); } else { BusinessManager.Update(cardObjSet); } //get data EntityObject cardObj = BusinessManager.Load("ClubCartd", 12); var test = (string)cardObj["TitleField"]; //delete DataContext.Current.MetaModel.DeleteMetaClass("ClubCard"); MetaFieldType cardEnumDelete = DataContext.Current.MetaModel.RegisteredTypes["CardType"]; if (cardEnumDelete != null && !MetaEnum.IsUsed(cardEnum)) { MetaEnum.Remove(cardEnumDelete); } }