Example #1
0
        public void DeleteFromXML(Guid varId)
        {
            List <Guid> lstRecID = RecordService.GetAllRecordID();
            Guid        vrId     = lstRecID.FirstOrDefault();

            try
            {
                List <ExportRecordData> exportDataList    = DataToList();
                List <ExportRecordData> newExportDataList = new List <ExportRecordData>();

                if (exportDataList != null)
                {
                    foreach (ExportRecordData e in exportDataList)
                    {
                        var index = e.Variables.FindIndex(a => a.Key == varId.ToString());

                        List <KeyValue>     vVariables  = e.Variables.Where(v => v.Key != varId.ToString()).ToList(); //should be -1
                        Guid                vRecID      = e.RecID;
                        List <ExportRecord> vRecords    = e.Records.ToList();
                        List <ExportRecord> newVRecords = new List <ExportRecord>();

                        foreach (ExportRecord r in vRecords)
                        {
                            ExportRecord newExp = new ExportRecord();
                            newExp = r;
                            try { r.VariableValues.RemoveAt(index); }
                            catch { }
                            newExp.VariableValues = r.VariableValues;
                            newVRecords.Add(newExp);
                        }

                        #region [Create New Record]
                        ExportRecordData exprt = new ExportRecordData();
                        exprt.RecID     = vRecID;
                        exprt.Records   = newVRecords;
                        exprt.Variables = vVariables;
                        #endregion

                        newExportDataList.Add(exprt);
                    }
                    SaveXMLToData(newExportDataList);
                }
            }
            catch (Exception ee)
            {
                ErrorLog.WriteLog("ManageRecordModel", "UpdateXML", ee, "");
            }
        }
