/// <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); }