protected void btnChangePaging_Click(object sender, EventArgs e)
        {
            ICodelistMutableObject cl = GetCodeListFromSession();

            if (cl == null) return;

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);

            IList<CodeItem> lCodeListItem = new List<CodeItem>();
            foreach (ICode code in cl.ImmutableInstance.Items)
            {
                lCodeListItem.Add(new CodeItem(code.Id, localUtils.GetNameableName(code), localUtils.GetNameableDescription(code), code.ParentCode));
            }

            int numberOfRows = 0;
            if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                if ( numberOfRows > 0 )
                {
                    gvCodelistsItem.PageSize = numberOfRows;
                }
                else
                {
                    gvCodelistsItem.PageSize = Utils.DetailsCodelistGridNumberRow;
                    txtNumberOfRows.Text = Utils.DetailsCodelistGridNumberRow.ToString();
                }
            }
            else if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && !int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                Utils.ShowDialog( Resources.Messages.err_wrong_rows_number_pagination );
                Utils.AppendScript( "location.href='#codes';" );
                return;
            }
            else if ( txtNumberOfRows.Text.Trim().Equals( string.Empty ) )
            {
                gvCodelistsItem.PageSize = Utils.DetailsCodelistGridNumberRow;
                txtNumberOfRows.Text = Utils.DetailsCodelistGridNumberRow.ToString();
            }
            gvCodelistsItem.DataSource = lCodeListItem;
            gvCodelistsItem.DataBind();
            Utils.AppendScript( "location.href='#codes';" );
        }
        protected void gvCodelistsItem_Sorting(object sender, GridViewSortEventArgs e)
        {
            ICodelistMutableObject cl = GetCodeListFromSession();

            if (cl == null) return;

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);

            IList<CodeItem> lCodeListItem = new List<CodeItem>();
            foreach (ICode code in cl.ImmutableInstance.Items)
            {
                lCodeListItem.Add(new CodeItem(code.Id, localUtils.GetNameableName(code), localUtils.GetNameableDescription(code), code.ParentCode));
            }

            if ((SortDirection)ViewState["SortExpr"] == SortDirection.Ascending)
            {
                lCodeListItem = lCodeListItem.OrderBy(x => TypeHelper.GetPropertyValue(x, e.SortExpression)).Reverse().ToList();
                ViewState["SortExpr"] = SortDirection.Descending;
            }
            else
            {
                lCodeListItem = lCodeListItem.OrderBy(x => TypeHelper.GetPropertyValue(x, e.SortExpression)).ToList();
                ViewState["SortExpr"] = SortDirection.Ascending;
            }
            int numberOfRows = 0;
            if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                gvCodelistsItem.PageSize = numberOfRows;
            }
            else if ( txtNumberOfRows.Text.Trim().Equals( string.Empty ) )
            {
                    gvCodelistsItem.PageSize = Utils.DetailsCodelistGridNumberRow;
            }
            gvCodelistsItem.DataSource = lCodeListItem;
            gvCodelistsItem.DataBind();
            Utils.AppendScript( "location.href='#codes'" );
        }
        private void BindData(bool isNewItem = false)
        {
            IOrganisationUnitSchemeMutableObject ous = GetOrganizationUnitSchemeFromSession();

            if (ous == null) return;

            SetGeneralTab(ous.ImmutableInstance);

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);
            IList<OrganizationUnit> lOrganizationUnitSchemeItem = new List<OrganizationUnit>();

            foreach (IOrganisationUnit organizationUnit in ous.ImmutableInstance.Items)
            {
                lOrganizationUnitSchemeItem.Add(new OrganizationUnit(organizationUnit.Id, localUtils.GetNameableName(organizationUnit), localUtils.GetNameableDescription(organizationUnit), organizationUnit.ParentUnit));
            }

            int numberOfRows = 0;

            if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                gvOrganizationunitschemesItem.PageSize = numberOfRows;
            }
            else
            {
                gvOrganizationunitschemesItem.PageSize = Utils.DetailsOrganizationUnitSchemeGridNumberRow;
            }
            lblNumberOfTotalElements.Text = string.Format( Resources.Messages.lbl_number_of_total_rows, lOrganizationUnitSchemeItem.Count.ToString() );

            gvOrganizationunitschemesItem.DataSource = lOrganizationUnitSchemeItem;
            gvOrganizationunitschemesItem.DataBind();

            if ( lOrganizationUnitSchemeItem.Count == 0 )
            {
                txtNumberOfRows.Visible = false;
                lblNumberOfRows.Visible = false;
                btnChangePaging.Visible = false;
            }
            else
            {
                txtNumberOfRows.Visible = true;
                lblNumberOfRows.Visible = true;
                btnChangePaging.Visible = true;
            }
        }
        private void BindData(bool isNewItem = false)
        {
            ICodelistMutableObject cl = GetCodeListFromSession();

            if (cl == null) return;

            SetGeneralTab(cl.ImmutableInstance);

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);

            IList<CodeItem> lCodeListItem = new List<CodeItem>();
            foreach (ICode code in cl.ImmutableInstance.Items)
            {
                lCodeListItem.Add(new CodeItem(code.Id, localUtils.GetNameableName(code), localUtils.GetNameableDescription(code), code.ParentCode));
            }

            int numberOfRows = 0;

            if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                gvCodelistsItem.PageSize = numberOfRows;
            }
            else
            {
                gvCodelistsItem.PageSize = Utils.DetailsCodelistGridNumberRow;
            }
            int numberOfTotalElements = lCodeListItem.Count;
            lblNumberOfTotalElements.Text = string.Format( Resources.Messages.lbl_number_of_total_rows, numberOfTotalElements.ToString() );
            gvCodelistsItem.DataSource = lCodeListItem;
            gvCodelistsItem.DataBind();

            if ( lCodeListItem.Count == 0 )
            {
                txtNumberOfRows.Visible = false;
                lblNumberOfRows.Visible = false;
                btnChangePaging.Visible = false;
                lblNoItemsPresent.Visible = true;
                lblNumberOfTotalElements.Visible = false;
            }
            else
            {
                txtNumberOfRows.Visible = true;
                lblNumberOfRows.Visible = true;
                btnChangePaging.Visible = true;
                lblNoItemsPresent.Visible = false;
                lblNumberOfTotalElements.Visible = true;
            }
        }
        private void BindData(bool isNewItem = false)
        {
            IAgencySchemeMutableObject agencyScheme = GetAgencySchemeFromSession();

            if (agencyScheme == null) return;

            SetGeneralTab(agencyScheme.ImmutableInstance);

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);
            IList<Agency> lAgencySchemeItem = new List<Agency>();

            foreach (IAgency agency in agencyScheme.ImmutableInstance.Items)
            {
                lAgencySchemeItem.Add(new Agency(agency.Id, localUtils.GetNameableName(agency), localUtils.GetNameableDescription(agency)));
            }

            int numberOfRows = 0;

            if ( !txtNumberOfRows.Text.Trim().Equals( string.Empty ) && int.TryParse( txtNumberOfRows.Text, out numberOfRows ) )
            {
                gvAgencyschemesItem.PageSize = numberOfRows;
            }
            else
            {
                gvAgencyschemesItem.PageSize = Utils.DetailsAgencyschemeGridNumberRow;
            }
            lblNumberOfTotalElements.Text = string.Format( Resources.Messages.lbl_number_of_total_rows, lAgencySchemeItem.Count.ToString() );
            gvAgencyschemesItem.DataSource = lAgencySchemeItem;
            gvAgencyschemesItem.DataBind();

            if ( lAgencySchemeItem.Count == 0 )
            {
                txtNumberOfRows.Visible = false;
                lblNumberOfRows.Visible = false;
                btnChangePaging.Visible = false;
                lblNoItemsPresent.Visible = true;
                lblNumberOfTotalElements.Visible = false;
            }
            else
            {
                txtNumberOfRows.Visible = true;
                lblNumberOfRows.Visible = true;
                btnChangePaging.Visible = true;
                lblNoItemsPresent.Visible = false;
                lblNumberOfTotalElements.Visible = true;
            }
        }
 private void RecursiveOnItems( ICategoryObject code, ref DataTable dt )
 {
     LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);
     string completeSequence = code.Parent.ToString().Split( '=' )[1].Split( ')' )[1];
     if ( !completeSequence.Equals( string.Empty )  )
     {
         completeSequence = completeSequence.Remove( 0, 1 );
     }
     dt.Rows.Add(code.Id, localizedUtils.GetNameableName(code), localizedUtils.GetNameableDescription( code ), completeSequence );
     if ( code.Items.Count != 0 )
     {
         foreach ( ICategoryObject subCode in code.Items )
         {
             RecursiveOnItems( subCode, ref dt );
         }
         return;
     }
     else
     {
         return;
     }
 }
        private void PopolateDataTable(DataTable dt, ISdmxObjects sdmxObjects)
        {
            LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);

            switch (ucArtefactType)
            {
                case "CodeList":
                    foreach (ICodelistObject codelist in sdmxObjects.Codelists)
                    {
                        foreach (ICode code in codelist.Items)
                        {
                            dt.Rows.Add(code.Id, localizedUtils.GetNameableName(code), localizedUtils.GetNameableDescription(code), code.ParentCode);
                        }
                        break;
                    }
                    break;
                case "ConceptScheme":
                    foreach (IConceptSchemeObject cs in sdmxObjects.ConceptSchemes)
                    {
                        foreach (IConceptObject concept in cs.Items)
                        {
                            dt.Rows.Add(concept.Id, localizedUtils.GetNameableName(concept), localizedUtils.GetNameableDescription( concept ), concept.ParentConcept );
                        }
                        break;
                    }
                    break;
                case "CategoryScheme":
                    foreach (ICategorySchemeObject cs in sdmxObjects.CategorySchemes)
                    {
                        foreach (ICategoryObject code in cs.Items)
                        {
                            string completeSequence = code.Parent.ToString().Split( '=' )[1].Split( ')' )[1];
                            if ( !completeSequence.Equals( string.Empty )  )
                            {
                                completeSequence = completeSequence.Remove( 0, 1 );
                            }
                            dt.Rows.Add(code.Id, localizedUtils.GetNameableName(code), localizedUtils.GetNameableDescription( code ), completeSequence );
                            if ( code.Items.Count != 0 )
                            {
                                foreach ( ICategoryObject subCode in code.Items )
                                {
                                    RecursiveOnItems( subCode, ref dt );
                                }
                            }
                        }
                        break;
                    }
                    break;
                case "DataFlow":
                    ISdmxObjects catObjects = GetCatObjects();
                    foreach (IDataflowObject dataFlow in sdmxObjects.Dataflows)
                    {
                        dt.Rows.Add("DataflowID", dataFlow.Id);
                        dt.Rows.Add("AgencyID", dataFlow.AgencyId);
                        dt.Rows.Add("Version", dataFlow.Version);
                        dt.Rows.Add("Name", localizedUtils.GetNameableName(dataFlow));
                        dt.Rows.Add("KeyFamilyID", dataFlow.DataStructureRef.MaintainableId);
                        dt.Rows.Add("KeyFamilyAgencyID", dataFlow.DataStructureRef.AgencyId);
                        dt.Rows.Add("KeyFamilyVersion", dataFlow.DataStructureRef.Version);

                        if (catObjects != null)
                        {
                            foreach (ICategorisationObject cat in catObjects.Categorisations)
                            {
                                if (cat.StructureReference.MaintainableId == dataFlow.Id &&
                                    cat.StructureReference.AgencyId == dataFlow.AgencyId &&
                                    cat.StructureReference.Version == dataFlow.Version)
                                {
                                    dt.Rows.Add("CategorySchemeID", cat.CategoryReference.MaintainableId);
                                    dt.Rows.Add("CategorySchemeAgencyID", cat.CategoryReference.AgencyId);
                                    dt.Rows.Add("CategorySchemeVersion", cat.CategoryReference.Version);
                                    dt.Rows.Add("CategoryID", cat.CategoryReference.FullId);
                                }
                            }
                        }
                        break;
                    }
                    break;
                case "Categorization":
                    foreach (ICategorisationObject cat in sdmxObjects.Categorisations)
                    {
                        dt.Rows.Add(cat.Id, localizedUtils.GetNameableName(cat), "");
                    }
                    break;
                case "AgencyScheme":
                    foreach (IAgencyScheme agency in sdmxObjects.AgenciesSchemes)
                    {
                        foreach (IAgency agencyItem in agency.Items)
                        {
                            dt.Rows.Add(agencyItem.Id, localizedUtils.GetNameableName(agencyItem), localizedUtils.GetNameableDescription( agencyItem ) );
                        }
                        break;
                    }
                    break;
                case "DataProviderScheme":
                    foreach (IDataProviderScheme dataProviderScheme in sdmxObjects.DataProviderSchemes)
                    {
                        foreach (IDataProvider dataProviderSchemeItem in dataProviderScheme.Items)
                        {
                            dt.Rows.Add(dataProviderSchemeItem.Id, localizedUtils.GetNameableName(dataProviderSchemeItem), localizedUtils.GetNameableDescription( dataProviderSchemeItem ) );
                        }
                        break;
                    }
                    break;
                case "DataConsumerScheme":
                    foreach (IDataConsumerScheme dataConsumerScheme in sdmxObjects.DataConsumerSchemes)
                    {
                        foreach (IDataConsumer dataConsumerSchemeItem in dataConsumerScheme.Items)
                        {
                            dt.Rows.Add(dataConsumerSchemeItem.Id, localizedUtils.GetNameableName(dataConsumerSchemeItem), localizedUtils.GetNameableDescription( dataConsumerSchemeItem ) );
                        }
                        break;
                    }
                    break;
                case "OrganizationUnitScheme":
                    foreach (IOrganisationUnitSchemeObject organizationUnitScheme in sdmxObjects.OrganisationUnitSchemes)
                    {
                        foreach (IOrganisationUnit organizationUnitSchemeItem in organizationUnitScheme.Items)
                        {
                            dt.Rows.Add(organizationUnitSchemeItem.Id, localizedUtils.GetNameableName(organizationUnitSchemeItem), localizedUtils.GetNameableDescription( organizationUnitSchemeItem ), organizationUnitSchemeItem.ParentUnit );
                        }
                        break;
                    }
                    break;
            }
        }
        private void BindData(bool isNewItem = false)
        {
            ICategorySchemeMutableObject cs = GetCategorySchemeFromSession();

            if (cs == null) return;

            SetGeneralTab(cs.ImmutableInstance);

            LocalizedUtils localUtils = new LocalizedUtils(Utils.LocalizedCulture);
            EntityMapper eMapper = new EntityMapper(Utils.LocalizedLanguage);

            TreeView1.Nodes.Clear();

            IList<Category> lCategorySchemeItem = new List<Category>();
            TreeNode rootNode = new TreeNode(string.Format("[ {0} ] {1}", cs.Id, localUtils.GetNameableName(cs.ImmutableInstance)));
            rootNode.Value = cs.Id;

            foreach (ICategoryObject category in cs.ImmutableInstance.Items)
            {
                //TreeNode node = new TreeNode( string.Format( "{0} - {1} - {2}", category.Id, localUtils.GetNameableName( category ), localUtils.GetNameableDescription( category ) ) );
                TreeNode node = new TreeNode(string.Format("[ {0} ] {1}", category.Id, localUtils.GetNameableName(category)));
                node.Value = category.Id;
                node.SelectAction = TreeNodeSelectAction.Select;
                CreateTreeWithRecursion(category, node);
                rootNode.ChildNodes.Add(node);
                lCategorySchemeItem.Add(new Category(category.Id, localUtils.GetNameableName(category), localUtils.GetNameableDescription(category), (category.IdentifiableParent != null) ? category.IdentifiableParent.Id : string.Empty));
            }

            TreeView1.Nodes.Add(rootNode);
            rootNode.Expand();
        }
        private void PopulateAgenciesGrid()
        {
            WSModel wsModel = new WSModel();
            LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture);
            string[] agencySchemeParts = cmbAgencies.SelectedItem.Text.Split('+');
            string id = agencySchemeParts[0], agencyId = agencySchemeParts[1], version = agencySchemeParts[2];
            IAgencyScheme agencyScheme = wsModel.GetAgencyScheme(new ArtefactIdentity(id, agencyId, version), false, true).AgenciesSchemes.FirstOrDefault();
            List<AssociatedAgency> items = new List<AssociatedAgency>();
            foreach (var agency in agencyScheme.Items)
            {
                items.Add(new AssociatedAgency(agency.Id, localizedUtils.GetNameableName(agency), localizedUtils.GetNameableDescription(agency), true));
            }
            gridView.DataSource = items;
            gridView.DataBind();

            List<string> agencies = null;
            if (Session[SESSION_KEYS.AGENCIES_TO_SET] == null)
            {
                agencies = new List<string>();
            }
            else
            {
                agencies = Session[SESSION_KEYS.AGENCIES_TO_SET] as List<string>;
            }

            foreach (GridViewRow row in gridView.Rows)
            {
                if (((CheckBox)row.Cells[3].Controls[1]).Checked)
                {
                    string currentAgency = ((Label)row.Cells[0].Controls[1]).Text;
                    if (!agencies.Contains(currentAgency))
                    {
                        agencies.Add(string.Format("{0}|{1}", currentAgency, cmbAgencies.SelectedItem.Text));
                    }
                }
            }

            Session[SESSION_KEYS.AGENCIES_TO_SET] = agencies;
            if (Page.IsPostBack)
            {
                Utils.AppendScript("openP('setAgencyDiv', 400 );");
            }
        }