protected ChartViewModel InitModelWithVarAndStation(int? varId, int? StatId) { var model = new ChartViewModel(); model.VarId = varId.GetValueOrDefault(16); model.VarName = Helper.Vars[model.VarId].PageName; model.Vars = new SelectList(Helper.VarsTable.Select(x => new { Id = x.Id, PageName = T.Text(x.PageName) }), "Id", "PageName", model.VarId); model.StatId = StatId.GetValueOrDefault(0); var st = Repo.GetStations(model.VarId); model.Stations = new SelectList(st, "st_id", "st_name", model.StatId); model.Date = DateTime.Now; return model; }
public ActionResult Search(int? varId, int? StatId, string date) { var model = new ChartViewModel(); model.VarId = varId.GetValueOrDefault(16); model.StatId = StatId.GetValueOrDefault(0); var act = Request.Params["act"]; if (StatId.HasValue) LoadData(date, act, 1, model); return PartialView("_partChartTable", model); }
private void LoadData(string date, string act, int pg, ChartViewModel model) { var sql = DBHelper.SQLGetValByVarAndStat(model.VarId, model.StatId); var d = ParseDate(date); d = new DateTime(d.Year, d.Month, 1); if (act == "prev") d = d.AddMonths(-1); if (act == "next") d = d.AddMonths(1); model.Date = d; sql = sql.Where(" time_utc>=@0 and time_utc<@1", d, d.AddMonths(1)); sql = sql.OrderBy("time_utc asc"); model.Items = db.Page<TableValue>(pg, 3000, sql).Items; }
private void LoadData(string date, string act, int _pg, ChartViewModel model) { var sql = DBHelper.SQLGetValByVarAndStat(model.VarId, model.StatId); DateTime d; if (DateTime.TryParse(date, out d)) { model.Date = d; if (model.VarId == 8 || model.VarId == 2) sql = sql.Where(" time_utc>=@0 and time_utc<@1", d, d.AddMonths(1)); else sql = sql.Where(" time_utc>=@0 and time_utc<@1", d, d.AddDays(1)); } sql = sql.OrderBy("time_utc asc"); model.Page = db.Page<TableValue>(_pg, Helper.PageSize, sql); }