// Use this for initialization void Start() { Database db = new Database(); DAO dao = new DAO(); Debug.Log("Login With Email:\t\t" + dao.LoginWithEmail("*****@*****.**", "aaa")); Debug.Log("Register with Email:\t\t" + dao.Register("*****@*****.**", "zzz")); Debug.Log("Register with Facebook:\t\t" + dao.RegisterWithFacebook("32151fads12321")); Debug.Log("Login with Facebook:\t\t" + dao.LoginWithFacebook("32151fads12321")); Augmon augmon = new Augmon(); augmon.ID = 2; augmon.Total_xp = 292929; augmon.Attack = 25; augmon.Defense = 40; augmon.Happiness = 88; Debug.Log("Update Augmon Info:\t\t" + dao.UpdateAugmon(augmon)); Pedometer p = new Pedometer(); p.ID = 2; p.Total_step = 10231; p.Daily_step = 2131; Debug.Log("Update Pedometer Info:\t\t" + dao.UpdatePedometer(p)); Debug.Log("Get Augmon Info:\t\t" + dao.GetAugmonInfo(2)); Debug.Log("Get Pedometer Info:\t\t" + dao.GetPedometerInfo(2)); Debug.Log("Get User Info:\t\t" + dao.GetUserInfo(2)); }
public Database() { DropTables(); // Drop table to ensure that the table is fresh CheckDbExist("1"); GetAugmonInfo(); // retrieve default augmon data GetPedometerInfo(); // retrieve default pedometer data Augmon tempmon = new Augmon(); /*** Tested Dummy Data ***/ tempmon.ID = 1; tempmon.Total_xp = 50; tempmon.Lvl = 2; tempmon.Attack = 35; tempmon.Defense = 26; tempmon.Happiness = 99; StoreAugmonInfo(tempmon); Pedometer pp = new Pedometer(); /*** Tested Dummy Data ***/ pp.ID = 1; pp.Total_step = 500; pp.Daily_step = 60; StorePedometerInfo(pp); GetAugmonInfo(); // retrieve updated augmon data GetPedometerInfo(); // retrieve updated pedometer data }
/******************************************************************************************************************************/ /*** Get All function : Augmon ***/ /******************************************************************************************************************************/ public Augmon GetAugmonInfo() { OpenConnection(); Debug.Log("GetAugmonInfo being called"); dbcmd = dbcon.CreateCommand(); string sql = "SELECT * FROM augmon"; dbcmd.CommandText = sql; IDataReader reader = dbcmd.ExecuteReader(); Augmon augmon = new Augmon(); while (reader.Read()) { augmon.ID = reader.GetInt32(0); augmon.Total_xp = reader.GetInt32(1); augmon.Lvl = reader.GetInt32(2); augmon.Attack = reader.GetInt32(3); augmon.Defense = reader.GetInt32(4); augmon.Happiness = reader.GetInt32(5); } Debug.Log("Augmon:\tid = " + augmon.ID + "\ttotal_xp = " + augmon.Total_xp + "\tlvl = " + augmon.Lvl + "\tattack = " + augmon.Attack + "\tdefense = " + augmon.Defense + "\thappiness = " + augmon.Happiness); reader.Close(); reader = null; CloseConnection(); return(augmon); }
/******************************************************************************************************************************/ /*** Update All function : Augmon ***/ /******************************************************************************************************************************/ public void StoreAugmonInfo(Augmon augmon) { OpenConnection(); Debug.Log("StoreAugmonInfo being called"); dbcmd = dbcon.CreateCommand(); dbcmd.CommandType = CommandType.Text; string sql = "UPDATE augmon SET total_xp = " + augmon.Total_xp + ", lvl = " + augmon.Lvl + ", attack = " + augmon.Attack + ", defense = " + augmon.Defense + ", happiness = " + augmon.Happiness + " WHERE id = " + augmon.ID; dbcmd.CommandText = sql; dbcmd.ExecuteNonQuery(); Debug.Log("all columns on augmon table updated"); CloseConnection(); }
public void registerSteps() { DAO database = new DAO(); Pedometer ped = database.GetPedometerInfo(FacebookManager.Instance().user_ID); ped.Total_step += FeaturePedometer.Instance().stepCnt; pedometersteps += FeaturePedometer.Instance().stepCnt; Augmon aug = database.GetAugmonInfo(FacebookManager.Instance().user_ID); aug.Lvl += (int)(FeaturePedometer.Instance().stepCnt / 100); FeaturePedometer.Instance().stepCnt = 0; //update database database.UpdateAugmon(aug); database.UpdatePedometer(ped); }
public bool UpdateAugmon(Augmon augmon) { string url = "http://ec2-54-183-168-17.us-west-1.compute.amazonaws.com/augmonted/augmon/update"; string jsonString; bool result = false; try { ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "{\"augmon_id\":" + augmon.ID + ", \"name\":" + "\"" + augmon.Name + "\"" + "\"total_xp\":" + augmon.Total_xp + ",\"attack\":" + augmon.Attack + ", \"defense\":" + augmon.Defense + ", \"happiness\":" + augmon.Happiness + "}"; byte[] data = encoding.GetBytes(postData); var http = (HttpWebRequest)WebRequest.Create(new Uri(url)); http.Accept = "applicaiton/json"; http.ContentType = "application/json"; http.Method = "POST"; Stream stream = http.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); WebResponse response = http.GetResponse(); stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); jsonString = sr.ReadToEnd(); sr.Close(); stream.Close(); var N = JSON.Parse(jsonString); Debug.Log("Reassembled: " + N.ToString()); var success = N ["success"]; if (success.AsBool) { result = true; } } catch (Exception ex) { Debug.Log("Error : " + ex.Message); } return(result); }
public Augmon GetAugmonInfo(int id) { string url = "http://ec2-54-183-168-17.us-west-1.compute.amazonaws.com/augmonted/augmon/" + id.ToString(); Augmon augmon = new Augmon(); try { HttpWebRequest http = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)http.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader sr = new StreamReader(stream); string jsonString = sr.ReadToEnd(); Debug.Log("jsonString:\t" + jsonString); sr.Close(); stream.Close(); var N = JSON.Parse(jsonString); Debug.Log("string:\t" + N); Debug.Log("Reassembled: " + N.ToString()); var success = N["success"]; Debug.Log("success:\t" + success.AsBool); if (success.AsBool) { augmon.ID = N["data"]["id"].AsInt; augmon.Name = N["data"]["name"]; augmon.Total_xp = N["data"]["total_xp"].AsInt; augmon.Lvl = N["data"]["lvl"].AsInt; augmon.Attack = N["data"]["attack"].AsInt; augmon.Defense = N["data"]["defense"].AsInt; augmon.Happiness = N["data"]["happiness"].AsInt; Debug.Log("Augmon:\t\t" + "ID : " + augmon.ID + "\tTotal_xp : " + augmon.Total_xp + "\tLvl : " + augmon.Lvl + "\tattack : " + augmon.Attack + "\tdefense : " + augmon.Defense + "\thappiness : " + augmon.Happiness); return(augmon); } } catch (Exception ex) { Debug.Log("Error : " + ex.Message); } return(null); }
private void displayStats() { //change this to FB login ID Augmon augmon = database.GetAugmonInfo(FacebookManager.Instance().user_ID); for (int i = 0; i < 5; i++) { RectTransform trans = augmonbuttons[i].ButtonText.rectTransform; augmonbuttons[i].ButtonText.fontStyle = FontStyle.Bold; switch (augmonbuttons[i].name) { case "Battle": augmonbuttons[i].ButtonText.text = "Name: " + augmon.ID; //augmon.Name; trans.anchoredPosition = new Vector2(-20, 0); break; case "Stats": augmonbuttons[i].ButtonText.text = "Level: " + augmon.Lvl; trans.anchoredPosition = new Vector2(-20, 0); break; case "Feed": augmonbuttons[i].ButtonText.text = "Attack: " + augmon.Attack; trans.anchoredPosition = new Vector2(-20, 0); break; case "Steps": augmonbuttons[i].ButtonText.text = "Def: " + augmon.Defense; trans.anchoredPosition = new Vector2(-20, 0); break; case "Logout": //augmonbuttons[i].ButtonText.text = "Health: " + augmon.Happiness + "%"; //augmonbuttons[i].ButtonText.text = "ID: " + augmon.ID; augmonbuttons[i].ButtonText.text = "Health: " + augmon.Happiness + "%"; trans.anchoredPosition = new Vector2(-20, 0); break; } augmonbuttons[i].RippleScript.enabled = false; augmonbuttons[i].Icon.enabled = false; augmonbuttons[i].ButtonScript.enabled = false; } }