private void BtnXacNhan_Click(object sender, RoutedEventArgs e) { if (cbSeme.SelectedIndex != -1) { var seme = cbSeme.SelectedValue.ToString(); Commons.semesterNow = seme; File.WriteAllText(Paths.hocky, seme); spnlView.Visibility = Visibility.Visible; spnlSelectSeme.Visibility = Visibility.Collapsed; new Thread(new ThreadStart(update)).Start(); } else { WDialogNoti noti = new WDialogNoti("Vui lòng chọn kỳ học muốn cập nhật"); noti.ShowDialog(); } }
private void update() { try { ConnectAPI.getSemester(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(1) Đang cập nhật lịch học..."; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getTime(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(2) Đang cập nhật lịch thi..."; }); ConnectAPI.getExam(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(3) Đang cập nhật điểm học phần..."; }); ConnectAPI.getMark(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(OK) Cập nhật hoàn tất! Chuẩn bị khởi động lại..."; }); Commons.readDataToFile(); this.Dispatcher.Invoke(() => { Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); }); } catch (Exception) { WDialogNoti noti = new WDialogNoti("Vui lòng kiểm tra lại kết nối mạng của bạn rồi thử lại!"); noti.ShowDialog(); this.Dispatcher.Invoke(() => { spnlView.Visibility = Visibility.Collapsed; spnlSelectSeme.Visibility = Visibility.Visible; }); } }
private void login() { var username = ""; var password = ""; this.Dispatcher.Invoke(() => { username = txtCode.Text; password = txtPass.Password; }); username = username.ToUpper(); var result = ConnectAPI.Login(username, password); if (result != "false" && result != "error") { this.Dispatcher.Invoke(() => { lblStatus.Content = "Đăng nhập thành công!\nĐang chuẩn bị lưu dữ liệu, vui lòng đợi!"; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getProfile(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(1) Đang tải danh sách kỳ học..."; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getSemester(); getSemester(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(2) Đang lưu lịch học..."; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getTime(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(3) Đang kiểm tra lịch thi..."; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getExam(); this.Dispatcher.Invoke(() => { lblStatus.Content = "(4) Đang tải điểm học phần..."; lblStatus.Foreground = Brushes.Green; }); ConnectAPI.getMark(); this.Dispatcher.Invoke(() => { Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); }); } else { if (result == "error") { WDialogNoti noti = new WDialogNoti("Có lỗi xảy ra vui lòng thử lại sau!"); noti.ShowDialog(); } this.Dispatcher.Invoke(() => { lblStatus.Content = "Đăng nhập thất bại!"; lblStatus.Foreground = Brushes.Red; }); } }