Exemple #1
0
        private void SetupFooter()
        {
            var footerDescription = new FooterDescription();
            var footerAggregates  = footerDescription.Aggregates;

            _orderIDAggregateDefinition.PropertyName = "OrderID";
            footerAggregates.Add(_orderIDAggregateDefinition);

            _productAggregateDefinition.PropertyName = "Product";
            _productAggregateDefinition.Caption      = "Product Count: ";
            _productAggregateDefinition.Aggregate    = AggregateEnum.CountDistinct;
            footerAggregates.Add(_productAggregateDefinition);

            _unitPriceAggregateDefinition.PropertyName = "UnitPrice";
            footerAggregates.Add(_unitPriceAggregateDefinition);

            _quantityAggregateDefinition.PropertyName = "Quantity";
            footerAggregates.Add(_quantityAggregateDefinition);

            _discountAggregateDefinition.PropertyName = "Discount";
            _discountAggregateDefinition.Caption      = "Total Earnings: {0:N2}";
            _discountAggregateDefinition.Expression   = "SUM(UnitPrice * Quantity * (1 - Discount))";
            footerAggregates.Add(_discountAggregateDefinition);

            flexGrid.Footers.Descriptions.Add(footerDescription);
            flexGrid.Footers.Fixed = true;

            _footerRowIndex = flexGrid.Rows.Count - 1;
        }
Exemple #2
0
        private void InitFlexGrid()
        {
            // setup flexgrid
            _flexGrid.AllowFiltering     = true;
            _flexGrid.AllowFiltering     = true;
            _flexGrid.AllowMerging       = AllowMergingEnum.Nodes;
            _flexGrid.HideGroupedColumns = true;
            _flexGrid.ShowErrors         = true;

            ColumnCollection columns = _flexGrid.Cols;

            // setup flexgrid columns
            columns[0].Width = 22;

            Column idColumn = columns["ID"];

            idColumn.Width        = 50;
            idColumn.AllowEditing = false;

            // setup combo list
            IEnumerable <string> products = (from s in _dataSet.Tables["Products"].Rows.Cast <DataRow>() select s)
                                            .Select(x => x["Name"].ToString());

            columns["Product"].ComboList = string.Join("|", products);

            // build image map for countries
            var flagImageMap = new Dictionary <Country, Image>();

            foreach (Country country in Enum.GetValues(typeof(Country)))
            {
                flagImageMap.Add(country, LoadImage(country.ToString()));
            }

            Column countryColumn = columns["Country"];

            // assign image map to country column
            countryColumn.ImageMap     = flagImageMap;
            countryColumn.ImageAndText = true;

            // build image map for colors
            var colorImageMap = new Dictionary <DrawColor, Image>();

            foreach (DrawColor color in Enum.GetValues(typeof(DrawColor)))
            {
                colorImageMap.Add(color, LoadImage(color.ToString()));
            }

            Column colorColumn = columns["Color"];

            // assign image map to color column
            colorColumn.ImageMap     = colorImageMap;
            colorColumn.ImageAndText = true;

            Column priceColumn = columns["Price"];

            priceColumn.Format    = "C2";
            priceColumn.TextAlign = TextAlignEnum.RightCenter;
            priceColumn.Width     = 80;

            ValidationRuleCollection priceEditorValidation = _flexGrid.Cols["Price"].EditorValidation;

            // add validation rules
            priceEditorValidation.Add(new RequiredRule());
            priceEditorValidation.Add(new RangeRule()
            {
                Minimum      = decimal.Zero,
                Maximum      = decimal.MaxValue,
                ErrorMessage = "Price cannot be negative"
            });

            Column changeColumn = columns["Change"];

            changeColumn.Format    = "C2";
            changeColumn.TextAlign = TextAlignEnum.RightCenter;

            Column historyColumn = columns["History"];

            historyColumn.AllowEditing = false;

            // setup sparkline for history column
            historyColumn.ShowSparkline = true;

            Sparkline historySparkline = historyColumn.Sparkline;

            historySparkline.ShowLow  = true;
            historySparkline.ShowHigh = true;

            Column discountColumn = columns["Discount"];

            discountColumn.Format       = "p0";
            discountColumn.AllowEditing = false;
            discountColumn.Width        = 80;

            Column ratingColumn = columns["Rating"];

            ratingColumn.ImageAndText = false;
            ratingColumn.AllowEditing = false;

            columns["Active"].Width = 60;

            Column dateColumn = columns["Date"];

            dateColumn.Format = "g";

            // creating footers
            var footerDescription = new FooterDescription();

            // price aggregate
            var priceAggregateDefinition = new AggregateDefinition()
            {
                Aggregate    = AggregateEnum.Average,
                Caption      = "Average price: ${0:N2}",
                PropertyName = "Price"
            };

            // discount aggregate
            var discountAggregateDefinition = new AggregateDefinition
            {
                Aggregate    = AggregateEnum.Average,
                Caption      = "Average discount: {0:P}",
                PropertyName = "Discount"
            };

            ObservableCollection <AggregateDefinition> aggregates = footerDescription.Aggregates;

            aggregates.Add(priceAggregateDefinition);
            aggregates.Add(discountAggregateDefinition);

            // add footers
            Footers footers = _flexGrid.Footers;

            footers.Descriptions.Add(footerDescription);
            footers.Fixed = true;

            // set details
            _flexGrid.RowDetailProvider = (g, r) => new CustomRowDetail();

            // add red style
            CellStyle redStyle = _flexGrid.Styles.Add("Red");

            redStyle.ImageAlign = ImageAlignEnum.LeftCenter;
            redStyle.ForeColor  = Color.Red;

            // add green style
            CellStyle greenStyle = _flexGrid.Styles.Add("Green");

            greenStyle.ImageAlign = ImageAlignEnum.LeftCenter;
            greenStyle.ForeColor  = Color.Green;

            // add rating style
            CellStyle ratingStyle = _flexGrid.Styles.Add("Rating");

            ratingStyle.ImageAlign = ImageAlignEnum.RightCenter;
        }
