Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using MySql.Data.MySqlClient;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class MySqlTestScript : MonoBehaviour
- {
- private static MySqlTestScript _instnace;
- public static MySqlTestScript sharedInstance()
- {
- return _instnace;
- }
- string row = "";
- public string host = "*****";
- public string database = "*******";
- public string usrename= "*******";
- public string password = "******";
- public List<Data> userData = new List<Data>();
- Data data;
- void Awake()
- {
- _instnace = this;
- }
- // Use this for initialization
- public void Start()
- {
- GetDataFromDatabase();
- }
- public string GetDataFromDatabase()
- {
- string myConnectionString = "Server="+host+";Database="+database+";Uid="+usrename+ ";Pwd="+password+";";
- MySqlConnection connection = new MySqlConnection(myConnectionString);
- MySqlCommand command = connection.CreateCommand();
- command.CommandText = "SELECT * FROM Users";
- MySqlDataReader Reader;
- try
- {
- connection.Open();
- Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- for (int i = 0; i < Reader.FieldCount; i++)
- {
- //rfid_tags.Add (Reader.GetString("UserName"));
- //rfid_tags.Add(Reader.GetString("RFID_Tag"));
- data = new Data(Reader.GetString("UserName"), Reader.GetString("RFID_Tag"));
- userData.Add(data);
- // ws.DomainUrl = reader.GetString("DomainUrl");
- // rfid_tags.Add(Reader.GetValue(i).ToString() + ",");
- // row += Reader.GetValue(i).ToString() + ", ";
- }
- Debug.Log(row);
- }
- }
- catch (Exception x)
- {
- Debug.Log(x.Message);
- return x.Message;
- }
- connection.Close();
- return row;
- }
- }
- public class Data {
- public string username { get; set; }
- public string rfid { get; set; }
- public Data(string _name, string _rfid)
- {
- username = _name;
- rfid = _rfid;
- }
- public void SetUserName(string _userName) { username = _userName; }
- public void SetRFID(string _rfid) { rfid = _rfid; }
- }
- void OnTagsReported(ImpinjReader sender, TagReport report)
- {
- Debug.Log("OnTagsReported");
- // This event handler is called asynchronously
- // when tag reports are available.
- // Loop through each tag in the report
- // and print the data.
- foreach (Tag tag in report)
- {
- Debug.Log(tag.Epc);
- // Debug.Log(MySqlTestScript.sharedInstance().rfid_tags[0]);
- Debug.Log("STEP ONE");
- for (int i = 0; i < MySqlTestScript.sharedInstance().userData.Count; i++)
- {
- Debug.Log("STEP TWO");
- if (tag.Epc.ToString().Trim() == MySqlTestScript.sharedInstance().userData[i].rfid)
- {
- Debug.Log("STEP THREE");
- // TODO References the Name
- Loom.QueueOnMainThread(() => {
- namesTxt[i].text = MySqlTestScript.sharedInstance().userData[i].username;
- });
- }
- }
- if (MySqlTestScript.sharedInstance().longNumbers.Length > 1) {
- if (tag.Epc.ToString().Trim() == MySqlTestScript.sharedInstance().longNumbers[0].ToString()) {
- if(MySqlTestScript.sharedInstance().userNames[0] != null)
- txt1.text = "Hello "+ MySqlTestScript.sharedInstance().userNames[0];
- }
- }
- }
- else {
- txt1.text = "";
- }
- using UnityEngine;
- using System.Collections;
- using MySql.Data.MySqlClient;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class MySqlTestScript : MonoBehaviour
- {
- private static MySqlTestScript _instnace;
- public static MySqlTestScript sharedInstance()
- {
- return _instnace;
- }
- string row = "";
- public string host = "*****";
- public string database = "*******";
- public string usrename= "*******";
- public string password = "******";
- public List<AppUser> users = new List<AppUser>();
- void Awake()
- {
- _instnace = this;
- }
- // Use this for initialization
- public void Start()
- {
- GetDataFromDatabase();
- }
- public string GetDataFromDatabase()
- {
- string myConnectionString = "Server=" + host + ";Database=" + database + ";Uid=" + usrename + ";Pwd=" + password + ";";
- MySqlConnection connection = new MySqlConnection(myConnectionString);
- MySqlCommand command = connection.CreateCommand();
- command.CommandText = "SELECT * FROM users";
- MySqlDataReader Reader;
- try
- {
- connection.Open();
- Reader = command.ExecuteReader();
- while (Reader.Read())
- {
- users.Add(new AppUser() {
- username = Reader.GetString("UserName").Trim(),
- rfid = Reader.GetString("longNumbers ").Trim()
- });
- }
- }
- catch (Exception x)
- {
- Debug.Log(x.Message);
- return x.Message;
- }
- connection.Close();
- return row;
- }
- }
- public Class AppUser
- {
- public string rfid { get; set; }
- public string username { get; set; }
- }
- void OnTagsReported(ImpinjReader sender, TagReport report)
- {
- Debug.Log("OnTagsReported");
- // This event handler is called asynchronously
- // when tag reports are available.
- // Loop through each tag in the report
- // and print the data.
- foreach (Tag tag in report)
- {
- Debug.Log(tag.Epc);
- List<AppUser> appUsers = MySqlTestScript.sharedInstance().users;
- int numUsers = appUsers.Count;
- Debug.Log(numUsers);
- for (int i = 0; i < numUsers; i++)
- {
- if (tag.Epc.ToString().Trim() == appUsers[i].rfid)
- {
- // TODO References the Name
- Loom.QueueOnMainThread(() => {
- if (i < namesTxt.Count) namesTxt[i].Text = appUsers[i].username; //assumes textnames is a "List" of textboxes and is already populated with instances of text1, text2 text3 etc. The if is just to guard against there being more rows in the DB than textboxes
- });
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment