/// <summary>
		/// 保存
		/// </summary>
		private void Save()
		{
			var trueName = edit_trueName.Text;
			if (string.IsNullOrEmpty (trueName)) {
				Toast.MakeText(this,"真实姓名不能为空,请输入真实姓名",ToastLength.Short).Show();
				return ;
			}
			if (!EldYoungUtil.IsTrueName (trueName)) {
				Toast.MakeText(this,"真实姓名不可包含字母、数字、特殊符号和非法词汇[2~8个汉字]\n",ToastLength.Short).Show();
				return ;
			}
			ProgressDialogUtil.StartProgressDialog(this,"正在保存...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网络",ToastLength.Short).Show();	
				ProgressDialogUtil.StopProgressDialog();
				return;
			}

			//调用restapi注册,将用户名、密码信息写
			var updateMyInfoParam = new UpdateMyInfoParam () {
				Uid = Global.MyInfo.UId,ParamType = "TrueName",ParamValue = edit_trueName.Text
			};
			if (!requestParams.ContainsKey ("key"))
				requestParams.Add ("key", updateMyInfoParam.Key);
			else
				requestParams ["key"] = updateMyInfoParam.Key;

			if (!requestParams.ContainsKey ("eUId"))
				requestParams.Add ("eUId", updateMyInfoParam.Euid);
			else
				requestParams ["eUId"] = updateMyInfoParam.Euid;
			
			if (!requestParams.ContainsKey ("eparamType"))
				requestParams.Add ("eparamType", updateMyInfoParam.EparamType);
			else
				requestParams ["eparamType"] = updateMyInfoParam.EparamType;
	
			if (!requestParams.ContainsKey ("eparamValue"))
				requestParams.Add ("eparamValue", updateMyInfoParam.EparamValue);
			else
				requestParams ["eparamValue"] = updateMyInfoParam.EparamValue;

			if (!requestParams.ContainsKey ("md5"))
				requestParams.Add ("md5", updateMyInfoParam.Md5);
			else
				requestParams ["md5"] = updateMyInfoParam.Md5;	
			var restSharpRequestHelp = new RestSharpRequestHelp(updateMyInfoParam.Url,requestParams);
			restSharpRequestHelp.ExcuteAsync((RestSharp.IRestResponse response) => 
				{
					if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
					{
						//获取并解析返回resultJson获取安全码结果值
						var result = response.Content;
						var updateMyInfoJson = JsonConvert.DeserializeObject<UpdateMyInfoJson>(result);
						if(updateMyInfoJson.statuscode == "1")
						{
							RunOnUiThread(()=>
								{
									Toast.MakeText(this,"保存成功",ToastLength.Short).Show();
									Global.MyInfo.TrueName = edit_trueName.Text;
									ProgressDialogUtil.StopProgressDialog();
									this.Finish();
									OverridePendingTransition(Android.Resource.Animation.SlideInLeft,Android.Resource.Animation.SlideOutRight);
								});
						}
						else
						{
							RunOnUiThread(()=>
								{
									Toast.MakeText(this,updateMyInfoJson.message,ToastLength.Short).Show();
									ProgressDialogUtil.StopProgressDialog();
									return;
								});
						}
					}
					else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut){
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,"网络连接超时,请重试",ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}
					else
					{
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}

				});
		}
		/// <summary>
		/// Reister this instance.
		/// </summary>
		private void Reister()
		{
			ProgressDialogUtil.StartProgressDialog(this,"正在注册...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网路",ToastLength.Short).Show();
				ProgressDialogUtil.StopProgressDialog();
				return;
			}


			//todo:调用restapi注册,将用户名、密码信息写
			var registerInfoParam = new RegisterInfoParam () {
				PhoneNumber = phoneNum,NickName = nickName,PassWord = passWord
			};

			//初始化参数
			SetRestRequestParams (registerInfoParam);

			var restSharpRequestHelp = new RestSharpRequestHelp(registerInfoParam.Url,requestParams);
			restSharpRequestHelp.ExcuteAsync ((response) => {
				if(response.ResponseStatus == ResponseStatus.Completed)
				{
					//获取并解析返回resultJson获取Guid结果值
					if(response.StatusCode == System.Net.HttpStatusCode.OK)
					{
						var resultJson = response.Content;
						var registerJson = JsonConvert.DeserializeObject<RegisterJson>(resultJson);
						if(registerJson.statuscode=="1")
						{
							Global.MyInfo = registerJson.data.Table[0];
							var Uid = Global.MyInfo.UId;
							var guidAsAlias = Uid.Replace("-","_");
							//注册用户成功,写极光推送别名,进入主界面
							_jpushUtil.SetAlias(guidAsAlias);
							sp_userinfo.Edit().PutString(Global.login_UserName,nickName).Commit();
							sp_userinfo.Edit().PutString(Global.login_Password,passWord).Commit();
							sp_userinfo.Edit().PutBoolean(Global.login_Password_Check,true).Commit();
							RunOnUiThread(()=>
								{
									//跳转到功能主界面
									var intent = new Intent(this,typeof(MainFragActivity));
									intent.SetFlags(ActivityFlags.ClearTask|ActivityFlags.NewTask);
									StartActivity(intent);			
									this.Finish();
									ProgressDialogUtil.StopProgressDialog();
									Toast.MakeText(this,"注册成功",ToastLength.Short).Show();
									OverridePendingTransition(Android.Resource.Animation.SlideInLeft,Android.Resource.Animation.SlideOutRight);
								});

						}
						else
						{
							//注册失败
							RunOnUiThread(()=>
								{
									Toast.MakeText(this,registerJson.message,ToastLength.Short).Show();
									ProgressDialogUtil.StopProgressDialog();
									return;
								});
						}
					}

				}
				else if(response.ResponseStatus == ResponseStatus.TimedOut)
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							return;
						});
				}
				else
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							return;
						});
				}



			});

		}
		private void PublishAdvice()
		{
			var adviceTitle = edit_advice_title.Text;
			if (string.IsNullOrEmpty (adviceTitle)) {
				Toast.MakeText(Activity,"留言标题不能为空,请输入标题",ToastLength.Short).Show();
				return ;
			}
			var adviceContent = edit_advice_content.Text;
			if (string.IsNullOrEmpty (adviceContent)) {
				Toast.MakeText(Activity,"留言内容不能为空,请输入留言内容",ToastLength.Short).Show();
				return ;
			}

			ProgressDialogUtil.StartProgressDialog(Activity,"正在保存...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(Activity))
			{
				Toast.MakeText(Activity,"网络连接超时,请检测网络",ToastLength.Short).Show();	
				ProgressDialogUtil.StopProgressDialog();
				return;
			}

			//调用restapi注册,将用户名、密码信息写
			var adviceWriteParam = new AdviceWriteParam () {
				UId = Global.MyInfo.UId,AdviceType = _adviceType,AdviceTitle = adviceTitle,AdviceContent = adviceContent
			};
			if (!requestParams.ContainsKey ("key"))
				requestParams.Add ("key", adviceWriteParam.Key);
			else
				requestParams ["key"] = adviceWriteParam.Key;

			if (!requestParams.ContainsKey ("eaction"))
				requestParams.Add ("eaction", adviceWriteParam.Eaction);
			else
				requestParams ["eaction"] = adviceWriteParam.Eaction;

			if (!requestParams.ContainsKey ("eUId"))
				requestParams.Add ("eUId", adviceWriteParam.Euid);
			else
				requestParams ["eUId"] = adviceWriteParam.Euid;

			if (!requestParams.ContainsKey ("eAdviceType"))
				requestParams.Add ("eAdviceType", adviceWriteParam.EadviceType);
			else
				requestParams ["eAdviceType"] = adviceWriteParam.EadviceType;

			if (!requestParams.ContainsKey ("ePlatformType"))
				requestParams.Add ("ePlatformType", adviceWriteParam.EplatformType);
			else
				requestParams ["ePlatformType"] = adviceWriteParam.EplatformType;

			if (!requestParams.ContainsKey ("eAdviceTitle"))
				requestParams.Add ("eAdviceTitle", adviceWriteParam.EadviceTitle);
			else
				requestParams ["eAdviceTitle"] = adviceWriteParam.EadviceTitle;

			if (!requestParams.ContainsKey ("eAdviceContent"))
				requestParams.Add ("eAdviceContent", adviceWriteParam.EadviceContent);
			else
				requestParams ["eAdviceContent"] = adviceWriteParam.EadviceContent;

			if (!requestParams.ContainsKey ("md5"))
				requestParams.Add ("md5", adviceWriteParam.Md5);
			else
				requestParams ["md5"] = adviceWriteParam.Md5;	

			var restSharpRequestHelp = new RestSharpRequestHelp(adviceWriteParam.Url,requestParams);
			restSharpRequestHelp.ExcuteAsync((RestSharp.IRestResponse response) => 
				{
					if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
					{
						//获取并解析返回resultJson获取安全码结果值
						var result = response.Content;
						var adviceWriteJson = JsonConvert.DeserializeObject<AdviceWriteJson>(result);
						if(adviceWriteJson.statuscode == "1")
						{
							Activity.RunOnUiThread(()=>
								{
									Toast.MakeText(Activity,"保存成功",ToastLength.Short).Show();
									ProgressDialogUtil.StopProgressDialog();

								});
						}
						else
						{
							Activity.RunOnUiThread(()=>
								{
									Toast.MakeText(Activity,adviceWriteJson.message,ToastLength.Short).Show();
									ProgressDialogUtil.StopProgressDialog();
									return;
								});
						}
					}
					else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut){
						Activity.RunOnUiThread(()=>
							{
								Toast.MakeText(Activity,"网络连接超时,请重试",ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}
					else
					{
						Activity.RunOnUiThread(()=>
							{
								Toast.MakeText(Activity,response.StatusDescription,ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}

				});

		}
		/// <summary>
		/// 保存
		/// </summary>
		private void Save()
		{
			
			var locationthreelevel = edit_locationthreelevel.Text;//todo:采用选择框赋值
			var locationdetail = edit_locationdeatil.Text;
			if (string.IsNullOrEmpty (locationthreelevel) || string.IsNullOrEmpty (locationdetail)) {
				Toast.MakeText(this,"省市区或实际地址不能为空,请输入",ToastLength.Short).Show();
				return ;
			}

			var contactAddress = locationthreelevel + locationdetail;

			ProgressDialogUtil.StartProgressDialog(this,"正在保存...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网络",ToastLength.Short).Show();	
				ProgressDialogUtil.StopProgressDialog();
				return;
			}


			var updateMyInfoParam = new UpdateMyInfoParam () {
				Uid = Global.MyInfo.UId,ParamType = "ContactAddress",ParamValue = contactAddress
			};
			if (!requestParams.ContainsKey ("key"))
				requestParams.Add ("key", updateMyInfoParam.Key);
			else
				requestParams ["key"] = updateMyInfoParam.Key;

			if (!requestParams.ContainsKey ("eUId"))
				requestParams.Add ("eUId", updateMyInfoParam.Euid);
			else
				requestParams ["eUId"] = updateMyInfoParam.Euid;

			if (!requestParams.ContainsKey ("eparamType"))
				requestParams.Add ("eparamType", updateMyInfoParam.EparamType);
			else
				requestParams ["eparamType"] = updateMyInfoParam.EparamType;

			if (!requestParams.ContainsKey ("eparamValue"))
				requestParams.Add ("eparamValue", updateMyInfoParam.EparamValue);
			else
				requestParams ["eparamValue"] = updateMyInfoParam.EparamValue;

			if (!requestParams.ContainsKey ("md5"))
				requestParams.Add ("md5", updateMyInfoParam.Md5);
			else
				requestParams ["md5"] = updateMyInfoParam.Md5;	
			var restSharpRequestHelp = new RestSharpRequestHelp(updateMyInfoParam.Url,requestParams);
			restSharpRequestHelp.ExcuteAsync((RestSharp.IRestResponse response) => 
				{
					if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
					{
						//获取并解析返回resultJson获取安全码结果值
						var result = response.Content;
						var updateMyInfoJson = JsonConvert.DeserializeObject<UpdateMyInfoJson>(result);
						if(updateMyInfoJson.statuscode == "1")
						{
							RunOnUiThread(()=>
								{
									Toast.MakeText(this,"保存成功",ToastLength.Short).Show();
									Global.MyInfo.ContactAddress = contactAddress;
									ProgressDialogUtil.StopProgressDialog();
									this.Finish();
									OverridePendingTransition(Android.Resource.Animation.SlideInLeft,Android.Resource.Animation.SlideOutRight);
								});
						}
						else
						{
							RunOnUiThread(()=>
								{
									Toast.MakeText(this,updateMyInfoJson.message,ToastLength.Short).Show();
									ProgressDialogUtil.StopProgressDialog();
									return;
								});
						}
					}
					else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut){
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,"网络连接超时,请重试",ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}
					else
					{
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}

				});
		}
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="phoneNum">Phone number.</param>
		private void SendSMS(string _phoneNumber)
		{
			ProgressDialogUtil.StartProgressDialog(this,"正在发送验证码...");

			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网路",ToastLength.Short).Show();
				ProgressDialogUtil.StopProgressDialog();
				return;
			}

			var smsInfoParam = new SmsInfoParam () {
				PhoneNumber = phoneNum,NickName = nickName,PassWord = passWord
			};

			//使用restsharpApi方式

			SetRestRequestParams (smsInfoParam);

			var restSharpRequestHelp = new RestSharpRequestHelp(smsInfoParam.Url,requestSmsParams);

			restSharpRequestHelp.ExcuteAsync ((response) => {

				if(response.ResponseStatus == ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
				{
					
					//获取并解析返回resultJson获取安全码结果值
					var resultJson = response.Content;
					var smsJson = JsonConvert.DeserializeObject<SmsJson>(resultJson);
					if(smsJson.statuscode =="1")
					{
						RunOnUiThread(()=>{
							securityCode = smsJson.data.ToString();

							mc.Start();
							tv_SendCodeStatusShow.Visibility = ViewStates.Visible;
						});
					}
					else
					{
						RunOnUiThread(()=>
							{
								tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
								Toast.MakeText(this,smsJson.message,ToastLength.Short).Show();

							});
					}
				}
				else if(response.ResponseStatus == ResponseStatus.TimedOut)
				{
					RunOnUiThread(()=>
						{
							tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
							Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show();
						});
				}
				else
				{
					RunOnUiThread(()=>
						{
							tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
							Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
						});
				}
				RunOnUiThread(()=>
					{
						ProgressDialogUtil.StopProgressDialog();
						return;
					});
			});
		}
		/// <summary>
		/// 发送验证码
		/// </summary>
		private void SendCode()
		{
			if (!ValidInput ()) {
				
				return;
			}
			ProgressDialogUtil.StartProgressDialog(this,"正在发送验证码...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网络",ToastLength.Short).Show();
				btn_Send.Enabled = true;
				ProgressDialogUtil.StopProgressDialog();
				return;
			}

			var sendCodeParam = new SendCodeParam () {
				PhoneNumberOne = phoneNumber,Type = sendType
			};
			//使用restsharpApi方式

			SetRestRequestSendCodeParams (sendCodeParam);

			var restSharpRequestHelp = new RestSharpRequestHelp(sendCodeParam.Url,requestsendcodeParams);
			restSharpRequestHelp.ExcuteAsync ((RestSharp.IRestResponse response) => {
				if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
				{
					//获取并解析返回resultJson获取安全码结果值
					var result = response.Content;
					var sendCodeJson = JsonConvert.DeserializeObject<SendCodeJson>(result);
					if(sendCodeJson.statuscode =="1")
					{
						RunOnUiThread(()=>{
							securityCode = sendCodeJson.data.ToString();
							ProgressDialogUtil.StopProgressDialog();
							Toast.MakeText(this,"验证码发送成功",ToastLength.Short).Show();
							tv_SendCodeStatusShow.Visibility = ViewStates.Visible;
							mc.Start();

						});
					}
					else
					{
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,sendCodeJson.message,ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								btn_Send.Enabled = true;
								tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
								return;
							});
					}
				}
				else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut)
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							btn_Send.Enabled = true;
							tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
							return;
						});
				}
				else
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							btn_Send.Enabled = true;
							tv_SendCodeStatusShow.Visibility = ViewStates.Invisible;
							return;
						});
					
				}
			});
		}