Example #2
0
        public void UpdateXML()
        {
            List <Guid> lstRecID = RecordService.GetAllRecordID();
            Guid        vrId     = lstRecID.FirstOrDefault();

            try
            {
                List <ExportRecordData> exportDataList    = DataToList();
                List <ExportRecordData> newExportDataList = new List <ExportRecordData>();

                if (exportDataList != null)
                {
                    foreach (ExportRecordData e in exportDataList)
                    {
                        List <KeyValue>     vVariables = e.Variables;
                        Guid                vRecID     = e.RecID;
                        List <ExportRecord> vRecords   = e.Records.Where(x => x.RecordID != vrId).ToList();

                        #region [Create New Record]
                        ExportRecordData exprt = CreateNewRecord(vrId);
                        #endregion

                        foreach (ExportRecord r in exprt.Records)
                        {
                            vRecords.Add(r);
                        }
                        ExportRecordData expData = new ExportRecordData();
                        expData.RecID     = vRecID;
                        expData.Records   = vRecords;
                        expData.Variables = exprt.Variables;
                        newExportDataList.Add(expData);
                    }
                    SaveXMLToData(newExportDataList);
                }
            }
            catch (Exception ee)
            {
                ErrorLog.WriteLog("ManageRecordModel", "UpdateXML", ee, "");
            }
        }
        public void RebuildRecordAsync()
        {
            Guid          languageId = TSM.Model.TSMContext.CurrentLanguageID;
            List <Record> record     = new List <Record>();

            List <Guid> listRecordsID = RecordService.GetAllRecordID();

            List <ExportRecordData> ExportdataList = new List <ExportRecordData>();

            var cacheProvider = CacheFactory.Get();

            if (listRecordsID != null)
            {
                SearchAttributes searchParam = GetSearchParam();
                record = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam);
                ExportRecordData ExportRecordData = new ExportRecordData();
                ExportRecordData.Records = new List <ExportRecord>();

                #region [If Not Null Record]
                if (record != null)
                {
                    #region [Cache Data Load]

                    //Get Variable Items
                    List <Variable_Language> variableItems = new List <Variable_Language>();
                    variableItems = SearchServices.GetVariableLanguageForVariable(languageId).ToList();

                    //Get Get All Country With Region
                    List <Country> listofAllCountries = new List <Country>();
                    listofAllCountries = SearchServices.GetAllCountryWithRegion();

                    //Get list of All Region
                    List <Region_Language> listofAllRegion = new List <Region_Language>();
                    listofAllRegion = SearchServices.GetAllRegionWithLanguage();

                    //Get list of All  Country with language
                    List <Country_Language> lstCountryLang = new List <Country_Language>();
                    lstCountryLang = SearchServices.GetAllCountry(languageId);

                    //Get Sector Language
                    List <Sector_Language> lstSectorLanguage = new List <Sector_Language>();
                    lstSectorLanguage = SearchServices.GetAllSectorNames(languageId);

                    //Get Sector
                    List <TSMSector> lstTSMSector = new List <TSMSector>();
                    lstTSMSector = SearchServices.GetAllSector();

                    // Get Record Variable
                    List <Record_Variable> recordVariables = new List <Record_Variable>();
                    recordVariables = SearchServices.GetAllRecordVariable();

                    #endregion

                    foreach (var exportRecordData in record)
                    {
                        try
                        {
                            ExportRecordData.Variables = new List <KeyValue>();
                            foreach (var keyValue in variableItems)
                            {
                                KeyValue keyValuevariableLanguageItem = new KeyValue
                                {
                                    Key   = keyValue.ID.ToString(),
                                    Value = keyValue.Name
                                };
                                ExportRecordData.Variables.Add(keyValuevariableLanguageItem);
                            }
                            ExportRecord exportRecord = null;

                            #region [sector = 0 && country = 1]
                            if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count == 0))
                            {
                                exportRecord = new ExportRecord();
                                //document
                                try
                                {
                                    if (exportRecordData.Documents.Count > 0)
                                    {
                                        exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                    }
                                    else
                                    {
                                        exportRecord.Document = null;
                                    }
                                }
                                catch
                                {
                                    exportRecord.Document = "";
                                }
                                //ID
                                exportRecord.RecordID = exportRecordData.ID;

                                //Name
                                exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower();

                                //Regions start
                                var     selectedRegion = new List <Region>();
                                Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                if (tmpCountry != null)
                                {
                                    foreach (var r in tmpCountry.Regions)
                                    {
                                        selectedRegion.Add(r);
                                    }
                                }
                                var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();
                                if (regionLanguageList.Count > 0)
                                {
                                    exportRecord.Regions = regionLanguageList[0].ToString();
                                }
                                //Region end

                                //Country start
                                Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                exportRecord.Countries = countryLanguage.Name;
                                //country end
                                exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode;


                                //variable values
                                exportRecord.VariableValues = new List <string>();
                                List <string> recordVariableKey = new List <string>();
                                foreach (var variableValue in ExportRecordData.Variables)
                                {
                                    if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                    {
                                        recordVariableKey.Add(variableValue.Key);
                                        exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                        //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key));
                                    }
                                }

                                if (exportRecord != null)
                                {
                                    ExportRecordData.Records.Add(exportRecord);
                                    ExportRecordData.RecID = exportRecord.RecordID;
                                }
                            }
                            #endregion
                            #region [sector > 0 && country = 1]
                            else if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count > 0))
                            {
                                foreach (var sec in exportRecordData.Sectors)
                                {
                                    exportRecord = new ExportRecord();

                                    //document
                                    try
                                    {
                                        if (exportRecordData.Documents.Count > 0)
                                        {
                                            exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                        }
                                        else
                                        {
                                            exportRecord.Document = null;
                                        }
                                    }
                                    catch
                                    {
                                        exportRecord.Document = "";
                                    }

                                    //ID
                                    exportRecord.RecordID = exportRecordData.ID;

                                    //Name
                                    exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower();

                                    //Regions start
                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();
                                    if (regionLanguageList.Count > 0)
                                    {
                                        exportRecord.Regions = regionLanguageList[0].ToString();
                                    }
                                    //Region end

                                    //Country start
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    exportRecord.Countries = countryLanguage.Name;
                                    //country end

                                    exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode;
                                    //variable values
                                    exportRecord.VariableValues = new List <string>();
                                    List <string> recordVariableKey = new List <string>();
                                    foreach (var variableValue in ExportRecordData.Variables)
                                    {
                                        if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                        {
                                            recordVariableKey.Add(variableValue.Key);
                                            exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                            //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key));
                                        }
                                    }

                                    //sector
                                    Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault();
                                    exportRecord.Sectors = secLang.Name;

                                    exportRecord.SectorType = sec.Type.ToString();


                                    var intSec = exportRecord.Sectors;
                                    //International Nomenclature Code
                                    string intNId = "";
                                    if (sec.International_NomenclatureID != Guid.Empty)
                                    {
                                        try
                                        {
                                            var       interNid = sec.International_NomenclatureID.Value;
                                            TSMSector INT_Nom  = new TSMSector();
                                            INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                            if (INT_Nom != null)
                                            {
                                                intNId = INT_Nom.Code;
                                            }
                                        }
                                        catch { }
                                    }
                                    if (intNId == "")
                                    {
                                        TSMSector INT_Nom = new TSMSector();
                                        INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                        if (INT_Nom != null)
                                        {
                                            intNId = INT_Nom.Code;
                                        }
                                    }
                                    //ITC Nomenclature Code

                                    string itcNid = "";
                                    if (sec.ITC_NomenclatureID != Guid.Empty)
                                    {
                                        try
                                        {
                                            var       itcid   = sec.ITC_NomenclatureID.Value;
                                            TSMSector ITC_Nom = new TSMSector();
                                            ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                            if (ITC_Nom != null)
                                            {
                                                itcNid = ITC_Nom.Code;
                                            }
                                        }
                                        catch { }
                                    }
                                    if (itcNid == "")
                                    {
                                        TSMSector ITC_Nom = new TSMSector();
                                        ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                        if (ITC_Nom != null)
                                        {
                                            itcNid = ITC_Nom.Code;
                                        }
                                    }
                                    exportRecord.ITCCode = itcNid;
                                    exportRecord.INTCode = intNId;

                                    if (exportRecord != null)
                                    {
                                        ExportRecordData.Records.Add(exportRecord);
                                        ExportRecordData.RecID = exportRecord.RecordID;
                                    }
                                }
                            }
                            #endregion
                            #region [sector > 0 && country > 1]
                            else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count > 0))
                            {
                                foreach (var cnt in exportRecordData.Countries)
                                {
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();

                                    foreach (var sec in exportRecordData.Sectors)
                                    {
                                        exportRecord = new ExportRecord();

                                        //document
                                        try
                                        {
                                            if (exportRecordData.Documents.Count > 0)
                                            {
                                                exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                            }
                                            else
                                            {
                                                exportRecord.Document = null;
                                            }
                                        }
                                        catch
                                        {
                                            exportRecord.Document = "";
                                        }
                                        //ID
                                        exportRecord.RecordID = exportRecordData.ID;

                                        //Name
                                        exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower();

                                        //Regions
                                        if (regionLanguageList.Count > 0)
                                        {
                                            exportRecord.Regions = regionLanguageList[0].ToString();
                                        }

                                        //Country
                                        exportRecord.Countries = countryLanguage.Name;

                                        exportRecord.CountryCode = cnt.ISOCode;
                                        //variable values
                                        exportRecord.VariableValues = new List <string>();
                                        List <string> recordVariableKey = new List <string>();
                                        foreach (var variableValue in ExportRecordData.Variables)
                                        {
                                            if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                            {
                                                recordVariableKey.Add(variableValue.Key);
                                                exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                                //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key));
                                            }
                                        }
                                        //sector
                                        Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault();
                                        exportRecord.Sectors = secLang.Name;

                                        exportRecord.SectorType = sec.Type.ToString();

                                        var intSec = exportRecord.Sectors;
                                        //International Nomenclature Code
                                        string intNId = "";
                                        if (sec.International_NomenclatureID != Guid.Empty)
                                        {
                                            try
                                            {
                                                var       interNid = sec.International_NomenclatureID.Value;
                                                TSMSector INT_Nom  = new TSMSector();
                                                INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                                if (INT_Nom != null)
                                                {
                                                    intNId = INT_Nom.Code;
                                                }
                                            }
                                            catch { }
                                        }
                                        if (intNId == "")
                                        {
                                            TSMSector INT_Nom = new TSMSector();
                                            INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                            if (INT_Nom != null)
                                            {
                                                intNId = INT_Nom.Code;
                                            }
                                        }
                                        //ITC Nomenclature Code

                                        string itcNid = "";
                                        if (sec.ITC_NomenclatureID != Guid.Empty)
                                        {
                                            try
                                            {
                                                var       itcid   = sec.ITC_NomenclatureID.Value;
                                                TSMSector ITC_Nom = new TSMSector();
                                                ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                                if (ITC_Nom != null)
                                                {
                                                    itcNid = ITC_Nom.Code;
                                                }
                                            }
                                            catch { }
                                        }
                                        if (itcNid == "")
                                        {
                                            TSMSector ITC_Nom = new TSMSector();
                                            ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                            if (ITC_Nom != null)
                                            {
                                                itcNid = ITC_Nom.Code;
                                            }
                                        }

                                        exportRecord.ITCCode = itcNid;
                                        exportRecord.INTCode = intNId;

                                        if (exportRecord != null)
                                        {
                                            ExportRecordData.Records.Add(exportRecord);
                                            ExportRecordData.RecID = exportRecord.RecordID;
                                        }
                                    }
                                }
                            }

                            #endregion
                            #region [sector = 0 && country > 1]
                            else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count == 0))
                            {
                                foreach (var cnt in exportRecordData.Countries)
                                {
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();


                                    exportRecord = new ExportRecord();

                                    //document
                                    try
                                    {
                                        if (exportRecordData.Documents.Count > 0)
                                        {
                                            exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                        }
                                        else
                                        {
                                            exportRecord.Document = null;
                                        }
                                    }
                                    catch
                                    {
                                        exportRecord.Document = "";
                                    }
                                    //ID
                                    exportRecord.RecordID = exportRecordData.ID;

                                    //Name
                                    exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();//.ToLower();

                                    //Regions
                                    if (regionLanguageList.Count > 0)
                                    {
                                        exportRecord.Regions = regionLanguageList[0].ToString();
                                    }

                                    //Country
                                    exportRecord.Countries = countryLanguage.Name;

                                    exportRecord.CountryCode = cnt.ISOCode;
                                    //variable values
                                    exportRecord.VariableValues = new List <string>();
                                    List <string> recordVariableKey = new List <string>();
                                    foreach (var variableValue in ExportRecordData.Variables)
                                    {
                                        if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                        {
                                            recordVariableKey.Add(variableValue.Key);
                                            exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                            //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key));
                                        }
                                    }

                                    if (exportRecord != null)
                                    {
                                        ExportRecordData.Records.Add(exportRecord);
                                        ExportRecordData.RecID = exportRecord.RecordID;
                                    }
                                }
                            }
                            #endregion


                            recordProcessed++;
                        }
                        catch (Exception ee)
                        {
                            recordNotProcessed++;
                            ErrorLog.WriteLog("RebuildDownload", "AsyncCall", ee, "");
                        }
                    }
                }
                ExportdataList.Add(ExportRecordData);
                //Save(ExportdataList);
                //return;
                if (SaveXMLToData(ExportdataList))
                {
                    isSaved   = 1;
                    TotalRows = ExportdataList[0].Records.Count.ToString();
                    //lblNumberRows.Text = TotalRows;
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableButton1",
                                                        "$('#btnRebuildDownloadCache').prop('disabled', false); $('#loaderImg').hide();", true);
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess1",
                                                        "$('#dvSuccess').show();", true);
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure1",
                                                        "$('#dvFailure').hide();", true);
                }
                else
                {
                    isSaved = 2;
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableButton1",
                                                        "$('#btnRebuildDownloadCache').prop('disabled', false); $('#loaderImg').hide();", true);
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess",
                                                        "$('#dvSuccess').hide();", true);
                    ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure",
                                                        "$('#dvFailure').show();", true);
                }
                #endregion
            }
        }
