Пример #1
0
        public bool CreateMetadataFromSDMX(string templateFileName,string tempFolderPath, string languageCode,string sdmxRegistryUrl)
        {
            bool RetVal = true;
            DIConnection DBConnection = null;
            DIQueries DBQueries;
            try
            {
                //create temp template file
                DIDatabase TempTemplateFile = new DIDatabase(templateFileName, "UT_", languageCode);

                // create database object
                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, templateFileName, string.Empty, string.Empty);
                DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), languageCode);

                // delete default categories from blank template
                DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.MetadataCategory.Delete.DeleteMetadataCategory(DBQueries.TablesName.MetadataCategory, string.Empty));

                // import data from SDMX
                BaseSDMXHelper HelperObj = new BaseSDMXHelper(DBConnection, DBQueries);
                string TempXmlFile = tempFolderPath + "\\IMPORT_MSDXML_" + this.GetDateTimeStamp() + DICommon.FileExtension.XML;

                HelperObj.GenerateMetadataXMLFromSDMXWebservice(sdmxRegistryUrl, TempXmlFile);

            }
            catch (Exception ex)
            {
                RetVal = false;

            }
            finally
            {
                // dispose database object
                if (DBConnection != null)
                {
                    DBConnection.Dispose();
                }

            }

            return RetVal;
        }
