package com.szu;



import com.szu.accountsoft.dao.PwdDAO;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register_Activity extends Activity {
	private EditText password_1,password_2;
	private Button sure,clear, back;
	
	String password;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register_activity);
		
		
//		View v = findViewById(R.id.background_r);
//        v.getBackground().setAlpha(100);
		
		findView();
		
		setTitle("注册页面");
		
		
		sure.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
//				Intent intent = new Intent(Register_Activity.this, MainActivity.class);// 创建Intent对象
				PwdDAO pwdDAO = new PwdDAO(Register_Activity.this);// 创建PwdDAO对象
				
				if(password_1.getText().toString().trim().equals(""))
				{
					Toast.makeText(Register_Activity.this, "密码不能为空", Toast.LENGTH_LONG).show();
				}
				else if(password_2.getText().toString().trim().equals("") || password_2.getText().toString().trim().equals(""))
				{
					Toast.makeText(Register_Activity.this, "密码不能为空", Toast.LENGTH_LONG).show();
				}
				else if(password_1.getText().length()<6)
				{
					Toast.makeText(Register_Activity.this, "密码长度最少为6", Toast.LENGTH_SHORT).show();
				}
				else if(password_2.getText().length()<6)
				{
					Toast.makeText(Register_Activity.this, "密码长度最少为6", Toast.LENGTH_SHORT).show();
				}
				else if(password_1.getText().toString().trim().equals(password_2.getText().toString().trim()))
				{
					
					password = password_1.getText().toString().trim();
					
					
					
					if (pwdDAO.getCount() == 0)// 判断数据库中是否已经设置了密码
					{
						
						// 弹出信息提示
						Intent intent2 = new Intent(Register_Activity.this, Calculate_Activity.class);// 创建Intent对象
						Toast.makeText(Register_Activity.this, "请输入验证码！", Toast.LENGTH_SHORT).show();
						intent2.putExtra("password", password);
						startActivity(intent2);
						finish();
					
					} 
					else 
					{
						Toast.makeText(Register_Activity.this, "对不起，密码已存在！", Toast.LENGTH_SHORT).show();
					}
					
						
					}
				else
				{
					Toast.makeText(Register_Activity.this, "密码不匹配！", Toast.LENGTH_SHORT).show();
				}
			}
		});
		
		clear.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				password_1.setText("");
				password_2.setText("");
			}
		});

		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

	private void findView() {
		// TODO Auto-generated method stub
		password_1 = (EditText) findViewById(R.id.password_1);
		password_2 = (EditText) findViewById(R.id.password_2);
		sure = (Button) findViewById(R.id.login_button);
		clear = (Button) findViewById(R.id.clear_Button);
		back = (Button) findViewById(R.id.back);
	}

}
