/// <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++; } }
/// <summary> /// Imports mapped values into database and returns unmatched elements info /// </summary> /// <param name="mappedValues"></param> /// <param name="dataValue"></param> /// <param name="denominator"></param> /// <returns></returns> public UnMatchedElementInfo ImportMappedValuesIntoDB(DIConnection dbConnection, DIQueries dbQueries, string dataValue, string denominator) { UnMatchedElementInfo RetVal = new UnMatchedElementInfo(); int IndicatorNId = -1; int UnitNId = -1; int SGNId = -1; int IUSNId = -1; int AreaNId = -1; int SourceNId = -1; int TimeperiodNId = -1; int DataNId = -1; Dictionary <string, int> IUSNIds = new Dictionary <string, int>(); Dictionary <string, int> AreaNIds = new Dictionary <string, int>(); Dictionary <string, int> SourceNIds = new Dictionary <string, int>(); Dictionary <string, int> TimeperiodNIds = new Dictionary <string, int>(); IndicatorBuilder IndicatorBuilderObj; UnitBuilder UnitBuilderObj; DI6SubgroupValBuilder SGValBuilderObj; IUSBuilder IUSBuilderObj; AreaBuilder AreaBuilderObj; SourceBuilder SourceBuilderObj; TimeperiodBuilder TimeperiodBuilderObj; DIDatabase TargetDatabase; try { IndicatorBuilderObj = new IndicatorBuilder(dbConnection, dbQueries); UnitBuilderObj = new UnitBuilder(dbConnection, dbQueries); SGValBuilderObj = new DI6SubgroupValBuilder(dbConnection, dbQueries); IUSBuilderObj = new IUSBuilder(dbConnection, dbQueries); AreaBuilderObj = new AreaBuilder(dbConnection, dbQueries); SourceBuilderObj = new SourceBuilder(dbConnection, dbQueries); TimeperiodBuilderObj = new TimeperiodBuilder(dbConnection, dbQueries); TargetDatabase = new DIDatabase(dbConnection, dbQueries); // import value if (this.IsVaildMappedValues()) { // check IUSNId in IUSNIDs list if (IUSNIds.ContainsKey(this._IndicatorGID + this._UnitGID + this._SubgroupValGID)) { IUSNId = IUSNIds[this._IndicatorGID + this._UnitGID + this._SubgroupValGID]; } else { // indicator Nid IndicatorNId = IndicatorBuilderObj.GetIndicatorNid(this._IndicatorGID, this._IndicatorName); // UnitNId UnitNId = UnitBuilderObj.GetUnitNid(this._UnitGID, this._UnitName); // SG Val NID SGNId = SGValBuilderObj.GetSubgroupValNid(this._SubgroupValGID, this._SubgroupVal); //IUSNID IUSNId = IUSBuilderObj.GetIUSNid(IndicatorNId, UnitNId, SGNId); // if IUSNID <=0 then create the given IUS combinator into database if (IUSNId <= 0) { IUSNId = IUSBuilderObj.InsertIUSIntoDB(this._IndicatorGID, this._UnitGID, this._SubgroupValGID); } IUSNIds.Add((this._IndicatorGID + this._UnitGID + this._SubgroupValGID), IUSNId); } if (IUSNId > 0) { // get AREANID if (AreaNIds.ContainsKey(this._AreaID)) { AreaNId = AreaNIds[this._AreaID]; } else { AreaNId = AreaBuilderObj.GetAreaNidByAreaID(this._AreaID); AreaNIds.Add(this._AreaID, AreaNId); } // get sourcenid if (SourceNIds.ContainsKey(this._Source)) { SourceNId = SourceNIds[this._Source]; } else { SourceNId = SourceBuilderObj.CheckNCreateSource(this._Source); SourceNIds.Add(this._Source, SourceNId); } // get timeperiodNId if (TimeperiodNIds.ContainsKey(this._Timeperiod)) { TimeperiodNId = TimeperiodNIds[this._Timeperiod]; } else { TimeperiodNId = TimeperiodBuilderObj.CheckNCreateTimeperiod(this._Timeperiod); TimeperiodNIds.Add(this._Timeperiod, TimeperiodNId); } if (AreaNId > 0 && IUSNId > 0 && SourceNId > 0 && TimeperiodNId > 0 && !string.IsNullOrEmpty(dataValue)) { DataNId = TargetDatabase.CheckNCreateData(AreaNId, IUSNId, SourceNId, TimeperiodNId, dataValue); } // denominator value if (!string.IsNullOrEmpty(denominator) && DataNId > 0) { try { TargetDatabase.UpdateDenominatorValue(DataNId, Convert.ToInt32(Convert.ToDecimal(denominator))); } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } } } } // for log file if (!string.IsNullOrEmpty(dataValue)) { if (AreaNId <= 0 || IUSNId <= 0 || SourceNId <= 0 || TimeperiodNId <= 0) { // for log file if (AreaNId <= 0) { RetVal.Areas.Add(this._AreaID, this._Area); } if (IndicatorNId <= 0) { RetVal.Indicators.Add(this._IndicatorGID, this._IndicatorName); } if (UnitNId <= 0) { RetVal.Units.Add(this._UnitGID, this._UnitName); } if (SGNId <= 0) { RetVal.Subgroups.Add(this._SubgroupValGID, this._SubgroupVal); } } } } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } return(RetVal); }
/// <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); }