/// <summary> /// 单元格点击事件 /// </summary> /// <param name="cell">单元格</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值</param> public override void onCellClick(FCGridCell cell, FCTouchInfo touchInto) { base.onCellClick(cell, touchInto); List <FCGridRow> rows = m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { FCGridRow row = rows[i]; List <FCGridCell> cells = row.getCells(); int cellsSize = cells.Count; for (int j = 0; j < cellsSize; j++) { FCGridControlCell cCell = cells[j] as FCGridControlCell; if (cCell != null) { if (row == cell.Row) { cCell.Control.TextColor = FCDraw.FCCOLORS_TEXTCOLOR4; } else { cCell.Control.TextColor = FCColor.Text; } } } } }
/// <summary> /// 表格单元格点击事件 /// </summary> /// <param name="sender">调用者</param> /// <param name="cell">单元格</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值</param> private void gridCellClick(object sender, FCGridCell cell, FCTouchInfo touchInfo) { if (touchInfo.m_firstTouch && touchInfo.m_clicks == 2) { onSelectRow(); } }
/// <summary> /// 绘制编辑文本框 /// </summary> /// <param name="cell">单元格</param> /// <param name="paint">绘图对象</param> /// <param name="rect">区域</param> /// <param name="clipRect">裁剪区域</param> public override void onPaintEditTextBox(FCGridCell cell, FCPaint paint, FCRect rect, FCRect clipRect) { FCTextBox editTextBox = EditTextBox; if (editTextBox != null) { FCTreeNode node = cell as FCTreeNode; if (node != null) { int indent = node.Indent; rect.left += indent; if (rect.right < rect.left) { rect.right = rect.left; } editTextBox.Bounds = rect; editTextBox.DisplayOffset = false; editTextBox.bringToFront(); } else { base.onPaintEditTextBox(cell, paint, rect, clipRect); } } }
/// <summary> /// 移除单元格 /// </summary> /// <param name="columnIndex">列索引</param> public void removeCell(int columnIndex) { int cellSize = m_cells.size(); if (columnIndex >= 0 && columnIndex < cellSize) { FCGridCell cell = m_cells.get(columnIndex); if (cell.Column.Index == columnIndex) { m_cells.remove(cell); cell.onRemove(); return; } for (int i = 0; i < cellSize; i++) { cell = m_cells.get(i); if (cell.Column.Index == columnIndex) { m_cells.remove(cell); cell.onRemove(); break; } } } }
/// <summary> /// 清除目标 /// </summary> public void clearTargets() { //保存上次编辑的控件属性 FCTextBox editTextBox = EditTextBox; if (editTextBox != null) { if (editTextBox.Tag != null) { FCGridCell editingCell = EditTextBox.Tag as FCGridCell; if (editingCell != null) { FCGridCell nameCell = editingCell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { String cellName = nameCell.Name; String cellValue = editTextBox.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { m_xml.setProperty(m_targets[i], cellName, cellValue); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(cellName, cellValue); } } } } } editTextBox.Visible = false; } m_targets.Clear(); }
/// <summary> /// 单元格触摸移动方法 /// </summary> /// <param name="cell">单元格</param> /// <param name="touchInfo">触摸信息</param> public override void onCellTouchMove(FCGridCell cell, FCTouchInfo touchInfo) { base.onCellTouchMove(cell, touchInfo); if (m_movingNode != null) { invalidate(); } }
/// <summary> /// 添加单元格 /// </summary> /// <param name="columnName">列名</param> /// <param name="cell">单元格</param> public void addCell(String columnName, FCGridCell cell) { cell.Grid = m_grid; cell.Column = m_grid.getColumn(columnName); cell.Row = this; m_cells.add(cell); cell.onAdd(); }
/// <summary> /// 添加单元格 /// </summary> /// <param name="columnIndex">列索引</param> /// <param name="cell">单元格</param> public void addCell(int columnIndex, FCGridCell cell) { cell.Grid = m_grid; cell.Column = m_grid.getColumn(columnIndex); cell.Row = this; m_cells.add(cell); cell.onAdd(); }
/// <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="cell">单元格</param> /// <param name="touchInfo">触摸信息</param> public override void onCellTouchDown(FCGridCell cell, FCTouchInfo touchInfo) { base.onCellTouchDown(cell, touchInfo); FCPoint mp = touchInfo.m_firstPoint; FCTreeNode node = cell as FCTreeNode; if (node != null) { int scrollH = 0; FCHScrollBar hscrollBar = HScrollBar; if (hscrollBar != null && hscrollBar.Visible) { scrollH = hscrollBar.Pos; } FCRect headerRect = node.TargetColumn.Bounds; headerRect.left += HorizontalOffset - scrollH; headerRect.top += VerticalOffset - scrollH; int left = headerRect.left; //复选框 if (m_checkBoxes) { int cw = m_checkBoxSize.cx; if (mp.x >= left && mp.x <= left + cw) { node.Checked = !node.Checked; return; } left += cw + 10; } //折叠节点 ArrayList <FCTreeNode> childNodes = node.getChildNodes(); if (childNodes != null && childNodes.size() > 0) { int nw = m_nodeSize.cx; if (mp.x >= left && mp.x <= left + nw) { if (node.Expended) { node.collapse(); } else { node.expend(); } update(); return; } } //移动 if (node.AllowDragOut) { m_movingNode = node; } } }
/// <summary> /// 单元格触摸抬起方法 /// </summary> /// <param name="cell">单元格</param> /// <param name="touchInfo">触摸信息</param> public override void onCellTouchUp(FCGridCell cell, FCTouchInfo touchInfo) { base.onCellTouchUp(cell, touchInfo); FCPoint mp = touchInfo.m_firstPoint; if (m_movingNode != null) { FCGridRow curRow = getRow(mp); //移动 if (curRow != null) { FCTreeNode curNode = curRow.getCell(0) as FCTreeNode; if (curNode.AllowDragIn && m_movingNode != curNode) { FCTreeNode curNodeParent = curNode.Parent; FCTreeNode movingNodeParent = m_movingNode.Parent; if (movingNodeParent != null) { movingNodeParent.removeNode(m_movingNode); } else { removeNode(m_movingNode); } //有父节点 if (curNodeParent != null) { if (movingNodeParent == curNodeParent) { curNodeParent.insertNode(curNodeParent.getNodeIndex(curNode), m_movingNode); } else { curNode.appendNode(m_movingNode); } } //无父节点 else { if (movingNodeParent == curNodeParent) { insertNode(getNodeIndex(curNode), m_movingNode); } else { curNode.appendNode(m_movingNode); } } curNode.expend(); } } m_movingNode = null; update(); } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { String target = cell.getString(); String value = getString(); if (value != null) { return(value.CompareTo(target)); } return(-1); }
/// <summary> /// 导出到Txt /// </summary> /// <param name="fileName">文件名</param> /// <param name="grid">表格控件</param> public static void exportToTxt(String fileName, FCGrid grid) { StringBuilder sb = new StringBuilder(); List <FCGridColumn> columns = grid.m_columns; int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { sb.Append(columns[i].Text); if (i != columnsSize - 1) { sb.Append(","); } } List <FCGridRow> rows = grid.m_rows; int rowsSize = rows.Count; List <FCGridRow> visibleRows = new List <FCGridRow>(); for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { visibleRows.Add(rows[i]); } } int visibleRowsSize = visibleRows.Count; if (visibleRowsSize > 0) { sb.Append("\r\n"); for (int i = 0; i < visibleRowsSize; i++) { for (int j = 0; j < columnsSize; j++) { FCGridCell cell = visibleRows[i].getCell(j); String cellValue = cell.getString(); sb.Append(cellValue); if (j != columnsSize - 1) { sb.Append(","); } } if (i != visibleRowsSize - 1) { sb.Append("\r\n"); } } } DataCenter.ExportService.ExportHtmlToTxt(fileName, sb.ToString()); }
/// <summary> /// 移除单元格 /// </summary> /// <param name="columnName">列名</param> public void removeCell(String columnName) { int cellSize = m_cells.size(); for (int i = 0; i < cellSize; i++) { FCGridCell cell = m_cells.get(i); if (cell.Column.Name == columnName) { m_cells.remove(cell); cell.onRemove(); break; } } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { double value = getDouble(); double target = cell.getDouble(); if (value > target) { return(1); } else if (value < target) { return(-1); } else { return(0); } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { float value = getFloat(); float target = cell.getFloat(); if (value > target) { return(1); } else if (value < target) { return(-1); } else { return(0); } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { long value = getLong(); long target = cell.getLong(); if (value > target) { return(1); } else if (value < target) { return(-1); } else { return(0); } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public override int compareTo(FCGridCell cell) { bool value = getBool(); bool target = cell.getBool(); if (value && !target) { return(1); } else if (!value && target) { return(-1); } else { return(0); } }
/// <summary> /// 单元格编辑结束 /// </summary> /// <param name="cell">单元格</param> public override void onCellEditEnd(FCGridCell cell) { base.onCellEditEnd(cell); if (cell != null) { FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String eventName = "on" + name.ToLower(); String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; if (value == null || value.Trim().Length == 0) { m_xml.removeProperty(target, eventName); } else { m_xml.setProperty(target, eventName, value); } target.update(); } //恢复正确的值 String rightValue = ""; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; Dictionary <String, String> attributes = m_xml.getAttributes(m_xml.Nodes[target]); if (attributes.ContainsKey(eventName)) { rightValue = attributes[eventName]; } } cell.Text = rightValue; Native.update(); Native.invalidate(); } } }
/// <summary> /// 清除目标 /// </summary> public void clearTargets() { //保存上次编辑的控件属性 FCTextBox editTextBox = EditTextBox; if (editTextBox != null) { if (editTextBox.Tag != null) { FCGridCell editingCell = EditTextBox.Tag as FCGridCell; if (editingCell != null) { FCGridCell nameCell = editingCell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { String cellName = nameCell.Name; String cellValue = editTextBox.Text; String eventName = "on" + cellName.ToLower(); int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; if (cellValue == null || cellValue.Trim().Length == 0) { m_xml.removeProperty(target, eventName); } else { m_xml.setProperty(target, eventName, cellValue); } target.update(); } } } } editTextBox.Visible = false; } m_targets.Clear(); }
/// <summary> /// 单元格编辑结束 /// </summary> /// <param name="cell">单元格</param> public override void onCellEditEnd(FCGridCell cell) { base.onCellEditEnd(cell); if (cell != null) { if (cell.Row.m_cells.Count > 0) { FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } } }
/// <summary> /// 导出到Excel /// </summary> /// <param name="path">路径</param> public static void exportToExcel(String fileName, FCGrid grid) { DataTable dataTable = new DataTable(); List <FCGridColumn> columns = grid.m_columns; int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { dataTable.Columns.Add(new DataColumn(columns[i].Text)); } List <FCGridRow> rows = grid.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { DataRow dr = dataTable.NewRow(); for (int j = 0; j < columnsSize; j++) { FCGridCell cell = grid.m_rows[i].getCell(j); if (cell is FCGridStringCell) { dr[j] = cell.getString(); } else { dr[j] = cell.getDouble(); } } dataTable.Rows.Add(dr); } } DataCenter.ExportService.ExportDataTableToExcel(dataTable, fileName); dataTable.Dispose(); }
/// <summary> /// 创建表格行 /// </summary> /// <param name="node">节点</param> /// <param name="control">控件</param> protected virtual void createGridRow(XmlNode node, FCView control) { FCGrid grid = control as FCGrid; FCGridRow row = new FCGridRow(); grid.addRow(row); setAttributesBefore(node, row); //单元格 int col = 0; foreach (XmlNode node3 in node.ChildNodes) { String subNodeName = node3.Name.ToLower(); String subNodeValue = node3.InnerText; if (subNodeName == "cell" || subNodeName == "td") { String cellType = "string"; HashMap <String, String> attributes = getAttributes(node3); if (attributes.containsKey("type")) { cellType = attributes.get("type"); } attributes.clear(); FCGridCell cell = null; if (cellType == "bool") { cell = new FCGridBoolCell(); } else if (cellType == "button") { cell = new FCGridButtonCell(); } else if (cellType == "checkbox") { cell = new FCGridCheckBoxCell(); } else if (cellType == "combobox") { cell = new FCGridComboBoxCell(); } else if (cellType == "double") { cell = new FCGridDoubleCell(); } else if (cellType == "float") { cell = new FCGridFloatCell(); } else if (cellType == "string") { cell = new FCGridStringCell(); } else if (cellType == "int") { cell = new FCGridIntCell(); } else if (cellType == "long") { cell = new FCGridLongCell(); } else if (cellType == "textbox") { cell = new FCGridTextBoxCell(); } row.addCell(col, cell); setAttributesBefore(node3, cell); cell.setString(subNodeValue); setAttributesAfter(node3, cell); col++; } } setAttributesAfter(node, row); }
/// <summary> /// 单元格开始编辑 /// </summary> /// <param name="cell">单元格</param> public override void onCellEditBegin(FCGridCell cell) { base.onCellEditBegin(cell); }
/// <summary> /// 单元格点击事件 /// </summary> /// <param name="cell">单元格</param> /// <param name="mp">坐标</param> /// <param name="button">按钮</param> /// <param name="clicks">点击次数</param> /// <param name="delta">滚轮值</param> public override void onCellClick(FCGridCell cell, FCTouchInfo touchInto) { base.onCellClick(cell, touchInto); List <FCGridRow> rows = m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { FCGridRow row = rows[i]; List <FCGridCell> cells = row.getCells(); int cellsSize = cells.Count; for (int j = 0; j < cellsSize; j++) { FCGridControlCell cCell = cells[j] as FCGridControlCell; if (cCell != null) { if (row == cell.Row) { cCell.Control.TextColor = FCDraw.FCCOLORS_TEXTCOLOR4; } else { cCell.Control.TextColor = FCColor.Text; } } } } if (touchInto.m_firstTouch) { if (touchInto.m_clicks == 1) { if (!cell.AllowEdit && cell is GridColorCell) { GridColorCell colorCell = cell as GridColorCell; ColorDialog colorDialog = new ColorDialog(); colorDialog.AllowFullOpen = true; colorDialog.AnyColor = true; colorDialog.SolidColorOnly = false; int a = 0, r = 0, g = 0, b = 0; FCColor.toArgb(Native.Paint, FCStr.convertStrToColor(colorCell.getString()), ref a, ref r, ref g, ref b); colorDialog.Color = Color.FromArgb(a, r, g, b); if (colorDialog.ShowDialog() == DialogResult.OK) { Color newColor = colorDialog.Color; a = newColor.A; r = newColor.R; g = newColor.G; b = newColor.B; colorCell.setString(FCStr.convertColorToStr(FCColor.argb(a, r, g, b))); FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } colorDialog.Dispose(); } //字体单元格 else if (!cell.AllowEdit && cell is GridFontCell) { GridFontCell fontCell = cell as GridFontCell; FontDialog fontDialog = new FontDialog(); fontDialog.Font = getFont(FCStr.convertStrToFont(fontCell.getString())); if (fontDialog.ShowDialog() == DialogResult.OK) { Font newFont = fontDialog.Font; fontCell.setString(FCStr.convertFontToStr(new FCFont(newFont.Name, newFont.Size, newFont.Bold, newFont.Underline, newFont.Italic, newFont.Strikeout))); FCGridCell nameCell = cell.Row.getCell("PROPERTYNAME"); if (nameCell != null) { m_designerDiv.saveUndo(); String name = nameCell.Name; String value = cell.Text; int targetsSize = m_targets.Count; for (int i = 0; i < targetsSize; i++) { FCView target = m_targets[i]; m_xml.setProperty(target, name, value); if (m_collectionWindow != null) { m_collectionWindow.onPropertyChanged(name, value); } target.update(); } //恢复正确的值 String rightValue = "", type = ""; for (int i = 0; i < targetsSize; i++) { m_targets[i].getProperty(name.ToLower(), ref rightValue, ref type); } cell.Text = rightValue; Native.update(); Native.invalidate(); } } } //单击编辑框 else if (cell is FCGridButtonCell) { FCButton cButton = (cell as FCGridButtonCell).Button; if (cButton.Tag != null) { String collectionName = cButton.Tag.ToString(); int targetsSize = m_targets.Count; if (targetsSize > 0) { FCView target = m_targets[0]; CollectionWindow collectionWindow = new CollectionWindow(m_native); collectionWindow.CollectionName = collectionName; collectionWindow.DesignerDiv = m_designerDiv; collectionWindow.Target = target; collectionWindow.Xml = m_xml; collectionWindow.IsWinForm = false; collectionWindow.showDialog(); } } } } } }
/// <summary> /// 单元格大小比较,用于排序 /// </summary> /// <param name="cell">比较单元格</param> /// <returns>1:较大 0:相等 -1:较小</returns> public virtual int compareTo(FCGridCell cell) { return(0); }