private void btCreate_Click(object sender, EventArgs e) { try { Database my_Database = new Database(); if (btCreate.Text == "Create Node") { if (cbSelectNode.SelectedIndex == 0) { if (txtmac.Text != "" && tbLatitude.Text != "" && tbLongitude.Text != "" && tbActor.Text != "") { string mac = txtmac.Text; int latitude = int.Parse(tbLatitude.Text); int longitude = int.Parse(tbLongitude.Text); string actor = tbActor.Text; if (my_Database.CheckSensor(mac) == "true") { int a = my_Database.setSensorPixel_x(mac, latitude); int b = my_Database.setSensorPixel_y(mac, longitude); int c = my_Database.setVanSensor(mac, actor); if (a == 1 && b == 1 && c == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } else { int d = my_Database.setSensor(mac, latitude, longitude, actor); if (d == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } } else { MessageBox.Show("Not enough informations!", "Error"); } } else { if (txtmac.Text != "" && tbLatitude.Text != "" && tbLongitude.Text != "") { string mac = txtmac.Text; int latitude = int.Parse(tbLatitude.Text); int longitude = int.Parse(tbLongitude.Text); string actor = tbActor.Text; if (my_Database.CheckActor(mac) == "true") { int a = my_Database.setActorPixel_x(mac, latitude); int b = my_Database.setActorPixel_y(mac, longitude); if (a == 1 && b == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } else { int d = my_Database.setActor(mac, latitude, longitude); if (d == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } } else { MessageBox.Show("Not enough informations!", "Error"); } } } if (btCreate.Text == "Delete Node") { if (cbmac.SelectedIndex != -1) { string mac = cbmac.Text; DialogResult result = MessageBox.Show("Do you want to delete " + cbSelectNode.Text + " " + cbmac.Text + "?", "Warring",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1); if (result == DialogResult.OK) { if (cbSelectNode.SelectedIndex == 0) { int totalSensor = my_Database.getTotalSensor(); int a = my_Database.deleteSensor(mac); if (a == 1) { totalSensor--; my_Database.setTotalSensor(totalSensor); MessageBox.Show("Deleted succeessful! ", "Informations"); } else { MessageBox.Show("Deleted unsucceessful! ", "Informations"); } } else { int totalActor = my_Database.getTotalActor(); int a = my_Database.deleteActor(mac); if (a == 1) { totalActor--; my_Database.setTotalActor(totalActor); MessageBox.Show("Deleted succeessful!", "Informations"); } else { MessageBox.Show("Deleted unsucceessful!", "Informations"); } } } } else { MessageBox.Show("You must select node or MAC address!", "Error"); } } if (btCreate.Text == "Edit Node") { if (cbSelectNode.SelectedIndex == 0) { if (cbmac.SelectedIndex != -1 && tbLatitude.Text != "" && tbLongitude.Text != "" && tbActor.Text != "") { string mac = cbmac.Text; int latitude = int.Parse(tbLatitude.Text); int longitude = int.Parse(tbLongitude.Text); string actor = tbActor.Text; int a = my_Database.setSensorPixel_x(mac, latitude); int b = my_Database.setSensorPixel_y(mac, longitude); int c = my_Database.setVanSensor(mac, actor); if (a == 1 && b == 1 && c == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } else { MessageBox.Show("Not enough informations!", "Error"); } } else { if (cbmac.SelectedIndex != -1 && tbLatitude.Text != "" && tbLongitude.Text != "") { string mac = cbmac.Text; int latitude = int.Parse(tbLatitude.Text); int longitude = int.Parse(tbLongitude.Text); string actor = tbActor.Text; int a = my_Database.setActorPixel_x(mac, latitude); int b = my_Database.setActorPixel_y(mac, longitude); if (a == 1 && b == 1) { MessageBox.Show("Saved succeessful! ", "Informations"); } } else { MessageBox.Show("Not enough informations!", "Error"); } } } comPort.reload(comPort.pictureBox); } catch { } }