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(); } }
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(); }
public Tree1(CUser tempUser, CTree tempTree) { InitializeComponent(); myUser = tempUser; myTree = tempTree; lblUsername.Content = myUser.Username; lblSpecies.Content = myTree.Species; System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); void dispatcherTimer_Tick(object sender, EventArgs e) //every 1s, execute block of command between parentheses { update(); mytreeUpdate(); } System.Windows.Threading.DispatcherTimer dispatcherTimer2 = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer2.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer2.Interval = new TimeSpan(1, 0, 0); dispatcherTimer2.Start(); void dispatcherTimer2_Tick(object sender, EventArgs e) //every 1h, execute block of command between parentheses { myTree.hydrationLoss(); } void update() { myTree.checkStatus(); myTree.updateTree(); TbMoney.Text = myUser.Money.ToString(); TbFertilizer.Text = myUser.Fertilizer.ToString(); TbWater.Text = myUser.Water.ToString(); lbStatus.Text = myTree.Status; } //karena percobaan assignment bitmap via class gagal, sementara saya hardcode agar fungsionalitas bagian lain app dapat diperlihatkan. void mytreeUpdate() { if (myTree.GrowthPhase == 1 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1s.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1dh.jpg")); } else if (myTree.GrowthPhase == 1 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/1snh.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2s.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2dh.jpg")); } else if (myTree.GrowthPhase == 2 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/2snh.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3s.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3dh.jpg")); } else if (myTree.GrowthPhase == 3 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/3snh.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == false & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == true & myTree.IsDehydrated == false) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4s.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == false & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4dh.jpg")); } else if (myTree.GrowthPhase == 4 & myTree.IsSick == true & myTree.IsDehydrated == true) { myTreeIMG.Source = new BitmapImage(new Uri("pack://application:,,,/Image/4snh.jpg")); } } }