public static void AddLH (LichHoc lt, SQLiteConnection connection)
		{
			DataProvider dtb = new DataProvider (connection);
			if (dtb.GetLH_Ma (lt.MaMH) == null) {
				dtb.AddLH (lt);
			}
		}
Beispiel #2
0
		public static bool AddLH (LichHoc lh, SQLiteConnection connection)
		{
			DataProvider dtb = new DataProvider (connection);
			if (dtb.GetLH_Ma (lh.MaMH, lh.NamHoc,lh.HocKy) == null) {
				dtb.AddLH (lh);
				return true;
			}
			return false;
		}
Beispiel #3
0
		public static async Task<List<LichHoc>> MakeDataFromXml (SQLiteConnection connection)
		{
			if (BUser.GetMainUser (connection) != null) {
				list = new List<LichHoc> ();
				var httpClient = new HttpClient ();
				httpClient.Timeout = TimeSpan.FromSeconds (20);
				Task<string> contentsTask = httpClient.GetStringAsync (UrlHelper.UrlLH(BUser.GetMainUser(connection).Id));
				string contents;

				try
				{
					contents =  await contentsTask;

				}
				catch(Exception e) {
					return null;
				}
				XDocument doc = XDocument.Parse (contents);
				//get lichthi 
				IEnumerable<XElement> childList =
					from el in doc.Root.Elements ()
					select el;
				//get attri lichthi
				int k = GetId (connection);
				DataProvider dtb = new DataProvider (connection);
				foreach (XElement node in childList) {
				
					LichHoc lichhoc = new LichHoc ();
					lichhoc = dtb.GetLH_Ma (node.Elements ().ElementAt (3).Value.Trim (),node.Elements ().ElementAt (4).Value.Trim (),node.Elements ().ElementAt (1).Value.Trim ());

					if (lichhoc != null) {
						chiTietLH ct = new chiTietLH ();
						ct.Id = lichhoc.Id;
						ct.CBGD = node.Elements ().ElementAt (0).Value.Trim ();
						ct.Phong = node.Elements ().ElementAt (6).Value.Trim ();
						ct.Thu = node.Elements ().ElementAt (11).Value.Trim ();
						ct.TietBatDau = node.Elements ().ElementAt (12).Value.Trim ();
						ct.SoTiet = node.Elements ().ElementAt (8).Value.Trim ();
						ct.ThoigianBD = node.Elements ().ElementAt (10).Value.Trim ().Substring (0, 10);
						ct.ThoigianKT = node.Elements ().ElementAt (10).Value.Trim ().Substring (12);
						ct.Tuan = convertToDate (setTKB_Tuan (node.Elements ().ElementAt (13).Value.Trim ()),ct.ThoigianBD);
						AddCTLH (connection, ct);
					} else {
						k++;
						LichHoc lh = new LichHoc ();
						MonHoc mh = new MonHoc ();

						lh.Id = k.ToString ();
						lh.MaMH = node.Elements ().ElementAt (3).Value.Trim ();
						lh.MaLop = node.Elements ().ElementAt (2).Value.Trim ();
						lh.NhomMH = node.Elements ().ElementAt (5).Value.Trim ();
						lh.HocKy = node.Elements ().ElementAt (1).Value.Trim ();
						lh.NamHoc = node.Elements ().ElementAt (4).Value.Trim ();
						mh.MaMH = lh.MaMH;
						mh.TenMH = node.Elements ().ElementAt (9).Value.Trim ();
						mh.SoTC = int.Parse (node.Elements ().ElementAt (7).Value.Trim ());

						chiTietLH ct = new chiTietLH ();
						ct.Id = k.ToString ();
						ct.CBGD = node.Elements ().ElementAt (0).Value.Trim ();
						ct.Phong = node.Elements ().ElementAt (6).Value.Trim ();
						ct.Thu = node.Elements ().ElementAt (11).Value.Trim ();
						ct.TietBatDau = node.Elements ().ElementAt (12).Value.Trim ();
						ct.SoTiet = node.Elements ().ElementAt (8).Value.Trim ();
						ct.ThoigianBD = node.Elements ().ElementAt (10).Value.Trim ().Substring (0, 10);
						ct.ThoigianKT = node.Elements ().ElementAt (10).Value.Trim ().Substring (12);
						ct.Tuan = convertToDate (setTKB_Tuan (node.Elements ().ElementAt (13).Value.Trim ()),ct.ThoigianBD);
						AddCTLH (connection, ct);

						bool done=AddLH (lh, connection);
						if (done) {
							list.Add (lh);
						}
						BMonHoc.Add (connection, mh);
					
					}


				}
				return list;
			}
			return null;
		}
