コード例 #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, "");
            }
        }
コード例 #2
0
        public ExportRecordData CreateNewRecord(Guid recd)
        {
            ExportRecordData ExportRecordData = new ExportRecordData();

            if (recd != Guid.Empty)
            {
                Guid        recID         = recd;
                List <Guid> listRecordsID = new List <Guid>();
                listRecordsID.Add(recID);
                List <Record>    recordlist  = new List <Record>();
                SearchAttributes searchParam = GetSearchParam();
                recordlist = SearchServices.GetFilterRecordInformation(listRecordsID, 20000, searchParam);
                Record rec = recordlist.FirstOrDefault();

                Guid languageId = TSM.Model.TSMContext.CurrentLanguageID;
                ExportRecordData.Records = new List <ExportRecord>();

                #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

                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 ((rec.Countries.Count == 1) && (rec.Sectors.Count == 0))
                {
                    exportRecord = new ExportRecord();
                    //document
                    try
                    {
                        if (rec.Documents.Count > 0)
                        {
                            exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString();
                        }
                        else
                        {
                            exportRecord.Document = null;
                        }
                    }
                    catch
                    {
                        exportRecord.Document = "";
                    }

                    //ID
                    exportRecord.RecordID = rec.ID;

                    //Name
                    exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name;

                    //Regions start
                    var     selectedRegion = new List <Region>();
                    Country tmpCountry     = listofAllCountries.Where(c => c.ID == rec.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 == rec.Countries[0].ID).FirstOrDefault();
                    exportRecord.Countries = countryLanguage.Name;
                    //country end
                    exportRecord.CountryCode = rec.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, rec.ID, recordVariableKey, variableValue.Key, recordVariables));
                            //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key));
                        }
                    }

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

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

                        //ID
                        exportRecord.RecordID = rec.ID;

                        //Name
                        exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name;

                        //Regions start
                        var     selectedRegion = new List <Region>();
                        Country tmpCountry     = listofAllCountries.Where(c => c.ID == rec.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 == rec.Countries[0].ID).FirstOrDefault();
                        exportRecord.Countries = countryLanguage.Name;
                        //country end

                        exportRecord.CountryCode = rec.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, rec.ID, recordVariableKey, variableValue.Key, recordVariables));
                                //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.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 ((rec.Countries.Count > 1) && (rec.Sectors.Count > 0))
                {
                    foreach (var cnt in rec.Countries)
                    {
                        Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                        var     selectedRegion = new List <Region>();
                        Country tmpCountry     = listofAllCountries.Where(c => c.ID == rec.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 rec.Sectors)
                        {
                            exportRecord = new ExportRecord();

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

                            //ID
                            exportRecord.RecordID = rec.ID;

                            //Name
                            exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name;

                            //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, rec.ID, recordVariableKey, variableValue.Key, recordVariables));
                                    //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.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 ((rec.Countries.Count > 1) && (rec.Sectors.Count == 0))
                {
                    foreach (var cnt in rec.Countries)
                    {
                        Country_Language countryLanguage = lstCountryLang.Where(cl => cl.ID == cnt.ID).FirstOrDefault();

                        var     selectedRegion = new List <Region>();
                        Country tmpCountry     = listofAllCountries.Where(c => c.ID == rec.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 (rec.Documents.Count > 0)
                            {
                                exportRecord.Document = rec.Documents[0].Path.Split('.')[0].ToString();
                            }
                            else
                            {
                                exportRecord.Document = null;
                            }
                        }
                        catch
                        {
                            exportRecord.Document = "";
                        }

                        //ID
                        exportRecord.RecordID = rec.ID;

                        //Name
                        exportRecord.Name = rec.Record_Languages.FirstOrDefault().Name;

                        //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, rec.ID, recordVariableKey, variableValue.Key, recordVariables));
                                //exportRecord.VariableValues.Add(SearchServices.GetVariableValueByVariableId(languageId, rec.ID, recordVariableKey, variableValue.Key));
                            }
                        }

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