Ejemplo n.º 1
0
 public ActionResult list()
 {
     if (!isLogin()) return RedirectToAction("login", "auth");
     User user = getCurrentUser();
     Provider db = new Provider();
     List<User> mlist = db.getAllUser();
     List<UserViewModel> obj = new List<UserViewModel>();
     foreach (User u in mlist)
     {
         UserInfo ui=db.getUserInfo(u.Id);
         UserViewModel uv = new UserViewModel();
         uv.Id = u.Id;
         uv.IsAdmin = u.IsAdmin;
         uv.RegisterTime = u.RegisterTime;
         uv.UserName = u.UserName;
         uv.Address = ui.Address;
         uv.Email = ui.Email;
         uv.Info = ui.Info;
         uv.Phone = ui.Phone;
         obj.Add(uv);
     }
     UserListViewModel viewmodel = new UserListViewModel()
     {
         list=obj
     };
     return View(viewmodel);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
        public ActionResult edit(EditPasswordViewModel m)
        {
            m.Password = Global.md5(m.Password);
            m.Password1 = Global.md5(m.Password1);
            m.Password2 = Global.md5(m.Password2);

            if (!isLogin()) return RedirectToAction("login", "auth");
            Provider db = new Provider();
            if (m.Password1 != m.Password2)
            {
                ViewData["error"] = "两次密码不一样";
                return View();
            }
            User u = getCurrentUser();
            if (u.Password != m.Password)
            {
                ViewData["error"] = "密码错了,再试试吧";
                return View();
            }
            u.Password = m.Password1;
            db.updateUser(u);
            UserInfo ui = new UserInfo();
            ui.Id = u.Id;
            ui.Address = m.Address;
            ui.Phone = m.Phone;
            ui.Email = m.Email;
            ui.Info = m.Info;
            db.updateUserInfo(ui);
            return View("EditSuccess");
        }
Ejemplo n.º 4
0
 public static void addDefaultTag(int uid)
 {
     Provider db = new Provider();
     foreach (string t in DefaultTag)
     {
         Tag tag = new Tag()
         {
             Name = t,
             UserId = uid,
             Count = 0
         };
         db.insertTag(tag);
     }
 }
Ejemplo n.º 5
0
 public ActionResult edit(Note m)
 {
     try
     {
         Provider db = new Provider();
         db.updateNote(m);
         string content = "<td>" + m.Name + "</td><td>" + m.Content + "</td><td>" + m.SubmitTime.ToString("yyyy-MM-dd") + "</td><td style='font-size:20px;'><a href='javascript:void(0)' class='btn_edit' onclick='showEditNote(" + m.Id + ")'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td><td style='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteNote(" + m.Id + ")'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>";
         return Content(content);
     }
     catch (Exception e)
     {
         return Content("fail" + e.Message);
     }
 }
Ejemplo n.º 6
0
        public ActionResult delete(int id)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");

            Provider db = new Provider();
            try
            {
                db.deleteNote(id);
            }
            catch (Exception e)
            {
                return Content("fail" + e.Message);
            }
            return Content("ok");
        }
Ejemplo n.º 7
0
        public ActionResult edit()
        {
            if (!isLogin()) return RedirectToAction("login", "auth");

            Provider db = new Provider();
            User u=getCurrentUser();
            UserInfo userinfo=db.getUserInfo(u.Id);
            EditPasswordViewModel obj = new EditPasswordViewModel();
            obj.Address = userinfo.Address;
            obj.Phone = userinfo.Phone;
            obj.Email = userinfo.Email;
            obj.Info = userinfo.Info;
            obj.Password = "";
            obj.Password1 = "";
            obj.Password2 = "";
            return View(obj);
        }
Ejemplo n.º 8
0
        public ActionResult add(Note m)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();
            m.UserId = user.Id;
            m.SubmitTime = DateTime.Now;
            Provider db = new Provider();
            try
            {
                db.insertNote(m);
                int nid = (int)db.getDataRow("SELECT Id FROM Note ORDER BY Id DESC")["Id"];

                string content = "<tr id='note_item_" + nid + "'><td>" + m.Name+ "</td><td>" +m.Content + "</td><td>" + m.SubmitTime.ToString("yyyy-MM-dd") + "</td><td style='font-size:20px;'><a href='javascript:void(0)' class='btn_edit' onclick='showEditNote(" + nid + ")'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td><td style='style='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteNote(" + nid + ")'><span style='font-size:24px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>";
                return Content(content);
            }
            catch (Exception e)
            {
                return Content("fail" + e.Message);
            }
        }
Ejemplo n.º 9
0
        public ActionResult editTag(Tag tag)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            tag.UserId = user.Id;
            Provider db = new Provider();
            try
            {
                db.updateTag(tag);
                db.mergeTag(tag.Id, tag.Name);
            }
            catch (Exception e)
            {
                return Content("fail" + e.Message);
            }
            return Content("ok");
        }
Ejemplo n.º 10
0
 public ActionResult list()
 {
     if (!isLogin()) return RedirectToAction("login", "auth");
     User user = getCurrentUser();
     Provider db = new Provider();
     List<Note> mlist = db.getNotesByUser(user.Id);
     NoteListViewModel obj = new NoteListViewModel()
     {
         list = mlist
     };
     return View(obj);
 }
Ejemplo n.º 11
0
 public ActionResult login(LoginViewModel m)
 {
     if (m.Password == null || m.UserName == null)
     {
         ViewData["error"] = "没填的input伤不起";
         return View();
     }
     m.Password = Global.md5(m.Password);
     Provider db = new Provider();
     User user = db.getUser(m.UserName);
     if (user == null) {
         ViewData["error"] = "用户名不存在,要先注册有木有!!!";
         return View();
     }
     if (user.Password != m.Password)
     {
         ViewData["error"] = "密码错了,再试试吧";
         return View();
     }
     Session["user"] = user;
     if (user.IsAdmin)
     {
         return RedirectToAction("index", "admin");
     }
     return RedirectToAction("index","home");
 }
Ejemplo n.º 12
0
        public ActionResult addAccount(AccountViewModel account)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            account.SubmitTime = DateTime.Now;
            account.State = false;
            if (account.Info==null) account.Info = "";
            account.UserId = user.Id;

            Provider db=new Provider();
            db.insertAccount(account);

            int aid = (int)db.getDataRow("SELECT Id FROM Account ORDER BY Id DESC")["Id"];
            db.deleteAccountTagByAccount(aid);

            string[] tmp = account.Tag.Split(new char[] { ' ', ',', ',', ' ' });
            foreach (string t in tmp)
            {
                Tag tag = db.getTagsByName(t);
                if (tag == null)
                {
                    db.insertTag(new Tag() {Name=t,Count=0, UserId=user.Id });
                }
                db.insertAccountTag(aid, tag.Id);
            }
            string content = "<tr id='account_item_" + aid + "'><td>" + (account.Type ? "收入" : "支出") + "</td><td>" + account.Money + "</td><td>" + account.Time.ToString("yyyy-MM-dd") + "</td><td>" + account.Info + "</td><td>" + account.Tag + "</td><td style='font-size:20px;'><a href='javascript:void(0)' class='btn_edit' onclick='showEditAccount(" + aid + ")'> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td><td style='style='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteAccount(" + aid + ")'><span style='font-size:24px'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td></tr>";
            return Content(content);
        }
Ejemplo n.º 13
0
        public ActionResult addAccount()
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db = new Provider();
            ViewData["TagCloud"] = db.getTagsByUser(user.Id);

            return View();
        }
Ejemplo n.º 14
0
 public ActionResult taglist()
 {
     if (!isLogin()) return RedirectToAction("login", "auth");
     int uid = getCurrentUser().Id;
     Provider db = new Provider();
     TagListViewModel obj = new TagListViewModel()
     {
         list=db.getTagsByUser(uid)
     };
     return View(obj);
 }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
 public ActionResult edit(int id)
 {
     Provider db = new Provider();
     Note m = db.getNoteById(id);
     return View(m);
 }
