public NetPort(NetDevice new_device) { id_real = id; id++; device = new_device; enabled = false; settings = new NetSettings(); sprite = new PictureBox { Name = "port", BackColor = System.Drawing.Color.Transparent, Size = new Size(32, 32), Location = new Point(5, 5), Visible = true, Image = Image.FromFile("port.png"), }; sprite.SizeMode = PictureBoxSizeMode.StretchImage; sprite.Size = new Size(6, 6); sprite.MouseClick += OnMouseClick; connected_port = null; context = new ContextMenuStrip(); // создаем элементы меню ToolStripMenuItem deleteMenuItem = new ToolStripMenuItem("Удалить связь"); // добавляем элементы в меню context.Items.Add(deleteMenuItem); // ассоциируем контекстное меню с текстовым полем sprite.ContextMenuStrip = context; // устанавливаем обработчики событий для меню deleteMenuItem.Click += deleteMenuItem_Click; }
public void deleteConnection() { if (connected_port != null) { connected_port.connected_port = null; connected_port = null; device.workspace.panel.Refresh(); } }
public Workspace(Panel p) { devices = new List <NetDevice>(); panel = p; touched_device = null; pc_settings = null; sw_settings = null; rt_settings = null; pr_settings = null; start_connection = false; first_port = null; GetActualVersion(); }
private void OnMouseClick(object sender, MouseEventArgs e) { if (device.workspace.start_connection) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (device.workspace.first_port == null) { if (connected_port != null) { return; } device.workspace.first_port = this; } else { if (connected_port != null) { return; } foreach (NetPort port in device.ports) { if (port == device.workspace.first_port) { return; } } device.workspace.first_port.connected_port = this; this.connected_port = device.workspace.first_port; device.workspace.first_port = null; device.workspace.panel.Refresh(); } } } else { if (e.Button == System.Windows.Forms.MouseButtons.Right) { } } }
public void LoadDB(int load_version_id, int version_number) { GetActualVersion(); using (Network_SchemeEntities db = new Network_SchemeEntities(DBUtils.getConnString())) { List <Network_Hardware> db_devices; List <Network_Settings> db_settings; List <Network_Ports> db_ports; List <Network_Connections> db_connections; try { db_devices = db.Network_Hardware.Where(b => b.C_Version == load_version_id).ToList <Network_Hardware>(); db_settings = db.Network_Settings.Where(b => b.C_Version == load_version_id).ToList <Network_Settings>(); db_ports = db.Network_Ports.Where(b => b.C_Version == load_version_id).ToList <Network_Ports>(); db_connections = db.Network_Connections.Where(b => b.C_Version == load_version_id).ToList <Network_Connections>(); } catch { MessageBox.Show("Ошибка загрузки актуальной версии"); return; } panel.Controls.Clear(); devices.Clear(); NetDevice.id = 0; NetSettings.id = 0; NetPort.id = 0; NetDevice.pc_id = 0; NetDevice.pr_id = 0; NetDevice.sw_id = 0; NetDevice.ro_id = 0; int max_real_id = 0; int id_shift = (load_version_id) * (-1000); foreach (Network_Hardware db_device in db_devices) { int id = id_shift + db_device.ID; if (id > max_real_id) { max_real_id = id; } NetDevice device = new NetDevice(this, db_device.C_Type, false); device.x = db_device.C_Interface_X; device.y = db_device.C_Interface_Y; device.name = db_device.C_Name; device.title.Text = device.name; device.id_real = id; devices.Add(device); } NetDevice.id = max_real_id + 1; max_real_id = 0; foreach (Network_Ports db_port in db_ports) { int id = id_shift + db_port.ID; if (id > max_real_id) { max_real_id = id; } NetPort port = new NetPort(null); port.id_real = id; port.enabled = db_port.C_Status; port.settings_id = id_shift + db_port.C_Settings_ID; // set device int device_id = id_shift + db_port.C_Hardware_ID; foreach (NetDevice device in devices) { if (device.id_real == device_id) { port.device = device; for (int i = 0; i < device.ports.Count; i++) { if (device.ports[i] == null) { device.ports[i] = port; break; } } break; } } } NetPort.id = max_real_id + 1; max_real_id = 0; foreach (Network_Settings db_setting in db_settings) { int id = id_shift + db_setting.ID; if (id > max_real_id) { max_real_id = id; } NetSettings setting = new NetSettings(); setting.id_real = id; setting.IP = db_setting.C_IP; setting.default_gateway = db_setting.C_Default_Gateway; setting.subnet_mask = db_setting.C_Subnet_Mask; // set device bool stop = false; foreach (NetDevice device in devices) { if (stop) { break; } foreach (NetPort port in device.ports) { if (setting.id_real == port.settings_id) { port.settings = setting; stop = true; break; } } } } NetSettings.id = max_real_id + 1; foreach (Network_Connections db_connection in db_connections) { int port_start_id = id_shift + db_connection.C_From_Port_ID; int port_end_id = id_shift + db_connection.C_To_Port_ID; NetPort start_port = null; NetPort end_port = null; bool stop = false; foreach (NetDevice device in devices) { if (stop) { break; } foreach (NetPort port in device.ports) { if (port.id_real == port_start_id) { start_port = port; stop = true; break; } } } stop = false; foreach (NetDevice device in devices) { if (stop) { break; } foreach (NetPort port in device.ports) { if (port.id_real == port_end_id) { end_port = port; stop = true; break; } } } start_port.connected_port = end_port; end_port.connected_port = start_port; } } RefreshDraw(); panel.Refresh(); MessageBox.Show("Успешно загружена версия : " + version_number); }