private void ConnectToDatabaseNCreateConverter(string fileNameWPath)
        {
            DIConnection DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, fileNameWPath, string.Empty, string.Empty);

            DIQueries DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

            this.CreateDBConverter(DBConnection, DBQueries);
        }
Beispiel #2
0
        /// <summary>
        /// Rename Data_value and TextualValue column into OrgData_value and OrgTextualValue
        /// and merge both column value into new column Data_Value
        /// </summary>
        /// <param name="dbConnection"></param>
        /// <param name="dbQueries"></param>
        public static void MergeTextualandNumericDataValueColumn(string databaseFileNameWPath)
        {
            try
            {
                using (DIConnection DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, databaseFileNameWPath, string.Empty, string.Empty))
                {
                    DIQueries DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));

                    MergeTextualandNumericDataValueColumn(DBConnection, DBQueries);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
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);
        }