private TableRow CreateContentRow(IEnumerable<string> values) { var row = new TableRow(_innerDocument); foreach (var value in values) { var transformedValue = value.Split('\n'); var p = new Paragraph(_innerDocument) { ParagraphFormat = new ParagraphFormat { Style = _cellContent } }; foreach (var s in transformedValue) { p.Inlines.Add(new Run(_innerDocument, s)); p.Inlines.Add(new SpecialCharacter(_innerDocument, SpecialCharacterType.LineBreak)); } row.Cells.Add(new TableCell(_innerDocument, p) { CellFormat = _tcfContent.Clone() }); } return row; }
private TableRow CreateHeaderRow(IEnumerable<string> columns) { var row = new TableRow(_innerDocument); foreach (var column in columns) { row.Cells.Add(new TableCell(_innerDocument, new Paragraph(_innerDocument, column) { ParagraphFormat = new ParagraphFormat { Style = _cellHeader } }) { CellFormat = _tcfHeader.Clone() }); } return row; }
public void Remove(TableRow row) { if (row.control != null) row.control.Dispose(); if (row.ItemsControls != null) for (int i = 0; i < row.ItemsControls.Length; i++) { var rowIC = row.ItemsControls[i]; if (rowIC != null) rowIC.Dispose(); } items.Remove(row); owner.UpdateRows(); }
//NEXT: Implement namedResource to insert image public static void InsertEntityTableXml(this word.Range range, IEnumerable<IEnumerable<EntityProperty>> entityProperties, string styleName, string namedResource) { SdtCell contentControl = null; TableRow row = null; int incrementor = 1; Stream packageStream = range.GetPackageStreamFromRange(); List<string> propertyNames = (from item in entityProperties select item).First<IEnumerable<EntityProperty>>() .Where(n => n.Type != "Edm.Stream" && n.Name != "id").Select(n => n.Name).ToList<string>(); int columnCount = propertyNames.Count(); int rowCount = entityProperties.Count(); using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(packageStream, true)) { //Remove all children wordDoc.MainDocumentPart.Document.Body.RemoveAllChildren(); //Generate table markup. Table table = new Table(); //Data Columns row = new TableRow(); foreach (string name in propertyNames) { incrementor++; contentControl = GenerateSdtCell(name, name, name, incrementor); row.AppendChild<SdtCell>(contentControl); } table.AppendChild<TableRow>(row); //Data Values //Reset incrementor incrementor = 1; foreach (IEnumerable<EntityProperty> items in entityProperties) { //For this sample, add namedResource to ContentControl tag string tag = string.Format("{0}/#{1}", (from p in items where p.Name == "id" select p.Value).First().ToString(), namedResource); row = new TableRow(); foreach (EntityProperty item in items) { //For this sample, ignore link.image/gif and id //See the Ribbon sample for how to used named resources if (item.Type != "Edm.Stream" && item.Name != "id") { incrementor++; contentControl = GenerateSdtCell(item.Name, item.Value.ToString(), tag, incrementor); row.AppendChild<SdtCell>(contentControl); } } table.AppendChild<TableRow>(row); } wordDoc.MainDocumentPart.Document .Body .AppendChild<Table>(table); wordDoc.MainDocumentPart.Document.Save(); //Flush the contents of the package wordDoc.Package.Flush(); //Convert back to flat opc using this in-memory package XDocument xDoc = OpcHelper.OpcToFlatOpc(wordDoc.Package); range.Application.ScreenUpdating = false; //Insert this flat opc Xml range.InsertXML(xDoc.ToString()); try { range.Tables[1].set_Style(styleName); } catch { //Catch a specific exception in a production application } range.Application.ScreenUpdating = true; } }
public virtual int Add(params object[] values) { TableRow row = new TableRow(this); row.Items = values; return Add(row); }
public int FindIndex(TableRow row) { return items.FindIndex(x => x == row); }
public virtual int Add() { TableRow row = new TableRow(this); row.Items = new object[owner.Columns.Count]; return Add(row); }
public virtual int Add(TableRow row) { items.Add(row); owner.UpdateRow(row); return items.Count - 1; }
public TableRowControlsCollection(TableRow row, int count) { owner = row; items = new Control[count]; }
internal void UpdateRow(TableRow row) { CreateTopLeftButton(); if (row.control == null) { var rButton = new TableRowButton(ColumnsStyle); rButton.row = row; rButton.Size = new Size(40, row.Height); rButton.Text = Rows.Count.ToString(); row.control = rButton; Controls.Add(rButton); } row.control.Visible = !rowHeadersHidden; if (row.Items.Length != Columns.Count) row.AddjustItemsCountTo(Columns.Count); if (row.ItemsControls == null) row.ItemsControls = new TableRow.TableRowControlsCollection(row, Columns.Count); if (row.ItemsControls.Length != row.Items.Length) { var newControls = new Control[Columns.Count]; if (row.ItemsControls.Length > newControls.Length) // Dispose unnecessary controls. { Array.Copy(row.ItemsControls.items, 0, newControls, 0, newControls.Length); for (int i = newControls.Length; i < row.ItemsControls.Length; i++) { var rowC = row.ItemsControls[i]; if (rowC != null) rowC.Dispose(); } } else Array.Copy(row.ItemsControls.items, 0, newControls, 0, row.ItemsControls.Length); row.ItemsControls.items = newControls; } if (SkipControlsInitializations == false) for (int i = 0; i < row.Items.Length; i++) { if (row.ItemsControls[i] != null) continue; int controlColumn = i; TextBox itemControl = new TextBox(); itemControl.BorderColor = Color.Transparent; itemControl.Size = new Size(Columns[i].Width, row.Height); itemControl.TextChanged += (s, a) => { row.Items[controlColumn] = itemControl.Text; }; if (row.Items[i] != null) itemControl.Text = row.Items[i].ToString(); row.ItemsControls.items[i] = itemControl; } }
internal void RaiseOnRowClick(TableRow row, MouseEventArgs mArgs) { OnRowClick(row, mArgs); }
public void LoadDataSet(DataSet ds) { Route route = new Route(model1); route.Avoid = true; model1.Route = route; Text = ds.DataSetName; TabText = ds.DataSetName; dataSet = ds; if (dataSet == null || dataSet.Relations == null) return; List<string> remove = new List<string>(); foreach (string table in entityTypes.Keys) { if (!dataSet.Tables.Contains(table)) remove.Add(table); } foreach (string str in remove) entityTypes.Remove(str); model1.Suspend(); model1.Shapes.Clear(); foreach (DataTable table in dataSet.Tables) { if (!visibleTables.Contains(table.TableName)) continue; Table t = new Table(); t.BackColor = Color.White; t.GradientColor = Color.FromArgb(96, SystemColors.Highlight); t.Location = new PointF(100, 50); t.Width = 140; t.Height = 200; t.Indent = 10; t.Heading = table.TableName; t.SubHeading = "Table"; t.MaximumSize = new SizeF(new Point(1000, 1000)); t.DrawExpand = true; t.AllowScale = false; TableGroup tg = new TableGroup(); tg.Text = "Columns"; t.Groups.Add(tg); float maxWidth = 0.0f; foreach (DataColumn column in table.Columns) { TableRow row = new TableRow(); row.Text = column.ColumnName; row.Image = new Crainiate.ERM4.Image("Resource.publicfield.gif", "Crainiate.ERM4.Component"); foreach (DataColumn col in table.PrimaryKey) { if (col.Equals(column)) row.Image = new Crainiate.ERM4.Image("Resource.protectedfield.gif", "Crainiate.ERM4.Component"); } tg.Rows.Add(row); Graphics g = model1.CreateGraphics(); SizeF size = g.MeasureString(row.Text, Component.Instance.DefaultFont); float width = size.Width + 50; if (width > maxWidth) maxWidth = width; } model1.Shapes.Add(table.TableName, t); t.Width = maxWidth; if (!entityTypes.ContainsKey(table.TableName)) entityTypes[table.TableName] = EntityTypes.Unclassified; } model1.Lines.Clear(); foreach (DataRelation dr in dataSet.Relations) { if (!visibleTables.Contains(dr.ParentTable.TableName)) continue; if (!visibleTables.Contains(dr.ChildTable.TableName)) continue; Connector line = new Connector((Shape)model1.Shapes[dr.ParentTable.TableName], (Shape)model1.Shapes[dr.ChildTable.TableName]); line.Avoid = true; line.Rounded = true; line.End.Marker = new Arrow(); line.Tag = dr.RelationName; model1.Lines.Add(model1.Lines.CreateKey(), line); } DoLayout(); RefreshHierarquies(); }
/*Создание отчёта в Word*/ private void saveReportToWord(string fileName) { // Create a Wordprocessing document. using (WordprocessingDocument myDoc = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = myDoc.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = new Body(); Table resultTable = new Table(); Table table = new Table(); TableProperties tblPr = new TableProperties(); TableBorders tblBorders = new TableBorders(); tblBorders.TopBorder = new TopBorder(); tblBorders.TopBorder.Val = BorderValues.Single; tblBorders.BottomBorder = new BottomBorder(); tblBorders.BottomBorder.Val = BorderValues.Single; tblBorders.LeftBorder = new LeftBorder(); tblBorders.LeftBorder.Val = BorderValues.Single; tblBorders.RightBorder = new RightBorder(); tblBorders.RightBorder.Val = BorderValues.Single; tblBorders.InsideHorizontalBorder = new InsideHorizontalBorder(); tblBorders.InsideHorizontalBorder.Val = BorderValues.Single; tblBorders.InsideVerticalBorder = new InsideVerticalBorder(); tblBorders.InsideVerticalBorder.Val = BorderValues.Single; tblPr.Append(tblBorders); table.Append(tblPr); TableRow tr; TableCell tc; tr = new TableRow(); body.Append(new Paragraph(new Run(new Text("Эксперимент: " + Experiment.Name.ToString() + "\n")))); body.Append(new Paragraph(new Run(new Text("Отклик: " + dgwExperiment.Columns[dgwExperiment.Columns.Count - 1].HeaderCell.Value.ToString() + "\n")))); if (dgwExperiment.Columns.Count == 2) { body.Append(new Paragraph(new Run(new Text("Фактор: ")))); } else { body.Append(new Paragraph(new Run(new Text("Факторы: ")))); } for (int col = 0; col < dgwExperiment.Columns.Count - 1; col++) { body.Append(new Paragraph(new Run(new Text(dgwExperiment.Columns[col].HeaderCell.Value.ToString() + "\n")))); } body.Append(new Paragraph(new Run(new Text("\n\n")))); tc = new TableCell(new Paragraph(new Run( new Text("Экспериментальные данные")))); TableCellProperties tcp = new TableCellProperties(); GridSpan gridSpan = new GridSpan(); gridSpan.Val = 11; tcp.Append(gridSpan); tc.Append(tcp); tr.Append(tc); table.Append(tr); tr = new TableRow(); tc = new TableCell(); tc.Append(new Paragraph(new Run(new Text("*")))); tr.Append(tc); for (int i = 0; i < dgwExperiment.Columns.Count; i++) { tr.Append(new TableCell(new Paragraph(new Run(new Text(dgwExperiment.Columns[i].HeaderCell.Value.ToString()))))); } table.Append(tr); for (int i = 0; i < dgwExperiment.Rows.Count; i++) { tr = new TableRow(); tr.Append(new TableCell(new Paragraph(new Run(new Text(dgwExperiment.Rows[i].HeaderCell.Value.ToString()))))); for (int j = 0; j < dgwExperiment.Columns.Count; j++) { tr.Append(new TableCell(new Paragraph(new Run(new Text( dgwExperiment.Rows[i].Cells[j].Value.ToString()))))); } table.Append(tr); } body.Append(table); body.Append(new Paragraph(new Run(new Text("\n\n")))); body.Append(new Paragraph(new Run(new Text("Результаты синтеза модели\n")))); for (int i = 0; i < txtCalcResult.Lines.Length; i++) { body.Append(new Paragraph(new Run(new Text(txtCalcResult.Lines[i].ToString())))); } body.Append(new Paragraph(new Run(new Text("\n\n")))); /* TableRowHeight a = new TableRowHeight(); a.HeightType = HeightRuleValues.Auto; */ TableProperties tblPr2 = new TableProperties(); TableBorders tblBorders2 = new TableBorders(); tblBorders2.TopBorder = new TopBorder(); tblBorders2.TopBorder.Val = BorderValues.Single; tblBorders2.BottomBorder = new BottomBorder(); tblBorders2.BottomBorder.Val = BorderValues.Single; tblBorders2.LeftBorder = new LeftBorder(); tblBorders2.LeftBorder.Val = BorderValues.Single; tblBorders2.RightBorder = new RightBorder(); tblBorders2.RightBorder.Val = BorderValues.Single; tblBorders2.InsideHorizontalBorder = new InsideHorizontalBorder(); tblBorders2.InsideHorizontalBorder.Val = BorderValues.Single; tblBorders2.InsideVerticalBorder = new InsideVerticalBorder(); tblBorders2.InsideVerticalBorder.Val = BorderValues.Single; tblPr2.Append(tblBorders2); resultTable.Append(tblPr2); TableRow tr2; TableCell tc2; tr2 = new TableRow(); tc2 = new TableCell(new Paragraph(new Run( new Text("Результаты расчёта по модели")))); TableCellProperties tcp2 = new TableCellProperties(); GridSpan gridSpan2 = new GridSpan(); gridSpan2.Val = 11; tcp2.Append(gridSpan2); tc2.Append(tcp2); tr2.Append(tc2); resultTable.Append(tr2); tr2 = new TableRow(); tc2 = new TableCell(); tc2.Append(new Paragraph(new Run(new Text(((dgwExperiment.ColumnCount == 2) ? "x1" : "x2 \\ x1"))))); tr2.Append(tc2); for (int i = 0; i < resultForm.dataGridView1.ColumnCount - 1; i++) { tr2.Append(new TableCell(new Paragraph(new Run(new Text(" " + resultForm.dataGridView1.Columns[i].HeaderCell.Value.ToString() + " "))))); } resultTable.Append(tr2); for (int i = 0; i < resultForm.dataGridView1.Rows.Count - 1; i++) { tr2 = new TableRow(); tr2.Append(new TableCell(new Paragraph(new Run(new Text(resultForm.dataGridView1.Rows[i].HeaderCell.Value.ToString()))))); for (int j = 0; j < resultForm.dataGridView1.ColumnCount - 1; j++) { tr2.Append(new TableCell(new Paragraph(new Run(new Text(resultForm.dataGridView1.Rows[i].Cells[j].Value.ToString()))))); } resultTable.Append(tr2); } body.Append(new Paragraph(new Run(resultTable))); nChartControl1.ImageExporter.SaveToFile(Path.GetDirectoryName(fileName) + "\\" + Experiment.Name.ToString() + ".bmp", new NSize(nChartControl1.Width, nChartControl1.Height), NResolution.ScreenResolution, new NBitmapImageFormat()); mainPart.Document.Append(body); mainPart.Document.Save(); saveResultToExcel(Path.GetDirectoryName(fileName) + "\\" + Experiment.Name.ToString() + ".xlsx"); } }