Example #1
0
    }                                   //父菜单是否可以点击

    public void Init(RectTransform rect, int count, Type t, IList dataList = null)
    {
        if (!typeof(ParentItem).IsAssignableFrom(t))
        {
            throw new Exception("传入类型必须是ParentItem的派生类");
        }
        childMenu  = transform.Find("childMenu").gameObject;
        itemRect   = rect;
        this.count = count;
        childs     = new RectTransform[this.count];
        offset     = new Vector3(0, itemRect.rect.height);
        for (int i = 0; i < this.count; i++)
        {
            childs[i] = Instantiate(itemRect, childMenu.transform);

            ParentItem parentComponent = childs[i].GetComponent(t) as ParentItem;
            if (parentComponent == null)
            {
                parentComponent = childs[i].gameObject.AddComponent(t) as ParentItem;
            }
            parentComponent.FindItem(childs[i]);
            parentComponent.FillItem(dataList[i]);
            childs[i].gameObject.SetActive(true);
        }
        childMenu.gameObject.SetActive(false);
        isOpening  = false;
        isCanClick = true;
        GetComponent <Button>().onClick.AddListener(OnButtonClick);
    }
 /// <exception cref="System.Exception"></exception>
 protected override void Store()
 {
     var parentItem = new ParentItem
         ();
     parentItem.child = new ChildItem();
     Store(parentItem);
 }
        /// <summary>
        /// Creates the poll.
        /// </summary>
        /// <returns></returns>
        private PollItem CreatePoll()
        {
            TemplateItem pollTemplate = PollConstants.DatabaseContext.Templates[PollConstants.PollTemplateID];
            string       pollName     = GetItemName(PollingName.Value.Trim()).Trim();
            Item         item;

            if (ParentItem.TemplateID == PollConstants.PollTemplateID)
            {
                item = ParentItem.Parent.Add(pollName, pollTemplate);
                Assert.IsNotNull(item, "Can't create poll item");
                var archivedPoll = new PollItem(ParentItem);
                archivedPoll.ArchiveTo(item);
            }
            else
            {
                item = ParentItem.Add(pollName, pollTemplate);
            }

            PollItem pollItem = new PollItem(item);

            if (pollName != PollingName.Value.Trim())
            {
                pollItem.DisplayName = HttpContext.Current.Server.HtmlEncode(PollingName.Value.Trim());
            }

            pollItem.Intro = string.Format("<h1>{0}</h1>", PollingName.Value.Trim());

            CreateOptions(pollItem);
            return(pollItem);
        }
Example #4
0
    private void BuildItemAsPerType()
    {
        switch (_itemType)
        {
        case (ItemType.Parent):
            ParentItem parentItem = gameObject.AddComponent <ParentItem>();
            parentItem.Layer           = _curLayer;
            parentItem.ItemObject      = _itemObject;
            parentItem.CancelItemLabel = _cancelItemLabel;

            parentItem.Build(_sSettings, _parentObj);

            _selectableItem = parentItem;

            break;

        case (ItemType.NormalButton):
            NormalButtonItem normalItem = gameObject.AddComponent <NormalButtonItem>();
            normalItem.Layer           = _curLayer;
            normalItem.Action          = _action;
            normalItem.IsCancelItem    = _isCancelItem;
            normalItem.CancelItemLabel = _cancelItemLabel;

            normalItem.Build(_sSettings, _parentObj);

            _selectableItem = normalItem;

            break;

        default:

            break;
        }
    }
Example #5
0
        /// <inheritdoc />
        override protected void OnInitialized()
        {
            expanded = Expanded;

            if (expanded)
            {
                Tree?.ExpandItem(this);
            }

            selected = Selected;

            if (selected)
            {
                Tree?.SelectItem(this);
            }

            if (Tree != null && ParentItem == null)
            {
                Tree.AddItem(this);
            }

            if (ParentItem != null)
            {
                ParentItem.AddItem(this);
            }
        }
Example #6
0
        /// <exception cref="System.Exception"></exception>
        protected override void Store()
        {
            var parentItem = new ParentItem
                                 ();

            parentItem.child = new ChildItem();
            Store(parentItem);
        }
 private ChildItem[] CastToChildItemArray(ParentItem
     [] array)
 {
     var res = new ChildItem
         [array.Length];
     for (var i = 0; i < res.Length; i++)
     {
         res[i] = (ChildItem) array[i];
     }
     return res;
 }
Example #8
0
 /// <inheritdoc />
 public void Dispose()
 {
     if (ParentItem != null)
     {
         ParentItem.RemoveItem(this);
     }
     else if (Tree != null)
     {
         Tree.RemoveItem(this);
     }
 }
Example #9
0
 protected override void Store()
 {
     var parentItem1 = new ParentItem
         ();
     var parentItem2 = new ParentItem
         ();
     var child = new ChildItem();
     child.parent1 = parentItem1;
     child.parent2 = parentItem2;
     parentItem1.child = child;
     parentItem2.child = child;
     Db().Store(parentItem1);
 }
        public override IEnumerable <string> GetDefineSymbols()
        {
            foreach (var d in base.GetDefineSymbols())
            {
                yield return(d);
            }

            var proj = ParentItem.GetFlavor <AddinProjectFlavor> ();

            //TODO: keep in sync with targets. eventually resolve from MSBuild
            var cv = proj.AddinRegistry.GetAddin("MonoDevelop.Core").Description.CompatVersion;

            yield return("MD_" + cv.Replace('.', '_'));
        }
Example #11
0
    public void CreatScrool(IDictionary info, Type t, Type t1)
    {
        if (!typeof(ParentItem).IsAssignableFrom(t))
        {
            throw new Exception("传入类型必须是ParentItem的派生类");
        }
        if (!typeof(ParentItem).IsAssignableFrom(t1))
        {
            throw new Exception("传入类型必须是ParentItem的派生类");
        }
        if (!isHorizontal)
        {
            parentOffset = new Vector3(0, parentRect.rect.height);
            childOffset  = new Vector3(0, childRect.rect.height);

            parentArr = new RectTransform[info.Count];
            cntArr    = new int[info.Count];
            //初始化content高度
            content.sizeDelta = new Vector2(content.rect.width, parentArr.Length * parentRect.rect.height);

            var Values = info.Values.GetEnumerator();
            var Keys   = info.Keys.GetEnumerator();
            int i      = 0;
            while (Keys.MoveNext())
            {
                IList list = info[Keys.Current] as IList;
                cntArr[i]    = list.Count;
                parentArr[i] = Instantiate(parentRect, content.transform);

                ParentItem parentComponent = parentArr[i].GetComponent(t) as ParentItem;
                if (parentComponent == null)
                {
                    parentComponent = parentArr[i].gameObject.AddComponent(t) as ParentItem;
                }
                parentComponent.FindItem(parentArr[i]);
                parentComponent.FillItem(Keys.Current);
                parentArr[i].localPosition -= i * parentOffset;

                parentArr[i].GetComponent <ParentMenu>().Init(childRect, list.Count, t1, list);
                int j = i;
                parentArr[i].GetComponent <Button>().onClick.AddListener(() => { OnButtonClick(j); });
                parentArr[i].gameObject.SetActive(true);
                i++;
            }
        }
    }
        private void AddOrUpdateParent(string parentId, ChildItem child, out string salePrice)
        {
            salePrice = "";
            if (string.IsNullOrEmpty(child.Id)) return;

            if (string.IsNullOrEmpty(parentId)) parentId = child.Id;

            //special handling in case parent id is a list --use only first id for replacements
            var parentList = new List<string> { parentId };
            if (parentId.Contains(","))
            {
                parentList = parentId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                parentId = parentList[0];
            }
            if (!child.Id.Equals(parentId)) //&& parentList.Count == 1) //TODO: should we skip if there are multiple parents
                _cart.Replacements.Add(new ReplacementRecord(child.Id, parentId));

            //remove invalid sale prices (common issue)
            if (child.SalePrice >= child.Price) child.SalePrice = 0F;
            salePrice = child.SalePrice > 0 ? child.SalePrice.ToString("F2") : ""; // validated sale price is passed back out

            foreach (var p in parentList) //usually only one
            {
                //parent item accumulates the price range of the children
                ParentItem parent;
                if (!_parentProducts.TryGetValue(p, out parent))
                {
                    parent = new ParentItem { Id = p };
                    _parentProducts.Add(p, parent);
                }

                if (child.Inventory > 0 || _rules.IgnoreStockInPriceRange)
                {
                    if (child.Inventory > 0)
                        parent.Inventory += child.Inventory; //ignore negative stock values
                    if (child.Price > 0)
                    {
                        if (parent.Price.Equals(0) || parent.Price > child.Price) parent.Price = child.Price;
                        if (parent.TopPrice < child.Price) parent.TopPrice = child.Price;
                    }
                    if (child.SalePrice > 0)
                    {
                        if (parent.SalePrice.Equals(0) || parent.SalePrice > child.SalePrice) parent.SalePrice = child.SalePrice;
                        if (parent.TopSalePrice < child.SalePrice) parent.TopSalePrice = child.SalePrice;
                    }
                    if (child.ListPrice > 0)
                    {
                        if (parent.ListPrice.Equals(0) || parent.ListPrice > child.ListPrice) parent.ListPrice = child.ListPrice;
                        if (parent.TopListPrice < child.ListPrice) parent.TopListPrice = child.ListPrice;
                    }
                    if (child.Cost > 0)
                    {
                        if (parent.Cost.Equals(0) || parent.Cost > child.Cost) parent.Cost = child.Cost;
                        if (parent.TopCost < child.Cost) parent.TopCost = child.Cost;
                    }
                }
                if (child.Rating > 0)
                {
                    if (parent.TopRating < child.Rating) parent.TopRating = child.Rating;
                    parent.RatingSum += child.Rating;
                    parent.RatingCount++;
                }
                _parentProducts[p] = parent;
            }
        }
        protected void AddOrUpdateParent(string parentId, ChildItem child, out string salePrice)
        {
            salePrice = "";
            if (string.IsNullOrEmpty(child.Id)) return;

            if (string.IsNullOrEmpty(parentId)) parentId = child.Id;

            //special handling in case parent id is a list --use only first id for replacements
            var parentList = new List<string> {parentId};
            if (parentId.Contains(","))
            {
                parentList = parentId.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).ToList();
                parentId = parentList[0];
            }
            if (parentList.Count == 1 && !child.Id.Equals(parentId)) //don't add to replacements if there are multiple parents
                Replacements.Add(new ReplacementRecord(child.Id, parentId));

            //need to remove invalid sale prices (common issue)
            if (child.SalePrice >= child.Price) child.SalePrice = 0F;
            salePrice = child.SalePrice > 0 ? child.SalePrice.ToString("F2") : ""; // validated sale price is passed back out

            foreach (var p in parentList) //usually only one
            {
                //parent item needs to have the price range of the children
                //float newPrice;
                ParentItem parent;
                if (!ParentProducts.TryGetValue(p, out parent))
                {
                    parent = new ParentItem {Id = p};
                    ParentProducts.Add(p, parent);
                    //check for parent in the full list to get price if any --is this ever non-zero?
                    //var parentMatch =
                    //  extraFieldsByItem.FirstOrDefault(
                    //    x => Input.GetValue(x, bareFieldnames[(int) SiteRules.FieldName.ProductId]).Equals(p));
                    //if (parentMatch != null
                    //    && Input.GetValue(out newPrice, parentMatch, bareFieldnames[(int) SiteRules.FieldName.Price])
                    //    && newPrice > 0)
                    //  parent.Price = newPrice;
                    //parentNonZero = true;
                }

                if (child.Inventory > 0 || Rules.IgnoreStockInPriceRange)
                {
                    parent.Inventory += child.Inventory;
                    if (child.Price > 0)
                    {
                        if (parent.Price.Equals(0) || parent.Price > child.Price) parent.Price = child.Price;
                        if (parent.TopPrice < child.Price) parent.TopPrice = child.Price;
                    }
                    if (child.SalePrice > 0)
                    {
                        if (parent.SalePrice.Equals(0) || parent.SalePrice > child.SalePrice) parent.SalePrice = child.SalePrice;
                        if (parent.TopSalePrice < child.SalePrice) parent.TopSalePrice = child.SalePrice;
                    }
                    if (child.ListPrice > 0)
                    {
                        if (parent.ListPrice.Equals(0) || parent.ListPrice > child.ListPrice) parent.ListPrice = child.ListPrice;
                        if (parent.TopListPrice < child.ListPrice) parent.TopListPrice = child.ListPrice;
                    }
                    if (child.Cost > 0)
                    {
                        if (parent.Cost.Equals(0) || parent.Cost > child.Cost) parent.Cost = child.Cost;
                        if (parent.TopCost < child.Cost) parent.TopCost = child.Cost;
                    }
                }
                if (child.Rating > 0)
                {
                    if (parent.TopRating < child.Rating) parent.TopRating = child.Rating;
                    parent.RatingSum += child.Rating;
                    parent.RatingCount++;
                }
                ParentProducts[p] = parent;
            }
        }
 public static ParentItem NewTestInstance()
 {
     var item = new ParentItem
         ();
     item._children = new[]
     {
         new ChildItem
             (),
         new ChildItem()
     };
     return item;
 }
 protected virtual bool HasSameNameAs(ParentItem other)
 {
     if (_name == null)
     {
         return other._name == null;
     }
     return _name.Equals(other._name);
 }