Esempio n. 1
0
        public override void Import(string selectedNids)
        {
            DataTable   Table           = null;
            int         ProgressCounter = 0;
            AreaBuilder AreaBuilderObj  = null;
            AreaInfo    AreaInfoObj     = 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.GetImportAreas(this._CurrentTemplateFileNameWPath,selectedNids));

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

            ////-- Step 3: Import Nids for each SourceFile
            //foreach (DataRow Row in Table.Copy().Rows)
            //{
            try
            {
                SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, this._CurrentTemplateFileNameWPath, String.Empty, MergetTemplateConstants.DBPassword);
                SourceDBQueries    = DataExchange.GetDBQueries(SourceDBConnection);

                // AreaInfoObj = this.GetIndicatorInfo(Row);

                //AreaBuilderObj.ImportArea(selectedNids, 1, SourceDBConnection, SourceDBQueries);
                //AreaBuilderObj.ImportAreaMaps(selectedNids, 1, SourceDBConnection, SourceDBQueries);

                AreaBuilderObj.ImportArea(selectedNids, DICommon.SplitString(selectedNids, ",").Length, SourceDBConnection, SourceDBQueries, true);
                ProgressCounter += 1;
                this.RaiseProgressBarIncrement(ProgressCounter);
            }
            catch (Exception ex) { ExceptionFacade.ThrowException(ex); }
            finally
            {
                if (SourceDBConnection != null)
                {
                    SourceDBConnection.Dispose();
                }
                if (SourceDBQueries != null)
                {
                    SourceDBQueries.Dispose();
                }
            }
            //}
            this._UnmatchedTable = this.GetUnmatchedTable();
            this._AvailableTable = this.GetAvailableTable();
            // Close ProgressBar
            this.RaiseProgressBarClose();
        }
Esempio n. 2
0
        private void IntializeSubgroupVal(ref string[] sgRow, bool exactMatch)
        {
            string[] SubgroupNids = new string[0];
            for (int Index = 0; Index < this.SelectedSubgroups.Count; Index++)
            {
                sgRow[Index] = "0";

                SubgroupNids = DICommon.SplitString(this.SelectedSubgroups[Index].ToString(), ",");
                this.SelectedNIds.Add(SubgroupNids[0]);
            }

            this.GetCommaSepratedSubgroupNids(exactMatch);
        }
Esempio n. 3
0
        /// <summary>
        /// Updates denominator table
        /// </summary>
        /// <param name="denominatorColIndex"></param>
        /// <param name="appliedColIndexes"></param>
        public void UpdateDenominatorTable(int denominatorColIndex, string appliedColIndexes)
        {
            DataRow   NewRow;
            DataTable TempTable;
            String    TempAppliedColIndex = string.Empty;

            // update denominator column info
            if (this._DenominatorTable != null)
            {
                // delete already mapped row where denominator column is equal to denominator column index
                foreach (DataRow Row in this._DenominatorTable.Select(DenominatorColumns.DenominatorColumn + " = '" + denominatorColIndex.ToString() + "'"))
                {
                    Row.Delete();
                }

                // delete already mapped row where denominator column is equal to applied column indexes
                foreach (string appliedColIndex in DICommon.SplitString(appliedColIndexes, ","))
                {
                    if (TempAppliedColIndex.Length > 0)
                    {
                        TempAppliedColIndex += ",";
                    }
                    TempAppliedColIndex = "'" + appliedColIndex + "'";
                }

                foreach (DataRow Row1 in this._DenominatorTable.Select(DenominatorColumns.DenominatorColumn + " IN ( " + TempAppliedColIndex + ")"))
                {
                    Row1.Delete();
                }

                // delete already mapped row where applied column is equal to denominator column
                foreach (DataRow Row2 in this._DenominatorTable.Select(DenominatorColumns.AppliedColumn + " = '" + denominatorColIndex + "'"))
                {
                    Row2.Delete();
                }


                // add denominator column index and applied columns indexes
                foreach (string appliedColIndex in DICommon.SplitString(appliedColIndexes, ","))
                {
                    NewRow = this._DenominatorTable.NewRow();
                    NewRow[DenominatorColumns.DenominatorColumn] = denominatorColIndex.ToString();
                    NewRow[DenominatorColumns.AppliedColumn]     = appliedColIndex;
                    this._DenominatorTable.Rows.Add(NewRow);
                }

                this._DenominatorTable.AcceptChanges();
            }
        }
