2024.6.16
第七十五天
所花时间:2小时
代码量:400+
博客量:1
了解到的知识点:会议——参会记录查询
package com.example.huiyi; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MeetingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_meeting); Button liulanButton = findViewById(R.id.liulan); Button chaxunButton = findViewById(R.id.chaxun); Button yuyueButton = findViewById(R.id.yuyue); Button xinxiButton = findViewById(R.id.xinxi); liulanButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳转到浏览会议室信息页面 Intent intent = new Intent(MeetingActivity.this, LiulanActivity.class); startActivity(intent); } }); chaxunButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳转到查询会议室信息页面 Intent intent = new Intent(MeetingActivity.this, SearchActivity.class); startActivity(intent); } }); yuyueButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳转到会议预约页面 Intent intent = new Intent(MeetingActivity.this, YuyueActivity.class); startActivity(intent); } }); xinxiButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳转到参会信息页面 Intent intent = new Intent(MeetingActivity.this, CanhuiActivity.class); startActivity(intent); } }); } }
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MeetingActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="50dp"> <Button android:id="@+id/liulan" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="浏览会议室信息" /> <Button android:id="@+id/chaxun" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="查询会议室信息" /> <Button android:id="@+id/yuyue" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="会议预约" /> <Button android:id="@+id/xinxi" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="参会信息" /> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
package com.example.huiyi; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.widget.ListView; import androidx.appcompat.app.AppCompatActivity; import com.example.huiyi.entity.Meeting; import com.example.huiyi.utils.JDBCUtils; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; // Activity to view meeting applications public class CanhuiActivity extends AppCompatActivity { private ListView listView; private List<Meeting> meetingList = new ArrayList<>(); private MeetingAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_canhui); listView = findViewById(R.id.listView); adapter = new MeetingAdapter(this, meetingList); listView.setAdapter(adapter); fetchMyMeetings(); } private void fetchMyMeetings() { new Thread(() -> { Connection connection = JDBCUtils.getConn(); String sql = "SELECT * FROM Meeting WHERE Participants LIKE ?"; try (PreparedStatement ps = connection.prepareStatement(sql)) { ps.setString(1, "%" + getCurrentUserName() + "%"); try (ResultSet rs = ps.executeQuery()) { meetingList.clear(); while (rs.next()) { Meeting meeting = new Meeting(rs.getInt("MeetingId"), rs.getString("MeetingName"), rs.getString("MeetingContent"), rs.getString("MeetingBegin"), rs.getString("MeetingEnd"), rs.getString("Participants"), rs.getString("AuditStatus"), rs.getString("AuditOpinion")); meetingList.add(meeting); } runOnUiThread(() -> adapter.notifyDataSetChanged()); } } catch (SQLException e) { e.printStackTrace(); } }).start(); } private String getCurrentUserName() { // 从SharedPreferences中获取已登录用户的用户名 SharedPreferences sharedPref = getSharedPreferences("app_prefs", Context.MODE_PRIVATE); String 李四 = null; return 李四; // 返回已登录用户的用户名,如果没有则返回空字符串 } }
<!-- res/layout/activity_meeting_detail.xml --> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:id="@+id/meetingName" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="会议主题" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/meetingContent" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="会议内容" /> <TextView android:id="@+id/meetingBeginTime" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="开始时间" /> <TextView android:id="@+id/meetingEndTime" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="结束时间" /> <TextView android:id="@+id/meetingParticipants" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="参会人员" /> <TextView android:id="@+id/meetingAuditStatus" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="审核状态" /> <TextView android:id="@+id/meetingAuditOpinion" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="审核意见" /> </LinearLayout> </ScrollView>