private List <Cabinet> GetCabinets() { List <Cabinet> result = new List <Cabinet>(); foreach (string[] row in parentForm.GetTableFromDB("SELECT id, cabinet FROM cabinets;", 2)) { result.Add(new Cabinet(int.Parse(row[0]), row[1])); } return(result); }
private void UpdateDeviceTree() //обновление дерева с устройствами { DevicesTree.Nodes.Clear(); //очистка дерева if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'MB');", 1)[0][0] == "1") // делаем запрос в базу, если есть материнки { DevicesTree.Nodes.Add("MB", "Материнская плата"); // и если есть устройства соответствующекго типа добавляем ветку //и в добавленную ветку поштучно добавляем все устройства такого типа foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, manufacturer, model ,name ,product, serial_number FROM device_mb WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='MB' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "));", 6)) { string result = string.Empty; string manufaturer = row[1] != "-1" ? row[1] : "Не известно"; string model = row[2] != "-1" ? row[2] : "Не известно"; string name = row[3] != "-1" ? row[3] : "Не известно"; string product = row[4] != "-1" ? row[4] : "Не известно"; string serial_number = row[5] != "-1" ? row[5] : "Не известно"; result = string.Format("Производитель: {0}" + " Model: {1}" + " Name: {2}" + " Product: {3}" + " Serial number: {4}", manufaturer, model, name, product, serial_number); DevicesTree.Nodes["MB"].Nodes.Add(row[0], result); } } //остальные куски кода работают аналогично if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'CPU');", 1)[0][0] == "1") { DevicesTree.Nodes.Add("CPU", "Процессор"); foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, manufacturer, name ,cores ,clock_speed FROM device_cpu WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='CPU' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "))", 5)) { string result = string.Empty; string manufaturer = row[1] != "-1" ? row[1] : "Не известно"; string name = row[2] != "-1" ? row[2] : "Не известно"; string cores = row[3] != "-1" ? row[3] : "Не известно"; string clock_speed = row[4] != "-1" ? row[4] : "Не известно"; result = string.Format("Производитель: {0}" + " Model: {1}" + " Cores: {2}" + " Clock Speed: {3} MHz", manufaturer, name, cores, clock_speed); DevicesTree.Nodes["CPU"].Nodes.Add(row[0], result); } } if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'RAM');", 1)[0][0] == "1") { DevicesTree.Nodes.Add("RAM", "Память"); foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, manufacturer, clock_speed, memory_type, form_factor,size FROM device_ram WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='RAM' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "))", 6)) { string result = string.Empty; string manufaturer = row[1] != "-1" ? row[1] : "Не известно"; string clock_speed = row[2] != "-1" ? row[2] : "Не известно"; string memory_type = row[3] != "-1" ? row[3] : "Не известно"; string form_factor = row[4] != "-1" ? row[4] : "Не известно"; string size = row[5] != "-1" ? (ulong.Parse(row[5]) / 1024 / 1024).ToString() : "Не известно"; result = string.Format("Производитель: {0}" + " Clock_Speed: {1}MHz" + " Memory_Type: {2}" + " Form_Factor: {3}" + " Size: {4}MB", manufaturer, clock_speed, memory_type, form_factor, size); DevicesTree.Nodes["RAM"].Nodes.Add(row[0], result); } } if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'HDD');", 1)[0][0] == "1") { DevicesTree.Nodes.Add("HDD", "Хранилище"); foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, description, caption, size,free_space, file_system FROM device_hdd WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='HDD' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "))", 6)) { string result = string.Empty; string description = row[1] != "-1" ? row[1] : "Не известно"; string caption = row[2] != "-1" ? row[2] : "Не известно"; double size = double.Parse(row[3]) / 1024 / 1024 / 1024; double free_space = double.Parse(row[4]) / 1024 / 1024 / 1024; string File_system = row[5] != "-1" ? row[5] : "Не известно"; result = string.Format(" description: {0}" + " caption: {1}" + " size: {2:#.##} GB" + " free_space: {3:#.##} GB" + " File_system: {4}", description, caption, size, free_space, File_system); DevicesTree.Nodes["HDD"].Nodes.Add(row[0], result); } } if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'NET');", 1)[0][0] == "1") { DevicesTree.Nodes.Add("NET", "Сетевые адаптеры"); foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, mac, description, gateway FROM device_net WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='NET' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "))", 4)) { string result = string.Empty; string mac = row[1] != "-1" ? row[1] : "Не известно"; string description = row[2] != "-1" ? row[2] : "Не известно"; string gateway_id = row[3] != "-1" ? row[3] : "Не известно"; result = string.Format("" + " mac: {0}" + " description: {1}" + " gateway: {2}", mac, description, gateway_id); DevicesTree.Nodes["NET"].Nodes.Add(row[0], result); foreach (string[] ip in parentForm.GetTableFromDB("SELECT ip FROM net_ip_addresses WHERE mac='" + row[1] + "';", 1)) { DevicesTree.Nodes["NET"].Nodes[row[0]].Nodes.Add(ip[0], "Сетевой адресс: " + ip[0]); } } } if (parentForm.GetTableFromDB("SELECT EXISTS(SELECT device_type FROM devices WHERE id IN (SELECT device_id FROM host_devices WHERE host_id = " + host_id + ") AND device_type = 'HDD');", 1)[0][0] == "1") { DevicesTree.Nodes.Add("GPU", "Видеоадаптер"); foreach (string[] row in parentForm.GetTableFromDB("SELECT device_name_hash, name, memory_size FROM device_gpu WHERE device_name_hash IN (SELECT device_name_hash FROM devices WHERE device_type='GPU' AND id IN(SELECT device_id FROM host_devices WHERE host_id=" + host_id + "))", 3)) { string result = string.Empty; string name = row[1] != "-1" ? row[1] : "Не известно"; double memory_size = double.Parse(row[2]) / 1024 / 1024; result = string.Format("" + " name: {0}" + " memory_size: {1:#,##}MB", name, memory_size); DevicesTree.Nodes["GPU"].Nodes.Add(row[0], result); } } DevicesTree.Update(); //обновляем дерево }