Search in sources :

Example 1 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication in project student-manager by SYYANI.

the class ScoreManageFragment method initScoreList.

private void initScoreList() throws JSONException {
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    JSONObject json = new JSONObject();
    json.put("cid", scoreManageFragmentBinding.scoreManageFragmentCourseNumber.getText().toString());
    json.put("cname", scoreManageFragmentBinding.scoreManageFragmentCourseName.getText().toString());
    json.put("cFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    json.put("highBound", scoreManageFragmentBinding.scoreManageFragmentHigh.getText().toString());
    json.put("lowBound", scoreManageFragmentBinding.scoreManageFragmentLow.getText().toString());
    json.put("sid", scoreManageFragmentBinding.scoreManageFragmentStudentNumber.getText().toString());
    json.put("sname", scoreManageFragmentBinding.scoreManageFragmentStudentName.getText().toString());
    json.put("sFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    json.put("term", scoreManageFragmentBinding.scoreManageTermSelect.getText().toString());
    if (application.getName().equals("admin")) {
        json.put("tid", "");
        json.put("tname", "");
    } else {
        json.put("tid", application.getId());
        json.put("tname", application.getName());
    }
    json.put("tFuzzy", scoreManageFragmentBinding.scoreManageFragmentFuzzySearch.isChecked());
    // Log.d(TAG, "initCourseList: "+ json.toString() );
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/SCT/findBySearch").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response;
            try {
                response = client.newCall(request).execute();
                if (response.isSuccessful()) {
                    ArrayList<ScoreTeacher> slist = null;
                    slist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<ScoreTeacher>>() {
                    }.getType());
                    scoreManageViewModel.setMutableLiveData_score_list(slist);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) ScoreTeacher(com.shu.studentmanager.entity.ScoreTeacher) Response(okhttp3.Response) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) MediaType(okhttp3.MediaType) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) RequestBody(okhttp3.RequestBody)

Example 2 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication in project student-manager by SYYANI.

the class AdminFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    adminViewModel = new ViewModelProvider(this).get(AdminViewModel.class);
    adminFragmentBinding = DataBindingUtil.inflate(inflater, R.layout.admin_fragment, container, false);
    adminFragmentBinding.setAdminViewModel(adminViewModel);
    adminFragmentBinding.setLifecycleOwner(getActivity());
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    adminFragmentBinding.adminFramentTeacherId.setText(application.getId());
    adminFragmentBinding.adminFragmentTeacherName.setText(application.getName());
    View root = adminFragmentBinding.getRoot();
    return root;
// return inflater.inflate(R.layout.student_fragment, container, false);
}
Also used : AdminViewModel(com.shu.studentmanager.viewmodel.AdminViewModel) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 3 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication in project student-manager by SYYANI.

the class TeacherFragment method initCourseList.

private void initCourseList() throws IOException {
    StudentManagerApplication application = (StudentManagerApplication) getActivity().getApplication();
    String url = "http://101.35.20.64:10086/courseTeacher/findMyCourse/" + application.getId() + "/" + application.getCurrentTerm();
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            Request request = new Request.Builder().url(url).method("GET", null).build();
            try {
                Response response = client.newCall(request).execute();
                // Log.d(TAG, "run: "+response.body().string());
                if (response.isSuccessful()) {
                    ArrayList<CourseTeacher> tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseTeacher>>() {
                    }.getType());
                    // mlist.addAll(tlist);
                    teacherViewModel.setMutableLiveData_course_list(tlist);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

Example 4 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication in project student-manager by SYYANI.

the class StudentCourseSelectAdapter method enSureSelect.

private void enSureSelect(CourseStudent courseStudent) throws JSONException {
    Log.d(TAG, "enSureSelect: select course");
    StudentManagerApplication application = (StudentManagerApplication) context.getApplicationContext();
    Toast.makeText(context, "选课成功", Toast.LENGTH_SHORT);
    MediaType JSON = MediaType.parse("application/json;charset=utf-8");
    JSONObject json = new JSONObject();
    json.put("cid", courseStudent.getCid());
    json.put("tid", courseStudent.getTid());
    json.put("sid", application.getId());
    json.put("term", application.getCurrentTerm());
    Log.d(TAG, "initCourseSelectList: " + json.toString());
    new Thread() {

        @Override
        public void run() {
            super.run();
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(JSON, json.toString());
            Request request = new Request.Builder().url("http://101.35.20.64:10086/SCT/save").method("POST", body).addHeader("Content-Type", "application/json").build();
            Response response = null;
            try {
                response = client.newCall(request).execute();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (response.isSuccessful()) {
                ArrayList<CourseStudent> tlist = null;
                try {
                    Log.d(TAG, "run: " + response.body().string());
                // tlist = new Gson().fromJson(response.body().string(), new TypeToken<ArrayList<CourseStudent>>() {}.getType());
                // mlist.addAll(tlist);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) JSONObject(org.json.JSONObject) Request(okhttp3.Request) ArrayList(java.util.ArrayList) MediaType(okhttp3.MediaType) IOException(java.io.IOException) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication) RequestBody(okhttp3.RequestBody)

Example 5 with StudentManagerApplication

use of com.shu.studentmanager.StudentManagerApplication in project student-manager by SYYANI.

the class LoginActivity method load_select_ok.

private void load_select_ok() throws IOException {
    OkHttpClient client = new OkHttpClient().newBuilder().build();
    Request request = new Request.Builder().url("http://101.35.20.64:10086/info/getCurrentTerm").method("GET", null).build();
    Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        // Log.d(TAG, "run: "+response.body().string());
        Boolean forbidCourseSelection = Boolean.parseBoolean(response.body().string());
        StudentManagerApplication application = (StudentManagerApplication) getApplication();
        application.setForbidCourseSelection(forbidCourseSelection);
    }
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) StudentManagerApplication(com.shu.studentmanager.StudentManagerApplication)

Aggregations

StudentManagerApplication (com.shu.studentmanager.StudentManagerApplication)16 OkHttpClient (okhttp3.OkHttpClient)11 Request (okhttp3.Request)11 Response (okhttp3.Response)11 IOException (java.io.IOException)10 Gson (com.google.gson.Gson)5 ArrayList (java.util.ArrayList)5 Handler (android.os.Handler)4 Message (android.os.Message)4 View (android.view.View)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)3 MainActivity (com.shu.studentmanager.activity.MainActivity)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 TypeToken (com.google.gson.reflect.TypeToken)2 MediaType (okhttp3.MediaType)2 RequestBody (okhttp3.RequestBody)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1