public ParentItem(string name, ChildItem child1, ChildItem child2) { _name = name; one = child1; two = child2; }
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; }
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); }
/// <summary> /// Reentrant version of Collapse/Expand Node /// </summary> /// <param name="Item"></param> /// <param name="ExpandNode"></param> private ModuleTreeViewItem FindModuleInTree(ModuleTreeViewItem Item, DisplayModuleInfo Module, bool Highlight = false) { if (Item.GetTreeNodeHeaderName(Dependencies.Properties.Settings.Default.FullPath) == Module.ModuleName) { if (Highlight) { ExpandAllParentNode(Item.Parent as ModuleTreeViewItem); Item.IsSelected = true; Item.BringIntoView(); Item.Focus(); } return(Item); } // BFS style search -> return the first matching node with the lowest "depth" foreach (ModuleTreeViewItem ChildItem in Item.Items) { if (ChildItem.GetTreeNodeHeaderName(Dependencies.Properties.Settings.Default.FullPath) == Module.ModuleName) { if (Highlight) { ExpandAllParentNode(Item); ChildItem.IsSelected = true; ChildItem.BringIntoView(); ChildItem.Focus(); } return(Item); } } foreach (ModuleTreeViewItem ChildItem in Item.Items) { ModuleTreeViewItem matchingItem = FindModuleInTree(ChildItem, Module, Highlight); // early exit as soon as we find a matching node if (matchingItem != null) { return(matchingItem); } } return(null); }
protected override void DragDropCopy(object sourceItem, object destinationItem, IList itemList, IList cloneList) { TCollection DestinationCollection = (TCollection)((TItem)destinationItem).Children; if (itemList != null && cloneList != null) { foreach (ICloneable ChildItem in itemList) { TItem Clone = (TItem)ChildItem.Clone(); Clone.ChangeParent((TItem)destinationItem); DestinationCollection.Add(Clone); cloneList.Add(Clone); } } DestinationCollection.Sort(); }
public void GetTopFields() { var item1 = new Item(); var item2 = new ChildItem(); var item3 = new ChildChildItem(); var fields1 = item1.GetType() .GetTopFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); var fields2 = item2.GetType() .GetTopFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); var fields3 = item3.GetType() .GetTopFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); Assert.AreEqual(2, fields1.Length); Assert.AreEqual(4, fields2.Length); Assert.AreEqual(5, fields3.Length); }
public void GetAllProperties() { var item1 = new Item(); var item2 = new ChildItem(); var item3 = new ChildChildItem(); var itemProperties1 = item1.GetType() .GetAllProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); var itemProperties2 = item2.GetType() .GetAllProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); var itemProperties3 = item3.GetType() .GetAllProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) .ToArray(); Assert.AreEqual(2, itemProperties1.Length); Assert.AreEqual(5, itemProperties2.Length); Assert.AreEqual(7, itemProperties3.Length); }
protected override void DragDropMove(object sourceItem, object destinationItem, IList itemList) { TCollection SourceCollection = (TCollection)((TItem)sourceItem).Children; TCollection DestinationCollection = (TCollection)((TItem)destinationItem).Children; if (itemList != null) { foreach (TItem ChildItem in itemList) { SourceCollection.Remove(ChildItem); } foreach (TItem ChildItem in itemList) { ChildItem.ChangeParent((TItem)destinationItem); DestinationCollection.Add(ChildItem); } } DestinationCollection.Sort(); }
/// <summary> /// Moves items from source to destination. /// </summary> /// <param name="sourceItem">The source item.</param> /// <param name="destinationItem">The destination item.</param> /// <param name="itemList">Moved children.</param> protected override void DragDropMove(object sourceItem, object destinationItem, IList itemList) { TItem SourceItem = (TItem)sourceItem; TItem DestinationItem = (TItem)destinationItem; TCollection SourceCollection = (TCollection)SourceItem.Children; TCollection DestinationCollection = (TCollection)DestinationItem.Children; #if NETCOREAPP3_1 foreach (TItem?ChildItem in itemList) { if (ChildItem != null) { SourceCollection.Remove(ChildItem); } } foreach (TItem?ChildItem in itemList) { if (ChildItem != null) { ChildItem.ChangeParent((TItem)destinationItem); DestinationCollection.Add(ChildItem); } } #else foreach (TItem ChildItem in itemList) { SourceCollection.Remove(ChildItem); } foreach (TItem ChildItem in itemList) { ChildItem.ChangeParent((TItem)destinationItem); DestinationCollection.Add(ChildItem); } #endif DestinationCollection.Sort(); }
/// <summary> /// Gets the child item. /// </summary> /// <param name="tfsUrlPath">The TFS URL path.</param> /// <param name="projectName">Name of the project.</param> /// <param name="workItem">The work item.</param> /// <returns>Child Item</returns> private static ChildItem GetChildItem(string tfsUrlPath, string projectName, Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem) { ChildItem childItem = new ChildItem(); childItem.ItemId = workItem.Id; childItem.IterationPath = workItem.IterationPath; childItem.State = workItem.State; childItem.Title = workItem.Title; Field assignedToField = workItem.Fields[TFSLiterals.AssignedTo]; childItem.AssignedTo = (string)assignedToField.Value; Field workItemTypeField = workItem.Fields[TFSLiterals.WorkItemType]; childItem.WorkItemType = (string)workItemTypeField.Value; if (workItem.Fields.Contains(TFSLiterals.CompletedWork)) { Field completedWorkfield = workItem.Fields[TFSLiterals.CompletedWork]; childItem.TaskEffortDetails.CompletedWork = (double)completedWorkfield.Value; } if (workItem.Fields.Contains(TFSLiterals.CompletedWork)) { Field remainingWorkfield = workItem.Fields[TFSLiterals.RemainingWork]; childItem.TaskEffortDetails.RemainingWork = (double)remainingWorkfield.Value; } if (workItem.Fields.Contains(TFSLiterals.CompletedWork)) { Field OriginalWorkfield = workItem.Fields[TFSLiterals.OriginalEstimate]; childItem.TaskEffortDetails.OriginalEstimate = (double)OriginalWorkfield.Value; } childItem.WorkItemUrl = tfsUrlPath + "/" + projectName + "/_workitems#_a=edit&id=" + workItem.Id; return(childItem); }
public Item(int id, ChildItem child, Item [] items) : this(id) { _child = child; _array = items; }
private async void OnChildItemTitleChanged(ChildItem childItem, ChangeEventArgs eventArgs) { childItem.Title = eventArgs.Value.ToString(); await UserItemManager.UpdateAsync(childItem); }
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; } }
//protected void CreateMigrationMap(string pid, XElement product) //{ // if (MigrationSubMap == null || Rules.MigrationRules == null || !Rules.MigrationRules.Enabled) return; // var field = _migrationSlave ? Rules.MigrationRules.MapFromField : Rules.MigrationRules.MapToField; // if (string.IsNullOrEmpty(field)) return; // field = Input.RemoveTablePrefix(field); // var key = Input.GetValue(product, field); // string value; // if (string.IsNullOrEmpty(key) // || (_migrationSlave && MigrationSubMap.TryGetValue(pid, out value)) // || (!_migrationSlave && MigrationSubMap.TryGetValue(key, out value))) // return; // //mapping goes from slave-id to slave-key to master-key to master-id // if (_migrationSlave) MigrationSubMap.Add(pid, key); // else MigrationSubMap.Add(key, pid); //} protected void AddOrUpdateParent(string parentId, string childId, XElement child, string[] fieldnames) { var inventory = Input.SafeIntConvert(Input.GetValue(child, Rules.Fields.GetName(FieldName.Inventory)), 0); float tempVal; var price = Input.GetValue(out tempVal, child, Rules.Fields.GetName(FieldName.Price)) ? tempVal : 0F; var salePrice = Input.GetValue(out tempVal, child, Rules.Fields.GetName(FieldName.SalePrice)) ? tempVal : 0F; var listPrice = Input.GetValue(out tempVal, child, Rules.Fields.GetName(FieldName.ListPrice)) ? tempVal : 0F; var cost = Input.GetValue(out tempVal, child, Rules.Fields.GetName(FieldName.Cost)) ? tempVal : 0F; var rating = Input.GetValue(out tempVal, child, Rules.Fields.GetName(FieldName.Rating)) ? tempVal : 0F; var childItem = new ChildItem { Id = childId, Inventory = inventory, Price = price, SalePrice = salePrice, ListPrice = listPrice, Cost = cost, Rating = rating }; string salePriceCheck; AddOrUpdateParent(parentId, childItem, out salePriceCheck); //check for migration mapping var mapId = _migrationSlave ? childId : parentId; //map from slave children to master parents if (Rules.MigrationRules != null) Rules.MigrationRules.MapItem(mapId, child); }
/// <summary> /// Calculate new bounds during interactive moving or resizing /// </summary> /// <param name="subItem"></param> /// <param name="mousePoint"></param> protected void CalculateNewBounds(ChildItem subItem, Point mousePoint) { Rectangle originalBounds = this.BoundsDragOrigin.Value; Rectangle draggedBounds = originalBounds; Point begin = originalBounds.Location; Point end = originalBounds.End(); bool ctrl = Control.ModifierKeys == Keys.Control; switch (subItem.ItemType) { case ChildItemType.Area: case ChildItemType.Border: if (ctrl) { Point d = begin.Sub(mousePoint); if (Math.Abs(d.X) >= Math.Abs(d.Y)) { mousePoint = new Point(mousePoint.X, originalBounds.Y); } else { mousePoint = new Point(originalBounds.X, mousePoint.Y); } } draggedBounds = new Rectangle(mousePoint, originalBounds.Size); break; case ChildItemType.TopLeft: draggedBounds = DrawingExtensions.FromDim(mousePoint.X, end.X, mousePoint.Y, end.Y); break; case ChildItemType.Top: draggedBounds = DrawingExtensions.FromDim(begin.X, end.X, mousePoint.Y, end.Y); break; case ChildItemType.TopRight: draggedBounds = DrawingExtensions.FromDim(begin.X, mousePoint.X, mousePoint.Y, end.Y); break; case ChildItemType.Right: draggedBounds = DrawingExtensions.FromDim(begin.X, mousePoint.X, begin.Y, end.Y); break; case ChildItemType.BottomRight: draggedBounds = DrawingExtensions.FromDim(begin.X, mousePoint.X, begin.Y, mousePoint.Y); break; case ChildItemType.Bottom: draggedBounds = DrawingExtensions.FromDim(begin.X, end.X, begin.Y, mousePoint.Y); break; case ChildItemType.BottomLeft: draggedBounds = DrawingExtensions.FromDim(mousePoint.X, end.X, begin.Y, mousePoint.Y); break; case ChildItemType.Left: draggedBounds = DrawingExtensions.FromDim(mousePoint.X, end.X, begin.Y, end.Y); break; } this.SetBounds(draggedBounds, ProcessAction.PrepareInnerItems, EventSourceType.InteractiveChanging); }
/// <summary> /// Called after any interactive change value of State /// </summary> /// <param name="e"></param> /// <param name="childItem"></param> protected void AfterStateChanged(GInteractiveChangeStateArgs e, ChildItem childItem) { if (childItem != null) { this.InteractiveState = e.TargetState; } switch (e.ChangeState) { case GInteractiveChangeState.MouseEnter: // Mouse can Enter to main item = this (childItem != null), or to child item (childItem != null): this.ActiveChild = childItem; this.Repaint(); if (childItem != null) { e.RequiredCursorType = childItem.OverCursorType; } break; case GInteractiveChangeState.MouseLeave: // Mouse can Leave from main item = this (childItem != null), or from child item (childItem != null): this.ActiveChild = null; this.Repaint(); if (childItem != null) { e.RequiredCursorType = SysCursorType.Default; } else { e.RepaintAllItems = true; } break; case GInteractiveChangeState.MouseOver: this.Repaint(); break; case GInteractiveChangeState.LeftDragMoveBegin: if (childItem != null && childItem.CanDrag) { this.BoundsDragOrigin = this.Bounds; this.ActiveChild = childItem; this.Repaint(GInteractiveDrawLayer.Standard | GInteractiveDrawLayer.Interactive); e.RepaintAllItems = true; e.RequiredCursorType = childItem.DragCursorType; e.UserDragPoint = this.Bounds.Location.Add(childItem.ActivePoint); } break; case GInteractiveChangeState.LeftDragMoveStep: if (this.ActiveChild != null && this.ActiveChild.CanDrag && e.UserDragPoint.HasValue) { this.Repaint(/* GInteractiveDrawLayer.Standard | */ GInteractiveDrawLayer.Interactive); Point currentPoint = e.UserDragPoint.Value; this.CalculateNewBounds(this.ActiveChild, e.UserDragPoint.Value); Rectangle newBounds = this.Bounds; Rectangle oldBounds = (this.BoundsDragOrigin.HasValue ? this.BoundsDragOrigin.Value : newBounds); this.CallBoundsChanged(oldBounds, newBounds, EventSourceType.InteractiveChanging | EventSourceType.BoundsChange); } break; case GInteractiveChangeState.LeftDragMoveCancel: if (this.BoundsDragOrigin.HasValue) { Rectangle oldBounds = this.Bounds; Rectangle newBounds = this.BoundsDragOrigin.Value; this.SetBounds(newBounds, ProcessAction.PrepareInnerItems, EventSourceType.InteractiveChanged); this.Repaint(); } break; case GInteractiveChangeState.LeftDragMoveDone: if (this.ActiveChild != null && this.ActiveChild.CanDrag) { Rectangle newBounds = this.Bounds; Rectangle oldBounds = (this.BoundsDragOrigin.HasValue ? this.BoundsDragOrigin.Value : newBounds); this.CallBoundsChanged(oldBounds, newBounds, EventSourceType.InteractiveChanged | EventSourceType.BoundsChange); this.Repaint(); } break; case GInteractiveChangeState.LeftDragMoveEnd: this.BoundsDragOrigin = null; if (childItem != null) { e.RequiredCursorType = childItem.OverCursorType; } e.RepaintAllItems = true; break; default: var s = e.ChangeState; break; } }
/// <summary> /// Add a set of rows to the catalog /// Only parents will be added to the catalog (unless _rules force ), but critical child item data will be aggregated /// </summary> /// <param name="data"></param> /// <param name="dataIncludesHeader"></param> /// <returns></returns> public int AddData(List<List<string>> data, bool dataIncludesHeader) { if (Header == null && !dataIncludesHeader) throw new Exception("Header has not beed defined"); if (data == null || data.Count < 1) return Rows.Count; if (dataIncludesHeader) { Header = data[0].Select(x => x.Replace(" ", "")).ToList(); //cannot have spaces in header names data.RemoveAt(0); if (_rules.CartType.Equals(CartType.Magento)) //special handling for Magento plugin bug Header = Header.Distinct().ToList(); _rules.Fields.SetFieldHeaderIndices(DataGroup.Catalog, Header); } var headColCount = Header.Count; //set the indices for the fields involved in child item data aggregation var iPId = _rules.Fields.GetHeaderIndex(FieldName.ProductId); if (iPId < 0) throw new Exception("Catalog feed header does not include a product id\nHeader = " + Header); var iParent = _rules.Fields.GetHeaderIndex(FieldName.ParentId); var iPrice = _rules.Fields.GetHeaderIndex(FieldName.Price); var iSale = _rules.Fields.GetHeaderIndex(FieldName.SalePrice); var iList = _rules.Fields.GetHeaderIndex(FieldName.ListPrice); var iCost = _rules.Fields.GetHeaderIndex(FieldName.Cost); var iInv = _rules.Fields.GetHeaderIndex(FieldName.Inventory); var iRate = _rules.Fields.GetHeaderIndex(FieldName.Rating); _progress.UpdateTask(-1, -1, "Getting child items"); //examine each row and capture parent-child relationships //children are added to replacements and (usually) omitted from the catalog //also remove rows that do not have the correct number of columns //two objects are created: the Rows (list of lists) that holds all fields for each item; //and the ParentProducts (dictionary) that accumulates the price and inventory data for all children var errors = 0; var childCount = 0; foreach (var cols in data) //each row of data contains a list of column values { try { if (cols.Count != headColCount) { if (cols.Count.Equals(headColCount - 1)) //sometimes the final column will be truncated if empty cols.Add(""); else //data error --rows must match header { errors++; continue; } } var id = cols[iPId]; //already checked >= 0 above if (id.Length < 1) { //data error --each row must have a product id errors++; continue; } var parentId = Input.GetColVal(cols, iParent); #if DEBUG var breakHere = false; if (!string.IsNullOrEmpty(parentId) && TableAccess.Instance.DebugIds.Contains(parentId)) breakHere = true; else if (TableAccess.Instance.DebugIds.Contains(id)) breakHere = true; #endif // track all item details in parent (even if this is the parent) // parent logic will clean up any pricing or stock issues var child = new ChildItem { Id = id, Price = Input.SafeFloatConvert(Input.GetColVal(cols, iPrice)), SalePrice = Input.SafeFloatConvert(Input.GetColVal(cols, iSale)), ListPrice = Input.SafeFloatConvert(Input.GetColVal(cols, iList)), Cost = Input.SafeFloatConvert(Input.GetColVal(cols, iCost)), Inventory = Input.SafeIntConvert(Input.GetColVal(cols, iInv)), Rating = Input.SafeFloatConvert(Input.GetColVal(cols, iRate)) }; string salePrice; AddOrUpdateParent(parentId, child, out salePrice); if (iSale >= 0) cols[iSale] = salePrice; if (string.IsNullOrEmpty(parentId) || child.Id.Equals(parentId)) { Rows.Add(cols); //parent item found continue; } ++childCount; //check for replacement rules ApplyReplacementRules(cols, parentId); //_progress.UpdateTask(childCount); //check for migration mapping if (_rules.MigrationRules != null) _rules.MigrationRules.MapItem(id, Header, cols); if (_rules.IncludeChildrenInCatalog) Rows.Add(cols); } catch (Exception ex) { errors++; } } return Rows.Count; }
public static void CreateTestUser( IUserItemManager userItemManager = null, IUserManager userManager = null ) { var user = new User(); user.Id = 123; user.UserName = "******"; user.FirstName = "Billy Joe"; user.LastName = "Azur"; user.Password = "******"; user.GenderType = GenderTypeEnum.Male; user.UserItems = new ObservableCollection <BaseItem>(); if (userManager != null) { userManager.InsertUserAsync(user); } TextItem textItem = null; if (userItemManager != null) { textItem = (TextItem)userItemManager .CreateNewUserItemAndAddItToUserAsync(user, ItemTypeEnum.Text).Result; } else { textItem = new TextItem(); user.UserItems.Add(textItem); } textItem.ParentId = user.Id; textItem.Id = 1; textItem.Title = "Buy Apples"; textItem.SubTitle = "Red | 5"; textItem.Detail = "From New Zealand preferred"; textItem.ItemTypeEnum = ItemTypeEnum.Text; textItem.Position = 1; UrlItem urlItem; if (userItemManager != null) { urlItem = (UrlItem)userItemManager.CreateNewUserItemAndAddItToUserAsync(user, ItemTypeEnum.Url).Result; } else { urlItem = new UrlItem(); user.UserItems.Add(urlItem); } urlItem.ParentId = user.Id; urlItem.Id = 2; urlItem.Title = "Buy Sunflowers"; urlItem.Url = "https://drive.google.com/file/d/1NXiNFLEUGUiNtkyzdHDtf-HDocFh3OJ0/view?usp=sharing"; urlItem.ItemTypeEnum = ItemTypeEnum.Url; urlItem.Position = 2; ParentItem parentItem; if (userItemManager != null) { parentItem = (ParentItem)userItemManager .CreateNewUserItemAndAddItToUserAsync(user, ItemTypeEnum.Parent) .Result; } else { parentItem = new ParentItem(); user.UserItems.Add(parentItem); } parentItem.ParentId = user.Id; parentItem.Id = 3; parentItem.Title = "Make Birthday Present"; parentItem.ItemTypeEnum = ItemTypeEnum.Parent; parentItem.Position = 3; parentItem.ChildItems = new ObservableCollection <ChildItem>(); ChildItem childItem; if (userItemManager != null) { childItem = (ChildItem)userItemManager .CreateNewChildItemAndAddItToParentItemAsync(parentItem).Result; //Clear becuase entites are stored user.UserItems.Clear(); } else { childItem = new ChildItem(); parentItem.ChildItems.Add(childItem); } childItem.ParentId = parentItem.Id; childItem.Id = 4; childItem.ItemTypeEnum = ItemTypeEnum.Child; childItem.Position = 1; childItem.Title = "Cut"; TestUser = user; }
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; } }
private void initChildList() { mChildList = new List<ChildItem>(); if (_parent.childCount != 0) { ChildItem aItem; for (int aIndex = 0; aIndex < _parent.childCount; aIndex++) { if (_parent.GetChild(aIndex).gameObject.activeSelf == false) { continue; } aItem = new ChildItem(_parent.GetChild(aIndex)); mChildList.Add (aItem); } } Sort (); }
public async Task Scenario() { await TestDbContext.ExecAsync(context => { var parents = context.Set <ParentItem>(); var children = context.Set <ChildItem>(); var parent = new ParentItem { ID = 123 }; var child = new ChildItem { ID = 1 }; var orphan = new ChildItem { ID = 2 }; parent.Children.Add(child); parents.Add(parent); children.Add(orphan); context.SaveChanges(); { var loadResut = DataSourceLoader.Load(children, new SampleLoadOptions { Select = new[] { "Parent.ID" }, Sort = new[] { new SortingInfo { Selector = "Parent.ID" } } }); dynamic items = loadResut.data.Cast <object>().ToArray(); Assert.Null(items[0].Parent.ID); Assert.Equal(123, items[1].Parent.ID); } { var loadResult = DataSourceLoader.Load(children, new SampleLoadOptions { Filter = new[] { "Parent.ID", null } }); Assert.Single(loadResult.data); } { var loadResult = DataSourceLoader.Load(children, new SampleLoadOptions { Filter = new[] { "Parent.ID", "<>", null } }); Assert.Single(loadResult.data); } { var loadResult = DataSourceLoader.Load(children, new SampleLoadOptions { Filter = new[] { "ID", null } }); Assert.Empty(loadResult.data); } }); }
public static MultiUse Load(List <string> values) { MultiUse multiUse = new MultiUse(); multiUse.prefireGraphic = new Graphics(ref values, 71); multiUse.prefireSound = new Sound(ref values, 79); multiUse.firingSound = new Sound(ref values, 93); multiUse.iconGraphic = new Graphics(ref values, 23); ItemInfo.LoadGeneralSettings1((ItemInfo)multiUse, values); multiUse.useAmmoID = CSVReader.GetInt(values[31]); multiUse.ammoUsedPerShot = CSVReader.GetInt(values[32]); multiUse.ammoCapacity = CSVReader.GetInt(values[33]); multiUse.requiredItem = CSVReader.GetInt(values[34]); multiUse.requiredAmmoAmount = CSVReader.GetInt(values[35]); multiUse.energyCostTerrain0 = CSVReader.GetInt(values[36]); multiUse.energyCostTerrain1 = CSVReader.GetInt(values[37]); multiUse.energyCostTerrain2 = CSVReader.GetInt(values[38]); multiUse.energyCostTerrain3 = CSVReader.GetInt(values[39]); multiUse.energyCostTerrain4 = CSVReader.GetInt(values[40]); multiUse.energyCostTerrain5 = CSVReader.GetInt(values[41]); multiUse.energyCostTerrainTerrain6 = CSVReader.GetInt(values[42]); multiUse.energyCostTerrain7 = CSVReader.GetInt(values[43]); multiUse.energyCostTerrain8 = CSVReader.GetInt(values[44]); multiUse.energyCostTerrain9 = CSVReader.GetInt(values[45]); multiUse.energyCostTerrain10 = CSVReader.GetInt(values[46]); multiUse.energyCostTerrain11 = CSVReader.GetInt(values[47]); multiUse.energyCostTerrain12 = CSVReader.GetInt(values[48]); multiUse.energyCostTerrain13 = CSVReader.GetInt(values[49]); multiUse.energyCostTerrain14 = CSVReader.GetInt(values[50]); multiUse.energyCostTerrain15 = CSVReader.GetInt(values[51]); multiUse.secondShotEnergy = CSVReader.GetInt(values[52]); multiUse.secondShotTimeout = CSVReader.GetInt(values[53]); multiUse.fireDelay = CSVReader.GetInt(values[54]); multiUse.fireDelayOther = CSVReader.GetInt(values[55]); multiUse.maxFireDelay = CSVReader.GetInt(values[56]); multiUse.entryFireDelay = CSVReader.GetInt(values[57]); multiUse.reloadDelayNormal = CSVReader.GetInt(values[58]); multiUse.reloadDelayPartial = CSVReader.GetInt(values[59]); multiUse.reloadDelayAsynchronous = CSVReader.GetInt(values[60]); multiUse.reloadDelayAsynchronousPartial = CSVReader.GetInt(values[61]); multiUse.routeRange = CSVReader.GetInt(values[62]); multiUse.routeRotationalRange = CSVReader.GetInt(values[63]); multiUse.routeFriendly = CSVReader.GetBool(values[65]); multiUse.recoil = CSVReader.GetInt(values[66]); multiUse.verticalRecoil = CSVReader.GetInt(values[67]); multiUse.prefireDelay = CSVReader.GetInt(values[68]); multiUse.reliability = CSVReader.GetInt(values[69]); multiUse.reliabilityFireDelay = CSVReader.GetInt(values[70]); multiUse.movementCancelsPrefire = CSVReader.GetBool(values[83]); multiUse.notifyOthersOfPrefire = CSVReader.GetBool(values[84]); multiUse.cashCost = CSVReader.GetInt(values[85]); multiUse.useWhileCarryingBall = CSVReader.GetBool(values[86]); multiUse.useWhileCarryingFlag = CSVReader.GetBool(values[87]); multiUse.soccerThrow = CSVReader.GetInt(values[88]); multiUse.soccerBallFriction = CSVReader.GetInt(values[89]); multiUse.soccerBallSpeed = CSVReader.GetInt(values[90]); multiUse.soccerLowFireAngle = CSVReader.GetInt(values[91]); multiUse.soccerHighFireAngle = CSVReader.GetInt(values[92]); int currentPlace = 97; multiUse.childItems = new List <ChildItem>(); for (int i = 0; i < 32; i++) { if (currentPlace < values.Count) { ChildItem child = new ChildItem(); child.id = CSVReader.GetInt(values[currentPlace + 0]); child.deltaX = CSVReader.GetInt(values[currentPlace + 1]); child.deltaY = CSVReader.GetInt(values[currentPlace + 2]); child.deltaZ = CSVReader.GetInt(values[currentPlace + 3]); child.deltaAngle = CSVReader.GetInt(values[currentPlace + 4]); child.theMultiLinkMode = (ChildItem.MultiLinkModes)CSVReader.GetInt(values[currentPlace + 5]); multiUse.childItems.Add(child); currentPlace += 6; } else { break; } } return(multiUse); }