/// <summary>
        /// Imports records from source database to target database/template
        /// </summary>
        /// <param name="selectedNids"></param>
        /// <param name="allSelected">Set true to import all records</param>
        public override void ImportValues(List<string> selectedNids, bool allSelected)
        {
            DataRow Row;
            SourceInfo SourceRecord = null;
            SourceBuilder SourceBuilderObj = null;
            DI7MetadataCategoryBuilder SourceMetadataCategoryBuilder = null;
            int ProgressBarValue = 0;

            try
            {
                // import source metadata categories from source dadtabase
                SourceMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this._TargetDBConnection, this._TargetDBQueries);
                SourceMetadataCategoryBuilder.ImportAllMetadataCategories(this.SourceDBConnection, this.SourceDBQueries, MetadataElementType.Source);

                //import selected sources
                foreach (string Nid in selectedNids)
                {
                    try
                    {
                        Row = this.SourceTable.Select(this.TagValueColumnName + "=" + Nid)[0];

                        //import indicator
                        SourceRecord = new SourceInfo();
                        SourceRecord.Name = Row[IndicatorClassifications.ICName].ToString();
                        SourceRecord.Info = Row[IndicatorClassifications.ICInfo].ToString();
                        SourceRecord.ISBN = Row[IndicatorClassifications.ISBN].ToString();
                        SourceRecord.Nature = Row[IndicatorClassifications.Nature].ToString();

                        SourceBuilderObj = new SourceBuilder(this._TargetDBConnection, this._TargetDBQueries);
                        SourceBuilderObj.ImportSource(SourceRecord, Convert.ToInt32(Nid), this.SourceDBQueries, this.SourceDBConnection);

                    }
                    catch (Exception ex)
                    {

                        throw new ApplicationException(ex.ToString());
                    }

                    this.RaiseIncrementProgessBarEvent(ProgressBarValue);
                    ProgressBarValue++;

                }

            }
            catch (Exception ex)
            {
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
            }
        }
