protected override void OnDisappearing() { Debug.WriteLine("close Notification-----------------------------------------------------------"); var month = (int)ContentGlobal.allldata["timeoff"]["period"]; ContentGlobal.INTcountNotiUnread = ContentGlobal.CountNotiUnread("individualistic", month) + ContentGlobal.CountNotiUnread("public", month); CrossBadge.Current.SetBadge(ContentGlobal.INTcountNotiUnread); if (saveNoti == true) { if (ContentGlobal.statusNetwork().Equals("Connected") != false) { try { var data = ContentGlobal.allldata["notificaton"]; Debug.WriteLine("date save---------------" + data); string strSub = "UpdateNotification"; string strParam = @"{""uid"":""" + Application.Current.Properties["uId"].ToString() + @""",""content"":" + data + @"}"; Debug.WriteLine("strParam-------------------------------------------------" + strParam); var dataEE = ContentGlobal.FirebasePUTFunctions(strSub, strParam); Debug.WriteLine("dataEE----------------------------------" + dataEE); ContentGlobal.saveSetting = false; } catch (Exception ex) { Debug.WriteLine("Err Notifiaction----------------------------------------" + ex); } } } }
//Page pagePersion = new Personal.PersonalPage(); public NotificationPage() { var stkPrivate = new StackLayout(); var stkPublic = new StackLayout(); InitializeComponent(); this.BackgroundColor = Color.FromHex("#F0EFF5"); List <String> months = ContentGlobal.ListMonth; foreach (String nn in months) { pickerMonth.Items.Add(nn); } month = (int)ContentGlobal.allldata["timeoff"]["period"]; selectedIndexMonth = month - 1; pickerMonth.SelectedIndex = selectedIndexMonth; pickerMonth.SelectedIndexChanged += (sender, e) => { Debug.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++changed month"); selectedIndexMonth = pickerMonth.SelectedIndex; int tong = ContentGlobal.INTcountNotiUnread = ContentGlobal.CountNotiUnread("individualistic", selectedIndexMonth + 1) + ContentGlobal.CountNotiUnread("public", selectedIndexMonth + 1); if (tong > 0) { DisplayAlert("Thông báo", string.Format("Tháng {0} bạn có {1} thông báo chưa đọc!", selectedIndexMonth + 1, tong), "OK"); } Iitem.Clear(); Iitem = loadNotification(); lvNotifications.ItemsSource = Iitem; }; //stkContent.Children.Add(stkPrivate); var tapPrivate = new TapGestureRecognizer(); tapPrivate.Tapped += (s, e) => { if (boolPrivate == false) { bvPrivate.BackgroundColor = Color.FromHex("#157EFB"); lbPrivate.FontAttributes = FontAttributes.Bold; lbPrivate.TextColor = Color.White; bvPublic.BackgroundColor = Color.White; lbPublic.TextColor = Color.FromHex("#157EFB"); lbPublic.FontAttributes = FontAttributes.None; boolPrivate = true; boolPublic = false; Iitem.Clear(); Iitem = loadNotification(); lvNotifications.ItemsSource = Iitem; } }; lbPrivate.GestureRecognizers.Add(tapPrivate); var tapPublic = new TapGestureRecognizer(); tapPublic.Tapped += (s, e) => { if (boolPublic == false) { bvPublic.BackgroundColor = Color.FromHex("#157EFB"); lbPublic.FontAttributes = FontAttributes.Bold; lbPublic.TextColor = Color.White; bvPrivate.BackgroundColor = Color.White; lbPrivate.FontAttributes = FontAttributes.None; lbPrivate.TextColor = Color.FromHex("#157EFB"); boolPublic = true; boolPrivate = false; Iitem.Clear(); Iitem = loadNotification(); lvNotifications.ItemsSource = Iitem; } }; lbPublic.GestureRecognizers.Add(tapPublic); }
protected async override void OnAppearing() { var properties = Xamarin.Forms.Application.Current.Properties; if (properties.ContainsKey("uId") && properties["uId"].ToString().Length > 0) { Debug.WriteLine("uId------------------------------------" + properties["uId"].ToString()); stkMain.IsVisible = false; stkLoad.IsVisible = true; if (ContentGlobal.statusNetwork().Equals("Connected") != false) { try { ContentGlobal.allldata = await ContentGlobal.GetAllOfPersonal(); if ((int)ContentGlobal.allldata["info"]["active"] == 0) { App.Current.MainPage = new Account.NoAcctivePage(); } else { ContentGlobal.loadListRequest(); if (ContentGlobal.registrationId.Length > 0) { var registrationId = ContentGlobal.allldata["info"]["registrationId"]; if (registrationId != null) { if (registrationId.ToString().Equals(ContentGlobal.registrationId) == false) { string strSubFirebase = "pushData"; string strParam = @"{""uid"" : """ + properties["uId"].ToString() + @""", ""registrationId"" :""" + ContentGlobal.registrationId + @""" }"; Debug.WriteLine("strParam-----------------------------------------------------" + strParam); var rt = ContentGlobal.FirebasePOSTFunctions(strSubFirebase, strParam); } } else { string strSubFirebase = "pushData"; string strParam = @"{""uid"" : """ + properties["uId"].ToString() + @""", ""registrationId"" :""" + ContentGlobal.registrationId + @""" }"; Debug.WriteLine("strParam-----------------------------------------------------" + strParam); var rt = ContentGlobal.FirebasePOSTFunctions(strSubFirebase, strParam); } } if ((int)ContentGlobal.allldata["info"]["acted"] == 1) { ContentGlobal.PeopleWorking = await ContentGlobal.peopleWorkingAsync(); ContentGlobal.Userroot = true; } else { ContentGlobal.Userroot = false; } var month = (int)ContentGlobal.allldata["timeoff"]["period"]; ContentGlobal.INTcountNotiUnread = ContentGlobal.CountNotiUnread("individualistic", month) + ContentGlobal.CountNotiUnread("public", month); Debug.WriteLine("INTcountNotiUnread--------------------------------------------------" + ContentGlobal.INTcountNotiUnread); CrossBadge.Current.SetBadge(ContentGlobal.INTcountNotiUnread); var list_request = ContentGlobal.allldata["info"]["company_rules"]["list_request"]; ContentGlobal.loadListRequest(); Device.StartTimer(TimeSpan.FromMinutes(5), () => { Task.Factory.StartNew(async() => { try { ContentGlobal.allldata = await ContentGlobal.GetAllOfPersonal(); ContentGlobal.loadListRequest(); } catch (Exception el) { Debug.WriteLine("erorr refesh data" + el.ToString()); } }); return(true); }); Page page = new MainPage(); NavigationPage.SetHasNavigationBar(page, false); App.Current.MainPage = new NavigationPage(page); } } catch (Exception ex) { stkMain.IsVisible = true; stkLoad.IsVisible = false; await DisplayAlert("Lỗi", "Có vấn dề đã sảy ra, thử lại sau !", "OK"); Debug.WriteLine("Error OnAppearing--------------------------------", ex); } } else { stkMain.IsVisible = true; stkLoad.IsVisible = false; //await DisplayAlert("thong bao mang", ContentGlobal.statusNetwork(), "OK"); } } else { stkLoad.IsVisible = false; stkMain.IsVisible = true; /*Page page = new SignIn_Page(); * NavigationPage.SetHasNavigationBar(page, false); * App.Current.MainPage = new NavigationPage(page);*/ } }
public async void SignInButtonClicked(object sender, EventArgs e) { stkMain.IsVisible = false; stkLoad.IsVisible = true; if (ContentGlobal.statusNetwork().Equals("Connected") == false) { stkMain.IsVisible = true; stkLoad.IsVisible = false; //await DisplayAlert("thong bao mang", ContentGlobal.statusNetwork(), "OK"); } else { try { if (EntryUserName.Text.ToString().Length > 0 && EntryPassword.Text.ToString().Length > 0) { stkMain.IsVisible = false; stkLoad.IsVisible = true; string strSubFirebase = "verifyPassword"; string strParam = @"{ ""email"" : """ + EntryUserName.Text.ToString().ToLower() + @""",""password"" : """ + EntryPassword.Text.ToString() + @""",""returnSecureToken"" : ""true"" } "; Debug.WriteLine("PARAM---------------------------------------------------------------" + strParam); var rtFB = await ContentGlobal.PostAllFirebase_Auth(strSubFirebase, strParam); Debug.WriteLine("rtFB-------------------" + rtFB); string dataFB = (string)rtFB["idToken"]; Debug.WriteLine("idToken---------------------------" + dataFB); if (dataFB != null) { Application.Current.Properties["uId"] = (string)rtFB["localId"]; ContentGlobal.allldata = await ContentGlobal.GetAllOfPersonal(); ContentGlobal.loadListRequest(); Debug.WriteLine("allldata---------------------------" + ContentGlobal.allldata); if ((int)ContentGlobal.allldata["info"]["active"] == 0) { App.Current.MainPage = new Account.NoAcctivePage(); } else { if (ContentGlobal.registrationId.Length > 0) { var registrationId = ContentGlobal.allldata["info"]["registrationId"]; if (registrationId != null) { if (registrationId.ToString().Equals(ContentGlobal.registrationId) == false) { strSubFirebase = "pushData"; strParam = @"{""uid"" : """ + Application.Current.Properties["uId"].ToString() + @""", ""registrationId"" :""" + ContentGlobal.registrationId + @""" }"; Debug.WriteLine("strParam-----------------------------------------------------" + strParam); var rt = ContentGlobal.FirebasePOSTFunctions(strSubFirebase, strParam); } } else { strSubFirebase = "pushData"; strParam = @"{""uid"" : """ + Application.Current.Properties["uId"].ToString() + @""", ""registrationId"" :""" + ContentGlobal.registrationId + @""" }"; Debug.WriteLine("strParam-----------------------------------------------------" + strParam); var rt = ContentGlobal.FirebasePOSTFunctions(strSubFirebase, strParam); } } if ((int)ContentGlobal.allldata["info"]["acted"] == 1) { ContentGlobal.PeopleWorking = await ContentGlobal.peopleWorkingAsync(); ContentGlobal.Userroot = true; } else { ContentGlobal.Userroot = false; } ContentGlobal.email = EntryUserName.Text.ToString().ToLower(); if ((int)ContentGlobal.allldata["info"]["password_safety"] == 0) { //await DisplayAlert("Warring", "Bạn cần thay đổi mật khẩu hiện tại", "OK"); App.Current.MainPage = new Account.FistLoginPage(); } else { var month = (int)ContentGlobal.allldata["timeoff"]["period"]; ContentGlobal.INTcountNotiUnread = ContentGlobal.CountNotiUnread("individualistic", month) + ContentGlobal.CountNotiUnread("public", month); Debug.WriteLine("INTcountNotiUnread--------------------------------------------------" + ContentGlobal.INTcountNotiUnread); CrossBadge.Current.SetBadge(ContentGlobal.INTcountNotiUnread); Device.StartTimer(TimeSpan.FromMinutes(5), () => { Task.Factory.StartNew(async() => { try { ContentGlobal.allldata = await ContentGlobal.GetAllOfPersonal(); ContentGlobal.loadListRequest(); } catch (Exception el) { Debug.WriteLine("erorr refesh data" + el.ToString()); } }); return(true); }); var page = new MainPage(); NavigationPage.SetHasNavigationBar(page, false); App.Current.MainPage = new NavigationPage(page); } } } else { stkMain.IsVisible = true; stkLoad.IsVisible = false; if ((string)rtFB["error"]["message"] == "INVALID_PASSWORD") { EntryPassword.Text = ""; await DisplayAlert("Lỗi", "Mật khẩu bạn vừa nhập không đúng, nhập và thử lại!", "OK"); } else if ((string)rtFB["error"]["message"] == "EMAIL_NOT_FOUND") { EntryUserName.Text = ""; EntryPassword.Text = ""; await DisplayAlert("Lỗi", "Tài khoản đăng nhập không đúng, nhập lại email và password!", "OK"); } else { await DisplayAlert("Lỗi", (string)rtFB["error"]["message"], "OK"); } } } } catch (Exception ex) { stkMain.IsVisible = true; stkLoad.IsVisible = false; await DisplayAlert("Lỗi", "Có vấn dề đã sảy ra, thử lại sau !", "OK"); Debug.WriteLine("Error SignInButtonClicked--------------------------------", ex); // throw ex; } } }