PageRenderTime 75ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/UnifyShow/Wicresoft.UnifyShow.Portal/Controllers/ServiceDeskController.cs

http://fjycUnifyShow.codeplex.com
C# | 205 lines | 157 code | 3 blank | 45 comment | 24 complexity | dd4c1fe14e1e05b7c06448e685ce5cfc MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Wicresoft.UnifyShow.Business;
  7. using Microsoft.Practices.Unity;
  8. using System.Windows.Forms.DataVisualization.Charting;
  9. using System.IO;
  10. using System.Drawing;
  11. using Wicresoft.UnifyShow.Portal.Extensions;
  12. namespace Wicresoft.UnifyShow.Portal.Controllers
  13. {
  14. public class ServiceDeskController : BaseController
  15. {
  16. // GET: /ServiceDesk/
  17. private IServiceDesk serviceDesk;
  18. private IIncident incident;
  19. private DateTime sTimes;
  20. private DateTime eTimes;
  21. Chart chart1 = new Chart();
  22. Series series1 = new Series();
  23. ChartArea chartArea1 = new ChartArea();
  24. protected override void Dispose(bool disposing)
  25. {
  26. ((IDisposable)serviceDesk).Dispose();
  27. ((IDisposable)incident).Dispose();
  28. }
  29. [InjectionConstructor]
  30. public ServiceDeskController(IServiceDesk e, IIncident iIcident)
  31. {
  32. serviceDesk = e;
  33. incident = iIcident;
  34. }
  35. //时间转换和为空处理
  36. private void timeSet(string sTime, string eTime)
  37. {
  38. sTimes = Convert.ToDateTime(sTime);
  39. eTimes = Convert.ToDateTime(eTime);
  40. if (sTime == null)
  41. sTimes = GlobalHelper.starTime;
  42. if (eTime == null)
  43. eTimes = GlobalHelper.endTime;
  44. }
  45. //事件来源(饼图)
  46. [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
  47. public ActionResult IncidentSource(int? sid, int? bnid, string sTime, string eTime)
  48. {
  49. //时间转换和为空处理
  50. timeSet(sTime, eTime);
  51. List<IncidentAndChangeModel> lpm = serviceDesk.IncidentSourceBySite(sid, bnid, sTimes, eTimes);
  52. if (lpm.FirstOrDefault(p => p.ID == 2000) == null)
  53. {
  54. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 2000 });
  55. }
  56. if (lpm.FirstOrDefault(p => p.ID == 3000) == null)
  57. {
  58. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 3000 });
  59. }
  60. if (lpm.FirstOrDefault(p => p.ID == 4000) == null)
  61. {
  62. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 4000 });
  63. }
  64. if (lpm.FirstOrDefault(p => p.ID == 4201) == null)
  65. {
  66. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 4201 });
  67. }
  68. if (lpm.FirstOrDefault(p => p.ID == 6000) == null)
  69. {
  70. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 6000 });
  71. }
  72. if (lpm.FirstOrDefault(p => p.ID == 10000) == null)
  73. {
  74. lpm.Add(new IncidentAndChangeModel { alls = 0, ID = 10000 });
  75. }
  76. List<double> lyval = new List<double>();
  77. List<string> lxval = new List<string>();
  78. List<string> llegend = new List<string>();
  79. double sum = (double)lpm.Sum(p => p.alls);
  80. foreach (var ResultSort in lpm)
  81. {
  82. double percent = (double)ResultSort.alls / sum;
  83. lyval.Add(percent);
  84. string percents = Convert.ToString(((percent * 100).ToString("0.00")) + "%");
  85. lxval.Add(Convert.ToString(percents));
  86. switch (ResultSort.ID.ToString())
  87. {
  88. case "2000": llegend.Add("电子邮件");
  89. break;
  90. case "3000": llegend.Add("监控系统");
  91. break;
  92. case "4000": llegend.Add("书面文档");
  93. break;
  94. case "4201": llegend.Add("自服务门户");
  95. break;
  96. case "6000": llegend.Add("电话");
  97. break;
  98. case "10000": llegend.Add("其他");
  99. break;
  100. }
  101. }
  102. //Series
  103. double[] yval = lyval.ToArray();
  104. string[] xval = lxval.ToArray();
  105. string[] legend = llegend.ToArray();
  106. series1.ChartType = SeriesChartType.Pie;
  107. series1.Points.DataBindXY(xval, yval);
  108. for (int i = 0; i < legend.Length; i++)
  109. {
  110. series1.Points[i].LegendText = legend[i];
  111. }
  112. //分割饼图
  113. //series1.Points[0]["Exploded"] = "true";
  114. // 设置标签风格
  115. //series1["PieLabelStyle"] = "Outside";
  116. //图样式 concave/SoftEdge
  117. series1["PieDrawingStyle"] = "SoftEdge";
  118. //ChartArea
  119. chartArea1.AxisY.LabelStyle.Format = "0%";
  120. //Chart
  121. chart1.Width = GlobalHelper.Width;
  122. chart1.Height = GlobalHelper.Height;
  123. Legend l = new Legend();
  124. l.BorderColor = Color.Black;
  125. chart1.Legends.Add(l);
  126. //设置图列样式颜色
  127. chart1.Legends[0].Font = GlobalHelper.fontLegend;
  128. //Title t = new Title("事件来源");
  129. //t.Font = GlobalHelper.fontTitle;
  130. //chart1.Legends[0].FontColorCombo = Color.Red;
  131. //设置图颜色
  132. //chart1.Palette = ChartColorPalette.Pastel;
  133. //此属性设置为None才可以自定义调色板
  134. chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
  135. // 自定义调色板
  136. Color[] colorSet = GlobalHelper.SixColorSet;
  137. chart1.PaletteCustomColors = colorSet;
  138. chart1.Width = GlobalHelper.Width;
  139. chart1.Height = GlobalHelper.Height;
  140. //chart1.Titles.Add(t);
  141. chart1.Series.Add(series1);
  142. chart1.ChartAreas.Add(chartArea1);
  143. return new ChartResult(chart1);
  144. }
  145. //服务台事件解决率(饼图)
  146. [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
  147. public ActionResult IncidentResolvedByServiceDesk(int? sid, int? bnid, string sTime, string eTime)
  148. {
  149. //时间转换和为空处理
  150. timeSet(sTime, eTime);
  151. //事件已解决总数量
  152. Decimal imAll = incident.GetApproveCountIncident(sid, bnid, sTimes, eTimes);
  153. //服务台解决数量
  154. Decimal imService = serviceDesk.GetApproveCountIncidentbyResolvedGroup(sid, bnid, sTimes, eTimes);
  155. //获取不由服务台解决数百分比
  156. double AppNum = ((double)imAll - (double)imService) / (double)imAll;
  157. //获取服务台解决数百分比
  158. double ServiceDeskNum = (double)imService / (double)imAll;
  159. AppNum = Convert.ToDouble(AppNum);
  160. ServiceDeskNum = Convert.ToDouble(ServiceDeskNum);
  161. //Series
  162. series1.ChartType = SeriesChartType.Pie;
  163. double[] yval = { ServiceDeskNum, AppNum };
  164. string[] xval = { (ServiceDeskNum * 100).ToString("0.00") + "%", (AppNum * 100).ToString("0.00") + "%" };
  165. series1.Points.DataBindXY(xval, yval);
  166. series1.Points[0].LegendText = "服务台解决率";
  167. series1.Points[1].LegendText = "非服务台解决率";
  168. //图样式 concave/SoftEdge
  169. series1["PieDrawingStyle"] = "SoftEdge";
  170. //分割饼图
  171. //series1.Points[0]["Exploded"] = "true";
  172. //// 设置标签风格
  173. //series1["PieLabelStyle"] = "Outside";
  174. //ChartArea
  175. chartArea1.Name = "Default";
  176. chartArea1.AxisY.LabelStyle.Format = "0%";
  177. //Chart
  178. //添加图列
  179. Legend l = new Legend();
  180. l.BorderColor = Color.Black;
  181. chart1.Legends.Add(l);
  182. //设置图列样式颜色
  183. chart1.Legends[0].Font = GlobalHelper.fontLegend;
  184. chart1.Width = GlobalHelper.Width;
  185. chart1.Height = GlobalHelper.Height;
  186. //Title t = new Title("服务台事件解决率");
  187. //t.Font = GlobalHelper.fontTitle;
  188. //chart1.Legends[0].FontColorCombo = Color.Red;
  189. //设置图颜色
  190. //chart1.Palette = ChartColorPalette.Pastel;
  191. //此属性设置为None才可以自定义调色板
  192. chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
  193. // 自定义调色板
  194. Color[] colorSet = GlobalHelper.TwoSetPei;
  195. chart1.PaletteCustomColors = colorSet;
  196. //chart1.Titles.Add(t);
  197. chart1.Series.Add(series1);
  198. chart1.ChartAreas.Add(chartArea1);
  199. return new ChartResult(chart1);
  200. }
  201. }
  202. }