Self Referencing Class and Hierarchy

5 posts, 0 answers
  1. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 12 Feb 2010 Link to this post

    Hi guys

    I'm banging my head against the wall with this one, I really need help.


    Here's my problem :

    I have a class, which is defined as the following :

    public class NomenclatureHierarchy 
        { 
            public NomenclatureHierarchy(donnees_grilleBO menu) 
            { 
                _menu = menu; 
                _sous_menu = new List<NomenclatureHierarchy>(); 
            } 
     
            public donnees_grilleBO _menu; 
            public donnees_grilleBO _Menu { get { return _menu; } } 
     
            List<NomenclatureHierarchy> _sous_menu; 
            public List<NomenclatureHierarchy> _Sous_menu { get { return _sous_menu; } } 
        } 

    What I'd like to do is use the self reference functionnality of the RadGridView to display a hierarchical grid which would have in the first level, the _Menu attribute, and then, in the child grid, the content of _Sous_menu (which of course, can have a _Sous_menu as well)

    So basically, can I create a self reference hierarchical grid from a self recursive datatype ?


  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 15 Feb 2010 Link to this post

    Hi Subileau Pascal,

    The Self Referencing hierarchy works by matching properties on the date items that are used as ItemsSource. For instance, our Self Reference demo uses Employee data object that have the following properties:

    public class Employee : INotifyPropertyChanging, INotifyPropertyChanged
        {
      
            private int _EmployeeID;
              
            private System.Nullable<int> _ReportsTo;
    }

    In addition to that we create new TableDefinition that sets up the relationship:

    <Controls:RadGridView.ChildTableDefinitions>
                  <Controls:GridViewTableDefinition>
                      <Controls:GridViewTableDefinition.Relation>
                          <data:TableRelation IsSelfReference="True">
                              <data:TableRelation.FieldNames>
                                  <data:FieldDescriptorNamePair 
                                      ParentFieldDescriptorName="EmployeeID" 
                                      ChildFieldDescriptorName="ReportsTo"/>
                              </data:TableRelation.FieldNames>
                          </data:TableRelation>
                      </Controls:GridViewTableDefinition.Relation>
                  </Controls:GridViewTableDefinition>
              </Controls:RadGridView.ChildTableDefinitions>

    With this definition we are instructing the grid to match the EmployeID property of every data item to the ReportTo properties of all data items. All matching rows are displayed in a child grid.

    If your data items allows such matching there should be no problem to create a self referencing hierarchy. 

    How do you intend to match NomenclatureHierarchy (_Sous_menu) to NomenclatureHierarchy?


    Best wishes,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 16 Feb 2010 Link to this post

    Well, actually, I managed to use the Self reference hierarchy the way I wanted it by creating in code behind a tabledefinition and a Propertyrelation like this

     
                    PropertyRelation relation = new PropertyRelation("_Sous_menu"); 
                    relation.IsSelfReference = true
                    GridViewTableDefinition table = new GridViewTableDefinition(); 
     
                    table.Relation = relation; 
                    this.NomenclatureGridView.ChildTableDefinitions.Add(table); 
                    this.NomenclatureGridView.ItemsSource = nomenclatureStruct; 

    Then, I subscribed to the loading event to recreate in every child grid when they load the columns to display with the proper binding of the IList<donnees_grilleBO> for each of its element, and for each gridviewdatacontrol, I subscribed to the rowloaded event to test if there is still elements to display in hierarchy, otherwise, I just set the IsExpandable to false.

    This way, I can get a n-deep hierarchical grid using a simple recursive class.


  5. Mark Huck
    Mark Huck avatar
    12 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2010 Link to this post

    Thanks, Subileau!

    You wouldn't happen to have a sample project of this? 
  6. Ludovic Gerbault
    Ludovic Gerbault avatar
    226 posts
    Member since:
    Apr 2009

    Posted 09 Mar 2010 Link to this post

    Hi Mark Huck

    Here's the source code I've used for my scenario

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Net; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Documents; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Animation; 
    using System.Windows.Shapes; 
    using SilverService.ApplicationService; 
    using T2J_Application.SilverNomenclatureGrille.Classes; 
    using T2J_Application.SilverEdition.Classes; 
    using Telerik.Windows; 
    using Telerik.Windows.Controls.TreeList; 
    using Telerik.Windows.Controls; 
    using System.Windows.Data; 
    using System.Windows.Markup; 
    using System.Text; 
    using Telerik.Windows.Data; 
    using Telerik.Windows.Controls.GridView; 
    namespace T2J_Application.SilverNomenclatureGrille 
        public partial class NomenclatureMainPage : UserControl 
        { 
            int id_client; 
            int id_societe; 
            int id_categorie_partenaire; 
            int id_contact; 
            int id_partenaire; 
            DataTable collection; 
            ApplicationServiceClient _wsNomenclatureService = new ApplicationServiceClient(); 
            ArticleBO currentArticle; 
     
            public NomenclatureMainPage(int id_client, int id_contact) 
            { 
                InitializeComponent(); 
     
                this.id_client = id_client; 
                this.id_contact = id_contact; 
     
                //_wsNomenclatureService.ListeFamillesAsync(this.id_client, this.id_contact); 
               // _wsNomenclatureService.ListeFamillesCompleted +=new EventHandler<ListeFamillesCompletedEventArgs>(_wsNomenclatureService_ListeFamillesCompleted); 
            } 
     
            public NomenclatureMainPage(int id_societe,int id_categorie_partenaire, int id_contact) 
            { 
                InitializeComponent(); 
     
                this.id_societe = id_societe; 
                this.id_categorie_partenaire = id_categorie_partenaire; 
                this.id_contact = id_contact; 
     
                _wsNomenclatureService.ExecuteInterfaceSelectAsync(this.id_societe, this.id_categorie_partenaire, this.id_contact); 
                _wsNomenclatureService.ExecuteInterfaceSelectCompleted += new EventHandler<ExecuteInterfaceSelectCompletedEventArgs>(_wsNomenclatureService_ExecuteInterfaceSelectCompleted); 
                
            } 
     
            public NomenclatureMainPage(int id_societe, int id_categorie_partenaire, int id_contact, int id_partenaire) 
            { 
                InitializeComponent(); 
     
                this.id_societe = id_societe; 
                this.id_categorie_partenaire = id_categorie_partenaire; 
                this.id_contact = id_contact; 
                this.id_partenaire = id_partenaire; 
     
                NomenclatureGridView.DataLoading += new EventHandler<Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs>(NomenclatureGridView_DataLoading); 
                _wsNomenclatureService.ExecuteInterfaceSelectAsync(this.id_societe, this.id_categorie_partenaire, this.id_contact); 
                _wsNomenclatureService.ExecuteInterfaceSelectCompleted += new EventHandler<ExecuteInterfaceSelectCompletedEventArgs>(_wsNomenclatureService_ExecuteInterfaceSelectCompleted); 
            } 
     
            void NomenclatureGridView_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e) 
            { 
                var dataControl = sender as GridViewDataControl; 
                IList<NomenclatureHierarchy> result = dataControl.ItemsSource as List<NomenclatureHierarchy>; 
               
                if (result.Count != 0) 
                { 
                    if (dataControl.Parent == null
                    { 
                        dataControl.AutoGenerateColumns = false
                        dataControl.ShowGroupPanel = false
                        dataControl.ShowColumnHeaders = false
                        CreerColonnes(dataControl, result[0]._Menu); 
                    } 
                    dataControl.RowLoaded += new EventHandler<RowLoadedEventArgs>(dataControl_RowLoaded); 
                } 
                else 
                { 
                    dataControl.TableDefinition.ChildTableDefinitions.Clear(); 
                } 
            } 
     
            void dataControl_RowLoaded(object sender, RowLoadedEventArgs e) 
            { 
                NomenclatureHierarchy element = e.DataElement as NomenclatureHierarchy; 
                if (e.Row.GetType() == typeof(GridViewRow)) 
                { 
                    e.Row.Tag = "588634";  
                    ((GridViewRow)e.Row).IsExpandable = (element._Sous_menu.Count != 0); 
                } 
            } 
     
     
     
            void _wsNomenclatureService_ExecuteInterfaceSelectCompleted(object sender, ExecuteInterfaceSelectCompletedEventArgs e) 
            { 
                _wsNomenclatureService.ExecuteInterfaceSelectCompleted -= new EventHandler<ExecuteInterfaceSelectCompletedEventArgs>(_wsNomenclatureService_ExecuteInterfaceSelectCompleted); 
                _wsNomenclatureService.GetOngletsAllContentAsync(this.id_societe, this.id_categorie_partenaire, this.id_contact); 
                _wsNomenclatureService.GetOngletsAllContentCompleted += new EventHandler<GetOngletsAllContentCompletedEventArgs>(_wsNomenclatureService_GetOngletsAllContentCompleted); 
            } 
     
            void _wsNomenclatureService_GetOngletsAllContentCompleted(object sender, GetOngletsAllContentCompletedEventArgs e) 
            { 
                _wsNomenclatureService.GetOngletsAllContentCompleted -= new EventHandler<GetOngletsAllContentCompletedEventArgs>(_wsNomenclatureService_GetOngletsAllContentCompleted); 
                if (e.Result != null
                { 
                    IList<NomenclatureHierarchy> nomenclatureStruct = new List<NomenclatureHierarchy>(); 
                    IList<donnees_grilleBO> result = e.Result; 
     
                    CreerColonnes(this.NomenclatureGridView,result[0]); 
                    IList<donnees_grilleBO> ItemParents = new List<donnees_grilleBO>(); 
                    IList<donnees_grilleBO> ItemEnfants = new List<donnees_grilleBO>(); 
     
                    foreach (donnees_grilleBO item in result) 
                    { 
                        if (int.Parse(item.id_fils) == int.Parse(item.id_pere)) 
                        { 
                            ItemParents.Add(item); 
                        } 
                        else 
     
                        { 
                            ItemEnfants.Add(item); 
                        } 
                    } 
     
                    foreach (donnees_grilleBO itemMenu in ItemParents) 
                    { 
                        nomenclatureStruct.Add(GetHierarchyElement(itemMenu, ItemEnfants)); 
                    } 
     
                    PropertyRelation relation = new PropertyRelation("_Sous_menu"); 
                    relation.IsSelfReference = true
                    GridViewTableDefinition table = new GridViewTableDefinition(); 
     
                    table.Relation = relation; 
                    this.NomenclatureGridView.ChildTableDefinitions.Add(table); 
                    this.NomenclatureGridView.ItemsSource = nomenclatureStruct; 
                } 
            } 
     
            private NomenclatureHierarchy GetHierarchyElement(donnees_grilleBO element, IList<donnees_grilleBO> enfants) 
            { 
                IList<donnees_grilleBO> enfantsTemp = new List<donnees_grilleBO>(); 
                foreach (donnees_grilleBO item in enfants) 
                { 
                    enfantsTemp.Add(item); 
                } 
                NomenclatureHierarchy hierarchy = new NomenclatureHierarchy(element); 
                for (int i = 0; i < enfantsTemp.Count; i++) 
                { 
                    donnees_grilleBO enfant = enfantsTemp[i]; 
                    if (int.Parse(element.id_fils) == int.Parse(enfant.id_pere)) 
                    { 
                        enfantsTemp.Remove(enfant); 
                        i--; 
                        hierarchy._Sous_menu.Add(GetHierarchyElement(enfant, enfantsTemp)); 
                    }    
                } 
                return hierarchy; 
            } 
     
            private void CreerColonnes(GridViewDataControl grid, donnees_grilleBO result) 
            { 
                if (grid.Columns.Count == 0) 
                { 
                    if (result != null
                    { 
                        String[] ComboValeurs = result.nom_colonnes.Split('|'); 
                        DataTable table = new DataTable(); 
                        table.Columns.Add(new DataColumn() { ColumnName = "Name", DataType = typeof(string) }); 
                        table.Columns.Add(new DataColumn() { ColumnName = "type", DataType = typeof(string) }); 
     
                        foreach (String ra in ComboValeurs) 
                        { 
     
                            String[] temp = ra.Split('-'); 
                            if (temp[0] != ""
                            { 
                                DataRow row = new DataRow(); 
                                row["Name"] = temp[0].ToString(); 
                                row["type"] = temp[1].ToString(); 
                                table.Rows.Add(row); 
                            } 
                        } 
                        int index = 0; 
                        foreach (DataRow row in table.Rows) 
                        { 
                            String path = ""
     
                            switch (index) 
                            { 
                                case 0: path = "txta"
                                    break
                                case 1: path = "txtb"
                                    break
                                case 2: path = "txtc"
                                    break
                                case 3: path = "txtd"
                                    break
                                case 4: path = "txte"
                                    break
                                case 5: path = "txtf"
                                    break
                                case 6: path = "txtg"
                                    break
                                case 7: path = "txth"
                                    break
                                case 8: path = "txti"
                                    break
                                case 9: path = "txtj"
                                    break
                                case 10: path = "txtk"
                                    break
                                case 11: path = "txtl"
                                    break
                                case 12: path = "txtm"
                                    break
                                case 13: path = "txtn"
                                    break
                                case 14: path = "txto"
                                    break
                                case 15: path = "txtp"
                                    break
                                case 16: path = "txtq"
                                    break
                                case 17: path = "txtr"
                                    break
                                case 18: path = "txts"
                                    break
                                case 19: path = "txtt"
                                    break
     
                            } 
     
                            GridViewDataColumn col8 = new GridViewDataColumn() { Header = row["Name"].ToString().Replace('_', ' ') }; 
     
                            StringBuilder CellTemp = new StringBuilder(); 
                            CellTemp.Append("<DataTemplate "); 
                            CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/"); 
                            CellTemp.Append("2006/xaml/presentation' "); 
                            CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>"); 
                            CellTemp.Append("<TextBlock "); 
                            CellTemp.Append("Text = '{Binding _Menu." + path + "}' />"); 
                            CellTemp.Append("</DataTemplate>"); 
     
                            StringBuilder CellETemp = new StringBuilder(); 
                            CellETemp.Append("<DataTemplate "); 
                            CellETemp.Append("xmlns='http://schemas.microsoft.com/winfx/"); 
                            CellETemp.Append("2006/xaml/presentation' "); 
                            CellETemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>"); 
                            CellETemp.Append("<TextBlock "); 
                            CellETemp.Append("Text = '{Binding _Menu." + path + "}' />"); 
                            CellETemp.Append("</DataTemplate>"); 
     
     
                            col8.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString()); 
                            col8.CellEditTemplate = (DataTemplate)XamlReader.Load(CellETemp.ToString()); 
                            col8.IsGroupable = true
                            col8.IsFilterable = true
                            grid.Columns.Add(col8); 
                            index++; 
                        } 
                    } 
                } 
            } 
            public void CreerCollection(IList<donnees_grilleBO> result) 
            { 
                if (result.Count != 0) 
                { 
                    collection = new DataTable(); 
                    String r = result[0].nom_colonnes; 
     
                    String[] tokenQuery = r.Split('|'); 
     
                    for (int i = 0; i < tokenQuery.Length; i++) 
                    { 
                        if (tokenQuery[i] != ""
                        { 
                            String[] colonne_param = tokenQuery[i].Split('-'); 
                            String nom_col = colonne_param[0]; 
                            String type_col = colonne_param[1].Trim(); 
                            DataColumn col = new DataColumn(); 
                            col.type_col = type_col; 
                            switch (type_col) 
                            { 
                                case "1": col.DataType = typeof(string); 
                                    break
                                case "2": col.DataType = typeof(string); 
                                    break
                                case "3": col.DataType = typeof(string); 
                                    break
                                case "4": col.DataType = typeof(string); 
                                    break
                                case "5": col.DataType = typeof(string); 
                                    break
                                case "6": col.DataType = typeof(string); 
                                    break
                                case "7": col.DataType = typeof(string); 
                                    break
                                default: col.DataType = typeof(string); 
                                    break
                            } 
                            col.groupable = true
                            col.attribut = nom_col; 
                            col.ColumnName = nom_col; 
                            col.IsVisible = true
                            collection.Columns.Add(col); 
                        } 
                    } 
     
                    DataColumn col_id_partenaire = new DataColumn(); 
                    col_id_partenaire.ColumnName = "id_partenaire"
                    col_id_partenaire.DataType = typeof(string); 
                    col_id_partenaire.type_col = "2"
                    col_id_partenaire.groupable = true
                    col_id_partenaire.aggrege = true
                    col_id_partenaire.attribut = "id_partenaire"
                    col_id_partenaire.IsVisible = false
                    collection.Columns.Add(col_id_partenaire); 
     
                    DataColumn col_row = new DataColumn(); 
                    col_row.ColumnName = "row"
                    col_row.DataType = typeof(DataRow); 
                    col_row.type_col = "1"
                    col_row.groupable = true
                    col_row.aggrege = true
                    col_row.attribut = "row"
                    col_row.IsVisible = false
                    collection.Columns.Add(col_row); 
     
                    DataColumn col2_row = new DataColumn(); 
                    col2_row.ColumnName = "id_pere"
                    col2_row.DataType = typeof(string); 
                    col2_row.type_col = "2"
                    col2_row.groupable = true
                    col2_row.aggrege = true
                    col2_row.attribut = "id_pere"
                    col2_row.IsVisible = false
                    collection.Columns.Add(col2_row); 
     
                    DataColumn col4_row = new DataColumn(); 
                    col4_row.ColumnName = "id_article"
                    col4_row.DataType = typeof(string); 
                    col4_row.type_col = "2"
                    col4_row.groupable = true
                    col4_row.aggrege = true
                    col4_row.attribut = "id_article"
                    col4_row.IsVisible = false
                    collection.Columns.Add(col4_row); 
     
                    DataColumn col3_row = new DataColumn(); 
                    col3_row.ColumnName = "id_fils"
                    col3_row.DataType = typeof(string); 
                    col3_row.type_col = "2"
                    col3_row.groupable = true
                    col3_row.aggrege = true
                    col3_row.attribut = "id_fils"
                    col3_row.IsVisible = false
                    collection.Columns.Add(col3_row); 
     
                    int y = 0; 
                    foreach (donnees_grilleBO ligne2 in result) 
                    { 
                        DataRow row = new DataRow(); 
     
                        foreach (DataColumn col in collection.Columns.Where(x => x.IsVisible == true)) 
                        { 
                            switch (y) 
                            { 
                                case 0: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txta.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txta.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txta.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txta.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txta.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 1: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtb.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtb.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtb.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtb.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtb.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 2: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtc.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtc.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtc.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtc.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtc.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 3: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtd.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtd.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtd.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtd.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtd.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 4: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txte.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txte.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txte.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txte.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txte.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 5: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtf.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtf.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtf.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtf.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtf.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 6: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtg.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtg.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtg.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtg.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtg.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 7: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txth.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txth.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txth.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txth.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txth.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 8: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txti.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txti.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txti.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txti.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txti.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 9: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtj.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtj.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtj.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtj.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtj.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 10: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtk.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtk.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtk.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtk.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtk.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 11: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtl.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtl.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtl.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtl.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtl.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 12: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtm.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtm.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtm.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtm.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtm.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 13: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtn.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtn.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtn.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtn.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtn.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 14: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txto.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txto.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txto.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txto.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txto.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 15: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtp.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtp.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtp.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtp.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtp.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 16: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtq.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtq.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtq.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtq.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtq.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 17: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtr.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtr.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtr.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtr.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtr.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 18: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txts.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txts.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txts.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txts.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txts.ToString().Replace('.', ',')); 
                                    } 
                                    break
                                case 19: 
                                    if (col.DataType == typeof(string)) 
                                    { 
                                        row[col.ColumnName] = ligne2.txtt.ToString(); 
                                    } 
                                    if (col.DataType == typeof(Decimal)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDecimal(ligne2.txtt.ToString().Replace('.', ',')); 
                                    } 
                                    if (col.DataType == typeof(DateTime)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToDateTime(ligne2.txtt.ToString()); 
                                    } 
                                    if (col.DataType == typeof(Boolean)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToBoolean(ligne2.txtt.ToString()); 
                                    } 
                                    if (col.DataType == typeof(int)) 
                                    { 
                                        row[col.ColumnName] = Convert.ToInt32(ligne2.txtt.ToString().Replace('.', ',')); 
                                    } 
                                    break
                            } 
                            y++; 
                        } 
                        y = 0; 
                        row["id_partenaire"] = ligne2.id_partenaire; 
                        row["row"] = row; 
                        row["id_pere"] = ligne2.id_pere.ToString(); 
                        row["id_fils"] = ligne2.id_fils.ToString(); 
                        row["id_article"] = ligne2.id_article.ToString(); 
                        collection.Rows.Add(row); 
                    } 
                } 
            } 
        } 
     
        class HierarchyComparer : EqualityComparer<donnees_grilleBO> 
        { 
            public override bool Equals(donnees_grilleBO x, donnees_grilleBO y) 
            { 
                if ((x.id_pere == y.id_pere)) 
                { 
                    return true
                } 
                else 
                { 
                    return false
                } 
            } 
     
            public override int GetHashCode(donnees_grilleBO temps) 
            { 
                int hCode = int.Parse(temps.id_pere.ToString()); 
                return hCode.GetHashCode(); 
            } 
        } 
     
     

    using System; 
    using System; 
    using System.Collections; 
    using System.Collections.Generic; 
    using System.Collections.ObjectModel; 
    using System.ComponentModel; 
    using System.Linq; 
    using System.Linq.Dynamic; 
    using System.Net; 
    using System.Web.Ria; 
    using System.Windows; 
    using System.Windows.Controls; 
    using System.Windows.Documents; 
    using System.Windows.Ink; 
    using System.Windows.Input; 
    using System.Windows.Media; 
    using System.Windows.Media.Animation; 
    using System.Windows.Shapes; 
    using SilverService.ApplicationService; 
     
    namespace T2J_Application.SilverNomenclatureGrille.Classes 
        public class NomenclatureHierarchy 
        { 
            public NomenclatureHierarchy(donnees_grilleBO menu) 
            { 
                _menu = menu; 
                _sous_menu = new List<NomenclatureHierarchy>(); 
            } 
     
            public donnees_grilleBO _menu; 
            public donnees_grilleBO _Menu { get { return _menu; } } 
     
            List<NomenclatureHierarchy> _sous_menu; 
            public List<NomenclatureHierarchy> _Sous_menu { get { return _sous_menu; } } 
        } 
     

Back to Top
DevCraft banner