当前位置: 首页>>代码示例>>C#>>正文


C# DataRow.ToList方法代码示例

本文整理汇总了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();
        }
开发者ID:poolsar,项目名称:LotCreator,代码行数:70,代码来源:Form1.cs


注:本文中的DataRow.ToList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。