public async System.Threading.Tasks.Task <bool> cleanUserTotalPoint(string emailStr) { bool result = false; if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = emailStr }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); var uri = app.url + "/AR_admin/UserCleanTotalPoint"; var postResult = await client.PostAsync(uri, content); if (postResult.IsSuccessStatusCode) { var resultString = await postResult.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <Result>(resultString); if (response != null && response.result != null && response.result != "" && response.result == "0") { result = true; } } } } else { await Application.Current.MainPage.DisplayAlert("訊息", app.networkMessage, "OK"); } return(result); }
public ShowPointLogDataService() { if (NetworkCheck.IsInternet()) { using (WebClient webClient = new WebClient()) { Uri address = new Uri(app.url + "/AR_admin/getUserPointLog"); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; UserRegister data = new UserRegister() { email = Application.Current.Properties["email"].ToString() }; string json = JsonConvert.SerializeObject(data); string result = webClient.UploadString(address, "POST", json); var response = JsonConvert.DeserializeObject <List <PointLog> >(result); if (response != null) { if (response.Count > 0) { TotlaCount = response.Count; for (int i = 0; i < response.Count; i++) { var MyItemListData = new MyItemListData(); MyItemListData.createDate = response[i].createDate; MyItemListData.stageName = response[i].stageName; MyItemListData.point = response[i].point; if (i % 2 == 0) { MyItemListData.CellBackgroundColor = Color.FromHex("#e8e8e8"); } else { MyItemListData.CellBackgroundColor = Color.FromHex("#f6f6f6"); } MyItemList.Add(MyItemListData); } } } else { Device.BeginInvokeOnMainThread(async() => { await Application.Current.MainPage.DisplayAlert("訊息", app.errorMessage, "OK"); }); } } } else { Device.BeginInvokeOnMainThread(async() => { await Application.Current.MainPage.DisplayAlert("訊息", app.networkMessage, "OK"); }); } }
public bool webClient(string inputSerialNumber) { bool original = false; string serverSerialNumber = ""; string emailStr = ""; if (Xamarin.Forms.Application.Current.Properties.ContainsKey("email") != false) { emailStr = Xamarin.Forms.Application.Current.Properties["email"].ToString(); } if (NetworkCheck.IsInternet()) { using (WebClient client = new WebClient()) { Uri address = new Uri(app.url + "/AR_admin/getUserSerialNumber"); client.Encoding = Encoding.UTF8; client.Headers[HttpRequestHeader.ContentType] = "application/json"; UserRegister data = new UserRegister() { email = emailStr }; string json = JsonConvert.SerializeObject(data); string result = client.UploadString(address, "POST", json); var post = JsonConvert.DeserializeObject <Result>(result); if (post != null && post.result != null && post.result != "" && post.result == "0") { serverSerialNumber = post.message; if (!string.IsNullOrEmpty(serverSerialNumber) && !string.IsNullOrEmpty(inputSerialNumber) && serverSerialNumber.Equals(inputSerialNumber)) { original = true; } else { original = false; } } else { original = false; } } } else { DisplayAlert("訊息", app.networkMessage, "OK"); } return(original); }
public void ValidateUserSN(String sn) { try { if (!string.IsNullOrEmpty(sn)) { if (NetworkCheck.IsInternet()) { var webClient = new WebClient(); Uri uri = new Uri(app.url + "/AR_admin/checkSN/" + sn); var result = webClient.DownloadString(uri); var data = JsonConvert.DeserializeObject <Result>(result); if (data != null && data.result != "") { if (data.result == "0") { serialNumber.Text = ""; snResult = true; } else if (data.result == "1") { serialNumber.Text = "激活碼已經被使用過"; snResult = false; } else if (data.result == "2") { serialNumber.Text = "激活碼不存在"; snResult = false; } } } else { Device.BeginInvokeOnMainThread(async() => { await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("訊息", app.networkMessage, "OK"); }); } } } catch (Exception ex) { Device.BeginInvokeOnMainThread(async() => { await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("訊息", app.errorMessage, "OK"); }); } }
private async void resetPWD_Tapped(object sender, EventArgs e) { if (!string.IsNullOrEmpty(email.Text)) { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = email.Text }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); var uri = app.url + "/AR_admin/sendMail"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Result>(resultString); if (post != null && post.result != null && post.result != "" && post.result == "0") { checkMailBox.IsVisible = true; resetBtn.IsVisible = false; } else { await DisplayAlert("訊息", "發送Email失敗!", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "請輸入Email!", "OK"); } }
//int amount = 0; public PrizeDetail(PrizeDetailItem arg) { InitializeComponent(); Title = "點數兌換"; On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); ((Xamarin.Forms.NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarBackgroundColor = Color.FromHex("#ff8400"); ((Xamarin.Forms.NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarTextColor = Color.White; if (NetworkCheck.IsInternet()) { Show(app.url + "/AR_admin/UsergetPrizeDetailbyId/" + arg.id); } else { DisplayAlert("訊息", app.networkMessage, "OK"); } }
public MyProfile() { InitializeComponent(); Title = "個人檔案"; On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); Xamarin.Forms.NavigationPage.SetHasBackButton(this, false); ((Xamarin.Forms.NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarBackgroundColor = Color.FromHex("#2f2f2f"); ((Xamarin.Forms.NavigationPage)Xamarin.Forms.Application.Current.MainPage).BarTextColor = Color.White; if (NetworkCheck.IsInternet()) { getUserData(); setSelect(Xamarin.Forms.Application.Current.Properties["email"].ToString()); } else { DisplayAlert("訊息", app.networkMessage, "OK"); } }
//public ObservableCollection<someDataClass> MyItemList { get; set; } public DataService() { if (NetworkCheck.IsInternet()) { if (Xamarin.Forms.Application.Current.Properties.ContainsKey("email") != false) { using (WebClient webClient = new WebClient()) { Uri address = new Uri(app.url + "/AR_admin/UserfindallPrize"); webClient.Encoding = Encoding.UTF8; webClient.Headers[HttpRequestHeader.ContentType] = "application/json"; UserRegister data = new UserRegister() { email = Application.Current.Properties["email"].ToString() }; string json = JsonConvert.SerializeObject(data); string result = webClient.UploadString(address, "POST", json); var posts = JsonConvert.DeserializeObject <List <PrizeContent> >(result); if (posts != null) { //handling the answer TotlaCount = posts.Count; if (posts.Count > 0) { //MyItemList = new ObservableCollection<MyItemListData>(); foreach (var postData in posts) { MyItemList.Add(new MyItemListData { id = postData.id, prizeName = postData.prizeName, point = postData.point, image = app.url + postData.image }); } } } } } } else { Device.BeginInvokeOnMainThread(async() => { await Application.Current.MainPage.DisplayAlert("訊息", app.networkMessage, "OK"); }); } }
private async void ratingStar_Tapped(object sender, EventArgs e) { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new RatingStarPrize { email = Xamarin.Forms.Application.Current.Properties["email"].ToString(), prizeID = prizeId, ratingStar = this.ratingStar.Text, comment = this.editFeedback.Text }; // create the request content and define Json var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/UserRatingStarPrize"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { await DisplayAlert("訊息", "感謝您寶貴的建議!", "OK"); await Navigation.PushAsync(new PrizeListView(), true); Navigation.RemovePage(this); } else { await DisplayAlert("訊息", "填寫評論失敗", "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
private async void circleImage_Tapped(object sender, EventArgs e) { if (NetworkCheck.IsInternet()) { var action = await DisplayActionSheet("從哪裏新增照片?", "取消", null, "拍照", "選擇照片"); switch (action) { case "選擇照片": await SelectFromImageLibrary(); break; case "拍照": await TakePhotoFromCamera(); break; } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
private async void changePWD_Tapped(object sender, EventArgs e) { if (NetworkCheck.IsInternet()) { if (!string.IsNullOrEmpty(newPWD.Text) && !string.IsNullOrEmpty(confirmPWD.Text)) { if (newPWD.Text == confirmPWD.Text) { } else { await DisplayAlert("訊息", "密碼不一致;請重新輸入!", "OK"); } } else { await DisplayAlert("訊息", "請輸入密碼", "OK"); } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
private async void login_Tapped(object sender, EventArgs e) { if (!string.IsNullOrEmpty(email.Text) && !string.IsNullOrEmpty(password.Text)) { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = email.Text, userPWD = password.Text }; // create the request content and define Json var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/userlogin"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Result>(resultString); if (post != null && post.result != null && post.result != "" && post.result == "0") { if (Xamarin.Forms.Application.Current.Properties.ContainsKey("email") != false) { Xamarin.Forms.Application.Current.Properties["email"] = email.Text; } else { Xamarin.Forms.Application.Current.Properties.Add("email", email.Text); } await Xamarin.Forms.Application.Current.SavePropertiesAsync(); //write user login log var postLogData = new UserLog { email = email.Text }; var jsonLog = JsonConvert.SerializeObject(postLogData); var contentLog = new StringContent(jsonLog, Encoding.UTF8, "application/json"); // send a POST request var uriLog = app.url + "/AR_admin/UserLoginLog"; var resultLog = await client.PostAsync(uriLog, contentLog); //導到選擇模式畫面 await Navigation.PushAsync(new MyProfile(), true); Navigation.RemovePage(this); } else { await DisplayAlert("訊息", "登入失敗!", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "請輸入Email和密碼!", "OK"); } }
private async void send_Tapped(object sender, EventArgs e) { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new MemberNumber { prizeId = prizeId, memberNumber = EnterMemberNumber.Text }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); var checkUri = app.url + "/AR_admin/checkMemberNumber"; var result = await client.PostAsync(checkUri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Result>(resultString); if (post.result != null && post.result != "" && post.result == "0") { var postOrderData = new PrizeOrder { prizeId = prizeId, email = Xamarin.Forms.Application.Current.Properties["email"].ToString(), amount = exchangeAmount, prizePoint = prizeTotalPoint }; var jsonOrder = JsonConvert.SerializeObject(postOrderData); var contentOrder = new StringContent(jsonOrder, Encoding.UTF8, "application/json"); var uri = app.url + "/AR_admin/UserExchangePrize"; var resultOrder = await client.PostAsync(uri, contentOrder); if (resultOrder.IsSuccessStatusCode) { var resultOrderString = await result.Content.ReadAsStringAsync(); var postOrder = JsonConvert.DeserializeObject <Result>(resultString); if (postOrder.result != null && postOrder.result != "" && postOrder.result == "0") { await DisplayAlert("訊息", "兌換成功", "Ok"); var prizeItem = new PrizeDetailItem { id = prizeId, prizeName = prizeName, amount = exchangeAmount, point = exchangePoint, image = imageSource }; await Navigation.PushAsync(new RatingStar(prizeItem), true); await PopupNavigation.Instance.PopAsync(); } else { await DisplayAlert("訊息", "兌換失敗!請稍候再試", "Ok"); } } else { await DisplayAlert("訊息", app.errorMessage, "Ok"); } } else { await DisplayAlert("訊息", "輸入的店家序號錯誤!", "Ok"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
public async void getUserData(string emailStr) { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = emailStr }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/getUserData"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var getUserData = JsonConvert.DeserializeObject <List <UserRegister> >(resultString); if (getUserData != null && getUserData.Count > 0) { foreach (var userData in getUserData) { if (!string.IsNullOrEmpty(userData.userPhotoImage)) { circleImage.IsVisible = true; circleImage.Source = new UriImageSource { CachingEnabled = false, Uri = new Uri(app.url + "/AR_admin/userImage/" + userData.userPhotoImage) }; } else { noImage.IsVisible = true; circleImage.IsVisible = false; } userName.Text = userData.userName; if (!string.IsNullOrEmpty(userData.sex.ToString()) && userData.sex.Equals("1")) { this.sex.Text = "1"; manEnable.IsVisible = true; womanDisable.IsVisible = true; manDisable.IsVisible = false; womanEnable.IsVisible = false; } else { this.sex.Text = "0"; womanEnable.IsVisible = true; manDisable.IsVisible = true; manEnable.IsVisible = false; womanDisable.IsVisible = false; } birthday.Text = userData.birthday; age.Text = userData.age; tall.Text = userData.tall; weight.Text = userData.weight; if (!string.IsNullOrEmpty(userData.serialNumber)) { serialNumber.Text = userData.serialNumber; originalSN = userData.serialNumber; } else { serialNumber.Text = ""; } if (!string.IsNullOrEmpty(userData.deviceNumber)) { deviceText.Text = userData.deviceNumber; } else { deviceText.Text = ""; } } } else { await DisplayAlert("訊息", "取得使用者資料失敗!", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
async Task SelectFromImageLibrary() { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("訊息", "無法打開相簿;設備不支援", "OK"); return; } //Check Permission var photosStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Photos); if (photosStatus != PermissionStatus.Granted) { var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Photos }); photosStatus = results[Permission.Photos]; } if (photosStatus == PermissionStatus.Granted) { var file = await CrossMedia.Current.PickPhotoAsync( new PickMediaOptions { PhotoSize = PhotoSize.Small, CompressionQuality = 92, }); if (file == null) { return; } if (NetworkCheck.IsInternet()) { userPhotoImageSN = await sn.getUserPhotoImageSN();//取得照片檔案序號 if (!string.IsNullOrEmpty(userPhotoImageSN) && userPhotoImageSN != "-1") { postImage(file, userPhotoImageSN); //show Image circleImage.IsVisible = true; img.IsVisible = false; circleImage.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); } else { await DisplayAlert("訊息", "取得序號資料失敗;請稍候再更改照片!", "OK"); } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "沒有權限開啟相簿", "OK"); //iOS客戶端時打開設置界面 if (Device.RuntimePlatform == Device.iOS) { CrossPermissions.Current.OpenAppSettings(); } } }
private async void postImage(MediaFile userImageFile, string sn) { UserRegister postData = null; if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { if (!string.IsNullOrEmpty(sn)) { //upload image to server using (var content = new MultipartFormDataContent()) { // get path var path = userImageFile.Path; // get filename var filename = Path.GetFileName(path); //get file extension int position = filename.IndexOf("."); if (position > 0) { extension = filename.Substring(position); } // read content using (var fs = userImageFile.GetStream()) { var streamContent = new StreamContent(fs); streamContent.Headers.Add("Content-Type", "application/octet-stream"); streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + Path.GetFileName(path) + "\""); content.Add(streamContent, "file", filename); if (!string.IsNullOrEmpty(sn)) { postData = new UserRegister { userPhotoImage = sn }; } if (postData != null && !string.IsNullOrEmpty(postData.userPhotoImage)) { content.Add(new StringContent(""), "email"); content.Add(new StringContent(sn), "userPhotoImage"); } // 上傳到遠端伺服器上 var response = await client.PostAsync(app.url + "/AR_admin/uploadfile", content); if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync().Result; string responseContent = await response.Content.ReadAsStringAsync(); //handling the answer var getResponse = JsonConvert.DeserializeObject <Result>(responseContent); if (getResponse != null && getResponse.result == "0") { await DisplayAlert("訊息", "上傳圖檔成功", "OK"); } else { await DisplayAlert("訊息", "上傳圖檔失敗;請稍候再更改照片", "OK"); } } else { await DisplayAlert("訊息", "上傳圖檔失敗;請稍候再更改照片", "OK"); } } } } else { await DisplayAlert("訊息", "取得序號資料失敗;請稍候再更改照片!", "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
private async void add_Tapped(object sender, EventArgs e) { string serialNumberText = "", deviceNumberText = ""; if (checkBox.IsChecked == true) { var isValid = _context.Validate(); if (isValid) { if (password.Text.Equals(confirmPassword.Text)) { if (!string.IsNullOrEmpty(snText.Text) || !string.IsNullOrEmpty(deviceText.Text)) { if (!string.IsNullOrEmpty(snText.Text)) { ValidateUserSN(snText.Text); } if (!string.IsNullOrEmpty(this.deviceText.Text) && string.IsNullOrEmpty(this.snText.Text)) { snResult = true; } if (snResult) { if (NetworkCheck.IsInternet()) { if (!string.IsNullOrEmpty(this.snText.Text)) { serialNumberText = this.snText.Text; } if (!string.IsNullOrEmpty(this.deviceText.Text)) { deviceNumberText = this.deviceText.Text; } using (var client = new HttpClient()) { if (!string.IsNullOrEmpty(userPhotoImageSN)) { userPhotoImageSN = userPhotoImageSN + extension; } var postData = new UserRegister { sex = this.sex, birthday = this.birthday, tall = this.tall, weight = this.weight, age = this.age, userName = this.userName.Text, email = this.email.Text, userPWD = this.password.Text, serialNumber = serialNumberText, deviceNumber = deviceNumberText, userPhotoImage = userPhotoImageSN }; //create the request content and define Json var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/addUser"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Result>(resultString); if (post != null && post.result != null && post.result != "" && post.result == "0") { if (Xamarin.Forms.Application.Current.Properties.ContainsKey("email") != false) { Xamarin.Forms.Application.Current.Properties["email"] = email.Text; } else { Xamarin.Forms.Application.Current.Properties.Add("email", email.Text); } await Xamarin.Forms.Application.Current.SavePropertiesAsync(); await DisplayAlert("訊息", "註冊帳號成功!", "OK"); await Navigation.PushAsync(new MyProfile(), true); Navigation.RemovePage(this); } else { await DisplayAlert("訊息", "註冊帳號失敗!請稍候再試", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "激活碼有誤請重新輸入!", "OK"); } } else { await DisplayAlert("訊息", "請輸入激活碼或者裝置號碼!", "OK"); } } else { await DisplayAlert("訊息", "密碼不一致請重新輸入", "OK"); } } else { await DisplayAlert("訊息", "有必填欄位未輸入或格式錯誤!", "OK"); } } else { await DisplayAlert("訊息", "未勾選同意合約", "OK"); } }
async Task TakePhotoFromCamera() { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("訊息", "無法開啟鏡頭;設備不支援", "OK"); return; } //Check camera and storage Permission var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera); var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage); if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted) { var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage }); cameraStatus = results[Permission.Camera]; storageStatus = results[Permission.Storage]; } if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted) { var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions { PhotoSize = PhotoSize.Medium, Name = "photo.jpg" }); if (file == null) { return; } if (NetworkCheck.IsInternet()) { userPhotoImageSN = await sn.getUserPhotoImageSN();//取得照片檔案序號 if (!string.IsNullOrEmpty(userPhotoImageSN) && userPhotoImageSN != "-1") { postImage(file, userPhotoImageSN); // show ImageSource circleImage.IsVisible = true; img.IsVisible = false; circleImage.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return(stream); }); } else { await DisplayAlert("訊息", "取得序號資料失敗;請稍候再更改照片!", "OK"); } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "沒有權限開啟鏡頭或進行檔案儲存", "OK"); //iOS客戶端時打開設置界面 if (Device.RuntimePlatform == Device.iOS) { CrossPermissions.Current.OpenAppSettings(); } } }
private async void save_Clicked(object sender, EventArgs e) { string email = Xamarin.Forms.Application.Current.Properties["email"].ToString(); if (string.IsNullOrEmpty(serialNumber.Text) && string.IsNullOrEmpty(deviceText.Text)) { await DisplayAlert("訊息", "請輸入激活碼或者裝置號碼!", "OK"); getUserData(email); return; } else if (string.IsNullOrEmpty(serialNumber.Text) && !string.IsNullOrEmpty(deviceText.Text)) { snResult = true; } else if (!string.IsNullOrEmpty(serialNumber.Text) && string.IsNullOrEmpty(deviceText.Text)) { CheckSN(serialNumber.Text); } else if (!string.IsNullOrEmpty(serialNumber.Text) && !string.IsNullOrEmpty(deviceText.Text)) { CheckSN(serialNumber.Text); } if (snResult) { var isValid = _context.Validate(); if (isValid) { GetUserSerialNumber getSN = new GetUserSerialNumber(); string userSerialNumber = await getSN.getUserSerialNumber(email); if (!string.IsNullOrEmpty(userSerialNumber) && serialNumber.Text != userSerialNumber) { CleanUserTotalPoint cleanPoint = new CleanUserTotalPoint(); bool answer = await DisplayAlert("訊息", "注意!!!若修改激活碼則上一場的點數將會全被歸零", "OK", "取消"); if (answer == true) { bool cleanResult = await cleanPoint.cleanUserTotalPoint(email); if (cleanResult != true) { await DisplayAlert("訊息", app.errorMessage, "OK"); return; } } else { getUserData(email); return; } } if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = Xamarin.Forms.Application.Current.Properties["email"].ToString(), userName = this.userName.Text, birthday = this.birthday.Text, sex = this.sex.Text, tall = this.tall.Text, weight = this.weight.Text, age = this.age.Text, serialNumber = serialNumber.Text, deviceNumber = deviceText.Text, userPhotoImage = userPhotoImageSN }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/updateUserData"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var responseData = JsonConvert.DeserializeObject <Result>(resultString); if (responseData != null && responseData.result != "") { if (responseData.result == "0") { await DisplayAlert("訊息", "更新使用者資料成功!", "OK"); } else if (responseData.result == "1") { await DisplayAlert("訊息", app.errorMessage, "OK"); } else if (responseData.result == "2") { await DisplayAlert("訊息", "更新資料失敗!帳號不存在", "OK"); } else if (responseData.result == "3") { await DisplayAlert("訊息", "更新資料失敗!使用者資料為空值", "OK"); } } else { await DisplayAlert("訊息", "更新資料失敗!請稍候再試", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "有必填欄位未輸入或格式錯誤!", "OK"); } } else { await DisplayAlert("訊息", "激活碼有誤請重新輸入!", "OK"); } }
public async void setSelect(string emailStr) { if (NetworkCheck.IsInternet()) { if (!string.IsNullOrEmpty(emailStr)) { using (var client = new HttpClient()) { var postData = new UserRegister { email = emailStr }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); var uri = app.url + "/AR_admin/getUserSelection"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <Result>(resultString); if (response != null && response.result != null && response.result != "" && response.result == "0") { if (response.message == "DeviceNumber and SerialNumber") { sport.IsVisible = true; tour.IsVisible = true; } else if (response.message == "DeviceNumber") { sport.IsVisible = true; tour.IsVisible = false; } else if (response.message == "SerialNumber") { sport.IsVisible = false; tour.IsVisible = true; } else { sport.IsVisible = false; tour.IsVisible = false; } } else { sport.IsVisible = false; tour.IsVisible = false; } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", "查無登入資料;請重新登入!", "OK"); await Navigation.PushAsync(new Register(), true); } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }
public async void getUserData() { if (NetworkCheck.IsInternet()) { using (var client = new HttpClient()) { var postData = new UserRegister { email = Xamarin.Forms.Application.Current.Properties["email"].ToString() }; var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/getUserData"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var getUserData = JsonConvert.DeserializeObject <List <UserRegister> >(resultString); if (getUserData != null && getUserData.Count > 0) { foreach (var userData in getUserData) { if (!string.IsNullOrEmpty(userData.userPhotoImage)) { circleImage.IsVisible = true; circleImage.Source = new UriImageSource { CachingEnabled = false, Uri = new Uri(app.url + "/AR_admin/userImage/" + userData.userPhotoImage.Trim()) }; } else { noImage.IsVisible = true; circleImage.IsVisible = false; } userName.Text = userData.userName; deviceNumber.Text = userData.deviceNumber; if (!string.IsNullOrEmpty(userData.sex.ToString()) && userData.sex == "1") { man.IsVisible = true; } else { women.IsVisible = true; } age.Text = userData.age; tall.Text = userData.tall; weight.Text = userData.weight; } } else { await DisplayAlert("訊息", "取得使用者資料失敗!", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } }