// Открыть private void OpenItem_Click(object sender, EventArgs e) { var serializer = new Newtonsoft.Json.JsonSerializer { TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto }; var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Figure |*.myfile"; if (openFileDialog.ShowDialog() == DialogResult.Cancel) { return; } var fileName = openFileDialog.FileName; using (StreamReader streamReader = new StreamReader(fileName)) { using (Newtonsoft.Json.JsonReader jreader = new Newtonsoft.Json.JsonTextReader(streamReader)) { ListFigure.List = serializer.Deserialize <List <IFigure> >(jreader); } for (int i = 0; i < ListFigure.List.Count; i++) { var figure = ListFigure.List[i]; var row = _tablefigure.NewRow(); row[0] = figure.ToString(); row[1] = figure.CalculateVolume(); row[2] = figure.X; row[3] = figure.Y; row[4] = figure.Z; _tablefigure.Rows.Add(row); } TableFigure.Update(); } }
/// <summary> /// Обработчик кнопки "Изменить данные" /// </summary> private void изменитьДанныеToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Изменить обьект?", "Изменение обьекта", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (TableFigure.CurrentRow != null) { foreach (DataGridViewCell cell in TableFigure.SelectedCells) { var figureForm = new FigureForm(); var a = TableFigure.SelectedCells[0].RowIndex; IFigure figure = ListFigure.List[a]; if (figureForm.ShowDialog() == DialogResult.OK) { TableFigure.Rows.RemoveAt(cell.RowIndex); ListFigure.List.Add(figure); var row = _tablefigure.NewRow(); row[0] = figure.ToString(); row[1] = figure.CalculateVolume(); row[2] = figure.X; row[3] = figure.Y; row[4] = figure.Z; _tablefigure.Rows.Add(row); TableFigure.Update(); } } } } }
private void ButtonModify_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Изменить обьект?", "Изменение обьекта", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (TableFigure.CurrentRow != null) { foreach (DataGridViewCell cell in TableFigure.SelectedCells) { FigureForm f = new FigureForm(); var a = TableFigure.SelectedCells[0].RowIndex; IFigure figure = ListFigure.List[a]; f.ShowDialog(); if (f.DialogResult == DialogResult.OK) { TableFigure.Rows.RemoveAt(cell.RowIndex); figure = f.Figures; ListFigure.List.Add(figure); var row = _tablefigure.NewRow(); row[0] = figure.Name; row[1] = figure.CalculateVolume(); _tablefigure.Rows.Add(row); TableFigure.Update(); } } } } }
// ======================================== // constructor // ======================================== public ChangeColumnWidthCommand(TableFigure target, int columnIndex, int newWidth) { Contract.Requires(target != null); Contract.Requires(columnIndex > -1); _target = target; _columnIndex = columnIndex; _newWidth = newWidth; }
// ======================================== // constructor // ======================================== public ChangeRowHeightCommand(TableFigure target, int rowIndex, int newHeight) { Contract.Requires(target != null); Contract.Requires(rowIndex > -1); _target = target; _rowIndex = rowIndex; _newHeight = newHeight; }
private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) { var newRow = _tablefigure.NewRow(); newRow["X"] = 3.0; newRow["Y"] = 5.0; newRow["Name"] = "Шар"; _tablefigure.Rows.Add(newRow); TableFigure.Update(); }
public static void AdjustRowSize(IEditor tableEditor, TableFigure tableFig, int rowIndex) { if (tableEditor == null || tableFig == null) { return; } if (rowIndex < 0 || rowIndex >= tableFig.TableData.RowCount) { throw new ArgumentException("rowIndex"); } var row = tableFig.TableData.Rows.ElementAt(rowIndex); var height = row.Cells.Where(cell => !(cell.IsMerging && cell.RowSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Height); var req = new ChangeRowHeightRequest(rowIndex, height + tableFig.Padding.Height); tableEditor.PerformRequest(req); }
// ======================================== // static field // ======================================== public static void AdjustRowAndColumnSizes(TableFigure tableFig) { if (tableFig == null) { return; } foreach (var row in tableFig.TableData.Rows) { var height = row.Cells.Where(cell => !(cell.IsMerging && cell.RowSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Height); row.Height = height + tableFig.Padding.Height; } foreach (var col in tableFig.TableData.Columns) { var width = col.Cells.Where(cell => !(cell.IsMerging && cell.ColumnSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Width); col.Width = width + tableFig.Padding.Width; } }
public static void AdjustColumnSize(IEditor tableEditor, TableFigure tableFig, int colIndex) { if (tableEditor == null || tableFig == null) { return; } if (colIndex < 0 || colIndex >= tableFig.TableData.ColumnCount) { throw new ArgumentException("colIndex"); } var col = tableFig.TableData.Columns.ElementAt(colIndex); var width = col.Cells.Where(cell => !(cell.IsMerging && cell.ColumnSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Width); var req = new ChangeColumnWidthRequest(colIndex, width + tableFig.Padding.Width); tableEditor.PerformRequest(req); }
// Создание строк private void ButtonCreate_Click(object sender, EventArgs e) { var figureForm = new FigureForm(); if (figureForm.ShowDialog() == DialogResult.OK) //добавить фигуру в таблицу { var figure = figureForm.Figure; ListFigure.List.Add(figure); var row = _tablefigure.NewRow(); row[0] = figure.ToString(); row[1] = figure.CalculateVolume(); row[2] = figure.X; row[3] = figure.Y; row[4] = figure.Z; _tablefigure.Rows.Add(row); TableFigure.Update(); } }
//public static void AdjustAllRowSizes(TableFigure tableFig) { // if (tableFig == null) { // return; // } // foreach (var row in tableFig.TableData.Rows) { // var height = row.Cells.Where(cell => !(cell.IsMerging && cell.RowSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Height); // row.Height = height + tableFig.Padding.Height; // } //} public static void AdjustRowSizesAtEvenInterval(IEditor tableEditor, TableFigure tableFig, int firstRowIndex, int lastRowIndex) { if (tableEditor == null || tableFig == null) { return; } if (firstRowIndex < 0 || lastRowIndex > tableFig.TableData.RowCount - 1 || firstRowIndex >= lastRowIndex) { return; } /// calc height var rowIndex = 0; var height = 0; foreach (var row in tableFig.TableData.Rows) { if (rowIndex >= firstRowIndex && rowIndex <= lastRowIndex) { height += row.Height; } ++rowIndex; } var rowCount = lastRowIndex - firstRowIndex + 1; var rowHeight = height / rowCount; var lastRowHeight = height - (rowHeight * (rowCount - 1)); rowIndex = 0; foreach (var row in tableFig.TableData.Rows) { if (rowIndex >= firstRowIndex && rowIndex <= lastRowIndex) { var req = new ChangeRowHeightRequest(rowIndex, rowIndex == lastRowIndex ? lastRowHeight : rowHeight); tableEditor.PerformRequest(req); } ++rowIndex; } }
//public static void AdjustAllColumnSizes(TableFigure tableFig) { // if (tableFig == null) { // return; // } // foreach (var col in tableFig.TableData.Columns) { // var width = col.Cells.Where(cell => !(cell.IsMerging && cell.ColumnSpan != 1) && !cell.IsMerged).Max(cell => cell.Value.StyledTextBounds.Width); // col.Width = width + tableFig.Padding.Width; // } //} public static void AdjustColumnSizesAtEvenInterval(IEditor tableEditor, TableFigure tableFig, int firstColumnIndex, int lastColumnIndex) { if (tableEditor == null || tableFig == null) { return; } if (firstColumnIndex < 0 || lastColumnIndex > tableFig.TableData.ColumnCount - 1 || firstColumnIndex >= lastColumnIndex) { return; } /// calc width var colIndex = 0; var width = 0; foreach (var col in tableFig.TableData.Columns) { if (colIndex >= firstColumnIndex && colIndex <= lastColumnIndex) { width += col.Width; } ++colIndex; } var colCount = lastColumnIndex - firstColumnIndex + 1; var colWidth = width / colCount; var lastColWidth = width - (colWidth * (colCount - 1)); colIndex = 0; foreach (var col in tableFig.TableData.Columns) { if (colIndex >= firstColumnIndex && colIndex <= lastColumnIndex) { var req = new ChangeColumnWidthRequest(colIndex, colIndex == lastColumnIndex ? lastColWidth : colWidth); tableEditor.PerformRequest(req); } ++colIndex; } }