Esempio n. 4
0
        private void GetSubgroupValsFromNIds(string[] sgRow, int startColIndex, int endRowIndex, int endColIndex, bool exactMatch)
        {
            string[] SubgroupNids = new string[0];
            int      RowIndex     = 0;

            if (this.SelectedSubgroups.Count > 1)
            {
                for (int SGTypeIndex = 0; SGTypeIndex < SelectedSubgroups.Count; SGTypeIndex++)
                {
                    //-- Increase the end column index so that it can reach to the end of the selected row.
                    SubgroupNids = DICommon.SplitString(this.SelectedSubgroups[endRowIndex].ToString(), ",");
                    if (SGTypeIndex + 1 < SelectedSubgroups.Count && endColIndex < SubgroupNids.Length - 1)
                    {
                        endColIndex                   += 1;
                        sgRow[endRowIndex]             = endColIndex.ToString();
                        this.SelectedNIds[endRowIndex] = SubgroupNids[endColIndex];
                        this.GetCommaSepratedSubgroupNids(exactMatch);
                    }
                    else if (endColIndex == SubgroupNids.Length - 1)
                    {
                        RowIndex = this.GetEndColumnIndex(ref sgRow, exactMatch);
                        if (RowIndex == -1)
                        {
                            break;
                        }
                        else
                        {
                            endColIndex = 0;
                        }
                    }
                    this.GetSubgroupValsFromNIds(sgRow, startColIndex, endRowIndex, endColIndex, exactMatch);
                }
            }
            else
            {
                if (this.SelectedSubgroups.Count > 0)
                {
                    SubgroupNids = DICommon.SplitString(this.SelectedSubgroups[0].ToString(), ",");
                    for (int Index = 1; Index < SubgroupNids.Length; Index++)
                    {
                        this.SelectedNIds.Clear();
                        this.SelectedNIds.Add(SubgroupNids[Index]);
                        this.GetCommaSepratedSubgroupNids(exactMatch);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Get the IUSNIds on the basis of IUNId
        /// </summary>
        /// <param name="iuNIds"></param>
        /// <returns></returns>
        public override List <string> GetIUSNIds(string iuNIds, bool checkUserSelection, bool selectSingleTon)
        {
            List <string> RetVal = new List <string>();

            try
            {
                IDataReader IUSReader;
                string[]    IUNId = new string[0];
                string      UserSelectionIUSNIds = this._UserPrefences.UserSelection.IndicatorNIds;
                bool        IUSFound             = false;

                UserSelectionIUSNIds  = UserSelectionIUSNIds.Insert(0, ",");
                UserSelectionIUSNIds += ",";

                IUNId     = DICommon.SplitString(iuNIds, ",");
                IUSReader = this._DBConnection.ExecuteReader(this.SqlQueries.IUS.GetIUSNIdByI_U_S(IUNId[0], IUNId[1], string.Empty));

                while (IUSReader.Read())
                {
                    if (checkUserSelection && UserSelectionIUSNIds.Contains("," + IUSReader[Indicator_Unit_Subgroup.IUSNId].ToString() + ","))
                    {
                        IUSFound = true;
                        break;
                    }
                    RetVal.Add(IUSReader[Indicator_Unit_Subgroup.IUSNId].ToString());
                }
                IUSReader.Close();

                if (IUSFound)
                {
                    RetVal.Clear();
                }
            }
            catch (Exception)
            {
            }
            return(RetVal);
        }
Esempio n. 6
0
        /// <summary>
        /// Get the row against which next subgroup nid is used to generate the subgroupVal.
        /// </summary>
        /// <param name="sgRow"></param>
        /// <param name="endRowIndex"></param>
        /// <param name="endColIndex"></param>
        /// <returns></returns>
        private int GetEndColumnIndex(ref string[] sgRow, bool exactMatch)
        {
            int RetVal = -1;

            try
            {
                string[] SubgroupNids = new string[0];
                for (int Index = this.SelectedSubgroups.Count - 2; Index >= 0; Index--)
                {
                    SubgroupNids = DICommon.SplitString(this.SelectedSubgroups[Index].ToString(), ",");

                    //-- Check if the dimension contains unused subgroupNIds
                    if (Convert.ToInt32(sgRow[Index]) < SubgroupNids.Length - 1)
                    {
                        sgRow[Index]             = Convert.ToString(Convert.ToInt32(sgRow[Index]) + 1);
                        this.SelectedNIds[Index] = SubgroupNids[Convert.ToInt32(sgRow[Index])];

                        RetVal = this.SelectedSubgroups.Count - 1;
                        for (int NIndex = Index + 1; NIndex < this.SelectedSubgroups.Count; NIndex++)
                        {
                            sgRow[NIndex] = "0";

                            SubgroupNids = DICommon.SplitString(this.SelectedSubgroups[NIndex].ToString(), ",");
                            this.SelectedNIds[NIndex] = SubgroupNids[0];

                            this.GetCommaSepratedSubgroupNids(exactMatch);
                        }
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }
            return(RetVal);
        }
Esempio n. 7
0
        /// <summary>
        /// Get all combinations of IUSNIds for the indicator and unit NId
        /// </summary>
        /// <param name="subgroupNIds"></param>
        /// <param name="indicatorNId"></param>
        /// <param name="unitNId"></param>
        /// <param name="showCombinations"></param>
        /// <returns></returns>
        public string GetIUSNIdCombinations(OrderedDictionary subgroupNIds, int indicatorNId, int unitNId, bool showCombinations, bool dataExists)
        {
            string RetVal = string.Empty;

            try
            {
                this._SelectedSubgroupVal = new Dictionary <int, string>();
                this._TrimedSubgroupVal   = string.Empty;
                DataView    dvIUS;
                DataTable   IUSTable;
                DataTable   SubgroupTable;
                IDataReader SubgroupValReader;
                DataRow[]   Rows                     = new DataRow[0];
                string      SubgroupVal              = string.Empty;
                string[]    SelSubgroupNIds          = new string[0];
                string      SelectedSubgroupNIds     = string.Empty;
                string      SubgroupValNIds          = string.Empty;
                string      TempSelectedSubgroupNIds = string.Empty;
                bool        Found                    = false;

                this.SelectedSubgroups = subgroupNIds;

                if (!dataExists || (string.IsNullOrEmpty(this.UserPreference.UserSelection.AreaNIds) && string.IsNullOrEmpty(this.UserPreference.UserSelection.TimePeriodNIds) && string.IsNullOrEmpty(this.UserPreference.UserSelection.SourceNIds)))
                {
                    //-- Get the IUSNIDs
                    dtIUS = this.DbConnection.ExecuteDataTable(this.DbQueries.IUS.GetIUS(FilterFieldType.None, "", FieldSelection.Light));

                    dvIUS                  = this.dtIUS.DefaultView;
                    dvIUS.RowFilter        = Indicator.IndicatorNId + " = " + indicatorNId + " AND " + Unit.UnitNId + " = " + unitNId;
                    this.dtIUS             = dvIUS.ToTable();
                    this._SubgroupValCount = dtIUS.Rows.Count;
                }
                else
                {
                    dtIUS                  = this.DbConnection.ExecuteDataTable(this.DbQueries.IUS.GetIUS(indicatorNId.ToString(), unitNId.ToString(), this.UserPreference.UserSelection.AreaNIds, this.UserPreference.UserSelection.TimePeriodNIds, this.UserPreference.UserSelection.SourceNIds));
                    SubgroupTable          = this.DbConnection.ExecuteDataTable(this.DbQueries.IUS.GetSubgroupValByIU(indicatorNId, unitNId));
                    this._SubgroupValCount = SubgroupTable.Rows.Count;
                }


                if (dataExists)
                {
                    dvIUS           = this.dtIUS.DefaultView;
                    dvIUS.RowFilter = Indicator_Unit_Subgroup.DataExist + " = true";
                    this.dtIUS      = dvIUS.ToTable();
                }

                //-- Get the selected subgroupNIds
                for (int Index = 0; Index < subgroupNIds.Count; Index++)
                {
                    if (!string.IsNullOrEmpty(SelectedSubgroupNIds))
                    {
                        SelectedSubgroupNIds += ",";
                    }
                    SelectedSubgroupNIds += subgroupNIds[Index].ToString();
                }

                if (!string.IsNullOrEmpty(SelectedSubgroupNIds))
                {
                    if (showCombinations)
                    {
                        //-- Get the combinations of SubgroupVals of the selected subgroupNIds
                        SubgroupValReader = this.DbConnection.ExecuteReader(this.DbQueries.SubgroupValSubgroup.GetSubgroupValsSubgroup(string.Empty, SelectedSubgroupNIds, true));
                        while (SubgroupValReader.Read())
                        {
                            Found                    = false;
                            SelSubgroupNIds          = DICommon.SplitString(SubgroupValReader[Indicator_Unit_Subgroup.SubgroupNids].ToString(), ",");
                            TempSelectedSubgroupNIds = "," + SelectedSubgroupNIds + ",";
                            foreach (string SelSubgroupNId in SelSubgroupNIds)
                            {
                                if (TempSelectedSubgroupNIds.Contains("," + SelSubgroupNId + ","))
                                {
                                    Found = true;
                                }
                                else
                                {
                                    Found = false;
                                    break;
                                }
                            }

                            if (Found)
                            {
                                SubgroupValNIds += "," + SubgroupValReader[SubgroupVals.SubgroupValNId].ToString();
                            }
                        }
                        if (!string.IsNullOrEmpty(SubgroupValNIds))
                        {
                            SubgroupValNIds = SubgroupValNIds.Substring(1);
                        }
                        SubgroupValReader.Close();
                    }
                    else
                    {
                        IUSTable = this.DbConnection.ExecuteDataTable(this.DbQueries.IUS.GetIUSNIdByI_U_SubgroupNIds(indicatorNId.ToString(), unitNId.ToString(), SelectedSubgroupNIds));
                        //-- Get the subgroup val of the selected subgroupNIds only
                        SelSubgroupNIds = DICommon.SplitString(SelectedSubgroupNIds, ",");

                        foreach (string SelSubgroupNId in SelSubgroupNIds)
                        {
                            Rows = IUSTable.Select(Subgroup.SubgroupNId + " = " + SelSubgroupNId + " AND " + Indicator_Unit_Subgroup.DataExist + " = true");
                            if (Rows.Length > 0)
                            {
                                foreach (DataRow Row in Rows)
                                {
                                    if (DICommon.SplitString(Row[Indicator_Unit_Subgroup.SubgroupNids].ToString(), ",").Length == 1)
                                    {
                                        SubgroupValNIds += "," + Row[SubgroupVals.SubgroupValNId].ToString();
                                        break;
                                    }
                                }
                            }
                        }


                        if (!string.IsNullOrEmpty(SubgroupValNIds))
                        {
                            SubgroupValNIds = SubgroupValNIds.Substring(1);
                        }
                    }
                }

                //-- Get the subgroupVals
                if (!string.IsNullOrEmpty(SubgroupValNIds))
                {
                    Rows = dtIUS.Select(SubgroupVals.SubgroupValNId + " IN (" + SubgroupValNIds + ")");
                    this._SelectedSubgroupValCount = Rows.Length;

                    IUSTable = new DataTable();
                    IUSTable = this.dtIUS.Clone();
                    foreach (DataRow Row in Rows)
                    {
                        IUSTable.ImportRow(Row);
                    }

                    dvIUS      = IUSTable.DefaultView;
                    dvIUS.Sort = SubgroupVals.SubgroupValOrder;
                    IUSTable   = dvIUS.ToTable();

                    foreach (DataRow Row in IUSTable.Rows)
                    {
                        RetVal += "," + Row[Indicator_Unit_Subgroup.IUSNId].ToString();
                        this._TrimedSubgroupVal += "," + Row[SubgroupVals.SubgroupVal].ToString();
                        this._SelectedSubgroupVal.Add(Convert.ToInt32(Row[SubgroupVals.SubgroupValNId].ToString()), Row[SubgroupVals.SubgroupVal].ToString());
                    }
                }

                if (!string.IsNullOrEmpty(RetVal))
                {
                    RetVal = RetVal.Substring(1);
                    this._TrimedSubgroupVal = this._TrimedSubgroupVal.Substring(1);
                    if (this._TrimedSubgroupVal.Length > SubgroupValLength)
                    {
                        this._TrimedSubgroupVal = this._TrimedSubgroupVal.Substring(0, SubgroupValLength - 3) + "...";
                    }
                }
                else
                {
                    this._SelectedSubgroupValCount = 0;
                    RetVal = "-1";
                }
            }
            catch (Exception)
            {
            }
            return(RetVal);
        }
Esempio n. 8
0
        private static void ImportMapping(string MappedValueString, string MappedTypeString, Mapping elementMapping)
        {
            string Value = string.Empty;
            string GID   = string.Empty;

            string[] MappedValues;
            string[] MappedTypes;
            string[] ElementValue;


            if (!string.IsNullOrEmpty(MappedValueString) && !string.IsNullOrEmpty(MappedTypeString))
            {
                MappedTypes  = DICommon.SplitString(MappedTypeString, "\r\n");
                MappedValues = DICommon.SplitString(MappedValueString, "\r\n");

                for (int i = 0; i < MappedTypes.Length; i++)
                {
                    // only if value exists
                    if (!string.IsNullOrEmpty(MappedTypes[i]) && !string.IsNullOrEmpty(MappedValues[i]))
                    {
                        ElementValue = DICommon.SplitString(MappedValues[i], "||");

                        // only if element value have value and GID
                        if (ElementValue.Length == 2)
                        {
                            Value = Convert.ToString(ElementValue[0]);
                            GID   = Convert.ToString(ElementValue[1]);

                            switch (MappedTypes[i].ToUpper())
                            {
                            case "INDICATOR":
                                elementMapping.IndicatorName = Value;
                                elementMapping.IndicatorGID  = GID;
                                break;

                            case "UNIT":
                                elementMapping.UnitName = Value;
                                elementMapping.UnitGID  = GID;
                                break;

                            case "SUBGROUP":
                                elementMapping.SubgroupVal    = Value;
                                elementMapping.SubgroupValGID = GID;
                                break;

                            case "AREA":
                                elementMapping.Area   = Value;
                                elementMapping.AreaID = GID;
                                break;

                            case "SOURCE":
                                elementMapping.Source = Value;
                                break;

                            case "TIMEPERIOD":
                                elementMapping.Timeperiod = Value;
                                break;

                            case "AGE":
                            case "SEX":
                            case "LOCATION":
                            case "OTHERS":
                                if (elementMapping.Subgroups.ContainsKey(GID) == false)
                                {
                                    DevInfo.Lib.DI_LibBAL.DA.DML.DI6SubgroupInfo SG = new DevInfo.Lib.DI_LibBAL.DA.DML.DI6SubgroupInfo();
                                    SG.Name = Value;
                                    SG.GID  = GID;
                                    elementMapping.Subgroups.Add(GID, SG);
                                }

                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
        }