Beispiel #1
0
        public async void BtnDangSimClicked(object sender, EventArgs e)
        {
            var confirm = await DisplayAlert("Xác nhận", "Bạn có muốn bán tất cả sim vừa import không", "Đồng ý", "Đóng");

            if (!confirm)
            {
                return;
            }

            gridLoading.IsVisible = true;
            ApiResponse response = await ApiHelper.Put("api/sim/postsimlist", _simList.Select(x => x.Id).ToArray());

            if (response.IsSuccess)
            {
                await Navigation.PopAsync(false);

                MySimListViewModel mySimListViewModel = Shell.Current.BindingContext as MySimListViewModel;
                mySimListViewModel.RefreshCommand.Execute(null);
                XFToast.ShortMessage("Đăng sim thành công");
            }
            else
            {
                await DisplayAlert("", response.Message, "Đóng");
            }
            gridLoading.IsVisible = false;
        }
        private async void DataGet()
        {
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Previous data or Internet");
                searbar.IsVisible = false;
            }
            else
            {
                try
                {
                    searbar.IsVisible = true;
                    newlist           = await MoneyCache.GetAsync <List <NepNews> >(Url);

                    foreach (NepNews n in newlist)
                    {
                        n.desc = Constants.ScrubHtml(n.description);
                        n.desc = new String(n.desc.Take(200).ToArray()) + "...";
                    }
                    NewsCollection       = new ObservableCollection <NepNews>(newlist);
                    listView.ItemsSource = NewsCollection;
                    listView.Opacity     = 0;
                    await listView.FadeTo(1, 1000, Easing.SpringIn);
                }catch (Exception ex)
                {
                }
            }
            listView.EndRefresh();
        }
Beispiel #3
0
        private async void DataGet()
        {
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Previous data or Internet");
                searbar.IsVisible = false;
            }
            else
            {
                try
                {
                    searbar.IsVisible = true;
                    videolist         = await MoneyCache.GetAsync2 <List <Video> >(Url);

                    foreach (Video n in videolist)
                    {
                        n.link = Constants.ScrubHtml2(n.link);
                    }
                    NewsCollection       = new ObservableCollection <Video>(videolist);
                    listView.ItemsSource = NewsCollection;
                    listView.Opacity     = 0;
                    await listView.FadeTo(1, 1000, Easing.SpringIn);
                }
                catch (Exception ex)
                {
                }
            }
            listView.EndRefresh();
        }
Beispiel #4
0
        private async void BtnLogin_Clicked(object sender, EventArgs e)
        {
            SetBusyIndicator(true);

            userinfo = new UserInfo
            {
                UserName = entUserName.Text,
                Password = entPassword.Text
            };

            if (await LoginValidation(entUserName.Text, entPassword.Text))
            {
                // PostLogin(url,userinfo);
                UserInfo data = await c.SaveUser(userinfo, url);

                if (!data.Equals(null))
                {
                    if (data.Messages.Equals("Successful"))
                    {
                        if (Device.OS == TargetPlatform.iOS)
                        {
                            await DisplayAlert("Message", "Login Successful", "Ok");
                        }
                        else
                        {
                            XFToast.ShortMessage("Login Successful");
                        }
                        App.Current.MainPage = new NavigationPage(new MasterPage());
                        SetBusyIndicator(false);
                    }
                    else
                    {
                        if (Device.OS == TargetPlatform.iOS)
                        {
                            await DisplayAlert("Message", "Invalid Credentia", "Ok");
                        }
                        else
                        {
                            XFToast.ShortMessage("Invalid Credential");
                        }

                        SetBusyIndicator(false);
                    }
                }
                else
                {
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        await DisplayAlert("Message", "Invalid Credentia", "Ok");
                    }
                    else
                    {
                        XFToast.ShortMessage("Invalid Credential");
                    }
                    SetBusyIndicator(false);
                }
            }
            SetBusyIndicator(false);
            // Loading.IsVisible = true;
        }
Beispiel #5
0
        private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            try
            {
                if (e.SelectedItem == null)
                {
                    return;
                }

                var item = (MasterPageItem)e.SelectedItem;
                if (item.id == 5)
                {
                    Navigation.PushAsync(new KnowCmPage());
                }
                else
                {
                    Detail = new MainTabPage(item.id);
                }
                IsPresented = false;
                navigationDrawerList.SelectedItem = null;
            }catch (Exception ex)
            {
                XFToast.ShortMessage(ex.Message);
            }
        }
        private async void Btnstart_Clicked(object sender, EventArgs e)
        {
            if (subjectPick.SelectedIndex != -1)
            {
                if (coursePick.SelectedIndex != -1)
                {
                    await Navigation.PushAsync(new StartQuizPage(courseId));
                }
                else
                {
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        await DisplayAlert("Message", "Please select any course", "Ok");
                    }
                    else
                    {
                        XFToast.ShortMessage("Please select any course");
                    }
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Please select any subject", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Please select any subject");
                }
            }


            SetBusyIndicator(false);
        }
Beispiel #7
0
        public async Task <bool> CheckPhoneNo(string phoneNo)
        {
            if (!string.IsNullOrEmpty(phoneNo))
            {
                if (phoneNo.Length == 10)
                {
                    return(true);
                }
                else
                {
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        await DisplayAlert("Message", "Please enter proper mobile No", "Ok");
                    }
                    else
                    {
                        XFToast.ShortMessage("Please enter proper mobile No");
                    }
                    return(false);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Please enter the Mobile No.", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Please enter the Mobile No.");
                }

                return(false);
            }
        }
Beispiel #8
0
        private async void DataGet()
        {
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Previous data or Internet");
            }
            else
            {
                try
                {
                    messagelist = await MoneyCache.GetAsync <List <Notifications> >(Url);

                    foreach (Notifications n in messagelist)
                    {
                        n.temp = DateTime.Parse(n.start_date);
                    }
                    NewsCollection = new ObservableCollection <Notifications>(messagelist);

                    timelineListView.ItemsSource = NewsCollection;
                    timelineListView.Opacity     = 0;
                    await timelineListView.FadeTo(1, 1000, Easing.SpringIn);
                }catch (Exception ex)
                {
                }
            }
            timelineListView.EndRefresh();
        }
Beispiel #9
0
 public async Task <bool> CheckName(string name, bool flag)
 {
     if (!string.IsNullOrEmpty(name))
     {
         return(true);
     }
     else
     {
         if (flag)
         {
             if (Device.OS == TargetPlatform.iOS)
             {
                 await DisplayAlert("Message", "Please enter the Name", "Ok");
             }
             else
             {
                 XFToast.ShortMessage("Please enter the Name");
             }
         }
         else
         {
             if (Device.OS == TargetPlatform.iOS)
             {
                 await DisplayAlert("Message", "Please enter the User Name", "Ok");
             }
             else
             {
                 XFToast.ShortMessage("Please enter the User Name");
             }
         }
         return(false);
     }
 }
Beispiel #10
0
        public void ResendVerify_Clicked(object sender, EventArgs e)
        {
            EntryVerifyCode.Text = "";
            var phone = this.EntryPhone.Text.Trim();

            this.SendVerifyCode(phone);
            XFToast.ShortMessage("Đã gửi mã xác thực");
        }
        async void UpBlue_Tapped(object sender, System.EventArgs e)
        {
            //show answer.

            PageDown.IsVisible = false;
            await PageDown.TranslateTo(0, 0, 500, Easing.SinIn);

            var a = answerList.Where(item => item.IsSelected == item.IsCorrect).Select(wrappedItem => new { wrappedItem.Answer, wrappedItem.IsCorrect, wrappedItem.IsSelected }).ToList();
            var b = answerList.Where(item => item.IsSelected == true).Select(wrappedItem => new { wrappedItem.Answer, wrappedItem.IsCorrect, wrappedItem.IsSelected }).ToList();

            if (b.Count != 0)
            {
                if (a.Count == answerList.Count)
                {
                    rightAns.IsVisible  = true;
                    wrongAns.IsVisible  = false;
                    PageDown.IsVisible  = true;
                    stackMain.IsEnabled = false;
                    txtrightAns.Text    = "Congrats Your Answer Is Right";
                }
                else
                {
                    var correctAns = answerList.Where(item => item.IsCorrect == true).Select(wrappedItem => wrappedItem.Answer).ToList();

                    string answer = "";
                    for (int x = 0; x < correctAns.Count(); x++)
                    {
                        answer = answer + correctAns[x] + ", ";
                    }

                    rightAns.IsVisible  = false;
                    wrongAns.IsVisible  = true;
                    PageDown.IsVisible  = true;
                    stackMain.IsEnabled = false;
                    txtwrongAns.Text    = "Your Right Answer Is :" + answer;
                }
            }

            else
            {
                PageDown.IsVisible = false;
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Select any answer", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Select any answer");
                }
            }
        }
