Example #1
0
        private void CalcDotDensity(DataView p_ThemeData, ref Theme p_Theme)
        {
            //*** Bugfix Feb 2006 Improper Dot Value logic

            decimal MinVal = 0;
            decimal MaxVal = 0;
            decimal DotValue;

            //*** Get Min and Max datavalues for current dataview
            //GetMinMaxDataValue(ref p_ThemeData, ref MinVal, ref MaxVal);
            p_ThemeData.Sort = DataExpressionColumns.DataType + " ASC," + DataExpressionColumns.NumericData + " ASC";
            MinVal = (decimal)p_ThemeData[0][DataExpressionColumns.NumericData];
            MaxVal = (decimal)p_ThemeData[p_ThemeData.Count - 1][DataExpressionColumns.NumericData];

            //*** Set the DotValues
            if (MaxVal > 0 & MaxVal < 1)
            {
                //For cases like Index datavalues
                DotValue = MinVal;
            }
            else if (MaxVal < 100)
            {
                //*** For cases like ALR where datavalues are less than 100
                DotValue = 1;
            }
            else
            {
                //-- Bug fix: When minValue = 0 and Max value > 100 , then max / min became infinity.
                if (MaxVal > 100 && MinVal == 0)
                {
                    MinVal = 1;
                }

                //*** For cases like population size where data values can be in lakhs
                if (MaxVal / MinVal > 500)
                {
                    //*** too much variation
                    DotValue = MaxVal / 500;
                }
                else
                {
                    DotValue = MinVal;
                }
            }

            p_Theme.Maximum = MaxVal;
            if (DotValue < 1)
            {
                p_Theme.DotValue = (double)Math.Round(DotValue, 2);
            }
            else if (DotValue < 10)
            {
                p_Theme.DotValue = (double)Math.Round(DotValue, 1);

            }
            else
            {
                p_Theme.DotValue = (double)Math.Round(DotValue, 0);
            }

            //object[] oMDKeys = new object[MDKeys.Keys.Count];
            //MDKeys.Keys.CopyTo(oMDKeys, 0);
            object[] oMDKeys = this.MDColumns;
            {
                foreach (DataRowView _DRV in p_ThemeData)
                {
                    if (!p_Theme.AreaIndexes.ContainsKey((string)_DRV[Area.AreaID]))            //"Area_ID"
                    {
                        AreaInfo _AreaInfo = new AreaInfo();
                        {
                            _AreaInfo.IndicatorGID = (string)_DRV[Indicator.IndicatorGId];      //"Indicator_GId"
                            _AreaInfo.UnitGID = (string)_DRV[Unit.UnitGId];                     //"Unit_GId"
                            _AreaInfo.SubgroupGID = (string)_DRV[SubgroupVals.SubgroupValGId];  //"Subgroup_Val_GId"
                            _AreaInfo.Subgroup = (string)_DRV[SubgroupVals.SubgroupVal];        //"Subgroup_Val"
                            _AreaInfo.Time = (string)_DRV[Timeperiods.TimePeriod];              //"TimePeriod"
                            _AreaInfo.AreaName = (string)_DRV[Area.AreaName];                   //"Area_Name"
                            _AreaInfo.Source = (string)_DRV[IndicatorClassifications.ICName];   //"IC_Name"

                            //*** Metadata
                            _AreaInfo.MDFldVal = new Hashtable();
                            for (int i = 0; i <= oMDKeys.Length - 1; i++)
                            {
                                if (p_ThemeData.Table.Columns.Contains(oMDKeys[i].ToString()))
                                {
                                    _AreaInfo.MDFldVal.Add(oMDKeys[i], _DRV[(string)oMDKeys[i]]);
                                }
                            }

                            _AreaInfo.DataValue = (decimal)Conversion.Val(_DRV[DataExpressionColumns.NumericData]); //"Data_Value"

                            //DisplayInfo stores textual DataValue (e.g. yes, no) and will be used as part map label
                            _AreaInfo.DisplayInfo = Convert.ToString(_DRV[Data.DataValue]);
                        }
                        //.RenderingInfo = CInt(Val(_DRV("Data_Value")) * DotValue / MaxVal)
                        p_Theme.AreaIndexes.Add((string)_DRV[Area.AreaID], _AreaInfo);      //"Area_ID"
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Build AreaInfo Collection (AreaId - AreaInfo (DataValue,...))
        /// </summary>
        private void SetDataForBreak()
        {
            m_AreaIndexDT = new DataTable();
            m_AreaIndexDT.Locale = new System.Globalization.CultureInfo("", false);
            DataColumn[] _PK = new DataColumn[1];
            {
                {
                    m_AreaIndexDT.Columns.Add(Area.AreaID, typeof(string)).Unique = true;
                    m_AreaIndexDT.Columns.Add(DataExpressionColumns.NumericData, typeof(decimal));
                    _PK[0] = m_AreaIndexDT.Columns[Area.AreaID];

                }
                m_AreaIndexDT.PrimaryKey = _PK;
            }
            int _MaxLengthFound = 0;   // Defalut Value assigned as 0, because C# compliler was not permitting use of unassigned local variable.
            int _Length;
            string[] _Value;

            foreach (DataRowView _DRV in m_ThemeData)
            {
                try
                {
                    AreaInfo _AreaInfo = new AreaInfo();
                    if (!m_AreaIndex.ContainsKey((string)_DRV[Area.AreaID]))
                    {
                        {
                            _AreaInfo.IndicatorGID = _DRV[Indicator.IndicatorGId].ToString();
                            _AreaInfo.UnitGID = _DRV[Unit.UnitGId].ToString();
                            _AreaInfo.SubgroupGID = _DRV[SubgroupVals.SubgroupValGId].ToString();
                            _AreaInfo.Subgroup = _DRV[SubgroupVals.SubgroupVal].ToString();
                            _AreaInfo.Time = _DRV[Timeperiods.TimePeriod].ToString();
                            _AreaInfo.AreaName = _DRV[Area.AreaName].ToString();
                            _AreaInfo.Source = _DRV[IndicatorClassifications.ICName].ToString();

                            //*** Metadata
                            _AreaInfo.MDFldVal = new Hashtable();

                            for (int i = 0; i <= m_MDKeys.Length - 1; i++)
                            {
                                if (m_ThemeData.Table.Columns.Contains(m_MDKeys[i].ToString()))
                                {
                                    _AreaInfo.MDFldVal.Add(m_MDKeys[i], _DRV[(string)m_MDKeys[i]].ToString());
                                }
                            }

                            if (FirstBuild)
                            {
                                _AreaInfo.DataValue = (decimal)_DRV[DataExpressionColumns.NumericData];
                            }
                            else
                            {
                                _AreaInfo.DataValue = (decimal)_DRV[DataExpressionColumns.NumericData];
                            }
                            _AreaInfo.RenderingInfo = _AreaInfo.DataValue;

                            //DisplayInfo stores textual DataValue (e.g. yes, no) and will be used as part map label
                            _AreaInfo.DisplayInfo = _DRV[Data.DataValue].ToString();

                            m_AreaIndexDT.Rows.Add(new object[] { _DRV[Area.AreaID].ToString(), _AreaInfo.DataValue });
                        }
                        m_AreaIndex.Add(_DRV[Area.AreaID].ToString(), _AreaInfo);
                    }
                    else
                    {
                        //*** Bugfix 24 Aug 2006 Loss of data on decimal precision change
                        _AreaInfo = (AreaInfo)m_AreaIndex[_DRV[Area.AreaID]];
                        if (FirstBuild)
                        {
                            _AreaInfo.DataValue = (decimal)_DRV[DataExpressionColumns.NumericData];

                        }
                        else
                        {
                            _AreaInfo.DataValue = (decimal)_DRV[DataExpressionColumns.NumericData];
                        }
                        //-- Bugfix 1913 2007-05-19 When Area record repeats upadte RenderingInfo and AreaIndexDT value also
                        _AreaInfo.RenderingInfo = _AreaInfo.DataValue;

                        //DisplayInfo stores textual DataValue (e.g. yes, no) and will be used as part map label
                        _AreaInfo.DisplayInfo = _DRV[Data.DataValue].ToString();

                        m_AreaIndex[_DRV[Area.AreaID]] = _AreaInfo;
                        if (m_AreaIndexDT != null & m_AreaIndexDT.Rows.Count > 0)
                        {
                            m_AreaIndexDT.Rows.Find((string)_DRV[Area.AreaID])[DataExpressionColumns.NumericData] = _AreaInfo.DataValue;
                        }

                    }
                    _Value = Strings.Split(_AreaInfo.DataValue.ToString(), System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator.ToString(), -1, CompareMethod.Text);
                    if (_Value.Length > 1)
                    {
                        _Length = _Value[1].Length;
                    }
                    else
                    {
                        _Length = 0;
                    }
                    if (_Length > _MaxLengthFound)
                        _MaxLengthFound = _Length;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            //*** Take the filtered records and sort them on Indicator_NId and Subgroup_Nid
            switch (m_ThemeType)
            {
                case ThemeType.Chart:
                    break;

                default:
                    if (m_AreaIndexDT.Rows.Count <= 0)
                    {
                        foreach (string _Key in m_AreaIndex.Keys)
                        {
                            if (!(m_AreaIndexDT.Select(Area.AreaID + " = '" + _Key + "'").Length > 0))
                            {
                                {
                                    if (FirstBuild)
                                    {
                                        m_AreaIndexDT.Rows.Add(new object[] { _Key, ((AreaInfo)m_AreaIndex[_Key]).DataValue });
                                    }
                                    else
                                    {
                                        m_AreaIndexDT.Rows.Add(new object[] { _Key, Math.Round(((AreaInfo)m_AreaIndex[_Key]).DataValue, m_Decimals, MidpointRounding.AwayFromZero) });
                                    }
                                }

                            }
                        }
                    }

                    break;
            }

            DataView _Dv = m_AreaIndexDT.DefaultView;
            _Dv.Sort = DataExpressionColumns.NumericData + " ASC";
            if (FirstBuild)
            {
                m_Decimals = _MaxLengthFound;
                if (_Dv.Count > 0)
                {
                    m_Minimum = (decimal)_Dv[0][DataExpressionColumns.NumericData];
                    m_Maximum = (decimal)_Dv[_Dv.Count - 1][DataExpressionColumns.NumericData];
                }
                FirstBuild = false;
            }
        }
Example #3
0
        private void MakeChartTheme(string[] p_indicator, string[] p_Subgroup, DataView p_ThemeData, Theme p_Theme)
        {
            string _Value = string.Empty;
            string ChartDataTimeKey = string.Empty; // Key represents TimePeriod.
            string _RowFilter = p_ThemeData.RowFilter;
            string _LocalFilter = "";
            string[] SubgroupArray = null;
            string ID = string.Empty;
            string[] ChartSeriesTypeNIDs = null;
            bool DataFoundForTimePeriod = false;
            string ChartMRD = string.Empty;

            //--IMP: some dataValue might have decimal,
            //--and in French Setting, decimals are treated as "," which was causing error while rendering ChartMap

            //-- Set Culture Info setting to US-English, and then reset original CultureSetting at the end.
            //-- Get the current culture.
            System.Globalization.CultureInfo OldCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            //-- Reset the culture to english - US
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            //-- set Chart Series NIds on the basis of Source(multiple Sources) OR Subgroup ( Multiple Subgroups)
            if (p_Theme.ChartSeriestype == ChartSeriesType.Source)
            {
                ChartSeriesTypeNIDs = p_Theme.SourceNIds;
            }
            else
            {
                ChartSeriesTypeNIDs = p_Subgroup;
            }

            //object[] oMDKeys = new object[MDKeys.Keys.Count];
            //MDKeys.Keys.CopyTo(oMDKeys, 0);

            object[] oMDKeys = this.MDColumns;
            {
                //p_Theme.ChartVisibleTimePeriods.Clear();
                p_Theme.ChartTimePeriods.Clear();

                foreach (DataRowView _DRV in p_ThemeData)
                {
                    if (!p_Theme.AreaIndexes.ContainsKey((string)_DRV[Area.AreaID]))
                    {
                        ID = (string)_DRV[Area.AreaID];
                        _Value = "";
                        ChartMRD = "";
                        AreaInfo _AreaInfo = new AreaInfo();
                        _AreaInfo.ChartData = new Hashtable();
                        {
                            _AreaInfo.IndicatorGID = (string)_DRV[Indicator.IndicatorGId];
                            _AreaInfo.SubgroupGID = (string)_DRV[SubgroupVals.SubgroupValGId];
                            _AreaInfo.UnitGID = (string)_DRV[Unit.UnitGId];
                            _AreaInfo.Subgroup = (string)_DRV[SubgroupVals.SubgroupVal];
                            _AreaInfo.Time = (string)_DRV[Timeperiods.TimePeriod];
                            _AreaInfo.AreaName = (string)_DRV[Area.AreaName];
                            _AreaInfo.Source = (string)_DRV[IndicatorClassifications.ICName];

                            //*** Metadata
                            _AreaInfo.MDFldVal = new Hashtable();
                            for (int i = 0; i <= oMDKeys.Length - 1; i++)
                            {
                                if (p_ThemeData.Table.Columns.Contains(oMDKeys[i].ToString()))
                                {
                                    _AreaInfo.MDFldVal.Add(oMDKeys[i], _DRV[(string)oMDKeys[i]]);
                                }
                            }

                            _AreaInfo.DataValue = (decimal)Conversion.Val(_DRV[DataExpressionColumns.NumericData]);
                            //.RenderingInfo = CInt(Val(_DRV("Data_Value")) * _Count / p_Theme.Maximum)

                            //-- Loop each timeperiod and Get Delimieted dataValue for multiple Source/Subgroup
                            foreach (DataRowView drow in this.GetTimePeriods())
                            {
                                _Value = "";
                                ChartDataTimeKey = string.Empty;
                                DataFoundForTimePeriod = false;
                                foreach (string _Ind in p_indicator)
                                {
                                    foreach (string _SP in ChartSeriesTypeNIDs)
                                    {
                                        //-- Apply RowFilter
                                        _LocalFilter = " Indicator_Nid=" + (string)_Ind + " AND Area_NId=" + _DRV["Area_NId"].ToString();

                                        //In Pie chart - Multiple Subgroups , No timePeriod, NO Sources
                                        if (p_Theme.ChartType == ChartType.Pie)
                                        {
                                            _LocalFilter += " AND Subgroup_Val_NId=" + (string)_SP;
                                        }
                                        else
                                        {
                                            //- In Bar/Line chart, timeSeries will be ON, with multiple Source/Subgroups.
                                            if (p_Theme.ChartSeriestype == ChartSeriesType.Source)
                                            {
                                                _LocalFilter += " AND Subgroup_Val_NId=" + (string)p_Subgroup[0];
                                                _LocalFilter += " AND " + IndicatorClassifications.ICNId + " = " + (string)_SP;
                                            }
                                            else if (p_Theme.ChartSeriestype == ChartSeriesType.Subgroup)
                                            {
                                                _LocalFilter += " AND Subgroup_Val_NId=" + (string)_SP;
                                            }
                                        }

                                        _LocalFilter += " AND " + Timeperiods.TimePeriod + " = '" + drow[Timeperiods.TimePeriod].ToString() + "'";

                                        if (_RowFilter.Length > 0)
                                        {
                                            p_ThemeData.RowFilter += " AND " + _LocalFilter;
                                        }
                                        else
                                        {
                                            p_ThemeData.RowFilter = _LocalFilter;
                                        }
                                        //-- Get chart Data
                                        if (_Value.Length > 0)
                                            _Value += ",";

                                        if (p_ThemeData.Count > 0)
                                        {
                                            DataFoundForTimePeriod = true;      // indicating that data is found for at least one Subgroup/Source
                                            _Value += (p_ThemeData[0][DataExpressionColumns.NumericData]).ToString();
                                            ChartDataTimeKey = p_ThemeData[0][Timeperiods.TimePeriod].ToString();

                                            //-Set TimePeriod visibilty true (default)
                                            if (p_Theme.ChartTimePeriods.Keys.Contains(ChartDataTimeKey) == false)
                                            {
                                                //p_Theme.ChartVisibleTimePeriods.Add(ChartDataTimeKey);
                                                p_Theme.ChartTimePeriods.Add(ChartDataTimeKey, true);
                                            }
                                        }
                                        else
                                        {
                                            if (ChartDataTimeKey.Length == 0)
                                            {
                                                ChartDataTimeKey = drow[Timeperiods.TimePeriod].ToString();
                                            }
                                            // then insert '{^}' so that Pie chart can sense the 0 value for given SubgroupVal
                                            _Value += "{^}";
                                        }

                                        p_ThemeData.RowFilter = _RowFilter;

                                    }
                                }

                                if (DataFoundForTimePeriod)
                                {
                                    _Value = _Value.Replace("{^}", "");

                                    //_AreaInfo.ChartData = _Value;
                                    _AreaInfo.ChartData.Add(ChartDataTimeKey, _Value);
                                }
                                ////if (p_Theme.ChartType == ChartType.Pie)
                                ////{
                                ////    break;  // Only one TimePeriod is needed.
                                ////}
                            }
                        }

                        //-- Get Most recent Data for IUS + Area + Souce
                        foreach (string _SGNId in ChartSeriesTypeNIDs)
                        {
                            if (p_Theme.ChartSeriestype == ChartSeriesType.Subgroup)
                            {
                                ChartMRD += "," + this.GetMRDForThemeArea(p_ThemeData, p_indicator[0], string.Empty, (string)_SGNId, _DRV[Area.AreaNId].ToString(), string.Empty);
                            }
                            else if (p_Theme.ChartSeriestype == ChartSeriesType.Source)
                            {
                                ChartMRD += "," + this.GetMRDForThemeArea(p_ThemeData, p_indicator[0], string.Empty, p_Subgroup[0], _DRV[Area.AreaNId].ToString(), (string)_SGNId);
                            }
                        }

                        _AreaInfo.ChartMostRecentData = ChartMRD.Substring(1);  //removing first comma
                        _AreaInfo.ChartMostRecentDataCopy = ChartMRD.Substring(1);

                        p_Theme.AreaIndexes.Add(ID, _AreaInfo);
                    }
                }
            }

            //-- Restore the culture.
            System.Threading.Thread.CurrentThread.CurrentCulture = OldCulture;
        }