本文整理汇总了C#中DataTable.Column方法的典型用法代码示例。如果您正苦于以下问题:C# DataTable.Column方法的具体用法?C# DataTable.Column怎么用?C# DataTable.Column使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataTable
的用法示例。
在下文中一共展示了DataTable.Column方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRepoert
public void BuildRepoert()
{
var items = new List<SettlementDetails>
{
new SettlementDetails
{
Name = "A",
Amount = 1m,
},
new SettlementDetails
{
Name = "B",
Amount = 2m,
Amount1 = 2,
},
new SettlementDetails
{
Name = "C",
Amount = 3m,
Amount1 = 1,
}
};
var target = new DataTable<SettlementDetails>();
target.Column("Name", s => s.Name);
//計算列
IColumn colum4CalculateRow1 = target.Column("Amount0", s => s.Amount).Sum<decimal?>();
IColumn colum4CalculateRow2 = target.Column("Amount1", s => s.Amount1).Sum<decimal?>();
target.Sum<decimal?>("Amount+Amount1", colum4CalculateRow1, colum4CalculateRow2);
target.SetData(items);
var columns = new[] { "Name", "Amount0", "Amount1", "Amount+Amount1" };
int index = 0;
//check column Name;
foreach (IColumn column in target.Columns)
{
Assert.AreEqual(columns[index], column.Name);
index++;
}
//check the row item0;
index = 0;
foreach (var item in target.GetRows())
{
Assert.AreEqual(items[index].Name, item[0]);
Assert.AreEqual(items[index].Amount, item[1]);
Assert.AreEqual(items[index].Amount1, item[2]);
Assert.AreEqual((items[index].Amount ?? 0) + (items[index].Amount1 ?? 0), item[3], "row is " + index);
index++;
}
Assert.AreEqual(items.Sum(item => item.Amount), (colum4CalculateRow1).SumResult());
Assert.AreEqual(items.Sum(item => item.Amount1), (colum4CalculateRow2).SumResult());
}
示例2: CalcuteColumns
public void CalcuteColumns()
{
var target = new DataTable<SettlementDetails>();
var items = new List<SettlementDetails>
{
new SettlementDetails
{
Name = "A",
Amount = 1m,
},
new SettlementDetails
{
Name = "B",
Amount = 2m,
},
new SettlementDetails
{
Name = "C",
Amount = 4m,
}
};
target.Column("Name", s => s.Name);
target.Column("Ammount", s => s.Amount).Sum<decimal?>();
target.Column("Amount1", s => s.Amount1);
target.SetData(items);
target.GetRows();
Assert.AreEqual(7m, target.GetSummaries("Sum")[1]);
Assert.AreEqual(7m, target.Columns["Ammount"].SumResult());
}
示例3: BuildRepoert_empty
public void BuildRepoert_empty()
{
var target = new DataTable<SettlementDetails>();
target.Column("Name", s => s.Name);
//計算列
IColumn colum4CalculateRow1 = target.Column("Amount0", s => s.Amount).Sum<decimal?>();
IColumn colum4CalculateRow2 = target.Column("Amount1", s => s.Amount1).Sum<decimal?>();
target.Sum<decimal?>("Amount+Amount1", colum4CalculateRow1, colum4CalculateRow2);
target.SetData(new List<SettlementDetails>());
target.GetRows();
Assert.AreEqual(null, colum4CalculateRow1.SumResult());
}
示例4: TestSum_in_column
public void TestSum_in_column()
{
var items = new List<SettlementDetails>
{
new SettlementDetails
{
Name = "A",
Amount = 1m,
},
new SettlementDetails
{
Name = "B",
Amount = 2m,
Amount1 = 2,
},
new SettlementDetails
{
Name = "C",
Amount = 3m,
Amount1 = 1,
}
};
var target = new DataTable<SettlementDetails>();
target.Column("Name", s => s.Name);
target.Column("Ammount", s => s.Amount).Sum<Decimal?>();
target.SetData(items);
target.GetRows();
Assert.AreEqual(6m, target.Columns[1].GetResult(0));
}
示例5: TestAvg_in_a_row
public void TestAvg_in_a_row()
{
var items = new List<SettlementDetails>
{
new SettlementDetails
{
Name = "A",
Amount = 1m,
},
new SettlementDetails
{
Name = "B",
Amount = 2m,
Amount1 = 2,
},
new SettlementDetails
{
Name = "C",
Amount = 3m,
Amount1 = 1,
}
};
var target = new DataTable<SettlementDetails>();
target.Column("Name", s => s.Name);
target.Column("Ammount0", s => s.Amount);
target.Column("Ammount1", s => s.Amount1);
target.Column("合计avg", df =>
{
Decimal result = 0m;
foreach (var col in df)
{
result += Convert.ToDecimal(col);
}
return result;
}, "Ammount0", "Ammount1");
target.SetData(items);
var rows =new List<object[]>(target.GetRows());
Assert.AreEqual(1m, rows[0][3]);
}