Beispiel #12
0
        public async void DownloadGoogleSheetTemplate_Clicked(object sender, EventArgs a)
        {
            gridLoading.IsVisible = true;
            try
            {
                PermissionStatus storagePermission = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

                if (storagePermission != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Storage))
                    {
                        await DisplayAlert("Quyền truy cập", "Sim Here cần quyền truy cập vào bộ nhớ để lưu template", "Đồng ý");
                    }
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        storagePermission = await PermissionHelper.CheckPermissions(Permission.Storage, "Quyền truy cập bộ nhớ", "Sim Here cần quyền truy cập vào bộ nhớ để lưu template");
                    }
                    else
                    {
                        var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);

                        storagePermission = results[Permission.Storage];
                    }
                }
                if (storagePermission == PermissionStatus.Granted)
                {
                    HttpClient          client   = BsdHttpClient.Instance();
                    HttpResponseMessage response = await client.GetAsync(Configuration.AppConfig.API_IP + "import_template.xlsx", HttpCompletionOption.ResponseHeadersRead);

                    var streamToReadFrom = await response.Content.ReadAsByteArrayAsync();

                    var    service    = DependencyService.Get <IFileService>();
                    string folderName = Device.RuntimePlatform == Device.iOS ? "" : "Download/SimHere";
                    service.SaveFile("import_template.xlsx", streamToReadFrom, folderName);
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        service.OpenFile("import_template.xlsx", folderName);
                    }
                    else
                    {
                        XFToast.ShortMessage("Tải template thành công");
                    }
                }
            }
            catch
            {
                await DisplayAlert("", "Tải thất bại", "Đóng");
            }
            gridLoading.IsVisible = false;
        }
Beispiel #13
0
        public async void SaveProfile()
        {
            var fullName = EntryName.Text.Trim();
            var phone    = EntryPhone.Text.Trim();
            var address  = EntryAddress.Text.Trim();
            var email    = EntryEmail.Text.Trim();

            var data = new Dictionary <string, object>();

            data["FullName"] = fullName;
            data["Phone"]    = phone;
            data["Address"]  = address;
            if (EntryEmail.IsEnabled)
            {
                data["Email"] = email;
            }
            if (viewModel.SexOption != null)
            {
                bool sex = viewModel.SexOption.Id == 1 ? true : false;
                data["Sex"] = sex;
            }

            if (viewModel.Birthday != null)
            {
                data["Birthday"] = viewModel.Birthday;
            }
            ApiResponse response = await ApiHelper.Post("api/user/updateprofile", data, true);

            if (response.IsSuccess)
            {
                XFToast.ShortMessage("Cập nhật thành công");
                EntryEmail.IsEnabled  = false;
                UserLogged.FullName   = fullName;
                UserLogged.Phone      = phone;
                UserLogged.Address    = address;
                lblDefaultAvatar.Text = AvatarHelper.NameToAvatarText(UserLogged.FullName);

                // update lai full name
                //var account = PageHelper.GetAccountTabPage();
                //account_grouplv account_Grouplv = account.Content as account_grouplv;
                //account_Grouplv.RefreshName();
            }
            else
            {
                await DisplayAlert("", "Không thể cập nhật thông tin cá nhân. " + response.Message, "Đóng");
            }
            gridLoading.IsVisible = false;
        }
Beispiel #14
0
        public async void ImportFile(object sender, ItemTappedEventArgs e)
        {
            gridLoading.IsVisible = true;
            var file     = e.Item as GoogleSheetFileListResponse;
            var response = await ApiHelper.Post($"api/googlesheet/import/{file.id}?access_token={viewModel.Access_Token}", null, true);

            if (response.IsSuccess)
            {
                modalDriveFiles.IsVisible = false;
                XFToast.ShortMessage("Import thành công");
            }
            else
            {
                await DisplayAlert("", response.Message, "Đóng");
            }
            gridLoading.IsVisible = false;
        }
Beispiel #15
0
        private async void BtnCancleClicked(object sender, EventArgs e)
        {
            gridLoading.IsVisible = true;
            await ApiHelper.Put("api/sim/status", new AddUpdateSimViewModel()
            {
                Sim = new Sim()
                {
                    Status = 0,
                    Id     = SimId
                }
            }, true);

            await Shell.Current.Navigation.PopAsync();

            await Shell.Current.Navigation.PushAsync(new PostSim(SimId), false);

            XFToast.ShortMessage("Huỷ thành công !");
        }
