Esempio n. 1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (ValidateInput())
            {
                if (serverPtr2 == null)
                {
                    MessageBox.Show("You didn't started server");
                    return;
                }
                HashTableValues htv = new HashTableValues();
                htv.valid      = true;
                htv.ip         = textBox2.Text;
                htv.locationID = textBox3.Text;
                // Its valid, update Hashtable, update sender IP, and clear texboxes
                HashtableAndDatabaseClass.AddToHashTable(textBox1.Text, htv);
                serverPtr2.updateSender(textBox2.Text);

                // Update setting file
                Properties.Settings.Default.FormManualMAC      = textBox1.Text;
                Properties.Settings.Default.FormManualIP       = textBox2.Text;
                Properties.Settings.Default.FormManualLocation = textBox3.Text;
                Properties.Settings.Default.Save(); // Make it persistant


                // Clear, in case u want to add new device
                textBox2.Text = "";
                textBox1.Text = "";
                textBox3.Text = "";
            }
        }
Esempio n. 2
0
        public static void AddToHashTable(string key, HashTableValues value)
        {
            if (ht.ContainsKey(key))
            {
                return; // Already have that MAC address, ignore
            }

            ht.Add(key, value);
            return;
        }
Esempio n. 3
0
        public static void FetchValuesFromDatabase(string connectionString)
        {
            // Command to get MAC, IP and location ID
            string command1 = "SELECT device.MAC,device.IP,location.id FROM device INNER JOIN location ON device.ID=location.DEVICE_ID ORDER BY location.id";
            //string command2 = "SELECT * FROM device";

            OracleConnection conn = new OracleConnection(connectionString);

            conn.Open();
            OracleCommand cmd = new OracleCommand(command1);

            cmd.Connection  = conn;
            cmd.CommandType = System.Data.CommandType.Text;
            OracleDataReader dr = cmd.ExecuteReader();

            //StringBuilder sMAC = new StringBuilder();
            //StringBuilder sIP = new StringBuilder();

            //int bufferSize = 0;

            HashTableValues htv = new HashTableValues();

            htv.valid = true;

            StringBuilder MACsb   = new StringBuilder(); // Those are for testing purposes
            StringBuilder IPsb    = new StringBuilder();
            StringBuilder locIDsb = new StringBuilder();

            while (dr.Read()) // Read one row
            {
                MACsb.Append(dr.GetValue(0) + Environment.NewLine);
                htv.ip = dr.GetValue(1).ToString();
                IPsb.Append(htv.ip + Environment.NewLine);
                htv.locationID = dr.GetValue(2).ToString();
                locIDsb.Append(htv.locationID + Environment.NewLine);

                // Add read values to hashtable, MAC is key, others are values
                AddToHashTable(dr.GetValue(0).ToString(), htv);
            }
            conn.Close();
        }