/// <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) { int ProgressBarValue = 0; DataRow[] Rows; TimeperiodBuilder DBTimperiodBuilder = new TimeperiodBuilder(this._TargetDBConnection, this._TargetDBQueries); foreach (string Nid in SelectedNids) { //get timeperiod Rows=this.SourceTable.Select(this.TagValueColumnName + "=" + Nid); //import timeperiod DBTimperiodBuilder.CheckNCreateTimeperiod(Rows[0][Timeperiods.TimePeriod].ToString()); this.RaiseIncrementProgessBarEvent(ProgressBarValue); ProgressBarValue++; } }
private string GetTimeperiodNID(DataTable table, string key) { string RetVal = string.Empty; string sTimePeriod_NId = string.Empty; string sTime = string.Empty; // Time // Get DataValue of The Time Period try { if (key.Length == 0) { sTime = Convert.ToString(table.Select(QuestionTableColumns.QuestionKey +" = 'TIMEPERIOD'")[0][QuestionTableColumns.DataValue]); } else { sTime = Convert.ToString(table.Select(QuestionTableColumns.QuestionKey +" = '" + key + "'")[0][QuestionTableColumns.TimePeriod]); } if (!string.IsNullOrEmpty(sTime.Replace(".","").Replace("-","").Trim())) { TimeperiodBuilder Timeperiods = new TimeperiodBuilder(this._DBConnection, this._DBQuery); RetVal = Timeperiods.CheckNCreateTimeperiod(sTime).ToString(); } } catch (Exception ex) { // throw new ApplicationException(ex.ToString()); } return RetVal; }
/// <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> /// 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); }
/// <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; }