//Draw actor public void DrawActor(string mac) { try { Database myDatabase = new Database(); Bitmap icon_true; Bitmap icon_false; int pixel_x = Convert.ToInt32(myDatabase.getActorPixel_x(mac)); int pixel_y = Convert.ToInt32(myDatabase.getActorPixel_y(mac)); icon_true = new Bitmap(path_icon_actor_true); icon_false = new Bitmap(path_icon_actor_false); string status = myDatabase.getStatusActor(mac); if (status == "true" || status == "True") { gr.DrawImage(icon_true, pixel_x, pixel_y); } else { gr.DrawImage(icon_false, pixel_x, pixel_y); } gr.DrawString(mac, draw_font, draw_brush, pixel_x, pixel_y); } catch { } }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { try { Database myDatabase = new Database(); bool check = false; #if ACTOR_BAOCHAY XmlNodeList node = (myDatabase.xml_bc).GetElementsByTagName("node"); #else XmlNodeList node = (myDatabase.xml).GetElementsByTagName("node"); #endif foreach (XmlNode nodechild in node) { pixel_x = Int32.Parse(nodechild.Attributes["pixel_x"].Value); pixel_y = Int32.Parse(nodechild.Attributes["pixel_y"].Value); actor.Mac = nodechild.Attributes["mac"].Value; status = nodechild.Attributes["status"].Value; if (e.Button == MouseButtons.Right && e.X > pixel_x && e.X < pixel_x + WIDTH && e.Y > pixel_y && e.Y < pixel_y + HEIGHT) { if (actor.Mac == "00") { if (status == "true" || status == "True") { battatca.Enabled = true; MNstatusA.Enabled = true; tattatca.Enabled = true; } else { battatca.Enabled = false; MNstatusA.Enabled = false; tattatca.Enabled = false; } MNstatusA.Text = "Trang thai : " + nodechild.Attributes["status"].Value; ctMenuActor.Show(pictureBox1, new Point(e.X, e.Y)); } else if (actor.Mac[0] == 'B') { if (status == "true" || status == "True") { mnReset.Enabled = true; } else { mnReset.Enabled = false; } ctxMenuReset.Show(pictureBox1, new Point(e.X, e.Y)); } else { sensor.Ip = nodechild.Attributes["network_ip"].Value; MNstatusS.Text = "Trang thai: " + nodechild.Attributes["status"].Value; if (status == "true" || status == "True") { laydulieu.Enabled = true; MNstatusS.Enabled = true; menuTemp.Enabled = true; menuHumi.Enabled = true; menuTemp.Text = "Nhiet do: " + nodechild.Attributes["temperature"].Value + "°C"; menuHumi.Text = "Do am: " + nodechild.Attributes["humidity"].Value + "%"; } else { menuTemp.Text = "Nhiet do: 0°C"; menuHumi.Text = "Do am: 0%"; laydulieu.Enabled = false; MNstatusS.Enabled = false; menuTemp.Enabled = false; menuHumi.Enabled = false; } ctMenuSensor.Show(pictureBox1, new Point(e.X, e.Y)); } check = true; break; } } if (!check) { #if ACTOR_BAOCHAY #else XmlNodeList val = (myDatabase.xml).GetElementsByTagName("val"); status = myDatabase.getStatusActor("00"); foreach (XmlNode valchild in val) { pixel_x = Int32.Parse(valchild.Attributes["pixel_x"].Value); pixel_y = Int32.Parse(valchild.Attributes["pixel_y"].Value); if (e.Button == MouseButtons.Right && e.X > pixel_x && e.X < pixel_x + WIDTH && e.Y > pixel_y && e.Y < pixel_y + HEIGHT) { if (status == "true" || status == "True") { batvan.Enabled = true; tatvan.Enabled = true; MNstatusV.Enabled = true; } else { batvan.Enabled = false; tatvan.Enabled = false; MNstatusV.Enabled = false; } id = Int32.Parse(valchild.Attributes["id"].Value); MNstatusV.Text = "Trang thai : " + valchild.Attributes["state"].Value; ctMenuVan.Show(pictureBox1, new Point(e.X, e.Y)); break; } } #endif } } catch { } }