package com.activity.chaoran;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.EditText;
import com.chaoran.thread.UpdatePwdThread;
import com.sys.SysData;
import com.util.DialogUtil;

public class UpdatePwdActivity extends Activity {
    private EditText newPwd;
    private EditText CfNewPwd;
    public ProgressDialog pd;
    private Handler handler = new Handler() {
		@Override
		// 当有消息发送出来的时候就执行Handler的这个方法
		public void handleMessage(Message msg) {
			if (pd != null) {
				pd.dismiss();
			}
			if (msg.what == -1) {
				DialogUtil.builder(UpdatePwdActivity.this, "错误信息", msg.obj.toString(),0);
			}else{
				if(msg.obj.equals("0")){
					DialogUtil.builder(UpdatePwdActivity.this, "提示信息","修改密码成功",0);
				}else{
					DialogUtil.builder(UpdatePwdActivity.this, "错误信息","修改密码失败".concat( msg.obj.toString()),0);
				}
					
			}
		}

	};

    @Override
    public void onCreate(Bundle savedInstaneceState) {
        super.onCreate(savedInstaneceState);
        setContentView(R.layout.activity_update_pwd);
        ((EditText)findViewById(R.id.name)).setText(SysData.lgnname);
        newPwd=(EditText)findViewById(R.id.newpwd);
        CfNewPwd=(EditText)findViewById(R.id.cfnewpwd);
        newPwd.requestFocus();
    }
    public void onsub(View v) {
    	String newPwdValue=newPwd.getText().toString().trim();
    	if(newPwdValue.equals("")){
    		DialogUtil.builder(this, "错误信息", "请填写新密码！",0);
    		newPwd.requestFocus();
    		return;
    	}
    	String CfNewPwdValue=CfNewPwd.getText().toString().trim();
    	if(CfNewPwdValue.equals("")){
    		DialogUtil.builder(this, "错误信息", "请填写重复密码！",0);
    		CfNewPwd.requestFocus();
    		return;
    	}
    	if(!CfNewPwdValue.equals(newPwdValue)){
    		DialogUtil.builder(this, "错误信息", "新密码和重复密码不一致！",0);
    		newPwd.requestFocus();
    		return;
    	}
    	if (pd == null) {
			pd = ProgressDialog.show(this, "提示", "正在操作……");
		} else {
			DialogUtil.setDialog(pd, "提示", "正在操作……");
		}
    	new Thread(new UpdatePwdThread(handler,SysData.userid,newPwdValue)).start();
    }
    protected void onDestroy() {
		super.onDestroy();
		if (pd != null) {
			pd=null;
		}
		handler=null;
	}
}
