private void tabWeight_Enter(object sender, EventArgs e) { // load list box string lbxsql = "Select * From Weight WHERE FK_UserID = " + currentUser.UserID + " ORDER BY Date DESC"; //SQLiteDataReader lbxdata = new SQLiteCommand(lbxsql, database).ExecuteReader(); using (database = new SQLiteConnection("Data Source=FitThis.sqlite")) { try { database.Open(); } catch { // Load and connect to the DB when the form loads. DBManagement DB = new DBManagement(); this.database = DB.ConnectDB(database); database.Open(); } using (SQLiteDataReader lbxdata = new SQLiteCommand(lbxsql, database).ExecuteReader()) { lbxWeightLog.Items.Clear(); while (lbxdata.Read()) { //TODO Remove Time From Date Stamp //string date = lbxdata.GetDateTime(1).ToString(); lbxWeightLog.Items.Add(lbxdata["Date"] + "\t" + lbxdata["WeightRecorded"]); } lbxdata.Close(); } } // load labels (current and goal) lblGoalWeight.Text = currentUser.GoalWeight.ToString(); string currentweightsql = "Select WeightRecorded, Date FROM WEIGHT INNER JOIN USER ON User.UserID = Weight.FK_UserID " + "WHERE UserID = " + currentUser.UserID + " order by weightID desc"; using (database = new SQLiteConnection("Data Source=FitThis.sqlite")) { database.Open(); using (SQLiteDataReader curwght = new SQLiteCommand(currentweightsql, database).ExecuteReader()) { if (curwght.Read()) { this.lblCurrentWeight.Text = curwght[0].ToString(); } curwght.Close(); } database.Close(); } }
private void SignIn_Load(object sender, EventArgs e) { // When the sign in loads, check if the program database exists. DBManagement DB = new DBManagement(); DB.checkForFiles(); // Load the previous user lists based on database information. UserMgmt.FillLists(); // For each user name in the list, add it as an option to the // combobox dropdown selection menu on the sign in form. foreach (string s in UserMgmt.UserList) { this.cmbUser.Items.Add(s); } // Have the last user logged in as the default value in the combobox this.cmbUser.SelectedItem = UserMgmt.UserList[0]; }
/// <summary> /// Loads user information upon new user login. /// </summary> private void LoadUser() { tabConsole1.SelectedTab = tabDash; // Show the sign in form to find to create/select the current user. SignIn Si = new SignIn(); Si.ShowDialog(); // Set this form's current user field from the user selected at sign in. this.currentUser = Si.currentUserS; // If last login = null, show the about form. string checkLastLogin = "******" + currentUser.UserID.ToString(); using (SQLiteConnection c = new SQLiteConnection("Data Source=FitThis.sqlite")) { c.Open(); using (SQLiteCommand cmd = new SQLiteCommand(checkLastLogin, c)) { using (SQLiteDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { AboutForm AF = new AboutForm(); AF.ShowDialog(); } } } } // Update the last login field for the user. UserManagement UM = new UserManagement(); UM.UpdateLastLogin(currentUser); currentUserID = currentUser.UserID; // Load and connect to the DB when the form loads. DBManagement DB = new DBManagement(); this.database = DB.ConnectDB(database); Activity active = new Activity(); active.ImportData(dataGridActivity, ActivityChart); //Refresh Personal Info to form txtName.Text = currentUser.FName + " " + currentUser.LName; txtHeight.Text = currentUser.Height.ToString(); txtActLvl.Text = currentUser.ActivityLevel; txtStrtWght.Text = currentUser.CurrentWeight.ToString(); txtBMI.Text = currentUser.CalculateBMI().ToString(); txtBMR.Text = currentUser.CalculateBMR().ToString(); if (currentUser.UserID == 0) { Application.Exit(); } else { this.Show(); UpdateDashInfo(); } }