Esempio n. 1
0
 public override void ValidateUrl()
 {
     base.ValidateUrl();
     short _typeID = 0;
     switch (Request.GroupString["type"]) {
         case "add":
             _typeID = Convert.ToInt16(Request.GroupString["id"]);
             break;
         case "edit":
             long _entityID = Convert.ToInt64(Request.GroupString["id"]);
             XiaoYang.Entity.EntityBase _base = XiaoYang.Entity.EntityBase.GetInstance(_entityID);
             if (_base == null) throw new Exception("can not found entity");
             _typeID = _base.TypeID;
             XiaoYang.Entity.EntityHelper _helper = new Entity.EntityHelper(_base.TypeID);
             XiaoYang.Entity.Entity _entity = new Entity.EntityCollection(_helper.Get(_entityID), _base.TypeID)[0];
             PageData.AddXyDataModel("Entity", _entity);
             break;
     }
     System.Data.DataTable _typeChain = Entity.EntityType.Get(_typeID);
     if (_typeChain.Rows.Count == 0) throw new Exception("can not found entity type");
     Entity.EntityType _type = new Entity.EntityType();
     _type.Fill(_typeChain.Rows[0]);
     while (_type.ParentTypeID > 0) {
         _type = Entity.EntityType.GetInstance(_type.ParentTypeID);
         System.Data.DataRow _newRow = _typeChain.NewRow();
         foreach (string _columnName in _type.GetAttributesName()) {
             _newRow[_columnName] = _type.GetAttributesValue(_columnName);
         }
         _typeChain.Rows.Add(_newRow);
     }
     _typeChain.DefaultView.Sort = "ID ASC";
     _typeChain = _typeChain.DefaultView.ToTable();
     PageData.AddXyDataModel("Type", _type);
     PageData.Add("TypeChain", _typeChain);
 }
Esempio n. 2
0
        public override void onGetRequest()
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"])) {
                PageData.AddXyDataModel("Item", XiaoYang.Entity.EntityAttributeDisplay.GetInstance(Request.QueryString));
            }
            if (!string.IsNullOrEmpty(Request.Values["TypeID"])) {
                long _entityID = Convert.ToInt64(Request.Values["EntityID"]);
                short _typeID = Convert.ToInt16(Request.Values["TypeID"]);
                XiaoYang.Entity.EntityType _typeInstance = XiaoYang.Entity.EntityType.GetInstance(_typeID);
                string _typeName = _typeInstance.Key;
                System.Data.DataTable _attributesTable = XiaoYang.Entity.EntityAttribute.GetByTypeID(_typeID);
                System.Data.DataTable _entity_ext = null;
                if (_entityID > 0) {
                    XiaoYang.Entity.EntityHelper _entity = new Entity.EntityHelper(_typeID);
                    _entity_ext = _entity.Get(_entityID);
                }
                _attributesTable.Columns.Add("Template");
                Dictionary<long, string> _attr_resource = new Dictionary<long, string>();
                foreach (System.Data.DataRow _row in _attributesTable.Rows) {
                    XiaoYang.Entity.EntityAttributeDisplay _pad = XiaoYang.Entity.EntityAttributeDisplay.GetInstance(Convert.ToInt64(_row["Display"]));
                    if (!_attr_resource.ContainsKey(_pad.ID)) _attr_resource.Add(_pad.ID, _pad.Resource);
                    _pad.Template = _pad.Template
                                           .Replace("{{AttributeName}}", _row["Name"].ToString())
                                           .Replace("{{TypeID}}", Request.Values["TypeID"].ToString())
                                           .Replace("{{TypeName}}", _typeName)
                                           .Replace("{{EntityID}}", Request.Values["EntityID"] == null ? string.Empty : Request.Values["EntityID"].ToString())
                                           .Replace("{{IsMultiple}}", Convert.ToBoolean(_row["IsMultiple"]).ToString())
                                           .Replace("{{Split}}", _row["Split"].ToString());
                    if (_entity_ext != null) {
                        if (Convert.ToBoolean(_row["IsMultiple"])) {
                            StringBuilder _multi_val = new StringBuilder();
                            List<long> _multi_IDs = new List<long>();
                            foreach (System.Data.DataRow _inrow in _entity_ext.Rows) {
                                long _inID = Convert.ToInt64(_inrow[_row["Name"].ToString() + ".ID"]);
                                if (_multi_IDs.IndexOf(_inID) == -1) {
                                    _multi_IDs.Add(_inID);
                                    if (_multi_val.Length > 0) _multi_val.Append(_row["Split"].ToString());
                                    _multi_val.Append(_inrow[_row["Name"].ToString()].ToString());
                                }
                            }
                            _pad.Template = _pad.Template.Replace("{{Value}}", _multi_val.ToString());
                        } else {
                            _pad.Template = _pad.Template.Replace("{{Value}}", _entity_ext.Rows[0][_row["Name"].ToString()].ToString());
                        }
                    } else {
                        _pad.Template = _pad.Template.Replace("{{Value}}", _row["Default"] == null ? string.Empty : _row["Default"].ToString());
                    }
                    Xy.Web.Control.IncludeControl _padt = new Xy.Web.Control.IncludeControl();
                    _padt.InnerData = new Xy.Web.HTMLContainer(WebSetting.Encoding);
                    _padt.InnerData.Write(_pad.Template);
                    System.Collections.Specialized.NameValueCollection _createTag = new System.Collections.Specialized.NameValueCollection();
                    _createTag.Add("EnableScript", "True");

                    if (!string.IsNullOrEmpty(_pad.TypeClass)) {
                        _createTag.Add("Type", _pad.TypeClass);
                        StringBuilder _ext_values = new StringBuilder();
                        _ext_values.Append("{");
                        _ext_values.AppendFormat(" {0}=\"{1}\" ", "AttributeName", _row["Name"].ToString())
                                    .AppendFormat(" {0}=\"{1}\" ", "EntityID", Request.Values["EntityID"] == null ? string.Empty : Request.Values["EntityID"].ToString())
                                    .AppendFormat(" {0}=\"{1}\" ", "TypeID", Request.Values["TypeID"].ToString())
                                    .AppendFormat(" {0}=\"{1}\" ", "TypeName", _typeName)
                                    .AppendFormat(" {0}=\"{1}\" ", "IsMultiple", Convert.ToBoolean(_row["IsMultiple"]).ToString())
                                    .AppendFormat(" {0}=\"{1}\" ", "Split", _row["Split"].ToString());
                        _ext_values.Append("}");
                        if (_ext_values.Length > 2) {
                            _createTag.Add("Value", _ext_values.ToString());
                        }
                    }
                    Xy.Web.HTMLContainer _template = new Xy.Web.HTMLContainer(WebSetting.Encoding);
                    _padt.Init(_createTag, "attrubiteTemplate", 0);
                    _padt.Handle(ThreadEntity, this, _template);
                    _row["Template"] = _template.ToString();
                }
                PageData.Add("Attributes", _attributesTable);

                StringBuilder _attr_resource_template = new StringBuilder();
                foreach (string _item in _attr_resource.Values) {
                    _attr_resource_template.AppendLine(_item);
                }
                PageData.Add("Resource", _attr_resource_template.ToString());
            }
        }
