コード例 #1
0
        async Task SignIn()
        {
            try
            {
                IsBusy  = true;
                Message = "登录中...(Signing In...)";

                if (string.IsNullOrEmpty(currUser.username) || string.IsNullOrEmpty(currUser.password))
                {
                    Message = "请输入用户名/口令(Please input username/password)";
                }
                else
                {
                    App.ResetCookie();
                    var cookie = await TheLoginDataStore.DoLogin(currUser.username, currUser.password);

                    if (cookie != null)
                    {
                        Settings.Cookie = cookie.cookie_name + "=" + cookie.cookie;
                        Settings.UserId = cookie.user.id;
                        MyHttpClient.Instance.SetCookie();
                        App.GoToMainPage();
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ErrorMessage.GetMessage(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
 async void Save_Clicked(object sender, System.EventArgs e)
 {
     viewModel.CurrentUser.phone   = txtPhone.Text;
     viewModel.CurrentUser.address = txtAddress.Text;
     try
     {
         await viewModel.SaveCurrentUserInfo();
         await DisplayAlert("", "保存成功(Save succeed!)", "确定(OK)");
     }
     catch (System.Exception ex)
     {
         await DisplayAlert("", ErrorMessage.GetMessage(ex.Message), "确定(OK)");
     }
 }
コード例 #3
0
        async void Delete_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                await viewModel.Delete();

                MessagingCenter.Send(this, "DeleteItem", viewModel.Item);
                await DisplayAlert("", "删除成功(succeed!)", "确认(OK)");

                await Navigation.PopToRootAsync();
            }
            catch (System.Exception ex)
            {
                await DisplayAlert("", ErrorMessage.GetMessage(ex.Message), "确认(OK)");
            }
        }
コード例 #4
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            try
            {
                await viewModel.InitOptions();

                if (viewModel.CurrentUser != null)
                {
                    txtPhone.Text    = viewModel.CurrentUser.phone;
                    txtAddress.Text  = viewModel.CurrentUser.address;
                    lblUserName.Text = viewModel.CurrentUser.username;
                    lblEmail.Text    = viewModel.CurrentUser.email;
                }
            }
            catch (System.Exception ex)
            {
                await DisplayAlert("", ErrorMessage.GetMessage(ex.Message), "确定(OK)");
            }
        }
コード例 #5
0
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            var item = args.SelectedItem as Property;

            if (item == null)
            {
                return;
            }
            try
            {
                Property newProperty = await viewModel.RefreshProperty(item);

                await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(newProperty)));
            }
            catch (System.Exception ex)
            {
                await DisplayAlert("", ErrorMessage.GetMessage(ex.Message), "确定(OK)");
            }

            // Manually deselect item
            ItemsListView.SelectedItem = null;
        }
コード例 #6
0
        public async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy || (Items.Count > 0))
            {
                return;
            }

            IsBusy = true;
            try
            {
                await InitOptions();

                var items = await ThePropertyDataStore.GetItemsAsync(null);

                Items.ReplaceRange(items);
            }

            catch (Exception ex)
            {
                if (ex.Message == ErrorMessage.NotLogin)
                {
                    App.Reload();
                }
                else
                {
                    MessagingCenter.Send(new MessagingCenterAlert
                    {
                        Title   = "",
                        Message = ErrorMessage.GetMessage(ex.Message),
                        Cancel  = "确定(OK)"
                    }, "message");
                }
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #7
0
        public async Task <bool> Save()
        {
            if (IsBusy)
            {
                return(false);
            }

            IsBusy  = true;
            Message = string.Empty;
            if (String.IsNullOrEmpty(Item.title))
            {
                Message += "请输入标题(please input title)";
            }
            if (String.IsNullOrEmpty(Item.content))
            {
                Message += "\r\n请输入内容(please input content)";
            }
            if (_bufferPath.Count == 0)
            {
                Message += "\r\n请上传图片(please upload pictures)";
            }
            if (String.IsNullOrEmpty(Item.address))
            {
                Message += "\r\n请输入地址(please input address)";
            }

            if (!string.IsNullOrEmpty(Message))
            {
                IsBusy = false;
                return(false);
            }

            try
            {
                Message = "正在连接服务器(connecting)...";
                string id = await ThePropertyDataStore.AddItemAsync(Item);

                int i = 0;
                Item.attachments = new List <Attachment>();
                foreach (string str in _bufferPath)
                {
                    if (str == string.Empty)
                    {
                        break;
                    }
                    Message = String.Format("上传第{0}张图片(uploading image {0})", i + 1);
                    await TheMediaDataStore.UploadImage(str, id, i.ToString());

                    i++;
                }
                if (Item.address != App.CurrentUser.address)
                {
                    App.CurrentUser.address = Item.address.Trim();
                    await TheLoginDataStore.SaveCurrentUser(App.CurrentUser);
                }
                Item = await ThePropertyDataStore.GetItem(id);

                return(true);
            }
            catch (System.Exception ex)
            {
                Message = ErrorMessage.GetMessage(ex.Message);
                IsBusy  = false;
                return(false);
            }
            finally
            {
                IsBusy  = false;
                Message = string.Empty;
            }
        }