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.manager.R; import com.jqyd.manager.TabTitle; import com.jqyd.model.CustomerModule; import com.jqyd.model.EmpsModule; import com.jqyd.model.GroupsModule; import com.jqyd.model.ProTypeModule; 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.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.AdapterView.OnItemClickListener; import android.widget.RadioButton; public class MyOneData extends Activity implements OnClickListener{ private ListView listView; private Button sure; private Button cancel; private EditText find; private MyApp myApp; private MyAdapter adapter; private ArrayList<HashMap<String, String>> listInfo = new ArrayList<HashMap<String, String>>(); private ArrayList<String> lxrTels = new ArrayList<String>(); private ArrayList<String> lxrTelAndNames = new ArrayList<String>(); private ArrayList<String> custId = new ArrayList<String>();//临时创建 private ArrayList<String> custIdAndName = new ArrayList<String>(); //临时创建 private ArrayList<String> listGroups = new ArrayList<String>(); private String moduleName; private int num = -1; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.mylxr); listView = (ListView) this.findViewById(R.id.list); sure = (Button) this.findViewById(R.id.sure); cancel = (Button) this.findViewById(R.id.cancel); find = (EditText) this.findViewById(R.id.find); sure.setOnClickListener(this); cancel.setOnClickListener(this); myApp = (MyApp) this.getApplication(); Intent intent = this.getIntent(); moduleName = intent.getStringExtra("moduleName"); loadVirtualDatas(); setSearch(); } public void loadVirtualDatas(){ Optdb_interfce db = new Optdb_interfce(MyOneData.this); ArrayList<Object> list_obj = new ArrayList<Object>(); Optsharepre_interface share_obj = new Optsharepre_interface(MyOneData.this); HashMap<String,String> map = null; if(moduleName.equals("jhgl_emp_list")){ this.setTitle("员工列表"); //listInfo = VirtualData.getCustSonInfo(); listInfo = new ArrayList<HashMap<String, String>>(); String groupStr = db.RecursionGroup(share_obj.getDataFromPres("GLFW"), 1, 2,0); String groups[] = groupStr.split("#"); for(int i=0;i<groups.length;i++){ String gps[] = groups[i].split(","); ArrayList<Object> ls = db.searchEmpsByGps(gps[0],""); for(int k=0;k<ls.size();k++){ list_obj.add(ls.get(k)); } } for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); EmpsModule emp = (EmpsModule) list_obj.get(i); map.put("textView1", emp.getXm()); //map.put("textView2", emp.getDwhm()); listInfo.add(map); } }/*else if(moduleName.equals("jhgl_emp_group")){ //listInfo = VirtualData.getCustGroupInfo2(); //list_obj = db.searchGroups("GROUPS", share_obj.getDataFromPres("GID"),2); listInfo = new ArrayList<HashMap<String, String>>(); list_obj = db.searchGroups(share_obj.getDataFromPres("GLFW"), 2); for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); GroupsModule group = (GroupsModule) list_obj.get(i); map.put("textView1", group.getGname()); map.put("textView2", ""); map.put("gid", group.getGid()+""); listInfo.add(map); } }*/else if(moduleName.equals("ddsb_cust")){ this.setTitle("客户列表"); listInfo = new ArrayList<HashMap<String, String>>(); 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()); map.put("cid", cust.getCid()); listInfo.add(map); } }else if(moduleName.equals("ddsb_cust_group")){ listInfo = new ArrayList<HashMap<String, String>>(); list_obj = db.searchFGroups("0",1); for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); GroupsModule group = (GroupsModule) list_obj.get(i); map.put("textView1", group.getGname()); map.put("gid", group.getGid()+""); listInfo.add(map); } }else if(moduleName.equals("ddsb_good")){ this.setTitle("商品列表"); listInfo = new ArrayList<HashMap<String, String>>(); ArrayList<ProTypeModule> goods = db.searchProducts(1,1,""); for(int i=0;i<goods.size();i++){ ProTypeModule good = (ProTypeModule) goods.get(i); map = new HashMap<String, String>(); map.put("textView1", good.getName()); map.put("pid", good.getId()); listInfo.add(map); } }else if(moduleName.equals("ddsb_good_group")){ listInfo = new ArrayList<HashMap<String, String>>(); list_obj = db.searchFGroups("0",3); for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); GroupsModule group = (GroupsModule) list_obj.get(i); map.put("textView1", group.getGname()); map.put("gid", group.getGid()+""); listInfo.add(map); } } //System.out.println("-------总数据------"+listInfo.size()); db.close_SqlDb(); loadInfo(); } /** * 初始化,加载信息 */ public void loadInfo() { adapter = new MyAdapter(listInfo,MyOneData.this,8); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub LinearLayout ll = (LinearLayout)arg1;// 获得子级 RadioButton chkone = (RadioButton) ll.findViewById(R.id.select_one);// 从子级中获得控件 //选择当前单选按钮,上次选择的那个单选按钮定义为未选中 boolean flag = false; int flag_num = 0; if(num ==-1 || num == position){ num = position; flag = true;//为同一选项或初次选择 }else{ LinearLayout ll2 = (LinearLayout)listView.getChildAt(num); RadioButton chkone2 = (RadioButton) ll2.findViewById(R.id.select_one);// 从子级中获得控件 chkone2.setChecked(false); flag_num = num; num = position; flag = false;//为不同选项 } if(moduleName.equals("ddsb_good_group") || moduleName.equals("ddsb_cust_group")){//存放的是分组的id String gid= listInfo.get(position).get("gid"); if(chkone.isChecked()){ chkone.setChecked(false); listGroups.remove(gid); }else{ chkone.setChecked(true); listGroups.add(gid); } }else if(moduleName.equals("ddsb_good")){//存放的是客户的id和名称或商品的id和名称 String ids = listInfo.get(position).get("pid");//商品id String custNames = listInfo.get(position).get("textView1");//商品名称 if(chkone.isChecked()){ chkone.setChecked(false); lxrTels.remove(ids); lxrTelAndNames.remove(custNames); }else{ chkone.setChecked(true); if(!flag){//移除上一个选项 lxrTels.remove(listInfo.get(flag_num).get("pid")); lxrTelAndNames.remove(listInfo.get(flag_num).get("textView1")); } lxrTels.add(ids); lxrTelAndNames.add(custNames); } }else if(moduleName.equals("ddsb_cust")){//存放的是客户的id和名称 String ids = listInfo.get(position).get("cid");//客户id String custNames = listInfo.get(position).get("textView1");//客户名称 if(chkone.isChecked()){ chkone.setChecked(false); custId.remove(ids); custIdAndName.remove(custNames); }else{ chkone.setChecked(true); if(!flag){//移除上一个选项 custId.remove(listInfo.get(flag_num).get("cid")); custIdAndName.remove(listInfo.get(flag_num).get("textView1")); } custId.add(ids); custIdAndName.add(custNames); } }else if(moduleName.equals("jhgl_emp_list")){//存放的是员工的手机号和名称 String tel = listInfo.get(position).get("textView2"); String username = listInfo.get(position).get("textView1"); String telName = username+"<"+tel+">"; if(chkone.isChecked()){ chkone.setChecked(false); lxrTels.remove(tel); lxrTelAndNames.remove(telName); }else{ chkone.setChecked(true); if(!flag){//移除上一个选项 lxrTels.remove(listInfo.get(flag_num).get("textView2")); lxrTelAndNames.remove(listInfo.get(flag_num).get("textView1")); } lxrTels.add(tel); lxrTelAndNames.add(telName); } } } }); } /** * 模糊搜索 */ private void setSearch(){ find.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub Optdb_interfce db = new Optdb_interfce(MyOneData.this); ArrayList<Object> list_obj = new ArrayList<Object>(); Optsharepre_interface share_obj = new Optsharepre_interface(MyOneData.this); HashMap<String,String> map = null; if(moduleName.equals("jhgl_emp_list")){ listInfo = new ArrayList<HashMap<String, String>>(); String groupStr = db.RecursionGroup(share_obj.getDataFromPres("GLFW"), 1, 2,0); String groups[] = groupStr.split("#"); for(int i=0;i<groups.length;i++){ String gps[] = groups[i].split(","); ArrayList<Object> ls = db.searchEmpsByGps(gps[0],find.getText().toString()); for(int k=0;k<ls.size();k++){ list_obj.add(ls.get(k)); } } for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); EmpsModule emp = (EmpsModule) list_obj.get(i); map.put("textView1", emp.getXm()); //map.put("textView2", emp.getDwhm()); listInfo.add(map); } }else if(moduleName.equals("ddsb_cust")){ listInfo = new ArrayList<HashMap<String, String>>(); 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()); map.put("cid", cust.getCid()); listInfo.add(map); } }else if(moduleName.equals("ddsb_good")){ listInfo = new ArrayList<HashMap<String, String>>(); ArrayList<ProTypeModule> goods = db.searchProducts(1,1,find.getText().toString()); for(int i=0;i<goods.size();i++){ ProTypeModule good = (ProTypeModule) goods.get(i); map = new HashMap<String, String>(); map.put("textView1", good.getName()); map.put("pid", good.getId()); listInfo.add(map); } }else if(moduleName.equals("ddsb_good_group")){ listInfo = new ArrayList<HashMap<String, String>>(); list_obj = db.searchFGroups("0",3); for(int i=0;i<list_obj.size();i++){ map = new HashMap<String, String>(); GroupsModule group = (GroupsModule) list_obj.get(i); map.put("textView1", group.getGname()); map.put("gid", group.getGid()+""); listInfo.add(map); } } db.close_SqlDb(); loadInfo(); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } }); } /** * 捕获返回键 */ public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK){ if(moduleName.equals("ddsb_cust_group") || moduleName.equals("ddsb_cust")){ myApp.setModuleName("dd_cust"); }else if(moduleName.equals("ddsb_good_group") || moduleName.equals("ddsb_good")){ myApp.setModuleName("dd_good"); }else if(moduleName.equals("jhgl_emp_list")){ myApp.setModuleName("jh_emp"); } startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); return true; } return super.onKeyDown(keyCode, event); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(moduleName.equals("ddsb_cust_group") || moduleName.equals("ddsb_cust")){ myApp.setModuleName("dd_cust"); }else if(moduleName.equals("ddsb_good_group") || moduleName.equals("ddsb_good")){ myApp.setModuleName("dd_good"); }else if(moduleName.equals("jhgl_emp_list")){ myApp.setModuleName("jh_emp"); } if(v == sure){ //判断是否选择了某项 if((lxrTels.size()<=0 || lxrTelAndNames.size()<=0) && (custId.size()<=0 || custIdAndName.size()<=0) && listGroups.size()<=0){ System.out.println("没有做任何选择"); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); }else{ if(moduleName.equals("ddsb_good_group") || moduleName.equals("jhgl_emp_group")){ Optdb_interfce db = new Optdb_interfce(MyOneData.this); ArrayList<Object> list_obj = new ArrayList<Object>(); for(int i=0;i<listGroups.size();i++){ String groupStr = db.RecursionGroup(listGroups.get(i), 1, 3,0); String groups[] = groupStr.split("#"); for(int k=0;k<groups.length;k++){ String gps[] = groups[k].split(","); ArrayList<Object> ls = db.searchCustsByGps(gps[0],""); for(int m=0;m<ls.size();m++){ list_obj.add(ls.get(m)); } } for(int n=0;n<list_obj.size();n++){ ProTypeModule product = (ProTypeModule) list_obj.get(n); String goodName = product.getName(); String goodId = product.getId(); lxrTels.add(goodId); lxrTelAndNames.add(goodName); } } db.close_SqlDb(); myApp.setLxrTel(lxrTels); myApp.setLxrTelAndName(lxrTelAndNames); myApp.setIsInit(1); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); }else if(moduleName.equals("ddsb_cust_group")){ Optdb_interfce db = new Optdb_interfce(MyOneData.this); ArrayList<Object> list_obj = new ArrayList<Object>(); for(int i=0;i<listGroups.size();i++){ String groupStr = db.RecursionGroup(listGroups.get(i), 1, 1,0); String groups[] = groupStr.split("#"); for(int k=0;k<groups.length;k++){ String gps[] = groups[k].split(","); ArrayList<Object> ls = db.searchCustsByGps(gps[0],""); for(int m=0;m<ls.size();m++){ list_obj.add(ls.get(m)); } } for(int n=0;n<list_obj.size();n++){ CustomerModule cust = (CustomerModule) list_obj.get(n); String custName = cust.getShort_name(); String id = cust.getCid(); custId.add(id); custIdAndName.add(custName); } } db.close_SqlDb(); myApp.setCustId(custId); myApp.setCustIdAndName(custIdAndName); myApp.setIsInit(1); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); }else if(moduleName.equals("ddsb_good")){ myApp.setLxrTel(lxrTels); myApp.setLxrTelAndName(lxrTelAndNames); myApp.setIsInit(1); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); }else if(moduleName.equals("ddsb_cust")){ myApp.setCustId(custId); myApp.setCustIdAndName(custIdAndName); myApp.setIsInit(1); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); }else if(moduleName.equals("jhgl_emp_list")){ myApp.setLxrTel(lxrTels); myApp.setLxrTelAndName(lxrTelAndNames); startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); } } }else if(v == cancel){ startActivity(new Intent().setClass(MyOneData.this, TabTitle.class)); finish(); } } }