Beispiel #1
0
        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));
        }
Beispiel #2
0
        private void CreateRelation(string primaryClassName, string relatedClassName, string fieldName, string fieldFriendlyName, bool allowNulls, string sectionName, string displayText, string displayOrder, MetaFormSelector mfs)
        {
            if (sectionName == notSetValue || ListManager.MetaClassIsList(primaryClassName))
            {
                sectionName  = string.Empty;
                displayText  = string.Empty;
                displayOrder = string.Empty;
            }

            MetaField newField = MetaDataWrapper.CreateReference(primaryClassName, relatedClassName, fieldName, fieldFriendlyName, allowNulls, sectionName, displayText, displayOrder);

            //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);
                }

                List <string> profiles = mfs.ListProfiles;
                foreach (string profId in profiles)
                {
                    string          placeName = "EntityList";
                    ListViewProfile profile   = ListViewProfile.Load(primaryClassName, profId, placeName);
                    if (profile != null)
                    {
                        profile.FieldSet.Add(newField.Name);
                        profile.ColumnsUI.Add(new ColumnProperties(newField.Name, "200px", String.Empty));

                        ListViewProfile.SaveSystemProfile(primaryClassName, placeName, Mediachase.Ibn.Data.Services.Security.CurrentUserId, profile);
                    }
                }
            }
        }
        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);
            }
        }
Beispiel #4
0
        /// <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;

            if (MainPlaceHolder.Controls.Count > 0)
            {
                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("IbnFramework.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(mc.Name, newField.Name))
                            {
                                continue;
                            }
                            FormController.AddMetaPrimitive(fd.MetaClassName, fd.Name, newField.Name);
                        }

                        List <string> profiles = mfs.ListProfiles;
                        foreach (string profId in profiles)
                        {
                            string          placeName = "EntityList";
                            ListViewProfile profile   = ListViewProfile.Load(mc.Name, profId, placeName);
                            if (profile != null)
                            {
                                profile.FieldSet.Add(newField.Name);
                                profile.ColumnsUI.Add(new ColumnProperties(newField.Name, "200px", String.Empty));

                                ListViewProfile.SaveSystemProfile(mc.Name, placeName, Mediachase.Ibn.Data.Services.Security.CurrentUserId, profile);
                            }
                        }

                        //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("IbnFramework.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);
            }
        }