Last active
August 29, 2015 14:18
-
-
Save leestuartx/ff17dfab093090679f1c to your computer and use it in GitHub Desktop.
Database Manipulation, specifically used in Project Trak application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class DBManip_PHP : MonoBehaviour { | |
private string prefixURL = "http://localhost/"; | |
public string getProjectsURL = "getProjectList.php?"; | |
//Admin Control | |
private string createNewProjectURL = "addNewProject.php?"; | |
//Stats Bar | |
public string addStatEntryURL = "addStatEntry.php?"; | |
public string getTrackingList = "getTrackingTypes.php?"; | |
public string getTrackingEntriesURL = "getTrackingEntries.php?"; | |
public string getRemainingReqsURL = "getRemainingRequirements.php?"; | |
//TaskLists | |
private string getProjectTasksURL = "getProjectTasks.php?"; | |
private string getProjectTasksByURL = "getProjectTasksBy.php?"; | |
private string addNewTaskURL = "addTask.php?"; | |
private string updateTaskURL = "updateTask.php?"; | |
private string deleteTaskURL = "deleteTask.php?"; | |
private string disableTaskURL = "disableTask.php?"; | |
private string updatePriorityURL = "setPriority.php?"; | |
private string loginURL = "remoteLogin.php?"; | |
private string registerURL = "register.php?"; | |
private string createUserTables = "createNewTablesForUser.php?"; | |
private WWW retrievedData; | |
private bool inFirst; | |
private bool waitActive; | |
// Update is called once per frame | |
public void AddNewTrackEntry(string username, string curProject, string trackingType, string postingDate,int totalV1,int totalV2, int totalV3){ | |
if (curProject != "" && trackingType != ""){ | |
trackingType = RemoveAllSpacesSquigly(trackingType); | |
curProject = RemoveAllSpacesSquigly(curProject); | |
curProject = RemoveAllSpaces(curProject); | |
string postingData = "curUser=" + username + "&projName=" + curProject + "&trackingType=" + trackingType + "&postingDate=" + postingDate + "&var1=" + totalV1 + "&var2=" + totalV2 + "&var3=" + totalV3; | |
Debug.Log("adding tracking entry for : " + postingData); | |
StartCoroutine(PostData(addStatEntryURL + postingData, 1)); | |
} | |
} | |
public void CreateUserTables(string username){ // Create a table, name, column array, column type array | |
if (username != ""){ | |
string postingData = "curUser=" + username; | |
Debug.Log("Creating User Tables"); | |
StartCoroutine(PostData(createUserTables + postingData, 5)); | |
} | |
} | |
public void CreateNewProjectTable(string username, string projectName){ // Create a table, name, column array, column type array | |
if (username != "" && projectName != "" && projectName != "Project Name"){ | |
projectName = RemoveAllSpacesSquigly(projectName); | |
string postingData = "curUser=" + username + "&projectName=" + projectName; | |
Debug.Log("Creating new table for " + projectName); | |
StartCoroutine(PostData(createNewProjectURL + postingData, 5)); | |
} | |
} | |
public void AddNewTask(string username, string taskName,string taskCategory,string projectName){ | |
taskName = RemoveAllSpacesSquigly(taskName); | |
projectName = RemoveAllSpacesSquigly(projectName); | |
projectName = RemoveAllSpaces(projectName); | |
taskCategory = RemoveAllSpacesSquigly(taskCategory); | |
string postingData = "curUser=" + username + "&taskName=" + taskName + "&taskCategory=" + taskCategory + "&projectName=" + projectName; | |
StartCoroutine(PostData(addNewTaskURL + postingData, 2)); | |
} | |
public void UpdateTask(string username, string taskName,string taskCategory,string projectName, int oldID, int newPriority, int estHour, int estdMin,string subCategoryName, | |
int reorderNum, int taskDisabled){ | |
taskName = RemoveAllSpacesSquigly(taskName); | |
projectName = RemoveAllSpacesSquigly(projectName); | |
projectName = RemoveAllSpaces(projectName); | |
taskCategory = RemoveAllSpacesSquigly(taskCategory); | |
subCategoryName = RemoveAllSpacesSquigly(subCategoryName); | |
string postingData = "curUser=" + username +"&taskName=" + taskName + "&taskCategory=" + taskCategory + "&projectName=" + projectName + "&thisID=" + oldID; | |
postingData+= "&np=" + newPriority + "&estH=" + estHour + "&estM=" + estdMin + "&scName="+ subCategoryName + "&reNum=" +reorderNum + "&dis="+taskDisabled; | |
StartCoroutine(PostData(updateTaskURL + postingData, 3)); | |
Debug.Log("Updating Task"); | |
} | |
public void DeleteTask(string username, int oldID){ | |
string postingData = "curUser=" + username + "&thisID=" + oldID; | |
StartCoroutine(PostData(deleteTaskURL + postingData, 4)); | |
Debug.Log("Deleting Task"); | |
} | |
public void EnableDisableTask(string username, int oldID,bool isEnabled){ | |
int enabledBool = 0; | |
if (isEnabled) | |
enabledBool = 1; | |
string postingData = "curUser=" + username + "&thisID=" + oldID + "&isEnabled=" + enabledBool ; | |
StartCoroutine(PostData(disableTaskURL + postingData, 5)); | |
Debug.Log("EnableDisable Task"); | |
} | |
public void UpdateTaskPriority(string username, int oldID, int newPriority){ | |
//Update the server with the new task priority | |
string postingData = "curUser=" + username +"&thisID=" + oldID + "&priority=" + newPriority ; | |
StartCoroutine(PostData(updatePriorityURL + postingData, 6)); | |
Debug.Log("Updating Task Priority"); | |
} | |
public string RemoveAllSpacesSquigly(string inputString){ | |
string txt = inputString; | |
char[] charsToTrim = { ' ' }; | |
txt = txt.Trim(charsToTrim); // txt = "i am a string" | |
//Remove any offending characters that will corrupt the table | |
char[] trimComma = { ':' }; | |
txt = txt.Trim(trimComma); | |
//char[] trimAppo = { '\'' }; | |
string newText = txt.Replace(@"'",""); | |
//Remove semicolon as it breaks up entries from the table into rows in this program | |
newText = txt.Replace(@";",""); | |
return newText.Replace(" ", "~"); // txt = "iamastring" | |
} | |
public string RemoveAllSpaces(string inputString){ | |
string txt = inputString; | |
char[] charsToTrim = { ' ' }; | |
txt = txt.Trim(charsToTrim); // txt = "i am a string" | |
txt = txt.Replace(" ", ""); // txt = "iamastring" | |
txt = txt.Replace(System.Environment.NewLine, ""); | |
// Debug.Log("Do we have spaces:"+txt+"secondword"); | |
return txt; | |
} | |
public void SetStatus(string msg){ | |
//Forward the message to SQLDB_Manip status label | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.SetStatus(msg); | |
} | |
public void GetExerciseList(string username, string curProject){ | |
SetStatus("Getting exercise list"); | |
inFirst=true; | |
curProject = RemoveAllSpacesSquigly(curProject); | |
string strGet = "curUser=" + username + "&trackType=" + curProject; | |
StartCoroutine(GetURLData(1,getTrackingList,strGet)); //ExerciseList | |
StartCoroutine(SortURLData(1,getTrackingList,strGet)); | |
} | |
public void DoLogin(string curUser, string curPassword){ | |
SetStatus("Trying to login"); | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.SetLoginStatus("Logging in, please wait..."); | |
inFirst=true; | |
StartCoroutine(GetURLData(8,loginURL,"curUser=" + curUser + "&curPass=" + curPassword)); //ExerciseList | |
StartCoroutine(SortURLData(8,loginURL,"curUser=" + curUser + "&curPass=" + curPassword)); | |
} | |
public void DoRegister(string curUser, string curPassword){ | |
SetStatus("Trying to register"); | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.SetLoginStatus("Registering please wait..."); | |
inFirst=true; | |
StartCoroutine(GetURLData(7,registerURL,"curUser=" + curUser + "&curPass=" + curPassword)); //ExerciseList | |
StartCoroutine(SortURLData(7,registerURL,"curUser=" + curUser + "&curPass=" + curPassword)); | |
} | |
public IEnumerator GetRemainingRequirements(string curUser, string curProject){ | |
SetStatus("Getting remaining exercises"); | |
inFirst=true; | |
curProject = RemoveAllSpacesSquigly(curProject); | |
string getStr = "curUser=" + curUser + "&curProj=" + curProject; | |
StartCoroutine(GetURLData(6,getRemainingReqsURL,getStr)); | |
yield return StartCoroutine(SortURLData(6,getRemainingReqsURL,getStr)); | |
} | |
public void GetProjects(string curUsername){ | |
SetStatus("Getting project list"); | |
inFirst=true; | |
StartCoroutine(GetURLData(2,getProjectsURL,"curUser=" + curUsername)); //Projects List | |
StartCoroutine(SortURLData(2,getProjectsURL,"curUser=" + curUsername)); | |
} | |
public void GetTrackingEntries(string curUsername, string trackingeType, string projName){ //Exercise Entries | |
SetStatus("Getting exercise entries"); | |
trackingeType = RemoveAllSpacesSquigly(trackingeType); | |
projName = RemoveAllSpacesSquigly(projName); | |
trackingeType = RemoveAllSpaces(trackingeType); | |
string getStr = "curUser=" + curUsername + "&trackingType="+ trackingeType + "&projName=" + projName; | |
inFirst=true; | |
StartCoroutine(GetURLData(3,getTrackingEntriesURL,getStr)); | |
StartCoroutine(SortURLData(3,getTrackingEntriesURL,getStr)); | |
} | |
public void DebugOutput(List<List<string>> listValues){ | |
List<string> tempList = new List<string>(); | |
for (int i = 0; i < listValues.Count; i++){ //Rows | |
List<string> currentRow = listValues[i]; | |
for (int k = 0; k < currentRow.Count; k++){ //Columns | |
string currentColumn = currentRow[k]; | |
tempList.Add(currentColumn); | |
} | |
} | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.FillListRemainingExercises(tempList); | |
} | |
public void GetProjectTaskList(string username, string projectName){ | |
SetStatus("Getting project tasks"); | |
projectName = RemoveAllSpacesSquigly(projectName); | |
inFirst=true; | |
StartCoroutine(GetURLData(4,getProjectTasksURL + "curUser=" + username + "&curProject=" + projectName,"")); | |
StartCoroutine(SortURLData(4,getProjectTasksURL + "curUser=" + username + "&curProject=" + projectName,"")); | |
} | |
public void SortProjectTaskList(string username, string projectName, int sortType){ | |
string queryURL = ""; | |
Debug.Log("We are in the sort project type: " + sortType); | |
switch(sortType){ | |
case 0: //Sort by time | |
queryURL = "sortProjectsByTime.php?"; | |
Debug.Log("SORTING BY TIME"); | |
break; | |
case 1: //Sort by priority | |
Debug.Log("SORTING BY PRIORITY"); | |
queryURL = "sortProjectsByPriority.php?"; | |
break; | |
} | |
SetStatus("Sorting project tasks"); | |
projectName = RemoveAllSpacesSquigly(projectName); | |
inFirst = true; | |
StartCoroutine(GetURLData(4,queryURL + "curUser=" + username + "&curProject=" + projectName,"")); | |
StartCoroutine(SortURLData(4,queryURL + "curUser=" + username + "&curProject=" + projectName,"")); | |
} | |
public IEnumerator SortURLData(int forwardNum, string newUrl,string additionalPost){ | |
// Debug.Log("Sorting URL Data"); | |
while(inFirst) | |
yield return new WaitForSeconds(0.1f); | |
// Debug.Log("Finished downloading"); | |
if (retrievedData.error != null) | |
{ | |
SetStatus("Error: " + retrievedData.error); | |
} | |
else | |
{ | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
//Split the text into an array of strings. | |
//:(colon) is used to break up rows, ;(semicolon) is used to break up columns | |
List<List<string>> tableRows = new List<List<string>>(); | |
string[] split = retrievedData.text.Split(':'); //Split into rows | |
//Remove the first item, which is always empty | |
for (int i = 1; i < split.Length; i++){ | |
string currentRow = split[i]; //Get the current row | |
string[] columns = currentRow.Split(';'); //Split the row into columns | |
List<string> newColumn = new List<string>(); | |
for (int k = 0; k < columns.Length; k++){ | |
newColumn.Add(columns[k]); | |
} | |
tableRows.Add(newColumn); | |
} | |
//Forward the results to be used in the program | |
switch (forwardNum){ | |
case 1: editDB.SetExerciseTypes(tableRows); | |
break; | |
case 2:editDB.SetProjectList(tableRows); | |
break; | |
case 3:editDB.SetExerciseStats(tableRows); | |
break; | |
case 4: yield return StartCoroutine(editDB.RefreshBFPWorldWarPanel(tableRows)); | |
break; | |
case 5: editDB.SetNeededExercises(tableRows, additionalPost); | |
break; | |
case 6: DebugOutput(tableRows); // Used when wanting to see what data gets pulled from the url | |
break; | |
case 7: SetRegister(retrievedData.text); //Register | |
break; | |
case 8: SetLogin(retrievedData.text); //Login | |
break; | |
} | |
} | |
yield return 0; | |
} | |
void SetLogin(string newData){ | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.UpdateLoginStatus(newData); | |
} | |
void SetRegister(string newData){ | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
editDB.UpdateLoginStatus(newData); | |
} | |
// Get any type of data from a URL, the forward number is used to forward the result to a different script which is set within a switch | |
// new url is the php filename, | |
// additionalPost is any variable info to pass into the url | |
public IEnumerator GetURLData(int forwardNum, string newUrl,string additionalPost) | |
{ | |
float timeOut = Time.time + 5; | |
if (forwardNum == 8){ | |
retrievedData = new WWW(prefixURL + newUrl + additionalPost); | |
} | |
else{ | |
retrievedData = new WWW(prefixURL + "dbScripts/" + newUrl + additionalPost); | |
} | |
yield return retrievedData; | |
// Debug.Log(retrievedData.text); | |
StartCoroutine(Wait()); | |
} | |
IEnumerator Wait(){ | |
waitActive = true; | |
SetStatus("Waiting for 0.1 secs..."); | |
yield return new WaitForSeconds (0.1f); | |
while(!retrievedData.isDone){ | |
SetStatus("Waiting for data to finish downloading fully..."); | |
yield return new WaitForSeconds(0.1f); | |
} | |
inFirst = false; | |
waitActive = false; | |
SetStatus("Finished Waiting..."); | |
// | |
} | |
// remember to use StartCoroutine when calling this function! | |
public IEnumerator PostData(string postURL,int responseType)//string name, int score) | |
{ | |
//This connects to a server side php script that will add the name and score to a MySQL DB. | |
// Supply it with a string representing the players name and the players score | |
SetStatus("Posting Data now" ); | |
//Create a hash used to check with the PHP file to verify that the score is coming from this game | |
//string hash=Md5Sum(name + score + thisGameName + secretKey); | |
string post_url = prefixURL + "dbScripts/" + postURL;//"exerciseType=" + name + "&score=" + score + "&game=" + thisGameName + "&hash=" + hash; | |
// Debug.Log(post_url); | |
// Post the URL to the site and create a download object to get the result. | |
WWW hs_post = new WWW(post_url); | |
yield return hs_post; // Wait until the download is done | |
if (hs_post.error != null) | |
{ | |
SetStatus("Error" + hs_post.error); | |
} | |
else{ | |
SetStatus("Success! Data has been posted" ); | |
//Refresh the data | |
SQLDB_Manip editDB = gameObject.GetComponent<SQLDB_Manip>(); | |
switch(responseType){ | |
case 1: | |
//Get all the exercises for the selected type | |
editDB.GetExerciseEntries(); | |
break; | |
case 2: | |
break; | |
case 4: | |
editDB.FilterTasksByLastFilter(); //Refresh the task list, a task had been deleted | |
break; | |
case 5: Debug.Log("Creating the user tables POST()"); | |
break; | |
} | |
// StartCoroutine(GetScores()); //Get exercise list in order to add it to the stats bar | |
} | |
} | |
public string Md5Sum(string strToEncrypt) | |
{ | |
System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding(); | |
byte[] bytes = ue.GetBytes(strToEncrypt); | |
// encrypt bytes | |
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); | |
byte[] hashBytes = md5.ComputeHash(bytes); | |
// Convert the encrypted bytes back to a string (base 16) | |
string hashString = ""; | |
for (int i = 0; i < hashBytes.Length; i++) | |
{ | |
hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0'); | |
} | |
return hashString.PadLeft(32, '0'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class SQLDB_Manip : MonoBehaviour { | |
public string DatabaseName = "TestDB.sqdb"; | |
private SQLConn db; | |
public List<object> databaseData = new List<object>();// = new List<string> (); | |
private string ourUsername = ""; | |
private List<string> tableNames = new List<string>(); //Refreshed at startup and everytime a new table is added or deleted | |
//List to hold controls for the datagrid view | |
public Transform scrollingList; | |
public Transform horizScrollList; | |
public Transform needToCompleteList; | |
//Prefabs | |
public GameObject labelPrefab; | |
public UIInput textInputPrefab; | |
public GameObject statsBarPrefab; | |
private Vector3 labelCreationLocation = new Vector3(-330,232,0); | |
private Vector3 statsBarCreationLocation = new Vector3(-300,-340,0); | |
private bool filterOn; | |
private bool useLocalDB; | |
private DBManip_PHP editDB ; | |
public GameObject taskEntryPrefab; | |
public GameObject exerciseNeededPrefab; | |
//Panel Types | |
public GameObject statsPanel; | |
public GameObject taskListPanel; | |
public GameObject loginPanel; | |
public GameObject projectSelector; | |
public GameObject scrollDropDwnPrefab; | |
//public GameObject dropdownEntryPrefab; | |
public GameObject fileMenuPanel; | |
private bool projectsListOpen; | |
private GameObject projectScrollList; | |
public GameObject availableProjectsButton; | |
public UILabel statusLabel; | |
public UILabel incompleteTasksLabel; | |
public UILabel projectEstimatedTime; | |
public UILabel projectEstimatedFinishDay; | |
public UILabel tasksNotEstimated; | |
public UILabel disabledTasksLabel; | |
public GameObject adminControlPanel; | |
public UIInput repsValueLabel; | |
public UIInput weightValueLabel; | |
public UILabel loginStatus; | |
public UILabel DebugScrollLabel; | |
private enum FilterListType{ | |
all, | |
complete, | |
incomplete | |
} | |
private FilterListType filterType = FilterListType.all; | |
public List<string> exercisesRemain = new List<string>(); | |
public List<GameObject> taskListItems = new List<GameObject>(); | |
//All the other arrays to hold sorting by priority | |
private List<GameObject> taskItemsPriority1 = new List<GameObject>(); | |
private List<GameObject> taskItemsPriority2 = new List<GameObject>(); | |
private List<GameObject> taskItemsPriority3 = new List<GameObject>(); | |
private List<GameObject> taskItemsPriority4 = new List<GameObject>(); | |
private List<GameObject> taskItemsPriority5 = new List<GameObject>(); | |
private bool wasInEditMode = false; | |
public enum PanelSelection{ | |
listType, | |
statsType | |
} | |
private PanelSelection selectedPanelType = PanelSelection.listType; | |
private List<string> projectNames = new List<string>(); | |
private List<string> exerciseNames = new List<string>(); | |
private string selectedProjectName = ""; | |
private string selectedExerciseName = ""; | |
private bool doDeleteEntries = false; | |
private bool hasDeletedEntries = false; | |
private bool hasStartedFirst; | |
// DEBUG *** | |
// public UILabel dbgLabelTimeRightSide; | |
// public UILabel dbgLabelCalcTime; | |
public ToggleBtn shouldRemember; | |
public UIInput usernameInputBox; | |
public UIInput passwordInputBox; | |
//-------------------------- | |
// TOOLSET | |
//-------------------------- | |
public UISprite priority1; | |
public UISprite priority2; | |
public UISprite priority3; | |
public UISprite priority4; | |
public UISprite priority5; | |
public UIInput hourInputLabel; | |
public UIInput minuteInputLabel; | |
private int lastSelectedPriority; | |
private int curSelectedTask = -1; | |
private bool hasSetIntialChange; //Used to prevent having to save estimated time on the intialization of the object | |
private int nonEstimatedTasks; | |
private int accumulatedHours; | |
private int accumulatedMinutes; | |
private int totalDisabled; | |
private int currentPriority; | |
private int maxPriority = 5; | |
private bool isInStatsView = false; | |
void Start(){ | |
SetStatus("Starting..."); | |
if (useLocalDB){ | |
SetupLocalDB(); | |
} | |
else{ | |
editDB = gameObject.GetComponent<DBManip_PHP>(); | |
} | |
DisableAllPanels(); | |
projectSelector.SetActive(false); | |
loginPanel.SetActive(true); | |
} | |
public void Update(){ | |
if(doDeleteEntries){ | |
doDeleteEntries=false; | |
//Remove the old list of entries | |
CleanTaskList(); | |
} | |
if (hasDeletedEntries){ | |
hasDeletedEntries=false; | |
//Load up the new list | |
SetupNewTaskList(); | |
} | |
} | |
public void ShowAdminControlPanel(bool setActive){ | |
adminControlPanel.SetActive(setActive); | |
} | |
public void UpdateLoginStatus(string newStatus){ | |
int doRemember = shouldRemember.GetShouldRemember(); | |
//If shouldn't remember the username and password then overwrite them | |
if (doRemember != 1){ | |
PlayerPrefs.SetString("curUser", ""); | |
PlayerPrefs.SetString("curPassword", ""); | |
} | |
else{ | |
PlayerPrefs.SetString(usernameInputBox.value, "curUser"); | |
PlayerPrefs.SetString(passwordInputBox.value, "curPassword"); | |
} | |
if (newStatus.Contains("loginSuccess")){ | |
newStatus = "Login SUCCESS!!"; | |
//Save username globally | |
ourUsername = usernameInputBox.value; | |
loginPanel.SetActive(false); | |
projectSelector.SetActive(true); | |
//Load project categories for the selected user | |
SetupOnlineDB(); | |
} | |
else if (newStatus.Contains("accountCreated")){ | |
newStatus = "Registered!"; | |
//Save username globally | |
ourUsername = usernameInputBox.value; | |
//Create tables for he new user | |
editDB.CreateUserTables(ourUsername); | |
//Do login proceedure | |
loginPanel.SetActive(false); | |
projectSelector.SetActive(true); | |
} | |
else if (newStatus.Contains("incorrectPassword")){ | |
newStatus = "Incorrect Password!"; | |
} | |
else{ | |
//Registration or Login failed so re-enable the input boxes | |
usernameInputBox.enabled = true; | |
passwordInputBox.enabled = true; | |
} | |
if(newStatus.Contains("!DOCTYPE")){ | |
newStatus = "The server is temporarily down."; | |
} | |
else if(newStatus.Contains("usedUsername")){ | |
newStatus = "The username is already taken."; | |
} | |
SetLoginStatus(newStatus); | |
} | |
public void SetLoginStatus(string msg){ | |
loginStatus.text = msg; | |
} | |
public void GoToHome(){ | |
//Hide any other project panels | |
taskListPanel.SetActive(false); | |
statsPanel.SetActive(false); | |
//Set the name of the project to STATS | |
//Display the stats panel | |
} | |
public void SetStatus(string msg){ | |
statusLabel.text = "Status: " + msg; | |
// Debug.Log(statusLabel.text); | |
DebugScrollLabel.text += "\n" + msg; | |
} | |
public void SetIncompleteLabel(int numIncomplete){ | |
incompleteTasksLabel.text = "Incomplete: " + numIncomplete.ToString(); | |
} | |
public void SetupLocalDB(){ | |
db = new SQLConn(); | |
db.OpenDB(DatabaseName); | |
RefreshPopuplistTables(); | |
} | |
public void SetupOnlineDB(){ | |
SetStatus("Getting all projects"); | |
//Get all the projects | |
editDB.GetProjects(ourUsername); | |
} | |
//public GameObject scrollDropDwnPrefab; | |
//public GameObject dropdownEntryPrefab; | |
//projectsListOpen | |
public string GetCurrentUsername(){ | |
return ourUsername; | |
} | |
public List<string> GetProjectNames(){ | |
return projectNames; | |
} | |
public string GetSelectedExerciseName(){ | |
return selectedExerciseName; | |
} | |
public string GetSelectedProjectName(){ | |
return selectedProjectName; | |
} | |
public List<string> GetExerciseNames(){ | |
return exerciseNames; | |
} | |
public void CreateDropdownItem(string itemName, int colValue){ | |
} | |
public void CreateEmptyTask(){ | |
//Creates a new task gameobject at the bottom of the list | |
SetStatus("Create new task"); | |
UIScrollView sv = scrollingList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.verticalScrollBar; | |
sv.verticalScrollBar = null; | |
//DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
//taskListItems.Clear(); | |
int i = taskListItems.Count; | |
//Instantiate the task item and parent it to the scrolling list so it can scroll | |
GameObject newRowItem = Instantiate(taskEntryPrefab) as GameObject; | |
newRowItem.transform.parent = scrollingList; | |
//Offset the UILabel based on the row and column numbers | |
float addColumn = 35 * i; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(labelCreationLocation.x,labelCreationLocation.y + addColumn,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Temp Values | |
int idVal = 0; | |
string taskNameVal = ""; | |
string taskCategoryVal = ""; | |
string projectNameVal = ""; | |
System.DateTime completedTime; | |
bool activeVal = true; | |
//Set the value of the status bar | |
TaskRow taskComponent = newRowItem.GetComponent<TaskRow>(); | |
taskComponent.SetTaskName(i, taskNameVal); | |
//Add tag so the gameobject can be deleted | |
newRowItem.tag = "DisplayData"; | |
taskListItems.Add(newRowItem); | |
//Reset the scrollbar | |
sv.UpdatePosition(); | |
sv.ResetPosition(); | |
//Reassign the scrollbar | |
sv.verticalScrollBar = tempScrollbar; | |
sv.verticalScrollBar.value = 0; | |
//Select the last task list item, the one we just created | |
DisableTaskListSelections(taskListItems.Count - 1); | |
} | |
public void SaveToTaskList(string taskName){ | |
editDB.AddNewTask(ourUsername, taskName,"Unknown",selectedProjectName); | |
} | |
public void UpdateTaskList(string taskName,string taskCategory, int oldID, int newPriority, int estimatedHours, int estimatedMinutes,string subCategoryName, | |
int reorderNum, int taskDisabled){ | |
SetStatus("Updating task"); | |
//Updates a task entry with new data | |
editDB.UpdateTask(ourUsername, taskName,taskCategory,selectedProjectName,oldID, newPriority, estimatedHours, estimatedMinutes, subCategoryName, reorderNum, taskDisabled); | |
} | |
public void EnableDisableTask(int oldID, bool isEnabled){ | |
if (isEnabled) | |
SetStatus("completed"); | |
else | |
SetStatus("incomplete"); | |
editDB.EnableDisableTask(ourUsername, oldID,isEnabled); | |
} | |
public void DeleteTask(int oldID){ | |
editDB.DeleteTask(ourUsername, oldID); | |
} | |
public void FilterTasksByLastFilter(){ | |
CleanTaskList(); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
public void FilterTasksByAll(){ | |
SetStatus("Show all"); | |
filterType=FilterListType.all; | |
CleanTaskList(); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
public void FilterTasksByComplete(){ | |
SetStatus("Filter by complete"); | |
filterType=FilterListType.complete; | |
CleanTaskList(); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
public void FilterTasksByActive(){ | |
SetStatus("Filter by unfinished"); | |
filterType=FilterListType.incomplete; | |
CleanTaskList(); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
public void SortTasksByTime(){ | |
Debug.Log("Sorting tasks by time"); | |
SetStatus("Sorting tasks by time"); | |
//--------------------------------------- | |
//Reset the global stats for the project | |
//--------------------------------------- | |
nonEstimatedTasks=0; | |
accumulatedHours=0; | |
accumulatedMinutes=0; | |
//taskListItems.Clear(); | |
//CleanTaskList(); | |
editDB.SortProjectTaskList(ourUsername, selectedProjectName,0); | |
} | |
public void SortTasksByPriority(){ | |
Debug.Log("Sorting tasks by priority"); | |
//--------------------------------------- | |
//Reset the global stats for the project | |
//--------------------------------------- | |
nonEstimatedTasks=0; | |
accumulatedHours=0; | |
accumulatedMinutes=0; | |
//CleanTaskList(); | |
//taskListItems.Clear(); | |
editDB.SortProjectTaskList(ourUsername, selectedProjectName,1); | |
} | |
public void SaveAllTasks(){ | |
//Go through list of all visible tasks and save them or update them | |
for (int i = 0; i < taskListItems.Count; i++){ | |
TaskRow taskRowComponent = taskListItems[i].GetComponent<TaskRow>(); | |
taskRowComponent.SaveTask(); | |
} | |
} | |
public void EnableEditMode(bool inEditMode){ | |
wasInEditMode = inEditMode; | |
SetStatus("Edit mode " + wasInEditMode); | |
//Go through list of all visible tasks and put them in edit mode | |
for (int i = 0; i < taskListItems.Count; i++){ | |
TaskRow taskRowComponent = taskListItems[i].GetComponent<TaskRow>(); | |
taskRowComponent.EnableEditMode(inEditMode); | |
} | |
} | |
public void SetNeededExercises(List<List<string>> listValues, string exerciseName){ | |
//Set the needed exercises | |
SetStatus("Setting needed exercises"); | |
string lastDate = ""; //The last date used for merging entries that are from the same day | |
int lastDateI = 0; //Used to keep the same horizontal offsets when entries are merged in the same date | |
int totalMerged = 0; | |
int firstIWithDate = 0; | |
int offsetNum = 0; | |
int greatestRepsValue = 0; | |
int todaysEntries = 0; | |
int groupTotalValue = 0; | |
//Month and year to compare if we should filter this data out | |
int currentMonth = System.DateTime.Now.Month; | |
int currentYear = System.DateTime.Now.Year; | |
int currentDay = System.DateTime.Now.Day; | |
for (int i = 0; i < listValues.Count; i++){ //Rows | |
List<string> currentRow = listValues[i]; | |
List<string> graphItemData = new List<string>(); | |
int repsValue = 0; | |
int weightValue = 0; | |
//Date data | |
System.DateTime selectedDate; | |
int dayValue = 0; | |
int yearValue = 0; | |
int monthValue = 0; | |
if (filterOn){ | |
currentMonth = 2; //Filter by month of February | |
currentYear = 14; //Filter by this 2014 | |
} | |
for (int k = 0; k < currentRow.Count; k++){ //Column Data for the graph object | |
//For every column list the data in that cell | |
object newData = currentRow[k]; | |
if (k == 1){ //Date | |
if (System.DateTime.TryParse(newData.ToString(),out selectedDate)){ | |
// Debug.Log("SucceededParse"); | |
dayValue = selectedDate.Day; | |
monthValue = selectedDate.Month; | |
yearValue = selectedDate.Year; | |
} | |
else | |
Debug.Log("Issue parsing date"); | |
} | |
else if (k == 2){ //Reps | |
int.TryParse(newData.ToString(),out repsValue); | |
} | |
else if (k == 3){ //Weight | |
int.TryParse(newData.ToString(),out weightValue); | |
} | |
graphItemData.Add(newData.ToString()); | |
} | |
//if(the date of the entry is within the bounds of the filter than create the game object | |
string entryDate = (monthValue + "/" + dayValue); | |
//The Y Pos of the stat bar, changes when grouped with other bars of the same date | |
float statBarStartPosY = statsBarCreationLocation.y; | |
if (entryDate == lastDate){ | |
//Combine the reps values together | |
groupTotalValue += repsValue; | |
} | |
else{ | |
groupTotalValue = repsValue; | |
} | |
//Set the last date gathered in order to determine grouping of the next entry | |
lastDate = entryDate; | |
//Set the max value on the grid | |
if (groupTotalValue > greatestRepsValue) | |
greatestRepsValue = groupTotalValue; | |
//Get the total amount of today's entries | |
string entryFullDate = (monthValue + "/" + dayValue + "/" + yearValue); | |
string todaysFullDate = (currentMonth + "/" + currentDay + "/" + currentYear); | |
if (entryFullDate == todaysFullDate){ | |
//Combine the reps values together | |
todaysEntries+= repsValue; | |
} | |
} | |
string lastEntryDate = ""; | |
int remainingEntries = greatestRepsValue-todaysEntries; | |
//Only show the remaining exercise if there are remaining exercises | |
if (remainingEntries > 0){ | |
string exerciseStat = "-" + exerciseName + ", " + (remainingEntries ); | |
exercisesRemain.Add(exerciseStat); | |
} | |
SetStatus("Ready."); | |
//1.Curl,Remaining:80 | |
//(Number).(Exercise Name), Remaining: (GreatestRecordedValue - totalValueCurrentDay) | |
} | |
public void NotifyTaskToComplete(string taskData){ | |
} | |
public void CleanTaskList(){ | |
//Deleting the task list items | |
taskListPanel.SetActive(true); | |
UIScrollView sv = scrollingList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.verticalScrollBar; | |
sv.verticalScrollBar = null; | |
DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
taskListItems.Clear(); | |
//Reset the scrollbar | |
sv.ResetPosition(); | |
sv.UpdatePosition(); | |
// | |
//Reassign the scrollbar | |
sv.verticalScrollBar = tempScrollbar; | |
sv.verticalScrollBar.value = 0; | |
//sv.ResetPosition(); | |
taskListPanel.SetActive(false); | |
hasDeletedEntries=true; | |
//return true; | |
} | |
public void ClearTaskList(){ | |
//Get the task list for bfp world war and insert a new task item for every database row | |
// Debug.Log("Refreshing bfp world war task list"); | |
UIScrollView sv = scrollingList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.verticalScrollBar; | |
sv.verticalScrollBar = null; | |
DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
taskListItems.Clear(); | |
//Reset the scrollbar | |
sv.ResetPosition(); | |
sv.UpdatePosition(); | |
// | |
//Reassign the scrollbar | |
sv.verticalScrollBar = tempScrollbar; | |
sv.verticalScrollBar.value = 0; | |
} | |
public IEnumerator RefreshBFPWorldWarPanel(List<List<string>> tableRows){ | |
//Get the task list for bfp world war and insert a new task item for every database row | |
Debug.Log("REFRESHING BFP TASK LIST"); | |
SetStatus("REFRESHING BFP TASK LIST"); | |
UIScrollView sv = scrollingList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.verticalScrollBar; | |
sv.verticalScrollBar.value = 1; | |
sv.verticalScrollBar.value = 0; | |
sv.verticalScrollBar = null; | |
DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
taskListItems.Clear(); | |
int addedItems = 0; | |
int totalActiveItems = 0; | |
for (int i = 0; i < tableRows.Count; i++){ //Rows | |
List<string> currentRow = tableRows[i]; | |
//Temp Values | |
int idVal = 0; | |
string taskNameVal = ""; | |
string taskCategoryVal = ""; | |
string projectNameVal = ""; | |
System.DateTime completedTime; | |
bool activeVal = true; | |
bool hasHitRowFive = false; | |
int newTaskPriority = 0; | |
int newOrderNumber = -1; | |
bool newIsDisabled = false; | |
int estimatedH = 0; | |
int estimatedM = 0; | |
string newSubcategoryName = ""; | |
for (int k = 0; k < currentRow.Count; k++){ //Column Data for the graph object | |
//For every column list the data in that cell | |
object newData = currentRow[k]; | |
switch(k){ | |
case 0://id | |
//Debug.Log("ID: " + currentRow[k]); | |
if (int.TryParse(currentRow[k],out idVal)){ | |
//Successful grab id | |
} | |
else{ | |
Debug.Log("There was an issue parsing the ID for the task, there will definitely be data corruptions by "); | |
Debug.Log("misidentifying the task number"); | |
} | |
break; | |
case 1://taskname | |
taskNameVal = currentRow[k]; | |
//Debug.Log("taskNameVal: " + taskNameVal); | |
break; | |
case 2://taskcategory | |
taskCategoryVal = currentRow[k]; | |
break; | |
case 3://projectName | |
projectNameVal= currentRow[k]; | |
break; | |
case 4://completedOn | |
// completedTime = System.DateTime.Parse(currentRow[k]); | |
break; | |
case 5://active | |
if(currentRow[k]=="1") | |
activeVal = true; | |
else{ | |
activeVal = false; | |
} | |
break; | |
case 6: //priority | |
int.TryParse(currentRow[k],out newTaskPriority); | |
break; | |
case 7: //isDisabled Temporarily | |
if(currentRow[k]=="1") | |
newIsDisabled = true; | |
else{ | |
newIsDisabled = false; | |
} | |
break; | |
case 8: //estimated Hour | |
int.TryParse(currentRow[k],out estimatedH); | |
break; | |
case 9: //estimated Min | |
int.TryParse(currentRow[k],out estimatedM); | |
break; | |
case 10: //task subcategory | |
newSubcategoryName = currentRow[k]; | |
break; | |
case 11: //Order num | |
//Debug.Log("ORDERNUM: " + currentRow[k]); | |
int.TryParse(currentRow[k],out newOrderNumber); | |
break; | |
} | |
} | |
string displayNum = ""; | |
//Only add a number to the unfinished tasks in the list | |
if (activeVal){ | |
totalActiveItems++; | |
//displayNum = (totalActiveItems - unfinishedItems).ToString(); | |
} | |
if (filterType==FilterListType.complete){ | |
if (activeVal == false){ | |
CreateTaskListItem(addedItems, idVal, taskNameVal, taskCategoryVal, projectNameVal, activeVal, | |
displayNum, newTaskPriority, estimatedH, estimatedM, newSubcategoryName, newOrderNumber, newIsDisabled); | |
addedItems++; | |
if (newIsDisabled) | |
totalDisabled++; | |
if (estimatedH == 0 && estimatedM == 0){ | |
//Task estimate has not been set | |
nonEstimatedTasks++; | |
} | |
else{ | |
accumulatedHours += estimatedH; | |
accumulatedMinutes += estimatedM; | |
} | |
} | |
} | |
else if (filterType==FilterListType.incomplete){ | |
if (activeVal){ | |
CreateTaskListItem(addedItems, idVal, taskNameVal, taskCategoryVal, projectNameVal, activeVal, | |
displayNum, newTaskPriority, estimatedH, estimatedM, newSubcategoryName, newOrderNumber, newIsDisabled); | |
addedItems++; | |
if (newIsDisabled) | |
totalDisabled++; | |
if (estimatedH == 0 && estimatedM == 0){ | |
//Task estimate has not been set | |
nonEstimatedTasks++; | |
} | |
else{ | |
accumulatedHours += estimatedH; | |
accumulatedMinutes += estimatedM; | |
} | |
} | |
} | |
else{ | |
CreateTaskListItem(addedItems, idVal, taskNameVal, taskCategoryVal, projectNameVal, activeVal, | |
displayNum, newTaskPriority, estimatedH, estimatedM, newSubcategoryName, newOrderNumber, newIsDisabled); | |
addedItems++; | |
if (newIsDisabled) | |
totalDisabled++; | |
if (estimatedH == 0 && estimatedM == 0){ | |
//Task estimate has not been set | |
nonEstimatedTasks++; | |
} | |
else{ | |
accumulatedHours += estimatedH; | |
accumulatedMinutes += estimatedM; | |
} | |
} | |
} | |
int filterCount = totalActiveItems; | |
if (filterType==FilterListType.incomplete) | |
filterCount = addedItems; | |
//Display the amount of active tasks for the current project | |
SetIncompleteLabel(filterCount); | |
//Number the tasks | |
RenumberTaskItems(filterCount); | |
//Reset the scrollbar | |
sv.ResetPosition(); | |
sv.UpdatePosition(); | |
sv.ResetPosition(); | |
tempScrollbar.value = 0; | |
//Reassign the scrollbar | |
sv.verticalScrollBar = tempScrollbar; | |
sv.verticalScrollBar.value = 0; | |
DisplayCompletionStats(); | |
if (wasInEditMode){ | |
EnableEditMode(true); | |
} | |
yield return 0; | |
} | |
public void DisplayCompletionStats(){ | |
int minsToHours = 0; | |
int remainderMins = 0; | |
int totalHours = 0; | |
System.DateTime goalDate; | |
System.DateTime todaysDay = System.DateTime.Now; | |
tasksNotEstimated.text = "Tasks not Estimated: " + nonEstimatedTasks.ToString(); | |
disabledTasksLabel.text = "Disabled: " + totalDisabled; | |
//Turn the minutes into hours | |
try{ | |
minsToHours = (int)(accumulatedMinutes / 60); | |
remainderMins = (int)((minsToHours * 60) - accumulatedMinutes); | |
totalHours = accumulatedHours + minsToHours; | |
} | |
catch(UnityException ex){ | |
SetStatus(ex.Message); | |
} | |
//Show the total hours and minutes needed to finish the project | |
projectEstimatedTime.text = "Remaining Time: " + totalHours.ToString() + "h " + remainderMins.ToString() + "m"; | |
projectEstimatedFinishDay.text = "";//"Est. Finish: " + goalDate.Month.ToString() + "/" + goalDate.Day.ToString() + "/" + goalDate.Year.ToString(); | |
statusLabel.text = "Total Hours: " + accumulatedHours + " total Minutes: " + accumulatedMinutes; | |
} | |
public void DisableTaskListSelections(int selectedVal){ | |
Debug.Log("Selectedvale:" + selectedVal); | |
for (int i = 0; i < taskListItems.Count; i++){ | |
TaskRow taskComponent = taskListItems[i].GetComponent<TaskRow>(); | |
//if (taskComponent.GetTaskID() != selectedVal){ | |
if (i != selectedVal){ | |
taskComponent.selectionItem.Deselect(); | |
} | |
} | |
} | |
public void RenumberTaskItems(int totalActive){ | |
int curNum = 0; | |
//Can Renumber based on filtering if needed | |
for (int i = 0; i < taskListItems.Count; i++){ | |
//Set the value of the status bar | |
TaskRow taskComponent = taskListItems[i].GetComponent<TaskRow>(); | |
if (taskComponent.GetActiveState()){ | |
curNum++; | |
taskComponent.SetTaskNumber((totalActive - curNum).ToString()); | |
} | |
} | |
} | |
public void CreateTaskListItem(int increment, int newId, string newName, string newCategory, string newProject, bool isActiveVal, string displayNum, int newTaskPriority, | |
int estimatedH, int estimatedM, string newSubcategoryName,int newOrderNumber,bool newIsDisabled){ | |
//Instantiate the UILabel and parent it to the scrolling list so it can scroll | |
GameObject newRowItem = Instantiate(taskEntryPrefab) as GameObject; | |
newRowItem.transform.parent = scrollingList; | |
//Offset the UILabel based on the row and column numbers | |
float addColumn = 35 * increment; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(labelCreationLocation.x,labelCreationLocation.y + addColumn,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Set the value of the status bar | |
TaskRow taskComponent = newRowItem.GetComponent<TaskRow>(); | |
taskComponent.SetTaskValues(increment, newId, newName, newCategory, newProject, isActiveVal, displayNum, | |
newTaskPriority, estimatedH, estimatedM, newSubcategoryName, newOrderNumber,newIsDisabled); | |
//Add tag so the gameobject can be deleted | |
newRowItem.tag = "DisplayData"; | |
taskListItems.Add(newRowItem); | |
} | |
public void SetProjectList(List<List<string>> listValues){ | |
SetStatus("Setting Project List"); | |
for (int i = 0; i < listValues.Count; i++){ //Rows | |
List<string> currentRow = listValues[i]; | |
for (int k = 0; k < currentRow.Count; k++){ | |
projectNames.Add(currentRow[k]); | |
} | |
} | |
//Determine which project is currently active... since we are going to focus on exercises the exercise will always be active | |
//so: | |
if (selectedPanelType == PanelSelection.listType){ | |
} | |
else if (selectedPanelType == PanelSelection.statsType){ | |
} | |
SetStatus("Ready."); | |
} | |
public void EnableDisableTopBar(bool isEnabled){ | |
// Debug.Log("Switching task bar"); | |
//When a task list is selected then enable the top bar, if it is deselected then disable the top bar | |
Color onColor = new Color(); | |
Color offColor = new Color(1,1,1,0.4f); | |
if (!isEnabled){ | |
} | |
else{ | |
priority1.color = offColor; | |
priority2.color = offColor; | |
priority3.color = offColor; | |
priority4.color = offColor; | |
priority5.color = offColor; | |
} | |
} | |
public void RefreshPanelProjects(string selectedProject){ | |
DisableAllPanels(); | |
curSelectedTask = -1; //Unselect tasks | |
//Reset input labels | |
hourInputLabel.value = "0"; | |
minuteInputLabel.value = "0"; | |
//--------------------------------------- | |
//Reset the global stats for the project | |
//--------------------------------------- | |
nonEstimatedTasks=0; | |
accumulatedHours=0; | |
accumulatedMinutes=0; | |
EnableDisableTopBar(true); | |
//Reset filter type | |
filterType=FilterListType.incomplete; | |
SetStatus("Removing task list "); | |
//Set the project name as a global variable | |
selectedProjectName = selectedProject.Replace("/n", ""); | |
ChangeProjects prjLabel = availableProjectsButton.GetComponent<ChangeProjects>(); | |
prjLabel.projectName.text = selectedProjectName; | |
doDeleteEntries=true; | |
} | |
public void SetupNewTaskList(){ | |
SetStatus("Refreshing panel"); | |
//Set this here so we can jump out of it with a button | |
if (selectedProjectName == "Exercise"){ | |
isInStatsView = true; | |
} | |
else{ | |
isInStatsView = false; | |
} | |
if (isInStatsView){ | |
statsPanel.SetActive(true); | |
//Get all the stat bars | |
editDB.GetExerciseList(ourUsername, selectedProjectName); | |
} | |
else | |
{ //should create a section in the db for panelType - if listpanel, statsPanel... | |
//Should refresh the panel based on the panel that is active | |
taskListPanel.SetActive(true); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
} | |
//Switch the view between a list view or a stats bar view | |
public void SetPrimaryView(){ | |
if (isInStatsView){ | |
isInStatsView = false; | |
statsPanel.SetActive(false); | |
taskListPanel.SetActive(true); | |
editDB.GetProjectTaskList(ourUsername, selectedProjectName); | |
} | |
else{ | |
isInStatsView = true; | |
statsPanel.SetActive(true); | |
taskListPanel.SetActive(false); | |
editDB.GetExerciseList(ourUsername, selectedProjectName); | |
} | |
} | |
public void DisableAllPanels(){ | |
statsPanel.SetActive(false); | |
taskListPanel.SetActive(false); | |
} | |
public void AddNewExercise(string exerciseType,string postingDate,int var1,int var2){ | |
Debug.Log(ourUsername + " " + selectedProjectName+ " " + exerciseType+ " " + postingDate+ " " + var1+ " " + var2); | |
editDB.AddNewTrackEntry(ourUsername,selectedProjectName,exerciseType,postingDate,var1,var2,0); //Var 3 needs a purpose | |
} | |
public void SetExerciseTypes(List<List<string>> listValues){ | |
SetStatus("Setting Exercise Types"); | |
//Refreshes the available tables in the database | |
exerciseNames = new List<string>(); | |
for (int i = 0; i < listValues.Count - 1; i++){ //Rows | |
List<string> currentRow = listValues[i]; | |
// Debug.Log("Name:" + exerciseNames[i]); | |
for (int k = 0; k < currentRow.Count; k++){ | |
exerciseNames.Add(currentRow[k]); | |
} | |
} | |
if (exerciseNames.Count > 0){ | |
selectedExerciseName = exerciseNames[0]; | |
} | |
else | |
selectedExerciseName = ""; | |
//Reset the exercise name to to first selected | |
UILabel theExerciseName = GameObject.FindWithTag("ExerciseName").GetComponent<UILabel>(); | |
selectedExerciseName = selectedExerciseName.Replace("\n", ""); | |
theExerciseName.text = selectedExerciseName; | |
//Debug.Log("THE SELECTED EXERCISE: " + theExerciseName.text); | |
SetStatus("Getting Exercise Entries"); | |
//Get all the exercises for the selected type | |
GetExerciseEntries(); | |
} | |
public void GetExerciseEntries(){ | |
//Get all the exercise entries for the selected exercise type | |
editDB.GetTrackingEntries(ourUsername, selectedExerciseName, selectedProjectName); | |
} | |
public void SetupDefaultExerciseVals(string exerciseN){ | |
string rVal = PlayerPrefs.GetString(exerciseN + "a"); | |
if (rVal == "") | |
rVal = "0"; | |
repsValueLabel.value = rVal; | |
string wVal = PlayerPrefs.GetString(exerciseN + "b"); | |
if (wVal == "") | |
wVal = "0"; | |
weightValueLabel.value = wVal; | |
} | |
public void GetExerciseEntries(string newExercise){ | |
selectedExerciseName = newExercise; | |
editDB.GetTrackingEntries(ourUsername, newExercise, selectedProjectName); | |
} | |
//Called when initially setting the exercise stat bars and after a new set has been added to the db | |
public void SetExerciseStats(List<List<string>> listValues){ | |
SetStatus("Setting stats bars"); | |
UIScrollView sv = horizScrollList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.horizontalScrollBar; | |
sv.horizontalScrollBar = null; | |
DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
List<GameObject> rowItems = new List<GameObject>(); | |
int greatestRepsValue = 0; | |
PlayerData levelUp = gameObject.GetComponent<PlayerData>(); | |
levelUp.ResetXPBarValues(); | |
string lastDate = ""; //The last date used for merging entries that are from the same day | |
int lastDateI = 0; //Used to keep the same horizontal offsets when entries are merged in the same date | |
int totalMerged = 0; | |
int firstIWithDate = 0; | |
int offsetNum = 0; | |
for (int i = 0; i < listValues.Count; i++){ //Rows | |
List<string> currentRow = listValues[i]; | |
List<string> graphItemData = new List<string>(); | |
int repsValue = 0; | |
int weightValue = 0; | |
//Date data | |
System.DateTime selectedDate; | |
int dayValue = 0; | |
int yearValue = 0; | |
int monthValue = 0; | |
//Month and year to compare if we should filter this data out | |
int currentMonth = System.DateTime.Now.Month; | |
int currentYear = System.DateTime.Now.Year; | |
if (filterOn){ | |
currentMonth = 2; //Filter by month of February | |
currentYear = 14; //Filter by this 2014 | |
} | |
for (int k = 0; k < currentRow.Count; k++){ //Column Data for the graph object | |
//For every column list the data in that cell | |
object newData = currentRow[k]; | |
if (k == 1){ //Date | |
if (System.DateTime.TryParse(newData.ToString(),out selectedDate)){ | |
dayValue = selectedDate.Day; | |
monthValue = selectedDate.Month; | |
yearValue = selectedDate.Year; | |
} | |
else{ | |
Debug.Log("There was an issue parsing the date for this exercise entry... will cause data corruption"); | |
} | |
} | |
else if (k == 2){ //Reps | |
int.TryParse(newData.ToString(),out repsValue); | |
} | |
else if (k == 3){ //Weight | |
int.TryParse(newData.ToString(),out weightValue); | |
} | |
graphItemData.Add(newData.ToString()); | |
} | |
//if(the date of the entry is within the bounds of the filter than create the game object | |
string entryDate = (monthValue + "/" + dayValue); | |
//The Y Pos of the stat bar, changes when grouped with other bars of the same date | |
float statBarStartPosY = statsBarCreationLocation.y; | |
int groupTotalValue = repsValue; | |
if (entryDate == lastDate){ | |
int incVal = lastDateI+totalMerged; | |
totalMerged++; //Total of stats bars merged into the same section | |
//---------------------------- | |
// Merge reps values to the main stats bar for all entries in the current date | |
//----------------------------- | |
//Get the component for the graph item of the first item with the same date | |
StatusBar mainStatusBarCurDate = rowItems[lastDateI].GetComponent<StatusBar>(); | |
//Merge the reps values for all the stats with the same date to the main stats bar | |
mainStatusBarCurDate.ChangeDisplayValue(repsValue); | |
groupTotalValue = (int)mainStatusBarCurDate.GetGroupsTotalValue(); | |
StatusBar lastGroupItem = rowItems[incVal].GetComponent<StatusBar>(); | |
//Get the start pos and pixel height of the last item, do this by getting the main group item index and then adding totalMerged to get the index of the last item | |
float lastPixelHeight = lastGroupItem.GetXPBarPixelHeight(); | |
float lastPixelPos = lastGroupItem.gameObject.transform.localPosition.y; | |
//Get the reps value of all the items in the date to determine the max bar value | |
statBarStartPosY += lastPixelPos +lastPixelHeight; | |
} | |
else{ | |
offsetNum++; | |
lastDateI = i; | |
totalMerged = 0; | |
//firstIWithDate = i; | |
} | |
//Set the last date gathered in order to determine grouping of the next entry | |
lastDate = entryDate; | |
//Instantiate a new data object | |
GameObject newRowItem = Instantiate(statsBarPrefab) as GameObject; | |
newRowItem.transform.parent = horizScrollList; | |
//Offset the graph object based on the row and column numbers | |
float addColumn = 65 * offsetNum; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(statsBarCreationLocation.x + addColumn,statBarStartPosY,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Get the component for the graph item | |
StatusBar statusComponent = newRowItem.GetComponent<StatusBar>(); | |
//Set the max value on the grid | |
if (groupTotalValue > greatestRepsValue) | |
greatestRepsValue = groupTotalValue; | |
statusComponent.SetXPBar(repsValue,entryDate,weightValue,7); | |
if (totalMerged > 0){ | |
//Need to move the current stats bar on top of the last stats bar merged into the same date | |
//hide the value label of the current stats bar | |
statusComponent.SetupStatGroup(totalMerged); | |
} | |
newRowItem.tag = "DisplayData"; | |
rowItems.Add(newRowItem); | |
//Add XP to the player data file | |
levelUp.AddXP(repsValue); | |
} | |
string lastEntryDate = ""; | |
totalMerged = 0; | |
//Set the max value for all the items | |
for (int s = 0; s < rowItems.Count; s++){ | |
StatusBar statusComponent = rowItems[s].GetComponent<StatusBar>(); | |
statusComponent.AdjustHighestGraphValue(greatestRepsValue); | |
//Get the entry date, if it is the same as the last one then reposition the stats bar | |
string curDate = statusComponent.GetCurrentDate(); | |
if (curDate == lastEntryDate){ | |
int incVal = s-1; //last item | |
StatusBar lastGroupItem = rowItems[incVal].GetComponent<StatusBar>(); | |
//Get the start pos and pixel height of the last item, do this by getting the main group item index and then adding totalMerged to get the index of the last item | |
float lastPixelHeight = lastGroupItem.GetXPBarPixelHeight(); | |
float lastPixelPos = lastGroupItem.gameObject.transform.localPosition.y; | |
//Get the reps value of all the items in the date to determine the max bar value | |
float statBarStartPosY = lastPixelPos + lastPixelHeight; | |
//Reposition the current stats bars with the new values | |
rowItems[s].transform.localPosition = new Vector3(rowItems[s].transform.localPosition.x,statBarStartPosY,0); | |
} | |
//Get the width and height of the current status bar to adjust the collider | |
float curItemXVal = statusComponent.GetXPBarPixelHeight(); | |
float curItemYVal = statusComponent.GetBarWidth(); | |
//Adjust the collider to the size of the gameobject | |
BoxCollider bCollider = rowItems[s].GetComponent<BoxCollider>(); | |
bCollider.size = new Vector3(curItemXVal,curItemYVal,1); | |
bCollider.center = new Vector3(curItemXVal/2,0,0); | |
//Set the last entry date to use for repositioning the stats bars based on date | |
lastEntryDate = curDate; | |
} | |
//Reset the scrollbar | |
sv.UpdatePosition(); | |
sv.ResetPosition(); | |
//Reassign the scrollbar | |
sv.horizontalScrollBar = tempScrollbar; | |
sv.SetDragAmount(0,0, true); | |
sv.horizontalScrollBar.value = 1; | |
SetupDefaultExerciseVals(selectedExerciseName); | |
SetStatus("Getting exercise list to complete..."); | |
//Determine which exercises are left to complete | |
StartCoroutine(SetupExercisesToComplete()); | |
} | |
// GOING TO TRY TO GRAB ALL THE DATA FOR EXERCISES TO COMPLETE | |
public IEnumerator SetupExercisesToComplete(){ | |
//Need to go through every exercise | |
for (int k = 0; k < 1; k++){ | |
yield return StartCoroutine(editDB.GetRemainingRequirements(ourUsername,selectedProjectName)); | |
} | |
} | |
public void FillListRemainingExercises(List<string> exercisesRemain){ | |
UIScrollView sv = needToCompleteList.GetComponent<UIScrollView>(); | |
UIProgressBar tempScrollbar = sv.verticalScrollBar; | |
sv.verticalScrollBar = null; | |
sv.ResetPosition(); | |
for (int i = 0; i < exercisesRemain.Count; i++){ | |
//Instantiate the task item and parent it to the scrolling list so it can scroll | |
GameObject newRowItem = Instantiate(exerciseNeededPrefab) as GameObject; | |
newRowItem.transform.parent = needToCompleteList; | |
//Offset the UILabel based on the row and column numbers | |
float addColumn = 25 * i; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(508,5 - addColumn,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Set the text of the item | |
UILabel rowLabel = newRowItem.GetComponent<UILabel>(); | |
rowLabel.text = exercisesRemain[i]; | |
//Add tag so the gameobject can be deleted | |
newRowItem.tag = "DisplayData"; | |
taskListItems.Add(newRowItem); | |
} | |
//Reset the scrollbar | |
sv.UpdatePosition(); | |
sv.ResetPosition(); | |
//Reassign the scrollbar | |
sv.verticalScrollBar = tempScrollbar; | |
sv.verticalScrollBar.value = 0; | |
//SetStatus("Ready."); | |
} | |
public void RefreshExerciseTypes(){ | |
} | |
public void RefreshPopuplistTables(){ | |
//Get a list of all the table names | |
//tableNames = db.GetAllTableNames(); | |
string query = "SELECT Name FROM Categories"; | |
List<object> selectedRows = db.ReturnList(query); | |
//Add all names to the popup list | |
for (int i = 0; i < selectedRows.Count; i++){ | |
List<object> newList = (List<object>) selectedRows[i]; | |
for (int k = 0; k < newList.Count; k++){ | |
tableNames.Add(newList[k].ToString()); | |
//DatabaseTablesGUI.items.Add(newList[k].ToString()); | |
Debug.Log("selected row:" + newList[k].ToString()); | |
} | |
} | |
Debug.Log("FinishedRefreshing"); | |
} | |
public void InsertIntoGetStats(string tableName,List<string> values,string columnName, string whereClause){ | |
} | |
// Insert into the specified table | |
public void InsertInto(string tableName,List<string> values){ | |
db.InsertInto(tableName,values); | |
} | |
public void InsertRow(List<string> values){ | |
//Must have every column filled in order to work | |
values.Add ("'f'"); | |
values.Add ("'f'"); | |
values.Add ("'f'"); | |
db.InsertInto(selectedProjectName,values); | |
} | |
public void GetColumnNames(){ | |
//Get all the column names from the selected table | |
List<string> columnNames = db.GetAllColumnNames(selectedProjectName); | |
for (int i = 0; i < columnNames.Count; i++){ | |
CreateUILabel(columnNames[i],-1,i); | |
Debug.Log("column:" + columnNames[i]); | |
} | |
} | |
public void DeleteAllDisplayObjects(){ | |
//Delete any gameobjects with tag for previous display data | |
GameObject[] objects = GameObject.FindGameObjectsWithTag( "DisplayData" ); | |
foreach( GameObject go in objects ) | |
{ | |
Destroy( go ); | |
} | |
} | |
public void RenameTable(){ | |
} | |
public void RenameColumn(){ | |
} | |
public void ResortRow(){ | |
} | |
public void ResortColumn(){ | |
} | |
public void ReadFullTable(){ | |
DeleteAllDisplayObjects(); | |
UIScrollView sv = scrollingList.GetComponent<UIScrollView>(); | |
sv.ResetPosition(); | |
//Read all the data in the table | |
List<object> fullTableData = new List<object>(); | |
fullTableData = db.ReadFullTable(selectedProjectName); | |
GetColumnNames(); | |
for (int i = 0; i < fullTableData.Count; i++){ //Rows | |
List<object> newList = (List<object>) fullTableData[i]; | |
for (int k = 0; k < newList.Count; k++){ //Columns | |
//For every column list the data in that cell | |
object newData = newList[k]; | |
// Debug.Log("data: i:" + i + " k:" + k + " " + newData.ToString()); | |
CreateUILabel(newData.ToString(),i,k); | |
} | |
} | |
sv.ResetPosition(); | |
} | |
public void CreateUILabel(string labelText, int row, int column){ | |
//Instantiate the UILabel and parent it to the scrolling list so it can scroll | |
GameObject newRowItem = Instantiate(labelPrefab) as GameObject; | |
newRowItem.transform.parent = scrollingList; | |
//Offset the UILabel based on the row and column numbers | |
float addColumn = 200 * column; | |
float addRow = 20 * row; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(labelCreationLocation.x + addColumn,labelCreationLocation.y - addRow,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Set the text | |
UILabel labelComponent = newRowItem.GetComponent<UILabel>(); | |
labelComponent.text = labelText; | |
//Add tag so the gameobject can be deleted | |
newRowItem.tag = "DisplayData"; | |
} | |
public void DeleteTableContents(){ | |
db.DeleteTableContents(selectedProjectName); | |
} | |
public void CreateTable(string newTableName,List<string> columnNames, List<string> columnTypes){ | |
//CreateTable | |
db.CreateTable(newTableName,columnNames,columnTypes); | |
} | |
public void CreateColumn(string columnName, string columnType){ | |
//Adds a column to the selected table | |
db.CreateColumn(selectedProjectName,columnName, columnType); | |
} | |
public void GetStatBars(string tableName,string columnsToSelect, string columnName, string whereClause){ | |
UIScrollView sv = horizScrollList.GetComponent<UIScrollView>(); | |
Debug.Log("GETTING THE STAT BARS"); | |
UIProgressBar tempScrollbar = sv.horizontalScrollBar; | |
sv.horizontalScrollBar = null; | |
DeleteAllDisplayObjects(); | |
sv.ResetPosition(); | |
if (useLocalDB){ | |
List<object> selectedRows = db.SingleSelectWhere(tableName,columnsToSelect,columnName,"=","'"+whereClause+"'"); | |
List<GameObject> rowItems = new List<GameObject>(); | |
int greatestRepsValue = 0; | |
for (int i = 0; i < selectedRows.Count; i++){ //Rows | |
List<object> newList = (List<object>) selectedRows[i]; | |
List<string> graphItemData = new List<string>(); | |
int repsValue = 0; | |
int weightValue = 0; | |
//Date data | |
int dayValue = 0; | |
int yearValue = 0; | |
int monthValue = 0; | |
//Month and year to compare if we should filter this data out | |
int currentMonth = System.DateTime.Now.Month; | |
int currentYear = System.DateTime.Now.Year; | |
if (filterOn){ | |
currentMonth = 2; //Filter by month of February | |
currentYear = 14; //Filter by this 2014 | |
} | |
for (int k = 0; k < newList.Count; k++){ //Column Data for the graph object | |
//For every column list the data in that cell | |
object newData = newList[k]; | |
if (k == 0){ | |
int.TryParse(newData.ToString(),out yearValue); | |
} | |
else if (k == 1){ | |
int.TryParse(newData.ToString(),out monthValue); | |
} | |
else if (k == 2){ | |
int.TryParse(newData.ToString(),out dayValue); | |
} | |
else if (k == 4){ | |
int.TryParse(newData.ToString(),out repsValue); | |
} | |
else if (k == 5){ | |
int.TryParse(newData.ToString(),out weightValue); | |
} | |
graphItemData.Add(newData.ToString()); | |
} | |
//if(the date of the entry is within the bounds of the filter than create the game object | |
//Instantiate a new data object | |
GameObject newRowItem = Instantiate(statsBarPrefab) as GameObject; | |
newRowItem.transform.parent = horizScrollList; | |
//Offset the graph object based on the row and column numbers | |
float addColumn = 65 * i; | |
//Set the position and scale | |
newRowItem.transform.localPosition = new Vector3(statsBarCreationLocation.x + addColumn,statsBarCreationLocation.y,0); | |
newRowItem.transform.localScale = new Vector3(1,1,1); | |
//Get the component for the graph item | |
StatusBar statusComponent = newRowItem.GetComponent<StatusBar>(); | |
string entryDate = (monthValue + "/" + dayValue); | |
//Set the max value on the grid | |
if (repsValue > greatestRepsValue) | |
greatestRepsValue = repsValue; | |
statusComponent.SetXPBar(repsValue,entryDate,weightValue,7); | |
newRowItem.tag = "DisplayData"; | |
rowItems.Add(newRowItem); | |
} | |
//Set the max value for all the items | |
for (int s = 0; s < rowItems.Count; s++){ | |
StatusBar statusComponent = rowItems[s].GetComponent<StatusBar>(); | |
statusComponent.AdjustHighestGraphValue(greatestRepsValue); | |
} | |
} | |
//Reset the scrollbar | |
sv.UpdatePosition(); | |
sv.ResetPosition(); | |
//Reassign the scrollbar | |
sv.horizontalScrollBar = tempScrollbar; | |
sv.horizontalScrollBar.value = 0; | |
} | |
public void SetTaskPriorityColors(int currentPriority){ | |
Color onColor = new Color(20/255,1,20/255); | |
Color offColor = new Color(1,1,1); | |
switch(currentPriority){ | |
case 0: | |
priority1.color = offColor; | |
priority2.color = offColor; | |
priority3.color = offColor; | |
priority4.color = offColor; | |
priority5.color = offColor; | |
break; | |
case 1: | |
priority1.color = onColor; | |
priority2.color = offColor; | |
priority3.color = offColor; | |
priority4.color = offColor; | |
priority5.color = offColor; | |
break; | |
case 2: | |
priority1.color = onColor; | |
priority2.color = onColor; | |
priority3.color = offColor; | |
priority4.color = offColor; | |
priority5.color = offColor; | |
break; | |
case 3: | |
priority1.color = onColor; | |
priority2.color = onColor; | |
priority3.color = onColor; | |
priority4.color = offColor; | |
priority5.color = offColor; | |
break; | |
case 4: | |
priority1.color = onColor; | |
priority2.color = onColor; | |
priority3.color = onColor; | |
priority4.color = onColor; | |
priority5.color = offColor; | |
break; | |
case 5: | |
priority1.color = onColor; | |
priority2.color = onColor; | |
priority3.color = onColor; | |
priority4.color = onColor; | |
priority5.color = onColor; | |
break; | |
} | |
} | |
public void SetSelectedTaskPriority(int newPriority){ | |
//If a task is selected then adjust the task priority and set the priority color of the task bar | |
if (curSelectedTask != -1){ //If no task selected | |
//If a priority is pressed twice then the priority will be set to none | |
if (newPriority == lastSelectedPriority){ | |
newPriority = 0; | |
} | |
lastSelectedPriority = newPriority; | |
SetTaskPriorityColors(newPriority); | |
//Update the DB | |
TaskRow taskComponent = taskListItems[curSelectedTask].GetComponent<TaskRow>(); | |
taskComponent.UpdatePriority(newPriority); | |
editDB.UpdateTaskPriority(ourUsername, taskComponent.GetTaskID(), newPriority); | |
} | |
} | |
public void SetMainTaskModified(){ | |
//If there is a selected task then set it as modified | |
if (curSelectedTask != -1){ | |
if (!hasSetIntialChange){ | |
hasSetIntialChange=true; | |
} | |
else{ | |
TaskRow taskComponent = taskListItems[curSelectedTask].GetComponent<TaskRow>(); | |
UILabel hourLabel = hourInputLabel.GetComponent<UIInput>().label; | |
UILabel minuteLabel = minuteInputLabel.GetComponent<UIInput>().label; | |
int totalHourInt = 0; | |
int totalMinutesInt = 0; | |
if (int.TryParse(hourInputLabel.value,out totalHourInt)){ | |
//Debug.Log("SucceededParse"); | |
} | |
else | |
Debug.Log("Issue parsing hours"); | |
if (int.TryParse(minuteInputLabel.value, out totalMinutesInt)){ | |
//Debug.Log("SucceededParse"); | |
} | |
else | |
Debug.Log("Issue parsing minutes"); | |
Debug.Log("Has already gone through the initial select"); | |
SetStatus (totalHourInt.ToString() + "h " + totalMinutesInt.ToString() + "m"); | |
bool hasChangedTime = taskComponent.UpdateMinHour(totalHourInt, totalMinutesInt); | |
if (hasChangedTime) | |
taskComponent.SetHasBeenModified(); | |
} | |
// | |
} | |
} | |
public void SetSelectedObject(int thisTaskID, int estHour, int estMin , int thisTaskPriority, string subCategoryName){ | |
hasSetIntialChange=false; | |
bool shouldDisableTaskBar = false; | |
if (thisTaskID == -1){ | |
//We have deselected all tasks, so set all the toolbar values to null | |
thisTaskPriority = 0; //Remove task priority | |
subCategoryName = ""; | |
estHour = 0; | |
estMin = 0; | |
shouldDisableTaskBar = true; | |
} | |
curSelectedTask = thisTaskID; | |
SetTaskPriorityColors(thisTaskPriority); | |
hourInputLabel.value = estHour.ToString(); | |
minuteInputLabel.value = estMin.ToString(); | |
DisableTaskListSelections(curSelectedTask); | |
EnableDisableTopBar(shouldDisableTaskBar); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment