/// <summary>
 /// Use this function if you do not add your columns at design time.
 /// </summary>
 /// <param name="colType"></param>
 /// <returns></returns>
 private DataGridViewColumn SetupColumn(SandBoxGridColumn colType)
 {
     DataGridViewColumn column = null;
     switch (colType)
     {
         case SandBoxGridColumn.ColumnCustomerID:
             column = new KryptonDataGridViewTextBoxColumn();
             column.HeaderText = "Customer ID";
             column.Name = "ColumnCustomerID";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnCustomerName:
             column = new KryptonDataGridViewTreeTextColumn();// KryptonDataGridViewTextBoxColumn();
             column.HeaderText = "Name";
             column.Name = "ColumnCustomerName";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnAddress:
             column = new KryptonDataGridViewTextBoxColumn();
             column.HeaderText = "Address";
             column.Name = "ColumnAddress";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnCity:
             column = new KryptonDataGridViewTextBoxColumn();
             column.HeaderText = "City";
             column.Name = "ColumnCity";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnCountry:
             column = new KryptonDataGridViewTextAndImageColumn();
             column.HeaderText = "Country";
             column.Name = "ColumnCountry";
             column.Resizable = DataGridViewTriState.True;
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 78;
             return column;
         case SandBoxGridColumn.ColumnOrderDate:
             column = new KryptonDataGridViewDateTimePickerColumn();
             ((KryptonDataGridViewDateTimePickerColumn)column).CalendarTodayDate = DateTime.Now;
             ((KryptonDataGridViewDateTimePickerColumn)column).Checked = false;
             ((KryptonDataGridViewDateTimePickerColumn)column).Format = DateTimePickerFormat.Short;
             column.HeaderText = "Order Date";
             column.Name = "ColumnOrderDate";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnProduct:
             column = new KryptonDataGridViewTextBoxColumn();
             column.HeaderText = "Product";
             column.Name = "ColumnProduct";
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.ColumnPrice:
             column = new KryptonDataGridViewFormattingColumn();
             column.Name = colType.ToString();
             column.ValueType = typeof(decimal); //really  important for formatting
             DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
             dataGridViewCellStyle1.Format = "C2";
             dataGridViewCellStyle1.NullValue = "";
             column.DefaultCellStyle = dataGridViewCellStyle1;
             column.HeaderText = "Price";
             column.Resizable = DataGridViewTriState.True;
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.Width = 79;
             return column;
         case SandBoxGridColumn.SatisfactionColumn:
             column = new KryptonDataGridViewPercentageColumn();
             DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
             dataGridViewCellStyle2.Format = "0%";
             column.DefaultCellStyle = dataGridViewCellStyle2;
             column.HeaderText = "Satisfaction";
             column.Name = colType.ToString();
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             return column;
         case SandBoxGridColumn.ColumnToken:
             column = new KryptonDataGridViewTokenColumn();
             column.Name = colType.ToString();
             column.ReadOnly = true;
             column.SortMode = DataGridViewColumnSortMode.Programmatic;
             column.HeaderText = "Tag";
             return column;
         default:
             throw new Exception("Unknown Column Type !! TODO improve that !");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Use this function if you do not add your columns at design time.
        /// </summary>
        /// <param name="colType"></param>
        /// <returns></returns>
        private DataGridViewColumn SetupColumn(SandBoxGridColumn colType)
        {
            DataGridViewColumn column = null;

            switch (colType)
            {
            case SandBoxGridColumn.ColumnCustomerID:
                column            = new KryptonDataGridViewTextBoxColumn();
                column.HeaderText = "Customer ID";
                column.Name       = "ColumnCustomerID";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnCustomerName:
                column            = new KryptonDataGridViewTreeTextColumn();// KryptonDataGridViewTextBoxColumn();
                column.HeaderText = "Name";
                column.Name       = "ColumnCustomerName";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnAddress:
                column            = new KryptonDataGridViewTextBoxColumn();
                column.HeaderText = "Address";
                column.Name       = "ColumnAddress";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnCity:
                column            = new KryptonDataGridViewTextBoxColumn();
                column.HeaderText = "City";
                column.Name       = "ColumnCity";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnCountry:
                column            = new KryptonDataGridViewTextAndImageColumn();
                column.HeaderText = "Country";
                column.Name       = "ColumnCountry";
                column.Resizable  = DataGridViewTriState.True;
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 78;
                return(column);

            case SandBoxGridColumn.ColumnOrderDate:
                column = new KryptonDataGridViewDateTimePickerColumn();
                ((KryptonDataGridViewDateTimePickerColumn)column).CalendarTodayDate = DateTime.Now;
                ((KryptonDataGridViewDateTimePickerColumn)column).Checked           = false;
                ((KryptonDataGridViewDateTimePickerColumn)column).Format            = DateTimePickerFormat.Short;
                column.HeaderText = "Order Date";
                column.Name       = "ColumnOrderDate";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnProduct:
                column            = new KryptonDataGridViewTextBoxColumn();
                column.HeaderText = "Product";
                column.Name       = "ColumnProduct";
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.ColumnPrice:
                column           = new KryptonDataGridViewFormattingColumn();
                column.Name      = colType.ToString();
                column.ValueType = typeof(decimal);     //really  important for formatting
                DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
                dataGridViewCellStyle1.Format    = "C2";
                dataGridViewCellStyle1.NullValue = "";
                column.DefaultCellStyle          = dataGridViewCellStyle1;
                column.HeaderText = "Price";
                column.Resizable  = DataGridViewTriState.True;
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.Width      = 79;
                return(column);

            case SandBoxGridColumn.SatisfactionColumn:
                column = new KryptonDataGridViewPercentageColumn();
                DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
                dataGridViewCellStyle2.Format = "0%";
                column.DefaultCellStyle       = dataGridViewCellStyle2;
                column.HeaderText             = "Satisfaction";
                column.Name     = colType.ToString();
                column.SortMode = DataGridViewColumnSortMode.Programmatic;
                return(column);

            case SandBoxGridColumn.ColumnToken:
                column            = new KryptonDataGridViewTokenColumn();
                column.Name       = colType.ToString();
                column.ReadOnly   = true;
                column.SortMode   = DataGridViewColumnSortMode.Programmatic;
                column.HeaderText = "Tag";
                return(column);

            default:
                throw new Exception("Unknown Column Type !! TODO improve that !");
            }
        }
        /// <summary>
        /// Loads the configuration from file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="Grid">The grid.</param>
        private void LoadConfigFromFile(string file, JDHSoftware.Krypton.Toolkit.KryptonOutlookGrid.KryptonOutlookGrid Grid)
        {
            if (string.IsNullOrEmpty(file))
                throw new Exception("Grid config file is missing !");

            XDocument doc = XDocument.Load(file);
            int versionGrid = -1;
            int.TryParse(doc.Element("OutlookGrid").Attribute("V").Value, out versionGrid);

            //Upgrade if necessary the config file
            CheckAndUpgradeConfigFile(versionGrid, doc, Grid, LoadState.After);
            Grid.ClearEverything();
            Grid.GroupBox.Visible = CommonHelper.StringToBool(doc.XPathSelectElement("OutlookGrid/GroupBox").Value);
            Grid.HideColumnOnGrouping = CommonHelper.StringToBool(doc.XPathSelectElement("OutlookGrid/HideColumnOnGrouping").Value);

            //Initialize
            int NbColsInFile = doc.XPathSelectElements("//Column").Count();
            DataGridViewColumn[] columnsToAdd = new DataGridViewColumn[NbColsInFile];
            SandBoxGridColumn[] enumCols = new SandBoxGridColumn[NbColsInFile];
            OutlookGridColumn[] OutlookColumnsToAdd = new OutlookGridColumn[columnsToAdd.Length];
            SortedList<int, int> hash = new SortedList<int, int>();// (DisplayIndex , Index)

            int i = 0;
            IOutlookGridGroup group;
            XElement node2;

            foreach (XElement node in doc.XPathSelectElement("OutlookGrid/Columns").Nodes())
            {
                //Create the columns and restore the saved properties
                //As the OutlookGrid receives constructed DataGridViewColumns, only the parent application can recreate them (dgvcolumn not serializable)
                enumCols[i] = (SandBoxGridColumn)Enum.Parse(typeof(SandBoxGridColumn), node.Element("Name").Value);
                columnsToAdd[i] = SetupColumn(enumCols[i]);
                columnsToAdd[i].Width = int.Parse(node.Element("Width").Value);
                columnsToAdd[i].Visible = CommonHelper.StringToBool(node.Element("Visible").Value);
                hash.Add(int.Parse(node.Element("DisplayIndex").Value), i);
                //Reinit the group if it has been set previously
                group = null;
                if (!node.Element("GroupingType").IsEmpty && node.Element("GroupingType").HasElements)
                {
                    node2 = node.Element("GroupingType");
                    group = (IOutlookGridGroup)Activator.CreateInstance(Type.GetType(TypeConverter.ProcessType(node2.Element("Name").Value), true));
                    group.OneItemText = node2.Element("OneItemText").Value;
                    group.XXXItemsText = node2.Element("XXXItemsText").Value;
                    group.SortBySummaryCount = CommonHelper.StringToBool(node2.Element("SortBySummaryCount").Value);
                    if (!string.IsNullOrEmpty((node2.Element("ItemsComparer").Value)))
                    {
                        Object comparer = Activator.CreateInstance(Type.GetType(TypeConverter.ProcessType(node2.Element("ItemsComparer").Value), true));
                        group.ItemsComparer = (IComparer)comparer;
                    }
                    if (node2.Element("Name").Value.Contains("OutlookGridDateTimeGroup"))
                    {
                        ((OutlookGridDateTimeGroup)group).Interval = (OutlookGridDateTimeGroup.DateInterval)Enum.Parse(typeof(OutlookGridDateTimeGroup.DateInterval), node2.Element("GroupDateInterval").Value);
                    }
                }
                OutlookColumnsToAdd[i] = new OutlookGridColumn(columnsToAdd[i], group, (SortOrder)Enum.Parse(typeof(SortOrder), node.Element("SortDirection").Value), int.Parse(node.Element("GroupIndex").Value), int.Parse(node.Element("SortIndex").Value));

                i += 1;
            }
            //First add the underlying DataGridViewColumns to the grid
            Grid.Columns.AddRange(columnsToAdd);
            //And then the outlookgrid columns
            Grid.AddRangeInternalColumns(OutlookColumnsToAdd);

            //Add conditionnal formatting to the grid
            EnumConditionalFormatType conditionFormatType = default(EnumConditionalFormatType);
            IFormatParams conditionFormatParams = default(IFormatParams);
            foreach (XElement node in doc.XPathSelectElement("OutlookGrid/ConditionalFormatting").Nodes())
            {
                conditionFormatType = (EnumConditionalFormatType)Enum.Parse(typeof(EnumConditionalFormatType), node.Element("FormatType").Value);
                XElement nodeParams = node.Element("FormatParams");
                switch (conditionFormatType)
                {
                    case EnumConditionalFormatType.Bar:
                        conditionFormatParams = new BarParams(Color.FromArgb(int.Parse(nodeParams.Element("BarColor").Value)), CommonHelper.StringToBool(nodeParams.Element("GradientFill").Value));
                        break;
                    case EnumConditionalFormatType.ThreeColorsRange:
                        conditionFormatParams = new ThreeColorsParams(Color.FromArgb(int.Parse(nodeParams.Element("MinimumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MediumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MaximumColor").Value)));
                        break;
                    case EnumConditionalFormatType.TwoColorsRange:
                        conditionFormatParams = new TwoColorsParams(Color.FromArgb(int.Parse(nodeParams.Element("MinimumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MaximumColor").Value)));
                        break;
                    default:
                        conditionFormatParams = null;
                        //will never happened but who knows ? throw exception ?
                        break;
                }
                Grid.ConditionalFormatting.Add(new ConditionalFormatting(node.Element("ColumnName").Value, conditionFormatType, conditionFormatParams));
            }

            //We need to loop through the columns in the order of the display order, starting at zero; otherwise the columns will fall out of order as the loop progresses.
            foreach (KeyValuePair<int, int> kvp in hash)
            {
                columnsToAdd[kvp.Value].DisplayIndex = kvp.Key;
            }

            activeColumns = enumCols;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the configuration from file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="Grid">The grid.</param>
        private void LoadConfigFromFile(string file, JDHSoftware.Krypton.Toolkit.KryptonOutlookGrid.KryptonOutlookGrid Grid)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new Exception("Grid config file is missing !");
            }

            XDocument doc         = XDocument.Load(file);
            int       versionGrid = -1;

            int.TryParse(doc.Element("OutlookGrid").Attribute("V").Value, out versionGrid);

            //Upgrade if necessary the config file
            CheckAndUpgradeConfigFile(versionGrid, doc, Grid, LoadState.Before);
            Grid.ClearEverything();
            Grid.GroupBox.Visible     = CommonHelper.StringToBool(doc.XPathSelectElement("OutlookGrid/GroupBox").Value);
            Grid.HideColumnOnGrouping = CommonHelper.StringToBool(doc.XPathSelectElement("OutlookGrid/HideColumnOnGrouping").Value);

            //Initialize
            int NbColsInFile = doc.XPathSelectElements("//Column").Count();

            DataGridViewColumn[]  columnsToAdd        = new DataGridViewColumn[NbColsInFile];
            SandBoxGridColumn[]   enumCols            = new SandBoxGridColumn[NbColsInFile];
            OutlookGridColumn[]   OutlookColumnsToAdd = new OutlookGridColumn[columnsToAdd.Length];
            SortedList <int, int> hash = new SortedList <int, int>();// (DisplayIndex , Index)


            int i = 0;
            IOutlookGridGroup group;
            XElement          node2;

            foreach (XElement node in doc.XPathSelectElement("OutlookGrid/Columns").Nodes())
            {
                //Create the columns and restore the saved properties
                //As the OutlookGrid receives constructed DataGridViewColumns, only the parent application can recreate them (dgvcolumn not serializable)
                enumCols[i]             = (SandBoxGridColumn)Enum.Parse(typeof(SandBoxGridColumn), node.Element("Name").Value);
                columnsToAdd[i]         = SetupColumn(enumCols[i]);
                columnsToAdd[i].Width   = int.Parse(node.Element("Width").Value);
                columnsToAdd[i].Visible = CommonHelper.StringToBool(node.Element("Visible").Value);
                hash.Add(int.Parse(node.Element("DisplayIndex").Value), i);
                //Reinit the group if it has been set previously
                group = null;
                if (!node.Element("GroupingType").IsEmpty&& node.Element("GroupingType").HasElements)
                {
                    node2                    = node.Element("GroupingType");
                    group                    = (IOutlookGridGroup)Activator.CreateInstance(Type.GetType(TypeConverter.ProcessType(node2.Element("Name").Value), true));
                    group.OneItemText        = node2.Element("OneItemText").Value;
                    group.XXXItemsText       = node2.Element("XXXItemsText").Value;
                    group.SortBySummaryCount = CommonHelper.StringToBool(node2.Element("SortBySummaryCount").Value);
                    if (!string.IsNullOrEmpty((node2.Element("ItemsComparer").Value)))
                    {
                        Object comparer = Activator.CreateInstance(Type.GetType(TypeConverter.ProcessType(node2.Element("ItemsComparer").Value), true));
                        group.ItemsComparer = (IComparer)comparer;
                    }
                    if (node2.Element("Name").Value.Contains("OutlookGridDateTimeGroup"))
                    {
                        ((OutlookGridDateTimeGroup)group).Interval = (OutlookGridDateTimeGroup.DateInterval)Enum.Parse(typeof(OutlookGridDateTimeGroup.DateInterval), node2.Element("GroupDateInterval").Value);
                    }
                }
                OutlookColumnsToAdd[i] = new OutlookGridColumn(columnsToAdd[i], group, (SortOrder)Enum.Parse(typeof(SortOrder), node.Element("SortDirection").Value), int.Parse(node.Element("GroupIndex").Value), int.Parse(node.Element("SortIndex").Value));

                i += 1;
            }
            //First add the underlying DataGridViewColumns to the grid
            Grid.Columns.AddRange(columnsToAdd);
            //And then the outlookgrid columns
            Grid.AddRangeInternalColumns(OutlookColumnsToAdd);

            //Add conditionnal formatting to the grid
            EnumConditionalFormatType conditionFormatType   = default(EnumConditionalFormatType);
            IFormatParams             conditionFormatParams = default(IFormatParams);

            foreach (XElement node in doc.XPathSelectElement("OutlookGrid/ConditionalFormatting").Nodes())
            {
                conditionFormatType = (EnumConditionalFormatType)Enum.Parse(typeof(EnumConditionalFormatType), node.Element("FormatType").Value);
                XElement nodeParams = node.Element("FormatParams");
                switch (conditionFormatType)
                {
                case EnumConditionalFormatType.Bar:
                    conditionFormatParams = new BarParams(Color.FromArgb(int.Parse(nodeParams.Element("BarColor").Value)), CommonHelper.StringToBool(nodeParams.Element("GradientFill").Value));
                    break;

                case EnumConditionalFormatType.ThreeColorsRange:
                    conditionFormatParams = new ThreeColorsParams(Color.FromArgb(int.Parse(nodeParams.Element("MinimumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MediumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MaximumColor").Value)));
                    break;

                case EnumConditionalFormatType.TwoColorsRange:
                    conditionFormatParams = new TwoColorsParams(Color.FromArgb(int.Parse(nodeParams.Element("MinimumColor").Value)), Color.FromArgb(int.Parse(nodeParams.Element("MaximumColor").Value)));
                    break;

                default:
                    conditionFormatParams = null;
                    //will never happened but who knows ? throw exception ?
                    break;
                }
                Grid.ConditionalFormatting.Add(new ConditionalFormatting(node.Element("ColumnName").Value, conditionFormatType, conditionFormatParams));
            }



            //We need to loop through the columns in the order of the display order, starting at zero; otherwise the columns will fall out of order as the loop progresses.
            foreach (KeyValuePair <int, int> kvp in hash)
            {
                columnsToAdd[kvp.Value].DisplayIndex = kvp.Key;
            }

            activeColumns = enumCols;
        }