private TreeGridNodeCollection FindNodesByPortfolio(SmartQuant.Portfolio portfolio) { // 找到对应的节点然后再,然后再做决定 TreeGridNodeCollection Nodes = null; if (portfolio.Parent == null) { // 根节点 Nodes = this.treeGridView1.Nodes; } else { // 子节点 TreeGridNode _node; if (portfolio_nodes.TryGetValue(portfolio.Parent, out _node)) { Nodes = _node.Nodes; } else { Nodes = this.treeGridView1.Nodes; } } return(Nodes); }
private void CreateTreeView(databases.baseDS.portfolioDetailDataTable dataTbl, TreeGridView treeGV) { if (this.myPorfolioCode == null || this.myStockCode == null) { return; } DataView dataView = new DataView(dataTbl); dataView.Sort = dataTbl.subCodeColumn.ColumnName; dataView.RowFilter = dataTbl.portfolioColumn + "='" + this.myPorfolioCode + "' AND " + dataTbl.codeColumn + "='" + this.myStockCode + "'"; databases.baseDS.portfolioDetailRow dataRow; Font boldFont = new Font(treeGV.DefaultCellStyle.Font, FontStyle.Bold); string lastStrategy = ""; TreeGridNodeCollection strategyNodes = null; for (int idx = 0; idx < dataView.Count; idx++) { dataRow = (databases.baseDS.portfolioDetailRow)dataView[idx].Row; if (lastStrategy != dataRow.subCode.Trim()) { strategyNodes = AddNode(treeGV.Nodes, dataRow.subCode, GetStrategyDescription(dataRow.subCode), boldFont).Nodes; lastStrategy = dataRow.subCode.Trim(); } AddNodes((strategyNodes == null ? treeGV.Nodes : strategyNodes), dataRow, null); } }
private TreeGridNode AddPortfolio(SmartQuant.Portfolio portfolio, TreeGridNodeCollection Nodes, bool hasChildren) { // 添加投资组合 var node = Nodes.Add( portfolio.Name, null, null, null, null, portfolio.AccountValue, null, DateTime.Today ); node.Cells[IDX_Symbol].ReadOnly = false; node.Cells[IDX_Symbol].Style.BackColor = Color.LightYellow; node.Cells[IDX_Long].ReadOnly = true; node.Cells[IDX_Short].ReadOnly = true; node.Cells[IDX_AccountValue].Style.BackColor = Color.LightYellow; node.Cells[IDX_EntryDate].Style.BackColor = Color.LightYellow; // 记录下,下次添加子节点使用 portfolio_nodes.Add(portfolio, node); // 记录下,用于回头修改持仓,它一般有子节点 nodes_position_portfolio.Add(node, portfolio); if (!hasChildren) { node.DefaultCellStyle.BackColor = Color.LightPink; } return(node); }
private void BuildTree(TreeGridNodeCollection nodes, Node value) { var node = nodes.Add(value.m_value); foreach (var child in value.m_children) { BuildTree(node.Nodes, child); } }
/// <summary> /// Загрузка дерева рецептур в таблицу /// </summary> /// <param name="nodes">коллекция строк</param> /// <param name="data">рецептура</param> private void LoadReceptData(TreeGridNodeCollection nodes, DataRecept data) { TreeGridNode curNode = null; foreach (DataBase dr in data.Components) { //MessageBox.Show("Start Load: " + dr.name); // если компонента рецептуры есть сама рецептура, то делаем рекурсию if (dr is DataRecept) { DataRecept rec = dr as DataRecept; curNode = new TreeGridNode(); curNode.DefaultCellStyle.BackColor = Color.LightGray; curNode.Tag = rec; nodes.Add(curNode); curNode.Cells[dgvRecName.Index].Value = rec.Name; curNode.Cells[dgvRecCountNetto.Index].Value = rec.TotalExit; LoadReceptData(curNode.Nodes, rec); continue; } // иначе это обычная компонента и мы ее загружаем в корень DataRaw curRaw = dr as DataRaw; curNode = new TreeGridNode(); curNode.Tag = curRaw; nodes.Add(curNode); curNode.Cells[dgvRecCountNetto.Index].Value = (curRaw.Quantity != 0 ? curRaw.Quantity.ToString(CultureInfo.CurrentCulture) : string.Empty); curNode.Cells[dgvRecCountBrutto.Index].Value = (curRaw.Brutto != 0 ? curRaw.Brutto.ToString(CultureInfo.CurrentCulture) : string.Empty); curNode.Cells[dgvRecComment.Index].Value = curRaw.Comment; if (curRaw.RawStruct != null) { curNode.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember; if (curRaw.Brutto == 0 && curRaw.Quantity != 0 && curRaw.RawStruct.Brutto != 0) { curNode.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto); } if (curRaw.Quantity == 0 && curRaw.RawStruct.Brutto != 0 && curRaw.Brutto != 0) { curNode.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto); } } if (curRaw.ProcessLoss != null) { (curNode.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value = curRaw.ProcessLoss.ValueMember; } } // добавляем пустую новую строку для каждой рецептуры nodes.Add(new TreeGridNode()); }
private static TreeGridNode AddNode(TreeGridNodeCollection parentNodes, string strategyCode, string strategyDescription, Font fon) { TreeGridNode node; node = parentNodes.Add(strategyCode + " - " + strategyDescription); node.Tag = new nodeData(strategyCode, AppTypes.MainDataTimeScale.Code); if (fon != null) { node.DefaultCellStyle.Font = fon; } node.ImageIndex = 0; return(node); }
private void AddNodes_Portfolio(SmartQuant.Portfolio portfolio) { // 找到对应的节点然后再,然后再做决定 TreeGridNodeCollection Nodes = FindNodesByPortfolio(portfolio); if (Nodes == null) { return; } TreeGridNode node = null; bool hasChildren = portfolio.Children.Count > 0; node = AddPortfolio(portfolio, Nodes, hasChildren); node.Expand(); }
private static void AddNodes(TreeGridNodeCollection parentNodes, databases.baseDS.portfolioDetailRow row, Font fon) { StringCollection list = common.MultiValueString.String2List(row.data.Trim()); TreeGridNode node; for (int idx = 0; idx < list.Count; idx++) { node = parentNodes.Add(list[idx]); node.Tag = new nodeData(row.subCode.Trim(), list[idx]); node.ImageIndex = 1; if (fon != null) { node.DefaultCellStyle.Font = fon; } } }
private TreeGridNode FindParentNode(TreeGridNodeCollection nodes, Predicate <TreeGridNode> predicate) { foreach (TreeGridNode node in nodes) { if (predicate(node)) { return(node); } else { TreeGridNode nodeChild = FindParentNode(node.Nodes, predicate); if (nodeChild != null) { return(nodeChild); } } } return(null); }
private void AddPositions(SmartQuant.Portfolio portfolio, TreeGridNodeCollection Nodes, bool hasChildren) { // 检查是否有持仓 foreach (var position in portfolio.Positions) { // 添加持仓 var entryPrice = 0.0; var entyDate = DateTime.Today; if (position.Fills.Count > 0) { entryPrice = position.Fills.Last().Price; entyDate = position.Fills.Last().DateTime; } var _node = Nodes.Add( portfolio.Name, position.Instrument.Symbol, position.Amount, position.LongPositionQty, position.ShortPositionQty, null, entryPrice, entyDate ); _node.Cells[IDX_Symbol].ReadOnly = true; _node.Cells[IDX_Long].Style.BackColor = Color.LightYellow; _node.Cells[IDX_Short].Style.BackColor = Color.LightYellow; _node.Cells[IDX_AccountValue].ReadOnly = true; _node.Cells[IDX_EntryPrice].Style.BackColor = Color.LightYellow; _node.Cells[IDX_EntryDate].Style.BackColor = Color.LightYellow; if (!hasChildren) { _node.DefaultCellStyle.BackColor = Color.LightGreen; } // 记录下,用于回头修改持仓,它没有子节点 nodes_position_portfolio.Add(_node, position); } }
private void SyncRows(List <IFieldModel> modelNodes, TreeGridNodeCollection viewNodes) { foreach (var model in modelNodes) { var row = viewNodes.OfType <FieldRow>().FirstOrDefault(r => r.Model == model); if (row == null) { row = new FieldRow(model); viewNodes.Add(row); //XRay.LogMessage("Row added"); ModelRowMap[model.ID] = row; if (model.PossibleSubNodes) { row.Nodes.Add("Loading..."); } } row.SyncCells(); } }
private void AddNodes(SmartQuant.Portfolio portfolio, ShowType show_type) { // 找到对应的节点然后再,然后再做决定 TreeGridNodeCollection Nodes = FindNodesByPortfolio(portfolio); if (Nodes == null) { return; } TreeGridNode node = null; bool hasChildren = portfolio.Children.Count > 0; switch (show_type) { case ShowType.All: node = AddPortfolio(portfolio, Nodes, hasChildren); AddPositions(portfolio, node.Nodes, hasChildren); node.Expand(); break; case ShowType.PortfolioOnly: node = AddPortfolio(portfolio, Nodes, hasChildren); node.Expand(); break; case ShowType.PositionOnly: // 只显示根节点 // 注意,如果出现在父节点上添加持仓将无法处理,所以最好不要使用特别的用法 if (hasChildren) { return; } AddPositions(portfolio, this.treeGridView1.Nodes, hasChildren); break; } }
private void SyncRows(List<IFieldModel> modelNodes, TreeGridNodeCollection viewNodes) { foreach (var model in modelNodes) { var row = viewNodes.OfType<FieldRow>().FirstOrDefault(r => r.Model == model); if (row == null) { row = new FieldRow(model); viewNodes.Add(row); XRay.LogMessage("Row added"); ModelRowMap[model.ID] = row; if (model.PossibleSubNodes) row.Nodes.Add("Loading..."); } row.SyncCells(); } }
private TreeGridNode AddNode(ManagementBaseObject o, PropertyData p, TreeGridNodeCollection nodes) { TreeGridNode node = nodes.Add(p.Name, p.GetValueAsString(this.valueMaps)); string guid = GetGUID(); node.Tag = guid; this.objectMap.Add(guid, o); this.propertyMap.Add(guid, p); // Get property description var description = String.Empty; if (this.ManagementClass != null && this.managementClass.HasProperty(p.Name)) { description = this.ManagementClass.Properties[p.Name].GetDescription(); if (!String.IsNullOrEmpty(description)) description = "\r\n" + description; } // Set tooltip node.Cells[0].ToolTipText = String.Format( "{0} {1}.{2}{3}", p.Type.ToString() + (p.IsArray ? "[]" : String.Empty), this.ManagementObject.ClassPath.ClassName, p.Name, description ); // Highlight key columns if (p.IsKey()) { // Apply styles Font f = node._grid.DefaultCellStyle.Font; node.Cells[0].Style.Font = new Font(f.FontFamily, f.Size, FontStyle.Bold); } // Expand arrays if (p.Value != null && p.IsArray) { var values = p.GetValueAsStringArray(this.ShowMappedValues ? this.valueMaps : null); int i = 0; bool addValues = true; foreach (object value in values) { if (i >= MAX_ARRAY_MEMBERS) { addValues = false; } else { // Keep add values or just count them? if (addValues) { TreeGridNode child = node.Nodes.Add(String.Format("[{0}]", i), value.ToString()); child.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; child.Cells[0].Style.ForeColor = SystemColors.GrayText; } i++; } } // Add note if results were truncated if (!addValues) { TreeGridNode truncNode = node.Nodes.Add(String.Format("[...{0}]", i), "Results were truncated."); truncNode.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleRight; truncNode.Cells[0].Style.ForeColor = SystemColors.GrayText; } node.Cells[1].Value = String.Format("{0} [{1}]", p.Type, i); } // Expand Objects if (p.Type == CimType.Reference || p.Type == CimType.Object) { if (p.Value != null) { // TODO: What about object arrays? ManagementBaseObject refObject; if (p.Type == CimType.Reference && null != this.Scope) { refObject = new ManagementObject(this.Scope, new ManagementPath((String)p.Value), new ObjectGetOptions()); } else { refObject = (ManagementBaseObject) p.Value; } node.Cells[1].Value = refObject.GetRelativePath(); foreach (PropertyData subProperty in refObject.Properties) { TreeGridNode subNode = this.AddNode(refObject, subProperty, node.Nodes); string subGuid = GetGUID(); subNode.Tag = subGuid; this.objectMap.Add(subGuid, refObject); this.propertyMap.Add(subGuid, subProperty); } } else { node.Cells[1].Value = "NULL"; } } return node; }
public void OnExpanding() { try { if (!populated) { if (this._owner == null) { this._owner = this.Nodes; } foreach (ListItem item in Content.SubItems) { TreeGridNode tn = new TreeGridNode(this._grid, item); tn._owner = Nodes; tn._parent = this; tn.InExpanding = true; tn.UserRow = false; item.Changed += tn.OnContentChanged; tn.Update(); Nodes.Add(tn); } populated = true; //this.IsExpandedOnce = true; // this.Tree.UpdateSelection(); // this.Tree.FullUpdate(); } } catch (System.Exception e) { } }
public static void UpdateNodes(TreeGridView tree, TreeGridNodeCollection collection, IList<IListItem> contents) { // Add or overwrite existing items for (int i = 0; i < contents.Count; i++) { if (i < collection.Count) { // Overwrite //if (!contents[i].IsLiteral) ((TreeGridNode)collection[i]).Content = contents[i]; } else { // Add //if (!contents[i].IsLiteral) { TreeGridNode tn = new TreeGridNode(tree,contents[i]); tn.UserRow = false; tn.Update(); collection.Add(tn); } } } // Delete other nodes while (collection.Count > contents.Count) { collection.RemoveAt(collection.Count - 1); } //tree.Update(); // tree.UpdateSelection(); // tree.FullUpdate(); }
private static void AddNodes(TreeGridNodeCollection parentNodes,data.baseDS.portfolioDetailRow row, Font fon) { StringCollection list = common.MultiValueString.String2List(row.data.Trim()); TreeGridNode node; for (int idx = 0; idx < list.Count; idx++) { node = parentNodes.Add(list[idx]); node.Tag = new nodeData(row.subCode.Trim(), list[idx]); node.ImageIndex = 1; if (fon != null) node.DefaultCellStyle.Font = fon; } }
private static TreeGridNode AddNode(TreeGridNodeCollection parentNodes,string strategyCode, string strategyDescription, Font fon) { TreeGridNode node; node = parentNodes.Add(strategyCode + " - " + strategyDescription); node.Tag = new nodeData(strategyCode, AppTypes.MainDataTimeScale.Code); if (fon != null) node.DefaultCellStyle.Font = fon; node.ImageIndex = 0; return node; }
/// <summary> /// Проверка данных формы и данных рецептуры /// </summary> /// <param name="root">дерево строк формы</param> /// <param name="curRec">рецептура</param> private void CheckReceptData(TreeGridNodeCollection root, DataRecept curRec) { ArrayList toDelete = new ArrayList(); TreeGridNode lastNode = null; // собираем строчки для удаления if (dgvRawList.Nodes.Count > 0) { foreach (TreeGridNode dr in root) { // если это пустая последняя строчка, то пропускаем if (dr.Tag == null) { if (lastNode == null) { lastNode = dr; } else { toDelete.Add(dr); } continue; } DataBase curBase = (DataBase)dr.Tag; if (!curRec.Components.Contains(curBase)) { toDelete.Add(dr); continue; } // если это рецептура, то рекурсия проверки if (curBase is DataRecept) { CheckReceptData(dr.Nodes, curBase as DataRecept); continue; } DataRaw curRaw = curBase as DataRaw; if (curRaw.RawStruct != null) { if (!curRaw.RawStruct.DisplayMember.Equals(dr.Cells[dgvRecName.Index].Value)) { dr.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember; } } if (!((Decimal)curRaw.Brutto).Equals(dr.Cells[dgvRecCountBrutto.Index].Value)) { dr.Cells[dgvRecCountBrutto.Index].Value = curRaw.Brutto; } if (curRaw.ProcessLoss != null) { if (!curRaw.ProcessLoss.ValueMember.Equals((dr.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value)) { dr.Cells[dgvRecProcessLoss.Index].Value = curRaw.ProcessLoss.ValueMember; } } if (!curRaw.Quantity.Equals(dr.Cells[dgvRecCountNetto.Index].Value)) { dr.Cells[dgvRecCountNetto.Index].Value = curRaw.Quantity; } if (!curRaw.Comment.Equals(dr.Cells[dgvRecComment.Index].Value)) { dr.Cells[dgvRecComment.Index].Value = curRaw.Comment; } if (curRaw.RawStruct != null) { if (curRaw.Brutto == 0 && curRaw.Quantity != 0) { dr.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto); } if (curRaw.Quantity == 0 && curRaw.Brutto != 0 && curRaw.RawStruct.Brutto != 0) { dr.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto); } } } } if (toDelete.Count > 0) { foreach (TreeGridNode dr in toDelete) { root.Remove(dr); } } // добавление новых if (curRec.Components.Count > 0) { foreach (DataBase newRec in curRec.Components) { Boolean isExists = false; foreach (TreeGridNode dr in root) { if (newRec.Equals(dr.Tag)) { isExists = true; break; } } if (!isExists) { TreeGridNode node = new TreeGridNode(); node.Tag = newRec; root.Add(node); if (newRec is DataRecept) { //TreeGridNode curNode = root.Add(null, newRec.name, null, null, (newRec as DataRecept).totalExit, newRec.comment); node.Cells[dgvRecName.Index].Value = newRec.Name; node.Cells[dgvRecCountNetto.Index].Value = (newRec as DataRecept).TotalExit; node.DefaultCellStyle.BackColor = Color.LightGray; LoadReceptData(node.Nodes, newRec as DataRecept); continue; } DataRaw curRaw = newRec as DataRaw; //TreeGridNode newNode = root.Add(curRaw.id, null, null, curRaw.brutto, curRaw.quantity, curRaw.comment); node.Cells[dgvRecCountBrutto.Index].Value = curRaw.Brutto; node.Cells[dgvRecCountNetto.Index].Value = curRaw.Quantity; node.Cells[dgvRecComment.Index].Value = curRaw.Comment; if (curRaw.RawStruct != null) { node.Cells[dgvRecName.Index].Value = curRaw.RawStruct.DisplayMember; if (curRaw.Brutto == 0 && curRaw.Quantity != 0 && curRaw.RawStruct.Brutto != 0) { node.Cells[dgvRecCountBrutto.Index].Value = CommonFunctions.Round(curRaw.Quantity * curRaw.RawStruct.Brutto); } if (curRaw.Brutto != 0 && curRaw.Quantity == 0 && curRaw.RawStruct.Brutto != 0) { node.Cells[dgvRecCountNetto.Index].Value = CommonFunctions.Round(curRaw.Brutto / curRaw.RawStruct.Brutto); } } if (curRaw.ProcessLoss != null) { (node.Cells[dgvRecProcessLoss.Index] as DataGridViewComboBoxCell).Value = curRaw.ProcessLoss.ValueMember; } } } } // проверяем, чтобы последняя строчка была последней if (dgvRawList.Nodes.Count > 0 && (lastNode == null || !lastNode.IsLastSibling)) { root.Add(new TreeGridNode()); if (lastNode != null) { root.Remove(lastNode); } } }