Exemplo n.º 7
0
		/// <summary>
		/// 检测是否需要更新,调用web服务
		/// </summary>
		/// <returns><c>true</c> if this instance is update; otherwise, <c>false</c>.</returns>
		private bool IsUpdate()
		{
			var checkFlag = false;
			var returnFlag = false;
			// 获取本地软件版本号,
			localversionCode =EldYoungUtil.GetAppVersionCode(context);
			//localversionCode =Global.version_code;
			//获取webservice中android app版本号,两者比较,如果不同,返回true else false
			//检测网络连接
			if(!EldYoungUtil.IsConnected(context))
			{
				return returnFlag;
			}
			var getAppVersionParam = new GetAppVersionParam ();

			if (!requestParams.ContainsKey ("key"))
				requestParams.Add ("key", getAppVersionParam.Key);
			else
				requestParams ["key"] = getAppVersionParam.Key;
			if (!requestParams.ContainsKey ("eappPlatform"))
				requestParams.Add ("eappPlatform", getAppVersionParam.EappPlatform);
			else
				requestParams ["eappPlatform"] = getAppVersionParam.EappPlatform;

			if (!requestParams.ContainsKey ("epackageName"))
				requestParams.Add ("epackageName", getAppVersionParam.EpackageName);
			else
				requestParams ["epackageName"] = getAppVersionParam.EpackageName;
			
			if (!requestParams.ContainsKey ("md5"))
				requestParams.Add ("md5", getAppVersionParam.Md5);
			else
				requestParams ["md5"] = getAppVersionParam.Md5;

			var restSharpRequestHelp = new RestSharpRequestHelp(getAppVersionParam.Url,requestParams);
			restSharpRequestHelp.ExcuteAsync ((RestSharp.IRestResponse response) => {
				if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
				{
					//获取并解析返回resultJson获取安全码结果值
					var result =response.Content;
					if(string.IsNullOrEmpty(result))
					{
						checkFlag = true;
					}
					else
					{
						var appVersionJson = JsonConvert.DeserializeObject<GetAppVersionJson>(result);
						if(appVersionJson.statuscode =="1")
						{
							var serverAppVersionCode = appVersionJson.data.AppServerVersionCode;
							if(localversionCode!=serverAppVersionCode)
							{
								//版本不一致有更新
								Global.AppPackagePath = appVersionJson.data.AppFilePath;
								returnFlag = true;
								checkFlag=true;
							}
							else
								checkFlag=true;
						}
						else
							checkFlag = true;
					}
				}
				else
				{
					checkFlag=true;
					Log.Info("CheckAppServerVersion",string.IsNullOrEmpty(response.StatusDescription)?"":response.StatusDescription);

				}
			});

			while (true) {
				//检测完成
				if (checkFlag) {
					return returnFlag;
				}
			}
		}
		/// <summary>
		/// Submit this instance.
		/// </summary>
		private void Submit()
		{
			passWord = edit_Pwd.Text;
			if (string.IsNullOrEmpty (passWord)) {
				Toast.MakeText(this,"密码不能为空,请输入密码",ToastLength.Short).Show();
				return ;
			}
			confirmPassWord = edit_ConfirmPwd.Text;
			if (string.IsNullOrEmpty (confirmPassWord)) {
				Toast.MakeText(this,"确认密码不能为空,请输入确认密码",ToastLength.Short).Show();
				return ;
			}
			if (passWord != confirmPassWord) {
				Toast.MakeText(this,"输入两次密码不一致,请检查",ToastLength.Short).Show();
				return ;
			}
			if (!EldYoungUtil.IsPassWord (passWord)) {
				Toast.MakeText (this, "请输入正确规范用户名6-20位,建议由字母、数字和符号两种以上组成", ToastLength.Short).Show ();
				return;
			}
			ProgressDialogUtil.StartProgressDialog(this,"正在提交...");
			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网路",ToastLength.Short).Show();
				ProgressDialogUtil.StopProgressDialog();
				return;
			}
			//调用restapi注册,将用户名、密码信息写
			var modipwdParam = new ModiyPasswordParam () {
				Type = sendType,Password = passWord
			};
			if (sendType == "FindPwd")
				modipwdParam.UId = phoneNumber;
			else
				modipwdParam.UId = Global.MyInfo.UId;

			//初始化参数
			SetRestRequestParams (modipwdParam);
			var restSharpRequestHelp = new RestSharpRequestHelp(modipwdParam.Url,requestsubmitParams);
			restSharpRequestHelp.ExcuteAsync ((RestSharp.IRestResponse response) => {
				if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
				{
					
					//获取并解析返回resultJson获取安全码结果值
	 				var result = response.Content;
					var setpwdJson = JsonConvert.DeserializeObject<SetPasswordJson>(result);
					if(setpwdJson.statuscode =="1")
					{
						RunOnUiThread(()=>{

							Toast.MakeText(this,setpwdJson.message,ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							var intent = new Intent(this,typeof(LoginActivity));
							intent.SetFlags(ActivityFlags.ClearTask|ActivityFlags.NewTask);
							StartActivity(intent);			

							this.Finish();

						});
					}
					else
					{
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,setpwdJson.message,ToastLength.Short).Show();
								ProgressDialogUtil.StopProgressDialog();
								return;
							});
					}


				}
				else if(response.ResponseStatus == RestSharp.ResponseStatus.TimedOut)
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,"网络连接超时,请重试",ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							return;
						});
				}
				else
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,response.StatusDescription,ToastLength.Short).Show();
							ProgressDialogUtil.StopProgressDialog();
							return;
						});
				}
			});

		}
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="phoneNum">Phone number.</param>
		private void SendSMS(string _phoneNumber)
		{
			ProgressDialogUtil.StartProgressDialog(this,"正在发送验证码...");

			//检测网络连接
			if(!EldYoungUtil.IsConnected(this))
			{
				Toast.MakeText(this,"网络连接超时,请检测网路",ToastLength.Short).Show();
				ProgressDialogUtil.StopProgressDialog();
				return;
			}

			var smsInfoParam = new SmsInfoParam () {
				PhoneNumber = phoneNumber,NickName = nickName,PassWord = passWord
			};
					
			//使用restsharpApi方式

			SetRestRequestParams (smsInfoParam);

			var restSharpRequestHelp = new RestSharpRequestHelp(smsInfoParam.Url,requestParams);

			restSharpRequestHelp.ExcuteAsync ((resoponse) => {

				if(resoponse.ResponseStatus == ResponseStatus.Completed && resoponse.StatusCode == System.Net.HttpStatusCode.OK)
				{
					//获取并解析返回resultJson获取安全码结果值
					var result= resoponse.Content;
					var smsJson = JsonConvert.DeserializeObject<SmsJson>(result);
					if(smsJson.statuscode =="1")
					{
						RunOnUiThread(()=>{
							Intent intent = new Intent(this,typeof(RegisterResultActivity));
							var bundle = new Bundle();
							bundle.PutString("phoneNum",phoneNumber);
							bundle.PutString("nickName",nickName);
							bundle.PutString("passWord",passWord);
							bundle.PutString("securityCode",smsJson.data.ToString());
							intent.PutExtras(bundle);
							StartActivity(intent);
						});
					}
					else
					{
						RunOnUiThread(()=>
							{
								Toast.MakeText(this,smsJson.message,ToastLength.Short).Show();
							});
					}	
				}
				else if(resoponse.ResponseStatus == ResponseStatus.TimedOut)
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,"网络连接超时",ToastLength.Short).Show();
						});
				}
				else
				{
					RunOnUiThread(()=>
						{
							Toast.MakeText(this,resoponse.StatusDescription,ToastLength.Short).Show();
						});
				}
				RunOnUiThread(()=>
					{
						ProgressDialogUtil.StopProgressDialog();
						return;
					});

			});
		}
