Esempio n. 1
0
        private void Getdata_1v2(string search)
        {
            DataTable table = new DataTable();

            table = GetTable_metadata(table);
            float _max, _min, _avg;

            _max = _min = _avg = 0;
            int[] index = new int[2];
            for (int i = 0; i < 2; i++)
            {
                index[i] = -1;
            }
            using (var db = new NORTHWNDEntities())
            {
                var test = db.Products.Select(c => new
                {
                    ProductCode     = c.ProductID,
                    ProductName     = c.ProductName,
                    Price           = (float)c.UnitPrice,
                    PriceIncludeVAT = ((float?)c.UnitPrice * 1.07)
                });
                if (!String.IsNullOrEmpty(search))
                {
                    test = test.Where(t => t.ProductName.Contains(search) || t.ProductCode.ToString().Equals(search));
                }
                if (test.ToList().Count() != 0)
                {
                    _max = test.Select(c => (float?)c.Price).Max(a => a.Value);
                    _min = test.Select(c => (float?)c.Price).Min(a => a.Value);
                    _avg = test.Select(c => (float?)c.Price).Average(a => a.Value);

                    int count = 0;
                    foreach (var p in test)
                    {
                        DataRow dr = table.NewRow();
                        dr["ProductCode"]       = p.ProductCode;
                        dr["ProductName"]       = p.ProductName;
                        dr["Price"]             = p.Price;
                        dr["Price include VAT"] = p.PriceIncludeVAT;
                        table.Rows.Add(dr);
                        if (p.Price == _max)
                        {
                            index[0] = count;
                        }
                        if (p.Price == _min)
                        {
                            index[1] = count;
                        }
                        count++;
                    }
                }
                else
                {
                    DataRow dr = table.NewRow();
                    dr["ProductCode"] = "Data not found.";
                    table.Rows.Add(dr);
                }
            }
            max.Text             = SetFormat(_max);
            min.Text             = SetFormat(_min);
            avg.Text             = SetFormat(_avg);
            dataGrid1.DataSource = table;
            setGridColour(dataGrid1, index);
        }
Esempio n. 2
0
        private void GetData_2(string search)
        {
            DataTable table = new DataTable();

            table = GetTable_metadata2(table);
            float _max, _min, _avg, _sum;

            _max = _min = _avg = _sum = 0;
            int[] index = new int[2];
            for (int i = 0; i < 2; i++)
            {
                index[i] = -1;
            }

            using (var db = new NORTHWNDEntities())
            {
                var test = db.Customers.Select(c => new
                {
                    c.CustomerID,
                    c.CompanyName,
                    c.ContactName,
                    ToTalOrderPrice = (float?)c.Orders.Sum(a => a.Order_Details.Sum(t => t.Quantity * t.UnitPrice))
                });
                if (!String.IsNullOrEmpty(search))
                {
                    test = test.Where(t => t.CustomerID.Contains(search) || t.CompanyName.Contains(search));
                }
                if (test.ToList().Count() != 0)
                {
                    _max = test.Select(c => c.ToTalOrderPrice).Max(a => a.Value);
                    _min = test.Select(c => c.ToTalOrderPrice).Min(a => a.Value);
                    _avg = test.Select(c => c.ToTalOrderPrice).Average(a => a.Value);
                    _sum = test.Select(c => c.ToTalOrderPrice).Sum(a => a.Value);


                    int count = 0;
                    foreach (var p in test)
                    {
                        DataRow dr = table.NewRow();
                        dr["Customer ID"]       = p.CustomerID;
                        dr["Company Name"]      = p.CompanyName;
                        dr["Contact Name"]      = p.ContactName;
                        dr["Total Order Price"] = p.ToTalOrderPrice;
                        if (p.ToTalOrderPrice == _max)
                        {
                            index[0] = count;
                        }
                        else if (p.ToTalOrderPrice == _min)
                        {
                            index[1] = count;
                        }
                        table.Rows.Add(dr);
                        count++;
                    }
                }
                else
                {
                    DataRow dr = table.NewRow();
                    dr["Customer ID"] = "Data not found.";
                    table.Rows.Add(dr);
                }
            }
            Max2.Text            = SetFormat(_max);
            Min2.Text            = SetFormat(_min);
            Avg2.Text            = SetFormat(_avg);
            Sum2.Text            = SetFormat(_sum);
            dataGrid2.DataSource = table;
            setGridColour(dataGrid2, index);
        }