async void LoadData()
		{
			
			if (Common.checkNWConnection (Activity) == true && autoupdate == true) {
				
				var rs= await BHocPhi.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();
				}
			}

			hp = BHocPhi.GetHP(SQLite_Android.GetConnection ());
			progress.Visibility = ViewStates.Gone;
			if (hp != null) {
				listCT = BHocPhi.GetCTHP (SQLite_Android.GetConnection (), hp.NamHoc, hp.HocKy);
				txtNotify.Visibility = ViewStates.Gone;
				linear.Visibility = ViewStates.Visible;
				HocPhiAdapter adapter = new HocPhiAdapter (Activity, listCT);
				rootView.FindViewById<TextView> (Resource.Id.txtHocKyHP).Text = "Học Kỳ " + hp.HocKy + " Năm Học " + hp.NamHoc;
				listView.Adapter = adapter;
			} else {
			linear.Visibility = ViewStates.Gone;
			progress.Visibility = ViewStates.Gone;
			txtNotify.Visibility = ViewStates.Visible;
			txtNotify.Text = "Hiện tại học phí chưa có dữ liệu. Xin vui lòng thử lại sau!!!";
			}

		}
		public static int AddHP(SQLiteConnection connection, HocPhi hp)
		{
			DataProvider dtb = new DataProvider (connection);
			if (dtb.GetHP (hp.NamHoc,hp.HocKy) == null) {
				return dtb.AddHP (hp);
			}
			return 0;
		}
Beispiel #3
0
		public static async Task<HocPhi> MakeDataFromXml(SQLiteConnection connection)
		{

			if (BUser.GetMainUser (connection) != null) {
				
				var httpClient = new HttpClient ();
				httpClient.Timeout = TimeSpan.FromSeconds (20);
				string contents;
				Task<string> contentsTask = httpClient.GetStringAsync (UrlHelper.UrlHP(BUser.GetMainUser(connection).Id,BUser.GetMainUser(connection).Password));

				HocPhi hp = new HocPhi ();

				try
				{
					contents =  await contentsTask;

				}
				catch(Exception e) {
					return hp;
				}
				XDocument doc = XDocument.Parse (contents);

				XElement node = doc.Root;

				hp.HocKy = int.Parse (node.Elements ().ElementAt (1).Value [7].ToString ());
				hp.NamHoc = int.Parse (node.Elements ().ElementAt (1).Value.Substring (19, 4));
				hp.TienConNo = node.Elements ().ElementAt (2).Value.Trim ();
				hp.TienDaDong = node.Elements ().ElementAt (3).Value.Trim ();
				hp.TienDongTTLD = node.Elements ().ElementAt (4).Value.Trim ();
				hp.TongSoTC = node.Elements ().ElementAt (5).Value.Trim ();
				hp.TongSoTien = node.Elements ().ElementAt (6).Value.Trim ();

				foreach (XElement node1 in node.Elements ().ElementAt (0).Elements()) {
					CTHocPhi ct = new CTHocPhi ();
					ct.HocPhi = node1.Elements ().ElementAt (0).Value.Trim ();
					ct.MaNhom = node1.Elements ().ElementAt (1).Value.Trim ();
					ct.MienGiam = node1.Elements ().ElementAt (2).Value.Trim ();
					ct.PhaiDong = node1.Elements ().ElementAt (3).Value.Trim ();
					ct.HocKy = hp.HocKy;
					ct.NamHoc = hp.NamHoc;
					MonHoc mh = new MonHoc ();
					ct.MaMH = node1.Elements ().ElementAt (4).Elements ().ElementAt (0).Value.Trim ();
					mh.MaMH = ct.MaMH;
					mh.TenMH=node1.Elements ().ElementAt (4).Elements ().ElementAt (2).Value.Trim ();
					mh.SoTC=int.Parse(node1.Elements ().ElementAt (4).Elements ().ElementAt (1).Value.Trim ());
					;
					AddCTHP (connection, ct);
					BMonHoc.Add (connection, mh);
				}
				AddHP (connection, hp);
				return hp;

			}
			return null;
		}
		public static async Task<HocPhi> MakeDataFromXml(SQLiteConnection connection)
		{
			var httpClient = new HttpClient ();
			Task<string> contentsTask = httpClient.GetStringAsync("http://www.schoolapi.somee.com/api/hocphi/3111410089/secret01");
			string contents = await contentsTask;
			XDocument doc = XDocument.Parse (contents);
			 


			XElement node = doc.Root;
			HocPhi hp = new HocPhi();
			hp.HocKy = int.Parse(node.Elements().ElementAt(1).Value[7].ToString());
			hp.NamHoc = int.Parse(node.Elements().ElementAt(1).Value.Substring(19, 4));
			hp.TienConNo = node.Elements ().ElementAt (2).Value.Trim ();
			hp.TienDaDong = node.Elements ().ElementAt (3).Value.Trim ();
			hp.TienDongTTLD = node.Elements ().ElementAt (4).Value.Trim ();
			hp.TongSoTC = node.Elements ().ElementAt (5).Value.Trim ();
			hp.TongSoTien = node.Elements ().ElementAt (6).Value.Trim ();

			foreach (XElement node1 in node.Elements ().ElementAt (0).Elements())
			{
				CTHocPhi ct = new CTHocPhi();
				ct.HocPhi = node1.Elements().ElementAt(0).Value.Trim();
				ct.MaNhom = node1.Elements().ElementAt(1).Value.Trim();
				ct.MienGiam = node1.Elements().ElementAt(2).Value.Trim();
				ct.PhaiDong = node1.Elements().ElementAt(3).Value.Trim();
				ct.HocKy = hp.HocKy;
				ct.NamHoc = hp.NamHoc;

				ct.MaMH = node1.Elements().ElementAt(4).Elements().ElementAt(0).Value.Trim();;
				AddCTHP (connection, ct);
			}
			AddHP(connection,hp);
			return hp;

		}
Beispiel #5
0
		public int AddHP (HocPhi T)
		{
			int i = _connection.Insert (T);
			_connection.Commit ();
			return i;
		}