Beispiel #16
0
        public static async Task <T> GetAsync <T>(string url, int days = 100, bool forceRefresh = false)
        {
            var        json   = string.Empty;
            HttpClient client = new HttpClient();

            try
            {
                //check if we are connected, else check to see if we have valid data
                if (CrossConnectivity.Current.IsConnected)
                {
                    json = await client.GetStringAsync(url);

                    if (string.IsNullOrWhiteSpace(json))
                    {
                        json = Barrel.Current.Get(url);
                    }
                    if (!string.IsNullOrWhiteSpace(json))
                    {
                        json = Constants.ScrubHtml3(json);
                        Barrel.Current.Add(url, json, TimeSpan.FromDays(days));
                    }
                }
                else if (!forceRefresh && !Barrel.Current.IsExpired(url))
                {
                    json = Barrel.Current.Get(url);
                }


                return(await Task.Run(() => JsonConvert.DeserializeObject <T>(json)));
            }
            catch (Exception ex)
            {
                XFToast.ShortMessage("Couldn't retrieve data");
                json = Barrel.Current.Get(url);
                if (!string.IsNullOrWhiteSpace(json))
                {
                    return(await Task.Run(() => JsonConvert.DeserializeObject <T>(json)));
                }
                else
                {
                    return(default(T));
                }
            }
        }
Beispiel #17
0
        async void LoadSchedule(object sender, EventArgs e)
        {
            if ((Xamarin.Forms.Application.Current.Properties["Class"].ToString() != (Classes.SelectedIndex + 1).ToString()) && (Xamarin.Forms.Application.Current.Properties["ClassNumber"].ToString() != (Classes.SelectedIndex + 1).ToString()))
            {
                try
                {
                    string       ClassNumber = (Classes.SelectedIndex + 1).ToString();
                    string       url         = "http://www.zse.srem.pl/index.php?opcja=modules/plan_lekcji/pokaz_plan";
                    HtmlWeb      web         = new HtmlWeb();
                    HtmlDocument version     = await Task.Run(() => web.Load(url));

                    var versionNode = version.DocumentNode.SelectSingleNode("//div[@class='col-md-12']/a");
                    url = versionNode.GetAttributeValue("href", "http://www.zse.srem.pl/plan_lekcji/b/index.html");
                    string[] url_pieces     = url.Substring(7).Split('/');
                    string   ScheduleLetter = url_pieces[2];
                    App.Current.Properties["ScheduleLetter"] = ScheduleLetter;
                    await App.Current.SavePropertiesAsync();

                    url = url.Replace("index", "plany/o" + ClassNumber);
                    HtmlDocument htmldoc = await Task.Run(() => web.Load(url));

                    htmldoc.DocumentNode.InnerHtml = htmldoc.DocumentNode.SelectSingleNode("//table[@class='tabela']").InnerHtml;
                    htmldoc.Save(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/plan.html");
                    Xamarin.Forms.Application.Current.Properties["Class"]       = Classes.Items[Classes.SelectedIndex].ToLower();
                    Xamarin.Forms.Application.Current.Properties["ClassNumber"] = Classes.SelectedIndex + 1;
                    Xamarin.Forms.Application.Current.Properties["changed"]     = true;
                    await App.Current.SavePropertiesAsync();

                    XFToast.ShortMessage("Pomyślnie zapisano!");
                }
                catch (Exception ex)
                {
                    XFToast.ShortMessage("Błąd podczas zapisywania.");
                    Debug.WriteLine(ex);
                }
            }
            if (int.Parse(Xamarin.Forms.Application.Current.Properties["startscreen"].ToString()) != default_option.SelectedIndex)
            {
                Xamarin.Forms.Application.Current.Properties["startscreen"] = default_option.SelectedIndex;
                await App.Current.SavePropertiesAsync();

                XFToast.ShortMessage("Pomyślnie zapisano!");
            }
        }
Beispiel #18
0
        private async void listView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }

            var dataCard = e.SelectedItem as News;

            if (CrossConnectivity.Current.IsConnected)
            {
                await Navigation.PushAsync(new NewsDetailPage(dataCard), true);
            }
            else
            {
                XFToast.ShortMessage("No Internet Connection");
            }
            listView.SelectedItem = null;
        }
Beispiel #19
0
        public async Task <bool> LoginValidation(string username, string password)
        {
            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
            {
                return(true);
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Please enter the UserName and Password", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Please enter the UserName and Password ");
                }

                return(false);
            }
        }
        public async void GetDataCourse()
        {
            SetBusyIndicator(true);

            CourseList = new List <CourseInfo>();
            CourseList.Clear();
            coursePick.Items.Clear();
            string url = "http://13.126.189.26:10008/api/Get_CourseList/" + subjectId;

            JObject data = c.GetDetail(url);

            IList <JToken> results = data["list"].Children().ToList();

            if (results.Count != 0)
            {
                foreach (JToken result in results)
                {
                    System.Diagnostics.Debug.WriteLine(result);                                              //just to check my json data.
                    CourseInfo searchResult = JsonConvert.DeserializeObject <CourseInfo>(result.ToString()); //get exception on this line.
                    coursePick.Items.Add(searchResult.CourseName);
                    coursePick.IsEnabled = true;
                    CourseList.Add(searchResult);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    coursePick.IsEnabled = false;
                    await DisplayAlert("Message", "No Courses in this subject", "Ok");
                }
                else
                {
                    coursePick.IsEnabled = false;
                    XFToast.ShortMessage("No Courses in this subject");
                }
                //coursePick.Items.Add("No Courses in this subject ):");
                //coursePick.SelectedIndex = -1;
            }
            SetBusyIndicator(false);
        }
Beispiel #21
0
        public BioPage()
        {
            InitializeComponent();
            view.Opacity = 0;
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Previous data or Internet");
            }
            else
            {
                DataGet();
            }

            CrossConnectivity.Current.ConnectivityChanged += async(sender, args) =>
            {
                if (args.IsConnected)
                {
                    DataGet();
                }
            };
        }
Beispiel #22
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Internet Connection");
            }
            else
            {
                try
                {
                    if (enUser.Text != null && enUser.Text != "" && enEmail.Text != null && enEmail.Text != "" && enPhone.Text != null && enPhone.Text != "" && enSub.Text != null && enSub.Text != "" && enDesc.Text != null && enDesc.Text != "")
                    {
                        var msg = new Message {
                            full_name = enUser.Text, email = enEmail.Text, contact_no = enPhone.Text, subject = enSub.Text, body = enDesc.Text, status = "Sent"
                        };
                        var content  = JsonConvert.SerializeObject(msg);
                        var response = await _client.PostAsync(Url, new StringContent(content, Encoding.UTF8, "application/json"));

                        if ((int)response.StatusCode >= 200 && (int)response.StatusCode <= 299)
                        {
                            XFToast.ShortMessage("Message Sent");
                            await Navigation.PopAsync(true);
                        }
                        else
                        {
                            XFToast.ShortMessage("Please enter a valid email address");
                        }
                    }
                    else
                    {
                        XFToast.ShortMessage("Please fill all the fields");
                    }
                }
                catch (Exception ex)
                {
                    XFToast.ShortMessage("Internet cut-off while sending");
                }
            }
        }
Beispiel #23
0
        public async Task <bool> CheckEmailId(string emailId)
        {
            if (!string.IsNullOrEmpty(emailId))
            {
                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Match match = regex.Match(emailId);
                if (match.Success)
                {
                    return(true);
                }
                else
                {
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        await DisplayAlert("Message", "Please enter proper EmailId", "Ok");
                    }
                    else
                    {
                        XFToast.ShortMessage("Please enter proper EmailId");
                    }

                    return(false);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Please enter the EmailId", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Please enter the EmailId");
                }
                return(false);
            }
        }
        private async void DataGet()
        {
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.ShortMessage("No Previous data or Internet");
            }
            else
            {
                try
                {
                    notlist = await MoneyCache.GetAsync <List <Notifications> >(Url);

                    NotiCollection       = new ObservableCollection <Notifications>(notlist);
                    listView.ItemsSource = NotiCollection;
                    listView.Opacity     = 0;
                    await listView.FadeTo(1, 1000, Easing.SpringIn);
                }
                catch (Exception e)
                {
                }
            }

            listView.EndRefresh();
        }
Beispiel #25
0
        public async void BtnDeleteSimClicked(object sender, EventArgs e)
        {
            var confirm = await DisplayAlert("Xác nhận", "Bạn có muốn xóa sim đã import không", "Đồng ý", "Đóng");

            if (!confirm)
            {
                return;
            }

            gridLoading.IsVisible = true;
            ApiResponse response = await ApiHelper.Delete("api/sim?Ids=" + string.Join(",", _simList.Select(x => x.Id).ToArray()));

            if (response.IsSuccess)
            {
                await Navigation.PopAsync(false);

                XFToast.ShortMessage("Xoá sim thành công");
            }
            else
            {
                await DisplayAlert("", response.Message, "Đóng");
            }
            gridLoading.IsVisible = false;
        }
Beispiel #26
0
        public async Task <bool> CheckPassword(string password)
        {
            if (!string.IsNullOrEmpty(password))
            {
                if (password.Length > 5)
                {
                    return(true);
                }
                else
                {
                    if (Device.OS == TargetPlatform.iOS)
                    {
                        await DisplayAlert("Message", "The password lenght should be above 6", "Ok");
                    }
                    else
                    {
                        XFToast.ShortMessage("The password lenght should be above 6");
                    }

                    return(false);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Please Enter the password", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Please Enter the password");
                }

                return(false);
            }
        }