Пример #2
0
        /// <summary>
        /// Insert Newly added records from DES to database
        /// </summary>
        /// <param name="sDestDBPath">Destination Database Path</param>
        /// <param name="MsAccessPwd">Password</param>
        /// <param name="sLng_Suffix">Lang suffix</param>
        public void InsertNewRecords(String tempDESheetPath, string sDestDBPath, String MsAccessPwd)
        {
            DataView oDV = null;
            DataRowView oDVRow;
            string sDB_Prefix;
            string sQry = "";
            DIConnection DBConnection;
            int i;
            int j;
            int iIndicatorNId = 0;
            int iUnitNId = 0;

            int[] iSubgroupNId = new int[this.DESheetInformation.Subgroup.Length];
            int[] iIUSNId = new int[this.DESheetInformation.Subgroup.Length];
            int iSectorNID = 0;
            //int[] iClassNId = new int[Strings.Split(this.DESheetInformation.ClassGUID, "{}").Length];
            int[] iClassNId = new int[this.DESheetInformation.ClassGUID.Split("{}".ToCharArray()).Length];
            int iParentNId;
            //Used for Class and Source
            bool bNewIUS = false;
            Boolean bNewSector = false;
            bool bNewClass = false;
            //*** True if any of I / U / S is new
            bool SectorGlobal = false;

            // -- Create New DiConnection with db as sDestDBPath
            DBConnection = new DIConnection(DIServerType.MsAccess, "", "", sDestDBPath, "", MsAccessPwd);

            //--- Using DAL for getting Database default Prefix
            sDB_Prefix = DBConnection.DIDataSetDefault();
            String sLng_Suffix = DBConnection.DILanguageCodeDefault(sDB_Prefix);
            DIQueries DBQueries = new DIQueries(sDB_Prefix, DBConnection.DILanguageCodeDefault(sDB_Prefix));

            // Get SectorNId
            iSectorNID = GetSectorNId(DBConnection, DBQueries, out bNewSector, out bNewSector);

            //*** If Selected Class has not been inserted by export routine then insert new Class
            string[] sClassGuid;
            string[] sClassName;
            string[] sClassGlobal;
            iParentNId = iSectorNID;
            //sClassGuid = Strings.Split(this.DESheetInformation.ClassGUID,"{}");
            sClassGuid = this.DESheetInformation.ClassGUID.Split("{}".ToCharArray());
            sClassName = this.DESheetInformation.ClassName.Split("{}".ToCharArray());
            sClassGlobal = this.DESheetInformation.ClassGlobal.Split("{}".ToCharArray());

            //*** BugFix 29 Aug 2006 Do not try to insert class into database if indicator is directly associated with sector
            if (this.DESheetInformation.ClassGUID != "" & this.DESheetInformation.ClassName != "")
            {
                for (i = 0; i <= sClassGuid.Length - 1; i++)
                {
                    iClassNId[i] = GetClassNId(DBConnection, DBQueries, out bNewClass, sClassGuid[i].ToString(), SectorGlobal, iParentNId, sClassName[i].ToString());
                    iParentNId = Convert.ToInt32(iClassNId[i]);
                }
            }

            //*** Indicator_NId
            sQry = DBQueries.Indicators.GetIndicator(FilterFieldType.GId, "'" + this.DESheetInformation.IndicatorGUID + "'", FieldSelection.NId);
            iIndicatorNId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

            if (iIndicatorNId == 0)
            {
                bNewIUS = true;
                //-- Getting insert query using DAL
                sQry = DI_LibDAL.Queries.Indicator.Insert.InsertIndicator(sDB_Prefix, sLng_Suffix, this.DESheetInformation.Indicator.Replace("'", "''"), this.DESheetInformation.IndicatorGUID, "", false);

                //-- Using DAL for query execution and getting identity value
                DBConnection.ExecuteNonQuery(sQry);
                iIndicatorNId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
            }

            //*** Unit_NId
            //-- Using DAL for getting and executing query for getting unit NId
            sQry = DBQueries.Calculates.GetUnitNIdByGId(this.DESheetInformation.UnitGUID);
            iUnitNId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

            if (iUnitNId == 0)
            {
                bNewIUS = true;
                //-- Getting insert query using DAL
                sQry = DI_LibDAL.Queries.Unit.Insert.InsertUnit(sDB_Prefix, sLng_Suffix, this.DESheetInformation.Unit.Replace("'", "''"), this.DESheetInformation.UnitGUID, false);

                //-- Using DAL for query execution and getting identity value
                DBConnection.ExecuteNonQuery(sQry);
                iUnitNId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
            }

            //*** Subgroup_Val_NId
            for (i = 0; i <= iSubgroupNId.Length - 1; i++)
            {

                sQry = DBQueries.Calculates.GetSubgroupValNIdByGId(this.DESheetInformation.SubgroupGUID[i]);
                iSubgroupNId[i] = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                if (iSubgroupNId[i] == 0)
                {
                    bNewIUS = true;
                    //-- Getting insert query using DAL
                    sQry = DBQueries.Calculates.InsertSubgroupVal(this.DESheetInformation.Subgroup[0].Replace("'", "''"), this.DESheetInformation.SubgroupGUID[0], false);

                    //-- Using DAL for query execution and getting identity value
                    DBConnection.ExecuteNonQuery(sQry);
                    iSubgroupNId[i] = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                }
            }

            //*** IUSNId
            if (bNewIUS)
            {
                //*** Insert New IUS
                for (i = 0; i <= iSubgroupNId.Length - 1; i++)
                {
                    //-- Get query from DAL
                    sQry = DBQueries.Calculates.InsertNIdsInIUSTable(iIndicatorNId, iUnitNId, iSubgroupNId[i]);

                    //-- Using DAL for query execution and getting identity value
                    DBConnection.ExecuteNonQuery(sQry);
                    iIUSNId[i] = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));

                    //*** Create Relationship with IndicatorClassification
                    string sICGuid;
                    sClassGuid = this.DESheetInformation.ClassGUID.Split("{}".ToCharArray());
                    sICGuid = "'" + this.DESheetInformation.SectorGUID + "'";
                    for (j = 0; j <= sClassGuid.Length - 1; j++)
                    {
                        sICGuid += ",'" + sClassGuid[j].ToString() + "'";
                    }
                    sQry = DBQueries.Calculates.GetICNIdByGId(sICGuid);

                    //-- Get Dataview using DAL
                    oDV = DBConnection.ExecuteDataTable(sQry).DefaultView;

                    foreach (DataRowView oDVRow1 in oDV)
                    {
                        //-- Using DAL for inserting IC IUS relation
                        sQry = DBQueries.Calculates.InsertIC_IUSRelation(Convert.ToInt32(oDVRow1["IC_NId"]), iIUSNId[i]);
                        DBConnection.ExecuteNonQuery(sQry);
                    }
                }
            }

            else if (bNewSector || bNewClass)
            {
                for (i = 0; i <= iSubgroupNId.Length - 1; i++)
                {
                    sQry = DBQueries.IUS.GetIUSByI_U_S(iIndicatorNId.ToString(), iUnitNId.ToString(), iSubgroupNId[i].ToString());
                    iIUSNId[i] = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                    if (bNewSector)
                    {
                        //-- Using DAL for inserting IC IUS relation
                        sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSectorNID, iIUSNId[i]);
                        DBConnection.ExecuteNonQuery(sQry);
                    }

                    if (bNewClass)
                    {
                        for (j = 0; j <= iClassNId.Length - 1; j++)
                        {

                            //-- Using DAL for inserting IC IUS relation
                            sQry = DBQueries.Calculates.InsertIC_IUSRelation(iClassNId[j], iIUSNId[i]);
                            try
                            {
                                DBConnection.ExecuteNonQuery(sQry);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
            }
            else
            {
                int Index = 0;
                foreach (int SubgroupNId in iSubgroupNId)
                {
                    //-- Using DAL Query for getting IUSNId
                    sQry = DBQueries.Calculates.GetIUSNIdByIUS(iIndicatorNId, iUnitNId, SubgroupNId);
                    iIUSNId[Index] = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));
                    Index += 1;
                }
            }

            string sTimePeriod = string.Empty;
            int iTimePeriod_NId = 0;
            Hashtable oTimePeriod = new Hashtable();
            string sAreaId = string.Empty;
            int iArea_NId = 0;
            Hashtable oAreaId = new Hashtable();
            string sDataValue = string.Empty;
            System.DateTime dtStartDate = System.DateTime.Now;
            System.DateTime dtEndDate = System.DateTime.Now;
            string sSubgroup = string.Empty;
            string sSource = string.Empty;
            int iSource_NId = 0;
            Hashtable oSource = new Hashtable();
            string sFootNote = "";
            int iFootNote_NId = -1;
            Hashtable oFootNote = new Hashtable();
            string sData_Denominator = "";
            IWorksheet DataSheet;
            DIDatabase DIdatabase = null;

            this.DIExcel = new DIExcel(tempDESheetPath);
            // this.DIExcel = new DIExcel(this.TempLogFilePath);
            DataSheet = DIExcel.GetWorksheet(0);

            {
                //For each record in excel sheet '*** Get TimePeriod_NId, Area_NId, Data Value, Subgroup, SourceNId
                for (i = 10; i <= miCtrFillTo; i++)
                {
                    try
                    {
                        if (DataSheet.Cells[i, 0].Value.ToString() == "" || DataSheet.Cells[i, 1].Value.ToString() == "" || DataSheet.Cells[i, 3].Value.ToString() == "" || DataSheet.Cells[i, 4].Value.ToString() == "" || DataSheet.Cells[i, 5].Value.ToString() == "")
                        {
                        }
                        //*** If TimePeriod, AreaID, DataValue,Subgroup, Source is blank leave this record
                        else
                        {
                            //*** TimePeriod
                            sTimePeriod = DataSheet.Cells[i, 0].Value.ToString();
                            iTimePeriod_NId = -1;
                            if (CheckDate(sTimePeriod))
                            {
                                //*** Check for Valid TimeFormat allowed in DE
                                if (oTimePeriod.ContainsKey(sTimePeriod))
                                {
                                    iTimePeriod_NId = Convert.ToInt32(oTimePeriod[sTimePeriod]);
                                }
                                else
                                {
                                    sQry = DBQueries.Calculates.GetTimeperiodNIdByTimePeriod(sTimePeriod);
                                    iTimePeriod_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                    if (iTimePeriod_NId == 0)
                                    {
                                        // Using DAL for getting and executing Query for inserting timeperiod
                                        sQry = DI_LibDAL.Queries.Timeperiod.Insert.InsertTimeperiod(sDB_Prefix, sTimePeriod);
                                        DBConnection.ExecuteNonQuery(sQry);
                                        iTimePeriod_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                                    }
                                    oTimePeriod.Add(sTimePeriod, iTimePeriod_NId);
                                }
                                SetDate(sTimePeriod, ref dtStartDate, ref dtEndDate);
                            }
                            else
                            {
                                iTimePeriod_NId = -1;
                            }

                            //*** Area
                            sAreaId = DataSheet.Cells[i, 1].Value.ToString();
                            iArea_NId = -1;
                            if (oAreaId.ContainsKey(sAreaId))
                            {
                                iArea_NId = Convert.ToInt32(oAreaId[sAreaId]);
                            }
                            else
                            {
                                //-- Using DAL for getting AreaNId Using AreaID
                                sQry = DBQueries.Calculates.GetAreaNIdByAreaID(sAreaId);
                                iArea_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                if (iArea_NId == 0)
                                {
                                    oAreaId.Add(sAreaId, -1);
                                }
                                //*** Don't add New areas to database
                                else
                                {
                                    oAreaId.Add(sAreaId, iArea_NId);
                                }
                            }

                            //*** Data value
                            sDataValue = DataSheet.Cells[i, 3].Value.ToString();

                            //*** Subgroup
                            sSubgroup = DataSheet.Cells[i, 4].Value.ToString();

                            //*** Source
                            sSource = DI_LibBAL.Utility.DICommon.RemoveQuotes(DataSheet.Cells[i, 5].Value.ToString());
                            iSource_NId = -1;
                            if (oSource.ContainsKey(sSource))
                            {
                                iSource_NId = Convert.ToInt32(oSource[sSource]);
                            }
                            else
                            {
                                sQry = DBQueries.IndicatorClassification.GetIC(FilterFieldType.Name, " '" + sSource + "'", ICType.Source, FieldSelection.NId);
                                iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                if (iSource_NId == 0)
                                {
                                    string[] sSourceArr;
                                    sSourceArr = sSource.Split('_');
                                    //Publisher_ISOCode_Year: Parent= Publisher; Child= Abbr_Year
                                    if (sSourceArr.Length >= 2)
                                    {
                                        //*** Insert Parent
                                        sQry = DBQueries.IndicatorClassification.GetIC(FilterFieldType.Name, " '" + sSourceArr[0] + "'", ICType.Source, FieldSelection.NId);
                                        iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                        if (iSource_NId == 0)
                                        {
                                            sQry = DI_LibDAL.Queries.IndicatorClassification.Insert.InsertIC(sDB_Prefix, sLng_Suffix, sSourceArr[0], Guid.NewGuid().ToString(), false, -1, "", ICType.Source);
                                            DBConnection.ExecuteNonQuery(sQry);
                                            iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                                        }
                                        //*** Create relationship
                                        for (j = 0; j <= iIUSNId.Length - 1; j++)
                                        {
                                            sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSource_NId, iIUSNId[j]);
                                            //'sQry = "INSERT INTO " & sDB_Prefix & "Indicator_Classifications_IUS" & " (IC_NId,IUSNId) VALUES (" & iSource_NId & "," & iIUSNId(j) & ")"
                                            try
                                            {
                                                DBConnection.ExecuteNonQuery(sQry);
                                            }

                                            catch (Exception ex)
                                            {
                                            }
                                        }

                                        //*** Insert Source
                                        // Using DAL for inserting Source
                                        sQry = DI_LibDAL.Queries.IndicatorClassification.Insert.InsertIC(sDB_Prefix, sLng_Suffix, sSource.Replace("'", "''"), Guid.NewGuid().ToString(), false, iSource_NId, "", ICType.Source);
                                        DBConnection.ExecuteNonQuery(sQry);
                                        iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));

                                        //*** Create relationship
                                        for (j = 0; j <= iIUSNId.Length - 1; j++)
                                        {
                                            sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSource_NId, iIUSNId[j]);

                                            try
                                            {
                                                DBConnection.ExecuteNonQuery(sQry);
                                            }
                                            //' oDestDB.ExecuteNonQuery(sQry)
                                            catch (Exception ex)
                                            {
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //iSource_NId = -1
                                        if (sSource.Trim() != "")
                                        {
                                            //*** Insert Parent as "Global"
                                            sQry = DBQueries.IndicatorClassification.GetIC(FilterFieldType.Name, "Global", ICType.Source, FieldSelection.NId);
                                            iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                            if (iSource_NId == 0)
                                            {
                                                sQry = DI_LibDAL.Queries.IndicatorClassification.Insert.InsertIC(sDB_Prefix, sLng_Suffix, "Global", Guid.NewGuid().ToString(), false, -1, "", ICType.Source);
                                                DBConnection.ExecuteNonQuery(sQry);
                                                iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                                            }

                                            //*** Create relationship
                                            for (j = 0; j <= iIUSNId.Length - 1; j++)
                                            {
                                                sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSource_NId, iIUSNId[j]);
                                                try
                                                {
                                                    DBConnection.ExecuteNonQuery(sQry);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }

                                            //*** Insert Source
                                            sQry = DI_LibDAL.Queries.IndicatorClassification.Insert.InsertIC(sDB_Prefix, sLng_Suffix, "Global_" + sSource.Replace("'", "''"), Guid.NewGuid().ToString(), false, iSource_NId, "", ICType.Source);
                                            DBConnection.ExecuteNonQuery(sQry);
                                            iSource_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));

                                            //*** Create relationship
                                            for (j = 0; j <= iIUSNId.Length - 1; j++)
                                            {

                                                sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSource_NId, iIUSNId[j]);

                                                try
                                                {
                                                    DBConnection.ExecuteNonQuery(sQry);
                                                }
                                                catch (Exception ex)
                                                {
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //*** If New IUS was created then Create Relationship with Source
                                    if (bNewIUS)
                                    {
                                        // using DAL query for getting parentNId
                                        sQry = DBQueries.Calculates.GetICParentNIdByICNId(iSource_NId, "SR");
                                        iParentNId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));

                                        if (iParentNId != 0)
                                        {
                                            for (j = 0; j <= iIUSNId.Length - 1; j++)
                                            {
                                                sQry = DBQueries.Calculates.InsertIC_IUSRelation(iParentNId, iIUSNId[j]);
                                                try
                                                {
                                                    DBConnection.ExecuteNonQuery(sQry);
                                                }

                                                catch (Exception ex)
                                                {
                                                    //*** database maintains unique composite key for IC_NId and IUSNId - this will prevent duplicate entry if any
                                                }
                                            }
                                        }

                                        for (j = 0; j <= iIUSNId.Length - 1; j++)
                                        {
                                            sQry = DBQueries.Calculates.InsertIC_IUSRelation(iSource_NId, iIUSNId[j]);
                                            try
                                            {
                                                DBConnection.ExecuteNonQuery(sQry);
                                            }

                                            catch (Exception ex)
                                            {
                                                Console.Write(ex.Message);
                                            }
                                        }
                                    }
                                }
                                oSource.Add(sSource, iSource_NId);
                            }

                            try
                            {
                                sFootNote = DataSheet.Cells[i, 6].Value.ToString();
                            }
                            catch (Exception ex)
                            {
                                sFootNote = "";
                            }

                            iFootNote_NId = -1;
                            if (sFootNote != "")
                            {
                                if (oFootNote.ContainsKey(sFootNote))
                                {
                                    iFootNote_NId = Convert.ToInt32(oFootNote[sFootNote]);
                                }
                                else
                                {
                                    sQry = DBQueries.Calculates.GetFootNoteNIdByFootNote(Utility.DICommon.EscapeWildcardChar(Utility.DICommon.RemoveQuotes(sFootNote)));
                                    iFootNote_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery(sQry));
                                    if (iFootNote_NId == 0)
                                    {
                                        sQry = DI_LibDAL.Queries.Footnote.Insert.InsertFootnote(sDB_Prefix, sLng_Suffix, sFootNote, Guid.NewGuid().ToString());
                                        DBConnection.ExecuteNonQuery(sQry);
                                        iFootNote_NId = Convert.ToInt32(DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                                    }
                                    oFootNote.Add(sFootNote, iFootNote_NId);
                                }
                            }

                            try
                            {
                                if (Utility.DICommon.IsNumeric(DataSheet.Cells[i, 7].Value.ToString(), System.Threading.Thread.CurrentThread.CurrentCulture))
                                {
                                    sData_Denominator = DataSheet.Cells[i, 7].Value.ToString() + ",";
                                }
                                else
                                {
                                    sData_Denominator = "";
                                }
                            }
                            catch (Exception ex)
                            {
                                sData_Denominator = "";
                            }

                            if (iIUSNId[0] == -1 | iTimePeriod_NId == -1 | iArea_NId == -1 | iSource_NId == -1 | sDataValue == "")
                            {
                            }
                            else
                            {
                                if (this.ApplicationWizardType == WizardType.HundredMinus)
                                {
                                    sQry = DBQueries.Calculates.InsertDataForCalculate(iIUSNId[Array.IndexOf(this.DESheetInformation.Subgroup, sSubgroup)], iTimePeriod_NId, iArea_NId, sDataValue, "#" + dtStartDate.ToString("MM/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "#", "#" + dtEndDate.ToString("MM/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "#", "", iFootNote_NId, iSource_NId);

                                    DBConnection.ExecuteNonQuery(sQry);

                                }

                                else
                                {
                                    sQry = DBQueries.Calculates.InsertDataForCalculate(iIUSNId[Array.IndexOf(this.DESheetInformation.Subgroup, sSubgroup)], iTimePeriod_NId, iArea_NId, sDataValue, "#" + dtStartDate.ToString("MM/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "#", "#" + dtEndDate.ToString("MM/dd/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "#", sData_Denominator, iFootNote_NId, iSource_NId);

                                    DBConnection.ExecuteNonQuery(sQry);
                                }
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                    }
                }

                // Update Indicator Unit subgroupNId
                DIdatabase = new DIDatabase(DBConnection, DBQueries);
                DIdatabase.UpdateIndicatorUnitSubgroupNIDsInData();
                DBConnection.Dispose();
            }
            //1.Time - 2.AreaId - 3.AreaName - 4.DataValue - 5.Subgroup - 6.Source - 7.Footnote - 8.Denominator - 12.SubgroupNId
            //DataSheet = null;

            if ((oDV != null))
            {
                oDV.Dispose();
                oDV = null;
            }
        }
Пример #3
0
        public bool CreateTemplateFrmSDMX(string templateFileName, List<string> SDMXFilenames, string tempFolderPath, string languageCode, bool importMetadata,string sdmxMetadataWebservice)
        {
            bool RetVal = true;
            DIConnection DBConnection = null;
            DIQueries DBQueries;
            try
            {
                //create temp template file
                DIDatabase TempTemplateFile = new DIDatabase(templateFileName, "UT_", languageCode);

                // create database object
                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, templateFileName, string.Empty, string.Empty);
                DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), languageCode);

                // delete default categories from blank template
                DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.MetadataCategory.Delete.DeleteMetadataCategory(DBQueries.TablesName.MetadataCategory, string.Empty));

                // import data from SDMX
                foreach (string DSDFilenameWPath in SDMXFilenames)
                {
                    //if (SDMXUtility.Validate_DSDFile(SDMXSchemaType.Two_One, DSDFilenameWPath))
                    //{
                        SDMXHelper.Import_DSD(SDMXSchemaType.Two_One, DSDFilenameWPath, DataFormats.StructureSpecificTS, "TempTemp", DBConnection, DBQueries, true);

                        if (importMetadata)
                        {
                            SDMXHelper.Import_Metadata(SDMXSchemaType.Two_One, "", sdmxMetadataWebservice, DBConnection, DBQueries);
                        }
                    //}
                    //else
                    //{
                    //    RetVal = false;
                    //    break;
                    //}
                }

            }
            catch (Exception ex)
            {
                RetVal = false;

            }
            finally
            {
                // dispose database object
                if (DBConnection != null)
                {
                    DBConnection.Dispose();
                }

            }

            return RetVal;
        }
