コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            AllowNullsCheckBox.Text = " " + GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "AllowNulls").ToString();
            ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btnUpdate);
            lblNotEmptyName.Style.Add("display", "none");
            if (!Page.IsPostBack)
            {
                ViewState["_keyLIP"] = Request["key"];
                if (Request["field"] != null)
                {
                    ViewState["_field"] = Request["field"];
                }
                else
                {
                    ViewState["_field"] = null;
                }

                ViewState[currentControlKey] = null;

                //lip = (ListImportParameters)CHelper.GetFromContext(ViewState["_keyLIP"].ToString());
                //if(lip == null)
                lip = (ListImportParameters)Session[ViewState["_keyLIP"].ToString()];
                if (lip != null)
                {
                    BindData();

                    if (!AutogenerateSystemNames)
                    {
                        Page.SetFocus(NameTextBox);
                    }
                    else
                    {
                        Page.SetFocus(FriendlyNameTextBox);
                    }
                }
            }
        }
コード例 #2
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;
            }

            if (ViewState["_keyLIP"] != null)
            {
                //lip = (ListImportParameters)CHelper.GetFromContext(ViewState["_keyLIP"].ToString());
                //if (lip == null)
                lip = (ListImportParameters)Session[ViewState["_keyLIP"].ToString()];
                if (lip != null)
                {
                    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)
                    {
                        if (attr.ContainsKey("NewEnum") || attr.ContainsKey("NewMultiEnum"))
                        {
                            sDefaultValue = "1";
                        }

                        ErrorMessage.Text = GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "ErrorMessage_AllowNulls").ToString();
                        return;
                    }

                    if (sDefaultValue == null)
                    {
                        sDefaultValue = String.Empty;
                    }

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

                    string sFriendlyName = FriendlyNameTextBox.Text.Trim();
                    if (String.IsNullOrEmpty(sFriendlyName))
                    {
                        sFriendlyName = sName;
                    }

                    try
                    {
                        string typeName = FormatList.SelectedValue;
                        if (attr.ContainsKey("NewEnum"))
                        {
                            string name         = attr["EnumName"].ToString();
                            string friendlyname = attr["EnumFriendlyName"].ToString();
                            bool   isPrivate    = (bool)attr["EnumPrivate"];

                            attr.Remove("NewEnum");
                            attr.Remove("EnumName");
                            attr.Remove("EnumFriendlyName");
                            attr.Remove("EnumPrivate");

                            NewEnumInfo nei = new NewEnumInfo();
                            nei.Name           = name;
                            nei.FriendlyName   = friendlyname;
                            nei.MultipleValues = false;
                            nei.IsPrivate      = isPrivate;
                            lip.NewEnumTypes.Add(nei);

                            typeName = name;
                        }
                        //NewMultiEnum
                        if (attr.ContainsKey("NewMultiEnum"))
                        {
                            string name         = attr["EnumName"].ToString();
                            string friendlyname = attr["EnumFriendlyName"].ToString();
                            bool   isPrivate    = (bool)attr["EnumPrivate"];

                            attr.Remove("NewMultiEnum");
                            attr.Remove("EnumName");
                            attr.Remove("EnumFriendlyName");
                            attr.Remove("EnumPrivate");

                            NewEnumInfo nei = new NewEnumInfo();
                            nei.Name           = name;
                            nei.FriendlyName   = friendlyname;
                            nei.MultipleValues = true;
                            nei.IsPrivate      = isPrivate;
                            lip.NewEnumTypes.Add(nei);

                            typeName = 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");
                        }

                        MappingRule mr = null;
                        if (ViewState["_field"] != null)
                        {
                            mr = lip.GetRuleByMetaField(ViewState["_field"].ToString());
                            lip.RemoveNewMetaField(ViewState["_field"].ToString());
                        }

                        lip.AddNewMetaField(sName, sFriendlyName, typeName, AllowNullsCheckBox.Checked, sDefaultValue, attr);
                        if (mr != null)
                        {
                            mr.FieldName = sName;
                        }
                        Session[ViewState["_keyLIP"].ToString()] = lip;
                        CommandParameters cp = new CommandParameters(_commandName);
                        Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
                        //CHelper.AddToContext("NeedToChangeDataSource", true);
                    }
                    catch (MetaFieldAlreadyExistsException)
                    {
                    }

                    //NameTextBox.Text = String.Empty;
                    //FriendlyNameTextBox.Text = String.Empty;
                }
            }
        }