Beispiel #27
0
        private async void BtnRegister_Clicked()
        {
            SetBusyIndicator(true);
            userInfo = new UserInfo
            {
                FirstName    = entFName.Text,
                UserName     = entUName.Text,
                Email        = entEmail.Text,
                MobileNumber = entMobile.Text,
                Password     = entPassword.Text,
                RoleId       = 3,
                IsAgree      = true,
                UserType     = "Individual"
            };


            if (await CheckName(entFName.Text, true))
            {
                if (await CheckName(entUName.Text, false))
                {
                    if (await CheckPhoneNo(entMobile.Text))
                    {
                        if (await CheckEmailId(entEmail.Text))
                        {
                            if (await CheckPassword(entPassword.Text))
                            {
                                if (await CheckPassword(entCPassword.Text))
                                {
                                    if (entPassword.Text.Equals(entCPassword.Text))
                                    {
                                        UserInfo data = await c.SaveUser(userInfo, Url);

                                        if (data.Messages.Equals("Successful Inserted"))
                                        {
                                            if (Device.OS == TargetPlatform.iOS)
                                            {
                                                await DisplayAlert("Message", "Registered Successfully", "Ok");
                                            }
                                            else
                                            {
                                                XFToast.ShortMessage("Registered Successfully");
                                            }

                                            App.Current.MainPage = new NavigationPage(new MasterPage());
                                            SetBusyIndicator(false);
                                        }
                                        else
                                        {
                                            SetBusyIndicator(false);
                                            if (Device.OS == TargetPlatform.iOS)
                                            {
                                                await DisplayAlert("Message", "Invalid credential", "Ok");
                                            }
                                            else
                                            {
                                                XFToast.ShortMessage("Invalid credential");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        SetBusyIndicator(false);
                                        if (Device.OS == TargetPlatform.iOS)
                                        {
                                            await DisplayAlert("Message", "The password and Confirm Password should be same", "Ok");
                                        }
                                        else
                                        {
                                            XFToast.ShortMessage("The password and Confirm Password should be same");
                                        }
                                    }
                                    SetBusyIndicator(false);
                                }
                                SetBusyIndicator(false);
                            }
                            SetBusyIndicator(false);
                        }
                        SetBusyIndicator(false);
                    }
                    SetBusyIndicator(false);
                }
                SetBusyIndicator(false);
            }
            SetBusyIndicator(false);
        }
Beispiel #28
0
        private async void SelectImage_Clicked(object sender, EventArgs e)
        {
            var actionSheet = await DisplayActionSheet("Tuỳ chọn", "Đóng", null, "Chụp ảnh", "Chọn ảnh");


            Plugin.Media.Abstractions.MediaFile file = null;

            if (actionSheet == "Chụp ảnh")
            {
                await CrossMedia.Current.Initialize();

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("Máy ảnh", "Máy ảnh không khả dụng", "Đóng");

                    gridLoading.IsVisible = false;
                    return;
                }


                PermissionStatus cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);

                if (cameraStatus != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Camera))
                    {
                        await DisplayAlert("Quyền truy cập máy ảnh", "Sim ,ere cần truy cập vào máy ảnh để chụp hình cho ảnh đại diện", "Đồng ý");
                    }
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        cameraStatus = await PermissionHelper.CheckPermissions(Permission.Camera, "Quyền truy cập máy ảnh", "Sim Here cần truy cập vào máy ảnh để chụp hình cho ảnh đại diện");
                    }
                    else
                    {
                        var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Camera);

                        cameraStatus = results[Permission.Camera];
                    }
                }
                if (cameraStatus == PermissionStatus.Granted)
                {
                    gridLoading.IsVisible = true;
                    file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        SaveToAlbum    = false,
                        PhotoSize      = Plugin.Media.Abstractions.PhotoSize.MaxWidthHeight,
                        MaxWidthHeight = 300,
                    });
                }
            }
            else if (actionSheet == "Chọn ảnh")
            {
                await CrossMedia.Current.Initialize();

                Permission pickPhotoStatus = Permission.Storage;
                if (Device.RuntimePlatform == Device.iOS)
                {
                    pickPhotoStatus = Permission.Photos;
                }


                PermissionStatus photoPermisstionStatue = await CrossPermissions.Current.CheckPermissionStatusAsync(pickPhotoStatus);

                if (photoPermisstionStatue != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(pickPhotoStatus))
                    {
                        await DisplayAlert("Quyền truy cập hình ảnh", "Sim Here cần truy cập vào thư viện hình ảnh để đặt anh đại ", "Đồng ý");
                    }
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        photoPermisstionStatue = await PermissionHelper.CheckPermissions(pickPhotoStatus, "Quyền truy cập hình ảnh", "Sim Here muốn truy cập vào thư viện hình ảnh của bạn để lấy hình ảnh đặt làm ảnh đại diện cho bạn.");
                    }
                    else
                    {
                        var results = await CrossPermissions.Current.RequestPermissionsAsync(pickPhotoStatus);

                        photoPermisstionStatue = results[pickPhotoStatus];
                    }
                }
                if (photoPermisstionStatue == PermissionStatus.Granted)
                {
                    gridLoading.IsVisible = true;
                    file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions()
                    {
                        MaxWidthHeight = 300,
                        PhotoSize      = Plugin.Media.Abstractions.PhotoSize.MaxWidthHeight
                    });
                }
            }
            else
            {
                gridLoading.IsVisible = false;
            }

            if (file == null)
            {
                gridLoading.IsVisible = false;
                return;
            }

            var client = BsdHttpClient.Instance();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", UserLogged.AccessToken);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            MultipartFormDataContent form = new MultipartFormDataContent();


            var stream  = file.GetStream();
            var content = new StreamContent(stream);

            content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
            {
                Name     = "files",
                FileName = "test.jpg"
            };

            form.Add(content);



            try
            {
                HttpResponseMessage response = await(client.PostAsync("api/user/changeavatar", form));
                string body = await response.Content.ReadAsStringAsync();

                ApiResponse apiResponse = JsonConvert.DeserializeObject <ApiResponse>(body);
                if (apiResponse.IsSuccess)
                {
                    string newFileName = apiResponse.Content.ToString();

                    ImageSource newImageSource = ImageSource.FromStream(() => file.GetStream());
                    SetAvatar(newImageSource);

                    TrackProfileChange.AvatarHasChanged = true;
                    UserLogged.AvatarUrl = AppConfig.API_IP + "Upload/Avatar/" + newFileName;
                    XFToast.ShortMessage("Cập nhật thành cộng");
                    gridLoading.IsVisible = false;
                }
                else
                {
                    await DisplayAlert("", "Không thể cập nhật ảnh đại diện", "Đóng");

                    gridLoading.IsVisible = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                gridLoading.IsVisible = false;
            }
        }