Esempio n. 2
0
        private void Get_Source()
        {
            //'Dictionary<string, int> RetVal = new Dictionary<string, int>();
            SourceBuilder SrcBuilderObj = null;
            string        Name          = string.Empty;
            string        GID           = string.Empty;
            string        LanguageCode  = this._LanguageCode;
            int           NID           = 0;
            string        ParentID      = string.Empty;
            ICType        icICType      = ICType.Sector;

            this.SourceDetails = new Dictionary <string, CommonInfo>();
            //SrcBuilderObj = new SourceBuilder(this.DBConnection, this.DBQueries);

            foreach (SDMXObjectModel.Structure.CategorySchemeType CodeListObj in this._DSDStructure.Structures.CategorySchemes)
            {
                icICType = (ICType)DIQueries.ICTypeText.Values.IndexOf("'" + CodeListObj.id.Substring(3) + "'");

                if (icICType == ICType.Source)
                {
                    foreach (SDMXObjectModel.Structure.CategoryType CatTypeCode in CodeListObj.Items)
                    {
                        GID = CatTypeCode.id;
                        string ParentName = string.Empty;

                        foreach (TextType IndTextType in CatTypeCode.Name)
                        {
                            if (IndTextType.lang.Trim('_') == this._LanguageCode)
                            {
                                ParentName = IndTextType.Value;
                            }
                        }

                        foreach (SDMXObjectModel.Structure.CategoryType SubCatTypeCode in CatTypeCode.Items)
                        {
                            GID  = CatTypeCode.id;
                            Name = string.Empty;

                            foreach (TextType IndTextType in SubCatTypeCode.Name)
                            {
                                if (IndTextType.lang.Trim('_') == this._LanguageCode)
                                {
                                    Name = IndTextType.Value;
                                    break;
                                }
                            }
                        }
                        ParentID = "-1";

                        //NID = SrcBuilderObj.CheckNCreateSource(Name);

                        //if (!RetVal.ContainsKey(GID) && NID > 0)
                        //{
                        //    RetVal.Add(GID, NID);
                        //}

                        if (!this.SourceDetails.ContainsKey(Name))
                        {
                            CommonInfo TableInfoObj = new CommonInfo();
                            TableInfoObj.GID  = GID;
                            TableInfoObj.Name = Name;
                            this.SourceDetails.Add(Name, TableInfoObj);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private int GetSourceNid(DataTable table, string key)
        {
            string Source;
            int RetVal = 0;

            //'-- Source
            //'-- Get DataValue of The Source
            try
            {
                if (key.Length == 0)
                {
                    Source = table.Select( QuestionTableColumns.QuestionKey +" = 'SRC_PUBLISHER'")[0][QuestionTableColumns.DataValue].ToString();
                }
                else
                {
                    Source = table.Select(QuestionTableColumns.QuestionKey + " = '" + key + "'")[0][QuestionTableColumns.Source].ToString();
                }

                if (!(string.IsNullOrEmpty(Source)))
                {
                    Source = Utility.RemoveQuotes(Source);

                    SourceBuilder Sources = new SourceBuilder(this._DBConnection, this._DBQuery);
                    RetVal = Sources.CheckNCreateSource(Source);
                }
            }
            catch (Exception)
            {

            }

            return RetVal;
        }
Esempio n. 4
0
        /// <summary>
        /// Imports source metadata from template/database
        /// </summary>
        /// <param name="dataPrefix"></param>
        /// <param name="sourceDBConnection"></param>
        /// <param name="sourceDBQueries"></param>
        /// <param name="selectedNIDs"></param>
        /// <param name="selectionCount"></param>
        /// <param name="metadataType"></param>
        public void ImportSourceMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType)
        {
            DataTable TempDataTable;
            ICType    ClassificationType;
            int       CurrentRecordIndex = 0;
            int       SrcElementNid;
            int       TrgElementNid;
            DI7MetadataCategoryBuilder SourceMetadataCategoryBuilder;

            SourceBuilder ICBuilder;

            try
            {
                this.RaiseStartProcessEvent();


                ICBuilder = new SourceBuilder(this.DBConnection, this.DBQueries);

                // import source categories
                SourceMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries);
                SourceMetadataCategoryBuilder.ImportAllMetadataCategories(sourceDBConnection, sourceDBQueries, MetadataElementType.Source);


                ClassificationType = ICType.Source;
                if (selectionCount == -1)
                {
                    // -- GET ALL
                    TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.None, string.Empty, ClassificationType, FieldSelection.Heavy));
                }
                else
                {
                    // -- GET SELECTED
                    TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, selectedNIDs, ClassificationType, FieldSelection.Heavy));
                }



                ////// -- Initialize Progress Bar
                this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count);
                CurrentRecordIndex = 0;

                foreach (DataRow Row in TempDataTable.Rows)
                {
                    CurrentRecordIndex++;
                    SrcElementNid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]);
                    TrgElementNid = ICBuilder.CheckSourceExists(Convert.ToString(Row[IndicatorClassifications.ICName]));

                    // import source metadadta
                    if (TrgElementNid > 0)
                    {
                        this.ImportMetadata(sourceDBConnection, sourceDBQueries, SrcElementNid, TrgElementNid, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource);
                    }

                    ////// -- Increemnt the Progress Bar Value
                    this.RaiseProcessInfoEvent(CurrentRecordIndex);
                }
                // -- Dispose the Data Table object
                TempDataTable.Dispose();
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// To open or create DevInfo database
        /// </summary>
        /// <param name="fileNameWPath"></param>
        /// <param name="datasetPrefix"></param>        
        /// <param name="langaugeCode"></param>
        public void OpenDatabase(string fileNameWPath, string datasetPrefix, string langaugeCode)
        {
            DBConverterDecorator DBConverter;

            //check file exists or not. If not exists then create it.
            if (!File.Exists(fileNameWPath))
            {
                DIDatabase.CreateDevInfoDBFile(fileNameWPath);

                // update the db schema
                DBConverter = new DBConverterDecorator(fileNameWPath);
                DBConverter.DoConversion(false);
                DBConverter.Dispose();
            }

            this.SetDatabaseObjects(fileNameWPath, datasetPrefix, langaugeCode);

            this.DIArea = new AreaBuilder(this.DBConnection, this.DBQueries);
            this.DIIUS = new IUSBuilder(this.DBConnection, this.DBQueries);
            this.DITimeperiod = new TimeperiodBuilder(this.DBConnection, this.DBQueries);
            this.DISource = new SourceBuilder(this.DBConnection, this.DBQueries);
            this.DIFootnote = new FootnoteBuilder(this.DBConnection, this.DBQueries);
        }
Esempio n. 6
0
        /// <summary>
        /// Generate SDMX Files from DES
        /// </summary>
        /// <param name="DESFileNameWithPath"></param>
        /// <param name="DSDFileNameWPath"></param>
        /// <param name="outputFolder"></param>
        /// <returns></returns>
        public static bool Generate_SDMXML_Data(string DESFileNameWithPath, string DSDFileNameWPath, string outputFolder)
        {
            bool         RetVal       = false;
            DIConnection DBConnection = null;
            DIQueries    DBQueries    = null;
            int          count        = 0;

            //  Utility.TemporaryFileNamePath
            DataTable Table = DevInfo.Lib.DI_LibBAL.Import.DAImport.DES.DataEntrySpreadsheets.GetDataTableForAllDESSheets(DESFileNameWithPath);

            string TempDatabaseName        = string.Empty;
            string TempDatabaseNameCompact = string.Empty;

            TempDatabaseName = Path.Combine(Path.GetDirectoryName(DESFileNameWithPath), DICommon.GetValidFileName(DateTime.Now.Ticks.ToString() + DICommon.FileExtension.Template));

            Dictionary <string, int> IndicatorList  = new Dictionary <string, int>();
            Dictionary <string, int> UnitList       = new Dictionary <string, int>();
            Dictionary <string, int> AreaList       = new Dictionary <string, int>();
            Dictionary <string, int> SgValList      = new Dictionary <string, int>();
            Dictionary <string, int> TimepeirodList = new Dictionary <string, int>();
            Dictionary <string, int> SourceList     = new Dictionary <string, int>();

            try
            {
                DevInfo.Lib.DI_LibDAL.Resources.Resource.GetBlankDevInfoDBFile(TempDatabaseName);

                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, TempDatabaseName, string.Empty, string.Empty);
                DBQueries    = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

                DIDataValueHelper.MergeTextualandNumericDataValueColumn(DBConnection, DBQueries);

                IndicatorBuilder               IndBuilder     = new IndicatorBuilder(DBConnection, DBQueries);
                UnitBuilder                    UBuilder       = new UnitBuilder(DBConnection, DBQueries);
                DI6SubgroupValBuilder          SGBuilder      = new DI6SubgroupValBuilder(DBConnection, DBQueries);
                AreaBuilder                    AreaBuilderObj = new AreaBuilder(DBConnection, DBQueries);
                IndicatorClassificationBuilder ICBuilder      = new IndicatorClassificationBuilder(DBConnection, DBQueries);
                TimeperiodBuilder              TBuilder       = new TimeperiodBuilder(DBConnection, DBQueries);
                SourceBuilder                  SrcBuilder     = new SourceBuilder(DBConnection, DBQueries);
                DIDatabase DatabaseObj   = new DIDatabase(DBConnection, DBQueries);
                IUSBuilder IUSBuilderObj = new IUSBuilder(DBConnection, DBQueries);


                foreach (DataRow Row in Table.Rows)
                {
                    int IndicatorNId  = 0;
                    int UnitNId       = 0;
                    int SGValNId      = 0;
                    int AreaNId       = 0;
                    int TimeperiodNId = 0;
                    int SourceNid     = 0;
                    int IUSNID        = 0;

                    //-- Import Indicator
                    if (IndicatorList.ContainsKey(Convert.ToString(Row[Indicator.IndicatorGId])))
                    {
                        IndicatorNId = IndicatorList[Convert.ToString(Row[Indicator.IndicatorGId])];
                    }
                    else
                    {
                        IndicatorNId = IndBuilder.ImportIndicator(Convert.ToString(Row[Indicator.IndicatorName]), Convert.ToString(Row[Indicator.IndicatorGId]), false);
                        IndicatorList.Add(Convert.ToString(Row[Indicator.IndicatorGId]), IndicatorNId);
                    }

                    //-- Import Unit
                    if (UnitList.ContainsKey(Convert.ToString(Row[Unit.UnitGId])))
                    {
                        UnitNId = UnitList[Convert.ToString(Row[Unit.UnitGId])];
                    }
                    else
                    {
                        UnitNId = UBuilder.ImportUnit(Convert.ToString(Row[Unit.UnitGId]), Convert.ToString(Row[Unit.UnitName]).Trim(), false);
                        UnitList.Add(Convert.ToString(Row[Unit.UnitGId]), UnitNId);
                    }

                    //-- Import SubgroupVal
                    if (!string.IsNullOrEmpty(Convert.ToString(Row[SubgroupVals.SubgroupVal])))
                    {
                        if (SgValList.ContainsKey(Convert.ToString(Row[SubgroupVals.SubgroupValGId])))
                        {
                            SGValNId = SgValList[Convert.ToString(Row[SubgroupVals.SubgroupValGId])];
                        }
                        else
                        {
                            SGValNId = SGBuilder.ImportSubgroupVal(Convert.ToString(Row[SubgroupVals.SubgroupVal]), Convert.ToString(Row[SubgroupVals.SubgroupValGId]), false);
                            SgValList.Add(Convert.ToString(Row[SubgroupVals.SubgroupValGId]), SGValNId);
                        }
                    }

                    //-- Import Area
                    if (AreaList.ContainsKey(Convert.ToString(Row[Area.AreaID])))
                    {
                        AreaNId = AreaList[Convert.ToString(Row[Area.AreaID])];
                    }
                    else
                    {
                        AreaNId = AreaBuilderObj.ImportArea(Convert.ToString(Row[Area.AreaName]), Convert.ToString(Row[Area.AreaID]), String.Empty, false);
                        AreaList.Add(Convert.ToString(Row[Area.AreaID]), AreaNId);
                    }

                    //-- Import Timeperiod
                    if (TimepeirodList.ContainsKey(Convert.ToString(Row[Timeperiods.TimePeriod])))
                    {
                        TimeperiodNId = TimepeirodList[Convert.ToString(Row[Timeperiods.TimePeriod])];
                    }
                    else
                    {
                        TimeperiodNId = TBuilder.CheckNCreateTimeperiod(Convert.ToString(Row[Timeperiods.TimePeriod]));
                        TimepeirodList.Add(Convert.ToString(Row[Timeperiods.TimePeriod]), TimeperiodNId);
                    }

                    //-- Import Source
                    if (SourceList.ContainsKey(Convert.ToString(Row[IndicatorClassifications.ICName])))
                    {
                        SourceNid = SourceList[Convert.ToString(Row[IndicatorClassifications.ICName])];
                    }
                    else
                    {
                        SourceNid = SrcBuilder.CheckNCreateSource(Convert.ToString(Row[IndicatorClassifications.ICName]));
                        SourceList.Add(Convert.ToString(Row[IndicatorClassifications.ICName]), SourceNid);
                    }


                    IUSNID = IUSBuilderObj.ImportIUS(IndicatorNId, UnitNId, SGValNId, 0, 0, DBQueries, DBConnection);

                    if (IUSNID > 0 && AreaNId > 0 && TimeperiodNId > 0 && !string.IsNullOrEmpty(Convert.ToString(Row[Data.DataValue])))
                    {
                        DatabaseObj.CheckNCreateData(AreaNId, IUSNID, SourceNid, TimeperiodNId, Convert.ToString(Row[Data.DataValue]));
                    }
                }

                DatabaseObj.UpdateIndicatorUnitSubgroupNIDsInData();

                //-- Compact Database into TempFile
                TempDatabaseNameCompact = Path.Combine(Path.GetDirectoryName(DESFileNameWithPath), DICommon.GetValidFileName(DateTime.Now.Ticks.ToString() + DICommon.FileExtension.Template));

                DIDatabase.CompactDataBase(ref DBConnection, DBQueries, TempDatabaseNameCompact, true);


                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, TempDatabaseNameCompact, string.Empty, string.Empty);
                DBQueries    = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

                if (!Directory.Exists(Path.Combine(outputFolder, DBQueries.LanguageCode.Trim('_'))))
                {
                    Directory.CreateDirectory(Path.Combine(outputFolder, DBQueries.LanguageCode.Trim('_')));
                }

                System.Xml.XmlDocument XmlDoc = SDMXUtility.Get_Query(SDMXSchemaType.Two_One, null, QueryFormats.StructureSpecificTS, DataReturnDetailTypes.Full, Guid.NewGuid().ToString().Replace("-", "").Replace("_", ""), DBConnection, DBQueries);

                RetVal = SDMXUtility.Generate_Data(SDMXSchemaType.Two_One, XmlDoc, DevInfo.Lib.DI_LibSDMX.DataFormats.StructureSpecificTS, DBConnection, DBQueries, outputFolder);
            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }

            return(RetVal);
        }