Ejemplo n.º 17
0
        public ActionResult editAccount(int id)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db=new Provider();
            Account r=db.getAccount(id);
            if (user.Id != r.UserId) return View("msg", new MsgViewModel() { msg = "没有权限" });
            AccountViewModel obj = 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))
            };
            ViewData["TagCloud"] = db.getTagsByUser(user.Id);

            return View(obj);
        }
Ejemplo n.º 18
0
        public ActionResult addTag(Tag tag)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            tag.UserId = user.Id;
            tag.Count = 0;
            Provider db = new Provider();
            try
            {
                db.insertTag(tag);
            }
            catch (Exception e)
            {
                return Content("fail" + e.Message);
            }
            tag.Id=(int)db.getDataRow("SELECT Id FROM Tag ORDER BY Id DESC")["Id"];

            db.mergeTag(tag.Id, tag.Name);
            string content = "<li id='tag_item_+" + tag.Id + "> <span class='tag_name'>" + tag.Name + " </span><a href='javascript:void(0)' onclick='showEditTag(" + tag.Id + ")'>编辑</a> | <a href='javascript:void(0)' onclick='showDeleteTag(" + tag.Id + ")'>删除</a></li>";
            return Content(content);
        }
Ejemplo n.º 19
0
        public ActionResult detail(int id = 1)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db = new Provider();
            Account account = db.getAccount(id);

            if (account == null) return View("msg", new MsgViewModel() { msg = "出错了肿么办...页面不存在", url = "/" });
            if (account.UserId != user.Id) return View("msg", new MsgViewModel() { msg = "没有权限...看别人隐私的不是好孩纸" });

            return View(account);
        }
Ejemplo n.º 20
0
        public ActionResult deleteTag(int id)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db = new Provider();
            try
            {
                db.deleteAccountTagByTag(id);
                db.deleteTag(id);
            }
            catch (Exception e)
            {
                return Content("fail" + e.Message);
            }
            return Content("ok");
        }
Ejemplo n.º 21
0
        public ActionResult editTagList()
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Provider db = new Provider();
            List<Tag> tags = db.getTagsByUser(user.Id);
            TagListViewModel obj = new TagListViewModel()
            {
                list = tags
            };

            return View(obj);
        }
Ejemplo n.º 22
0
        public ActionResult register(RegisterViewModel m)
        {
            if (m.UserName==null || m.Password1 == null || m.Password2 == null)
            {
                ViewData["error"] = "没填的input伤不起";
                return View();
            }
            m.Password1 = Global.md5(m.Password1);
            m.Password2 = Global.md5(m.Password2);
            Provider db = new Provider();
            User user = db.getUser(m.UserName);
            if (user != null)
            {
                ViewData["error"] = "哎呀,此用户名已经被注册了";
                return View();
            }
            if (m.Password1 != m.Password2)
            {
                ViewData["error"] = "两次密码不一样";
                return View();
            }
            Regex emailExp = new Regex(@"^\w+@\w+(\.\w+)+(\,\w+@\w+(\.\w+)+)*$");
            if (!string.IsNullOrEmpty(m.Email) && !emailExp.Match(m.Email).Success)
            {
                ViewData["error"] = "邮箱格式不正确";
                return View();
            }

            User u = new User();
            u.UserName = m.UserName;
            u.Password = m.Password1;
            u.RegisterTime = DateTime.Now;
            db.insertUser(u);

            int uid = (int)db.getDataRow("SELECT Id FROM [User] ORDER BY Id DESC")["Id"];
            Global.addDefaultTag(uid);

            UserInfo userinfo = new UserInfo();
            userinfo.Id = uid;
            userinfo.Address = m.Address;
            userinfo.Email = m.Email;
            userinfo.Phone = m.Phone;
            userinfo.Info = "";
            db.insertUserInfo(userinfo);
            return View("msg", new MsgViewModel() { msg = "注册成功", url = "/auth/login" });
        }