Beispiel #4
0
		public static LichHoc GetLH (SQLiteConnection connection, string id, string namHoc, string hocKy)
		{
			DataProvider dtb = new DataProvider (connection);
			return dtb.GetLH_Ma (id, namHoc , hocKy);
		}
		public static async Task<List<LichHoc>> MakeDataFromXml (SQLiteConnection connection)
		{
			list = new List<LichHoc> ();
			var httpClient = new HttpClient ();
			Task<string> contentsTask = httpClient.GetStringAsync("http://www.schoolapi.somee.com/api/thoikhoabieu/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
			int k = GetId (connection);
			DataProvider dtb = new DataProvider (connection);
			foreach (XElement node in childList) {
				
				LichHoc lichhoc = new LichHoc ();
				lichhoc = dtb.GetLH_Ma (node.Elements ().ElementAt (3).Value.Trim());

					if (lichhoc!=null) {
					chiTietLH ct = new chiTietLH ();
					ct.Id = lichhoc.Id;
					ct.CBGD = node.Elements ().ElementAt (0).Value.Trim ();
					ct.Phong = node.Elements ().ElementAt (6).Value.Trim ();
					ct.Thu = node.Elements ().ElementAt (11).Value.Trim ();
					ct.TietBatDau = node.Elements ().ElementAt (12).Value.Trim ();
					ct.SoTiet = node.Elements ().ElementAt (8).Value.Trim ();
					ct.ThoigianBD = node.Elements ().ElementAt (10).Value.Trim ().Substring (0, 10);
					ct.ThoigianKT = node.Elements ().ElementAt (10).Value.Trim ().Substring (12);
					ct.Tuan = node.Elements ().ElementAt (13).Value.Trim ();
					AddCTLH (connection, ct);
				} else {
					k++;
					LichHoc lh = new LichHoc ();
					MonHoc mh = new MonHoc ();

					lh.Id = k.ToString ();
					lh.MaMH = node.Elements ().ElementAt (3).Value.Trim ();
					lh.MaLop = node.Elements ().ElementAt (2).Value.Trim ();
					lh.NhomMH = node.Elements ().ElementAt (5).Value.Trim ();
					lh.HocKy = node.Elements ().ElementAt (1).Value.Trim ();
					lh.NamHoc = node.Elements ().ElementAt (4).Value.Trim ();
					mh.MaMH = lh.MaMH;
					mh.TenMH = node.Elements ().ElementAt (9).Value.Trim ();
					mh.SoTC = int.Parse (node.Elements ().ElementAt (7).Value.Trim ());

					chiTietLH ct = new chiTietLH ();
					ct.Id = k.ToString ();
					ct.CBGD = node.Elements ().ElementAt (0).Value.Trim ();
					ct.Phong = node.Elements ().ElementAt (6).Value.Trim ();
					ct.Thu = node.Elements ().ElementAt (11).Value.Trim ();
					ct.TietBatDau = node.Elements ().ElementAt (12).Value.Trim ();
					ct.SoTiet = node.Elements ().ElementAt (8).Value.Trim ();
					ct.ThoigianBD = node.Elements ().ElementAt (10).Value.Trim ().Substring (0, 10);
					ct.ThoigianKT = node.Elements ().ElementAt (10).Value.Trim ().Substring (12);
					ct.Tuan = node.Elements ().ElementAt (13).Value.Trim ();
					AddCTLH (connection, ct);
					list.Add (lh);
					AddLH (lh, connection);
					BMonHoc.Add (connection, mh);
					
				}


			}
			return list;
		}