package com.jqyd.newprocess; 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.Xszs; import com.jqyd.model.CustomerModule; import com.jqyd.model.GroupsModule; import com.jqyd.model.ProTypeModule; import com.jqyd.shareInterface.Optdb_interfce; import com.jqyd.son.Info; 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.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.EditText; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Toast; /** * 分组列表:商品、竞品 * @author Administrator * */ public class GoodGroupList extends Activity { private ListView listView; private EditText find; private MyAdapter adapter; private String groupNums = "";//存放一个分组编号 private ArrayList<String> groupNumList = null; private boolean flag_exit = false; private String dataType = ""; private String moduleName = "";//功能模块名称 //private boolean groupData = true;//判断当前分组下是否数据,如果没有则返回上一分组,否则返回分组初始化界面 private Optdb_interfce db; private MyApp myApp; private ArrayList<HashMap<String,String>> custList = null; private ArrayList<HashMap<String,String>> goodList = null; private ArrayList<HashMap<String,String>> compList = null; private ArrayList<Bundle> listBundle = null; private boolean isCust = false; private int actNum = 0;//判断当条数据 private boolean longPress = true;//是否长按了 @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.grouplist); listView = (ListView) this.findViewById(R.id.listView); find = (EditText) this.findViewById(R.id.find); myApp = (MyApp) this.getApplication(); //数据类型1、客户2、商品3、竞品4、员工 dataType = myApp.getDataType(); moduleName = myApp.getModuleName(); System.out.println("分组类型-------------------"+dataType); loadData(); mhSearch(); //将当前Activity放入存储器中 ArrayList<Activity> listActivity = myApp.getListActivity(); listActivity.add(GoodGroupList.this); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); System.out.println("**************************"); } /** * 加载数据 */ public void loadData(){ db = new Optdb_interfce(GoodGroupList.this); listBundle = new ArrayList<Bundle>(); System.out.println("加载数据***********************************************************************"); if(dataType.equals("2")){//商品 this.setTitle("请选择商品"); groupNumList = new ArrayList<String>(); goodList = new ArrayList<HashMap<String,String>>(); Bundle bundle = null; //groupNums = myApp.getGroupNums(); groupNums = myApp.getGoodGroupNum(); if(groupNums.equals("")){ ArrayList<Object> li = db.searchFGroups("0",3);//取出一级分组编号 for(int i=0;i<li.size();i++){ HashMap<String,String> map = new HashMap<String,String>(); GroupsModule group = (GroupsModule) li.get(i); map.put("textView1", group.getGname()); goodList.add(map); groupNumList.add(group.getGid()+""); } }else{ ArrayList<Object> li = db.searchFGroups(groupNums,3);//逐级取出分组编号及分组名称 //判断分组下是否有产品存在,如果存在,则直接在当前界面显示出来,否则不显示 ArrayList<Object> products = db.searchProsByMoreGps(groupNums); groupNums = ""; //分组循环 for(int i=0;i<li.size();i++){ HashMap<String,String> map = new HashMap<String,String>(); GroupsModule group = (GroupsModule) li.get(i); map.put("textView1", group.getGname()); goodList.add(map); groupNumList.add(group.getGid()+""); } //产品循环 for(int j=0;j<products.size();j++){ HashMap<String,String> map = new HashMap<String,String>(); bundle = new Bundle(); ProTypeModule product = (ProTypeModule) products.get(j); map.put("textView1", product.getName()); goodList.add(map); bundle.putString("spid", product.getId()); bundle.putString("spbh", product.getCode()); bundle.putString("p_name", product.getName()); bundle.putString("p_type", product.getModel()); bundle.putString("p_status", product.getStatus()); bundle.putString("p_unit", product.getUnit()); bundle.putString("p_cbj", product.getCbPrise()); bundle.putString("p_pbj", product.getPfPrise()); bundle.putString("p_lsj", product.getLsPrise()); bundle.putString("p_factory", product.getProducer()); bundle.putString("p_addr", product.getOrigin()); bundle.putString("p_bz", product.getDescription()); bundle.putString("p_sort", product.getType()); listBundle.add(bundle); flag_exit = true; } } }else if(dataType.equals("3")){//竞品 this.setTitle("请选择竞品"); groupNumList = new ArrayList<String>(); compList = new ArrayList<HashMap<String,String>>(); Bundle bundle = null; //groupNums = myApp.getGroupNums(); groupNums = myApp.getGoodGroupNum(); if(groupNums.equals("")){ ArrayList<Object> li = db.searchFGroups("0",4);//取出一级分组编号 for(int i=0;i<li.size();i++){ HashMap<String,String> map = new HashMap<String,String>(); GroupsModule group = (GroupsModule) li.get(i); map.put("textView1", group.getGname()); compList.add(map); groupNumList.add(group.getGid()+""); } }else{ ArrayList<Object> li = db.searchFGroups(groupNums,4);//逐级取出分组编号及分组名称 //判断分组下是否有产品存在,如果存在,则直接在当前界面显示出来,否则不显示 ArrayList<Object> products = db.searchProsByMoreGps(groupNums); groupNums = ""; //分组循环 for(int i=0;i<li.size();i++){ HashMap<String,String> map = new HashMap<String,String>(); GroupsModule group = (GroupsModule) li.get(i); map.put("textView1", group.getGname()); compList.add(map); groupNumList.add(group.getGid()+""); } //产品循环 for(int j=0;j<products.size();j++){ HashMap<String,String> map = new HashMap<String,String>(); bundle = new Bundle(); ProTypeModule product = (ProTypeModule) products.get(j); map.put("textView1", product.getName()); compList.add(map); bundle.putString("spid", product.getId()); bundle.putString("spbh", product.getCode()); bundle.putString("p_name", product.getName()); bundle.putString("p_type", product.getModel()); bundle.putString("p_status", product.getStatus()); bundle.putString("p_unit", product.getUnit()); bundle.putString("p_cbj", product.getCbPrise()); bundle.putString("p_pbj", product.getPfPrise()); bundle.putString("p_lsj", product.getLsPrise()); bundle.putString("p_factory", product.getProducer()); bundle.putString("p_addr", product.getOrigin()); bundle.putString("p_bz", product.getDescription()); bundle.putString("p_sort", product.getType()); listBundle.add(bundle); flag_exit = true; } } } db.close_SqlDb(); //显示数据 showList(); } /** * 当前列表显示数据 */ public void showList(){ ArrayList<HashMap<String,String>> list = null; if(dataType.equals("2")){ list = goodList; }else if(dataType.equals("3")){ list = compList; } adapter=new MyAdapter(list, this,-1); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub System.out.println("-------------------------------单击事件-----------------------------"); if(flag_exit){ Bundle bundle = listBundle.get(position); Intent intent =new Intent(); //intent.putExtras(bundle); if(dataType.equals("2") || dataType.equals("3")){ //添加商品至购物车中 ArrayList<Bundle> goodList = myApp.getGoodList(); goodList.add(bundle); myApp.setGoodList(goodList); intent.putExtra("num", goodList.size()-1); if(moduleName.equals("ddsb")){ startActivity(intent.setClass(GoodGroupList.this, GoodEdit.class)); }else if(moduleName.equals("xssb") || moduleName.equals("kcsb") || moduleName.equals("jpsb")){ startActivity(intent.setClass(GoodGroupList.this, GoodAdd.class)); } } }else{ System.out.println(flag_exit); System.out.println("***"+dataType); String groupNum = groupNumList.get(position); myApp.setGoodGroupNum(groupNum);//商品分组 startActivity(new Intent().setClass(GoodGroupList.this, GoodGroupList.class)); } //finish(); } }); } /** * 模糊搜索 */ private void mhSearch(){ find.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub listBundle = new ArrayList<Bundle>(); Bundle bundle = null; HashMap<String,String> map = null; Optdb_interfce db = new Optdb_interfce(GoodGroupList.this); if(dataType.equals("2")){ ArrayList<ProTypeModule> products = null; goodList = new ArrayList<HashMap<String,String>>(); if(find.getText().toString().equals("")){ loadData();//初始化 }else{ products = db.searchProducts(1,0,find.getText().toString()); for(int i=0;i<products.size();i++){ ProTypeModule product = (ProTypeModule) products.get(i); map = new HashMap<String, String>(); map.put("textView1", product.getName()); goodList.add(map); bundle = new Bundle(); bundle.putString("p_name", product.getName()); bundle.putString("p_type", product.getModel()); bundle.putString("p_status", product.getStatus()); bundle.putString("p_unit", product.getUnit()); bundle.putString("p_cbj", product.getCbPrise()); bundle.putString("p_pbj", product.getPfPrise()); bundle.putString("p_lsj", product.getLsPrise()); bundle.putString("p_factory", product.getProducer()); bundle.putString("p_addr", product.getOrigin()); bundle.putString("p_bz", product.getDescription()); bundle.putString("p_sort", product.getType()); listBundle.add(bundle); flag_exit = true; } showList(); } }else if(dataType.equals("3")){ compList = new ArrayList<HashMap<String,String>>(); ArrayList<ProTypeModule> products = null; goodList = new ArrayList<HashMap<String,String>>(); if(find.getText().toString().equals("")){ loadData();//初始化 }else{ products = db.searchProducts(2,0,find.getText().toString()); for(int i=0;i<products.size();i++){ ProTypeModule product = (ProTypeModule) products.get(i); map = new HashMap<String, String>(); map.put("textView1", product.getName()); goodList.add(map); bundle = new Bundle(); bundle.putString("p_name", product.getName()); bundle.putString("p_type", product.getModel()); bundle.putString("p_status", product.getStatus()); bundle.putString("p_unit", product.getUnit()); bundle.putString("p_cbj", product.getCbPrise()); bundle.putString("p_pbj", product.getPfPrise()); bundle.putString("p_lsj", product.getLsPrise()); bundle.putString("p_factory", product.getProducer()); bundle.putString("p_addr", product.getOrigin()); bundle.putString("p_bz", product.getDescription()); bundle.putString("p_sort", product.getType()); listBundle.add(bundle); flag_exit = true; } showList(); } } db.close_SqlDb(); } @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 boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode == KeyEvent.KEYCODE_BACK){ System.out.println("--------------------------------------"); myApp.setGroupNums(""); startActivity(new Intent().setClass(GroupList.this, GroupList.class)); finish(); return true; } return super.onKeyDown(keyCode, event); }*/ }