using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using HLWebOKBAdminPlugin.ViewModels;
using System.Web.Security;
using System.ServiceModel.Security;
//using HLWebPluginHost.OKBService;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using HLWebOKBQueryPlugin.Models;
using HLWebOKBQueryPlugin.OKBQueryService;
using HLWebOKBQueryPlugin.Helpers;
namespace HLWebOKBQueryPlugin.Controllers {
public class QueryController : Controller {
public ActionResult Index() {
return View();
}
public ActionResult Menu() {
return View();
}
public ActionResult Filter() {
QueryServiceClient client = Query.GetClientFactory();
QueryModel qm = new QueryModel();
Session["SelectedSubMenu"] = "Filter";
return View(qm);
}
public ActionResult Results() {
QueryServiceClient client = Query.GetClientFactory();
QueryModel qm = new QueryModel();
Session["SelectedSubMenu"] = "Results";
return View(qm);
}
public ActionResult RunCollectionTable() {
// Get runs from filter
QueryServiceClient client = Query.GetClientFactory();
long[] ids;
if (Session["Content"] != null)
ids = client.GetRunIds((CombinedFilter)Session["Content"]);
else
ids = new long[0];
QueryModel qm = new QueryModel();
qm.Runs = ids;
Session["QueryRuns"] = qm.RunCollection;
return View(qm);
}
public ActionResult Details(long id = 0) {
QueryServiceClient client = Query.GetClientFactory();
QueryModel qm = new QueryModel();
Session["SelectedSubMenu"] = "Details";
if (id != 0)
Session["QueryRunDetailId"] = id;
return View(qm);
}
public ActionResult RunCollectionDetail() {
QueryModel qm = new QueryModel();
Session["QueryRunDetail"] = qm.getRun((long)Session["QueryRunDetailId"]);
return View(qm);
}
public string DetailValue(String id) {
// get current property and return value
string retVal = String.Empty;
RunCollectionData rcd = (RunCollectionData)Session["QueryRunDetail"];
PropertyInfo pi = rcd.GetType().GetProperties().First(p => p.Name.Equals(id));
Object pv = pi.GetValue(rcd, null);
if (pv.GetType() == typeof(bool))
retVal = GetCheckBox("Value: ", (bool)pv);
if (pv.GetType() == typeof(int))
retVal = GetTextBox("Value: ", pv.ToString());
if (pv.GetType() == typeof(double))
retVal = GetTextBox("Value: ", ((Double)pv).ToString("#,##0.00"));
if (pv.GetType() == typeof(string))
retVal = GetTextBox("Value: ", (string)pv);
if (retVal.Equals(String.Empty))
retVal = GetTextBox("Value:", "");
return retVal;
}
/***
* Helper
*/
private string GetTextBox(string caption, string value) {
StringBuilder sb = new StringBuilder();
sb.Append(" ");
sb.Append("");
return sb.ToString();
}
private string GetCheckBox(string caption, bool value) {
StringBuilder sb = new StringBuilder();
sb.Append(" ");
sb.Append("");
return sb.ToString();
}
}
}