Example #1
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);
     }
 }
Example #2
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");
        }
Example #3
0
        public ActionResult editAccount(AccountViewModel account)
        {
            if (!isLogin()) return RedirectToAction("login", "auth");
            User user = getCurrentUser();

            Account a = new Account()
            {
                Id=account.Id,
                Info=account.Info,
                Money=account.Money,
                State=account.State,
                Time=account.Time,
                Type=account.Type,
                UserId=account.UserId
            };
            Provider db = new Provider();
            db.updateAccount(a);

            int aid = account.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 });
                    tag = new Tag();
                    tag.Id = (int)db.getDataRow("SELECT Id FROM Tag ORDER BY Id DESC")["Id"];
                }
                db.insertAccountTag(aid, tag.Id);
            }

            string content = "<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='font-size:20px;'><a href='javascript:void(0)' class='btn_delete' onclick='showDeleteAccount(" + aid + ")'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>";

            return Content(content);
        }
Example #4
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);
        }
Example #5
0
 public void updateTag(Tag tag)
 {
     executeNonQuery("UPDATE Tag SET UserId=" + tag.UserId + ", Name='" + tag.Name + "', Count=" + tag.Count + " WHERE Id=" + tag.Id);
 }
Example #6
0
 public Tag toTag(DataRow data)
 {
     if (data == null) return null;
     Tag tag = new Tag();
     tag.Id = (int)data["Id"];
     tag.Name = (string)data["Name"];
     tag.UserId = (int)data["UserId"];
     tag.Count = (int)data["Count"];
     return tag;
 }
Example #7
0
 public void insertTag(Tag tag)
 {
     executeNonQuery("INSERT INTO Tag (UserId, Name, Count) VALUES (" + tag.UserId + ", '" + tag.Name + "', 0)");
 }