private static Dictionary<String, List<PerformanceValue>> GetChartDatas(SqlDatabase db, DbCommand cmd) { Dictionary<String, List<PerformanceValue>> results = new Dictionary<String, List<PerformanceValue>>(); List<PerformanceValue> caseValue = new List<PerformanceValue>(); try { using (IDataReader reader = db.ExecuteReader(cmd)) { if(reader.Read()) { DateTime d = Convert.ToDateTime(reader[1]); string controlName = Convert.ToString(reader[0]).TrimEnd(); double value = Convert.ToDouble(reader[2]); caseValue.Add(new PerformanceValue(){ Date=d, Value=value} ); results.Add(controlName, caseValue); } while (reader.Read()) { string controlName = Convert.ToString(reader[0]).TrimEnd(); if(!results.ContainsKey(controlName)) { caseValue = new List<PerformanceValue>(); results.Add(controlName, caseValue); } DateTime d = Convert.ToDateTime(reader[1]); PerformanceValue pv = new PerformanceValue() { Value = Convert.ToDouble(reader[2]), Date = new DateTime(d.Year, d.Month, d.Day) }; caseValue.Add(pv); } } } catch (SqlException ex) { throw new Exception("access db failed.", ex); } return results; }
public static List<PerformanceValue> GetMainControlValuesList(Int32 reduceDay, String caseName, String watcherName, String assemblyType) { SqlDatabase db = new SqlDatabase(_connString); DbCommand cmd = db.GetStoredProcCommand("TestCases_SelectValuesOfMainControl"); DbParameter p1 = cmd.CreateParameter(); DbParameter p2 = cmd.CreateParameter(); DbParameter p3 = cmd.CreateParameter(); DbParameter p4 = cmd.CreateParameter(); p1.ParameterName = "@TestTimeFrom"; p1.Value = DateTime.Now.AddDays(-reduceDay); p2.ParameterName = "@CaseName"; p2.Value = caseName; p3.ParameterName = "@WatherName"; p3.Value = watcherName; p4.ParameterName = "@AssemblyType"; p4.Value = assemblyType; cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Parameters.Add(p3); cmd.Parameters.Add(p4); List<PerformanceValue> caseValues = new List<PerformanceValue>(); try { using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { DateTime d = Convert.ToDateTime(reader[1]); //String temp = d.Year.ToString() + "-" + d.Month.ToString() + "-" + d.Day.ToString(); PerformanceValue pv = new PerformanceValue() { Value = Convert.ToDouble(reader[0]), Date = new DateTime(d.Year, d.Month, d.Day) }; caseValues.Add(pv); } } } catch (SqlException ex) { throw new Exception("access db failed.", ex); } // return runIDs.Count > 0 ? runIDs : null; return caseValues; }