Esempio n. 7
0
        /// <summary>
        /// Convets Database into template
        /// </summary>
        public void ConvertDatabaseToTemplate()
        {
            SourceBuilder SrcBuilder;
            FootnoteBuilder FoonotesBuilder;
            IndicatorClassificationBuilder ICBuilder;
            RecommendedSourcesBuilder RecommendedSrcBuilder;
            DataTable ICTable;
            string ICNIds = string.Empty;

            try
            {
                // STEP 1: Remove records from DATA table
                this.DBConnection.ExecuteNonQuery(this.DBQueries.Delete.Data.DeleteRecords(string.Empty));

                // STEP 2: Remove records from TIME table
                this.DBConnection.ExecuteNonQuery(this.DBQueries.Delete.Timeperiod.DeleteRecords(string.Empty));

                // STEP 3: Remove records from SOURCE table
                SrcBuilder = new SourceBuilder(this.DBConnection, this.DBQueries);
                SrcBuilder.DeleteSources(string.Empty);

                // STEP 4: Remove source records from Indicator_classification tables
                ICBuilder = new IndicatorClassificationBuilder(this.DBConnection, this.DBQueries);

                ICTable = this.DBConnection.ExecuteDataTable(this.DBQueries.IndicatorClassification.GetIC(FilterFieldType.Type, "'SR'", FieldSelection.NId));
                if (ICTable != null && ICTable.Rows.Count > 0)
                {
                    ICNIds = DIConnection.GetDelimitedValuesFromDataTable(ICTable, IndicatorClassifications.ICNId);
                }
                ICBuilder.DeleteClassification(ICNIds);

                // STEP 5: Remove records from Footnotes table
                FoonotesBuilder = new FootnoteBuilder(this.DBConnection, this.DBQueries);
                FoonotesBuilder.DeleteFootnote(string.Empty);

                // STEP 6: Creates DevInfoSP2 tables if missing.
                DICommon.CheckNCreateDevInfoSP2Database(this.DBConnection, this.DBQueries, false);

                // STEP 7: remove records from notes table
                this.ClearNotesTables();

                // STEP 8: remove records from RecommendedSources table
                RecommendedSrcBuilder = new RecommendedSourcesBuilder(this.DBConnection, this.DBQueries);
                RecommendedSrcBuilder.DeleteRecommendedSources(string.Empty);

                // STEP 9:Remove Source metadata reports
                new DI7MetaDataBuilder(this.DBConnection, this.DBQueries).DeleteMetadataReports(MetadataElementType.Source);

            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Returns instance of DIDatabase.
 /// </summary>
 /// <param name="connection">Instance of DIConnection which is already opened</param>
 /// <param name="queries">Instance of DIQueries which is already opened</param>
 public DIDatabase(DIConnection connection, DIQueries queries)
 {
     this.DBConnection = connection;
     this.DBQueries = queries;
     this.DIArea = new AreaBuilder(this.DBConnection, this.DBQueries);
     this.DIIUS = new IUSBuilder(this.DBConnection, this.DBQueries);
     this.DITimeperiod = new TimeperiodBuilder(this.DBConnection, this.DBQueries);
     this.DISource = new SourceBuilder(this.DBConnection, this.DBQueries);
     this.DIFootnote = new FootnoteBuilder(this.DBConnection, this.DBQueries);
 }
        /// <summary>
        /// Imports source metadata from template/database
        /// </summary>
        /// <param name="dataPrefix"></param>
        /// <param name="sourceDBConnection"></param>
        /// <param name="sourceDBQueries"></param>
        /// <param name="selectedNIDs"></param>
        /// <param name="selectionCount"></param>
        /// <param name="metadataType"></param>
        public void ImportSourceMetadata(string dataPrefix, DIConnection sourceDBConnection, DIQueries sourceDBQueries, string selectedNIDs, int selectionCount, MetaDataType metadataType)
        {
            DataTable TempDataTable;
            ICType ClassificationType;
            int CurrentRecordIndex = 0;
            int SrcElementNid;
            int TrgElementNid;
            DI7MetadataCategoryBuilder SourceMetadataCategoryBuilder;

            SourceBuilder ICBuilder;

            try
            {
                this.RaiseStartProcessEvent();

                ICBuilder = new SourceBuilder(this.DBConnection, this.DBQueries);

                // import source categories
                SourceMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this.DBConnection, this.DBQueries);
                SourceMetadataCategoryBuilder.ImportAllMetadataCategories(sourceDBConnection, sourceDBQueries, MetadataElementType.Source);

                ClassificationType = ICType.Source;
                if (selectionCount == -1)
                {
                    // -- GET ALL
                    TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.None, string.Empty, ClassificationType, FieldSelection.Heavy));
                }
                else
                {
                    // -- GET SELECTED
                    TempDataTable = sourceDBConnection.ExecuteDataTable(sourceDBQueries.IndicatorClassification.GetIC(FilterFieldType.NId, selectedNIDs, ClassificationType, FieldSelection.Heavy));
                }

                ////// -- Initialize Progress Bar
                this.RaiseBeforeProcessEvent(TempDataTable.Rows.Count);
                CurrentRecordIndex = 0;

                foreach (DataRow Row in TempDataTable.Rows)
                {
                    CurrentRecordIndex++;
                    SrcElementNid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]);
                    TrgElementNid = ICBuilder.CheckSourceExists(Convert.ToString(Row[IndicatorClassifications.ICName]));

                    // import source metadadta
                    if (TrgElementNid > 0)
                    {
                        this.ImportMetadata(sourceDBConnection, sourceDBQueries, SrcElementNid, TrgElementNid, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource);

                    }

                    ////// -- Increemnt the Progress Bar Value
                    this.RaiseProcessInfoEvent(CurrentRecordIndex);

                }
                // -- Dispose the Data Table object
                TempDataTable.Dispose();
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Generate SDMX Files from DES
        /// </summary>
        /// <param name="DESFileNameWithPath"></param>
        /// <param name="DSDFileNameWPath"></param>
        /// <param name="outputFolder"></param>
        /// <returns></returns>
        public static bool Generate_SDMXML_Data(string DESFileNameWithPath, string DSDFileNameWPath, string outputFolder)
        {
            bool RetVal = false;
            DIConnection DBConnection = null;
            DIQueries DBQueries = null;
            int count = 0;

            //  Utility.TemporaryFileNamePath
            DataTable Table = DevInfo.Lib.DI_LibBAL.Import.DAImport.DES.DataEntrySpreadsheets.GetDataTableForAllDESSheets(DESFileNameWithPath);

            string TempDatabaseName = string.Empty;
            string TempDatabaseNameCompact = string.Empty;
            TempDatabaseName = Path.Combine(Path.GetDirectoryName(DESFileNameWithPath), DICommon.GetValidFileName(DateTime.Now.Ticks.ToString() + DICommon.FileExtension.Template));

            Dictionary<string, int> IndicatorList = new Dictionary<string, int>();
            Dictionary<string, int> UnitList = new Dictionary<string, int>();
            Dictionary<string, int> AreaList = new Dictionary<string, int>();
            Dictionary<string, int> SgValList = new Dictionary<string, int>();
            Dictionary<string, int> TimepeirodList = new Dictionary<string, int>();
            Dictionary<string, int> SourceList = new Dictionary<string, int>();

            try
            {

                DevInfo.Lib.DI_LibDAL.Resources.Resource.GetBlankDevInfoDBFile(TempDatabaseName);

                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, TempDatabaseName, string.Empty, string.Empty);
                DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

                DIDataValueHelper.MergeTextualandNumericDataValueColumn(DBConnection, DBQueries);

                IndicatorBuilder IndBuilder = new IndicatorBuilder(DBConnection, DBQueries);
                UnitBuilder UBuilder = new UnitBuilder(DBConnection, DBQueries);
                DI6SubgroupValBuilder SGBuilder = new DI6SubgroupValBuilder(DBConnection, DBQueries);
                AreaBuilder AreaBuilderObj = new AreaBuilder(DBConnection, DBQueries);
                IndicatorClassificationBuilder ICBuilder = new IndicatorClassificationBuilder(DBConnection, DBQueries);
                TimeperiodBuilder TBuilder = new TimeperiodBuilder(DBConnection, DBQueries);
                SourceBuilder SrcBuilder = new SourceBuilder(DBConnection, DBQueries);
                DIDatabase DatabaseObj = new DIDatabase(DBConnection, DBQueries);
                IUSBuilder IUSBuilderObj = new IUSBuilder(DBConnection, DBQueries);

                foreach (DataRow Row in Table.Rows)
                {
                    int IndicatorNId = 0;
                    int UnitNId = 0;
                    int SGValNId = 0;
                    int AreaNId = 0;
                    int TimeperiodNId = 0;
                    int SourceNid = 0;
                    int IUSNID = 0;

                    //-- Import Indicator
                    if (IndicatorList.ContainsKey(Convert.ToString(Row[Indicator.IndicatorGId])))
                    {
                        IndicatorNId = IndicatorList[Convert.ToString(Row[Indicator.IndicatorGId])];
                    }
                    else
                    {
                        IndicatorNId = IndBuilder.ImportIndicator(Convert.ToString(Row[Indicator.IndicatorName]), Convert.ToString(Row[Indicator.IndicatorGId]), false);
                        IndicatorList.Add(Convert.ToString(Row[Indicator.IndicatorGId]), IndicatorNId);
                    }

                    //-- Import Unit
                    if (UnitList.ContainsKey(Convert.ToString(Row[Unit.UnitGId])))
                    {
                        UnitNId = UnitList[Convert.ToString(Row[Unit.UnitGId])];
                    }
                    else
                    {
                        UnitNId = UBuilder.ImportUnit(Convert.ToString(Row[Unit.UnitGId]), Convert.ToString(Row[Unit.UnitName]).Trim(), false);
                        UnitList.Add(Convert.ToString(Row[Unit.UnitGId]), UnitNId);
                    }

                    //-- Import SubgroupVal
                    if (!string.IsNullOrEmpty(Convert.ToString(Row[SubgroupVals.SubgroupVal])))
                    {
                        if (SgValList.ContainsKey(Convert.ToString(Row[SubgroupVals.SubgroupValGId])))
                        {
                            SGValNId = SgValList[Convert.ToString(Row[SubgroupVals.SubgroupValGId])];
                        }
                        else
                        {
                            SGValNId = SGBuilder.ImportSubgroupVal(Convert.ToString(Row[SubgroupVals.SubgroupVal]), Convert.ToString(Row[SubgroupVals.SubgroupValGId]), false);
                            SgValList.Add(Convert.ToString(Row[SubgroupVals.SubgroupValGId]), SGValNId);
                        }
                    }

                    //-- Import Area
                    if (AreaList.ContainsKey(Convert.ToString(Row[Area.AreaID])))
                    {
                        AreaNId = AreaList[Convert.ToString(Row[Area.AreaID])];
                    }
                    else
                    {
                        AreaNId = AreaBuilderObj.ImportArea(Convert.ToString(Row[Area.AreaName]), Convert.ToString(Row[Area.AreaID]), String.Empty, false);
                        AreaList.Add(Convert.ToString(Row[Area.AreaID]), AreaNId);
                    }

                    //-- Import Timeperiod
                    if (TimepeirodList.ContainsKey(Convert.ToString(Row[Timeperiods.TimePeriod])))
                    {
                        TimeperiodNId = TimepeirodList[Convert.ToString(Row[Timeperiods.TimePeriod])];
                    }
                    else
                    {
                        TimeperiodNId = TBuilder.CheckNCreateTimeperiod(Convert.ToString(Row[Timeperiods.TimePeriod]));
                        TimepeirodList.Add(Convert.ToString(Row[Timeperiods.TimePeriod]), TimeperiodNId);
                    }

                    //-- Import Source
                    if (SourceList.ContainsKey(Convert.ToString(Row[IndicatorClassifications.ICName])))
                    {
                        SourceNid = SourceList[Convert.ToString(Row[IndicatorClassifications.ICName])];
                    }
                    else
                    {
                        SourceNid = SrcBuilder.CheckNCreateSource(Convert.ToString(Row[IndicatorClassifications.ICName]));
                        SourceList.Add(Convert.ToString(Row[IndicatorClassifications.ICName]), SourceNid);
                    }

                    IUSNID = IUSBuilderObj.ImportIUS(IndicatorNId, UnitNId, SGValNId, 0, 0, DBQueries, DBConnection);

                    if (IUSNID > 0 && AreaNId > 0 && TimeperiodNId > 0 && !string.IsNullOrEmpty(Convert.ToString(Row[Data.DataValue])))
                    {
                        DatabaseObj.CheckNCreateData(AreaNId, IUSNID, SourceNid, TimeperiodNId, Convert.ToString(Row[Data.DataValue]));
                    }
                }

                DatabaseObj.UpdateIndicatorUnitSubgroupNIDsInData();

                //-- Compact Database into TempFile
                TempDatabaseNameCompact = Path.Combine(Path.GetDirectoryName(DESFileNameWithPath), DICommon.GetValidFileName(DateTime.Now.Ticks.ToString() + DICommon.FileExtension.Template));

                DIDatabase.CompactDataBase(ref DBConnection, DBQueries, TempDatabaseNameCompact, true);

                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, TempDatabaseNameCompact, string.Empty, string.Empty);
                DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

                if (!Directory.Exists(Path.Combine(outputFolder, DBQueries.LanguageCode.Trim('_'))))
                {
                    Directory.CreateDirectory(Path.Combine(outputFolder, DBQueries.LanguageCode.Trim('_')));
                }

                System.Xml.XmlDocument XmlDoc = SDMXUtility.Get_Query(SDMXSchemaType.Two_One, null, QueryFormats.StructureSpecificTS, DataReturnDetailTypes.Full, Guid.NewGuid().ToString().Replace("-", "").Replace("_", ""), DBConnection, DBQueries);

                RetVal = SDMXUtility.Generate_Data(SDMXSchemaType.Two_One, XmlDoc, DevInfo.Lib.DI_LibSDMX.DataFormats.StructureSpecificTS, DBConnection, DBQueries, outputFolder);

            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }

            return RetVal;
        }