Exemplo n.º 10
0
		private void SetPicToLocalAndServer(Bitmap mBitmap) 
		{

			var sdStatus = Android.OS.Environment.ExternalStorageState;
			//检测sd是否可用
			if (!sdStatus.Equals (Android.OS.Environment.MediaMounted)) {
				return;
			}
			System.IO.FileStream MyFileStream = null;

			Java.IO.File file = new Java.IO.File(path);
			if(!file.Exists())
				file.Mkdirs();// 创建文件夹
			string fileName = path + "myHead.jpg";
			try{
				MyFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.OpenOrCreate);  
				//保存照片  
				mBitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, MyFileStream); 

				byte[] buffer = new byte[MyFileStream.Length];
				// 设置当前流的位置为流的开始
				MyFileStream.Seek(0, SeekOrigin.Begin);
				MyFileStream.Read(buffer, 0, buffer.Length);


				var  headimgStr = Convert.ToBase64String(buffer);
				//调用restapi提交头像
				var headImgPostParam = new HeadImgPostParam () {
					UId = Global.MyInfo.UId,ImageStr = headimgStr
				};
				SetRestRequestParams (headImgPostParam);
				var restSharpRequestHelp = new RestSharpRequestHelp(headImgPostParam.Url,requestParams);
				restSharpRequestHelp.ExcuteAsync ((RestSharp.IRestResponse response) => {
					if(response.ResponseStatus == RestSharp.ResponseStatus.Completed && response.StatusCode == System.Net.HttpStatusCode.OK)
					{
						//获取并解析返回resultJson获取安全码结果值
						var result = response.Content;
						var headimgJson = JsonConvert.DeserializeObject<HeadImgJson>(result);
						if(headimgJson.statuscode == "1")
							Global.MyInfo.HeadImgUrl = headimgJson.data[0].HeadImgUrl;
						else
						{
							Activity.RunOnUiThread(()=>
								{
									Toast.MakeText(Activity,"头像上传失败",ToastLength.Short).Show();
								});
						}

					}
	
				});
			}
			catch(Java.IO.FileNotFoundException e) {
				e.PrintStackTrace ();
			}
			finally {
				MyFileStream.Flush ();
				MyFileStream.Close ();
			}	

		}