public DiemThiHKSource ()
		{
			tableItems = new List<DiemMon> ();
			isHeader = true;
			DiemMon dm = new DiemMon ();
			dm.MaMH = "000";
			tableItems.Add (dm);
		}
			public static int AddDM(DiemMon dm,SQLiteConnection connection)
			{
				DataProvider dtb = new DataProvider (connection);
				if (dtb.GetDM (dm) == null) {
					return dtb.AddDM(dm);
					}
				return 0;
			}
		public static async  Task<List<DiemThi>> MakeDataFromXml(SQLiteConnection connection)
			{
				list = new List<DiemThi> ();

			var httpClient = new HttpClient ();
			Task<string> contentsTask = httpClient.GetStringAsync("http://www.schoolapi.somee.com/api/diemthi/3111410094");
			string contents = await contentsTask;
			XDocument doc = XDocument.Parse (contents);
			//get lichthi 
			IEnumerable<XElement> childList =
				from el in doc.Root.Elements ()
				select el;
			//get attri lichthi

			foreach (XElement node in childList) {
				DiemThi lt = new DiemThi();
				lt.DiemRL = node.Elements().ElementAt(0).Value.Trim();

				foreach (XElement nod in node.Elements().ElementAt(5).Elements())
				{
					DiemMon dm = new DiemMon();
					MonHoc mh = new MonHoc();
					dm.Hocky = int.Parse(node.Elements().ElementAt(9).Value.Trim()[7].ToString());
					dm.NamHoc = int.Parse(node.Elements().ElementAt(9).Value.Trim().Substring(17));
					dm.DiemKT = nod.Elements().ElementAt(0).Value.Trim();
					// change TIle & also happened in BlichHOc
					dm.MaMH = nod.Elements().ElementAt(1).Value.Trim();
					mh.MaMH = dm.MaMH;
					mh.TenMH = nod.Elements().ElementAt(5).Value.Trim();
					mh.SoTC = int.Parse(nod.Elements().ElementAt(4).Value.Trim());
					mh.TiLeThi = int.Parse(nod.Elements().ElementAt(3).Value.Trim());
					dm.DiemThi = nod.Elements().ElementAt(6).Value.Trim();
					dm.DiemTK10 = nod.Elements ().ElementAt (7).Value.Trim ();
					dm.DiemChu = nod.Elements ().ElementAt (8).Value.Trim ();

					AddDM(dm,connection);
					BMonHoc.Add (connection, mh);
					BMonHoc.UpdateMH(connection,mh);
				}
				lt.DiemTB4 = node.Elements().ElementAt(1).Value.Trim();
				lt.DiemTB10 = node.Elements().ElementAt(2).Value.Trim();
				lt.DiemTBTL4 = node.Elements().ElementAt(3).Value.Trim();
				lt.DiemTBTL10 = node.Elements().ElementAt(4).Value.Trim();
				lt.LoaiRL = node.Elements().ElementAt(6).Value.Trim();
				lt.SoTCDat = node.Elements().ElementAt(7).Value.Trim();
				lt.SoTCTL = node.Elements().ElementAt(8).Value.Trim();  
				lt.NamHoc = int.Parse(node.Elements().ElementAt(9).Value.Trim().Substring(17));
				lt.Hocky = int.Parse(node.Elements().ElementAt(9).Value.Trim()[7].ToString());

				Add(lt,connection);
				list.Add(lt);


			}
			return list;
			}
		async void LoadData()
		{
			progress.Visibility = ViewStates.Visible;
			progress.Indeterminate = true;
			List<DiemMon> list = new List<DiemMon>();
			if (Common.checkNWConnection (Activity) == true && autoupdate == true) {
				var rs=await BDiemThi.MakeDataFromXml (SQLite_Android.GetConnection ());
				if (rs==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();
				}
			}
			List<DiemThi> listDT = new List<DiemThi>();

			listDT = BDiemThi.getAll(SQLite_Android.GetConnection ());
			if (listDT.Count > 0) {
				linear.Visibility = ViewStates.Visible;
				txtNotify.Visibility = ViewStates.Gone;
				foreach (var item in listDT) {
				
					DiemMon Header = new DiemMon ();
					Header.Hocky = item.Hocky;
					Header.NamHoc = item.NamHoc;
					Header.MaMH = "Header";
					list.Add (Header);
					list.AddRange (BDiemThi.GetDiemMons (SQLite_Android.GetConnection (), item.Hocky, item.NamHoc));
					DiemMon Footer = new DiemMon ();
					if (item.Hocky != "3") {
						Footer.Hocky = item.Hocky;
						Footer.NamHoc = item.NamHoc;
						Footer.MaMH = "Footer";
						list.Add (Footer);
					}

				}
				listView.Adapter = new DiemThiApdater (Activity, list); 
			} else {
				linear.Visibility = ViewStates.Gone;
				txtHocKyDT.Visibility=ViewStates.Gone;
				txtNotify.Visibility = ViewStates.Visible;
				txtNotify.Text = "Hiện tại điểm thi chưa có dữ liệu. Xin vui lòng thử lại sau!!!";
			}
			progress.Indeterminate = false;
			progress.Visibility = ViewStates.Gone;
		}
