|
以下为代码的内容:
/// <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(); } |