Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. public partial class Components__TagCloud : System.Web.UI.UserControl
  9. {
  10.     #region Переменные
  11.  
  12.     DataSet _wordsdata = null;
  13.     String _title = String.Empty;
  14.  
  15.     #endregion
  16.  
  17.     #region Свойства
  18.  
  19.     public DataSet WordsData
  20.     {
  21.         set
  22.         {
  23.             _wordsdata = value;
  24.         }
  25.         get
  26.         {
  27.             return _wordsdata;
  28.         }
  29.     }
  30.  
  31.     public String Title
  32.     {
  33.         set
  34.         {
  35.             _title = value;
  36.         }
  37.         get
  38.         {
  39.             return _title;
  40.         }
  41.     }
  42.  
  43.     #endregion
  44.  
  45.     /// <summary>
  46.     /// Пошла загрузка
  47.     /// </summary>
  48.     /// <param name="sender"></param>
  49.     /// <param name="e"></param>
  50.     protected void Page_Load(object sender, EventArgs e)
  51.     {
  52.         Content.Text = "<div id=\"tagCloud"+this.ID+"\" class=\"TagCloud\">";
  53.         if(!String.IsNullOrEmpty(this.Title)){
  54.             Content.Text += "<h3>"+this.Title+"</h3>";
  55.         }
  56.         Content.Text += "</div><br/>";
  57.         if (WordsData != null && WordsData.Tables.Count > 0
  58.             && WordsData.Tables[0].Rows.Count > 0)
  59.         {
  60.             Content.Text += "<script type=\"text/javascript\">";
  61.             Content.Text += "$(function() {   " +
  62.            "iTagCloud.init('tagCloud"+this.ID+"', {tags:[";
  63.             int Min = int.MaxValue;
  64.             int Max = int.MinValue;
  65.  
  66.             //пройдемся по всем данным.
  67.             foreach(DataRow dr in WordsData.Tables[0].Rows){
  68.                 // $json .= "{tag:'" . $row["tag"] . "',freq:'" . $row["frequency"] . "'}";   
  69.                 Content.Text += "{tag:'" + dr[0].ToString()+"',freq:'"+ dr[1].ToString()+"'},";
  70.                 int freq;
  71.                 if(int.TryParse(dr[1].ToString(),out freq)){
  72.                     if (freq < Min)
  73.                     {
  74.                         Min = freq;
  75.                     }
  76.                     else if(freq > Max)
  77.                     {
  78.                         Max = freq;
  79.                     }
  80.                 }
  81.             }
  82.             Content.Text = Content.Text.TrimEnd(',')
  83.                 + "],min:'"+Min.ToString()+"',max:'"+Max.ToString()+"'})});"; //закрытие объекта
  84.             Content.Text += "</script>";
  85.         }else{
  86.             Content.Text += "-- недостаточно данных для построения облака слов --";
  87.         }
  88.  
  89.     }
  90. }
  91.  
  92.  
  93.  




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012