public ViewChart GetChart(Int64 id, Guid userId) { Trace.Assert(Db != null); ObjectSet <ViewChart> os = Db.ViewChart; ViewChart result = os.Single(t => (t.ID == id) && (t.DataOwnerID == userId)); return(result); }
public ActionResult Delete(long id) { try { ViewChart viewchart = BaseChartRepository.GetChart(id, GetUserId()); return(View(viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ViewResult Details(long id) { try { ViewChart viewchart = BaseChartRepository.GetChart(id, GetUserId()); ViewBag.ChartTypes = new SelectList(ChartTypes, viewchart != null ? viewchart.ChartType.TrimEnd() : ChartTypes[0]); return(View("Details", viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
protected ViewChart FillChartData(Int64 id /*chart id.*/, int width, int height, Guid userId) { ViewChart viewchart = BaseChartRepository.GetChart(id, userId); ViewBag.Width = (width != -1) ? width : viewchart.Width; ViewBag.Height = (height != -1) ? height : viewchart.Height; if (viewchart.ChartType.TrimEnd().ToLower() == Diagram.ToLower()) { // the reference to document is meaningful only for diagrams, // so it can be null if (viewchart.DocID != null) { List <String> states = ChartRepository.ExportDataElementStates((long)viewchart.DocID, userId); ViewBag.DataStates = states; } else { ViewBag.DataStates = new List <String>(); } } else { var fileNames = new List <String>(); var statFileNames = new List <String>(); var l = viewchart.DataSetType.Trim().ToLower() == LastSeconds? BaseChartRepository.GetPointsVsAcqTime_Stat_LastSeconds(id, userId, viewchart.DataSetMaxCount) : BaseChartRepository.GetPointsVsAcqTime_Stat_Last(id, userId, viewchart.DataSetMaxCount); for (int i = 0; i < l.Count(); i++) { ViewFile vf = l[i]; if (vf.Content.ToLower() == "dataset") { fileNames.Add(vf.FileName); } else if (vf.Content.ToLower() == "datastat") { statFileNames.Add(vf.FileName); } } ViewBag.FileNames = fileNames; ViewBag.StatFileNames = statFileNames; } return(viewchart); }
public ActionResult CreateDiagram() { try { SetCreateEditViewBag(null); var viewchart = new ViewChart { DataSetType = Last, DataSetMaxCount = 2, ChartType = Diagram }; return(View("CreateDiagram", viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult ShowDiagram(Int64 id /*chart id.*/) { try { Guid userId = GetUserId(); ViewChart viewchart = BaseChartRepository.GetChart(id, userId); return(View(viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); // this view is showed in frame, so // it should show error message by itself return(View()); } }
public ActionResult Edit(ViewChart viewchart) { try { if (ModelState.IsValid) { BaseChartRepository.UpdateChart(viewchart, GetUserId()); return(RedirectToAction("ShowChart", "Chart", new { viewchart.ID })); } return(View(viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult ShowChart(Int64 id /*chart id.*/) { try { Guid userId = GetUserId(); ViewChart v = BaseChartRepository.GetChart(id, userId); ViewBag.ChartID = v.ID; ViewBag.Width = v.Width; ViewBag.Height = v.Height; return(View("ShowChart", v)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult Edit(long id) { try { ViewChart v = BaseChartRepository.GetChart(id, GetUserId()); SetCreateEditViewBag(v); if (v.ChartType.ToLower() == Diagram.ToLower()) { return(View("EditDiagram", v)); } return(View("Edit", v)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult Create(ViewChart viewchart) { try { if (ModelState.IsValid) { BaseChartRepository.AddChart(viewchart, GetUserId()); return(RedirectToAction("Index")); } SetCreateEditViewBag(viewchart); return(View(viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public ActionResult ShowDiagramDataSet(Int64 id /*chart id.*/) { try { Guid userId = GetUserId(); ViewChart v = BaseChartRepository.GetChart(id, userId); if (v.ChartType.ToLower() == Diagram.ToLower()) { ViewBag.ChartID = v.ID; ViewBag.Width = v.Width; ViewBag.Height = v.Height; return(View("ShowDiagramDataSet", v)); } return(RedirectToAction("ShowChart", new { id })); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
/* * public ActionResult XLSX(Int64 id/*chart id.* /) * { * try * { * // here should be export to XLSX realization * ViewChart viewchart = chartRepository.GetChart(id, GetUserID()); * return View(viewchart); * } * catch (Exception e) * { * ExceptionMessageToViewBag(e); * return View("Error"); * } * } */ public ActionResult DataSet(Int64 id /*chart id.*/, long?groupId, String group, long?ownerId, String owner, long?locationId, String location, String element, String svgId) { try { ViewChart viewchart = BaseChartRepository.GetChart(id, GetUserId()); ViewBag.Group = group; ViewBag.GroupID = groupId; ViewBag.Owner = owner; ViewBag.OwnerID = ownerId; ViewBag.Location = location; ViewBag.LocationID = locationId; ViewBag.Element = element; ViewBag.SVGID = svgId; List <ViewElementFiltered> v = BaseChartRepository.GetElementFilteredList(element, ownerId, groupId, locationId, GetUserId(), id); ViewBag.ElementList = v; return(View(viewchart)); } catch (Exception e) { ExceptionMessageToViewBag(e); return(View("Error")); } }
public void UpdateChart(ViewChart v, Guid userId) { Trace.Assert(Db != null); Db.UpdateChart(v.ID, v.Name, v.Width, v.Height, userId, v.DataSetType, v.DataSetMaxCount, v.ChartType); }
public void SetCreateEditViewBag(ViewChart viewchart) { ViewBag.ChartType = new SelectList(ChartTypes, viewchart != null ? viewchart.ChartType.TrimEnd() : ChartTypes[0]); ViewBag.DataSetType = new SelectList(DataSetTypes, viewchart != null ? viewchart.DataSetType.TrimEnd() : DataSetTypes[0]); }
protected Chart RenderChart(ViewChart v) { var xmlData = (List <String>)ViewBag.FileNames; var xmlStat = (List <String>)ViewBag.StatFileNames; var chart = new Chart(ViewBag.Width != null ? (Int32)ViewBag.Width : v.Width, ViewBag.Height != null ? (Int32)ViewBag.Height : v.Height).AddTitle(v.Name.TrimEnd()); Double tMin = 0.0, tMax = 0.0, vMin = 0.0, vMax = 0.0, unitsInSec = 1.0; var elementName = ""; var timeUnits = "?"; //var origAcqTimeMax = "?"; var origAcqTimeMin = "?"; if ((xmlStat != null) && (xmlStat.Count() != 0)) { var xml = xmlStat[0]; var reader = new XmlTextReader(new MemoryStream(Encoding.ASCII.GetBytes(xml))); const string locale = "en-US"; var culture = new CultureInfo(locale); try { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. elementName = reader.Name.ToLower(); break; case XmlNodeType.Text: //Display the text in each element. switch (elementName) { case ("tmax"): tMax = Double.Parse(reader.Value, culture.NumberFormat); break; case ("tmin"): tMin = Double.Parse(reader.Value, culture.NumberFormat); break; case ("vmax"): vMax = Double.Parse(reader.Value, culture.NumberFormat); break; case ("vmin"): vMin = Double.Parse(reader.Value, culture.NumberFormat); break; case ("timeunits"): timeUnits = reader.Value; break; case ("unitsinsec"): unitsInSec = Double.Parse(reader.Value, culture.NumberFormat); break; case ("origacqtimemax"): //origAcqTimeMax = reader.Value; break; case ("origacqtimemin"): origAcqTimeMin = reader.Value; break; } break; case XmlNodeType.EndElement: //Display the end of the element. break; } } } finally { // this allows file deleting in the case of reading failure reader.Close(); } } var legendName = Guid.NewGuid().ToString(); //myChart.AddLegend("Legend\nStart time: " + origAcqTimeMin + "\nEnd time: " + origAcqTimeMax, legendName); chart.AddLegend("Legend", legendName); for (var i = 0; i < xmlData.Count(); i++) { // Must be separate object for every serie. var dataSet = new DataSet(); dataSet.ReadXmlSchema(Server.MapPath("~/App_Data/data.xsd")); dataSet.ReadXml(new MemoryStream(Encoding.ASCII.GetBytes(xmlData[i]))); var dataView = new DataView(dataSet.Tables[0]) { Sort = "Time" }; var chartType = v.ChartType.TrimEnd().ToLower(); chart.AddSeries("Last " + v.DataSetMaxCount.ToString(CultureInfo.InvariantCulture) + " points " + (i + 1).ToString(CultureInfo.InvariantCulture), chartType, markerStep: 1, legend: legendName, xValue: dataView, xField: "Time", yValues: dataView, yFields: "Value" ); } Debug.Assert(Math.Abs(unitsInSec) > 1e-6); if (v.DataSetType.Trim().ToLower() == LastSeconds) { tMin = (tMax * unitsInSec - v.DataSetMaxCount) / unitsInSec; } if (Math.Abs(tMax - tMin) > 1e-6) { double newMin, newMax, duration; GetTimeLimits(tMin * unitsInSec, tMax * unitsInSec, out newMin, out newMax, out duration); newMin /= unitsInSec; newMax /= unitsInSec; duration /= unitsInSec; chart.SetXAxis("Time, Start = " + origAcqTimeMin + ", Duration = " + duration.ToString(CultureInfo.InvariantCulture) + " (" + timeUnits + ")", newMin, newMax); } else if (Math.Abs(tMin - 0) < 1e-6) { chart.SetXAxis("Time, Start = " + origAcqTimeMin + ", Duration = " + tMax.ToString(CultureInfo.InvariantCulture) + " (" + timeUnits + ")", tMin, tMin + 1); } if (Math.Abs(vMax - vMin) > 1e-6) { double newMin, newMax; GetValueLimits(vMin, vMax, out newMin, out newMax); chart.SetYAxis("Value, Min = " + vMin.ToString(CultureInfo.InvariantCulture) + ", Max = " + vMax.ToString(CultureInfo.InvariantCulture), newMin, newMax); } else if (Math.Abs(vMin - 0) < 1e-6) { chart.SetYAxis("Value, Min = " + vMin.ToString(CultureInfo.InvariantCulture) + ", Max = " + vMax.ToString(CultureInfo.InvariantCulture), vMin, vMin + 1); } return(chart); }