|
|
|
|
@ -0,0 +1,247 @@
|
|
|
|
|
/*
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:timemanagerapp/wighets/AddCourseFormWidget.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
runApp(MyApp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
home: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text('添加课程'),
|
|
|
|
|
),
|
|
|
|
|
body: AddCourseFormWidget(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:sqflite/sqflite.dart';
|
|
|
|
|
import 'package:timemanagerapp/controller/CourseController.dart';
|
|
|
|
|
import 'package:timemanagerapp/controller/UserController.dart';
|
|
|
|
|
import 'package:timemanagerapp/entity/Course.dart';
|
|
|
|
|
import 'package:timemanagerapp/entity/User.dart';
|
|
|
|
|
import 'package:timemanagerapp/database/MyDatebase.dart';
|
|
|
|
|
import 'package:timemanagerapp/wighets/TimetableWighet.dart';
|
|
|
|
|
|
|
|
|
|
import '../main.dart';
|
|
|
|
|
import '../ruters/AddCourseRoute.dart';
|
|
|
|
|
import '../ruters/TimetableRoute.dart';
|
|
|
|
|
import '../tests/database_test.dart';
|
|
|
|
|
import 'package:timemanagerapp/wighets/AddCourseFormWidget.dart';
|
|
|
|
|
|
|
|
|
|
class TestWidget extends StatefulWidget {
|
|
|
|
|
const TestWidget({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_HomePageState createState() => _HomePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _HomePageState extends State<TestWidget> {
|
|
|
|
|
late UserController userController;
|
|
|
|
|
late CourseController courseController;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
MyDatabase.initDatabase();
|
|
|
|
|
userController = UserController.getInstance();
|
|
|
|
|
courseController = CourseController.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: userController.deleteAllUsers,
|
|
|
|
|
child: Text('删除所有用户'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => userController.insertUser(User(
|
|
|
|
|
teamId: 3231, username: "测试用户", password: "23243", role: 1)),
|
|
|
|
|
child: Text('插入一个测试用户'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
userController.getUsers().then((users) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('用户列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: users
|
|
|
|
|
.map((user) => ListTile(
|
|
|
|
|
title: Text(user['username']),
|
|
|
|
|
subtitle: Text(user.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Text('显示用户列表'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: courseController.deleteAllCourses,
|
|
|
|
|
child: Text('删除所有课程'),
|
|
|
|
|
),
|
|
|
|
|
// ElevatedButton(
|
|
|
|
|
// onPressed: () => courseController.autoImportCours(jsonstr),
|
|
|
|
|
// child: Text('导入课程(待开发)'),
|
|
|
|
|
// ),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () => courseController.insertCourse(Course(
|
|
|
|
|
userId: 1,
|
|
|
|
|
courseId: 2,
|
|
|
|
|
name: "测试课",
|
|
|
|
|
credit: 3,
|
|
|
|
|
teacher: "嘉豪",
|
|
|
|
|
location: "638",
|
|
|
|
|
remark: "happy",
|
|
|
|
|
start: DateTime.now(),
|
|
|
|
|
end: DateTime.now().add(Duration(hours: 2)))),
|
|
|
|
|
child: Text('插入一个测试课程'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AddCourseRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('添加自定义课程'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
courseController.getCourses().then((courses) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('课程列表'),
|
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: courses
|
|
|
|
|
.map((course) => ListTile(
|
|
|
|
|
title: Text(course.getName),
|
|
|
|
|
subtitle: Text(course.toString()),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Text('显示课程列表'),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
// 导航到AddCourseFormWidget页面
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return TimetableRoute();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
child: Text('查看时间表'),
|
|
|
|
|
),
|
|
|
|
|
AddCourseButton(
|
|
|
|
|
onCourseAdded: (jsonstr) {
|
|
|
|
|
// 在这里执行添加课程的逻辑,可以将课程名传递给你的 addCourse() 函数
|
|
|
|
|
// courseController.autoImportCours(jsonstr);
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//string导入测试
|
|
|
|
|
|
|
|
|
|
class AddCourseButton extends StatefulWidget {
|
|
|
|
|
final Function(String jsonstr) onCourseAdded;
|
|
|
|
|
|
|
|
|
|
AddCourseButton({required this.onCourseAdded});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_AddCourseButtonState createState() => _AddCourseButtonState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AddCourseButtonState extends State<AddCourseButton> {
|
|
|
|
|
TextEditingController _jsonstrController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
void _showAddCourseDialog(BuildContext context) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text('json导入课程'),
|
|
|
|
|
content: TextField(
|
|
|
|
|
controller: _jsonstrController,
|
|
|
|
|
decoration: InputDecoration(labelText: '请输入json字符串'),
|
|
|
|
|
),
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text('取消'),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text('确定'),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
final jsonstr = _jsonstrController.text;
|
|
|
|
|
if (jsonstr.isNotEmpty) {
|
|
|
|
|
widget.onCourseAdded(jsonstr);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return ElevatedButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
_showAddCourseDialog(context);
|
|
|
|
|
},
|
|
|
|
|
child: Text('json导入课程'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_jsonstrController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|