Пример #4
0
        public bool CreateTemplateFrmDES(string templateFileName, List<string> DESFilenames, string tempFolderPath)
        {
            bool RetVal;

            //create temp template file
            DIDatabase TempTemplateFile = new DIDatabase(templateFileName);

            //import data from DES
            this.Spreadsheets = new DataEntrySpreadsheets(DESFilenames, templateFileName, tempFolderPath, string.Empty);
            RetVal = this.Spreadsheets.StartImportProcess();

            if (RetVal)
            {
                //import only ius
                DataTable TempDataTable = this.Spreadsheets.DBConnection.ExecuteDataTable("Select * from " + DevInfo.Lib.DI_LibBAL.Import.DAImport.Common.Constants.TempDataTableName);
                foreach (DataRow Row in TempDataTable.Rows)
                {
                    TempTemplateFile.DIIUS.CheckNCreateIUS(this.GetIUSInfo(Row));
                }

                //delete temp tables
                this.Spreadsheets.DBConnection.ExecuteNonQuery("DROP Table " + DAImportCommon.Constants.TempDataTableName);
                this.Spreadsheets.DBConnection.ExecuteNonQuery("DROP Table " + DAImportCommon.Constants.TempUnmatchedIUSTable);
                this.Spreadsheets.DBConnection.ExecuteNonQuery("DROP Table " + DAImportCommon.Constants.TempBlankIUSTable);

                //dispose objects
                this.Spreadsheets.Dispose();
                TempTemplateFile.Dispose();

                RetVal = true;
            }

            return RetVal;
        }
Пример #5
0
        /// <summary>
        /// DevInfo_5_0 Indicator Spreadsheet (should have 2 columns only staring the value from 6th Row - Indicator,Indicator_GId)
        /// </summary>
        /// <param name="templateFileName"></param>
        /// <param name="xlsFilenames"></param>
        /// <param name="tempFolderPath"></param>
        /// <returns></returns>
        public bool CreateTemplateFrmIndicatorSpreadsheet(string templateFileName, List<string> xlsFilenames, string tempFolderPath, DIQueries trgQueries, string languageName)
        {
            bool RetVal = false;
            DIConnection DBConnection = null;
            DIQueries DBQueries;
            IndicatorBuilder IndicatorBuilderObj;
            DIDatabase TempTemplateFile;
            string DataPrefix = string.Empty;
            string LanguageCode = string.Empty;

            try
            {
                //create temp template file
                TempTemplateFile = new DIDatabase(templateFileName);
                TempTemplateFile.Dispose();

                //create DIConnection, queries and indicator objects
                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, templateFileName, string.Empty, string.Empty);

                if (trgQueries == null)
                {
                    DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), DBConnection.DILanguageCodeDefault(DBConnection.DIDataSetDefault()));
                }
                else
                {
                    DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), trgQueries.LanguageCode);
                    DataPrefix = DBQueries.DataPrefix;
                    LanguageCode = trgQueries.LanguageCode.Replace("_", "");

                    this.UpdateTablesForTargetLanguage(languageName, DBConnection, DBQueries, DataPrefix, LanguageCode);
                }

                IndicatorBuilderObj = new IndicatorBuilder(DBConnection, DBQueries);

                //get indicators from excel files
                foreach (string XlsFileName in xlsFilenames)
                {
                    try
                    {
                        // insert indicators into template
                        DIExcel IndicatorXlsFile = new DIExcel(XlsFileName);
                        IndicatorInfo NewIndicator;
                        DataTable TempTable = IndicatorXlsFile.GetDataTableFromSheet(IndicatorXlsFile.GetSheetName(0));
                        //check it is a valid indicator excel file or not
                        if (TempTable.Rows.Count > 5 & TempTable.Columns.Count > 1)
                        {
                            if (TempTable.Rows[2][0].ToString() == DITemplate.IndicatorString)
                            {
                                //starting index should be 5
                                for (int i = 5; i < TempTable.Rows.Count; i++)
                                {
                                    NewIndicator = new IndicatorInfo();

                                    //indicator Name
                                    NewIndicator.Name = DICommon.RemoveQuotes(TempTable.Rows[i][0].ToString());
                                    //indicator GId
                                    NewIndicator.GID = DICommon.RemoveQuotes(TempTable.Rows[i][1].ToString());
                                    //insert indicator into template
                                    IndicatorBuilderObj.CheckNCreateIndicator(NewIndicator);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //
                    }
                }
                RetVal = true;

            }
            catch (Exception ex)
            {
                RetVal = false;
                throw new ApplicationException(ex.ToString());
            }
            finally
            {
                if (DBConnection != null)
                {
                    DBConnection.Dispose();
                }
            }
            return RetVal;
        }
Пример #6
0
        /// <summary>
        /// DevInfo_5_0 Area Spreadsheet (should have 5 columns only staring the value from 6th Row - AreaID, AreaName, AreaLevel, AreaGID, ParentGID)
        /// </summary>
        /// <param name="templateFileName"></param>
        /// <param name="xlsFilenames"></param>
        /// <param name="tempFolderPath"></param>
        /// <param name="trgDBQueries">Instance of target queries object</param>
        /// <param name="languageName">languageName</param>
        /// <returns></returns>
        public bool CreateTemplateFrmAreaSpreadsheet(string templateFileName, List<string> xlsFilenames, string tempFolderPath, DIQueries trgDBQueries, string languageName)
        {
            bool RetVal = false;
            DIConnection DBConnection = null;
            DIQueries DBQueries;
            AreaBuilder AreaBuilderObj;
            DIDatabase TempTemplateFile;
            string DataPrefix = string.Empty;
            string LanguageCode = string.Empty;
            LanguageBuilder DILanguageBuilder;
            try
            {
                //create temp template file
                TempTemplateFile = new DIDatabase(templateFileName);
                TempTemplateFile.Dispose();

                //create DIConnection, queries and area objects
                DBConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, templateFileName, string.Empty, string.Empty);

                if (trgDBQueries != null)
                {
                    DBQueries = new DIQueries(DBConnection.DIDataSetDefault(), trgDBQueries.LanguageCode);
                    DataPrefix = DBQueries.DataPrefix;
                    LanguageCode = trgDBQueries.LanguageCode.Replace("_", "");

                    // create langauge dependent tables if not exists in the new template
                    this.UpdateTablesForTargetLanguage(languageName, DBConnection, DBQueries, DataPrefix, LanguageCode);
                }
                else
                {

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

                AreaBuilderObj = new AreaBuilder(DBConnection, DBQueries);

                //get areas from excel files
                foreach (string XlsFileName in xlsFilenames)
                {
                    try
                    {
                        // insert area into template
                        DIExcel AreaXlsFile = new DIExcel(XlsFileName);
                        AreaInfo NewArea;
                        DataTable TempTable = AreaXlsFile.GetDataTableFromSheet(AreaXlsFile.GetSheetName(0));

                        //check it is a valid area excel file or not
                        if (TempTable.Rows.Count > 5 & TempTable.Columns.Count > 1)
                        {
                            if (TempTable.Rows[2][0].ToString() == DITemplate.AreaIdString
                                & TempTable.Rows[2][1].ToString() == DITemplate.AreaNameString
                                & TempTable.Rows[2][2].ToString() == DITemplate.AreaLevelString
                                & TempTable.Rows[2][3].ToString() == DITemplate.AreaGIdString
                                & TempTable.Rows[2][4].ToString() == DITemplate.AreaParentGIdString)
                            {

                                // delete empty rows
                                for (int i = 0; i < 4; i++)
                                {
                                    TempTable.Rows[0].Delete();
                                }

                                TempTable.AcceptChanges();

                                // sort the table by level
                                TempTable.DefaultView.Sort = TempTable.Columns[this.AreaSheetColumns[AreaSheetColumnType.AreaLevel].ColumnIndex].ColumnName;

                                foreach (DataRowView Row in TempTable.DefaultView)
                                {
                                    try
                                    {
                                        // get area info from temp table
                                        NewArea = new AreaInfo();
                                        NewArea.ID = DICommon.RemoveQuotes(Row[this.AreaSheetColumns[AreaSheetColumnType.AreaID].ColumnIndex].ToString());
                                        NewArea.Name = DICommon.RemoveQuotes(Row[this.AreaSheetColumns[AreaSheetColumnType.AreaName].ColumnIndex].ToString());
                                        NewArea.Level = Convert.ToInt32(Row[this.AreaSheetColumns[AreaSheetColumnType.AreaLevel].ColumnIndex]);
                                        NewArea.GID = DICommon.RemoveQuotes(Row[this.AreaSheetColumns[AreaSheetColumnType.AreaGID].ColumnIndex].ToString());
                                        NewArea.Parent = new AreaInfo();
                                        NewArea.Parent.ID = DICommon.RemoveQuotes(Row[this.AreaSheetColumns[AreaSheetColumnType.PareaGID].ColumnIndex].ToString());

                                        //insert area into template
                                        // Step 1: If Area_Parent_ID is blank then set Area_Parent_NID to -1 and Area_Level=1
                                        if (string.IsNullOrEmpty(NewArea.Parent.ID))
                                        {
                                            NewArea.Parent.Nid = -1;
                                            NewArea.Level = 1;
                                        }
                                        else
                                        {
                                            // Step 2: If Area_Parent_ID is not blank then get Area_Parent_NID
                                            NewArea.Parent.Nid = AreaBuilderObj.GetAreaNidByAreaID(NewArea.Parent.ID);

                                            if (NewArea.Parent.Nid <= 0)
                                            { // Step 2.1: If Area_Parent_NID <=0 then set Area_Parent_NID to -1 and Area_Level=1
                                                NewArea.Parent.Nid = -1;
                                                NewArea.Level = 1;
                                            }
                                            else
                                            { // Step 2.1: If Area_Parent_NID >0 then Area_Level=Area_Parent_Level+1

                                                //get parent area level
                                                NewArea.Parent.Level = AreaBuilderObj.GetAreaLevelByAreaID(NewArea.Parent.ID);
                                                NewArea.Level = NewArea.Parent.Level + 1;
                                            }
                                        }

                                        // insert area into template
                                        AreaBuilderObj.InsertIntoDatabase(NewArea.Name, NewArea.ID, NewArea.GID, NewArea.Level, NewArea.Parent.Nid);

                                    }
                                    catch (Exception ex)
                                    {
                                        // do nothing
                                    }

                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //
                    }
                }
                RetVal = true;

            }
            catch (Exception ex)
            {
                RetVal = false;
                throw new ApplicationException(ex.ToString());
            }
            finally
            {
                if (DBConnection != null)
                {
                    DBConnection.Dispose();
                }
            }
            return RetVal;
        }
        /// <summary>
        /// Converts DevInfo Database into DevInfo6.0.0.5 format
        /// </summary>
        /// <param name="forOnlineDB"></param>
        /// <returns></returns>
        public override bool DoConversion(bool forOnlineDB)
        {
            bool RetVal = false;
            int TotalSteps = 7;
            DBVersionBuilder VersionBuilder;
            DIDatabase DBDatabase;

            // Do the conversion only if database has different Schema
            try
            {
                if (!this.IsValidDB(forOnlineDB))
                {
                    if (!base.IsValidDB(forOnlineDB))
                    {
                        RetVal = base.DoConversion(forOnlineDB);
                    }

                    // Step 1: insert version info into database
                    VersionBuilder = new DBVersionBuilder(this._DBConnection, this._DBQueries);
                    VersionBuilder.InsertVersionInfo(Constants.Versions.DI6_0_0_5, Constants.VersionsChangedDates.DI6_0_0_5, Constants.VersionComments.DI6_0_0_5);

                    this.RaiseProcessStartedEvent(TotalSteps);

                    // Step 2: Add new columns into IC, Indicator, IUS & area table and create document table
                    this.UpdateDBSchema(forOnlineDB);

                    // Step 3: Create Metadata_Category Table
                    this.CreateMetadatCategoryTable(forOnlineDB);
                    this.RaiseProcessInfoEvent(1);

                    // Step 4: Add Order Column into Subgroup, SubgrouVal,IC
                    this.AddOrderColumn(forOnlineDB, this._DBConnection.ConnectionStringParameters.ServerType);
                    this.RaiseProcessInfoEvent(2);

                    // Step 5: Convert Metadata Values of Indicator,Area,Source
                    this.ConvertMetadataXmlIntoDatabse();
                    this.RaiseProcessInfoEvent(3);

                    // Step 6: Update Metadata Values of Indicator,Area,Source and Set Category values from Mask Files
                    this.ConvertMetataCategoryIntoDatabase();
                    this.RaiseProcessInfoEvent(4);

                    // Step 7: Update Order value SubgroupVal
                    this.UpdateSortOrderIntoSubgroupVal();
                    this.RaiseProcessInfoEvent(5);

                    // Step 8: Update Sortt Column for Subgroup Dimension Values
                    this.UpdateSortOrderIntoSubgroup();
                    this.RaiseProcessInfoEvent(6);

                    // Step 9: Update Order value for Indicator Classification(for Sector,Goal,Source... etc. and IC_IUS_Order IN IC_IUS table
                    this.UpdateSortOrderIntoIC(-1, ICType.Sector);
                    this.UpdateSortOrderIntoIC(-1, ICType.Source);
                    this.UpdateSortOrderIntoIC(-1, ICType.Theme);
                    this.UpdateSortOrderIntoIC(-1, ICType.Goal);
                    this.UpdateSortOrderIntoIC(-1, ICType.Institution);
                    this.UpdateSortOrderIntoIC(-1, ICType.Convention);
                    this.UpdateSortOrderIntoIC(-1, ICType.CF);
                    this.RaiseProcessInfoEvent(7);

                    RetVal = true;

                    // Step 10: update auto calcualted fields
                    DBDatabase = new DIDatabase(this._DBConnection, this._DBQueries);
                    DBDatabase.UpdateAutoCalculatedFieldsInTables();
                }
                else
                {
                    RetVal = true;
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }

            return RetVal;
        }
Пример #8
0
        public static bool CompactNUpdateOnlineDataBase(ref DIConnection sourceDBConnection, DIQueries dbQueries)
        {
            bool RetVal = false;
            DIConnectionDetails SourceDBConnectionDetails;
            DBMetadataTableBuilder DBMetadataTable;

            DIDatabase DBDatabase;
            string DataPrefix = string.Empty;

            try
            {
                if (sourceDBConnection != null)
                {

                    // update counts in DBMetadata table( only if database/template is in DI6 format)
                    if (dbQueries == null)
                    {
                        DataPrefix = sourceDBConnection.DIDataSetDefault();

                        dbQueries = new DIQueries(DataPrefix, sourceDBConnection.DILanguageCodeDefault(DataPrefix));
                    }

                    DBMetadataTable = new DBMetadataTableBuilder(sourceDBConnection, dbQueries);
                    if (DBMetadataTable.IsDBMetadataTableExists())
                    {
                        DBMetadataTable.GetNUpdateCounts();
                    }

                    if (DIDatabase.SeperateDataValueColumn)
                    {
                        // Check orgTextual_Data_value exists or not. If column exists then move textual & numeric values into their respective column.
                        DIDataValueHelper.SeparateTextualandNemericData(sourceDBConnection, dbQueries);
                    }

                    // update indicator unit and subgroup nids in Data table
                    DBDatabase = new DIDatabase(sourceDBConnection, dbQueries);
                    DBDatabase.UpdateIndicatorUnitSubgroupNIDsInData();

                    // remove FootnoteNId inconsistency. (replace 0 or null FootnoteNId by -1 in UT_data table).
                    DBDatabase.RemoveFootnoteNIdsInconsistencyInData();

                    RetVal = true;
                }

            }
            catch (Exception ex)
            {
                RetVal = false;
                ExceptionFacade.ThrowException(ex);
            }
            return RetVal;
        }
Пример #9
0
        /// <summary>
        /// Compact the database mainly Access database(.mdb) and save as specified destination file.
        /// </summary>
        ///<param name="sourceDBConnection"> Source database connection</param>
        /// <param name="destFilePath">destination file name with path.</param>
        /// <param name="disposeConnection"> Set true when calling this methods for finish process otherwise false.For only saving the database, pass False and for finish , pass true.  </param>
        /// <returns>true, if success.</returns>
        /// <remarks>Before calling this function,dont dispose source database connection </remarks>
        public static bool CompactDataBase(ref DIConnection sourceDBConnection, DIQueries dbQueries, string destFilePath, bool disposeConnection)
        {
            bool RetVal = false;
            bool IsFileOpen = false;
            DIConnectionDetails SourceDBConnectionDetails;
            DBMetadataTableBuilder DBMetadataTable;
            DIDatabase DBDatabase;
            string SourceDBNameWPath;
            JRO.JetEngine je;
            string DataPrefix = string.Empty;
            DI7MetadataCategoryBuilder DI7MetadataCategory;

            // -- NOTE: USE sDestFile only when sDestFile <> sSourceDB
            try
            {
                if (sourceDBConnection != null && !string.IsNullOrEmpty(destFilePath))
                {
                    //Drop index for ut_data table for IUSNID, areanid column
                    DIDatabase.DropDefaultIndex(sourceDBConnection);

                    // update counts in DBMetadata table( only if database/template is in DI6 format)
                    if (dbQueries == null)
                    {
                        DataPrefix = sourceDBConnection.DIDataSetDefault();

                        dbQueries = new DIQueries(DataPrefix, sourceDBConnection.DILanguageCodeDefault(DataPrefix));
                    }

                    DBMetadataTable = new DBMetadataTableBuilder(sourceDBConnection, dbQueries);
                    if (DBMetadataTable.IsDBMetadataTableExists())
                    {
                        DBMetadataTable.GetNUpdateCounts();
                    }
                    //Updating XSLT from Resourse File into database.
                    DI7MetadataCategory = new DI7MetadataCategoryBuilder(sourceDBConnection, dbQueries);
                    DI7MetadataCategory.UpdateXSLT(dbQueries.DataPrefix);

                    // update database name in DB_Available table
                    sourceDBConnection.InsertNewDBFileName(dbQueries.DataPrefix, DICommon.RemoveQuotes(System.IO.Path.GetFileName(destFilePath)));

                    if (DIDatabase.SeperateDataValueColumn)
                    {
                        // Check orgTextual_Data_value exists or not. If column exists then move textual & numeric values into their respective column.
                        DIDataValueHelper.SeparateTextualandNemericData(sourceDBConnection, dbQueries);
                    }

                    // update indicator unit and subgroup nids in Data table
                    DBDatabase = new DIDatabase(sourceDBConnection, dbQueries);
                    DBDatabase.UpdateIndicatorUnitSubgroupNIDsInData();

                    // remove FootnoteNId inconsistency. (replace 0 or null FootnoteNId by -1 in UT_data table).
                    DBDatabase.RemoveFootnoteNIdsInconsistencyInData();

                    // Update auto calculated columns ( IC table - Publisher, Year & title ,Indicator table- Data_Exists, area table - data_exist, IUS table - subgroup_nids & data_exist) into the database/template
                    DBDatabase.UpdateAutoCalculatedFieldsInTables();

                    // Update auto calculated column of DI7
                    DBDatabase.UpdateAutoCalculatedDI7FieldsInTables();

                    //Update those subgroupVals which is not associated with any subgroup type.Then insert association with others for those subgroup
                    DBDatabase.UpdateSubgroupValsInOthersSGDimensionInTables();

                    //Create index for ut_data table for IUSNID, areanid column
                    DIDatabase.CreateDefaultIndex(sourceDBConnection);

                    // dispose source database connection
                    SourceDBConnectionDetails = sourceDBConnection.ConnectionStringParameters;
                    SourceDBNameWPath = SourceDBConnectionDetails.DbName;
                    sourceDBConnection.Dispose();
                    System.Threading.Thread.Sleep(10);
                    try
                    {
                        if (File.Exists(destFilePath))
                        {
                            File.SetAttributes(destFilePath, FileAttributes.Normal);
                            File.Delete(destFilePath);
                        }
                    }
                    catch { }

                    //-- Copy SourceFile to temp file so that any existing connection on database shall not stop compact database process.
                    //string TempFile = DICommon.GetValidFileName(DateTime.Now.ToString()) + Path.GetExtension(SourceDBNameWPath);
                    //File.Copy(SourceDBNameWPath, TempFile, true);

                    try
                    {
                        // compacting the database
                        je = new JRO.JetEngine();
                        je.CompactDatabase("Data Source=\"" + SourceDBNameWPath + "\";Jet OLEDB:Database Password="******"Data Source=\"" + destFilePath + "\";Jet OLEDB:Database Password="******"Database already exists"))
                            IsFileOpen = true;
                    }

                    // reconnect to source database
                    if (!disposeConnection)
                    {
                        sourceDBConnection = new DIConnection(SourceDBConnectionDetails);
                    }

                    if (IsFileOpen == false)
                        RetVal = true;
                }
            }
            catch (Exception ex)
            {
                RetVal = false;
                ExceptionFacade.ThrowException(ex);
            }
            return RetVal;
        }
Пример #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;
        }