WEB开发网
开发学院数据库MSSQL Server sqlserver2005的KPI展示控件开发详解 阅读

sqlserver2005的KPI展示控件开发详解

 2008-11-24 10:10:40 来源:WEB开发网   
核心提示: DataGridViewTrendColumn定义using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace KPIDisplayer{intern

DataGridViewTrendColumn定义

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace KPIDisplayer
{
  internal class DataGridViewTrendColumn : DataGridViewImageColumn
  {
    public DataGridViewTrendColumn()
    {
      CellTemplate = new DataGridViewTrendCell();
    }
  }
}

step3.取得analysis services 中的定义的KPI的信息和KPI的值。

/**//// <summary>
    /// 展示结果
    /// </summary>
    public void Display()
    {
      AdomdConnection myKPIConnection = new AdomdConnection(_connectString);
      _kpiDataSet = new KPIDataSet();
      KPIDataSet.KPIModelRow kpiRow;
      try
      {
        myKPIConnection.Open();
        CubeDef myCubeDef = myKPIConnection.Cubes[this._cubeName];
        AdomdCommand myKPICommand;
        foreach (Kpi k in myCubeDef.Kpis)
        {
          myKPICommand = new AdomdCommand();
          myKPICommand.Connection = myKPIConnection;
          StringBuilder sb = new StringBuilder();
          sb.Append("SELECT { ");
          sb.Append("KPIValue("" + k.Name + ""), ");
          sb.Append("KPIGoal("" + k.Name + ""), ");
          sb.Append("KPIStatus("" + k.Name + ""), ");
          sb.Append("KPITrend("" + k.Name + "")");
          sb.Append("} ON COLUMNS FROM ["+this._cubeName+"]");
          myKPICommand.CommandText = sb.ToString();
          CellSet cellset = myKPICommand.ExecuteCellSet();
          string kpiName = k.Name;
          string kpiValue = cellset.Cells[0].FormattedValue;
          string kpiGoal = cellset.Cells[1].FormattedValue;
          string kpiStatus = cellset.Cells[2].FormattedValue;
          string kpiTrend = cellset.Cells[3].FormattedValue;
          string kpiStatusGraph = k.StatusGraphic;
          string kpiTrendGraph = k.TrendGraphic;
          kpiRow = this._kpiDataSet.KPIModel.NewKPIModelRow();
          kpiRow.Name = kpiName;
          kpiRow.Value = Convert.ToDecimal(kpiValue);
          kpiRow.Goal = Convert.ToDecimal(kpiGoal);
          kpiRow.Status = kpiStatusGraph + "," + kpiStatus;
          kpiRow.Trend = kpiTrendGraph + "," + kpiTrend;
          this._kpiDataSet.KPIModel.AddKPIModelRow(kpiRow);
        }
      }
      catch (AdomdErrorResponseException myException)
      {
        MessageBox.Show(this, "连接Analysis Service服务器出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
      }
      catch (Exception ex)
      {
        MessageBox.Show(this, "未知错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
      }
      finally
      {
        myKPIConnection.Close();
      }

step4.绑定到DataGridView。

this.kpiDataGridView1.DataSource = this._kpiDataSet.KPIModel;

step5.搞定,运行。

sqlserver2005的KPI展示控件开发详解

上一页  1 2 3 

Tags:sqlserver KPI 展示

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接