Beispiel #29
0
        private async void BtnPost_Clicked(object sender, EventArgs e)
        {
            AddSimViewModel model = viewModel.Sim;

            if (string.IsNullOrWhiteSpace(model.SimNumber))
            {
                await DisplayAlert("", "Vui lòng nhập số sim", "Đóng");

                return;
            }

            if (model.SimNumber.Length < 9)
            {
                await DisplayAlert("", "Số Sim không đúng định dạng", "Đóng");

                return;
            }

            if (string.IsNullOrWhiteSpace(model.DisplayNumber))
            {
                await DisplayAlert("", "Vui lòng nhập số sim", "Đóng");

                return;
            }

            if (model.Carrier == null)
            {
                await DisplayAlert("", "Vui lòng chọn nhà mạng", "Đóng");

                return;
            }

            if (model.Price.HasValue == false)
            {
                await DisplayAlert("", "Vui lòng nhập giá sim", "Đóng");

                return;
            }
            gridLoading.IsVisible = true;

            Sim sim = new Sim();

            sim.SimNumber     = model.SimNumber;
            sim.DisplayNumber = model.DisplayNumber;
            sim.Price         = model.Price.Value;
            sim.CarrierId     = model.Carrier.Id;
            sim.Description   = model.Description;
            if (model.SubcribeType != null)
            {
                sim.SubcribeTypeId = model.SubcribeType.Id;
            }

            if (SimId != null) // sửa thì gán thêm id.
            {
                sim.Id = SimId;
            }

            IEnumerable <NumberType> numberTypes = viewModel.NumberTypeOptions.Where(x => x.IsSelected).Select(x => new NumberType()
            {
                Id = x.Id
            });

            AddUpdateSimViewModel addUpdateSimViewModel = new AddUpdateSimViewModel();

            addUpdateSimViewModel.Sim         = sim;
            addUpdateSimViewModel.NumberTypes = numberTypes;

            ApiResponse response = null;

            if (SimId == null)
            {
                response = await ApiHelper.Post("api/sim", addUpdateSimViewModel, true);
            }
            else
            {
                response = await ApiHelper.Put("api/sim", addUpdateSimViewModel, true);
            }

            if (response.IsSuccess)
            {
                if (SimId == null)
                {
                    //MySimList mySimList = ((App.Current.MainPage as MainPage).Children[3] as NavigationPage).RootPage as MySimList;
                    //MySimListViewModel mySimListVM = mySimList.BindingContext as MySimListViewModel;

                    MySimListViewModel mySimListVM = Shell.Current.BindingContext as MySimListViewModel;

                    //mySimListVM.RefreshCommand.Execute(null);
                    //await Navigation.PopAsync(false);
                    await mySimListVM.LoadOnRefreshCommandAsync();

                    var added = mySimListVM.Data[0];

                    SimId = added.Id;

                    gridLoading.IsVisible = false;
                    var actionSheet = await DisplayActionSheet("Lưu thành công. Bạn có muốn đăng bán sim này không?", "Để sau", null, "Đăng bán");

                    if (actionSheet == "Đăng bán")
                    {
                        BtnDangSimClicked(sender, EventArgs.Empty);
                    }
                    else
                    {
                        await Shell.Current.Navigation.PopAsync();

                        await Shell.Current.Navigation.PushAsync(new PostSim(SimId), false);

                        XFToast.ShortMessage("Lưu thành công !");
                    }
                }
                else
                {
                    gridLoading.IsVisible = false;
                    XFToast.ShortMessage("Lưu thành công !");
                }
            }
            else
            {
                await DisplayAlert("", response.Message, "Đóng");

                gridLoading.IsVisible = false;
            }
        }
        async void DownWhite_Tapped(object sender, System.EventArgs e)
        {
            //change question
            stackMain.IsEnabled = true;
            await PageDown.TranslateTo(0, Page.Height, 500, Easing.SinIn);

            var a = answerList.Where(item => item.IsSelected == item.IsCorrect).Select(wrappedItem => new { wrappedItem.Answer, wrappedItem.IsCorrect, wrappedItem.IsSelected }).ToList();
            var b = answerList.Where(item => item.IsSelected == true).Select(wrappedItem => new { wrappedItem.Answer, wrappedItem.IsCorrect, wrappedItem.IsSelected }).ToList();

            if (b.Count != 0)
            {
                quesNo++;
                if (a.Count == answerList.Count)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        for (int j = 0; j < list[i].listQuestion.Count; j++)
                        {
                            if (i == 0 && j == 0)
                            {
                            }
                            else
                            {
                                lstCnt++;
                                if (quesNo == lstCnt)
                                {
                                    lblQuestion.Text    = list[i].listQuestion[j].Question;
                                    lblquesNo.Text      = "Q." + quesNo;
                                    listAns.ItemsSource = list[i].listQuestion[j].listAnswer;
                                    answerList          = list[i].listQuestion[j].listAnswer;
                                    var multiPage = new SelectMultipleBasePage <AnswerInfo>(answerList);
                                    SetBusyIndicator(false);
                                }
                            }
                        }
                    }
                    if (Qcount == quesNo)
                    {
                        var result = await DisplayAlert("Message", "Quiz Completed", "ok", "");

                        if (result == true)
                        {
                            await Navigation.PushAsync(new MasterPage());

                            SetBusyIndicator(false);
                        }
                        else
                        {
                            return;
                        }
                    }
                    lstCnt = 1;
                    SetBusyIndicator(false);
                }

                else
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        for (int j = 0; j < list[i].listQuestion.Count; j++)
                        {
                            if (i == 0 && j == 0)
                            {
                            }
                            else
                            {
                                lstCnt++;
                                if (quesNo == lstCnt)
                                {
                                    lblQuestion.Text    = list[i].listQuestion[j].Question;
                                    lblquesNo.Text      = "Q." + quesNo;
                                    listAns.ItemsSource = list[i].listQuestion[j].listAnswer;
                                    answerList          = list[i].listQuestion[j].listAnswer;
                                    var multiPage = new SelectMultipleBasePage <AnswerInfo>(answerList);
                                    SetBusyIndicator(false);
                                }
                            }
                        }
                    }

                    if (Qcount == quesNo)
                    {
                        var result = await DisplayAlert("Message", "Quiz Completed", "ok", "cancel");

                        if (result == true)
                        {
                            await Navigation.PushAsync(new MasterPage());

                            SetBusyIndicator(false);
                        }
                        else
                        {
                            return;
                        }
                    }
                    lstCnt = 1;
                    SetBusyIndicator(false);
                }
            }
            else
            {
                if (Device.OS == TargetPlatform.iOS)
                {
                    await DisplayAlert("Message", "Select any answer", "Ok");
                }
                else
                {
                    XFToast.ShortMessage("Select any answer");
                }
            }
        }