StatisticsListBase.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » Web » StatisticsListBase.cs
using System;
using System.Collections;
using System.Globalization;
using System.Resources;
using System.Web;
using System.Web.UI.WebControls;
using newtelligence.DasBlog.Web.Core;

namespace newtelligence.DasBlog.Web{
    public class StatisticsItem
    {
        internal string identifier;
        internal int count;
        internal StatisticsItem(string identifier, int count)
        {
            this.identifier = identifier;
            this.count = count;
        }

        public class Comparer : IComparer
        {
            public int Compare(object left, object right)
            {
              StatisticsItem leftItem = (StatisticsItem)left;
        StatisticsItem rightItem = (StatisticsItem)right;

        int leftValue = leftItem.count;
              int rightValue = rightItem.count;
                if (leftValue > rightValue)
                {
                    return -1;
                }
                else if (leftValue < rightValue)
                {
                    return 1;
                }
        
                return String.Compare(leftItem.identifier, rightItem.identifier, StringComparison.InvariantCultureIgnoreCase);
            }
        }

      public class SearchStringComparer : IComparer
      {
        public int Compare(object left, object right)
        {
          StatisticsItem leftItem = (StatisticsItem) left;
          StatisticsItem rightItem = (StatisticsItem) right;

          int leftValue = leftItem.count;
          int rightValue = rightItem.count;
          if (leftValue > rightValue)
          {
            return -1;
          }
          else if (leftValue < rightValue)
          {
            return 1;
          }

          return
            String.Compare(SiteUtilities.ParseSearchString(leftItem.identifier).Text,
                           SiteUtilities.ParseSearchString(rightItem.identifier).Text,
                           StringComparison.InvariantCultureIgnoreCase);
        }
    }
    }

    public delegate void StatisticsBuilderCallback( TableRow currentRow, StatisticsItem item, object args );
    
    public class StatisticsListBase : System.Web.UI.UserControl
  {
        protected ResourceManager resmgr;

    public StatisticsListBase()
    {
            resmgr = ApplicationResourceTable.Get();
    }

    protected Table BuildStatisticsTable( 
      IEnumerable items, 
      string itemColumnName, 
      string numberColumnName, 
      StatisticsBuilderCallback buildFn, 
      object args )
    {
      string total = string.Empty;
      return BuildStatisticsTable(items,itemColumnName,numberColumnName,buildFn,out total,args);
    }

        protected Table BuildStatisticsTable( 
            IEnumerable items, 
            string itemColumnName, 
            string numberColumnName, 
            StatisticsBuilderCallback buildFn, 
      out string totalString,
            object args )
        {
            int total = 0;
            Table table = new Table();
            table.CssClass = "statsTableStyle";
            TableRow row = new TableRow();
            row.CssClass = "statsTableHeaderRowStyle";
            row.Cells.Add(new TableCell());
            row.Cells.Add(new TableCell());
            row.Cells[0].CssClass = "statsTableHeaderColumnStyle";
            row.Cells[1].CssClass = "statsTableHeaderNumColumnStyle";
            row.Cells[0].Text = itemColumnName;
            row.Cells[1].Text = numberColumnName;
            table.Rows.Add(row);

            foreach (StatisticsItem item in items)
            {
                row = new TableRow();
                row.CssClass = "statsTableRowStyle";
                row.Cells.Add(new TableCell());
                row.Cells.Add(new TableCell());
                row.Cells[0].CssClass = "statsTableColumnStyle";
                row.Cells[1].CssClass = "statsTableNumColumnStyle";

                buildFn( row, item, args );

        if (row.Cells[1].Text.Length > 0)
        {
          total += item.count;
          table.Rows.Add(row);
        }
            }

            TableRow totalRow = new TableRow();
            totalRow.CssClass="statsTableFooterRowStyle";
            totalRow.Cells.Add(new TableCell());
            totalRow.Cells.Add(new TableCell());
            totalRow.Cells[0].CssClass = "statsTableFooterColumnStyle";
            totalRow.Cells[1].CssClass = "statsTableFooterNumColumnStyle";
            totalRow.Cells[0].Text = resmgr.GetString("text_activity_total");
      totalString = total.ToString();
            totalRow.Cells[1].Text = totalString;
            table.Rows.Add(totalRow);
            return table;
        }

        protected void BuildAgentsRow( TableRow row, StatisticsItem item, object unused )
        {
            Label agentLabel = new Label();
            string text = SiteUtilities.ClipString(item.identifier,80);
            agentLabel.Text = text;
            row.Cells[0].Controls.Add(agentLabel);
            row.Cells[1].Text = item.count.ToString();
        }

        protected void BuildReferrerRow( TableRow row, StatisticsItem item, object unused )
        {
            HyperLink link = new HyperLink();
            string text = SiteUtilities.ClipString(item.identifier,80);
            link.Text = System.Web.HttpUtility.HtmlEncode(text);
            link.NavigateUrl = item.identifier.ToString();
            row.Cells[0].Controls.Add(link);
            row.Cells[1].Text = item.count.ToString();
        }
    
    protected void BuildSearchesRow(TableRow row, StatisticsItem item, object unused)
    {
      HyperLink link = SiteUtilities.ParseSearchString(item.identifier);

      if (link != null)
      {
        row.Cells[0].Controls.Add(link);
        row.Cells[1].Text = item.count.ToString();
      }
    }

    protected void BuildUserDomainRow(TableRow row, StatisticsItem item, object unused)
    {
      Label userDomainLabel = new Label();
      string text = SiteUtilities.ClipString(item.identifier, 80);
      userDomainLabel.Text = text;
      row.Cells[0].Controls.Add(userDomainLabel);
      row.Cells[1].Text = item.count.ToString();
    }

        protected ArrayList GenerateSortedItemList( IDictionary dict )
        {
            ArrayList listItems = new ArrayList(dict.Count);
            foreach (DictionaryEntry de in dict)
            {
                listItems.Add(new StatisticsItem(de.Key.ToString(), (int)de.Value));
            }
            listItems.Sort(new StatisticsItem.Comparer());
            return listItems;
        }

    protected ArrayList GenerateSortedSearchStringItemList(IDictionary dict)
    {
      ArrayList listItems = new ArrayList(dict.Count);
      foreach (DictionaryEntry de in dict)
      {
        listItems.Add(new StatisticsItem(de.Key.ToString(), (int)de.Value));
      }
      listItems.Sort(new StatisticsItem.SearchStringComparer());
      return listItems;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.