public async void LoadData_HK ()
		{
			listView_HK.Visibility = ViewStates.Invisible;

			progress.Visibility = ViewStates.Visible;
			progress.Indeterminate = true;
			List<LichHoc> listLH = new List<LichHoc> ();
			if (Common.checkNWConnection (Activity) == true&&autoupdate==true&&isfirst) {
			
				var newlistlh = BLichHoc.MakeDataFromXml (SQLite_Android.GetConnection ());
				List<LichHoc> newListLH= await newlistlh;
				if (newListLH == null) {
					Toast.MakeText (Activity, "Xảy ra lỗi trong quá trình cập nhật dữ liệu từ server", ToastLength.Long).Show ();
				} else {
					if (check) {
						ScheduleReminder reminder = new ScheduleReminder (Activity);

						await reminder.RemindAllLH (newListLH);
					}
				}
			}
			listLH = BLichHoc.GetNewestLH (SQLite_Android.GetConnection ());
			if (listLH.Count > 0) {
				//radioGroup.Visibility = ViewStates.Visible;
				linearLH.Visibility = ViewStates.Visible;
				linear.Visibility = ViewStates.Visible;
				txtNotify.Visibility = ViewStates.Gone;
				listCT = new List<chiTietLH> ();
				foreach (var item in listLH) {
					listCT.AddRange (BLichHoc.GetCTLH (SQLite_Android.GetConnection (), item.Id));

				}

				lbl_HK.Text = listLH [0].HocKy;
				lbl_NH.Text = listLH [0].NamHoc;
				LichHocHKAdapter adapter = new LichHocHKAdapter (Activity, listCT);
				listView_HK.Adapter = adapter;  
				isfirst = false;
			}else {
				//radioGroup.Visibility= ViewStates.Invisible;
				linearLH.Visibility = ViewStates.Gone;
				linear.Visibility = ViewStates.Gone;
				txtNotify.Visibility = ViewStates.Visible;
				txtNotify.Text = "Hiện tại lịch học chưa có dữ liệu. Xin vui lòng thử lại sau!!!";
			}
			progress.Indeterminate = false;
			progress.Visibility = ViewStates.Gone;
			listView_HK.Visibility = ViewStates.Visible;

		
		}
		public async void LoadData_Tuan (DateTime dateOfWeek)
		{
			try
			{
			btnTuanTruoc.Visibility= ViewStates.Invisible;
			btnTuanKe.Visibility= ViewStates.Invisible;
			listView_Tuan.Visibility = ViewStates.Invisible;
			progress.Visibility = ViewStates.Visible;
			progress.Indeterminate = true;
			List<LichHoc> listLH = new List<LichHoc> ();
				if (Common.checkNWConnection (Activity) == true && autoupdate == true&&	isfirst) {
				var newlistlh= BLichHoc.MakeDataFromXml (SQLite_Android.GetConnection ());
				List<LichHoc> newListLH= await newlistlh;
				if (newListLH == null) {
					Toast.MakeText (Activity, "Xảy ra lỗi trong quá trình cập nhật dữ liệu từ server", ToastLength.Long).Show ();
				} else {
					if (check) {
						ScheduleReminder reminder = new ScheduleReminder (Activity);

						await reminder.RemindAllLH (newListLH);
					}
				}
			}
			listLH = BLichHoc.GetNewestLH (SQLite_Android.GetConnection ());
			listCT = new List<chiTietLH> ();
			foreach (var item in listLH) {
				List<chiTietLH> list = BLichHoc.GetCTLH (SQLite_Android.GetConnection (), item.Id).ToList ();
				foreach (var ct in list) {
					String result = checkTuan (ct.Tuan, dateOfWeek);
					if (result != "") {
						ct.Tuan = result;
						listCT.Add (ct);
						break;
					}

				}

			}
			string begining;
			string end;
			GetWeek (dateOfWeek, out begining, out end);
			lbl_TuNgay.Text = begining;
			lbl_DenNgay.Text = end;
			lbl_HK.Text = "Học Kỳ " + listLH [0].HocKy + " Năm học " + listLH [0].NamHoc;
			listCT = listCT.OrderBy (x => x.Thu).ToList();
			listView_Tuan.SetAdapter (new LichHocTuanAdapter (Activity, listCT)); 
			progress.Indeterminate = false;
			progress.Visibility = ViewStates.Gone;
			listView_Tuan.Visibility = ViewStates.Visible;
			btnTuanTruoc.Visibility= ViewStates.Visible;
			btnTuanKe.Visibility= ViewStates.Visible;
			isfirst = false;
		}
		catch {
			
		}
		}
		async void CbNLT_CheckedChange (object sender, CompoundButton.CheckedChangeEventArgs e)
		{
			progressNL.Visibility= ViewStates.Visible;
			progressNL.Indeterminate = true;
			if (cbNLT.Checked == true) {

				try{
					List<LichThi> listlt= BLichThi.GetNewestLT(SQLite_Android.GetConnection());
					Log.Debug("logsettings","Load LT Success");
					List<LichHoc> listlh= BLichHoc.GetNewestLH(SQLite_Android.GetConnection());
					Log.Debug("logsettings","Load LH Success");
					ScheduleReminder reminder = new ScheduleReminder(Activity);
					await reminder.RemindAllLH(listlh);
					await reminder.RemindAllLT(listlt);
					Toast.MakeText (Activity, "Cài đặt nhắc lịch hoàn tất", ToastLength.Long).Show();
				}
				catch {

				}

			} else {
				AlertDialog.Builder builder = new AlertDialog.Builder (
					Activity);

				// Setting Dialog Title

				builder.SetTitle (Resource.String.Alertitle); 
				builder.SetIcon (Android.Resource.Drawable.IcDialogAlert); 
				builder.SetMessage ("Bạn có muốn xoá hết nhắc lịch đã tạo không?"); 
				builder.SetPositiveButton ("Có", async (sender1, e1) => {
				ScheduleReminder reminder = new ScheduleReminder(Activity);
				await reminder.DeleteAlLRemind ();
				Toast.MakeText (Activity, "Xoá nhắc lịch hoàn tất", ToastLength.Long).Show();
				});
				builder.SetNegativeButton ("Không", (sender1, e1) => {
				});
				builder.Show(); 

				
			}
			progressNL.Indeterminate = false;
			progressNL.Visibility = ViewStates.Gone;
			var prefs = Application.Context.GetSharedPreferences("SGU APP", FileCreationMode.Private);
			var prefEditor = prefs.Edit();
			prefEditor.PutBoolean("Remind",cbNLT.Checked);
			prefEditor.Commit();
		}
