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