private void toolStripButton2_Click(object sender, EventArgs e)
        {
            frmStrategyPerformance newFrm = new frmStrategyPerformance();

            newFrm.MdiParent = this;
            newFrm.Show();
        }
Beispiel #2
0
        private void btnPivot_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)dgvDocs.DataSource;

            // DataRow[] dr = dt.Select("Select Symbol, Sum(ProfitnLoss)");

            var results = from Trans in dt.AsEnumerable()
                          where Trans.Field <decimal>("SellProfitPercent") == 0.5m
                          select Trans;
            // DataTable view = results.CopyToDataTable();

            var dataRow = dt.AsEnumerable().Where(x => x.Field <decimal>("SellProfitPercent") == 0.5m)
                          .Select(x => new { Name = x.Field <string>("Symbol"), profit = x.Field <decimal>("ProfitnLoss") })
                          .GroupBy(x => x.Name)
                          .Select(x => new
            {
                Name   = Name,
                Profit = x.Sum(y => y.profit)
            });

            var rst = (from row in dt.AsEnumerable()
                       group row by row.Field <string>("Symbol") into grp
                       select new
            {
                Name = grp.Key,
                Sum = (from r in grp where r.Field <decimal>("SellProfitPercent") == 0.5m select r.Field <decimal>("ProfitnLoss")).Sum()
            }).ToList();


            var totalPnlList = (from row in dt.AsEnumerable()
                                group row by row.Field <decimal>("SellProfitPercent") into grp
                                select new
            {
                Name = grp.Key,
                Sum = (from r in grp select r.Field <decimal>("ProfitnLoss")).Sum()
            }).ToList();


            var pnlDayList = (from row in dt.AsEnumerable()
                              group row by new
            {
                Date = row.Field <DateTime>("ModifiedOn"),
                SPP = row.Field <decimal>("SellProfitPercent"),
                MPL = row.Field <int>("MinPositionLevel")
            } into grp
                              select new
            {
                Name = grp.Key,
                Sum = (from r in grp select r.Field <decimal>("ProfitnLoss")).Sum()
            }).ToList();

            DataTable newItems = new DataTable();

            newItems.Columns.Add("Name");
            newItems.Columns.Add("Sum");

            foreach (var item in pnlDayList)
            {
                DataRow newRow = newItems.NewRow();
                newRow["Name"] = item.Name;
                newRow["Sum"]  = item.Sum;
                newItems.Rows.Add(newRow);
            }

            frmStrategyPerformance frmPro = new frmStrategyPerformance();

            frmPro.pnlDayDT = newItems;
            frmPro.Show();
        }