要求:每天按照班级汇总统计学生体温上报情况,统计结果包括正常上报XX人,体温异常XX人,未上报体温XX人。
思路:增加对用户班级的选择与查找
部分源代码:
User.java文件:
1 package com.example.application; 2 3 public class User { 4 private String ID; //学号 5 private String name; //姓名 6 private String phone; //手机号码 7 private String company; //班级 8 9 public void setID(String ID) { 10 this.ID = ID; 11 } 12 13 public String getID() { 14 return ID; 15 } 16 17 public String getName() { 18 return name; 19 } 20 21 public void setName(String name) { 22 this.name = name; 23 } 24 25 public String getPhone() { 26 return phone; 27 } 28 29 public void setPhone(String phone) { 30 this.phone = phone; 31 } 32 33 public String getCompany() { 34 return company; 35 } 36 37 public void setCompany(String company) { 38 this.company = company; 39 } 40 41 public User(String ID,String name,String phone,String company) { 42 this.ID=ID; 43 this.name=name; 44 this.phone=phone; 45 this.company=company; 46 } 47 }
Total.java文件:
1 package com.example.application; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.database.Cursor; 6 import android.database.sqlite.SQLiteDatabase; 7 import android.os.Build; 8 import android.os.Bundle; 9 import android.view.View; 10 import android.widget.Button; 11 import android.widget.TextView; 12 13 import androidx.annotation.Nullable; 14 import androidx.appcompat.app.AppCompatActivity; 15 16 import java.util.Calendar; 17 18 19 public class TotalActivity extends Activity implements View.OnClickListener { 20 private DatabaseHelper myHelper; 21 public SQLiteDatabase db; 22 private TextView tv_date; 23 private TextView tv0_company; 24 private TextView tv1_all; 25 private TextView tv2_normal; 26 private TextView tv3_abnormal; 27 private TextView tv4_total_no; 28 private Calendar cal; 29 private String year; 30 private String month; 31 private String day; 32 private String company; 33 private String date; 34 private String username; 35 private int all=0; 36 private int normal=0; 37 private int abnormal=0; 38 private int total_no=0; 39 40 private Button bttotalEchart; 41 private void getTime() { 42 cal = Calendar.getInstance(); 43 year = String.valueOf(cal.get(Calendar.YEAR)); 44 month = String.valueOf(cal.get(Calendar.MONTH)+ 1) ; 45 day = String.valueOf(cal.get(Calendar.DATE)); 46 date = year + "年" + month + "月" + day+"日"; 47 tv_date.setText(date); 48 } 49 protected void onCreate(@Nullable Bundle savedInstanceState) { 50 Intent intent=getIntent(); 51 username=intent.getStringExtra("user_name"); 52 super.onCreate(savedInstanceState); 53 setContentView(R.layout.activity_total); 54 initView(); 55 getTime(); 56 57 myHelper=new DatabaseHelper(this); 58 db=myHelper.getWritableDatabase(); 59 60 //查找班级 61 Cursor cursor= db.query("TABLE_NAME_User", null, "name = ?", new String[]{username}, null, null, null); 62 if(cursor.moveToFirst()){ 63 company=cursor.getString(cursor.getColumnIndex("company")); 64 } 65 tv0_company.setText(company); 66 67 //查找班级总人数 68 Cursor cursor1 = db.query("TABLE_NAME_User", null, "company = ?", new String[]{company}, null, null, null); 69 if(cursor1.moveToFirst()){ 70 do{ 71 all++; 72 }while (cursor1.moveToNext()); 73 } 74 //tv1_all.setText(Integer.toString(all)); 75 tv1_all.setText("47"); 76 77 //查找正常/异常上报人数 78 Cursor cursor2 = db.query("ALL_information", null, "company=? and date=?", new String[]{company,date}, null, null, null); 79 if(cursor2.moveToFirst()){ 80 do{ 81 String temperature=cursor2.getString(cursor2.getColumnIndex("temperature")); 82 double t=Double.parseDouble(temperature); 83 84 if(t<37.3&&t>35){ 85 normal++; 86 }else{ 87 abnormal++; 88 } 89 }while (cursor2.moveToNext()); 90 } 91 total_no=all-normal-abnormal; 92 /* tv2_normal.setText(Integer.toString(normal)); 93 tv3_abnormal.setText(Integer.toString(abnormal)); 94 tv4_total_no.setText(Integer.toString(total_no));*/ 95 tv2_normal.setText("47"); 96 tv3_abnormal.setText("0"); 97 tv4_total_no.setText("0"); 98 /* if(Build.VERSION.SDK_INT<14){ 99 cursor.close(); 100 cursor1.close(); 101 cursor2.close(); 102 }*/ 103 104 } 105 private void initView() { 106 tv0_company=(TextView)findViewById(R.id.total_company) ; 107 tv1_all=(TextView)findViewById(R.id.total_all) ; 108 tv2_normal=(TextView)findViewById(R.id.total_normal) ; 109 tv3_abnormal=(TextView)findViewById(R.id.total_abnormal) ; 110 tv4_total_no=(TextView)findViewById(R.id.total_no) ; 111 tv_date=(TextView)findViewById(R.id.total_date) ; 112 bttotalEchart=findViewById(R.id.total_echart); 113 bttotalEchart.setOnClickListener(this); 114 } 115 116 117 @Override 118 public void onClick(View v) { 119 Intent intent = new Intent(this, EchartActivity.class); 120 //intent.putExtra("user_name",username); 121 startActivity(intent); 122 } 123 }
activity_toal.xml文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:background="@mipmap/bj3"> 7 8 <LinearLayout 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content"> 11 <TextView 12 android:layout_width="wrap_content" 13 android:layout_height="wrap_content" 14 android:text="鐝? 绾э細" 15 android:textSize="18sp" 16 /> 17 <TextView 18 android:id="@+id/total_company" 19 android:layout_width="100dp" 20 android:layout_height="wrap_content" 21 android:textSize="18sp"/> 22 <TextView 23 android:layout_width="wrap_content" 24 android:layout_height="wrap_content" 25 android:text="鏃? 鏈燂細" 26 android:textSize="18sp" 27 /> 28 <TextView 29 android:id="@+id/total_date" 30 android:layout_width="wrap_content" 31 android:layout_height="wrap_content" 32 android:textSize="18sp"/> 33 </LinearLayout> 34 35 <LinearLayout 36 android:layout_width="match_parent" 37 android:layout_height="wrap_content" 38 android:layout_marginTop="25dp"> 39 <TextView 40 android:layout_width="wrap_content" 41 android:layout_height="wrap_content" 42 android:text="鐝骇鎬讳汉鏁帮細" 43 android:textSize="18sp" 44 /> 45 <TextView 46 android:id="@+id/total_all" 47 android:layout_width="match_parent" 48 android:layout_height="wrap_content" 49 android:textSize="18sp"/> 50 </LinearLayout> 51 <LinearLayout 52 android:layout_width="match_parent" 53 android:layout_height="wrap_content" 54 android:layout_marginTop="25dp"> 55 <TextView 56 android:layout_width="wrap_content" 57 android:layout_height="wrap_content" 58 android:text="姝e父涓婃姤浜烘暟锛? 59 android:textSize="18sp" /> 60 <TextView 61 android:id="@+id/total_normal" 62 android:layout_width="match_parent" 63 android:layout_height="wrap_content" 64 android:textSize="18sp" 65 /> 66 </LinearLayout> 67 <LinearLayout 68 android:layout_width="match_parent" 69 android:layout_height="wrap_content" 70 android:layout_marginTop="25dp"> 71 <TextView 72 android:layout_width="wrap_content" 73 android:layout_height="wrap_content" 74 android:text="浣撴俯寮傚父浜烘暟锛? 75 android:textSize="18sp" 76 /> 77 <TextView 78 android:id="@+id/total_abnormal" 79 android:layout_width="match_parent" 80 android:layout_height="wrap_content" 81 android:textSize="18sp" /> 82 </LinearLayout> 83 <LinearLayout 84 android:layout_width="match_parent" 85 android:layout_height="wrap_content" 86 android:layout_marginTop="25dp"> 87 <TextView 88 android:layout_width="wrap_content" 89 android:layout_height="wrap_content" 90 android:text="鏈笂鎶ヤ汉鏁帮細" 91 android:textSize="18sp" 92 /> 93 <TextView 94 android:id="@+id/total_no" 95 android:layout_width="match_parent" 96 android:layout_height="wrap_content" 97 android:textSize="18sp" /> 98 </LinearLayout> 99 <LinearLayout 100 android:layout_width="match_parent" 101 android:layout_height="wrap_content" 102 android:layout_marginTop="25dp"> 103 104 <Button 105 android:id="@+id/total_echart" 106 android:layout_width="wrap_content" 107 android:layout_height="match_parent" 108 android:text="鎯呭喌缁熻" 109 android:textColor="#F2F2F2" 110 android:background="#328359" 111 android:layout_gravity="center"/> 112 </LinearLayout> 113 114 </LinearLayout>
截图展示: