/// <summary> /// 移除节点方法 /// </summary> public virtual void onRemovingNode() { m_indent = 0; FCGridRow row = Row; if (row != null) { if (m_nodes != null && m_nodes.size() > 0) { int nodeSize = m_nodes.size(); for (int i = 0; i < nodeSize; i++) { m_nodes.get(i).onRemovingNode(); } } m_tree.removeRow(row); row.clearCells(); Row = null; ArrayList <FCGridRow> rows = m_tree.getRows(); int rowSize = rows.size(); for (int i = 0; i < rowSize; i++) { rows.get(i).Index = i; } m_targetColumn = null; } }
/// <summary> /// 删除类 /// </summary> public void deleteClass() { List <FCGridRow> selectedRows = m_tvCollection.SelectedRows; int selectedRowsSize = selectedRows.Count; if (selectedRowsSize > 0) { if (m_collectionName == "TabPages") { FCTabControl tabControl = m_target as FCTabControl; FCTabPage tabPage = selectedRows[0].Tag as FCTabPage; m_xml.removeControl(tabPage); m_tvCollection.removeRow(selectedRows[0]); m_tvCollection.update(); tabControl.update(); } else if (m_collectionName == "Columns") { FCGrid grid = m_target as FCGrid; FCGridColumn column = selectedRows[0].Tag as FCGridColumn; grid.removeColumn(column); m_xml.m_controls.Remove(column); m_xml.Nodes[column].ParentNode.RemoveChild(m_xml.Nodes[column]); m_xml.Nodes.Remove(column); m_tvCollection.removeRow(selectedRows[0]); m_tvCollection.update(); grid.update(); } Native.invalidate(); m_designerDiv.saveUndo(); } }
/// <summary> /// 保存配置 /// </summary> public void save() { List <FCGridColumn> columns = m_columns; int columnsSize = columns.Count; String sortStr = ""; for (int i = 0; i < columnsSize; i++) { FCGridColumn column = columns[i]; if (column == m_orderColumn) { sortStr += "1"; } else if (column == m_nameColumn) { sortStr += "2"; } else if (column == m_valueColumn) { sortStr += "3"; } else if (column == m_enNameColumn) { sortStr += "4"; } } UserCookie cookie = new UserCookie(); cookie.m_key = "PROPERTYGRIDCOLUMNS"; cookie.m_value = sortStr; DataCenter.UserCookieService.AddCookie(cookie); }
/// <summary> /// 表格选中行改变方法 /// </summary> public void onGridSelectedRowsChanged() { List <FCGridRow> selectedRows = m_tvCollection.SelectedRows; int selectedRowsSize = selectedRows.Count; if (selectedRowsSize > 0) { if (selectedRows[0].Tag != null) { List <FCView> targets = new List <FCView>(); if (m_collectionName == "TabPages") { FCTabPage tabPage = selectedRows[0].Tag as FCTabPage; targets.Add(tabPage); } else if (m_collectionName == "Columns") { FCGridColumn column = selectedRows[0].Tag as FCGridColumn; targets.Add(column); } m_gridProperty.clearTargets(); m_gridProperty.addTargets(targets); } } }
/// <summary> /// 添加单元格 /// </summary> /// <param name="column">列索引</param> /// <param name="cell">单元格</param> public void addCell(FCGridColumn column, FCGridCell cell) { cell.Grid = m_grid; cell.Column = column; cell.Row = this; m_cells.add(cell); cell.onAdd(); }
/// <summary> /// 加载树的模板 /// </summary> /// <param name="tree">树</param> /// <param name="node">节点</param> public static void TreeTemplate(FCTree tree, UIXmlEx xml, XmlNode node) { XmlDocument xmlDoc = node.OwnerDocument; tree.Size = new FCSize(200, 200); FCGridColumn column = new FCGridColumn("Column1"); column.AllowSort = false; tree.addColumn(column); FCGridColumn column2 = new FCGridColumn("Column2"); column2.AllowSort = false; tree.addColumn(column2); tree.update(); FCTreeNode treeNode = new FCTreeNode(); treeNode.Text = "Node1"; tree.appendNode(treeNode); FCTreeNode subTreeNode = new FCTreeNode(); subTreeNode.Text = "Node2"; treeNode.appendNode(subTreeNode); tree.update(); XmlNode columnsNode = xmlDoc.CreateNode(XmlNodeType.Element, "tr", ""); node.AppendChild(columnsNode); XmlNode column1Node = xmlDoc.CreateNode(XmlNodeType.Element, "th", ""); columnsNode.AppendChild(column1Node); XmlAttribute xmlAtr1 = xmlDoc.CreateAttribute("text"); xmlAtr1.Value = "Column1"; column1Node.Attributes.Append(xmlAtr1); XmlNode column2Node = xmlDoc.CreateNode(XmlNodeType.Element, "th", ""); columnsNode.AppendChild(column2Node); XmlAttribute xmlAtr2 = xmlDoc.CreateAttribute("text"); xmlAtr2.Value = "Column2"; column2Node.Attributes.Append(xmlAtr2); XmlNode nodesNode = xmlDoc.CreateNode(XmlNodeType.Element, "nodes", ""); node.AppendChild(nodesNode); XmlNode nodeNode = xmlDoc.CreateNode(XmlNodeType.Element, "node", ""); nodesNode.AppendChild(nodeNode); XmlAttribute xmlAtr3 = xmlDoc.CreateAttribute("text"); xmlAtr3.Value = "Node1"; nodeNode.Attributes.Append(xmlAtr3); XmlNode subNodeNode = xmlDoc.CreateNode(XmlNodeType.Element, "node", ""); nodeNode.AppendChild(subNodeNode); XmlAttribute xmlAtr4 = xmlDoc.CreateAttribute("text"); xmlAtr4.Value = "Node2"; subNodeNode.Attributes.Append(xmlAtr4); }
/// <summary> /// 移除列头 /// </summary> /// <param name="column">列头</param> public override void removeColumn(FCGridColumn column) { FCBandedFCGridColumn bandedColumn = column as FCBandedFCGridColumn; if (bandedColumn != null) { m_columns.remove(column); removeControl(column); } }
/// <summary> /// 添加列 /// </summary> /// <param name="column">列</param> public override void addColumn(FCGridColumn column) { FCBandedFCGridColumn bandedColumn = column as FCBandedFCGridColumn; if (bandedColumn != null) { column.Grid = this; m_columns.add(column); addControl(column); } }
/// <summary> /// 根据列获取单元格 /// </summary> /// <param name="column">列</param> /// <returns>单元格</returns> public FCGridCell getCell(FCGridColumn column) { int cellSize = m_cells.size(); for (int i = 0; i < cellSize; i++) { if (m_cells.get(i).Column == column) { return(m_cells.get(i)); } } return(null); }
/// <summary> /// 移除单元格 /// </summary> /// <param name="column">列</param> public void removeCell(FCGridColumn column) { int cellSize = m_cells.size(); for (int i = 0; i < cellSize; i++) { FCGridCell cell = m_cells.get(i); if (cell.Column == column) { m_cells.remove(cell); cell.onRemove(); break; } } }
/// <summary> /// 加载表格的模板 /// </summary> /// <param name="node">节点</param> public static void GridTemplate(FCGrid grid, UIXmlEx xml, XmlNode node) { XmlDocument xmlDoc = node.OwnerDocument; grid.Size = new FCSize(200, 200); FCGridColumn column = new FCGridColumn("Column1"); grid.addColumn(column); FCGridColumn column2 = new FCGridColumn("Column2"); grid.addColumn(column2); grid.update(); FCGridRow row = new FCGridRow(); grid.addRow(row); FCGridStringCell cell = new FCGridStringCell(); cell.setString("Cell1"); row.addCell(0, cell); FCGridStringCell cell2 = new FCGridStringCell(); cell2.setString("Cell2"); row.addCell(1, cell2); grid.update(); XmlNode columnsNode = xmlDoc.CreateNode(XmlNodeType.Element, "tr", ""); node.AppendChild(columnsNode); XmlNode column1Node = xmlDoc.CreateNode(XmlNodeType.Element, "th", ""); column1Node.InnerText = "Column1"; columnsNode.AppendChild(column1Node); XmlNode column2Node = xmlDoc.CreateNode(XmlNodeType.Element, "th", ""); column2Node.InnerText = "Column2"; columnsNode.AppendChild(column2Node); XmlNode rowNode = xmlDoc.CreateNode(XmlNodeType.Element, "tr", ""); node.AppendChild(rowNode); XmlNode cellNode1 = xmlDoc.CreateNode(XmlNodeType.Element, "td", ""); rowNode.AppendChild(cellNode1); cellNode1.InnerText = "Cell1"; XmlNode cellNode2 = xmlDoc.CreateNode(XmlNodeType.Element, "td", ""); rowNode.AppendChild(cellNode2); cellNode2.InnerText = "Cell2"; }
/// <summary> /// 显示 /// </summary> public override void showDialog() { if (m_collectionName == "TabPages") { FCTabControl tabControlA = m_target as FCTabControl; List <FCTabPage> tabPages = tabControlA.getTabPages(); int tabPagesSize = tabPages.Count; for (int i = 0; i < tabPagesSize; i++) { FCTabPage tabPage = tabPages[i]; FCTreeNode node = new FCTreeNode(); node.setString(tabPage.Text); m_tvCollection.appendNode(node); node.Row.Tag = tabPage; } } else if (m_collectionName == "Columns") { FCGrid grid = m_target as FCGrid; List <FCGridColumn> columns = grid.getColumns(); int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { FCGridColumn column = columns[i]; FCTreeNode node = new FCTreeNode(); node.setString(column.Text); m_tvCollection.appendNode(node); node.Row.Tag = column; } } m_tvCollection.update(); m_gridSelectedRowsChangedEvent = new FCEvent(gridSelectedRowsChanged); m_gridProperty.Xml = m_xml; m_gridProperty.DesignerDiv = m_designerDiv; m_tvCollection.addEvent(m_gridSelectedRowsChangedEvent, FCEventID.GRIDSELECTEDROWSCHANGED); if (m_tvCollection.getRows().Count > 0) { ArrayList <FCGridRow> selectedRows = new ArrayList <FCGridRow>(); selectedRows.Add(m_tvCollection.getRow(0)); m_tvCollection.SelectedRows = selectedRows; } base.showDialog(); }
/// <summary> /// 添加控件方法 /// </summary> public override void onLoad() { base.onLoad(); if (m_grid == null) { m_grid = new FCGrid(); m_grid.AutoEllipsis = true; m_grid.GridLineColor = FCColor.None; m_grid.Size = new FCSize(240, 200); m_grid.addEvent(m_gridCellClickEvent, FCEventID.GRIDCELLCLICK); m_grid.addEvent(m_gridKeyDownEvent, FCEventID.KEYDOWN); addControl(m_grid); m_grid.beginUpdate(); //添加列 FCGridColumn securityCodeColumn = new FCGridColumn("股票代码"); securityCodeColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; securityCodeColumn.BorderColor = FCColor.None; securityCodeColumn.Font = new FCFont("Simsun", 14, true, false, false); securityCodeColumn.TextColor = FCDraw.FCCOLORS_FORECOLOR; securityCodeColumn.TextAlign = FCContentAlignment.MiddleLeft; securityCodeColumn.Width = 120; m_grid.addColumn(securityCodeColumn); FCGridColumn securityNameColumn = new FCGridColumn("股票名称"); securityNameColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; securityNameColumn.BorderColor = FCColor.None; securityNameColumn.Font = new FCFont("Simsun", 14, true, false, false); securityNameColumn.TextColor = FCDraw.FCCOLORS_FORECOLOR; securityNameColumn.TextAlign = FCContentAlignment.MiddleLeft; securityNameColumn.Width = 110; m_grid.addColumn(securityNameColumn); m_grid.endUpdate(); } if (m_searchTextBox == null) { m_searchTextBox = new FCTextBox(); m_searchTextBox.Location = new FCPoint(0, 200); m_searchTextBox.Size = new FCSize(240, 20); m_searchTextBox.Font = new FCFont("SimSun", 16, true, false, false); m_searchTextBox.addEvent(m_textBoxInputChangedEvent, FCEventID.TEXTCHANGED); m_searchTextBox.addEvent(m_textBoxKeyDownEvent, FCEventID.KEYDOWN); addControl(m_searchTextBox); } }
/// <summary> /// 设置控件不可见方法 /// </summary> public override void onSetEmptyClipRegion() { //隐藏控件 ArrayList <FCView> controls = m_controls; int controlsSize = controls.size(); FCRect emptyClipRect = new FCRect(); for (int i = 0; i < controlsSize; i++) { FCView control = controls.get(i); FCScrollBar scrollBar = control as FCScrollBar; FCGridColumn gridColumn = control as FCGridColumn; FCGridBand gridBand = control as FCGridBand; if (control != EditTextBox && scrollBar == null && gridColumn == null && gridBand == null) { control.Region = emptyClipRect; } } }
/// <summary> /// 创建表格列 /// </summary> /// <param name="node">节点</param> /// <param name="control">控件</param> protected virtual void createGridColumns(XmlNode node, FCView control) { FCGrid grid = control as FCGrid; foreach (XmlNode subNode in node.ChildNodes) { FCView subControl = createControl(subNode, subNode.Name.ToLower()); FCGridColumn column = subControl as FCGridColumn; if (column != null) { column.Native = m_native; grid.addColumn(column); } setAttributesBefore(subNode, subControl); readChildNodes(subNode, subControl); setAttributesAfter(subNode, subControl); if (subNode.InnerText.Length > 0) { column.Text = subNode.InnerText; } onAddControl(subControl, subNode); } }
/// <summary> /// 添加节点 /// </summary> /// <param name="index">行索引</param> public virtual void onAddingNode(int index) { FCGridRow row = Row; if (Row == null) { //创建行 row = new FCGridRow(); FCTreeNode parentNode = m_parent; if (parentNode == null) { if (index != -1) { //插入行 m_tree.insertRow(index, row); //重置行的索引 ArrayList <FCGridRow> rows = m_tree.getRows(); int rowSize = rows.size(); for (int i = 0; i < rowSize; i++) { rows.get(i).Index = i; } } else { //添加行 m_tree.addRow(row); //设置索引 ArrayList <FCGridRow> rows = m_tree.getRows(); row.Index = rows.size() - 1; } row.addCell(0, this); m_targetColumn = m_tree.getColumn(0); } else { //获取行索引 int rowIndex = parentNode.Row.Index + 1; if (index != -1) { rowIndex = index; } else { //查找上个节点 FCTreeNode lastNode = getLastNode(parentNode.getChildNodes()); if (lastNode != null) { if (lastNode.Row == null) { return; } rowIndex = lastNode.Row.Index + 1; } } //插入行 m_tree.insertRow(rowIndex, row); ArrayList <FCGridRow> rows = m_tree.getRows(); int rowSize = rows.size(); //重置索引 if (rowIndex == rowSize - 1) { row.Index = rowIndex; } else { for (int i = 0; i < rowSize; i++) { rows.get(i).Index = i; } } row.addCell(0, this); m_targetColumn = m_tree.getColumn(parentNode.m_targetColumn.Index + 1); } ColSpan = m_tree.getColumns().size(); //添加子节点 if (m_nodes != null && m_nodes.size() > 0) { int nodeSize = m_nodes.size(); for (int i = 0; i < nodeSize; i++) { m_nodes.get(i).onAddingNode(-1); } } row.Visible = isNodeVisible(this); } }
/// <summary> /// 拖动中方法 /// </summary> public override void onDragging() { base.onDragging(); if (m_grid != null) { ArrayList <FCGridColumn> columns = m_grid.getColumns(); int columnSize = columns.size(); for (int i = 0; i < columnSize; i++) { FCGridColumn column = columns.get(i); if (column == this) { FCGridColumn lastColumn = null; FCGridColumn nextColumn = null; int lastIndex = i - 1; int nextIndex = i + 1; while (lastIndex >= 0) { FCGridColumn thatColumn = columns.get(lastIndex); if (thatColumn.Visible) { lastColumn = thatColumn; break; } else { lastIndex--; } } while (nextIndex < columnSize) { FCGridColumn thatColumn = columns.get(nextIndex); if (thatColumn.Visible) { nextColumn = thatColumn; break; } else { nextIndex++; } } //交换列 FCNative native = Native; int clientX = native.clientX(this); if (lastColumn != null) { int lastClientX = native.clientX(lastColumn); if (clientX < lastClientX + lastColumn.Width / 2) { columns.set(lastIndex, this); columns.set(i, lastColumn); m_grid.update(); break; } } if (nextColumn != null) { int nextClientX = native.clientX(nextColumn); if (clientX + column.Width > nextClientX + nextColumn.Width / 2) { columns.set(nextIndex, this); columns.set(i, nextColumn); m_grid.update(); break; } } break; } } } }
/// <summary> /// 添加控件方法 /// </summary> public override void onLoad() { base.onLoad(); String sortStr = "1432"; UserCookie cookie = new UserCookie(); if (DataCenter.UserCookieService.GetCookie("PROPERTYGRIDCOLUMNS", ref cookie) > 0) { sortStr = cookie.m_value; } foreach (char ch in sortStr) { switch (ch) { case '1': //创建序号列 if (m_orderColumn == null) { m_orderColumn = new GridColumnEx(); m_orderColumn.TextColor = FCDraw.FCCOLORS_TEXTCOLOR; m_orderColumn.Font = new FCFont("微软雅黑", 12, false, false, false); m_orderColumn.Text = "序号"; m_orderColumn.Name = "NO"; m_orderColumn.Width = 30; m_orderColumn.AllowResize = true; m_orderColumn.AllowSort = false; m_orderColumn.AllowDrag = true; m_orderColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; addColumn(m_orderColumn); } break; case '2': //创建名称列 if (m_nameColumn == null) { m_nameColumn = new GridColumnEx(); m_nameColumn.TextColor = FCDraw.FCCOLORS_TEXTCOLOR; m_nameColumn.Font = new FCFont("微软雅黑", 12, false, false, false); m_nameColumn.Text = "属性名称"; m_nameColumn.Name = "PROPERTYNAME"; m_nameColumn.Width = 120; m_nameColumn.AllowResize = true; m_nameColumn.AllowDrag = true; m_nameColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; addColumn(m_nameColumn); } break; case '3': //创建属性值列 if (m_valueColumn == null) { m_valueColumn = new GridColumnEx(); m_valueColumn.TextColor = FCDraw.FCCOLORS_TEXTCOLOR; m_valueColumn.Font = new FCFont("微软雅黑", 12, false, false, false); m_valueColumn.Text = "属性值"; m_valueColumn.Name = "PROPERTYVALUE"; m_valueColumn.Width = 120; m_valueColumn.AllowResize = true; m_valueColumn.AllowDrag = true; m_valueColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; addColumn(m_valueColumn); } break; case '4': //创建英文属性列 if (m_enNameColumn == null) { m_enNameColumn = new GridColumnEx(); m_enNameColumn.TextColor = FCDraw.FCCOLORS_TEXTCOLOR; m_enNameColumn.Font = new FCFont("微软雅黑", 12, false, false, false); m_enNameColumn.Text = "英文名称"; m_enNameColumn.Name = "ENNAME"; m_enNameColumn.Width = 120; m_enNameColumn.AllowResize = true; m_enNameColumn.AllowDrag = true; m_enNameColumn.BackColor = FCDraw.FCCOLORS_BACKCOLOR; addColumn(m_enNameColumn); } break; } } }
/// <summary> /// 添加类 /// </summary> public void addClass() { XmlDocument xmlDoc = m_xml.XmlDoc; if (m_collectionName == "TabPages") { FCTabControl tabControl = m_target as FCTabControl; FCTabPage tabPage = new FCTabPage(); tabControl.addControl(tabPage); String newControlName = UITemplate.CreateControlName(tabPage, m_xml); tabPage.Name = newControlName; tabPage.Text = newControlName; XmlNode tabControlNode = m_xml.Nodes[tabControl]; XmlNode tabpageNode = m_xml.XmlDoc.CreateNode(XmlNodeType.Element, "div", ""); tabControlNode.AppendChild(tabpageNode); XmlAttribute xmlAtr1 = xmlDoc.CreateAttribute("name"); xmlAtr1.Value = tabPage.Text; tabpageNode.Attributes.Append(xmlAtr1); XmlAttribute xmlAtr2 = xmlDoc.CreateAttribute("text"); xmlAtr2.Value = tabPage.Text; tabpageNode.Attributes.Append(xmlAtr2); XmlAttribute xmlAtr3 = xmlDoc.CreateAttribute("type"); xmlAtr3.Value = "tabpage"; tabpageNode.Attributes.Append(xmlAtr3); m_xml.m_controls.Add(tabPage); m_xml.Nodes[tabPage] = tabpageNode; FCTreeNode node = new FCTreeNode(); node.setString(tabPage.Name); m_tvCollection.appendNode(node); node.Row.Tag = tabPage; m_tvCollection.update(); m_tvCollection.selectNextRow(); tabControl.update(); } else if (m_collectionName == "Columns") { FCGrid grid = m_target as FCGrid; FCGridColumn column = new FCGridColumn(); grid.addColumn(column); String newControlName = UITemplate.CreateControlName(column, m_xml); column.Name = newControlName; column.Text = newControlName; XmlNode gridNode = m_xml.Nodes[grid]; XmlNode columnsNode = null; foreach (XmlNode subNode in gridNode.ChildNodes) { if (subNode.Name.ToLower() == "columns" || subNode.Name.ToLower() == "tr") { columnsNode = subNode; break; } } if (columnsNode == null) { columnsNode = xmlDoc.CreateNode(XmlNodeType.Element, "tr", ""); gridNode.AppendChild(columnsNode); } XmlNode columnNode = m_xml.XmlDoc.CreateNode(XmlNodeType.Element, "th", ""); columnNode.InnerText = column.Text; columnsNode.AppendChild(columnNode); XmlAttribute xmlAtr1 = xmlDoc.CreateAttribute("name"); xmlAtr1.Value = column.Text; columnNode.Attributes.Append(xmlAtr1); m_xml.m_controls.Add(column); m_xml.Nodes[column] = columnNode; FCTreeNode node = new FCTreeNode(); node.setString(column.Name); m_tvCollection.appendNode(node); node.Row.Tag = column; grid.update(); } m_tvCollection.update(); m_tvCollection.selectNextRow(); Native.invalidate(); m_designerDiv.saveUndo(); }