Example #4
0
        public void RebuildRecordAsync()
        {
            Console.WriteLine("Index Rebuild Started");

            Guid          languageId = TSM.Model.TSMContext.CurrentLanguageID;
            List <Record> record     = new List <Record>();

            List <Guid>             listRecordsID  = RecordService.GetAllRecordID();
            List <ExportRecordData> ExportdataList = new List <ExportRecordData>();


            if (listRecordsID != null)
            {
                SearchAttributes searchParam = GetSearchParam();
                record = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam);
                ExportRecordData ExportRecordData = new ExportRecordData();
                ExportRecordData.Records = new List <ExportRecord>();


                #region [If Not Null Record]
                if (record != null)
                {
                    #region [Data Load]

                    //Get Variable Items
                    List <Variable_Language> variableItems = new List <Variable_Language>();
                    variableItems = SearchServices.GetVariableLanguageForVariable(languageId).ToList();

                    //Get Get All Country With Region
                    List <Country> listofAllCountries = new List <Country>();
                    listofAllCountries = SearchServices.GetAllCountryWithRegion();

                    //Get list of All Region
                    List <Region_Language> listofAllRegion = new List <Region_Language>();
                    listofAllRegion = SearchServices.GetAllRegionWithLanguage();

                    //Get list of All  Country with language
                    List <Country_Language> lstCountryLang = new List <Country_Language>();
                    lstCountryLang = SearchServices.GetAllCountry(languageId);


                    //Get Sector Language
                    List <Sector_Language> lstSectorLanguage = new List <Sector_Language>();
                    lstSectorLanguage = SearchServices.GetAllSectorNames(languageId);


                    //Get Sector
                    List <TSMSector> lstTSMSector = new List <TSMSector>();
                    lstTSMSector = SearchServices.GetAllSector();

                    // Get Record Variable
                    List <Record_Variable> recordVariables = new List <Record_Variable>();
                    recordVariables = SearchServices.GetAllRecordVariable();

                    #endregion

                    TotalRecord = record.Count;
                    Console.WriteLine("Total Records: " + TotalRecord.ToString());
                    foreach (var exportRecordData in record)
                    {
                        try
                        {
                            ExportRecordData.Variables = new List <KeyValue>();
                            foreach (var keyValue in variableItems)
                            {
                                KeyValue keyValuevariableLanguageItem = new KeyValue
                                {
                                    Key   = keyValue.ID.ToString(),
                                    Value = keyValue.Name
                                };
                                ExportRecordData.Variables.Add(keyValuevariableLanguageItem);
                            }
                            ExportRecord exportRecord = null;

                            #region [sector = 0 && country = 1]
                            if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count == 0))
                            {
                                exportRecord = new ExportRecord();
                                //document
                                try
                                {
                                    if (exportRecordData.Documents.Count > 0)
                                    {
                                        exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                    }
                                    else
                                    {
                                        exportRecord.Document = null;
                                    }
                                }
                                catch
                                {
                                    exportRecord.Document = "";
                                }

                                //ID
                                exportRecord.RecordID = exportRecordData.ID;

                                //Name
                                exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();

                                //Regions start
                                var     selectedRegion = new List <Region>();
                                Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                if (tmpCountry != null)
                                {
                                    foreach (var r in tmpCountry.Regions)
                                    {
                                        selectedRegion.Add(r);
                                    }
                                }
                                var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();
                                if (regionLanguageList.Count > 0)
                                {
                                    exportRecord.Regions = regionLanguageList[0].ToString();
                                }
                                //Region end

                                //Country start
                                Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                exportRecord.Countries = countryLanguage.Name;
                                //country end
                                exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode;


                                //variable values
                                exportRecord.VariableValues = new List <string>();
                                List <string> recordVariableKey = new List <string>();
                                foreach (var variableValue in ExportRecordData.Variables)
                                {
                                    if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                    {
                                        recordVariableKey.Add(variableValue.Key);
                                        exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                    }
                                }

                                if (exportRecord != null)
                                {
                                    ExportRecordData.Records.Add(exportRecord);
                                    ExportRecordData.RecID = exportRecord.RecordID;
                                }
                            }
                            #endregion
                            #region [sector > 0 && country = 1]
                            else if ((exportRecordData.Countries.Count == 1) && (exportRecordData.Sectors.Count > 0))
                            {
                                foreach (var sec in exportRecordData.Sectors)
                                {
                                    exportRecord = new ExportRecord();

                                    //document
                                    try
                                    {
                                        if (exportRecordData.Documents.Count > 0)
                                        {
                                            exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                        }
                                        else
                                        {
                                            exportRecord.Document = null;
                                        }
                                    }
                                    catch
                                    {
                                        exportRecord.Document = "";
                                    }

                                    //ID
                                    exportRecord.RecordID = exportRecordData.ID;

                                    //Name
                                    exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();

                                    //Regions start
                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();
                                    if (regionLanguageList.Count > 0)
                                    {
                                        exportRecord.Regions = regionLanguageList[0].ToString();
                                    }
                                    //Region end

                                    //Country start
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    exportRecord.Countries = countryLanguage.Name;
                                    //country end

                                    exportRecord.CountryCode = exportRecordData.Countries[0].ISOCode;
                                    //variable values
                                    exportRecord.VariableValues = new List <string>();
                                    List <string> recordVariableKey = new List <string>();
                                    foreach (var variableValue in ExportRecordData.Variables)
                                    {
                                        if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                        {
                                            recordVariableKey.Add(variableValue.Key);
                                            exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                        }
                                    }

                                    //sector
                                    Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault();
                                    exportRecord.Sectors = secLang.Name;

                                    exportRecord.SectorType = sec.Type.ToString();


                                    var intSec = exportRecord.Sectors;
                                    //International Nomenclature Code
                                    string intNId = "";
                                    if (sec.International_NomenclatureID != Guid.Empty)
                                    {
                                        try
                                        {
                                            var       interNid = sec.International_NomenclatureID.Value;
                                            TSMSector INT_Nom  = new TSMSector();
                                            INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                            if (INT_Nom != null)
                                            {
                                                intNId = INT_Nom.Code;
                                            }
                                        }
                                        catch { }
                                    }
                                    if (intNId == "")
                                    {
                                        TSMSector INT_Nom = new TSMSector();
                                        INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                        if (INT_Nom != null)
                                        {
                                            intNId = INT_Nom.Code;
                                        }
                                    }
                                    //ITC Nomenclature Code

                                    string itcNid = "";
                                    if (sec.ITC_NomenclatureID != Guid.Empty)
                                    {
                                        try
                                        {
                                            var       itcid   = sec.ITC_NomenclatureID.Value;
                                            TSMSector ITC_Nom = new TSMSector();
                                            ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                            if (ITC_Nom != null)
                                            {
                                                itcNid = ITC_Nom.Code;
                                            }
                                        }
                                        catch { }
                                    }
                                    if (itcNid == "")
                                    {
                                        TSMSector ITC_Nom = new TSMSector();
                                        ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                        if (ITC_Nom != null)
                                        {
                                            itcNid = ITC_Nom.Code;
                                        }
                                    }
                                    exportRecord.ITCCode = itcNid;
                                    exportRecord.INTCode = intNId;

                                    if (exportRecord != null)
                                    {
                                        ExportRecordData.Records.Add(exportRecord);
                                        ExportRecordData.RecID = exportRecord.RecordID;
                                    }
                                }
                            }
                            #endregion
                            #region [sector > 0 && country > 1]
                            else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count > 0))
                            {
                                foreach (var cnt in exportRecordData.Countries)
                                {
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();

                                    foreach (var sec in exportRecordData.Sectors)
                                    {
                                        exportRecord = new ExportRecord();

                                        //document
                                        try
                                        {
                                            if (exportRecordData.Documents.Count > 0)
                                            {
                                                exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                            }
                                            else
                                            {
                                                exportRecord.Document = null;
                                            }
                                        }
                                        catch
                                        {
                                            exportRecord.Document = "";
                                        }

                                        //ID
                                        exportRecord.RecordID = exportRecordData.ID;

                                        //Name
                                        exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();

                                        //Regions
                                        if (regionLanguageList.Count > 0)
                                        {
                                            exportRecord.Regions = regionLanguageList[0].ToString();
                                        }

                                        //Country
                                        exportRecord.Countries = countryLanguage.Name;

                                        exportRecord.CountryCode = cnt.ISOCode;
                                        //variable values
                                        exportRecord.VariableValues = new List <string>();
                                        List <string> recordVariableKey = new List <string>();
                                        foreach (var variableValue in ExportRecordData.Variables)
                                        {
                                            if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                            {
                                                recordVariableKey.Add(variableValue.Key);
                                                exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                            }
                                        }
                                        //sector
                                        Sector_Language secLang = lstSectorLanguage.Where(sl => sl.ID == sec.ID).FirstOrDefault();
                                        exportRecord.Sectors = secLang.Name;

                                        exportRecord.SectorType = sec.Type.ToString();

                                        var intSec = exportRecord.Sectors;
                                        //International Nomenclature Code
                                        string intNId = "";
                                        if (sec.International_NomenclatureID != Guid.Empty)
                                        {
                                            try
                                            {
                                                var       interNid = sec.International_NomenclatureID.Value;
                                                TSMSector INT_Nom  = new TSMSector();
                                                INT_Nom = lstTSMSector.Where(u => u.ID == interNid && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                                if (INT_Nom != null)
                                                {
                                                    intNId = INT_Nom.Code;
                                                }
                                            }
                                            catch { }
                                        }
                                        if (intNId == "")
                                        {
                                            TSMSector INT_Nom = new TSMSector();
                                            INT_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.International && u.Type == sec.Type).FirstOrDefault();
                                            if (INT_Nom != null)
                                            {
                                                intNId = INT_Nom.Code;
                                            }
                                        }
                                        //ITC Nomenclature Code

                                        string itcNid = "";
                                        if (sec.ITC_NomenclatureID != Guid.Empty)
                                        {
                                            try
                                            {
                                                var       itcid   = sec.ITC_NomenclatureID.Value;
                                                TSMSector ITC_Nom = new TSMSector();
                                                ITC_Nom = lstTSMSector.Where(u => u.ID == itcid && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                                if (ITC_Nom != null)
                                                {
                                                    itcNid = ITC_Nom.Code;
                                                }
                                            }
                                            catch { }
                                        }
                                        if (itcNid == "")
                                        {
                                            TSMSector ITC_Nom = new TSMSector();
                                            ITC_Nom = lstTSMSector.Where(u => u.Name == intSec && u.NomenclatureType == NomenclatureType.ITC && u.Type == sec.Type).FirstOrDefault();
                                            if (ITC_Nom != null)
                                            {
                                                itcNid = ITC_Nom.Code;
                                            }
                                        }

                                        exportRecord.ITCCode = itcNid;
                                        exportRecord.INTCode = intNId;

                                        if (exportRecord != null)
                                        {
                                            ExportRecordData.Records.Add(exportRecord);
                                            ExportRecordData.RecID = exportRecord.RecordID;
                                        }
                                    }
                                }
                            }

                            #endregion
                            #region [sector = 0 && country > 1]
                            else if ((exportRecordData.Countries.Count > 1) && (exportRecordData.Sectors.Count == 0))
                            {
                                foreach (var cnt in exportRecordData.Countries)
                                {
                                    Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                                    var     selectedRegion = new List <Region>();
                                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == exportRecordData.Countries[0].ID).FirstOrDefault();
                                    if (tmpCountry != null)
                                    {
                                        foreach (var r in tmpCountry.Regions)
                                        {
                                            selectedRegion.Add(r);
                                        }
                                    }
                                    var regionLanguageList = (from rl in listofAllRegion join r in selectedRegion on rl.ID equals r.ID where r.Type == TSM.Entity.RegionType.Geographical && rl.LanguageID == languageId select rl.Name).ToList();


                                    exportRecord = new ExportRecord();

                                    //document
                                    try
                                    {
                                        if (exportRecordData.Documents.Count > 0)
                                        {
                                            exportRecord.Document = exportRecordData.Documents[0].Path.Split('.')[0].ToString();
                                        }
                                        else
                                        {
                                            exportRecord.Document = null;
                                        }
                                    }
                                    catch
                                    {
                                        exportRecord.Document = "";
                                    }

                                    //ID
                                    exportRecord.RecordID = exportRecordData.ID;

                                    //Name
                                    exportRecord.Name = exportRecordData.Record_Languages.FirstOrDefault().Name.ToString();

                                    //Regions
                                    if (regionLanguageList.Count > 0)
                                    {
                                        exportRecord.Regions = regionLanguageList[0].ToString();
                                    }

                                    //Country
                                    exportRecord.Countries = countryLanguage.Name;

                                    exportRecord.CountryCode = cnt.ISOCode;
                                    //variable values
                                    exportRecord.VariableValues = new List <string>();
                                    List <string> recordVariableKey = new List <string>();
                                    foreach (var variableValue in ExportRecordData.Variables)
                                    {
                                        if (variableValue != null && variableValue.Value != null && !string.IsNullOrEmpty(variableValue.Value) && variableValue.Value != "")
                                        {
                                            recordVariableKey.Add(variableValue.Key);
                                            exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableIdFromList(languageId, exportRecordData.ID, recordVariableKey, variableValue.Key, recordVariables));
                                        }
                                    }

                                    if (exportRecord != null)
                                    {
                                        ExportRecordData.Records.Add(exportRecord);
                                        ExportRecordData.RecID = exportRecord.RecordID;
                                    }
                                }
                            }
                            #endregion

                            recordProcessed++;

                            int percentRecord = (recordProcessed / TotalRecord) * 100;
                            //Console.Clear();
                            Console.WriteLine(recordProcessed.ToString() + " of " + TotalRecord.ToString() + " records done. Plese wait...");
                        }
                        catch (Exception ee)
                        {
                            recordNotProcessed++;
                            Console.WriteLine(recordNotProcessed.ToString() + " of " + TotalRecord.ToString());
                            ErrorLog.WriteLog("Import", "Import", ee, "");
                        }
                    }
                }
                ExportdataList.Add(ExportRecordData);

                if (DeleteFile())
                {
                    Console.WriteLine("Delete Success");
                    if (SaveXMLToData(ExportdataList))
                    {
                        Console.WriteLine("Save Success");
                    }
                    else
                    {
                        Console.WriteLine("Save Error!");
                    }
                }
                else
                {
                    Console.Write("Delete Error!");
                }
                #endregion
            }
            Console.WriteLine(recordProcessed.ToString() + " of " + TotalRecord.ToString() + " & " + recordNotProcessed.ToString() + " fail(s).");
        }