本文整理汇总了C#中DataRow.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# DataRow.ToList方法的具体用法?C# DataRow.ToList怎么用?C# DataRow.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataRow
的用法示例。
在下文中一共展示了DataRow.ToList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: simpleButton1_Click
private void simpleButton1_Click(object sender, EventArgs e)
{
DataTable priceTable = GetExcelTable("c:/mytemp/price.xlsx");
DataTable abcTable = GetExcelTable("c:/mytemp/abc.xlsx");
DataRow[] priceRows = new DataRow[priceTable.Rows.Count];
priceTable.Rows.CopyTo(priceRows, 0);
DataRow[] abcRows = new DataRow[abcTable.Rows.Count];
abcTable.Rows.CopyTo(abcRows, 0);
//string tovNumber = priceRows[10][6].ToString();
//string url = string.Format("http://www.begemott.ru/tov_{0}.html", tovNumber);
//Process.Start(url);
//return;
var priceDict = new Dictionary<string, decimal>();
var abcDict = new Dictionary<string, decimal>();
priceRowsDict = new Dictionary<string, DataRow>();
priceRows.ToList().ForEach(p =>
{
var title = p[COL_PRICE_TITLE] as string;
if (title != null && !priceDict.ContainsKey(title))
{
priceDict.Add(p[COL_PRICE_TITLE] as string,
Convert.ToDecimal(p[COL_PRICE_PRICE]));
priceRowsDict.Add(title, p);
}
});
abcRows.ToList().ForEach(p =>
{
var title = p[COL_ABC_TITLE] as string;
if (title != null && !abcDict.ContainsKey(title))
{
abcDict.Add(p[COL_ABC_TITLE] as string,
Convert.ToDecimal(p[COL_ABC_COUNT]));
}
});
var rr = from p in priceDict
let title = p.Key
let price = p.Value
let shortTitle = abcDict.Keys.FirstOrDefault(a => title.Contains(a))
let count = shortTitle == null ? 0 : abcDict[shortTitle]
where count != 0
let pribil = count * price * (decimal)0.85
select new { title, price, count, pribil };
var abcResult = rr.ToList();
var maxPribil = abcResult.Max(a => a.pribil);
var fullPribil = abcResult.Sum(a => a.pribil);
var abcResult2 = abcResult.Select(a => new AbcRow
{
Title = a.title,
Count = a.count,
Price = a.price,
pribil = a.pribil,
PercToFull = (a.pribil / fullPribil).ToString("p"),
PercToMax = (a.pribil / maxPribil).ToString("p")
}).ToList();
gridControl1.DataSource = abcResult2;
gridControl1.RefreshDataSource();
gridView1.RefreshData();
}