vity.this, "密码错误", Toast.LENGTH_LONG).show(); System.out.println("密码错误"); showloginRegDialog(); } } }) .setNeutralButton("注册",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub EditText etName = (EditText)loginRegView.findViewById(R.id.login_name); EditText etPassword= (EditText) loginRegView.findViewById(R.id.login_password); String name = etName.getText().toString(); String password = etPassword.getText().toString(); System.out.println("register name"+name+"password"+password); UserInfo existUser = new UserInfo(); existUser = findUserByName(name); UserInfo registerUser = new UserInfo(); registerUser.setName(name); registerUser.setPassword(password); if(name.equals("") || password.equals("")){ Toast.makeText(WebserviceActivity.this, "请输入用户名和密码", Toast.LENGTH_LONG).show(); System.out.println("请输入用户名和密码"); showloginRegDialog(); }else if(existUser != null){ Toast.makeText(WebserviceActivity.this, "该用户已注册,请换个名字注册", Toast.LENGTH_LONG).show(); System.out.println("该用户已注册,请换个名字注册"); showloginRegDialog(); }else if((registerUser!=null) &&(existUser==null)) { saveUser(name,password); Toast.makeText(WebserviceActivity.this, "注册成功,请登录", Toast.LENGTH_LONG).show(); System.out.println("注册成功,请登录"); showloginRegDialog(); } } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); loginRegDialog = builder.create(); loginRegDialog.show(); }
public UserInfo findUserByName(String name) { // TODO Auto-generated method stub SoapObject soapObject = new SoapObject(NAMESPACE, FIND_METHOD_NAME); soapObject.addProperty("name", name); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);// 版本 envelope.bodyOut = soapObject ; envelope.dotNet = false ; envelope.setOutputSoapObject(soapObject) ; HttpTransportSE trans = new HttpTransportSE(URL) ; trans.debug = true ; // 使用调试功能 try { trans.call(SOAP_ACTION, envelope) ; } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } SoapObject result = (SoapObject) envelope.bodyIn; Gson gson = new Gson(); String json = result.getProperty(0).toString(); UserInfo userInfo = new UserInfo(); userInfo = gson.fromJson(json, UserInfo.class); System.out.println("Web Service返回的数据是:"+result.getProperty(0)); System.out.println("Web Service返回的userInfo"+userInfo); return userInfo; } public void saveUser(String name,String password) { // TODO Auto-generated method stub SoapObject soapObject = new SoapObject(NAMESPACE, SAVE_METHOD_NAME); soapObject.addProperty("name", name); soapObject.addProperty("password", password); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);// 版本 envelope.bodyOut = soapObject ; envelope.dotNet = false ; envelope.setOutputSoapObject(soapObject) ; HttpTransportSE trans = new HttpTransportSE(URL) ; trans.debug = true ; // 使用调试功能 try { trans.call(SOAP_ACTION, envelope) ; } catch (IOException e) { e |