roomをformの受信からSetUpの保存に置き換え

This commit is contained in:
nemukemo 2024-06-19 14:37:53 +09:00
parent 507cfc739c
commit 74062283af
6 changed files with 156 additions and 40 deletions

View File

@ -3,9 +3,8 @@ import androidx.room.Database;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.TypeConverters; import androidx.room.TypeConverters;
@Database(entities = {QuestionnaireForm.class}, version = 1) @Database(entities = {SetUpTable.class}, version = 1)
@TypeConverters({Converters.class})
public abstract class AppDatabase extends RoomDatabase { public abstract class AppDatabase extends RoomDatabase {
// データベースにアクセスするためのメソッドを提供する // データベースにアクセスするためのメソッドを提供する
public abstract QuestionnaireFormDao questionnaireFormDao(); public abstract SetUpTableDao setUpTableDao();
} }

View File

@ -39,4 +39,60 @@ public class MyDataClass {
", secondDay=" + secondDay + ", secondDay=" + secondDay +
'}'; '}';
} }
//getter
public String getPatronName() {
return patronName;
}
public int getClassId() {
return classId;
}
public List<String> getAddress() {
return address;
}
public List<Timestamp> getFirstDay() {
return firstDay;
}
public int getStudentNumber() {
return studentNumber;
}
public String getChildName() {
return childName;
}
public List<Timestamp> getThirdDay() {
return thirdDay;
}
public List<Timestamp> getSecondDay() {
return secondDay;
}
public double getLatitude() {
return latitude;
}
//setter
public void setPatronName(String patronName) {
this.patronName = patronName;
}
public void setClassId(int classId) {
this.classId = classId;
}
public void setAddress(List<String> address) {
this.address = address;
}
public void setFirstDay(List<Timestamp> firstDay) {
this.firstDay = firstDay;
}
public void setStudentNumber(int studentNumber) {
this.studentNumber = studentNumber;
}
public void setChildName(String childName) {
this.childName = childName;
}
public void setThirdDay(List<Timestamp> thirdDay) {
this.thirdDay = thirdDay;
}
public void setSecondDay(List<Timestamp> secondDay) {
this.secondDay = secondDay;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
} }

View File

@ -1,20 +0,0 @@
package com.example.oplogy;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity
public class QuestionnaireForm {
//主キー
@PrimaryKey(autoGenerate = true)
public int id;
//その他フィールド
public int classId;
public String patronName;
public String address;
public String firstDay;
public int studentNumber;
public String childName;
public String thirdDay;
public String secondDay;
}

View File

@ -1,17 +0,0 @@
package com.example.oplogy;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
@Dao
public interface QuestionnaireFormDao {
@Query("SELECT * FROM QuestionnaireForm")
List<QuestionnaireForm> getAll();
// このメソッドはQuestionnaireFormのリストを受け取りそれらをデータベースに挿入します
@Insert
void insertAll(QuestionnaireForm... questionnaireForms);
}

View File

@ -0,0 +1,86 @@
package com.example.oplogy;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity
public class SetUpTable {
//主キー
@PrimaryKey(autoGenerate = true)
public int id;
public String teacherName;
public String startPoint;
public String endPoint;
public String startTime;
public String endTime;
public String breakStartTime;
public String breakEndTime;
public int totalStudent;
//コンストラクタ
public SetUpTable(String teacherName, String startPoint, String endPoint, String startTime, String endTime, String breakStartTime,String breakEndTime, int totalStudent) {
this.teacherName = teacherName;
this.startPoint = startPoint;
this.endPoint = endPoint;
this.startTime = startTime;
this.endTime = endTime;
this.breakStartTime = breakStartTime;
this.breakEndTime = breakEndTime;
this.totalStudent = totalStudent;
}
//getter
public int getId() {
return id;
}
public String getTeacherName() {
return teacherName;
}
public String getStartPoint() {
return startPoint;
}
public String getEndPoint() {
return endPoint;
}
public String getStartTime() {
return startTime;
}
public String getEndTime() {
return endTime;
}
public String getBreakStartTime() {
return breakStartTime;
}
public String getBreakEndTime() {
return breakEndTime;
}
public int getTotalStudent() {
return totalStudent;
}
//setter
public void setId(int id) {
this.id = id;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
public void setStartPoint(String startPoint) {
this.startPoint = startPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public void setBreakStartTime(String breakStartTime) {
this.breakStartTime = breakStartTime;
}
public void setBreakEndTime(String breakEndTime) {
this.breakEndTime = breakEndTime;
}
public void setTotalStudent(int totalStudent) {
this.totalStudent = totalStudent;
}
}

View File

@ -0,0 +1,12 @@
package com.example.oplogy;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
@Dao
public interface SetUpTableDao {
@Insert
void insertAll(SetUpTable... setUpTables);
}