public static ISRoom GetRoomData(int userId) { ISRoom room; using (MySqlConnection conn = DBUtils.GetConnection()) { try { conn.Open(); string query = $"select rooms.id, rooms.roomName, dormitories.name as dormitoryName, address from users join rooms on users.roomId = rooms.id join dormitories on dormitories.id = rooms.dormitoryId where users.id = '{userId}'"; using (var command = new MySqlCommand(query, conn)) using (var reader = command.ExecuteReader()) { if (reader.Read()) { int id = Convert.ToInt32(reader[0]); string roomName = reader[1].ToString(); string dormitoryName = reader[2].ToString(); string address = reader[3].ToString(); room = new ISRoom(id, dormitoryName, roomName, address); return(room); } } } catch (Exception err) { MessageBox.Show("Error: " + err.Message, "Ошибка!"); } } return(null); }
private void SetRoomTab() { ISRoom room = DBRooms.GetRoomData(user.Id); List <ISUser> roomMates = DBRooms.GetRoomMates(user); _SetRoomInfo(room, roomMates); }
private void _SetRoomInfo(ISRoom room, List <ISUser> roomMates) { dormitoryNameField.Text = room.DormitoryName; roomNumField.Text = room.RoomName; addressField.Text = room.Address; if (roomMatesGrid.Rows.Count > 0) { roomMatesGrid.Rows.Clear(); } if (roomMates.Count > 0) { for (int i = 0; i < roomMates.Count; i++) { ISUser u = roomMates[i]; string[] row = new string[3] { (i + 1).ToString(), u.FullName, u.GroupId }; roomMatesGrid.Rows.Add(row); } } }
private void addUserButton_Click(object sender, EventArgs e) { string name = fullNameField.Text; string birthDate = birthDateField.Value.ToString("yyyy-MM-dd"); ISGenders gender = Utils.GetGenderEnum(genderField.Text); string genderStr = Enum.GetName(typeof(ISGenders), gender); string groupId = groupIdField.Text; ISRoles role = Utils.GetRoleEnum(roleField.Text); string roleStr = Enum.GetName(typeof(ISRoles), role); string studTicketId = studTicketIdField.Text; string userName = userNameField.Text; ISRoom room = ISRoom.GetRoomByName(rooms, roomIdField.Text); if (name.Length > 0) { if (birthDate.Length > 0) { if (genderStr.Length > 0) { if (groupId.Length > 0) { if (roleStr.Length > 0) { if (studTicketId.Length > 0) { if (userName.Length > 0) { if (room.Id > 0) { if (DBUsers.AddUser(name, birthDate, roleStr, genderStr, groupId, studTicketId, userName, room.Id)) { MessageBox.Show("Пользователь успешно добавлен!", "Успех!"); this.Close(); } else { MessageBox.Show("Произошла ошибка"); } } else { MessageBox.Show("Необходимо выбрать комнату!", "Ошибка!"); userNameField.Focus(); } } else { MessageBox.Show("Необходимо ввести имя пользователя!", "Ошибка!"); userNameField.Focus(); } } else { MessageBox.Show("Необходимо ввести номер студенческого билета!", "Ошибка!"); studTicketIdField.Focus(); } } else { MessageBox.Show("Необходимо выбрать роль!", "Ошибка!"); roleField.Focus(); } } else { MessageBox.Show("Необходимо ввести название группы!", "Ошибка!"); groupIdField.Focus(); } } else { MessageBox.Show("Необходимо выбрать пол!", "Ошибка!"); genderField.Focus(); } } else { MessageBox.Show("Необходимо выбрать день роджения!", "Ошибка!"); birthDateField.Focus(); } } else { MessageBox.Show("Необходимо ввести ФИО", "Ошибка!"); fullNameField.Focus(); } }