private void MainForm_Load(object sender, EventArgs e) { HotelList hotelList = new HotelList(); hotelList.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(hotelList); List <string> cities = SQLClass.Select("SELECT DISTINCT name FROM cities ORDER BY name"); foreach (string city in cities) { TreeNode node = new TreeNode(city); treeView1.Nodes[0].Nodes.Add(node); List <string> hotels = SQLClass.Select( "SELECT DISTINCT name, id FROM hotels" + " WHERE city='" + node.Text + "' ORDER BY name"); for (int i = 0; i < hotels.Count; i += 2) { TreeNode node2 = new TreeNode(hotels[i]); node2.Tag = hotels[i + 1]; node.Nodes.Add(node2); List <string> rooms = SQLClass.Select( "SELECT DISTINCT name, id FROM room" + " WHERE hotel_id='" + node2.Tag.ToString() + "' ORDER BY name"); for (int j = 0; j < rooms.Count; j += 2) { TreeNode node3 = new TreeNode(rooms[j]); node3.Tag = rooms[j + 1]; node2.Nodes.Add(node3); } } } }
/// <summary> /// Выбор узла дерева /// </summary> private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { #region Выбран город if (e.Node.Level == 0 && e.Node.Text == "Города" || e.Node.Level == 1 && e.Node.Parent.Text == "Города") { HotelList listUC = new HotelList(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } #endregion #region Выбрана гостиница else if (e.Node.Level == 2 && e.Node.Parent.Parent.Text == "Города") { HotelForm listUC = new HotelForm(e.Node.Tag.ToString()); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } #endregion #region Выбрана комната else if (e.Node.Level == 3 && e.Node.Parent.Parent.Parent.Text == "Города") { RoomForm listUC = new RoomForm(e.Node.Tag.ToString()); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } #endregion #region Выбрана админка else if (e.Node.Level == 0 && e.Node.Text == "Админка") { AdminForm listUC = new AdminForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } else if (e.Node.Level == 1 && e.Node.Parent.Text == "Админка" && e.Node.Text == "Гостиницы") { AdminHotelsForm listUC = new AdminHotelsForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } else if (e.Node.Level == 1 && e.Node.Parent.Text == "Админка" && e.Node.Text == "Комнаты") { AdminRoomsForm listUC = new AdminRoomsForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } else if (e.Node.Level == 1 && e.Node.Parent.Text == "Админка" && e.Node.Text == "Бронирования") { Admin.AdminBookingForm listUC = new Admin.AdminBookingForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } else if (e.Node.Level == 1 && e.Node.Parent.Text == "Админка" && e.Node.Text == "Ошибки") { Admin.AdminLogForm listUC = new Admin.AdminLogForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } else if (e.Node.Level == 1 && e.Node.Parent.Text == "Админка" && e.Node.Text == "Пользователи") { AdminUsersForm listUC = new AdminUsersForm(); listUC.Dock = DockStyle.Fill; panel1.Controls.Clear(); panel1.Controls.Add(listUC); } #endregion }