/// <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> private void ImportSectors(List <string> selectedNids, bool allSelected) { int ProgressBarValue = 0; IndicatorClassificationInfo SrcClassification; DataRow Row; List <string> ImportedNids = new List <string>(); foreach (string Nid in selectedNids) { try { //get ic from source table Row = this.SourceTable.Select(this.TagValueColumnName + "=" + Nid)[0]; if (!ImportedNids.Contains(Row[IndicatorClassifications.ICNId].ToString())) { SrcClassification = new IndicatorClassificationInfo(); SrcClassification.Name = DICommon.RemoveQuotes(Row[IndicatorClassifications.ICName].ToString()); SrcClassification.GID = Row[IndicatorClassifications.ICGId].ToString(); SrcClassification.IsGlobal = Convert.ToBoolean(Row[IndicatorClassifications.ICGlobal]); SrcClassification.Nid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]); if (!Information.IsDBNull(Row[IndicatorClassifications.ICInfo])) { SrcClassification.ClassificationInfo = DICommon.RemoveQuotes(Row[IndicatorClassifications.ICInfo].ToString()); } SrcClassification.Parent = new IndicatorClassificationInfo(); SrcClassification.Parent.Nid = Convert.ToInt32(Row[IndicatorClassifications.ICParent_NId]); SrcClassification.Type = this._IndicatorClassificationType; //import into target database Utility.CreateClassificationChainFromExtDB( SrcClassification.Nid, SrcClassification.Parent.Nid, SrcClassification.GID, SrcClassification.Name, SrcClassification.Type, SrcClassification.ClassificationInfo, SrcClassification.IsGlobal, this.SourceDBQueries, this.SourceDBConnection, this._TargetDBQueries, this._TargetDBConnection); ImportedNids.Add(Row[IndicatorClassifications.ICNId].ToString()); } this.RaiseIncrementProgessBarEvent(ProgressBarValue); ProgressBarValue++; } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } } }
private IndicatorClassificationInfo GetICInfo(DataRow row) { IndicatorClassificationInfo RetVal; try { //get unit from source table RetVal = new IndicatorClassificationInfo(); RetVal.Name = DICommon.RemoveQuotes(row[IndicatorClassifications.ICName].ToString()); RetVal.GID = row[IndicatorClassifications.ICGId].ToString(); RetVal.IsGlobal = Convert.ToBoolean(row[IndicatorClassifications.ICGlobal]); RetVal.ClassificationInfo = DICommon.RemoveQuotes(Convert.ToString(row[IndicatorClassifications.ICInfo])); RetVal.Nid = Convert.ToInt32(row[IndicatorClassifications.ICNId]); RetVal.Parent = new IndicatorClassificationInfo(); RetVal.Parent.Nid = Convert.ToInt32(row[IndicatorClassifications.ICParent_NId]); } catch (Exception ex) { RetVal = null; ExceptionFacade.ThrowException(ex); } return(RetVal); }
private void ImportSector(DataRow row) { IndicatorClassificationInfo SrcClassification; try { //get ic from source table SrcClassification = new IndicatorClassificationInfo(); SrcClassification.Name = DICommon.RemoveQuotes(row[IndicatorClassifications.ICName].ToString()); SrcClassification.GID = row[IndicatorClassifications.ICGId].ToString(); SrcClassification.IsGlobal = Convert.ToBoolean(row[IndicatorClassifications.ICGlobal]); SrcClassification.Nid = Convert.ToInt32(row[IndicatorClassifications.ICNId]); if (!Information.IsDBNull(row[IndicatorClassifications.ICInfo])) { SrcClassification.ClassificationInfo = DICommon.RemoveQuotes(row[IndicatorClassifications.ICInfo].ToString()); } SrcClassification.Parent = new IndicatorClassificationInfo(); SrcClassification.Parent.Nid = Convert.ToInt32(row[IndicatorClassifications.ICParent_NId]); SrcClassification.Type = ICType.Sector; //import into target database Utility.CreateClassificationChainFromExtDB( SrcClassification.Nid, SrcClassification.Parent.Nid, SrcClassification.GID, SrcClassification.Name, SrcClassification.Type, SrcClassification.ClassificationInfo, SrcClassification.IsGlobal, this.SourceDBQueries, this.SourceDBConnection, this._TargetDBQueries, this._TargetDBConnection); } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } }
internal int CreateClassificationChainFromExtDB(int srcICNId, int srcParentNId, string srcICGid, string srcICName, ICType srcICType, string srcICInfo, bool isGlobal, DIQueries srcQueries, DIConnection srcDBConnection, DIQueries targetDBQueries, DIConnection targetDBConnection) { int RetVal; //int TrgParentNId; //string TrgParentName; int NewParentNId; DataTable TempTable; IndicatorClassificationInfo ICInfo; IndicatorClassificationBuilder ClassificationBuilder = new IndicatorClassificationBuilder(targetDBConnection, targetDBQueries); // -- STEP 1: If the Parent NID is -1 then create the Classification at the root if (srcParentNId == -1) { // -- Create the Classification // -------------------------------------------------------------- // While importing the Classifications, if the NId of the Source Classification is _ // the same as that of the one created, then the Duplicate check fails and a duplicate // classification getscreated. PASS -99 as the first parameter to the calling function // -------------------------------------------------------------- ICInfo = new IndicatorClassificationInfo(); ICInfo.Parent = new IndicatorClassificationInfo(); ICInfo.Parent.Nid = srcParentNId; ICInfo.Nid = srcICNId; ICInfo.Name = srcICName; ICInfo.ClassificationInfo = srcICInfo; ICInfo.GID = srcICGid; ICInfo.IsGlobal = isGlobal; ICInfo.Type = srcICType; RetVal = ClassificationBuilder.ImportIndicatorClassification(ICInfo, srcICNId, srcQueries, srcDBConnection); } else { // -- STEP 2: If the Parent is not -1 then check for the existence of the Parent and then create the Classification // Classification can only be created if the parent exists // -- STEP 2.1: If the Parent Exists then create the Classification under that parent // -- STEP 2.2: If the Parent does not Exist then create the Parent first and then the Classification under that parent // -- STEP 2: Check the existence of the Parent in the Target Database // -- get the parent from the source database TempTable = srcDBConnection.ExecuteDataTable(srcQueries.IndicatorClassification.GetIC(FilterFieldType.NId, srcParentNId.ToString(), srcICType, FieldSelection.Heavy)); { // -------------------------------------------------------------- // While importing the Classifications, if the NId of the Source Classification is _ // the same as that of the one created, then the Duplicate check fails and a duplicate // classification getscreated. PASS -99 as the first parameter to the calling function // -------------------------------------------------------------- DataRow Row; string ClassificationInfo = string.Empty; Row = TempTable.Rows[0]; ClassificationInfo = Convert.ToString(Row[IndicatorClassifications.ICInfo]); NewParentNId = CreateClassificationChainFromExtDB( Convert.ToInt32(Row[IndicatorClassifications.ICNId]), Convert.ToInt32(Row[IndicatorClassifications.ICParent_NId]), Row[IndicatorClassifications.ICGId].ToString(), Row[IndicatorClassifications.ICName].ToString(), srcICType, ClassificationInfo, Convert.ToBoolean(Row[IndicatorClassifications.ICGlobal]), srcQueries, srcDBConnection, targetDBQueries, targetDBConnection);; } // -- Create the Child Now ICInfo = new IndicatorClassificationInfo(); ICInfo.Parent = new IndicatorClassificationInfo(); ICInfo.Parent.Nid = NewParentNId; // set new parent nid ICInfo.Nid = srcICNId; ICInfo.Name = srcICName; ICInfo.ClassificationInfo = srcICInfo; ICInfo.GID = srcICGid; ICInfo.IsGlobal = isGlobal; ICInfo.Type = srcICType; RetVal = ClassificationBuilder.ImportIndicatorClassification(ICInfo, srcICNId, srcQueries, srcDBConnection); } //import ic and ius relationship into indicator_classification_IUS table ClassificationBuilder.ImportICAndIUSRelations(srcICNId, RetVal, ICInfo.Type, srcQueries, srcDBConnection); return(RetVal); }
public override void Import(string selectedNIds) { IndicatorClassificationInfo SrcClassification; string SrcFileName = string.Empty; DataTable Table = null; int ProgressCounter = 0; //IndicatorClassificationBuilder ICBuilder = null; //Dictionary<string, DataRow> FileWithNids = new Dictionary<string, DataRow>(); DIConnection SourceDBConnection = null; DIQueries SourceDBQueries = null; // Initialize progress bar this.RaiseProgressBarInitialize(selectedNIds.Split(',').GetUpperBound(0) + 1); //-- Step 1: Get TempTable with Sorted SourceFileName Table = this._TargetDBConnection.ExecuteDataTable(this.ImportQueries.GetImportICs(selectedNIds)); ////-- Step 2:Initialise Indicator Builder with Target DBConnection //ICBuilder = new IndicatorClassificationBuilder(this.TargetDBConnection, this.TargetDBQueries); try { //-- Step 3: Import Nids for each SourceFile foreach (DataRow Row in Table.Copy().Rows) { try { if (SrcFileName != Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME])) { SrcFileName = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]); //-- Step 2:Initialise DBConnection if (SourceDBConnection != null) { SourceDBConnection.Dispose(); } SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SrcFileName, String.Empty, MergetTemplateConstants.DBPassword); SourceDBQueries = DataExchange.GetDBQueries(SourceDBConnection); } SrcClassification = new IndicatorClassificationInfo(); SrcClassification.Name = DICommon.RemoveQuotes(Row[IndicatorClassifications.ICName].ToString()); SrcClassification.GID = Row[IndicatorClassifications.ICGId].ToString(); SrcClassification.IsGlobal = Convert.ToBoolean(Row[IndicatorClassifications.ICGlobal]); SrcClassification.Nid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]); if (!string.IsNullOrEmpty(Convert.ToString((Row[IndicatorClassifications.ICInfo])))) { SrcClassification.ClassificationInfo = DICommon.RemoveQuotes(Row[IndicatorClassifications.ICInfo].ToString()); } SrcClassification.Parent = new IndicatorClassificationInfo(); SrcClassification.Parent.Nid = Convert.ToInt32(Row[IndicatorClassifications.ICParent_NId]); SrcClassification.Type = this._CurrentICType; //import into target database this.CreateClassificationChainFromExtDB( SrcClassification.Nid, SrcClassification.Parent.Nid, SrcClassification.GID, SrcClassification.Name, SrcClassification.Type, SrcClassification.ClassificationInfo, SrcClassification.IsGlobal, SourceDBQueries, SourceDBConnection, this._TargetDBQueries, this._TargetDBConnection); ProgressCounter += 1; this.RaiseProgressBarIncrement(ProgressCounter); } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } this._UnmatchedTable = this.GetUnmatchedTable(); this._AvailableTable = this.GetAvailableTable(); } } catch (Exception ex) { ExceptionFacade.ThrowException(ex); } finally { if (SourceDBConnection != null) { SourceDBConnection.Dispose(); } } // Close ProgressBar this.RaiseProgressBarClose(); }