Exemple #3
0
        private void InitFlexGrid()
        {
            _flex.AllowFiltering = true;
            _flex.ShowErrors     = true;

            _flex.Cols[0].Width = 22;

            // build data map
            var flagsHt = new Hashtable();

            Enum.GetValues(typeof(Countries))
            .Cast <Countries>()
            .ToList()
            .ForEach(x =>
            {
                flagsHt.Add(x, LoadImage(x.ToString()));
            });

            // assign ImageMap to countries column
            _flex.Cols["Country"].ImageMap     = flagsHt;
            _flex.Cols["Country"].ImageAndText = true;

            var colorsHt = new Hashtable();

            Enum.GetValues(typeof(DrawColors))
            .Cast <DrawColors>()
            .ToList()
            .ForEach(x =>
            {
                colorsHt.Add(x, LoadImage(x.ToString()));
            });

            _flex.Cols["Color"].ImageMap     = colorsHt;
            _flex.Cols["Color"].ImageAndText = true;

            // Formatting columns
            _flex.Cols["ID"].Width        = 50;
            _flex.Cols["ID"].AllowEditing = false;
            _flex.Cols["Date"].Format     = "g";
            _flex.Cols["Price"].Format    = "C2";
            _flex.Cols["Price"].TextAlign = TextAlignEnum.RightCenter;

            // Add validator
            _flex.Cols["Price"].EditorValidation.Add(new RequiredRule());
            _flex.Cols["Price"].EditorValidation.Add(new RangeRule()
            {
                Minimum      = decimal.Zero,
                Maximum      = decimal.MaxValue,
                ErrorMessage = "Price cannot be negative"
            });


            _flex.Cols["Change"].Format         = "C2";
            _flex.Cols["Change"].TextAlign      = TextAlignEnum.RightCenter;
            _flex.Cols["Discount"].Format       = "p0";
            _flex.Cols["Discount"].AllowEditing = false;
            _flex.Cols["Discount"].Width        = 80;
            _flex.Cols["Rating"].ImageAndText   = false;
            _flex.Cols["Rating"].AllowEditing   = false;
            _flex.Cols["Price"].Width           = 80;

            // For the history column initialize sparkline
            _flex.Cols["History"].ShowSparkline      = true;
            _flex.Cols["History"].Sparkline.ShowLow  = true;
            _flex.Cols["History"].Sparkline.ShowHigh = true;
            _flex.Cols["History"].AllowEditing       = false;

            _flex.Cols["Active"].Width = 60;

            // Init combobox list
            var productList = (from s in _ds.Tables["Products"].Rows.Cast <DataRow>() select s)
                              .Select(x => x["Name"].ToString())
                              .ToArray();
            var list = string.Join("|", productList);

            _flex.Cols["Product"].ComboList = list;


            // Creating footers
            var footerDescription = new FooterDescription();

            // Price agg
            var aggFooterPriceAvg = new AggregateDefinition();

            aggFooterPriceAvg.Aggregate    = AggregateEnum.Average;
            aggFooterPriceAvg.Caption      = "Average price: ${0:N2}";
            aggFooterPriceAvg.PropertyName = "Price";

            // Discount agg
            var aggFooterDiscoutAvg = new AggregateDefinition();

            aggFooterDiscoutAvg.Aggregate    = AggregateEnum.Average;
            aggFooterDiscoutAvg.Caption      = "Average discount: {0:P}";
            aggFooterDiscoutAvg.PropertyName = "Discount";

            footerDescription.Aggregates.Add(aggFooterPriceAvg);
            footerDescription.Aggregates.Add(aggFooterDiscoutAvg);

            // Add footers
            _flex.Footers.Descriptions.Add(footerDescription);
            _flex.Footers.Fixed = true;

            // Set details
            _flex.RowDetailProvider = (g, r) => new CustomRowDetail();

            // Other properties
            _flex.HideGroupedColumns = true;
            _flex.AllowFiltering     = true;
            _flex.AllowMerging       = AllowMergingEnum.Nodes;


            // Add styles (Red, Green and Rating)
            var style = _flex.Styles.Add("Red");

            style.ImageAlign = ImageAlignEnum.LeftCenter;
            style.ForeColor  = Color.Red;

            style            = _flex.Styles.Add("Green");
            style.ImageAlign = ImageAlignEnum.LeftCenter;
            style.ForeColor  = Color.Green;

            style            = _flex.Styles.Add("Rating");
            style.ImageAlign = ImageAlignEnum.RightCenter;
        }