package com.avicsafety.dangerous_chemicals;
import java.util.Date;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import com.avicsafety.conf.Configuration;
import com.avicsafety.lib.CustomView.AvicButton;
import com.avicsafety.lib.CustomView.AvicEditText;
import com.avicsafety.lib.CustomView.AvicSelect;
import com.avicsafety.lib.DateTimePicker.YearMonthPickerDialog;
import com.avicsafety.lib.DateTimePicker.YearMonthPickerDialog.OnYearMonthSetListener;
import com.avicsafety.lib.TreeManager.SelectPageActivity;
import com.avicsafety.lib.tools.DialogCreator;
import com.avicsafety.lib.tools.tools;
import com.avicsafety.service.Basis_CityInfoManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
@ContentView(R.layout.activity_accident_search)
//事故案例
public class AccidentSearchActivity extends BaseActivity implements OnClickListener {
private Dialog dg_type;
private Dialog dg_country;
private Dialog dg_provinces;
private Dialog dg_city;
private YearMonthPickerDialog dg_startMonth;
private YearMonthPickerDialog dg_endMonth;
private Basis_CityInfoManager cityManager = new Basis_CityInfoManager();
private String SelectedProvId = "0";
//初始化组件
@Override
protected void InitializeComponent() {
// TODO Auto-generated method stub
super.InitializeComponent();
setTitle("事故案例搜索");
as_accident_country.setVisibility(View.GONE);
}
//初始化数据
@Override
protected void InitializeData() {
// TODO Auto-generated method stub
super.InitializeData();
}
//初始化控件
@Override
protected void InitializeEvent() {
// TODO Auto-generated method stub
super.InitializeEvent();
as_accident_type.setOnClickListener(this);
as_start_time.setOnClickListener(this);
as_end_time.setOnClickListener(this);
as_accident_country.setOnClickListener(this);
as_accident_area_p.setOnClickListener(this);
as_accident_area_c.setOnClickListener(this);
btn_search.setOnClickListener(this);
}
//按钮的点击事件
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
//选择事故性质,弹出对话框
case R.id.as_accident_type:{
if(dg_type==null){
String[] key = this.getResources().getStringArray(R.array.accident_case_classify);
dg_type = DialogCreator.multipleChoiceDailog(oThis, key, as_accident_type);
}
dg_type.show();
break;
}
//选择事故开始时间,弹出对话框
case R.id.as_start_time:{
if(dg_startMonth==null){
dg_startMonth = new YearMonthPickerDialog(oThis,new Date().getTime());
dg_startMonth.setOnYearMonthSetListener(new OnYearMonthSetListener(){
@Override
public void OnYearMonthSet(AlertDialog arg0, long arg1, String sdate) {
as_start_time.setText(sdate);
}
});
}
dg_startMonth.show();
break;
}
//选择事故结束时间,弹出对话框
case R.id.as_end_time: {
if (dg_endMonth == null) {
dg_endMonth = new YearMonthPickerDialog(oThis,new Date().getTime());
dg_endMonth.setOnYearMonthSetListener(new OnYearMonthSetListener(){
@Override
public void OnYearMonthSet(AlertDialog arg0, long arg1, String sdate) {
as_end_time.setText(sdate);
}
});
}
dg_endMonth.show();
break;
}
//选择省份
case R.id.as_accident_area_p:{
String[] key = cityManager.getProvNameArray();
String[] value = cityManager.getProvIdArray();
dg_provinces = DialogCreator.singleChoiceDailog(oThis, key,new DialogCreator.OnSelectionChangedListener(){
@Override
public void onChanged(String key, String value) {
SelectedProvId = value;
as_accident_area_p.setText(key);
as_accident_area_p.setValue(value);
as_accident_area_c.setText("");
as_accident_area_c.setValue("");
}
}, value);
dg_provinces.show();
break;
}
//选择城市
case R.id.as_accident_area_c:{
//如果选择的省份为字符为零,这可以选择城市,否则将提示请先选择省份
if(!SelectedProvId.equals("0")){
String[] key = cityManager.getCityIdByProvIDBaArray(SelectedProvId);
String[] value = cityManager.getCityIdByProvIDBaArray(SelectedProvId);
dg_city = DialogCreator.singleChoiceDailog(oThis, key,new DialogCreator.OnSelectionChangedListener(){
@Override
public void onChanged(String key, String value) {
as_accident_area_c.setText(key);
as_accident_area_c.setValue(value);
}
}, value);
dg_city.show();
}else{
tools.showAlertTip("请先选择省份!", oThis);
}
break;
}
//查询按钮的作用,跳转界面,并把数据传递到下一个界面
case R.id.btn_search:{
//向下一个界面传送数据,
Bundle bundle = new Bundle();
bundle.putString("accident_type", as_accident_type.getValue());
bundle.putString("accident_name", aet_accident_name.getValue());
bundle.putString("chemical_name", aet_chemical_name.getValue());
bundle.putString("start_time", as_start_time.getValue());
bundle.putString("end_time", as_end_time.getValue());
bundle.putString("accident_area_p", as_accident_area_p.getValue());
bundle.putString("accident_area_c", as_accident_area_c.getValue());
//携带数据并跳转到下一个界面
tools.startActivity(oThis, AccidentCaseActivity.class, bundle);
break;
}
}
}
@ViewInject(R.id.as_accident_type)
private AvicSelect as_accident_type;
@ViewInject(R.id.aet_accident_name)
private AvicEditText aet_accident_name;
@ViewInject(R.id.aet_chemical_name)
private AvicEditText aet_chemical_name;
@ViewInject(R.id.as_start_time)
private AvicSelect as_start_time;
@ViewInject(R.id.as_end_time)
private AvicSelect as_end_time;
@ViewInject(R.id.as_accident_country)
private AvicSelect as_accident_country;
@ViewInject(R.id.as_accident_area_p)
private AvicSelect as_accident_area_p;
@ViewInject(R.id.as_accident_area_c)
private AvicSelect as_accident_area_c;
@ViewInject(R.id.btn_search)
private AvicButton btn_search;
}