Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/QueryController.cs @ 10207

Last change on this file since 10207 was 6315, checked in by msammer, 14 years ago

#1520 added Styles; fixed bugs

File size: 4.0 KB
RevLine 
[5910]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6//using HLWebOKBAdminPlugin.ViewModels;
7using System.Web.Security;
8using System.ServiceModel.Security;
9//using HLWebPluginHost.OKBService;
10using System.Diagnostics;
[6253]11using System.Reflection;
12using System.Text;
[6303]13using HLWebOKBQueryPlugin.Models;
[5910]14using HLWebOKBQueryPlugin.OKBQueryService;
[5919]15using HLWebOKBQueryPlugin.Helpers;
[5910]16
[6076]17namespace HLWebOKBQueryPlugin.Controllers {
18    public class QueryController : Controller {
19        public ActionResult Index() {
[5910]20            return View();
21        }
22
[6076]23        public ActionResult Menu() {
[5910]24            return View();
25        }
26
[6076]27        public ActionResult Filter() {
[5919]28            QueryServiceClient client = Query.GetClientFactory();
29
30
[5910]31            QueryModel qm = new QueryModel();
32            Session["SelectedSubMenu"] = "Filter";
33            return View(qm);
34        }
35
[6076]36        public ActionResult Results() {
37            QueryServiceClient client = Query.GetClientFactory();
38
[5910]39            QueryModel qm = new QueryModel();
40            Session["SelectedSubMenu"] = "Results";
41            return View(qm);
42        }
[6076]43
44        public ActionResult RunCollectionTable() {
[6303]45
46            // Get runs from filter
47
48            QueryServiceClient client = Query.GetClientFactory();
49
[6315]50            long[] ids;
51            if (Session["Content"] != null)
52                ids = client.GetRunIds((CombinedFilter)Session["Content"]);
53            else
54                ids = new long[0];
[6303]55
[6226]56            QueryModel qm = new QueryModel();
[6303]57            qm.Runs = ids;
58            Session["QueryRuns"] = qm.RunCollection;
[6226]59            return View(qm);
[6076]60        }
[6253]61
62        public ActionResult Details(long id = 0) {
63            QueryServiceClient client = Query.GetClientFactory();
64
65            QueryModel qm = new QueryModel();
66            Session["SelectedSubMenu"] = "Details";
67            if (id != 0)
68                Session["QueryRunDetailId"] = id;
69            return View(qm);
70        }
71
72        public ActionResult RunCollectionDetail() {
73            QueryModel qm = new QueryModel();
74            Session["QueryRunDetail"] = qm.getRun((long)Session["QueryRunDetailId"]);
75            return View(qm);
76        }
77
78        public string DetailValue(String id) {
79            // get current property and return value
80            string retVal = String.Empty;
81
82            RunCollectionData rcd = (RunCollectionData)Session["QueryRunDetail"];
83
84            PropertyInfo pi = rcd.GetType().GetProperties().First(p => p.Name.Equals(id));
85            Object pv = pi.GetValue(rcd, null);
86
87            if (pv.GetType() == typeof(bool))
88                retVal = GetCheckBox("Value: ", (bool)pv);
89            if (pv.GetType() == typeof(int))
90                retVal = GetTextBox("Value: ", pv.ToString());
91            if (pv.GetType() == typeof(double))
92                retVal = GetTextBox("Value: ", ((Double)pv).ToString("#,##0.00"));
93            if (pv.GetType() == typeof(string))
94                retVal = GetTextBox("Value: ", (string)pv);
95
96            if (retVal.Equals(String.Empty))
97                retVal = GetTextBox("Value:", "");
98           
99            return retVal;
100        }
101
102
103
104
105
106        /***
107         * Helper
108         */
109        private string GetTextBox(string caption, string value) {
110            StringBuilder sb = new StringBuilder();
111
112            sb.Append("<label>" + caption + "</label> ");
113            sb.Append("<input type=\"text\" value=\"" + value + "\" />");
114
115            return sb.ToString();
116        }
117
118        private string GetCheckBox(string caption, bool value) {
119            StringBuilder sb = new StringBuilder();
120
121            sb.Append("<label>" + caption + "</label> ");
122            sb.Append("<input type=\"checkbox\" value=\"" + value + "\"");
123            sb.Append(value ? " checked=\"checked\"" : "");
124            sb.Append(" />");
125
126            return sb.ToString();
127        }
128
[5910]129    }
130}
Note: See TracBrowser for help on using the repository browser.