private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to import the selected artefacts?", "Import", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (string cb in checkedListBoxArtefact.CheckedItems)
                {
                    if (cb.IndexOf("[DSD]") > -1)
                    {
                    }
                    else
                    {
                        string   val     = cb.Replace("[Codelist]: ", "");
                        string[] id_rest = val.Split(':');
                        string   agency  = id_rest[0].Trim();
                        string   id      = id_rest[1].Substring(0, id_rest[1].IndexOf('(')).Trim();
                        string   version = id_rest[1].Substring(id_rest[1].IndexOf('(') + 1).Replace(")", "").Trim();

                        foreach (BaseArtefactInfo bs in _codelistList)
                        {
                            if (bs.sdmxId == id && bs.sdmxVersion == version && bs.sdmxAgency == agency)
                            {
                                CommonItem.WaitOn();

                                VTLInt_Service.ServiceClient VTLMan   = VTLInt_ServiceManager.GetClient(CommonItem.CurrentSettings.InteractionWebService);
                                BaseArtefactInfo[]           one_item = { bs };
                                VTLMan.InsertValueDomain(id, agency, version, bs.name.ToArray(), one_item, true, BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD, ArtefactInfo.VTL.VTL_Model.VTL_DATATYPE.String);

                                CommonItem.WaitOff();
                            }
                        }
                    }
                }
                MessageBox.Show("Selected artefacts imported!");
            }
        }
        private void cm_ItemImportClicked(object sender, System.EventArgs e)
        {
            try
            {
                TreeNode                     tmpNode = (TreeNode)((MenuItem)sender).Tag;
                ArtefactNodeInfo             artInfo = (ArtefactNodeInfo)tmpNode.Tag;
                VTLInt_Service.ServiceClient VTLMan  = VTLInt_ServiceManager.GetClient(CommonItem.CurrentSettings.InteractionWebService);

                MetadataLoader mtl = null;

                //VTLMan.LineCountEvent += LineCountEventManager;


                switch (artInfo.artType)
                {
                case ArtefactNodeInfo.ArtefactType.ValueDomains:
                    string vd_id      = artInfo.artefactInfo.sdmxId;
                    string vd_agency  = artInfo.artefactInfo.sdmxAgency;
                    string vd_version = artInfo.artefactInfo.sdmxVersion;

                    if (MessageBox.Show("Do you want import into the VTL database the codelist: \n " + vd_id + " " + vd_agency + " " + vd_version, "Import codelist", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> dsList = mtl.LoadCodelistCodes21(vd_id, vd_agency, vd_version);

                        VTLMan.InsertValueDomain(vd_id, vd_agency, vd_version, artInfo.artefactInfo.name.ToArray(), dsList.ToArray(), true, BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD, ArtefactInfo.VTL.VTL_Model.VTL_DATATYPE.String);

                        CommonItem.WaitOff();

                        MessageBox.Show("Value domain :" + vd_id + " " + vd_agency + " " + vd_version + " successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }

                    break;

                case ArtefactNodeInfo.ArtefactType.DataStructureComponents:
                    string[] globIdent = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(artInfo.artefactComponentInfo)).valuedomain_id);

                    string cmp_id      = globIdent[0];
                    string cmp_agency  = globIdent[1];
                    string cmp_version = globIdent[2];

                    CommonItem.WaitOn();

                    mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                    List <BaseArtefactInfo> cmpList = mtl.LoadCodelistCodes21(cmp_id, cmp_agency, cmp_version);

                    VTLMan.InsertValueDomain(cmp_id, cmp_agency, cmp_version, artInfo.artefactInfo.name.ToArray(), cmpList.ToArray(), true, BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD, ArtefactInfo.VTL.VTL_Model.VTL_DATATYPE.String);

                    CommonItem.WaitOff();

                    MessageBox.Show("Value domain :" + cmp_id + " " + cmp_agency + " " + cmp_version + " successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    tmpNode.ForeColor = Color.Gray;
                    break;

                case ArtefactNodeInfo.ArtefactType.DataStructures:
                    string dsd_id      = artInfo.artefactInfo.sdmxId;
                    string dsd_agency  = artInfo.artefactInfo.sdmxAgency;
                    string dsd_version = artInfo.artefactInfo.sdmxVersion;
                    List <BaseArtefactInfo>  valueDomainValueList;
                    List <BaseComponentInfo> componentsList = new List <BaseComponentInfo>();

                    if (MessageBox.Show("Do you want import into the VTL database the Datastructure: \n " + dsd_id + " " + dsd_agency + " " + dsd_version + "\n and all the referenced artefacts?", "Import datastructure", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();
                        label1.Text = DateTime.Now.ToString();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> componentList = mtl.LoadDataStructuresComponents21(dsd_id, dsd_agency, dsd_version);

                        foreach (BaseComponentInfo comp in componentList[0].DataStructureDetails.Components)
                        {
                            BaseComponentInfo tmpComponentInfo     = new BaseComponentInfo();
                            ValueDomainInfoInDataStructure tmpInfo = new ValueDomainInfoInDataStructure();
                            string[] globalId = null;

                            tmpComponentInfo.vtlId = comp.vtlId;
                            tmpComponentInfo.name  = comp.name;
                            tmpComponentInfo.datastructure_id_ref = comp.datastructure_id_ref;
                            tmpComponentInfo.seq_id = comp.seq_id;

                            switch (((ArtefactInfo.model.DataStructureComponentInfo)(comp)).role)
                            {
                            case "Dimension":
                                tmpComponentInfo.Role = "Identifier";
                                if (!String.IsNullOrEmpty(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id))
                                {
                                    globalId = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id);
                                }
                                break;

                            case "TimeDimension":
                                tmpComponentInfo.Role = "Identifier";
                                globalId = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.TIME_PERIOD_default_valueDomainID);
                                break;

                            case "PrimaryMeasure":
                                tmpComponentInfo.Role = "Measure";
                                globalId = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.OBS_default_valueDomainID);
                                break;
                            }

                            tmpInfo.vd_id      = globalId[0];
                            tmpInfo.vd_agency  = globalId[1];
                            tmpInfo.vd_version = globalId[2];

                            valueDomainValueList = mtl.LoadCodelistCodes21(globalId[0], globalId[1], globalId[2]);

                            if (valueDomainValueList != null)
                            {
                                tmpInfo.values = valueDomainValueList;
                            }

                            if (comp.name != null)
                            {
                                tmpInfo.names = comp.name;
                            }
                            else
                            {
                                tmpInfo.names = new List <LocalizedValue>();
                                tmpInfo.names.Add(new LocalizedValue("EN", comp.vtlId));
                            }

                            tmpComponentInfo.ValueDomainInfo = tmpInfo;

                            componentsList.Add(tmpComponentInfo);
                        }
                        try
                        {
                            VTLMan.InsertDataStructure(dsd_id, dsd_agency, dsd_version, artInfo.artefactInfo.name.ToArray(), componentsList.ToArray(), BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD);
                        }
                        catch (TimeoutException ext)
                        {
                            MessageBox.Show("Time out exception");
                            return;
                        }

                        label2.Text = DateTime.Now.ToString();
                        CommonItem.WaitOff();

                        MessageBox.Show("Data structures :" + dsd_id + " " + dsd_agency + " " + dsd_version + "  and all the linked components successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }
                    break;

                case ArtefactNodeInfo.ArtefactType.DataFlows:
                    string ref_dsd_id      = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_id;
                    string ref_dsd_agency  = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_agency;
                    string ref_dsd_version = ((DataSetInfo)artInfo.artefactInfo).sdmx_DataStructure_version;
                    string df_id           = ((DataSetInfo)artInfo.artefactInfo).sdmxId;
                    string df_agency       = ((DataSetInfo)artInfo.artefactInfo).sdmxAgency;
                    string df_version      = ((DataSetInfo)artInfo.artefactInfo).sdmxVersion;

                    List <BaseArtefactInfo>  ds_valueDomainValueList;
                    List <BaseComponentInfo> ds_componentsList = new List <BaseComponentInfo>();

                    if (MessageBox.Show("Do you want import into the VTL database the DataSet: \n " + df_id + " " + df_agency + " " + df_version + "\n and all the referenced artefacts?", "Import datastructure", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        CommonItem.WaitOn();
                        label1.Text = DateTime.Now.ToString();

                        mtl = new MetadataLoader(CommonItem.CurrentSettings.QueriesPath, new WebServiceLayer.classes.service.Net.WebServiceLayer(CommonItem.CurrentSettings, int.Parse(artInfo.webServiceID)));
                        List <BaseArtefactInfo> componentList = mtl.LoadDataStructuresComponents21(ref_dsd_id, ref_dsd_agency, ref_dsd_version);

                        BaseComponentInfo tmpInfo;
                        ValueDomainInfoInDataStructure tmpValueDomain;

                        foreach (BaseComponentInfo comp in componentList[0].DataStructureDetails.Components)
                        {
                            tmpInfo       = new BaseComponentInfo();
                            tmpInfo.vtlId = comp.vtlId;
                            tmpInfo.name  = comp.name;
                            string[] globalId = null;


                            switch (((ArtefactInfo.model.DataStructureComponentInfo)(comp)).role)
                            {
                            case "Dimension":
                                tmpInfo.Role = "Identifier";
                                if (!String.IsNullOrEmpty(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id))
                                {
                                    globalId = CommonConstant.splitGlobalID(((ArtefactInfo.model.DataStructureComponentInfo)(comp)).valuedomain_id);
                                }
                                break;

                            case "TimeDimension":
                                tmpInfo.Role = "Identifier";
                                globalId     = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.TIME_PERIOD_default_valueDomainID);
                                break;

                            case "PrimaryMeasure":
                                tmpInfo.Role = "Measure";
                                globalId     = CommonConstant.splitGlobalID(CommonItem.CurrentSettings.OBS_default_valueDomainID);
                                break;
                            }
                            tmpValueDomain = new ValueDomainInfoInDataStructure();

                            tmpValueDomain.vd_id      = globalId[0];
                            tmpValueDomain.vd_agency  = globalId[1];
                            tmpValueDomain.vd_version = globalId[2];

                            if (comp.name != null)
                            {
                                tmpValueDomain.names = comp.name;
                            }
                            else
                            {
                                tmpValueDomain.names = new List <LocalizedValue>();
                                tmpValueDomain.names.Add(new LocalizedValue("EN", comp.vtlId));
                            }

                            ds_valueDomainValueList = mtl.LoadCodelistCodes21(globalId[0], globalId[1], globalId[2]);

                            if (ds_valueDomainValueList != null)
                            {
                                tmpValueDomain.values = ds_valueDomainValueList;
                            }

                            tmpInfo.ValueDomainInfo = tmpValueDomain;
                            ds_componentsList.Add(tmpInfo);
                        }
                        try
                        {
                            VTLMan.InsertDataSet(ref_dsd_id, ref_dsd_agency, ref_dsd_version, df_id, df_agency, df_version, artInfo.artefactInfo.name.ToArray(), ds_componentsList.ToArray(), BaseArtefactInfo.CREATION_TYPE.SDMX_WS_UPLOAD);
                        }
                        catch (TimeoutException ds_ext)
                        {
                            MessageBox.Show("Time out exception");
                            return;
                        }

                        label2.Text = DateTime.Now.ToString();
                        CommonItem.WaitOff();

                        MessageBox.Show("Data set :" + df_id + " " + df_agency + " " + df_version + "  and all the linked components successufully imported", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        tmpNode.ForeColor = Color.Gray;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                CommonItem.ErrManger.ErrorManagement(ex, false, this);
            }
            finally
            {
                CommonItem.WaitOff();
            }
        }