private void signUp()
        {
            mode = Mode.Insert;
            CUser tempUser = new CUser(CUser.UserCount, tbUsername.Text, tbPassword.Text, 10, 10, 10, CTree.TreeCount);
            CTree tempTree = new CTree(CTree.TreeCount, tempUser.Username, "exampleSpecies", 0, 10, 10);

            if (tbPassword.Text != "" && tbUsername.Text != "")
            {
                using (var db = new ModelUsers())
                {
                    user = new User
                    {
                        userId     = CUser.UserCount,
                        username   = tempUser.Username,
                        password   = tempUser.Password,
                        money      = tempUser.Money,
                        fertilizer = tempUser.Fertilizer,
                        water      = tempUser.Water,
                        treeID     = tempUser.TreeId
                    };
                    db.Users.Add(user);
                    db.SaveChanges();
                }
                using (var db = new ModelTrees())
                {
                    tree = new Tree
                    {
                        treeId        = tempTree.TreeId,
                        ownerUserName = tempUser.Username,
                        species       = tempTree.Species,
                        hydration     = tempTree.Hydration,
                        health        = tempTree.Health,
                        growth        = tempTree.Growth
                    };
                    db.Trees.Add(tree);
                    db.SaveChanges();
                }

                CUser.increaseUserCount();
                CTree.increaseTreeCount();
                Tree1 newTree1 = new Tree1(tempUser, tempTree);
                newTree1.ShowDialog();
            }
        }
示例#2
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ModelUsers())
     {
         var result = db.Users.SingleOrDefault(k => k.username == myUser.Username);
         if (result != null)
         {
             result.money      = myUser.Money;
             result.fertilizer = myUser.Fertilizer;
             result.water      = myUser.Water;
         }
     }
     using (var db = new ModelTrees())
     {
         var result = db.Trees.SingleOrDefault(k => k.treeId == myTree.TreeId);
         if (result != null)
         {
             result.growth    = myTree.Growth;
             result.health    = myTree.Health;
             result.hydration = myTree.Hydration;
         }
     }
 }
        private void signIn()
        {
            CUser tempUser = new CUser(0, "PLEASE RELOGIN USERNAME NOT FOUND", "temp", 0, 0, 0, 0);
            CTree tempTree = new CTree(0, "temp", "temp", 0, 0, 0);

            using (var db = new ModelUsers())
            {
                var query = from user in db.Users where user.username == tbUsername.Text && user.password == tbPassword.Text select user;
                foreach (var item in query)
                {
                    tempUser.Username   = user.username;
                    tempUser.Password   = user.password;
                    tempUser.Money      = user.money;
                    tempUser.Fertilizer = user.fertilizer;
                    tempUser.Water      = user.water;
                    tempUser.TreeId     = user.treeID;
                }
            }
            using (var db = new ModelTrees())
            {
                var query = from tree in db.Trees where tree.treeId == tempUser.TreeId select tree;
                foreach (var item in query)
                {
                    tempTree.TreeId        = tree.treeId;
                    tempTree.OwnerUserName = tree.ownerUserName;
                    tempTree.Species       = tree.species;
                    tempTree.Hydration     = tree.hydration;
                    tempTree.Health        = tree.health;
                    tempTree.Growth        = tree.growth;
                }
            }

            Tree1 newTree1 = new Tree1(tempUser, tempTree);

            newTree1.ShowDialog();
        }