Ejemplo n.º 1
0
        private DataTable GetICTableWLevel(ref System.Data.DataTable table)
        {
            DataTable RetVal;
            DataRow   NewRow;

            DataRow[] Rows;
            int       Level = 0;

            table.Constraints.Clear();
            //- Allow db null
            table.Columns[IndicatorClassifications.ICType].AllowDBNull = true;

            //Step 1: Set indicator classification levels
            table.Columns.Add(LanguageKeys.Level, System.Type.GetType("System.Int32"));
            this.SetIndicatorClassificationLevel(table, -1, 0);

            //Step 2: Get maximum level from table
            table.DefaultView.Sort = LanguageKeys.Level + " DESC";
            if (table.Rows.Count > 0)
            {
                this.MaxLevel = Convert.ToInt32(table.DefaultView.ToTable().Rows[0][LanguageKeys.Level]);
            }
            else
            {
                this.MaxLevel = 1;
            }

            //Step 2: Create New Data Table to fill the list view
            RetVal = table.Clone();

            //insert columns for classification level info.
            for (Level = 1; Level <= this.MaxLevel; Level++)
            {
                RetVal.Columns.Add(LanguageKeys.Level + " " + Level);
            }

            //insert rows into new table
            foreach (DataRow Row in table.Rows)
            {
                Rows = RetVal.Select(IndicatorClassifications.ICNId + " =" + Row[IndicatorClassifications.ICParent_NId].ToString());

                NewRow = RetVal.NewRow();
                NewRow[IndicatorClassifications.ICNId]        = Row[IndicatorClassifications.ICNId];
                NewRow[IndicatorClassifications.ICParent_NId] = Row[IndicatorClassifications.ICParent_NId];
                NewRow[IndicatorClassifications.ICName]       = Row[IndicatorClassifications.ICName].ToString();
                NewRow[IndicatorClassifications.ICGlobal]     = Row[IndicatorClassifications.ICGlobal];
                NewRow[IndicatorClassifications.ICInfo]       = Row[IndicatorClassifications.ICInfo];
                NewRow[IndicatorClassifications.ICGId]        = Row[IndicatorClassifications.ICGId];

                NewRow[LanguageKeys.Level] = Row[LanguageKeys.Level];
                NewRow[LanguageKeys.Level + " " + Convert.ToInt32(Row[LanguageKeys.Level])] = Row[IndicatorClassifications.ICName].ToString();
                RetVal.Rows.Add(NewRow);
            }

            RetVal.AcceptChanges();
            this.SetIndicatorClassificationLevelName(RetVal);
            RetVal.DefaultView.Sort = IndicatorClassifications.ICNId;

            return(RetVal);
        }
Ejemplo n.º 2
0
        //private void DeleteExtraRows(DataTable table)
        //{
        //    int IndicatorNid = 0;
        //    int UnitNid = 0;
        //    int SubgroupValNid = 0;
        //    int ICNid = 0;
        //    string FilterString = string.Empty;
        //    string LevelColumnName = string.Empty;

        //    List<ExtaRowInfo> ExtraRows = new List<ExtaRowInfo>();
        //    try
        //    {
        //        for (int Level = 1; Level < this.MaxLevel; Level++)
        //        {
        //            DataRow[] Rows = table.Select(Constants.LanguageKeys.Level + "=" + Level);

        //            // Get records where level is equal to 1
        //            foreach (DataRow Row in Rows)
        //            {
        //                ICNid = Convert.ToInt32(Row[IndicatorClassifications.ICNId]);
        //                IndicatorNid = Convert.ToInt32(Row[Indicator.IndicatorNId]);

        //                //create filterstring
        //                FilterString = string.Empty;
        //                for (int i = 1; i <= Level; i++)
        //                {
        //                    LevelColumnName = Constants.LanguageKeys.Level + " " + i;
        //                    FilterString += "[" + LevelColumnName + "]='" + Row[LevelColumnName].ToString() + "' And ";
        //                }


        //                FilterString += " " + Indicator.IndicatorNId + "=" + IndicatorNid;


        //                if (this._ShowIUS)
        //                {
        //                    UnitNid = Convert.ToInt32(Row[Unit.UnitNId]);
        //                    SubgroupValNid = Convert.ToInt32(Row[SubgroupVals.SubgroupValNId]);

        //                    FilterString += " and " + Unit.UnitNId + "=" + UnitNid;
        //                    FilterString += " and " + SubgroupVals.SubgroupValNId + "=" + SubgroupValNid;
        //                }



        //                //delete row if this is not the lowest IC level for the current IUS
        //                if (table.Select(FilterString).Length > 1)
        //                {
        //                    //ExtraRows.Add(new ExtaRowInfo(ICNid, IndicatorNid, UnitNid, SubgroupValNid));
        //                    Row.Delete();
        //                    table.AcceptChanges();
        //                }

        //            }

        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new ApplicationException(ex.ToString());
        //    }
        //}


        private DataTable DeleteExtraRows(DataTable table)
        {
            DataTable RetVal;
            int       IndicatorNid    = 0;
            int       UnitNid         = 0;
            int       SubgroupValNid  = 0;
            int       ICNid           = 0;
            string    FilterString    = string.Empty;
            string    LevelColumnName = string.Empty;

            try
            {
                RetVal = table.Clone();
                DataRow NewRow;

                for (int Level = this.MaxLevel; Level > 0; Level--)
                {
                    DataRow[] Rows = table.Select(Constants.LanguageKeys.Level + "=" + Level);

                    // Get records by level
                    foreach (DataRow Row in Rows)
                    {
                        IndicatorNid = Convert.ToInt32(Row[Indicator.IndicatorNId]);


                        LevelColumnName = Constants.LanguageKeys.Level + " " + Level;
                        FilterString    = "[" + LevelColumnName + "]='" + DICommon.RemoveQuotes(Row[LevelColumnName].ToString()) + "' And ";
                        FilterString   += " " + Indicator.IndicatorNId + "=" + IndicatorNid;

                        if (this._ShowIUS)
                        {
                            UnitNid        = Convert.ToInt32(Row[Unit.UnitNId]);
                            SubgroupValNid = Convert.ToInt32(Row[SubgroupVals.SubgroupValNId]);

                            FilterString += " and " + Unit.UnitNId + "=" + UnitNid;
                            FilterString += " and " + SubgroupVals.SubgroupValNId + "=" + SubgroupValNid;
                        }

                        if (RetVal.Select(FilterString).Length == 0)
                        {
                            RetVal.Rows.Add(Row.ItemArray);
                        }
                    }
                }
                RetVal.AcceptChanges();
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }

            return(RetVal);
        }