Ejemplo n.º 1
0
        private void colorizeBySld()
        {
            percentView.Clear();


            var query = listViewView.GroupBy(x => x.Sld)
                        .Select(g => new { Value = g.Key, Count = g.Count() })
                        .OrderByDescending(x => x.Count);


            //generate BatchWindowPercentView and colors
            Random random = new Random();

            foreach (var field in query)
            {
                BatchWindowPercentView prcnts = new BatchWindowPercentView();
                prcnts.Field   = field.Value;
                prcnts.Percent = (int)((double)field.Count / (double)listViewView.Count * 100);

                int colorR = random.Next(130, 255);
                int colorG = random.Next(130, 255);
                int colorB = random.Next(130, 255);

                prcnts.BackgroundColor = new SolidColorBrush(Color.FromRgb((byte)colorR, (byte)colorG, (byte)colorB));
                percentView.Add(prcnts);
            }

            //assign colors based on field.Value
            foreach (BatchWindowListViewView lv in listViewView)
            {
                foreach (BatchWindowPercentView p in percentView)
                {
                    if (lv.Sld == p.Field)
                    {
                        lv.BackgroundColor = p.BackgroundColor;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void colorizeByState()
        {

            percentView.Clear();

            var query = listViewView.GroupBy(x => x.State)
.Select(g => new { Value = g.Key, Count = g.Count() })
.OrderByDescending(x => x.Count);


            //generate BatchWindowPercentView and colors
            Random random = new Random();
            foreach (var field in query)
            {
                BatchWindowPercentView prcnts = new BatchWindowPercentView();
                prcnts.Field = field.Value;
                prcnts.Percent = (int)((double)field.Count / (double)listViewView.Count * 100);

                int colorR = random.Next(130, 255);
                int colorG = random.Next(130, 255);
                int colorB = random.Next(130, 255);

                prcnts.BackgroundColor = new SolidColorBrush(Color.FromRgb((byte)colorR, (byte)colorG, (byte)colorB));
                percentView.Add(prcnts);
            }

            //assign colors based on field.Value
            foreach (BatchWindowListViewView lv in listViewView)
            {
                foreach (BatchWindowPercentView p in percentView)
                {
                    if (lv.State == p.Field)
                    {
                        lv.BackgroundColor = p.BackgroundColor;
                    }
                }
            }
        }