using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (Test_Manager_DatabaseEntities entities = new Test_Manager_DatabaseEntities())
{
int TestExecID = Convert.ToInt32(Request.QueryString["ExecutionID"]);
var execution = entities.TestExecutionDetails.Where(p => p.TestExecutionID == TestExecID).Select(p => p).OrderBy(p => p.StartTime).ToArray();
var failures = entities.TestExecutionDetails.Select(p => p.Result != "Pass ").Count();
var count = entities.TestExecutionDetails.Count();
var uptime = entities.TestExecutionDetails.Where(p => p.Result == "Pass ").Select(p => p);
TimeSpan elapsedDuration = new TimeSpan(0);
foreach (var p in uptime)
{
elapsedDuration += (p.EndTime.Value - p.StartTime.Value);
}
var mtbfdisplay = elapsedDuration.TotalSeconds / failures;
string str1 = @"
data = google.visualization.arrayToDataTable([";
string str2 = @"['Label', 'Value'],['MTBF'," + mtbfdisplay + @"],]);";
string str3 = @"var options = {
width: 400, height: 120, redFrom: 90, redTo: 100, yellowFrom: 75, yellowTo: 90, minorTicks: 5
};
var chart = new google.visualization.gauge(document.getelementbyid('chart-success'));
drawchart(data, options);";
string postData = str1 + str2 + str3;
Console.WriteLine(postData);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "test", postData, true);
}
}
}
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %>
xmlns="http://www.w3.org/1999/xhtml">
runat="server">
Replies
Know the answer? Post it — somebody with the same question will find it here.