public static IEnumerable <NyModel> Getdata(int year, int month) { List <NyModel> resultlist = new List <NyModel>(); int maxdayinthismonth = DateTime.DaysInMonth(year, month); for (int i = 1; i <= maxdayinthismonth; i++) { string cmd = "select TagName, sum(Val) as sumval from " + "(select TagName,Val,DateAndTime from FloatTable where DateAndTime between @date1 and @date2) " + "as dt group by tagname "; var startdate = new DateTime(year, month, i); var date1 = new SqlParameter() { ParameterName = "@date1", Value = startdate, }; var enddate = startdate.AddHours(24.0); var date2 = new SqlParameter() { ParameterName = "@date2", Value = enddate, }; var s = SqlHelper.ExecuteReader(CommandType.Text, cmd, date1, date2); using (s) { if (s.HasRows) { while (s.Read()) { var model = new NyModel { TagDate = startdate, TagName = TagnameDict[s[0].ToString()], Tagval = float.Parse(string.IsNullOrEmpty(s[1].ToString())?"0f":s[1].ToString()) }; resultlist.Add(model); } } else { foreach (var kv in TagnameDict) { var model = new NyModel { TagDate = startdate, TagName = kv.Value, Tagval = 0f }; resultlist.Add(model); } } } } return(resultlist.ToList()); }
public static IEnumerable<NyModel> Getdata(int year,int month) { List<NyModel> resultlist=new List<NyModel>(); int maxdayinthismonth = DateTime.DaysInMonth(year, month); for (int i = 1; i<=maxdayinthismonth; i++) { string cmd = "select TagName, sum(Val) as sumval from " + "(select TagName,Val,DateAndTime from FloatTable where DateAndTime between @date1 and @date2) " + "as dt group by tagname "; var startdate = new DateTime(year, month, i); var date1 = new SqlParameter() { ParameterName = "@date1", Value = startdate, }; var enddate = startdate.AddHours(24.0); var date2 = new SqlParameter() { ParameterName = "@date2", Value = enddate, }; var s = SqlHelper.ExecuteReader(CommandType.Text, cmd,date1,date2); using (s) { if (s.HasRows) { while (s.Read()) { var model = new NyModel { TagDate = startdate, TagName =TagnameDict[s[0].ToString()], Tagval = float.Parse(string.IsNullOrEmpty(s[1].ToString())?"0f":s[1].ToString()) }; resultlist.Add(model); } } else { foreach (var kv in TagnameDict) { var model = new NyModel { TagDate = startdate,TagName =kv.Value,Tagval =0f}; resultlist.Add(model); } } } } return resultlist.ToList(); }