/// <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)
        {
            DI6SubgroupBuilder SGBuilderObj = new DI6SubgroupBuilder(this._TargetDBConnection, this._TargetDBQueries);
            DI6SubgroupInfo SourceDBSubgroup;
            DataRow Row;
            int ProgressBarValue = 0;

            foreach (string Nid in selectedNids)
            {
                try
                {
                    //get subgroup from source table
                    Row = this.SourceTable.Select(Subgroup.SubgroupNId + "=" + Nid)[0];
                    SourceDBSubgroup = new DI6SubgroupInfo();
                    SourceDBSubgroup.Name = DICommon.RemoveQuotes(Row[Subgroup.SubgroupName].ToString());
                    SourceDBSubgroup.GID = Row[Subgroup.SubgroupGId].ToString();
                    SourceDBSubgroup.Global = Convert.ToBoolean(Row[Subgroup.SubgroupGlobal]);
                    SourceDBSubgroup.Nid = Convert.ToInt32(Row[Subgroup.SubgroupNId]);
                    SourceDBSubgroup.Type = Convert.ToInt32(Row[Subgroup.SubgroupType]);

                    //import into target database
                    SGBuilderObj.ImportSubgroup(SourceDBSubgroup, SourceDBSubgroup.Nid, this.SourceDBQueries, this.SourceDBConnection);

                }
                catch (Exception ex)
                {
                    ExceptionFacade.ThrowException(ex);
                }
                this.RaiseIncrementProgessBarEvent(ProgressBarValue);
                ProgressBarValue++;
            }
        }
        public override void Import(string selectedNids)
        {
            DataTable Table = null;
            int ProgressCounter = 0;
            DI6SubgroupBuilder SGBuilderObj = null;
            DI6SubgroupInfo SGInfoObj = null;
            Dictionary<string, DataRow> FileWithNids = new Dictionary<string, DataRow>();

            DIConnection SourceDBConnection = null;
            DIQueries SourceDBQueries = null;
            DI6SubgroupBuilder SrcSGBuilder=null;

            //-- Step 1: Get TempTable with Sorted SourceFileName
            Table = this._TargetDBConnection.ExecuteDataTable(this.ImportQueries.GetImportSubgroupDimensionValues(selectedNids));

            //-- Step 2:Initialise DI6SubgroupBuilder Builder with Target DBConnection
            SGBuilderObj = new DI6SubgroupBuilder(this.TargetDBConnection, this.TargetDBQueries);

            // Initialize progress bar
            this.RaiseProgressBarInitialize(selectedNids.Split(',').GetUpperBound(0) + 1);

            //-- Step 3: Import Nids for each SourceFile
            foreach (DataRow Row in Table.Copy().Rows)
            {
                try
                {
                    string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]);

                    SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword);
                    SourceDBQueries = DataExchange.GetDBQueries(SourceDBConnection);

                    // get subgroup info
                    SrcSGBuilder = new DI6SubgroupBuilder(SourceDBConnection, SourceDBQueries);
                    SGInfoObj= SrcSGBuilder.GetSubgroupInfo(FilterFieldType.NId,Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]));

                    SGBuilderObj.ImportSubgroup(SGInfoObj, Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]), SourceDBQueries, SourceDBConnection);

                    ProgressCounter += 1;
                    this.RaiseProgressBarIncrement(ProgressCounter);

                }
                catch (Exception ex) { ExceptionFacade.ThrowException(ex); }
                finally
                {
                    if (SourceDBConnection != null)
                        SourceDBConnection.Dispose();
                    if (SourceDBQueries != null)
                        SourceDBQueries.Dispose();
                }
            }
            this._AvailableTable = this.GetAvailableTable();
            this._UnmatchedTable = this.GetUnmatchedTable();
            // Close ProgressBar
            this.RaiseProgressBarClose();
        }
        /// <summary>
        /// Process Matched Target Subgroup Dimension Values
        /// </summary>
        public void ProcessSubgroupDimensionValues()
        {
            DataTable Table = null;

            DI6SubgroupBuilder SGBuilderObj = null;
            DI6SubgroupInfo SourceSGInfoObj = null;
            Dictionary<string, DataRow> FileWithNids = new Dictionary<string, DataRow>();

            DIConnection SourceDBConnection = null;
            DIQueries SourceDBQueries = null;
            DI6SubgroupBuilder SourceSGBuilder = null;

            //-- Step 1: Get TempTable with Sorted SourceFileName
            Table = this.DBConnection.ExecuteDataTable(this.TemplateQueries.GetMatchedSubgroupDimValues());

            //-- Step 2:Initialise Indicator Builder with Target DBConnection
            SGBuilderObj = new DI6SubgroupBuilder(this.DBConnection, this.DBQueries);

            //-- Step 3: Import Nids for each SourceFile
            foreach (DataRow Row in Table.Copy().Rows)
            {
                try
                {
                    string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]);

                    SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword);
                    SourceDBQueries = DataExchange.GetDBQueries(SourceDBConnection);

                    // get subgroup info from source
                    SourceSGBuilder = new DI6SubgroupBuilder(SourceDBConnection, SourceDBQueries);
                    SourceSGInfoObj = SourceSGBuilder.GetSubgroupInfo(FilterFieldType.NId, Convert.ToString(Row[Subgroup.SubgroupNId]));

                    //import subgroup
                    SGBuilderObj.ImportSubgroup(SourceSGInfoObj, Convert.ToInt32(Row[Subgroup.SubgroupNId]), SourceDBQueries, SourceDBConnection);

                }
                catch (Exception ex) { ExceptionFacade.ThrowException(ex); }
                finally
                {
                    if (SourceDBConnection != null)
                        SourceDBConnection.Dispose();
                    if (SourceDBQueries != null)
                        SourceDBQueries.Dispose();
                }
            }
        }