Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6305 was 6303, checked in by mjesner, 13 years ago

#1499 result page, styling, functionality (add/remove) for post actions

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