Beispiel #5
0
		public async void LoadData()
		{
			try
			{
				
				progress.Hidden = false;
				progress.StartAnimating ();
				bool sync = SettingsHelper.LoadSetting ("AutoUpdate"); 
				if (sync)
				{
					bool accepted =false;
					while (Reachability.InternetConnectionStatus ()==NetworkStatus.NotReachable&&!accepted)
					{
						 accepted = await ShowAlert("Lỗi", "Bạn cần mở kết nối để cập nhật dữ liệu mới nhất");
							
				
					}
					if(Reachability.InternetConnectionStatus ()!=NetworkStatus.NotReachable)
					{
						UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
						var rs=await  BDiemThi.MakeDataFromXml(SQLite_iOS.GetConnection());
						if (rs==null)
						{
							UIAlertView _error = new UIAlertView ("Lỗi", "Xảy ra lỗi trong quá trình cập nhật dữ liệu từ server", null, "Ok", null);

							_error.Show ();
						}
						UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
					}
				}

				List<DiemThi> listDT = new List<DiemThi>();
				List<DiemMon> list = new List<DiemMon>();
				listDT = BDiemThi.getAll(SQLite_iOS.GetConnection ());
				if (listDT.Count>0)
				{
					listContent.Hidden= false;
					errorLB.Hidden=true;
					headers.Hidden=false;
					await Task.Run(()=>
					{
					foreach (var item in listDT) {

						DiemMon Header = new DiemMon ();
						Header.Hocky = item.Hocky;
						Header.NamHoc = item.NamHoc;
						Header.MaMH = "Header";
						list.Add (Header);
						list.AddRange (BDiemThi.GetDiemMons (SQLite_iOS.GetConnection (),item.Hocky, item.NamHoc));
						DiemMon Footer = new DiemMon ();
						if (item.Hocky != "3") {
							Footer.Hocky = item.Hocky;
							Footer.NamHoc = item.NamHoc;
							Footer.MaMH = "Footer";
							list.Add (Footer);
						}

					}
					});
					
					listContent.Source=new DiemThiSource(list);
					listContent.ReloadData();
				}
				else
				{
					headers.Hidden=true;
					listContent.Hidden= true;
					errorLB.Hidden=false;
				}
				progress.StopAnimating ();
			}
			catch {
			}
		}
Beispiel #6
0
		public int AddDM (DiemMon T)
		{
			int i = _connection.Insert (T);
			_connection.Commit ();
			return i;
		}
Beispiel #7
0
		public DiemMon GetDM (DiemMon dm)
		{
			var query = from c in _connection.Table<DiemMon> ()
			            where (c.Hocky == dm.Hocky) && (c.NamHoc == dm.NamHoc) && (c.MaMH.Equals (dm.MaMH))
			            select c;
			return query.FirstOrDefault ();
		}
Beispiel #8
0
		public static async  Task<List<DiemThi>> MakeDataFromXml (SQLiteConnection connection)
		{
			if (BUser.GetMainUser (connection) != null) {
				list = new List<DiemThi> ();

				var httpClient = new HttpClient ();
				httpClient.Timeout = TimeSpan.FromSeconds (30);
				string contents;
				Task<string> contentsTask = httpClient.GetStringAsync (UrlHelper.UrlDT(BUser.GetMainUser(connection).Id));
				try{
					contents = await contentsTask;
				}
				catch {
					return null;
				}
				XDocument doc = XDocument.Parse (contents);
				//get lichthi 
				IEnumerable<XElement> childList =
					from el in doc.Root.Elements ()
					select el;
				//get attri lichthi

				foreach (XElement node in childList) {
					DiemThi lt = new DiemThi ();
					lt.DiemRL = node.Elements ().ElementAt (0).Value.Trim ();

					foreach (XElement nod in node.Elements().ElementAt(5).Elements()) {
						DiemMon dm = new DiemMon ();
						MonHoc mh = new MonHoc ();
						dm.Hocky = node.Elements ().ElementAt (9).Value.Trim () [7].ToString ();
						dm.NamHoc = node.Elements ().ElementAt (9).Value.Trim ().Substring (17);
						dm.DiemKT = nod.Elements ().ElementAt (0).Value.Trim ();
						dm.MaMH = nod.Elements ().ElementAt (1).Value.Trim ();
						mh.MaMH = dm.MaMH;
						mh.TenMH = nod.Elements ().ElementAt (5).Value.Trim ();
						mh.SoTC = int.Parse (nod.Elements ().ElementAt (4).Value.Trim ());
						mh.TiLeThi = int.Parse (nod.Elements ().ElementAt (3).Value.Trim ());
						dm.DiemThi = nod.Elements ().ElementAt (6).Value.Trim ();
						dm.DiemTK10 = nod.Elements ().ElementAt (7).Value.Trim ();
						dm.DiemChu = nod.Elements ().ElementAt (8).Value.Trim ();

						AddDM (dm, connection);
						BMonHoc.Add (connection, mh);
						BMonHoc.UpdateMH (connection, mh);
					}
					lt.DiemTB4 = node.Elements ().ElementAt (1).Value.Trim ();
					lt.DiemTB10 = node.Elements ().ElementAt (2).Value.Trim ();
					lt.DiemTBTL4 = node.Elements ().ElementAt (3).Value.Trim ();
					lt.DiemTBTL10 = node.Elements ().ElementAt (4).Value.Trim ();
					lt.LoaiRL = node.Elements ().ElementAt (6).Value.Trim ();
					lt.SoTCDat = node.Elements ().ElementAt (7).Value.Trim ();
					lt.SoTCTL = node.Elements ().ElementAt (8).Value.Trim ();  
					lt.NamHoc = node.Elements ().ElementAt (9).Value.Trim ().Substring (17);
					lt.Hocky = node.Elements ().ElementAt (9).Value.Trim () [7].ToString ();

					Add (lt, connection);
					list.Add (lt);


				}
				return list;
			}
			return null;
		}