/// <summary> /// Checks and creates source /// </summary> /// <param name="sourceName"></param> /// <param name="isbn"></param> /// <param name="nature"></param> /// <returns></returns> public int CheckNCreateSource(string sourceName, string isbn,string nature) { int RetVal = 0; string Publisher = string.Empty; int ParentNid = 0; SourceInfo sourceInfo = new SourceInfo(); try { // check source exists or not RetVal = this.CheckSourceExists(sourceName); // if source does not exist then create it. if (RetVal <= 0) { //Step1: Get publisher from source. Publisher = this.GetSourceParentFrmSourceName(sourceName); //Step2: check publisher exists or not ParentNid = this.GetSourceParentNid(Publisher); //if not exists then create it if (ParentNid <= 0) { // create parent source this.InsertSourceParent(Publisher.ToString()); // get parent nid ParentNid = this.GetSourceParentNid(Publisher); } if (ParentNid > 0) { // create source this.InsertSource(sourceName, ParentNid, isbn, nature); RetVal = this.GetSourceNid(sourceName); } } // add source information into source collection sourceInfo.Name = sourceName; sourceInfo.Nid = RetVal; sourceInfo.ParentNid = ParentNid; sourceInfo.ISBN = isbn; sourceInfo.Nature = nature; this.AddSourceIntoCollection(sourceInfo); } catch (Exception) { RetVal = 0; } return RetVal; }
/// <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) { DataRow Row; SourceInfo SourceRecord = null; SourceBuilder SourceBuilderObj = null; DI7MetadataCategoryBuilder SourceMetadataCategoryBuilder = null; int ProgressBarValue = 0; try { // import source metadata categories from source dadtabase SourceMetadataCategoryBuilder = new DI7MetadataCategoryBuilder(this._TargetDBConnection, this._TargetDBQueries); SourceMetadataCategoryBuilder.ImportAllMetadataCategories(this.SourceDBConnection, this.SourceDBQueries, MetadataElementType.Source); //import selected sources foreach (string Nid in selectedNids) { try { Row = this.SourceTable.Select(this.TagValueColumnName + "=" + Nid)[0]; //import indicator SourceRecord = new SourceInfo(); SourceRecord.Name = Row[IndicatorClassifications.ICName].ToString(); SourceRecord.Info = Row[IndicatorClassifications.ICInfo].ToString(); SourceRecord.ISBN = Row[IndicatorClassifications.ISBN].ToString(); SourceRecord.Nature = Row[IndicatorClassifications.Nature].ToString(); SourceBuilderObj = new SourceBuilder(this._TargetDBConnection, this._TargetDBQueries); SourceBuilderObj.ImportSource(SourceRecord, Convert.ToInt32(Nid), this.SourceDBQueries, this.SourceDBConnection); } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } this.RaiseIncrementProgessBarEvent(ProgressBarValue); ProgressBarValue++; } } catch (Exception ex) { ExceptionHandler.ExceptionFacade.ThrowException(ex); } }
/// <summary> /// Add source info into sourcecollection. /// </summary> /// <param name="sourceRecord">object of SourceInfo</param> private void AddSourceIntoCollection(SourceInfo sourceInfo) { if (!this.Sources.ContainsKey(sourceInfo.Name)) { this.Sources.Add(sourceInfo.Name, sourceInfo); } }
/// <summary> /// To import source into template or database /// </summary> /// <param name="sourceInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSource(SourceInfo sourceInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; string MetadataInfo = string.Empty; string SqlString = string.Empty; string Publisher = string.Empty; int ParentNid = -1; DataRow Row; DataTable TempTable; Dictionary<String, String> OldIconNId_NewIconNId = new Dictionary<string, string>(); DI7MetaDataBuilder SourceMetadataBuilder = null; try { //check source already exists in database or not RetVal = this.GetSourceNid(sourceInfo.Name); if (RetVal > 0) { // if source indicator is global if (sourceInfo.Global) { // do nothing } } else { RetVal = this.CheckNCreateSource(sourceInfo.Name, sourceInfo.ISBN, sourceInfo.Nature); } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.IndicatorClassification, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata reports from source database into current database SourceMetadataBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); SourceMetadataBuilder.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource); //OldIconNId_NewIconNId = DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.MetadataSource, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); //// get metadata info. //MetadataInfo = sourceInfo.Info; //// Update IconNids in xml if exists //foreach (string OldIconName in OldIconNId_NewIconNId.Keys) //{ // MetadataInfo = MetadataInfo.Replace(OldIconName, OldIconNId_NewIconNId[OldIconName].ToString()); //} //MetadataInfo = DICommon.CheckNConvertMetadataXml(MetadataInfo); //// Update Metadata //this.DBConnection.ExecuteNonQuery(DALQueries.IndicatorClassification.Update.UpdateICInfo(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, DICommon.RemoveQuotes(MetadataInfo), ICType.Source, RetVal)); //// -- insert records in xslt tables //SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Source); //TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //if (TempTable.Rows.Count > 0) //{ // Row = TempTable.Rows[0]; // MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); // MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Source); //} } catch (Exception ex) { throw new ApplicationException(ex.Message); } return RetVal; }
/// <summary> /// Create and add record into database. /// </summary> /// <param name="areaInfo"></param> /// <param name="iusInfo"></param> /// <param name="timeperiodInfo"></param> /// <param name="sourceInfo"></param> /// <returns></returns> public int AddDataPoint(AreaInfo areaInfo, IUSInfo iusInfo, TimeperiodInfo timeperiodInfo, SourceInfo sourceInfo, string dataValue) { int RetVal = 0; int AreaNid = 0; int IUSNid = 0; int TimeperiodNid = 0; int SourceNid = 0; // Step 1: Area if (areaInfo.Nid <= 0) { AreaNid = this.DIArea.CheckNCreateArea(areaInfo); } else { AreaNid = areaInfo.Nid; } // Step 2: IUS, check for IUS only if IUSNid is zero. if (iusInfo.Nid <= 0) { IUSNid = this.DIIUS.CheckNCreateIUS(iusInfo); } else { IUSNid = iusInfo.Nid; } // Step 3: Timeperiod if (timeperiodInfo.Nid <= 0) { TimeperiodNid = this.DITimeperiod.CheckNCreateTimeperiod(timeperiodInfo.TimeperiodValue); } else { TimeperiodNid = timeperiodInfo.Nid; } // Step 4: Source if (sourceInfo.Nid <= 0) { SourceNid = this.DISource.CheckNCreateSource(sourceInfo.Name); } else { SourceNid = sourceInfo.Nid; } // Step 5: Insert Data and source , IUSNId & sourceparent ,IUSNID relationship into IC_IUS table RetVal = this.CheckNCreateData(AreaNid, IUSNid, SourceNid, TimeperiodNid, dataValue); return RetVal; }
/// <summary> /// Create and add record into database. /// </summary> /// <param name="areaInfo">object of AreaInfo</param> /// <param name="iusInfo">object of IUSInfo</param> /// <param name="timeperiod">Timeperiod</param> /// <param name="source">Source Name</param> /// <param name="dataValue">Data Value</param> /// <returns></returns> public int AddDataPoint(AreaInfo areaInfo, IUSInfo iusInfo, string timeperiod, string source, string dataValue) { int RetVal = 0; TimeperiodInfo TimeperiodObject = new TimeperiodInfo(); SourceInfo SourceObject = new SourceInfo(); if (areaInfo == null | string.IsNullOrEmpty(iusInfo.IndicatorInfo.Name) | string.IsNullOrEmpty(iusInfo.UnitInfo.Name) | string.IsNullOrEmpty(iusInfo.SubgroupValInfo.Name) | string.IsNullOrEmpty(timeperiod) | string.IsNullOrEmpty(source)) { //do nothing } else { //set timeperiod info TimeperiodObject.Nid = 0; TimeperiodObject.TimeperiodValue = timeperiod; //set source info SourceObject.Nid = 0; SourceObject.Name = source; //insert data RetVal = this.AddDataPoint(areaInfo, iusInfo, TimeperiodObject, SourceObject, dataValue); } return RetVal; }
/// <summary> /// To import source into template or database /// </summary> /// <param name="sourceInfo"></param> /// <param name="NidInSourceDB"></param> /// <param name="sourceQurey"></param> /// <param name="sourceDBConnection"></param> /// <returns></returns> public int ImportSource(SourceInfo sourceInfo, int NidInSourceDB, DIQueries sourceQurey, DIConnection sourceDBConnection) { int RetVal = -1; string MetadataInfo = string.Empty; string SqlString = string.Empty; string Publisher = string.Empty; int ParentNid = -1; DataRow Row; DataTable TempTable; Dictionary <String, String> OldIconNId_NewIconNId = new Dictionary <string, string>(); DI7MetaDataBuilder SourceMetadataBuilder = null; try { //check source already exists in database or not RetVal = this.GetSourceNid(sourceInfo.Name); if (RetVal > 0) { // if source indicator is global if (sourceInfo.Global) { // do nothing } } else { RetVal = this.CheckNCreateSource(sourceInfo.Name, sourceInfo.ISBN, sourceInfo.Nature); } //update/insert icon DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.IndicatorClassification, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); // import metadata reports from source database into current database SourceMetadataBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries); SourceMetadataBuilder.ImportMetadata(sourceDBConnection, sourceQurey, NidInSourceDB, RetVal, MetadataElementType.Source, MetaDataType.Source, IconElementType.MetadataSource); //OldIconNId_NewIconNId = DIIcons.ImportElement(NidInSourceDB, RetVal, IconElementType.MetadataSource, sourceQurey, sourceDBConnection, this.DBQueries, this.DBConnection); //// get metadata info. //MetadataInfo = sourceInfo.Info; //// Update IconNids in xml if exists //foreach (string OldIconName in OldIconNId_NewIconNId.Keys) //{ // MetadataInfo = MetadataInfo.Replace(OldIconName, OldIconNId_NewIconNId[OldIconName].ToString()); //} //MetadataInfo = DICommon.CheckNConvertMetadataXml(MetadataInfo); //// Update Metadata //this.DBConnection.ExecuteNonQuery(DALQueries.IndicatorClassification.Update.UpdateICInfo(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, DICommon.RemoveQuotes(MetadataInfo), ICType.Source, RetVal)); //// -- insert records in xslt tables //SqlString = sourceQurey.Xslt.GetXSLT(NidInSourceDB.ToString(), MetadataElementType.Source); //TempTable = sourceDBConnection.ExecuteDataTable(SqlString); //if (TempTable.Rows.Count > 0) //{ // Row = TempTable.Rows[0]; // MetaDataBuilderObj = new MetaDataBuilder(this.DBConnection, this.DBQueries); // MetaDataBuilderObj.ImportTransformInfo(Row[XSLT.XSLTText].ToString(), Row[XSLT.XSLTFile].ToString(), RetVal.ToString(), MetadataElementType.Source); //} } catch (Exception ex) { throw new ApplicationException(ex.Message); } return(RetVal); }