public void Remove() { if (ParentCollection.Count > 1) { ParentCollection.Remove(this); } }
protected UnitBase(string className, string symbol) : base(className) { _conversions = new ParentCollection <UnitBase, Conversion>(this, (unit, parent) => unit.BaseUnit = parent); Quantity = new Quantity(this); _symbol = symbol; }
public Duel(List <Property> properties, World world) : base(properties, world) { foreach (Property property in properties) { switch (property.Name) { case "ordinal": Ordinal = String.Intern(property.Value); break; case "coords": Coordinates = Formatting.ConvertToLocation(property.Value); break; case "parent_eventcol": ParentCollection = world.GetEventCollection(Convert.ToInt32(property.Value)); break; case "subregion_id": Region = world.GetRegion(Convert.ToInt32(property.Value)); break; case "feature_layer_id": UndergroundRegion = world.GetUndergroundRegion(Convert.ToInt32(property.Value)); break; case "site_id": Site = world.GetSite(Convert.ToInt32(property.Value)); break; case "attacking_hfid": Attacker = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break; case "defending_hfid": Defender = world.GetHistoricalFigure(Convert.ToInt32(property.Value)); break; } } //foreach (WorldEvent collectionEvent in Collection) this.AddEvent(collectionEvent); if (ParentCollection != null && ParentCollection.GetType() == typeof(Battle)) { foreach (HFDied death in Collection.OfType <HFDied>()) { Battle battle = ParentCollection as Battle; War parentWar = (battle.ParentCollection as War); if (battle.NotableAttackers.Contains(death.HistoricalFigure)) { battle.AttackerDeathCount++; battle.Attackers.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++; if (parentWar != null) { parentWar.AttackerDeathCount++; } } else if (battle.NotableDefenders.Contains(death.HistoricalFigure)) { battle.DefenderDeathCount++; battle.Defenders.Single(squad => squad.Race == death.HistoricalFigure.Race).Deaths++; if (parentWar != null) { parentWar.DefenderDeathCount++; } } if (parentWar != null) { (ParentCollection.ParentCollection as War).DeathCount++; } } } }
IEnumerable <IDirectedConnectedNode <T> > IDirectedConnectedNode <T> .GetNodesConnected(ConnectionDirection direction) { if (Helpers <T> .Check_GetNodesConnected_PreConditions(this)) { return(new List <ArrayDCN <T> >()); } return(ParentCollection.GetNodesConnected(this, direction)); }
bool IDirectedConnectedNode <T> .IsConnectedWith(IDirectedConnectedNode <T> secondNode, ConnectionDirection direction) { if (Helpers <T> .Check_IsConnectedWith_PreConditions(secondNode, this)) { return(false); } return(ParentCollection.NodesHaveConnection(this, secondNode, direction)); }
private void RemoveConnectionWith(ArrayDCN <T> typedNode, ConnectionDirection direction) { if (Helpers <T> .CheckWhether_RemoveConnectionWith_IsNeeded(typedNode, this)) { return; } ParentCollection.DisconnectNodes(this, typedNode, direction); }
public string GetCollectionParentString() { if (ParentCollection != null) { return(ParentCollection.GetCollectionParentString() + " > " + Type); } return(Type); }
/// <summary> /// Assigns a value to a variable /// </summary> /// <param name="name">Name of variable to set</param> /// <param name="value">Value to assign</param> public void Set(string name, string value) { if (!IsDefined(name) || Vars.ContainsKey(name)) { Vars[name] = value; return; } ParentCollection.Set(name, value); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { ParentCollection pc = new ParentCollection(); JArray array = JArray.Load(reader); foreach (var item in array) { pc.Add(item.ToObject <ChildDTO>()); } return(pc); }
public string GetCollectionParentString() { if (ParentCollection != null) { return(ParentCollection.GetCollectionParentString() + " > " + this.Type); } else { return(this.Type); } }
public ActionResult Save(Bam.Net.Data.Repositories.Tests.ClrTypes.Daos.Parent[] values) { try { ParentCollection saver = new ParentCollection(); saver.AddRange(values); saver.Save(); return(Json(new { Success = true, Message = "", Dao = "" })); } catch (Exception ex) { return(GetErrorResult(ex)); } }
/// <summary> /// Gets the value of a variable or another value if it does not exist /// </summary> /// <param name="name">Name of variable to get</param> /// <param name="defaultValue">Value to return if the variable is undefined</param> /// <returns></returns> public string GetOrDefault(string name, string defaultValue) { if (IsDefined(name)) { return(Vars[name]); } if (ParentCollection != null) { return(ParentCollection.GetOrDefault(name, defaultValue)); } return(defaultValue); }
/// <summary> /// Gets the value of a variable /// </summary> /// <param name="name">Name of variable to get</param> /// <returns></returns> public string Get(string name) { if (IsDefined(name)) { return(Vars[name]); } if (ParentCollection != null) { return(ParentCollection.Get(name)); } throw new ArgumentException("No variable with this name is defined"); }
public override string Print(bool link = true, DwarfObject pov = null) { string eventString = GetYearTime(); if (Source != null && Destination != null) { eventString += Destination.ToLink(link, pov) + " " + Decision + " an offer of peace from " + Source.ToLink(link, pov) + " in " + ParentCollection.ToLink(link, pov) + "."; } else { eventString += "Peace " + Decision + " in " + ParentCollection.ToLink(link, pov) + "."; } return(eventString); }
/// <summary> /// Apply styles, beginning at item 'pivotidx' in this collection, iterative backwards up and down the hierarchy. /// It stops at the first item of a collection here or down the hierarchy that do not inherit from it's parent collection. /// </summary> /// <param name="pivotidx">The index of the item where the application process starts.</param> /// <returns>The plot item collection where the process stops.</returns> protected PlotItemCollection ApplyStylesIterativeBackward(int pivotidx) { // if the pivot is lower than 0, we first distibute all changes to the first item and // then from the first item again down the line if (pivotidx > 0) { _styles.BeginApply(); for (int i = pivotidx; i >= 0; i--) { IGPlotItem pi = _plotItems[i]; if (pi is PlotItemCollection) { _styles.Step(-1); PlotItemCollection pic = (PlotItemCollection)pi; pic.ApplyStylesBackward_HierarchyUpOnly(_styles); } else { pi.ApplyStyles(_styles); if (i > 0) { _styles.Step(-1); } } } _styles.EndApply(); } // now use this styles to copy to the parent bool transferToParentStyles = ParentCollection != null && ParentCollection._styles.Count != 0 && ParentCollection._styles.DistributeToChildGroups && this._styles.InheritFromParentGroups; PlotItemCollection rootCollection = this; if (transferToParentStyles) { PlotGroupStyleCollection.TransferFromTo(_styles, ParentCollection._styles); rootCollection = ParentCollection.ApplyStylesIterativeBackward(ParentCollection._styles.Count - 1); } return(rootCollection); }
private void Delete() { try { if (ParentCollection?.Parent == null) { _owner.Criteria.RootCondition = null; } else { ParentCollection.Remove(this); } } catch (Exception ex) { _messageBoxService.Show(ex); } }
public void SetLocation(Chunk newChunk, IntegerPair newIndices) { if (ParentCollection) { ParentCollection.UpdateLocation(this, new Coordinates(newChunk, newIndices)); } if (newChunk != chunk) { if (chunk != null) { chunk.entitySet.Remove(this); } chunk = newChunk; chunk.entitySet.Add(this); } tileIndices = newIndices; }
/// <summary> /// Prepare styles, beginning at item 'pivotidx' in this collection, iterative backwards up and down the hierarchy. /// It stops at the first item of a collection here or down the hierarchy that do not inherit from it's parent collection. /// </summary> /// <param name="pivotidx">The index of the item where the application process starts.</param> /// <param name="layer">The plot layer.</param> protected void PrepareStylesIterativeBackward(int pivotidx, IPlotArea layer) { // if the pivot is lower than 0, we first distibute all changes to the first item and // then from the first item again down the line if (pivotidx > 0) { _plotGroupStyles.BeginPrepare(); for (int i = pivotidx; i >= 0; i--) { IGPlotItem pi = _plotItems[i]; if (pi is PlotItemCollection) { _plotGroupStyles.PrepareStep(); var pic = (PlotItemCollection)pi; pic.PrepareStylesBackward_HierarchyUpOnly(_plotGroupStyles, layer); } else { pi.PrepareGroupStyles(_plotGroupStyles, layer); if (i > 0) { _plotGroupStyles.PrepareStep(); } } } _plotGroupStyles.EndPrepare(); } // now use this styles to copy to the parent bool transferToParentStyles = ParentCollection != null && ParentCollection._plotGroupStyles.Count != 0 && ParentCollection._plotGroupStyles.DistributeToChildGroups && _plotGroupStyles.InheritFromParentGroups; if (transferToParentStyles) { PlotGroupStyleCollection.TransferFromTo(_plotGroupStyles, ParentCollection._plotGroupStyles); ParentCollection.ApplyStylesIterativeBackward(ParentCollection._plotGroupStyles.Count - 1); } }
/// <summary> /// If <paramref name="wantedType"/> is null, then all parents may attach themselves. /// </summary> /// <param name="wantedType"></param> public ParentsContainer(Type?wantedType) { Parents = new ParentCollection(); WantedType = wantedType; }
/// <summary> /// Returns true if a variable is defined with a specific name /// </summary> /// <param name="name">Name of variable</param> /// <returns></returns> public bool IsDefined(string name) { return(Vars.ContainsKey(name) || (ParentCollection?.IsDefined(name)).GetValueOrDefault()); }
public void Remove() { ParentCollection.Remove(this); }
private void AddConnectionWith(ArrayDCN <T> typedNode, ConnectionDirection direction) { Helpers <T> .Verify_AddConnectionWith_ConditionsAreSatisfied(typedNode, this); ParentCollection.ConnectNodes(this, typedNode, direction); }
protected Settings() { _derivedUnits = new ParentCollection <Settings, DerivedUnit>(this, (unit, settings) => unit.Settings = settings); _siUnits = new ParentCollection <Settings, SiUnit>(this, (unit, settings) => unit.Settings = settings); }
protected UnitBase() { _conversions = new ParentCollection <UnitBase, Conversion>(this, (unit, parent) => unit.BaseUnit = parent); Quantity = new Quantity(this); }
public void EndEdit() { if (beginEditCalled) { backupData = new CustomerData(); beginEditCalled = false; Console.WriteLine("Done EndEdit - " + this.custData.id + this.custData.lastName); if (ForwardEditableObject != null) { ForwardEditableObject.EndEdit(); } if (ParentCollection != null && modified) { this.ParentCollection.RaiseListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, ParentCollection.IndexOf(this), -1)); } modified = false; } }
public void _0001_Test() { //https://msdn.microsoft.com/en-us/library/system.data.datatable.childrelations(v=vs.110).aspx ParentCollection parents = new ParentCollection(); parents.Add(new ParentItem(1, "Parent-1")); parents.Add(new ParentItem(2, "Parent-2")); parents.Add(new ParentItem(3, "Parent-3")); parents.Add(new ParentItem(4, "Parent-4")); ChildCollection childs = new ChildCollection(); childs.Add(new ChildItem(1, "Child-1", 1)); childs.Add(new ChildItem(2, "Child-2", 1)); childs.Add(new ChildItem(3, "Child-3", 3)); childs.Add(new ChildItem(4, "Child-4", 4)); childs.Add(new ChildItem(5, "Child-5", 3)); childs.Add(new ChildItem(6, "Child-6", 4)); /*Data SET*/ DataSet dataSet = new DataSet("DemoDataSet"); /*Parent*/ /*ParentId-PK,ParentName*/ DataTable parentsDt = ToDataTable(parents, "Parents"); parentsDt.PrimaryKey = new DataColumn[] { parentsDt.Columns["ParentId"] }; dataSet.Tables.Add(parentsDt); /*Childs*/ /*ChildId-PK, ChildName, ParentId*/ DataTable childsDt = ToDataTable(childs, "Childs"); childsDt.PrimaryKey = new DataColumn[] { parentsDt.Columns["ChildId"] }; DataColumn parentsNameColumn = new DataColumn("ParentName", typeof(string)); childsDt.Columns.Add(parentsNameColumn); dataSet.Tables.Add(childsDt); /*SzÜlők gyerekei reláció*/ /*A szülő táblán végig lépkedve megtudható a szülők gyerekei*/ /*A szülő táblázat lesz amiben megjelnnek az eredmények!*/ DataRelation parentChildRelation = dataSet.Relations.Add("ParentChilds", dataSet.Tables["Parents"].Columns["ParentId"], dataSet.Tables["Childs"].Columns["ParentId"], false); foreach (DataRow parent in parentsDt.Rows) { /*Itt használja a relációt*/ DataRow[] children = parent.GetChildRows(parentChildRelation); //A Child táblával dolgozik Console.WriteLine("\n{0}, has {1} children", parent["ParentName"].ToString(), children.Count <DataRow>()); foreach (DataRow child in children) { Console.WriteLine("\t{0}", child["ChildName"].ToString()); } } Form2 f2 = new Form2(); f2.dataGridView1.DataSource = dataSet; f2.dataGridView1.DataMember = "Parents"; /*A szülők gyerekei*/ /*Egy szülőnek több gyereke is lehet, ezért az eredmény táblázat a gyerek számával nő, a szülők ismétlődnek*/ /*Ez a JOIN*/ var results = from table1 in parentsDt.AsEnumerable() join table2 in childsDt.AsEnumerable() on table1["ParentId"] equals table2["ParentId"] select new { ParentId = table1["ParentId"], ParentName = table1["ParentName"], ChildName = table2["ChildName"], }; var list = results.ToList(); f2.dataGridView2.DataSource = list; Application.Run(f2); }