Esempio n. 11
0
        private void InsertNewSources()
        {
            String SqlQuery = string.Empty;
            DataTable NewSourcesTable = new DataTable();
            DataTable SourceTempTable;
            DataTable TempTable;
            string SourceNID = string.Empty;
            string IUSNID = string.Empty;
            IndicatorClassificationBuilder ICBuilder;

            //DIDatabase Database = new DIDatabase();
            SourceBuilder DISource = new SourceBuilder(this.DBConnection, this.DBQueries);
            try
            {

                // 1. Update special quotes in sources

                // as replace function does not work with ADO.net so first get the special foonote with quotes and then update source text one by one.
                if (this.DBConnection.ConnectionStringParameters.ServerType == DIServerType.MsAccess)
                {
                    SourceTempTable = this.DBConnection.ExecuteDataTable(this.DAQuery.GetSourcesWSpecialQuotesFrmTempDataTbl());

                    //update source text
                    foreach (DataRow Row in SourceTempTable.Rows)
                    {
                        this.DBConnection.ExecuteNonQuery(this.DAQuery.UpdateSpecialQuotesInSourceText(Convert.ToString(Row[DevInfo.Lib.DI_LibBAL.Import.DAImport.Common.Constants.SourceColumnName]), Convert.ToString(Row[Data.DataNId])));
                    }
                }

                //// 2. Get Distinct Sources from Temp_Data which are not in UT_Indicator_Classification
                //NewSourcesTable = this.DBConnection.ExecuteDataTable(this.DAQuery.GetDistinctSourcesFromTempData());

                // 1. Get Distinct Sources from Temp_Data
                NewSourcesTable = this.DBConnection.ExecuteDataTable(this.DAQuery.GetAllSourceFrmTempDataTable()).DefaultView.ToTable(true, DAImportCommon.Constants.SourceColumnName);

                // 2. Insert Sources into UT_Indicator_Classification.
                foreach (DataRow SourceRow in NewSourcesTable.Rows)
                {

                    DISource.CheckNCreateSource(DICommon.RemoveQuotes(SourceRow[DAImportCommon.Constants.SourceColumnName].ToString()));
                }

                // 3. Update Source_Nid again in Temp_Data.
                this.DBConnection.ExecuteNonQuery(this.DAQuery.UpdateSourceNidInTempData());

                // 4. Update IC_Global in target database
                this.UpdateICGlobal();

                //  Insert IC_Nid & IUSNid in "Indicator_Classification_IUS" Table
                //this.DBConnection.ExecuteNonQuery(this.DAQuery.InsertRecordInIndicator_Classification_IUS());

                // 5. insert IC_NID and IUSNID relationship in Indicator_Classification_IUS" table
                TempTable = this.DBConnection.ExecuteDataTable(this.DAQuery.GetNewSourcesNIUSNID());

                if (TempTable != null)
                {
                    ICBuilder = new IndicatorClassificationBuilder(this.DBConnection, this.DBQueries);

                    foreach (DataRow Row in TempTable.Rows)
                    {
                        SourceNID = Convert.ToString(Row[Data.SourceNId]);
                        IUSNID = Convert.ToString(Row[DevInfo.Lib.DI_LibBAL.Import.DAImport.Common.Constants.NewIUSColumnName]);

                        if (!string.IsNullOrEmpty(SourceNID) && !string.IsNullOrEmpty(IUSNID))
                        {
                            ICBuilder.AddNUpdateICIUSRelationUptoRootlevel(Convert.ToInt32(SourceNID), Convert.ToInt32(IUSNID), false);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }
        }