Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6318 was 6315, checked in by msammer, 13 years ago

#1520 added Styles; fixed bugs

File size: 4.0 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            QueryServiceClient client = Query.GetClientFactory();
49
50            long[] ids;
51            if (Session["Content"] != null)
52                ids = client.GetRunIds((CombinedFilter)Session["Content"]);
53            else
54                ids = new long[0];
55
56            QueryModel qm = new QueryModel();
57            qm.Runs = ids;
58            Session["QueryRuns"] = qm.RunCollection;
59            return View(qm);
60        }
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
129    }
130}
Note: See TracBrowser for help on using the repository browser.