public string GetString(int decimalDigitCount) { StringBuilder b = new StringBuilder(); b.Append("["); for (int row = 0; row <= RowCount - 1; row++) { for (int column = 0; column <= ColumnCount - 1; column++) { double value = this[row, column]; string valueString; if (double.IsNaN(value)) { valueString = "-"; } else if (decimalDigitCount >= 0) { valueString = NumberFormatter.ForDecimalDigits(decimalDigitCount).ToText(value); } else { valueString = value.ToString(); } b.Append(valueString).Append(column == ColumnCount - 1 ? "; " : ", "); } } string s = b.ToString(); if (s.EndsWith("; ")) { s = s.Substring(0, s.Length - 2); } return(s + "]"); }
private void BuildChaptor2() { db.Title("二 步骤", 0); int seq = 0; foreach (Step step in context.Steps) { seq++; db.Br(); db.T1(string.Format("2.{0} {1}", seq, step.SourceExpression.Title)); db.P(step.SourceExpression.Description); db.Image(step.Image, "Graph" + seq + ".png"); foreach (string variable in step.OutVariables) { object value = context.GetValue(variable); if (value is Matrix) { db.P(variable); db.P((value as Matrix).GetString(context.Settings.DecimalDigitCount)); } else if (value is Bitmap) { db.P(variable); db.Image(value as Bitmap, variable + ".png"); } else { db.P(string.Format("{0}: {1}", variable, value is double? NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText((double)value) : value.ToString()) ); } } } }
public string GetString(int decimalDigitCount) { StringBuilder b = new StringBuilder(); b.Append("["); for (int i = 0; i <= Size - 1; i++) { double value = Items[i]; string valueString; if (double.IsNaN(value)) { valueString = "-"; } else if (decimalDigitCount >= 0) { valueString = NumberFormatter.ForDecimalDigits(decimalDigitCount).ToText(value); } else { valueString = value.ToString(); } b.Append(valueString).Append(", "); } string s = b.ToString(); if (s.EndsWith(", ")) { s = s.Substring(0, s.Length - 2); } return(s + "]"); }
public JobStepAreaVM(EvaluationContext context, Step step, int stepIndex, int updateCount) { Index = stepIndex; Title = step.SourceExpression.Title; Description = step.SourceExpression.Description; ImageUrl = "/Home/GetStepImage?stepIndex=" + stepIndex + "&updateCount=" + updateCount; ResultVariables = new ResultVariableVM[step.OutVariables.Length]; for (int i = 0; i <= step.OutVariables.Length - 1; i++) { string variableName = step.OutVariables[i]; object value = context.GetValue(variableName); Style style = context.Plan.Styles.FirstOrDefault(j => j.Target == variableName); int columnCount = 0; string[] rowNames = null; string[] columnNames = null; string[][] cells = null; string displayText = null; string url = null; if (value == null) { displayText = "?"; } else if (value is Matrix || value is Vector) { Matrix m = value is Matrix ? value as Matrix : new Matrix(1, (value as Vector).Size, (value as Vector).Items); cells = new string[m.RowCount][]; string styleRowName = style == null || string.IsNullOrEmpty(style.RowName) ? null : style.RowName; string[] styleRowNames = styleRowName == null || !styleRowName.Contains(",") ? null : styleRowName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); rowNames = new string[m.RowCount]; for (int row = 0; row <= m.RowCount - 1; row++) { string rowName; if (styleRowNames != null) { rowName = row <= styleRowNames.Length - 1 ? styleRowNames[row] : string.Format(styleRowName, row + 1); } else { rowName = styleRowName == null ? (row + 1).ToString() : string.Format(style.RowName, row + 1); } rowNames[row] = rowName; } columnCount = m.ColumnCount; columnNames = new string[m.ColumnCount]; for (int column = 0; column <= m.ColumnCount - 1; column++) { columnNames[column] = style == null || style.ColumnNames == null || column > style.ColumnNames.Length - 1 ? (column + 1).ToString() : style.ColumnNames[column]; } for (int row = 0; row <= m.RowCount - 1; row++) { cells[row] = new string[m.ColumnCount]; for (int column = 0; column <= m.ColumnCount - 1; column++) { double d = m[row, column]; cells[row][column] = double.IsNaN(d) ? "-" : NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText(d); } } } else if (value is Bitmap) { url = string.Format("/Home/GetResultImage?stepIndex={0}&variableIndex={1}×tamp={2}", stepIndex, i, DateTime.Now.ToString()); } else if (value is double) { displayText = NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText((double)value); } else if (value is int[] || value is double[]) { Array items = value as Array; StringBuilder b = new StringBuilder(); b.Append("["); for (int j = 0; j <= items.Length - 1; j++) { b.Append(NumberFormatter.ForDecimalDigits(context.Settings.DecimalDigitCount).ToText(Convert.ToDouble(items.GetValue(j)))); b.Append(j < items.Length - 1 ? "," : ""); } b.Append("]"); displayText = b.ToString(); } else { displayText = value.ToString().Replace("\r\n", "<br />"); } ResultVariables[i] = new ResultVariableVM() { Name = step.OutVariables[i], ColumnCount = columnCount, RowNames = rowNames, ColumnNames = columnNames, Cells = cells, Value = displayText, Url = url, Description = context.Plan.Variables.FirstOrDefault(m => m.Name == step.OutVariables[i]) == null ? "" : context.Plan.Variables.FirstOrDefault(m => m.Name == step.OutVariables[i]).Description }; } InVariables = new InVariableVM[step.InSourceVariables.Length]; for (int i = 0; i <= step.InSourceVariables.Length - 1; i++) { SourceVariable variable = step.InSourceVariables[i]; InVariables[i] = new InVariableVM() { Index = i, Name = variable.Name, Type = Strings.Of(variable), IsMatrix = variable.Type == DataType.Matrix || variable.Type == DataType.Vector, Value = step.InValues[i] == null ? string.Empty : getValue(step.InValues[i], context), Description = step.InSourceVariables[i].Description, }; } }