public ActionResult accountList(string tags="", string starttime="", string endtime="") { if (!isLogin()) return RedirectToAction("login", "auth"); User user=getCurrentUser(); Provider db = new Provider(); List<Account> result = new List<Account>(); tags = tags.Trim(); if (String.IsNullOrEmpty(tags)) { if (String.IsNullOrEmpty(starttime)) { result = db.getAccountsByUser(user.Id); } else { result = db.getAccountsByDate(user.Id, Convert.ToDateTime(starttime), Convert.ToDateTime(endtime)); } } else { string[] tagarray = tags.Split(new char[] { ',','|',' ' }); List<int> tagIds = new List<int>(); foreach (string s in tagarray) { try { tagIds.Add(Convert.ToInt32(s)); } catch (Exception e) { Console.WriteLine(e.Message); continue; } } List<Account> tmp = db.getAccountsByTags(tagIds); if (String.IsNullOrEmpty(starttime)) { result = tmp; } else { DateTime start=Convert.ToDateTime(starttime); DateTime end=Convert.ToDateTime(endtime); foreach (Account a in tmp) { if (a.Time >= start && a.Time <= end) result.Add(a); } } } AccountListViewModel obj = new AccountListViewModel(); obj.list=new List<AccountViewModel>(); foreach (Account r in result) { obj.list.Add(new AccountViewModel() { Id=r.Id, Info=r.Info, Money=r.Money, State=r.State, SubmitTime=r.SubmitTime, Time=r.Time, Type=r.Type, UserId=r.UserId, Tag=getTagString(db.getTagsByAccount(r.Id)) }); } return View(obj); }
public ActionResult statics(string tags="", string starttime="", string endtime="") { if (!isLogin()) return RedirectToAction("login", "auth"); User user=getCurrentUser(); Provider db = new Provider(); List<Account> result = new List<Account>(); tags = tags.Trim(); if (String.IsNullOrEmpty(tags)) { if (String.IsNullOrEmpty(starttime)) { result = db.getAccountsByUser(user.Id); } else { result = db.getAccountsByDate(user.Id, Convert.ToDateTime(starttime), Convert.ToDateTime(endtime)); } } else { string[] tagarray = tags.Split(new char[] { ',','|',' ' }); List<int> tagIds = new List<int>(); foreach (string s in tagarray) { try { tagIds.Add(Convert.ToInt32(s)); } catch (Exception e) { Console.WriteLine(e.Message); continue; } } List<Account> tmp = db.getAccountsByTags(tagIds); if (String.IsNullOrEmpty(starttime)) { result = tmp; } else { DateTime start=Convert.ToDateTime(starttime); DateTime end=Convert.ToDateTime(endtime); foreach (Account a in tmp) { if (a.Time >= start && a.Time <= end) result.Add(a); } } } double tincome = 0; double toutcome = 0; Dictionary<string, double> ttagout = new Dictionary<string, double>(); Dictionary<string, double> ttagin = new Dictionary<string, double>(); Dictionary<long, double> inchart = new Dictionary<long, double>(); Dictionary<long, double> outchart = new Dictionary<long, double>(); Dictionary<long, double> chart = new Dictionary<long, double>(); foreach (Account a in result) { if (a.Type == false) toutcome += a.Money; else tincome += a.Money; List<Tag> tlist = db.getTagsByAccount(a.Id); foreach (Tag tt in tlist) { if (!ttagin.ContainsKey(tt.Name) || !ttagout.ContainsKey(tt.Name)) { ttagin[tt.Name] = 0; ttagout[tt.Name] = 0; } if (a.Type == false) ttagout[tt.Name] += a.Money; else ttagin[tt.Name] += a.Money; } long ts = Global.getTimestamp(a.Time); if (!chart.ContainsKey(ts)) chart[ts] = 0; if (!inchart.ContainsKey(ts)) inchart[ts] = 0; if (!outchart.ContainsKey(ts)) outchart[ts] = 0; if (a.Type == false) { chart[ts] -= a.Money; inchart[ts] += a.Money; } else { chart[ts] += a.Money; outchart[ts] += a.Money; } } StaticsViewModel obj = new StaticsViewModel() { income = tincome, outcome = toutcome, tagin = ttagin, tagout = ttagout, schart = chart, ichart= inchart, ochart = outchart }; return View(obj); }