Exemplo n.º 1
0
        public void Save()
        {
            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName, Security.CurrentUser.UserID, DateTime.UtcNow);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            foreach (HtmlTableRow row in tblCustomFields.Rows)
            {
                if (row.Cells.Count > 1)
                {
                    HtmlTableCell cell = row.Cells[1];
                    if (cell.Controls.Count > 0)
                    {
                        ICustomField ctrl       = (ICustomField)cell.Controls[0];
                        object       FieldValue = ctrl.Value;
                        string       FieldName  = ctrl.FieldName;

                        obj[FieldName] = FieldValue;
                    }
                }
            }

            ObjectId = MetaDataWrapper.AcceptChanges(obj);
        }
        public void Save(int objectId)
        {
            obj = MetaDataWrapper.LoadMetaObject(objectId, MetaClassName);
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(objectId, MetaClassName);
            }

            if (mainTable.Controls.Count > 0)
            {
                ProcessCollection(mainTable.Controls, obj);
            }

            MetaDataWrapper.AcceptChanges(obj);
        }
        private void BindData(bool needToBind)
        {
            pageView = new PageView(false, PageViewType.Static, string.Empty, this.Page, MetaClassName);

            mc = MetaClass.Load(MetaClassName);

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            GenerateMainTable();

            LoadControls(needToBind);

            wasBound = true;
        }
        protected void btnSave_ServerClick(object sender, System.EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }


            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName, Security.CurrentUser.UserID, DateTime.UtcNow);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            foreach (HtmlTableRow row in tblCustomFields.Rows)
            {
                HtmlTableCell cell       = row.Cells[1];
                ICustomField  ctrl       = (ICustomField)cell.Controls[0];
                object        FieldValue = ctrl.Value;
                string        FieldName  = ctrl.FieldName;

                obj[FieldName] = FieldValue;
            }

            ObjectId = MetaDataWrapper.AcceptChanges(obj);

            Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(),
                                                    "<script language=javascript>" +
                                                    "try {var str=window.opener.location.href;" +
                                                    "window.opener.location.href=str;}" +
                                                    "catch (e){} window.close();</script>");
        }
