package com.jqyd.son;
import java.util.ArrayList;
import java.util.HashMap;
import com.jqyd.adapter.MyAdapter;
import com.jqyd.app.MyApp;
import com.jqyd.app.VirtualData;
import com.jqyd.manager.R;
import com.jqyd.model.CustomerModule;
import com.jqyd.model.EmpsModule;
import com.jqyd.shareInterface.Optdb_interfce;
import com.jqyd.shareInterface.Optsharepre_interface;
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 Khlb extends Activity implements OnClickListener {
private ListView listView;
private EditText find;
private Button groupList;
private MyAdapter adapter;
private MyApp myApp;
private ArrayList<Bundle> listBundle = null;
private HashMap<String,String> map = null;
private ArrayList<HashMap<String, String>> listInfo = new ArrayList<HashMap<String, String>>();
private String moduleName = "";
private String spid = "-1";
private Optdb_interfce db ;
private Optsharepre_interface share_obj = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custlist);
listView = (ListView) this.findViewById(R.id.list);
find = (EditText) this.findViewById(R.id.find);
share_obj=new Optsharepre_interface(Khlb.this);
setSearch();
groupList = (Button) this.findViewById(R.id.groupList);
groupList.setOnClickListener(this);
myApp = (MyApp) this.getApplication();
moduleName = myApp.getModuleName();
init();
loadInfo();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == groupList){
startActivity(new Intent().setClass(this, Fzcx.class));
}
}
public void init(){
db = new Optdb_interfce(Khlb.this);
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = new ArrayList<CustomerModule>();
if(moduleName.equals("sczf") || moduleName.equals("scjc")){
customers = db.searchCustomers(1,1,"");
}else if(moduleName.equals("echf")){
customers = db.searchCustomers(2,1,"");
}else if(moduleName.equals("jh_khzf") || moduleName.equals("jh_echf")
|| moduleName.equals("jh_scjc") || moduleName.equals("jh_cxzx")){
Intent intent = this.getIntent();
ArrayList<String> custIds = intent.getStringArrayListExtra("custIds");
String cid = "";
spid = intent.getStringExtra("spid");
for(int i=0;i<custIds.size();i++){
cid+="'"+custIds.get(i)+"',";
}
if(!cid.equals("")){
cid = cid.substring(0, cid.length()-1);
}
customers = db.searchCustByIds(cid);
}
System.out.println(customers.size());
for(int i=0;i<customers.size();i++){
CustomerModule cust = (CustomerModule) customers.get(i);
map = new HashMap<String, String>();
map.put("imageId", R.drawable.icon+"");
map.put("textView1", cust.getShort_name());
map.put("textView2", cust.getAddress());
listInfo.add(map);
bundle = new Bundle();
bundle.putString("cid", cust.getCid());
bundle.putString("cname", cust.getCname());
bundle.putString("linkman", cust.getLinkman());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("address", cust.getAddress());
bundle.putString("lon", cust.getLon());
bundle.putString("lat", cust.getLat());
bundle.putString("clon", cust.getClon());
bundle.putString("clat", cust.getClat());
listBundle.add(bundle);
}
db.close_SqlDb();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
myApp.setGroupNums("");
}
/**
* 初始化,加载信息
*/
public void loadInfo() {
adapter = new MyAdapter(listInfo,Khlb.this,-3);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
Bundle bundle = listBundle.get(position);
Intent intent =new Intent();
intent.putExtras(bundle);
intent.putExtra("jhid", spid);
share_obj.editPres("istakephoto", "0");
if(moduleName.equals("sczf") || moduleName.equals("echf") ||
moduleName.equals("jh_khzf") || moduleName.equals("jh_echf")){
intent.setClass(Khlb.this, VisCust.class);
}else if(moduleName.equals("scjc") || moduleName.equals("jh_scjc")){
intent.setClass(Khlb.this, Scjc.class);
}
intent.putExtra("spid", spid);
startActivity(intent);
}
});
}
/**
* 模糊搜索
*/
private void setSearch(){
find.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
Optdb_interfce db = new Optdb_interfce(Khlb.this);
listInfo = new ArrayList<HashMap<String,String>>();
listBundle = new ArrayList<Bundle>();
Bundle bundle = null;
ArrayList<CustomerModule> customers = new ArrayList<CustomerModule>();
if(moduleName.equals("sczf") || moduleName.equals("scjc")){
customers = db.searchCustomers(1,1,find.getText().toString());
}else if(moduleName.equals("echf")){
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("imageId", R.drawable.icon+"");
map.put("textView1", cust.getShort_name());
map.put("textView2", cust.getAddress());
listInfo.add(map);
bundle = new Bundle();
bundle.putString("cid", cust.getCid());
bundle.putString("cname", cust.getCname());
bundle.putString("linkman", cust.getLinkman());
bundle.putString("link_sim", cust.getLink_sim());
bundle.putString("address", cust.getAddress());
bundle.putString("lon", cust.getLon());
bundle.putString("lat", cust.getLat());
bundle.putString("clon", cust.getClon());
bundle.putString("clat", cust.getClat());
listBundle.add(bundle);
}
db.close_SqlDb();
adapter = new MyAdapter(listInfo,Khlb.this,-3);
listView.setAdapter(adapter);
listView.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);
share_obj.editPres("istakephoto", "0");
if(moduleName.equals("sczf") || moduleName.equals("echf")){
intent.setClass(Khlb.this, VisCust.class);
}else if(moduleName.equals("scjc")){
intent.setClass(Khlb.this, Scjc.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
}
});
}
}