package com.jqyd.son;
import java.util.ArrayList;
import java.util.HashMap;
import com.jqyd.adapter.LxrAdapter;
import com.jqyd.adapter.MyAdapter;
import com.jqyd.app.MyApp;
import com.jqyd.manager.R;
import com.jqyd.model.CustomerModule;
import com.jqyd.model.EmpsModule;
import com.jqyd.shareInterface.Optdb_interfce;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class TxlList extends Activity implements OnClickListener{
private ListView list;
private EditText find;
private Button groupList;
private MyAdapter adapter;
private ArrayList<HashMap<String,String>> LxrList = null;
private ArrayList<Bundle> listBundle = null;
private HashMap<String,String> map = null;
private String sort ;
private MyApp myApp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custlist);
list = (ListView) this.findViewById(R.id.list);
find = (EditText) this.findViewById(R.id.find);
groupList = (Button) this.findViewById(R.id.groupList);
groupList.setOnClickListener(this);
setSearch();
myApp = (MyApp) this.getApplication();
Intent intent = this.getIntent();
sort = intent.getStringExtra("sort");
if(sort.equals("qzkh")){//潜在客户不存在分组
groupList.setVisibility(Button.GONE);
}else{
groupList.setVisibility(Button.VISIBLE);
}
}
public void init(){
LxrList = new ArrayList<HashMap<String,String>>();
Optdb_interfce db = new Optdb_interfce(TxlList.this);
if(sort.equals("yg")){
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
myApp.setModuleName("ygtxl");
ArrayList<Object> emps = db.searchEmps("EMPS", "");
for(int i=0;i<emps.size();i++){
EmpsModule emp = (EmpsModule) emps.get(i);
map = new HashMap<String, String>();
map.put("textView1", emp.getXm());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("addr", emp.getAddr());
bundle.putString("department", emp.getDepartment());
bundle.putString("dwhm", emp.getDwhm());
bundle.putString("honor", emp.getHonor());
bundle.putString("email", emp.getEmail());
bundle.putString("xm", emp.getXm());
listBundle.add(bundle);
}
}else if(sort.equals("kh")){
myApp.setModuleName("khtxl");
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = db.searchCustomers(1,1,"");
for(int i=0;i<customers.size();i++){
CustomerModule cust = (CustomerModule) customers.get(i);
map = new HashMap<String, String>();
map.put("textView1", cust.getShort_name());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("cname", cust.getCname());
bundle.putString("address", cust.getAddress());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("linkman", cust.getLinkman());
listBundle.add(bundle);
}
}else if(sort.equals("qzkh")){
myApp.setModuleName("qzkhtxl");
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = db.searchCustomers(2,1,"");
for(int i=0;i<customers.size();i++){
CustomerModule cust = (CustomerModule) customers.get(i);
map = new HashMap<String, String>();
map.put("textView1", cust.getShort_name());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("cname", cust.getCname());
bundle.putString("address", cust.getAddress());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("linkman", cust.getLinkman());
listBundle.add(bundle);
}
}
adapter=new MyAdapter(LxrList, this,-1);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Bundle bundle = listBundle.get(position);
Intent intent =new Intent();
intent.putExtras(bundle);
intent.setClass(TxlList.this, LxrInfo.class);
startActivity(intent);
}
});
db.close_SqlDb();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
myApp.setGroupNums("");
init();
}
/**
* 模糊搜索
*/
private void setSearch(){
find.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
System.out.println("--------sort---------"+sort);
Optdb_interfce db = new Optdb_interfce(TxlList.this);
LxrList = new ArrayList<HashMap<String,String>>();
if(sort.equals("yg")){
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<Object> emps = db.searchEmpsBySelect(find.getText().toString());
for(int i=0;i<emps.size();i++){
EmpsModule emp = (EmpsModule) emps.get(i);
map = new HashMap<String, String>();
map.put("textView1", emp.getXm());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("addr", emp.getAddr());
bundle.putString("department", emp.getDepartment());
bundle.putString("dwhm", emp.getDwhm());
bundle.putString("honor", emp.getHonor());
bundle.putString("email", emp.getEmail());
bundle.putString("xm", emp.getXm());
listBundle.add(bundle);
}
}else if(sort.equals("kh")){
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = db.searchCustomers(1,1,find.getText().toString());
for(int i=0;i<customers.size();i++){
CustomerModule cust = (CustomerModule) customers.get(i);
map = new HashMap<String, String>();
map.put("textView1", cust.getShort_name());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("cname", cust.getCname());
bundle.putString("address", cust.getAddress());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("linkman", cust.getLinkman());
listBundle.add(bundle);
}
}else if(sort.equals("qzkh")){
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = db.searchCustomers(2,1,find.getText().toString());
for(int i=0;i<customers.size();i++){
CustomerModule cust = (CustomerModule) customers.get(i);
map = new HashMap<String, String>();
map.put("textView1", cust.getShort_name());
LxrList.add(map);
bundle = new Bundle();
bundle.putString("cname", cust.getCname());
bundle.putString("address", cust.getAddress());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("linkman", cust.getLinkman());
listBundle.add(bundle);
}
}
db.close_SqlDb();
adapter=new MyAdapter(LxrList, TxlList.this,-1);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Bundle bundle = listBundle.get(position);
Intent intent =new Intent();
intent.putExtras(bundle);
intent.setClass(TxlList.this, LxrInfo.class);
startActivity(intent);
}
});
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == groupList){
startActivity(new Intent().setClass(this, Fzcx.class));
}
}
}