Exemplo n.º 5
0
        private void BindCustomFields()
        {
            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            foreach (MetaField field in obj.MetaClass.UserMetaFields)
            {
                HtmlTableRow  row       = new HtmlTableRow();
                HtmlTableCell cellTitle = new HtmlTableCell();
                HtmlTableCell cellValue = new HtmlTableCell();

                cellTitle.Attributes.Add("class", "ibn-label");
                cellTitle.Width     = "110px";
                cellTitle.VAlign    = "middle";
                cellTitle.InnerHtml = String.Format("{0}:", field.FriendlyName);
                object fieldValue = obj[field.Name];
                System.Web.UI.UserControl control = null;

                switch (field.DataType)
                {
                case MetaDataType.Binary:
                    cellValue.InnerText = "[BinaryData]";
                    break;

                case MetaDataType.File:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FileValue.ascx");
                    break;

                case MetaDataType.ImageFile:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ImageFileValue.ascx");
                    break;

                case MetaDataType.DateTime:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    break;

                case MetaDataType.Money:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/MoneyValue.ascx");
                    break;

                case MetaDataType.Float:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FloatValue.ascx");
                    break;

                case MetaDataType.Integer:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/IntValue.ascx");
                    break;

                case MetaDataType.Boolean:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/BooleanValue.ascx");
                    break;

                case MetaDataType.Date:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    break;

                case MetaDataType.Email:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/EmailValue.ascx");
                    break;

                case MetaDataType.Url:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/URLValue.ascx");
                    break;

                case MetaDataType.ShortString:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ShortStringValue.ascx");
                    break;

                case MetaDataType.LongString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongStringValue.ascx");
                    break;

                case MetaDataType.LongHtmlString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongHTMLStringValue.ascx");
                    break;

                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionarySingleValue.ascx");
                    ((DictionarySingleValue)control).InitControl(field.Id, (field.AllowNulls ? !field.IsRequired : field.AllowNulls));
                    break;

                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionaryMultivalue.ascx");
                    ((DictionaryMultivalue)control).InitControl(field.Id);
                    break;

                default:
                    if (fieldValue != null)
                    {
                        cellValue.InnerText = fieldValue.ToString();
                    }
                    break;
                }

                if (control != null)
                {
                    cellValue.Controls.Add(control);
                }

                row.Cells.Add(cellTitle);
                row.Cells.Add(cellValue);

                tblCustomFields.Rows.Add(row);

                if (control != null)
                {
                    ICustomField iCustomField = ((ICustomField)control);
                    iCustomField.FieldName = field.Name;
                    if (fieldValue != null)
                    {
                        iCustomField.Value = fieldValue;
                    }
                    if (field.AllowNulls)
                    {
                        iCustomField.AllowEmptyValues = !field.IsRequired;
                    }
                    else
                    {
                        iCustomField.AllowEmptyValues = false;
                    }
                }
            }
        }
        private void BindCustomFields()
        {
            MetaObject obj = null;

            if (ObjectId > 0)
            {
                obj = MetaDataWrapper.LoadMetaObject(ObjectId, MetaClassName);
            }
            if (obj == null)
            {
                obj = MetaDataWrapper.NewMetaObject(ObjectId, MetaClassName);
            }

            MetaClass mc = obj.MetaClass;

            SortedList <int, MetaField> userMetaFields = new SortedList <int, MetaField>();

            foreach (MetaField field in mc.UserMetaFields)
            {
                if (ContainsMetaField(field.Name))
                {
                    int cur_weight = _mflist.IndexOf(field.Name);
                    userMetaFields.Add(cur_weight, field);
                }
            }

            foreach (MetaField field in userMetaFields.Values)
            {
                HtmlTableRow  row       = new HtmlTableRow();
                HtmlTableCell cellTitle = new HtmlTableCell();
                HtmlTableCell cellValue = new HtmlTableCell();

                cellTitle.VAlign    = "middle";
                cellTitle.InnerHtml = String.Format("<b>{0}</b>:", field.FriendlyName);
                object fieldValue = obj[field.Name];
                System.Web.UI.UserControl control = null;

                switch (field.DataType)
                {
                case MetaDataType.Binary:
                    cellValue.InnerText = "[BinaryData]";
                    break;

                case MetaDataType.File:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FileValue.ascx");
                    break;

                case MetaDataType.ImageFile:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ImageFileValue.ascx");
                    break;

                case MetaDataType.DateTime:
                    //control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    Mediachase.UI.Web.Modules.EditControls.DateTimeValue control_datetime = (Mediachase.UI.Web.Modules.EditControls.DateTimeValue)Page.LoadControl("~/Modules/EditControls/DateTimeValue.ascx");
                    control_datetime.Path_JS = "../../Scripts/";
                    control = (System.Web.UI.UserControl)control_datetime;
                    break;

                case MetaDataType.Money:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/MoneyValue.ascx");
                    break;

                case MetaDataType.Float:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/FloatValue.ascx");
                    break;

                case MetaDataType.Integer:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/IntValue.ascx");
                    break;

                case MetaDataType.Boolean:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/BooleanValue.ascx");
                    break;

                case MetaDataType.Date:
                    //control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    Mediachase.UI.Web.Modules.EditControls.DateValue control_date = (Mediachase.UI.Web.Modules.EditControls.DateValue)Page.LoadControl("~/Modules/EditControls/DateValue.ascx");
                    control_date.Path_JS = "../../Scripts/";
                    control = (System.Web.UI.UserControl)control_date;
                    break;

                case MetaDataType.Email:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/EmailValue.ascx");
                    break;

                case MetaDataType.Url:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/URLValue.ascx");
                    break;

                case MetaDataType.ShortString:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/ShortStringValue.ascx");
                    break;

                case MetaDataType.LongString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongStringValue.ascx");
                    break;

                case MetaDataType.LongHtmlString:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/LongHTMLStringValue.ascx");
                    break;

                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    control = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionarySingleValue.ascx");
                    ((DictionarySingleValue)control).InitControl(field.Id, (field.AllowNulls ? !field.IsRequired : field.AllowNulls));
                    break;

                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    cellTitle.VAlign = "top";
                    control          = (System.Web.UI.UserControl)Page.LoadControl("~/Modules/EditControls/DictionaryMultivalue.ascx");
                    ((DictionaryMultivalue)control).InitControl(field.Id);
                    break;

                default:
                    if (fieldValue != null)
                    {
                        cellValue.InnerText = fieldValue.ToString();
                    }
                    break;
                }

                if (control != null)
                {
                    cellValue.Controls.Add(control);
                }

                row.Cells.Add(cellTitle);
                row.Cells.Add(cellValue);

                tblCustomFields.Rows.Add(row);

                if (control != null)
                {
                    ICustomField iCustomField = ((ICustomField)control);
                    iCustomField.FieldName = field.Name;
                    if (fieldValue != null)
                    {
                        iCustomField.Value = fieldValue;
                    }
                    iCustomField.AllowEmptyValues = !mc.GetFieldIsRequired(field);
                }
            }
        }