Esempio n. 3
0
        public override void ValidateUrl()
        {
            switch (Request.GroupString["class"]) {
                case "entity":
                    switch (Request.GroupString["type"]) {
                        case "list":
                            short _typeID = Convert.ToInt16(Request.GroupString["id"]);

                            int _totalCout = -1;

                            int _pageIndex = 0,_pageSize = 20;
                            string _where = string.Empty, _order = string.Empty, _filters = string.Empty;
                            if (!string.IsNullOrEmpty(Request.Form["PageIndex"])) _pageIndex = Convert.ToInt32(Request.Form["PageIndex"]);
                            if (!string.IsNullOrEmpty(Request.Form["PageSize"])) _pageSize = Convert.ToInt32(Request.Form["PageSize"]);
                            if (!string.IsNullOrEmpty(Request.Form["Where"])) _where = Request.Form["Where"];
                            if (!string.IsNullOrEmpty(Request.Form["Order"])) _order = Request.Form["Order"];
                            if (!string.IsNullOrEmpty(Request.Form["Filter"])) _filters = Request.Form["Filter"].Trim(',') + ',';

                            XiaoYang.Entity.EntityHelper _helper = new Entity.EntityHelper(_typeID);

                            PageData.AddXyDataModel("EntityType", Entity.EntityType.GetInstance(_typeID));
                            System.Data.DataTable _dt = new System.Data.DataTable();
                            _dt.Columns.Add("Name", typeof(string));
                            _dt.Columns.Add("Key", typeof(string));
                            _dt.Columns.Add("IsShow", typeof(bool));
                            for (int i = 0; i < _helper.CacheInstance.AttributeKeys.Length; i++) {
                                System.Data.DataRow _row = _dt.NewRow();
                                _row["Name"] = _helper.CacheInstance.AttributeNames[i];
                                _row["Key"] = _helper.CacheInstance.AttributeKeys[i];
                                _row["IsShow"] = _filters.IndexOf(_helper.CacheInstance.AttributeKeys[i] + ',') != -1;
                                _dt.Rows.Add(_row);
                            }
                            PageData.Add("Attributes", _dt);
                            XiaoYang.Entity.EntityCollection _ec = _helper.GetList(_where, _pageIndex, _pageSize, _order, ref _totalCout);
                            PageData.AddEntireXyDataModel("EntityList", _ec);
                            PageData["EntityList"].CreatePagination(_pageIndex, _pageSize, _totalCout, 9);
                            break;
                        case "add":
                            XiaoYang.Entity.EntityHelper _addHelper = new Entity.EntityHelper(Convert.ToInt16(Request.GroupString["id"]));
                            long _addID = _addHelper.Add(Request.Form);
                            Response.Write("{status:'success',message:'Success',returnURL:'/entity_edit_" + _addID + "." + WebSetting.Config["ext"] + "'}");
                            Response.Redirect("/entity_edit_" + _addID + "." + WebSetting.Config["ext"] + "#successed");
                            break;
                        case "edit":
                            Entity.EntityBase _editEntity = Entity.EntityBase.GetInstance(Convert.ToInt64(Request.GroupString["id"]));
                            XiaoYang.Entity.EntityHelper _editHelper = new Entity.EntityHelper(_editEntity.TypeID);
                            _editHelper.Edit(Request.Form, _editEntity.ID);
                            Response.Redirect("/entity_edit_" + _editEntity.ID + "." + WebSetting.Config["ext"] + "#successed");
                            break;
                        case "del":
                            Entity.EntityBase _delEntity = Entity.EntityBase.GetInstance(Convert.ToInt64(Request.GroupString["id"]));
                            XiaoYang.Entity.EntityHelper _delHelper = new Entity.EntityHelper(_delEntity.TypeID);
                            _delHelper.Del(_delEntity.ID);
                            break;
                    }
                    break;
                case "type":
                    switch (Request.GroupString["type"]) {
                        case "add":
                            XiaoYang.Entity.EntityType.Add(Request.Form);
                            break;
                        case "getattr":
                            Xy.Web.Control.DataControl _dc = new Xy.Web.Control.DataControl();
                            System.Collections.Specialized.NameValueCollection _dcInitTag = new System.Collections.Specialized.NameValueCollection();
                            Xy.Web.HTMLContainer _dcData = new Xy.Web.HTMLContainer(WebSetting.Encoding);
                            Xy.Web.HTMLContainer _dcContent = new Xy.Web.HTMLContainer(WebSetting.Encoding);
                            _dcInitTag.Add("Provider", "Procedure");
                            _dcInitTag.Add("Command", @"select [PostAttribute].*, [PostType].[IsActive] from [PostAttribute] left join [PostType] on [PostAttribute].[TypeID] = [PostType].[ID] where [TypeID] = @TypeID");
                            _dcInitTag.Add("Parameter", @"{ TypeID=""" + Request.QueryString["ID"] + @"|i"" }");
                            _dcInitTag.Add("EnableScript", "True");
                            _dcInitTag.Add("EnableCode", "True");
                            _dcInitTag.Add("Xslt", "attributelist.xslt");
                            _dc.Init(_dcInitTag, "PostAttributeControl", 999);
                            _dc.InnerData = _dcData;
                            _dc.Handle(ThreadEntity, this, _dcContent);
                            Response.Write(_dcContent);
                            break;
                        case "active":
                            XiaoYang.Entity.EntityType.EditActive(Request.Form);
                            break;
                        case "multi":
                            XiaoYang.Entity.EntityType.EditWebRelated(Request.Form);
                            break;
                        case "display":
                            XiaoYang.Entity.EntityType.EditDisplay(Request.Form);
                            break;
                        case "del":
                            XiaoYang.Entity.EntityType.Del(Convert.ToInt16(Request.Form["ID"]));
                            break;
                    }
                    break;
                case "attr":
                    switch (Request.GroupString["type"]) {
                        case "add":
                            XiaoYang.Entity.EntityAttribute.Add(Request.Form);
                            break;
                        case "edit":
                            XiaoYang.Entity.EntityAttribute.Edit(Request.Form);
                            break;
                        case "del":
                            XiaoYang.Entity.EntityAttribute.Del(Request.Form);
                            break;
                    }
                    break;
            }
        }