PageRenderTime 57ms CodeModel.GetById 2ms app.highlight 46ms RepoModel.GetById 2ms app.codeStats 0ms

/Workarea/ContentRatingGraph.aspx.cs

https://github.com/eiursuajr/minGit
C# | 1065 lines | 947 code | 116 blank | 2 comment | 146 complexity | 482e9291f35693fe652d7a14e1aaf996 MD5 | raw file
   1using System.Web.UI.WebControls;
   2using System.Configuration;
   3using System.Collections;
   4using System.Linq;
   5using System.Data;
   6using System.Web.Caching;
   7using System.Xml.Linq;
   8using System.Web.UI;
   9using System.Diagnostics;
  10using System.Web.Security;
  11using System;
  12using System.Text;
  13using Microsoft.VisualBasic;
  14using System.Web.UI.HtmlControls;
  15using System.Web.SessionState;
  16using System.Text.RegularExpressions;
  17using System.Web.Profile;
  18using System.Collections.Generic;
  19using System.Web.UI.WebControls.WebParts;
  20using System.Collections.Specialized;
  21using System.Web;
  22using System.Drawing;
  23using System.Drawing.Drawing2D;
  24using System.Drawing.Imaging;
  25using System.Data.SqlClient;
  26using Ektron.Cms;
  27using System.IO;
  28
  29public partial class ContentRatingGraph : System.Web.UI.Page
  30{
  31    protected void Page_Load(object sender, EventArgs e)
  32    {
  33        WorkareaGraphBase graph;
  34
  35        string tmp = Request.QueryString["type"];
  36        if (tmp == "pie")
  37        {
  38            graph = new CircleGraph();
  39        }
  40        else if (tmp == "time")
  41        {
  42            graph = new TimeGraph();
  43        }
  44        else
  45        {
  46            graph = new BarGraph();
  47        }
  48
  49        graph.Init(this);
  50    }
  51}
  52
  53internal class TimeGraph : WorkareaGraphBase
  54{
  55    public TimeGraph()
  56    {
  57        _barBrush = new SolidBrush(Color.LightBlue);
  58        _barColor = Color.LightBlue;
  59        _bgBrush = new SolidBrush(Color.White);
  60        _bgColor = Color.White;
  61        _fontBrush = new SolidBrush(Color.Black);
  62        _fontColor = Color.Black;
  63
  64    }
  65    private int _height = 200;
  66    private int _width = 600;
  67    private int _bottomArea = 15;
  68    private float _percentageSpace = (float)(0.3F);
  69    private int _numBars = 24;
  70    private int _fontSize = 8;
  71    private int _clusterSize = 2;
  72    private SolidBrush _barBrush;
  73    private Color _barColor;
  74    private SolidBrush _bgBrush;
  75    private Color _bgColor;
  76    private SolidBrush _fontBrush;
  77    private Color _fontColor;
  78    private int[] weights;
  79    private float[] heights;
  80    private string CurrentView;
  81    private int Divisions = 8;
  82    private AnalyticsAPI Analytics = new Ektron.Cms.AnalyticsAPI();
  83    #region Properties
  84    private int FontSize
  85    {
  86        get
  87        {
  88            return _fontSize;
  89        }
  90    }
  91
  92    private int Height
  93    {
  94        get
  95        {
  96            return _height;
  97        }
  98        set
  99        {
 100            if (_height > 0)
 101            {
 102                _height = value;
 103            }
 104        }
 105    }
 106
 107    private int Width
 108    {
 109        get
 110        {
 111            return _width;
 112        }
 113        set
 114        {
 115            if (_width > 0)
 116            {
 117                _width = value;
 118            }
 119        }
 120    }
 121
 122    private float PercentageSpace
 123    {
 124        get
 125        {
 126            return _percentageSpace;
 127        }
 128        set
 129        {
 130            if (value >= 0 || value < 1)
 131            {
 132                _percentageSpace = value;
 133            }
 134        }
 135    }
 136
 137    private int NumBars
 138    {
 139        get
 140        {
 141            return _numBars;
 142        }
 143        set
 144        {
 145            if (value > 0)
 146            {
 147                _numBars = value;
 148            }
 149        }
 150    }
 151
 152    private int ClusterSize
 153    {
 154        get
 155        {
 156            return _clusterSize;
 157        }
 158        set
 159        {
 160            if (value > 0)
 161            {
 162                _clusterSize = value;
 163            }
 164        }
 165    }
 166
 167    private float BarWidth
 168    {
 169        get
 170        {
 171            return Width * (1 - PercentageSpace) / (NumBars * ClusterSize);
 172        }
 173    }
 174
 175    private float SpaceWidth
 176    {
 177        get
 178        {
 179            return Width * PercentageSpace / (NumBars * ClusterSize);
 180        }
 181    }
 182
 183    private int TextHeight
 184    {
 185        get
 186        {
 187            return _bottomArea;
 188        }
 189        set
 190        {
 191            _bottomArea = value;
 192        }
 193    }
 194
 195    private Color BarColor
 196    {
 197        get
 198        {
 199            return _barColor;
 200        }
 201        set
 202        {
 203            _barBrush = new SolidBrush(value);
 204        }
 205    }
 206
 207    private Color BGColor
 208    {
 209        get
 210        {
 211            return _bgColor;
 212        }
 213        set
 214        {
 215            _bgBrush = new SolidBrush(value);
 216        }
 217    }
 218
 219    private Color FontColor
 220    {
 221        get
 222        {
 223            return _fontColor;
 224        }
 225        set
 226        {
 227            _fontBrush = new SolidBrush(value);
 228        }
 229    }
 230    #endregion
 231
 232    protected bool CheckAccess()
 233    {
 234        ContentAPI contentApi = new ContentAPI();
 235		Utilities.ValidateUserLogin();
 236        if (contentApi.IsLoggedIn)
 237        {
 238            if ((!(Page.Request.QueryString["res_type"] == null)) && Page.Request.QueryString["res_type"].ToLower() == "content")
 239            {
 240
 241                long contentId = System.Convert.ToInt32(Page.Request.QueryString["res"]);
 242                ContentAPI.userPermissions permissions = contentApi.GetUserPermissionsForContent(contentId);
 243
 244                if (Ektron.Cms.Common.EkFunctions.GetBit((long)ContentAPI.userPermissions.View, (long)permissions))
 245                {
 246                    return true;
 247                }
 248                if (Ektron.Cms.Common.EkFunctions.GetBit((long)ContentAPI.userPermissions.Edit, (long)permissions))
 249                {
 250                    return true;
 251                }
 252            }
 253            else
 254            {
 255                return true; //this isn't content - return true.
 256            }
 257        }
 258
 259        return false;
 260    }
 261
 262    public override void Initialize()
 263    {
 264        try
 265        {
 266            CurrentView = Page.Request.QueryString["view"];
 267        }
 268        catch (Exception)
 269        {
 270            CurrentView = "day";
 271        }
 272        Height = 200;
 273        Width = 525;
 274        PercentageSpace = (float)(0.2F);
 275        NumBars = 24;
 276        ClusterSize = 2;
 277        weights = new int[NumBars * ClusterSize + 1];
 278        heights = new Single[NumBars * ClusterSize + 1];
 279        BarColor = Color.Blue;
 280
 281        if ((string)(CurrentView) == "day")
 282        {
 283            NumBars = 24;
 284            Divisions = 8;
 285        }
 286        else if ((string)(CurrentView) == "week")
 287        {
 288            NumBars = 7;
 289            Divisions = 7;
 290        }
 291        else if ((string)(CurrentView) == "month")
 292        {
 293            NumBars = 30;
 294            Divisions = 6;
 295        }
 296        else if ((string)(CurrentView) == "year")
 297        {
 298            NumBars = 12;
 299            Divisions = 12;
 300        }
 301
 302        if (!(Page.Request.QueryString["barColor"] == null))
 303        {
 304            try
 305            {
 306                BarColor = Color.FromName(Page.Request.QueryString["barColor"]);
 307            }
 308            catch
 309            {
 310
 311            }
 312        }
 313
 314        if (!(Page.Request.QueryString["fontColor"] == null))
 315        {
 316            try
 317            {
 318                FontColor = Color.FromName(Page.Request.QueryString["fontColor"]);
 319            }
 320            catch
 321            {
 322
 323            }
 324        }
 325    }
 326
 327    private string AddRestriction(string sqlStr)
 328    {
 329        string res_type = "";
 330        string res = "";
 331
 332        try
 333        {
 334            res_type = Page.Request.QueryString["res_type"];
 335        }
 336        catch (Exception)
 337        {
 338            res_type = "";
 339        }
 340
 341        try
 342        {
 343            res = Ektron.Cms.Common.EkFunctions.GetDbString(Page.Request.QueryString["res"], -1, true);
 344        }
 345        catch (Exception)
 346        {
 347            res = "";
 348        }
 349
 350        if (res_type == "content")
 351        {
 352            sqlStr += (string)(" AND content_id = " + int.Parse(res));
 353        }
 354        else if (res_type == "page")
 355        {
 356            sqlStr += " AND url = \'" + res + "\'";
 357        }
 358        else if (res_type == "referring")
 359        {
 360            sqlStr += " AND referring_url = \'" + res + "\'";
 361        }
 362
 363        return sqlStr;
 364    }
 365
 366    public override void Drawgraphic()
 367    {
 368        int tmpooo = 1000;
 369        int side = System.Convert.ToInt32(10 * Convert.ToInt32(tmpooo.ToString().Length - 1) + 5);
 370        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width + side, Height + TextHeight);
 371        MemoryStream ms = new MemoryStream();
 372        int i;
 373        Graphics g = Graphics.FromImage(bmp);
 374        System.Drawing.Font myfont = new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, Convert.ToSingle(12), FontStyle.Regular, GraphicsUnit.Pixel);
 375        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 376        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 377        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
 378
 379        g.FillRectangle(Brushes.White, 0, 0, Width + side, Height + TextHeight);
 380
 381
 382        if (!CheckAccess())
 383        {
 384            ContentAPI contentApi = new ContentAPI();
 385            Ektron.Cms.Common.EkMessageHelper msgApi = contentApi.EkMsgRef;
 386            throw (new Exception(msgApi.GetMessage("com: user does not have permission")));
 387        }
 388
 389        DateTime StartDate;
 390        DateTime EndDate;
 391        try
 392        {
 393            EndDate = DateTime.Parse(Page.Request.QueryString["EndDate"]);
 394        }
 395        catch (Exception)
 396        {
 397            EndDate = DateTime.Today;
 398        }
 399
 400        try
 401        {
 402            StartDate = DateTime.Parse(Page.Request.QueryString["StartDate"]);
 403        }
 404        catch (Exception)
 405        {
 406            StartDate = DateTime.MinValue;
 407        }
 408
 409        string[] sqlCommands = new string[NumBars + 1];
 410        DataSet dbData;
 411
 412        int[] data = new int[NumBars * ClusterSize + 1];
 413
 414        if (StartDate == DateTime.MinValue)
 415        {
 416
 417            if (CurrentView == "day")
 418            {
 419                for (i = 0; i <= NumBars - 1; i++)
 420                {
 421                    if (i == NumBars - 1)
 422                    {
 423                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddHours(i)), AnalyticsAPI.ProviderInvariantName) + " AND hit_date <= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddHours(i + 1)), AnalyticsAPI.ProviderInvariantName) + "");
 424                    }
 425                    else
 426                    {
 427                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddHours(i)), AnalyticsAPI.ProviderInvariantName) + " AND hit_date < " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddHours(i + 1)), AnalyticsAPI.ProviderInvariantName) + "");
 428                    }
 429
 430                }
 431                dbData = Analytics.QueryAnalytics(sqlCommands);
 432                i = 0;
 433                for (i = 0; i <= dbData.Tables.Count - 1; i++)
 434                {
 435                    data[i * 2] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][0]);
 436                    data[i * 2 + 1] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][1]);
 437                }
 438            }
 439            else if (CurrentView == "week")
 440            {
 441                for (i = 0; i <= NumBars - 1; i++)
 442                {
 443                    if (i == NumBars - 1)
 444                    {
 445                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date <= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 446                    }
 447                    else
 448                    {
 449                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date < " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 450                    }
 451
 452                }
 453                dbData = Analytics.QueryAnalytics(sqlCommands);
 454                i = 0;
 455                for (i = 0; i <= dbData.Tables.Count - 1; i++)
 456                {
 457                    data[i * 2] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][0]);
 458                    data[i * 2 + 1] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][1]);
 459                }
 460            }
 461            else if (CurrentView == "month")
 462            {
 463                for (i = 0; i <= NumBars - 1; i++)
 464                {
 465                    if (i == NumBars - 1)
 466                    {
 467                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date <= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 468                    }
 469                    else
 470                    {
 471                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date < " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddDays(System.Convert.ToDouble(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 472                    }
 473
 474                }
 475                dbData = Analytics.QueryAnalytics(sqlCommands);
 476                i = 0;
 477                for (i = 0; i <= dbData.Tables.Count - 1; i++)
 478                {
 479                    data[i * 2] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][0]);
 480                    data[i * 2 + 1] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][1]);
 481                }
 482            }
 483            else if (CurrentView == "year")
 484            {
 485                for (i = 0; i <= NumBars - 1; i++)
 486                {
 487                    if (i == NumBars - 1)
 488                    {
 489                        // MM-01-yyyy
 490                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date <= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddMonths(System.Convert.ToInt32(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddMonths(System.Convert.ToInt32(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 491                    }
 492                    else
 493                    {
 494                        sqlCommands[i] = AddRestriction("SELECT COUNT(visitor_id), COUNT(DISTINCT visitor_id) FROM content_hits_tbl WHERE " + "hit_date < " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddMonths(System.Convert.ToInt32(-1 * (NumBars - i - 2)))), AnalyticsAPI.ProviderInvariantName) + " AND hit_date >= " + AnalyticsAPI.FormatDate(Convert.ToString(EndDate.AddMonths(System.Convert.ToInt32(-1 * (NumBars - i - 1)))), AnalyticsAPI.ProviderInvariantName) + "");
 495                    }
 496
 497                }
 498                dbData = Analytics.QueryAnalytics(sqlCommands);
 499                i = 0;
 500                for (i = 0; i <= dbData.Tables.Count - 1; i++)
 501                {
 502                    data[i * 2] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][0]);
 503                    data[i * 2 + 1] = System.Convert.ToInt32(dbData.Tables[i].Rows[0][1]);
 504                }
 505            }
 506        }
 507        else
 508        {
 509
 510        }
 511
 512        int tmpS;
 513        if (CurrentView == "day")
 514        {
 515            for (i = 0; i <= 7; i++)
 516            {
 517                tmpS = i * (Width / Divisions) + side;
 518                g.DrawString((string)(EndDate.AddHours(System.Convert.ToDouble(3 * i)).ToString("hh:mm tt")), myfont, Brushes.Black, new System.Drawing.Point(tmpS, Height));
 519            }
 520        }
 521        else if (CurrentView == "week")
 522        {
 523            for (i = 0; i <= 6; i++)
 524            {
 525                tmpS = System.Convert.ToInt32((Divisions - i - 1) * (Width / Divisions) + side);
 526                g.DrawString((string)(EndDate.AddDays(System.Convert.ToDouble(-1 * i)).ToString("ddd MM-dd")), myfont, Brushes.Black, new System.Drawing.Point(tmpS, Height));
 527            }
 528        }
 529        else if (CurrentView == "month")
 530        {
 531            for (i = 0; i <= 5; i++)
 532            {
 533                tmpS = System.Convert.ToInt32((Divisions - i - 1) * (Width / Divisions) + side);
 534                g.DrawString((string)(EndDate.AddDays(System.Convert.ToDouble(-5 * i)).ToString("MM-dd-yyyy")), myfont, Brushes.Black, new System.Drawing.Point(tmpS, Height));
 535            }
 536        }
 537        else if (CurrentView == "year")
 538        {
 539            for (i = 0; i <= 11; i++)
 540            {
 541                tmpS = System.Convert.ToInt32((Divisions - i - 1) * (Width / Divisions) + side);
 542                g.DrawString((string)(EndDate.AddMonths(System.Convert.ToInt32(-1 * i)).ToString("MMM-yy")), myfont, Brushes.Black, new System.Drawing.Point(tmpS, Height));
 543            }
 544        }
 545
 546
 547        for (i = 0; i <= Divisions - 1; i++)
 548        {
 549            int start = i * (Width / Divisions) + side;
 550            g.DrawLine(Pens.Black, start, Height, start, 0);
 551        }
 552
 553
 554        Random rand = new Random();
 555
 556        int max = 1;
 557        for (i = 0; i <= NumBars * ClusterSize - 1; i++)
 558        {
 559            if (data[i] > max)
 560            {
 561                max = data[i];
 562            }
 563        }
 564
 565        int oom = this.GetOrderOfMagnitude(max);
 566        //g.DrawString(max, font, Brushes.Black, 0, 12)
 567        int trying = 0;
 568        trying = System.Convert.ToInt32((oom / max) * (Height));
 569
 570
 571        int j = 1;
 572        while ((j * oom) < max)
 573        {
 574            float tmp1 = Height - trying * j;
 575            g.DrawLine(Pens.Black, side, System.Convert.ToInt32(tmp1), Width + side, System.Convert.ToInt32(tmp1));
 576            g.DrawString((string)((oom * j).ToString()), myfont, Brushes.Black, 0, tmp1 - 7);
 577            j++;
 578        }
 579
 580        g.DrawLine(Pens.Black, side, Height, Width + side, Height);
 581
 582        for (i = 0; i <= NumBars * ClusterSize - 1; i++)
 583        {
 584            data[i] = System.Convert.ToInt32(data[i] * Height / max);
 585            if (i % 2 == 0)
 586            {
 587                g.FillRectangle(Brushes.Red, System.Convert.ToInt32((BarWidth + SpaceWidth) * i + side), Height - data[i], System.Convert.ToInt32(BarWidth), data[i]);
 588            }
 589            else
 590            {
 591                g.FillRectangle(Brushes.Blue, System.Convert.ToInt32((BarWidth + SpaceWidth) * i + side), Height - data[i], System.Convert.ToInt32(BarWidth), data[i]);
 592            }
 593        }
 594
 595        bmp.Save(ms, ImageFormat.Png);
 596        ms.WriteTo(Page.Response.OutputStream);
 597
 598        bmp.Dispose();
 599        ms.Dispose();
 600    }
 601
 602    private int GetOrderOfMagnitude(int val)
 603    {
 604        int i = 1;
 605
 606        while (true)
 607        {
 608            if (Math.Floor(Convert.ToDecimal(val / (i * 10))) == 0)
 609            {
 610                return i;
 611            }
 612            else
 613            {
 614                i = i * 10;
 615            }
 616        }
 617    }
 618
 619}
 620
 621internal class CircleGraph : WorkareaGraphBase
 622{
 623
 624
 625    private int _height = 100;
 626    private int _width = 100;
 627
 628    protected int Height
 629    {
 630        get
 631        {
 632            return _height;
 633        }
 634        set
 635        {
 636            _height = value;
 637        }
 638    }
 639
 640    protected int Width
 641    {
 642        get
 643        {
 644            return _width;
 645        }
 646        set
 647        {
 648            _width = value;
 649        }
 650    }
 651
 652
 653    public override void Initialize()
 654    {
 655        try
 656        {
 657            int tmp = Convert.ToInt32(Page.Request.QueryString["size"]);
 658            Height = tmp;
 659            Width = tmp;
 660        }
 661        catch (Exception)
 662        {
 663            Height = 100;
 664            Width = 100;
 665        }
 666
 667    }
 668
 669    public override void Drawgraphic()
 670    {
 671        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height);
 672        MemoryStream ms = new MemoryStream();
 673        Graphics objGraphics = Graphics.FromImage(bmp);
 674
 675        objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 676        objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 677        objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
 678
 679        SolidBrush whiteBrush = new SolidBrush(Color.White);
 680        SolidBrush blackBrush = new SolidBrush(Color.Black);
 681
 682        int r1 = Convert.ToInt32(Page.Request.QueryString["r1"]);
 683        int r2 = Convert.ToInt32(Page.Request.QueryString["r2"]);
 684
 685        int total = r1 + r2;
 686
 687        int tHeight = System.Convert.ToInt32(Math.Floor(Height * 0.9));
 688        int tWidth = System.Convert.ToInt32(Math.Floor(Width * 0.9));
 689        int delta = System.Convert.ToInt32(Math.Floor(Width * 0.05));
 690
 691        int d1;
 692        try
 693        {
 694            d1 = r1 * 360 / total;
 695        }
 696        catch (Exception)
 697        {
 698            objGraphics.FillRectangle(whiteBrush, 0, 0, Width, Height);
 699            objGraphics.FillPie(Brushes.Black, delta, delta, tWidth, tHeight, 0, 360);
 700            bmp.Save(ms, ImageFormat.Png);
 701            ms.WriteTo(Page.Response.OutputStream);
 702            return;
 703        }
 704
 705        int d2 = System.Convert.ToInt32(360 - d1);
 706
 707
 708
 709        objGraphics.FillRectangle(whiteBrush, 0, 0, Width, Height);
 710        objGraphics.FillPie(Brushes.Red, delta, delta, tWidth, tHeight, 0, d1);
 711        objGraphics.FillPie(Brushes.Blue, delta, delta, tWidth, tHeight, d1, d2);
 712
 713        bmp.Save(ms, ImageFormat.Png);
 714        ms.WriteTo(Page.Response.OutputStream);
 715
 716        bmp.Dispose();
 717        ms.Dispose();
 718    }
 719}
 720
 721internal class BarGraph : WorkareaGraphBase
 722{
 723    public BarGraph()
 724    {
 725        _barBrush = new SolidBrush(Color.LightBlue);
 726        _barColor = Color.LightBlue;
 727        _bgBrush = new SolidBrush(Color.White);
 728        _bgColor = Color.White;
 729        _fontBrush = new SolidBrush(Color.Black);
 730        _fontColor = Color.Black;
 731
 732    }
 733
 734    private int _height = 100;
 735    private int _width = 100;
 736    private int _bottomArea = 15;
 737    private float _percentageSpace = (float)(0.3F);
 738    private int _numBars = 9;
 739    private int _fontSize = 8;
 740    private SolidBrush _barBrush;
 741    private Color _barColor;
 742    private SolidBrush _bgBrush;
 743    private Color _bgColor;
 744    private SolidBrush _fontBrush;
 745    private Color _fontColor;
 746    private int[] weights;
 747    private float[] heights;
 748    private bool m_b0 = true;
 749    private bool m_bStars = false;
 750
 751    public override void Initialize()
 752    {
 753        Height = 125;
 754        Width = 150;
 755        PercentageSpace = (float)(0.3F);
 756        NumBars = 11;
 757        weights = new int[NumBars + 1];
 758        heights = new Single[NumBars + 1];
 759        int max = 1;
 760        BarColor = Color.LightBlue;
 761
 762        int i;
 763        for (i = 0; i <= 10; i++)
 764        {
 765            try
 766            {
 767                string val = Page.Request.QueryString.Get((string)("R" + (i)));
 768                if (i == 0 && val == null)
 769                {
 770                    m_b0 = false;
 771                }
 772                else if (!(i == 10 && val == null))
 773                {
 774                    weights[i] = Convert.ToInt32(val);
 775                }
 776            }
 777            catch
 778            {
 779                weights[i] = 0;
 780            }
 781            if (weights[i] > max)
 782            {
 783                max = weights[i];
 784            }
 785        }
 786
 787        for (i = 0; i <= 10; i++)
 788        {
 789            heights[i] = Height * System.Convert.ToSingle(weights[i] / max);
 790        }
 791
 792        FontColor = GetColor("fontColor", FontColor);
 793        BarColor = GetColor("barColor", BarColor);
 794        BGColor = GetColor("bgColor", BGColor);
 795        if (Page.Request.QueryString["fontColor"] == "0")
 796        {
 797            FontColor = Color.Black;
 798        }
 799        if (Page.Request.QueryString["bgColor"] == "0")
 800        {
 801            BGColor = Color.White;
 802        }
 803        if (Page.Request.QueryString["stars"] != "")
 804        {
 805            m_bStars = true;
 806            Width = 250;
 807            Height = 150;
 808            _bottomArea = 90;
 809        }
 810    }
 811
 812    private Color GetColor(string target, Color col)
 813    {
 814        if (!(Page.Request.QueryString[target] == null))
 815        {
 816            try
 817            {
 818                col = Color.FromArgb(Convert.ToInt32(Page.Request.QueryString[target]));
 819            }
 820            catch
 821            {
 822
 823            }
 824        }
 825        return col;
 826    }
 827
 828
 829    private int FontSize
 830    {
 831        get
 832        {
 833            return _fontSize;
 834        }
 835    }
 836
 837    private int Height
 838    {
 839        get
 840        {
 841            return _height;
 842        }
 843        set
 844        {
 845            if (_height > 0)
 846            {
 847                _height = value;
 848            }
 849        }
 850    }
 851
 852    private int Width
 853    {
 854        get
 855        {
 856            return _width;
 857        }
 858        set
 859        {
 860            if (_width > 0)
 861            {
 862                _width = value;
 863            }
 864        }
 865    }
 866
 867    private float PercentageSpace
 868    {
 869        get
 870        {
 871            return _percentageSpace;
 872        }
 873        set
 874        {
 875            if (value >= 0 || value < 1)
 876            {
 877                _percentageSpace = value;
 878            }
 879        }
 880    }
 881
 882    private int NumBars
 883    {
 884        get
 885        {
 886            return _numBars;
 887        }
 888        set
 889        {
 890            if (value > 0)
 891            {
 892                _numBars = value;
 893            }
 894        }
 895    }
 896
 897    private float BarWidth
 898    {
 899        get
 900        {
 901            return Width * (1 - PercentageSpace) / NumBars;
 902        }
 903    }
 904
 905    private float SpaceWidth
 906    {
 907        get
 908        {
 909            return Width * PercentageSpace / NumBars;
 910        }
 911    }
 912
 913    private int TextHeight
 914    {
 915        get
 916        {
 917            return _bottomArea;
 918        }
 919        set
 920        {
 921            _bottomArea = value;
 922        }
 923    }
 924
 925    private Color BarColor
 926    {
 927        get
 928        {
 929            return _barColor;
 930        }
 931        set
 932        {
 933            _barBrush = new SolidBrush(value);
 934        }
 935    }
 936
 937    private Color BGColor
 938    {
 939        get
 940        {
 941            return _bgColor;
 942        }
 943        set
 944        {
 945            _bgBrush = new SolidBrush(value);
 946        }
 947    }
 948
 949    private Color FontColor
 950    {
 951        get
 952        {
 953            return _fontColor;
 954        }
 955        set
 956        {
 957            _fontBrush = new SolidBrush(value);
 958        }
 959    }
 960
 961    public override void Drawgraphic()
 962    {
 963        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height + TextHeight);
 964        ContentAPI cAPI = null;
 965        System.Drawing.Image iStar = null;
 966        System.Drawing.Image iStarH = null;
 967        System.Drawing.Image iStop = null;
 968        MemoryStream ms = new MemoryStream();
 969
 970        if (m_bStars == true)
 971        {
 972            cAPI = new ContentAPI();
 973            iStar = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(cAPI.AppPath + "images/UI/icons/star.png"));
 974            iStarH = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(cAPI.AppPath + "images/UI/icons/starHalf.png"));
 975            iStop = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(cAPI.AppPath + "images/UI/icons/stop.png"));
 976        }
 977
 978        Graphics objGraphics = Graphics.FromImage(bmp);
 979        objGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
 980        objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 981        objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
 982
 983        Brush whiteBrush = _bgBrush;
 984        Brush blackBrush = _fontBrush;
 985
 986        objGraphics.FillRectangle(_bgBrush, 0, 0, Width, Height + TextHeight);
 987        int i;
 988        if (m_b0 == false && m_b0 == false)
 989        {
 990            NumBars = 9;
 991            for (i = 0; i <= NumBars - 1; i++)
 992            {
 993                objGraphics.FillRectangle(_barBrush, System.Convert.ToInt32((BarWidth + SpaceWidth) * i), Height - heights[i + 1], System.Convert.ToInt32(BarWidth), System.Convert.ToInt32(heights[i + 1]));
 994                objGraphics.DrawString((string)((i + 1).ToString()), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, Convert.ToSingle(8)), blackBrush, (BarWidth + SpaceWidth) * (i), Height);
 995            }
 996        }
 997        else
 998        {
 999            for (i = 0; i <= NumBars - 1; i++)
1000            {
1001                objGraphics.FillRectangle(_barBrush, System.Convert.ToInt32((BarWidth + SpaceWidth) * i), Height - heights[i], System.Convert.ToInt32(BarWidth), System.Convert.ToInt32(heights[i]));
1002                if (m_bStars == true)
1003                {
1004                    if (i % 2 == 0 && i > 0)
1005                    {
1006                        for (int j = 2; j <= i; j += 2)
1007                        {
1008                            objGraphics.DrawImage(iStar, System.Convert.ToInt32((BarWidth + SpaceWidth) * (i)), Height + ((j - 2) * 9));
1009                        }
1010                    }
1011                    else if (i > 1)
1012                    {
1013                        decimal dHeight = 0;
1014                        for (int j = 3; j <= i; j += 2)
1015                        {
1016                            dHeight = System.Convert.ToDecimal(Height + ((j - 2) * 9) - 9);
1017                            objGraphics.DrawImage(iStar, System.Convert.ToInt32((BarWidth + SpaceWidth) * (i)), System.Convert.ToInt32(dHeight));
1018                        }
1019                        if (i == 1)
1020                        {
1021                            dHeight = Convert.ToDecimal(Height) - Convert.ToDecimal(heights[i]) - 18;
1022                        }
1023                        objGraphics.DrawImage(iStarH, System.Convert.ToInt32((BarWidth + SpaceWidth) * (i)), System.Convert.ToInt32(dHeight + 18));
1024                    }
1025                    else if (i == 1)
1026                    {
1027                        objGraphics.DrawImage(iStarH, System.Convert.ToSingle((BarWidth + SpaceWidth) * (i)), System.Convert.ToSingle(Height + (-1 * 9) + 9));
1028                    }
1029                    else if (i == 0)
1030                    {
1031                        objGraphics.DrawImage(iStop, System.Convert.ToSingle((BarWidth + SpaceWidth) * (i)), System.Convert.ToSingle(Height + (-1 * 9) + 9));
1032                    }
1033                }
1034                else
1035                {
1036                    objGraphics.DrawString((string)((i).ToString()), new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, Convert.ToSingle(8)), blackBrush, (BarWidth + SpaceWidth) * i, Height);
1037                }
1038            }
1039        }
1040
1041        bmp.Save(ms, ImageFormat.Png);
1042        ms.WriteTo(Page.Response.OutputStream);
1043
1044        bmp.Dispose();
1045        ms.Dispose();
1046    }
1047}
1048
1049internal abstract class WorkareaGraphBase
1050{
1051
1052    protected System.Web.UI.Page Page;
1053
1054    public void Init(System.Web.UI.Page page)
1055    {
1056        this.Page = page;
1057        this.Page.Response.ContentType = "image/png";
1058        Initialize();
1059        Drawgraphic();
1060    }
1061
1062    abstract public void Initialize();
1063
1064    abstract public void Drawgraphic();
1065}