/// <summary> /// Copies properties from data row to typed instance. /// </summary> /// <param name="src">From: Table data row</param> /// <param name="dest">To: typed instance</param> internal void CopyFromDataRow(TRow dest, DataRow src) { object dbValue = src[Name]; object attributeValue = (dbValue != DBNull.Value) ? dbValue : null; attributeSetter.Invoke(dest, new object[] { attributeValue }); }
public TValue this[TRow row, TColumn column] { get { if (table.Rows.Contains(row) && table.Columns.Contains(column)) { return(table.GetValue(row, column)); } else { throw new ArgumentException("There's no such cell."); } } set { if (table.Rows.Contains(row) && table.Columns.Contains(column)) { table.SetValue(row, column, value); } else { throw new ArgumentException("There's no such cell."); } } }
private void AssertIndexExist(TRow row, TColumn column) { if (!_table.Rows.Any(r => r.Equals(row)) || !_table.Columns.Any(r => r.Equals(column))) { throw new ArgumentException(); } }
public TValue this[TRow row, TColumn column] { get { AssertIndexExist(row, column); if (!_table._values.ContainsKey(row) || !_table._values[row].ContainsKey(column)) { return(default(TValue)); } return(_table._values[row][column]); } set { AssertIndexExist(row, column); if (!_table._values.ContainsKey(row)) { _table._values[row] = new Dictionary <TColumn, TValue>(); } _table._values[row][column] = value; } }
/// <summary> /// Récupère une ligne du tableau excel du type passé en paramètre de la méthode générique. /// </summary> /// <typeparam name="TRow">Le type de l'objet de retour.</typeparam> /// <returns>Une ligne du fichier excel.</returns> public TRow ReadRow <TRow>() where TRow : new() { var row = new TRow(); var def = BeanDescriptor.GetDefinition(row); var initialColumn = _currentCell.ColumnName; var emptyCellsNb = 0; /* Parcourt des propriétés du bean. */ foreach (var propDesc in def.Properties) { var value = ReadCellCore(propDesc.PrimitiveType); // On suppose que la première ligne vide correspond à la fin du document. if (value == null) { emptyCellsNb++; if (emptyCellsNb == def.Properties.Count) { return(default(TRow)); } } propDesc.SetValue(row, value); /* Passe à la colonne suivante. */ _currentCell = _currentCell.ShiftColumn(1); } /* On retourne à la cellule initiale de la ligne. */ _currentCell = _currentCell.ChangeColumn(initialColumn); return(row); }
public virtual void FillValues(TRow row) { foreach (var setter in _setters) { setter(row); } }
/// <summary> /// Copies properties from typed instance to data row. /// </summary> /// <param name="dest">To: Table data row</param> /// <param name="src">From: typed instance</param> internal void CopyToDataRow(DataRow dest, TRow src) { object attributeValue = attributeGetter.Invoke(src, new object[] { }); object dbValue = (attributeValue ?? DBNull.Value); dest[Name] = dbValue; }
public TRow this[int index] { get { DataRow row = rows[index]; TRow typedRow = Extract(row); return(typedRow); } }
private static void ReadTr(List<TRow> alRow, TRowType rowType, HtmlElement elParent) { TRow row = new TRow(); row.RowType = rowType; foreach (HtmlElement el in elParent.Children) { if (String.Compare(el.TagName, "td", true) == 0 || String.Compare(el.TagName, "th", true) == 0) { row.Cells.Add(el.InnerText); } } alRow.Add(row); }
private void CreateIndex(TRow row, TColumn column) { _table.AddRow(row); _table.AddColumn(column); if (!_table._values.ContainsKey(row)) { _table._values[row] = new Dictionary <TColumn, TValue>(); } }
/// <summary> /// Adds the specified value. /// </summary> /// <param name="value">The value.</param> /// <param name="row">The row.</param> public void Add(TValue value, TRow row) { RowSet rows; if (!this.TryGetValue(value, out rows)) { this[value] = rows = new RowSet(); } rows.Add(row); }
protected override bool MoveNextCore() { Ch.Assert(State != CursorState.Done); var result = _enumerator.MoveNext(); _currentRow = result ? _enumerator.Current : null; if (result && _currentRow == null) { throw Ch.Except("Encountered null when iterating over data, this is not supported."); } return(result); }
public TValue this[TRow row, TColumn column] { get { return(table.GetValue(row, column)); } set { table.AddRow(row); table.AddColumn(column); table.SetValue(row, column, value); } }
public static Dictionary <string, Delegate> GetGetter <TRow>() where TRow : IClassWithGetter <TRow>, new() { var inst = new TRow(); var schema = SchemaDefinition.Create(typeof(TRow), SchemaDefinition.Direction.Read); var res = new Dictionary <string, Delegate>(); for (int i = 0; i < schema.Count; ++i) { var name = schema[i].ColumnName; res[name] = inst.GetGetter(i); } return(res); }
private TPage PrepareHeader() { var header = new TPage(); var trow = new TRow(); header.Groups.Add(new TGroup() { Rows = new List <TRow>() { } }); return(header); }
private static void ReadTr(List <TRow> alRow, TRowType rowType, HtmlElement elParent) { TRow row = new TRow(); row.RowType = rowType; foreach (HtmlElement el in elParent.Children) { if (String.Compare(el.TagName, "td", true) == 0 || String.Compare(el.TagName, "th", true) == 0) { row.Cells.Add(el.InnerText); } } alRow.Add(row); }
public void WriteXlsxTest() { string file = AppDomain.CurrentDomain.BaseDirectory + "/ExcelTests/t2.xlsx"; IExcel excel = ExcelFactory.CreateDefault(); DataTable dt = excel.Read(file, 0, 2); DataSet ds = new DataSet(); ds.Tables.Add(dt); TTemplate template = new TTemplate(); TRow R1 = new TRow(); TCell A = new TCell("A", "A", 0, 0); A.ColSpan = 2; TCell B = new TCell("", "B", 0, 2); TCell C = new TCell("C", "C", 0, 3); C.RowSpan = 2; TCell D = new TCell("D", "D", 0, 4); D.RowSpan = 2; TCell E = new TCell("", "E", 0, 5); E.ColSpan = 2; R1.Cells.Add(A); R1.Cells.Add(B); R1.Cells.Add(C); R1.Cells.Add(D); R1.Cells.Add(E); TRow R2 = new TRow(); TCell A1 = new TCell("A1", "A1", 1, 0); TCell A2 = new TCell("A2", "A2", 1, 1); TCell B1 = new TCell("B1", "B1", 1, 2); TCell E1 = new TCell("E1", "E1", 1, 5); TCell E2 = new TCell("E2", "E2", 1, 6); R2.Cells.Add(A1); R2.Cells.Add(A2); R2.Cells.Add(B1); R2.Cells.Add(E1); R2.Cells.Add(E2); TSheet tsheet = new TSheet(); tsheet.Name = "Sheet1"; tsheet.Title = "表格O"; tsheet.Head.Rows.Add(R1); tsheet.Head.Rows.Add(R2); template.Sheets.Add(tsheet); string outputFilePath = AppDomain.CurrentDomain.BaseDirectory + "/ExcelTests/out2.xlsx"; bool result = excel.WriteFile(outputFilePath, ds, template); Assert.IsTrue(result); }
public TRow AddFieldsInRow(IWidget[] fields) { var TRow = new TRow(); foreach (var f in fields) { if (AddField(f)) { var tCol = new TCol(f.WidgetId); TRow.Cols.Add(tCol); } } page.Groups[0].Rows.Add(TRow); return(TRow); }
public TValue this[TRow row, TColumn column] { get { if (!_table._values.ContainsKey(row) || !_table._values[row].ContainsKey(column)) { return(default(TValue)); } return(_table._values[row][column]); } set { CreateIndex(row, column); _table._values[row][column] = value; } }
public override void FillValues(TRow row) { Ch.Check(_input.State == CursorState.Good, "Can't fill values: the cursor is not active."); base.FillValues(row); }
public string GetCellValue(TRow row) { return(this.Pad(this.getCellValue(row).ToString())); }
public Cursor(IHostEnvironment env, SingleRowLoopDataView <TRow> dataView, Func <int, bool> predicate) : base(env, dataView, predicate) { _currentRow = dataView._current; }
/// <summary> /// Gets a specified portion of the table of <see cref="TcpViewEntry" /> objects that represent a snapshot of the current TCP and/or UDP connections in either IPv4, IPv6 or both. If <paramref name="resolveProtocolNames" /> is set to <see langword="true" />, Protocol names are resolved according to the services file in %systemroot%\drivers\etc\services. /// </summary> /// <param name="tcp4"><see langword="true" /> to include TCPv4 entries.</param> /// <param name="tcp6"><see langword="true" /> to include TCPv6 entries.</param> /// <param name="udp4"><see langword="true" /> to include UDPv4 entries.</param> /// <param name="udp6"><see langword="true" /> to include UDPv6 entries.</param> /// <param name="resolveProtocolNames"><see langword="true" /> to resolve Protocol names according to the services file in %systemroot%\drivers\etc\services.</param> /// <returns> /// A new <see cref="TcpViewEntry" />[] object with the TCP and/or UDP table in either IPv4, IPv6 or both. If <paramref name="resolveProtocolNames" /> is set to <see langword="true" />, Protocol names are resolved according to the services file in %systemroot%\drivers\etc\services. /// </returns> public static TcpViewEntry[] GetEntries(bool tcp4, bool tcp6, bool udp4, bool udp6, bool resolveProtocolNames) { List <TcpViewEntry> entries = new List <TcpViewEntry>(); if (tcp4) { entries.AddRange ( GetConnections <Native.TcpTable, Native.TcpRow>(false, 2) .Select(row => new TcpViewEntry { Protocol = TcpViewEntryProtocol.Tcp4, LocalAddress = new IPAddress(BitConverter.GetBytes(row.LocalAddress)), LocalPort = BitConverter.ToUInt16(new[] { row.LocalPort[1], row.LocalPort[0] }, 0), RemoteAddress = new IPAddress(BitConverter.GetBytes(row.RemoteAddress)), RemotePort = BitConverter.ToUInt16(new[] { row.RemotePort[1], row.RemotePort[0] }, 0), TcpState = (TcpState)row.State, ProcessId = (int)row.OwningProcessId }) ); } if (tcp6) { entries.AddRange ( GetConnections <Native.Tcp6Table, Native.Tcp6Row>(false, 23) .Select(row => new TcpViewEntry { Protocol = TcpViewEntryProtocol.Tcp6, LocalAddress = new IPAddress(row.LocalAddress), LocalPort = BitConverter.ToUInt16(new[] { row.LocalPort[1], row.LocalPort[0] }, 0), RemoteAddress = new IPAddress(row.RemoteAddress), RemotePort = BitConverter.ToUInt16(new[] { row.RemotePort[1], row.RemotePort[0] }, 0), TcpState = (TcpState)row.State, ProcessId = (int)row.OwningProcessId }) ); } if (udp4) { entries.AddRange ( GetConnections <Native.UdpTable, Native.UdpRow>(true, 2) .Select(row => new TcpViewEntry { Protocol = TcpViewEntryProtocol.Udp4, LocalAddress = new IPAddress(row.LocalAddress), LocalPort = BitConverter.ToUInt16(new[] { row.LocalPort[1], row.LocalPort[0] }, 0), ProcessId = (int)row.OwningProcessId }) ); } if (udp6) { entries.AddRange ( GetConnections <Native.Udp6Table, Native.Udp6Row>(true, 23) .Select(row => new TcpViewEntry { Protocol = TcpViewEntryProtocol.Udp6, LocalAddress = new IPAddress(row.LocalAddress), LocalPort = (int)row.LocalPort, ProcessId = (int)row.OwningProcessId }) ); } return(entries .Select(entry => { entry.LocalProtocolName = ResolvePort(entry.LocalPort, CSharp.EqualsAny(entry.Protocol, TcpViewEntryProtocol.Udp4, TcpViewEntryProtocol.Udp6)); entry.RemoteProtocolName = entry.RemotePort == null ? null : ResolvePort(entry.RemotePort.Value, CSharp.EqualsAny(entry.Protocol, TcpViewEntryProtocol.Udp4, TcpViewEntryProtocol.Udp6)); return entry; }) .ToArray()); TRow[] GetConnections <TTable, TRow>(bool udp, int version) { int bufferSize = 0; FieldInfo numEntriesField = typeof(TTable).GetField("EntryCount"); GetTable(IntPtr.Zero); IntPtr tcpTable = Marshal.AllocHGlobal(bufferSize); try { if (GetTable(tcpTable) == 0) { TTable table = Marshal.PtrToStructure <TTable>(tcpTable); int rowSize = Marshal.SizeOf <TRow>(); uint entryCount = numEntriesField.GetValue <uint>(table); TRow[] tableRows = new TRow[entryCount]; IntPtr ptr = tcpTable + 4; for (int i = 0; i < entryCount; i++, ptr += rowSize) { tableRows[i] = Marshal.PtrToStructure <TRow>(ptr); } return(tableRows); } else { return(new TRow[0]); } } finally { Marshal.FreeHGlobal(tcpTable); } uint GetTable(IntPtr table) => udp?Native.GetExtendedUdpTable(table, ref bufferSize, true, version, 1) : Native.GetExtendedTcpTable(table, ref bufferSize, true, version, 5); } string ResolvePort(int port, bool udp) { if (resolveProtocolNames) { if (ProtocolMap == null) { ProtocolMap = ProtocolMappingEntry.GetProtocolMappingEntries(); } return(ProtocolMap.FirstOrDefault(entry => entry.Protocol == (udp ? ProtocolMappingProtocol.Udp : ProtocolMappingProtocol.Tcp) && entry.Port == port)?.Name); } else { return(null); } } }
public Cursor(IHostEnvironment env, StreamingDataView <TRow> dataView, Func <int, bool> predicate) : base(env, dataView, predicate) { _enumerator = dataView._data.GetEnumerator(); _currentRow = null; }
public static TView CreateDefault(IDBEntity Entity, EntityLayoutType layoutType) { var view = new TView(); view.Fields = new List <TField>(); var page = new TPage(); view.Pages.Add(page); var group = new TGroup(); page.Groups.Add(group); var start_new_r = true; List <TCol> col_r = new List <TCol>(); var layoutF = Entity.GetLayoutFields(EntityLayoutType.Edit); int idx = 0; foreach (var f in layoutF) { var col = new TCol(f.Name); view.Fields.Add(new TField() { FieldId = f.Name, Text = f.Text }); if (col_r.Count == 1) { start_new_r = true; } else { start_new_r = false; } if (IsWidgetOnFullRow(f.ControlType)) { start_new_r = true; var row = new TRow(); col.Span = 24; row.Cols = new List <TCol>() { col }; group.Rows.Add(row); } else { col_r.Add(col); } if (start_new_r) { var row = new TRow(); row.Cols = col_r; group.Rows.Add(row); col_r = new List <TCol>(); } else if (layoutF.Count - 1 == idx) { var row = new TRow(); row.Cols = col_r; group.Rows.Add(row); } idx++; } return(view); }
public Cursor(IChannelProvider provider, SingleRowLoopDataView <TRow> dataView, Func <int, bool> predicate) : base(provider, dataView, predicate) { _currentRow = dataView._current; }
public Cursor(IChannelProvider provider, StreamingDataView <TRow> dataView, Func <int, bool> predicate) : base(provider, dataView, predicate) { _enumerator = dataView._data.GetEnumerator(); _currentRow = null; }
public override void FillValues(TRow row) { Ch.Check(Position >= 0, "Cannot fill values. The cursor is not active."); base.FillValues(row); }
/// <summary> /// Constructor /// </summary> public RowData(TableRowType type, TRow expected, RowDataActualValue actual) { Type = type; Expected = expected; Actual = actual; }
/// <summary> /// Constructor setting row value. /// </summary> public RowDataActualValue(TRow value) { Value = value; Exception = null; }
public ActionResult Export(int payId) { PaymentManager pm = new PaymentManager(); Payment payment = pm.LoadPayment(payId); #region 动态模板 TTemplate template = new TTemplate(); TRow R1 = new TRow(); TRow R2 = new TRow(); int index1 = 3; int index2 = 3; TCell A = new TCell("PersonId", "ID", 0, 0); A.RowSpan = 2; A.Width = 1; TCell B = new TCell("PersonName", "姓名", 0, 1); B.RowSpan = 2; TCell C = new TCell("PersonCode", "身份证", 0, 2); C.RowSpan = 2; R1.Cells.Add(A); R1.Cells.Add(B); R1.Cells.Add(C); foreach (PayItemDO item in payment.Items) { TCell cell = new TCell(); cell.Name = item.ItemName; cell.Caption = item.ItemCaption; if (item.IsLeaf == true) { //cell.Width = 50; } if (item.ParentId == 0) { cell.RowIndex = 0; cell.ColumnIndex = index1; int colspan = 1; foreach (PayItemDO pi in payment.Items) { if (pi.ParentId == item.ItemId) { colspan++; } } if (colspan == 1) { cell.RowSpan = 2; index1++; index2++; } else { cell.ColSpan = colspan - 1; index1 = index1 + cell.ColSpan; } R1.Cells.Add(cell); } else { cell.RowIndex = 1; cell.ColumnIndex = index2; index2 = index2 + 1; R2.Cells.Add(cell); } } TSheet tsheet = new TSheet(); tsheet.Name = "Sheet1"; tsheet.Title = "Sheet1"; tsheet.Head.Rows.Add(R1); tsheet.Head.Rows.Add(R2); template.Sheets.Add(tsheet); #endregion IExcel excel = ExcelFactory.CreateDefault(); DataSet ds = new DataSet(); payment.DataSource.TableName = "Sheet1"; ds.Tables.Add(payment.DataSource); POIStream stream = new POIStream(); stream.AllowClose = false; excel.Write(stream, template, ds, ExcelExtendType.XLSX); stream.AllowClose = true; byte[] buffer = new byte[stream.Length]; stream.Position = 0; stream.Read(buffer, 0, buffer.Length); stream.Close(); HttpResponse context = System.Web.HttpContext.Current.Response; try { context.ContentType = "application/ms-excel"; context.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", HttpUtility.UrlEncode(payment.PayTitle, System.Text.Encoding.UTF8))); context.BinaryWrite(buffer); context.Flush(); context.End(); } catch (Exception ex) { context.ContentType = "text/plain"; context.Write(ex.Message); } return(null); }