Example #4
0
		public static async Task<string> LoadDataFromSV(Context ctx)
		{
			try
			{
			var newlistlh= BLichHoc.MakeDataFromXml (SQLite_Android.GetConnection ());
			List<LichHoc> newListLH= await newlistlh;
			var newlistlt= BLichThi.MakeDataFromXml (SQLite_Android.GetConnection ());
			List<LichThi> newListLT= await newlistlt;
			var dtKS=await BDiemThi.MakeDataFromXml (SQLite_Android.GetConnection ());
			var hpKS= await BHocPhi.MakeDataFromXml (SQLite_Android.GetConnection ());
			try{
					DrawerActivity drAc=(DrawerActivity)ctx;
					drAc.SelectItem(drAc.previousItemChecked);
			}catch
			{
			}
			var prefs = Application.Context.GetSharedPreferences("SGU APP", FileCreationMode.Private);              
			var checkRemind = prefs.GetBoolean ("Remind",false);
			if ( checkRemind)
			{
			ScheduleReminder reminder = new ScheduleReminder(ctx);
					if (newListLH!=null) await reminder.RemindAllLH(newListLH);
					if (newListLT!=null) await reminder.RemindAllLT(newListLT);

			Toast.MakeText (ctx, "Cài đặt nhắc lịch cho dữ liệu mới thành công", ToastLength.Long).Show();
			}
			if (dtKS!=null&&hpKS!=null&&newListLH!=null&&newListLT!=null)
			{
					Toast.MakeText (ctx, "Cập nhật dữ liệu thành công", ToastLength.Long).Show();
					return "load success ";
			}	
				else
			{
				Toast.MakeText (ctx, "Xảy ra lỗi trong quá trình tải dữ liệu", ToastLength.Long).Show();
					return "load failed ";
			}

			
			
			}
			catch {
				Toast.MakeText (ctx, "Xảy ra lỗi trong quá trình tải dữ liệu, vui lòng thử lại sau", ToastLength.Long).Show();
				return "load failed";
			}



		}