Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private void CreateMetaField(MetaClass metaClass, string metaFieldName, string metaFieldFriendlyName, string type)
 {
     if (metaClass.Fields[metaFieldName] == null)
     {
         metaClass.CreateMetaField(metaFieldName, metaFieldFriendlyName, type, true, "", new AttributeCollection());
         FormController.AddMetaPrimitive(metaClass.Name, Constants.Forms.EditForm, metaFieldName);
         FormController.AddMetaPrimitive(metaClass.Name, Constants.Forms.ShortInfoForm, metaFieldName);
         FormController.AddMetaPrimitive(metaClass.Name, Constants.Forms.ViewForm, metaFieldName);
     }
 }
Ejemplo n.º 3
0
        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();
            }
        }