diff --git a/app/src/main/java/com/example/bpa/app/ICSApp.java b/app/src/main/java/com/example/bpa/app/ICSApp.java index 3c24abc..31391cc 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -8,6 +8,7 @@ import com.example.bpa.config.ConfigName; import com.example.bpa.db.QueryDB; import com.example.bpa.db.mode.BPA_MATERIAL; import com.example.bpa.db.mode.BPA_SILOS; +import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; import com.example.bpa.db.mode.BPA_USER; import com.example.bpa.helper.Json; import com.example.bpa.helper.SdCart; @@ -59,7 +60,11 @@ public class ICSApp extends Application { BPA_SILOS silo=new BPA_SILOS(); silo.id=java.util.UUID.randomUUID().toString(); silo.num=i+1; + BPA_SILOSANDMATERIAL sm = new BPA_SILOSANDMATERIAL(); + sm.silosID=silo.id; + sm.materialID= ""; QueryDB.AddSilos(silo); + QueryDB.AddSilosAndMaterial(sm); } } } diff --git a/app/src/main/java/com/example/bpa/db/QueryDB.java b/app/src/main/java/com/example/bpa/db/QueryDB.java index ca33805..b5e79b4 100644 --- a/app/src/main/java/com/example/bpa/db/QueryDB.java +++ b/app/src/main/java/com/example/bpa/db/QueryDB.java @@ -90,6 +90,8 @@ public class QueryDB { { return Delete(BPA_MATERIAL.class,data.id); } + + /** * 获取所有物料信息 * @return @@ -114,7 +116,7 @@ public class QueryDB { BPA_MATERIAL data=new BPA_MATERIAL(); ArrayList obj=Get(BPA_MATERIAL.class,where,args,orderby); - return (BPA_MATERIAL)obj.get(0); + return obj.size()>0? (BPA_MATERIAL)obj.get(0):null; } @@ -316,7 +318,7 @@ public class QueryDB { */ public static boolean UpdateSilosAndMaterial(BPA_SILOSANDMATERIAL data) { - return Update(BPA_SILOSANDMATERIAL.class,data); + return Update(BPA_SILOSANDMATERIAL.class,data,"silosID"); } /** * 删除料仓物料关联 @@ -362,19 +364,19 @@ public class QueryDB { return data; } /** - * 根据料仓id查询物料ID + * 根据物料id查询料仓ID * @param id * @return */ - public static ArrayList GetMaterial(String id) + public static ArrayList GetSilosLIst(String id) { String orderby=Desc_Time_Up;//先按排序 创建时间倒序 - String where="isDelete=? and silosID=?"; + String where="isDelete=? and materialID=?"; String[] args=new String[] { "0",id }; ArrayList data=new ArrayList<>(); ArrayList obj=Get(BPA_SILOSANDMATERIAL.class,where,args,orderby); for (Object k:obj) { - data.add(((BPA_SILOSANDMATERIAL)k).materialID); + data.add(((BPA_SILOSANDMATERIAL)k).silosID); } return data; } @@ -1275,6 +1277,54 @@ public class QueryDB { db.close(); return true; } + /** + * 修改 + * @param c + * @param data + * @param where + * @return + */ + private static boolean Update(Class c,Object data,String where) + { + ContentValues cv = new ContentValues(); + Map map= Tools.getObjValue(data); + String id=map.get(where).toString(); + if (id.isEmpty()) + return false; + for (String key : map.keySet()) { + if(!key.equals(where)) + { + Object value = map.get(key); + if(value instanceof String) + { + cv.put(key, (String) value); + }else if (value instanceof Integer) + { + cv.put(key, ((Integer) value).intValue()); + }else if (value instanceof Double) + { + cv.put(key, ((Double) value).doubleValue()); + }else if (value instanceof Float) + { + cv.put(key, ((Float) value).floatValue()); + }else if (value instanceof Long) + { + cv.put(key, ((Long) value).longValue()); + }else if (value instanceof Boolean) + { + cv.put(key, ((Boolean) value).booleanValue()); + } + } +// else if (value instanceof Date) +// { +// cv.put(key, (Date) value); +// } + } + SQLiteDatabase db = helper.getWritableDatabase(); + int i = db.update(c.getSimpleName(),cv,where+" = ?", new String[] { id }); + db.close(); + return true; + } /** * 删除 * @param c diff --git a/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java index 076c837..643fead 100644 --- a/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java +++ b/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java @@ -53,32 +53,8 @@ public class lc_item_adapter extends RecyclerView.Adapter adapter = new ArrayAdapter(mLayoutInflater.getContext(), android.R.layout.simple_spinner_item, list.get(position).materiallist); - //设置下拉列表的风格 - //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - // myViewHolder.spinner.setAdapter(adapter); - -// myViewHolder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ -// -// @Override -// public void onItemSelected(AdapterView parent, View view, int position, long id) { -// Log.d("onItemSelected","true"); -// String selectedOption = (String) parent.getItemAtPosition(position); // 获取用户选择的选项 -// myViewHolder.materialName.setText(selectedOption); -// } -// -// @Override -// public void onNothingSelected(AdapterView parent) { -// -// } -// -// -// -// -// }); + myViewHolder.MaterialName = list.get(position).materialName; + } } @@ -100,59 +76,22 @@ public class lc_item_adapter extends RecyclerView.Adapter parent, View view, int position, long id) { - Log.d("onItemSelected","true"); - String selectedOption = (String) parent.getItemAtPosition(position); // 获取用户选择的选项 - materialName.setText(selectedOption); - } - - @Override - public void onNothingSelected(AdapterView parent) { - } - }); - - - } - public boolean onspinnerClick(){ - spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){ - - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - Log.d("onItemSelected","true"); - String selectedOption = (String) parent.getItemAtPosition(position); // 获取用户选择的选项 - materialName.setText(selectedOption); - } - @Override - public void onNothingSelected(AdapterView parent) { - - } - - - - - }); - - return false; - } } diff --git a/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java b/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java index c79b9cf..8bd720e 100644 --- a/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java @@ -90,12 +90,18 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList //加载materials数据 if(bpa_silos.size()>0){ for (BPA_SILOS silo : bpa_silos){ - String materialid = QueryDB.GetMaterialList(silo.id).size()==0? "-1" : QueryDB.GetMaterialList(silo.id).get(0); - String m = "未设置"; - if (materialid != "-1"){ - m = (QueryDB.GetMaterialbyid(materialid) == null) ? "未设置" : QueryDB.GetMaterialbyid(materialid).name; + String resmaterialid = QueryDB.GetMaterialList(silo.id).size()==0? "-1" : QueryDB.GetMaterialList(silo.id).get(0); + String material_name = "未设置"; + String material_id = ""; + if (resmaterialid != "-1"){ + BPA_MATERIAL res= QueryDB.GetMaterialbyid(resmaterialid); + if (res!=null) { + material_name = res.name; + material_id = res.id; + } + } - datas.add(new lcMode(silo.id,silo.num,m,"")); + datas.add(new lcMode(silo.id,silo.num,material_name,"",material_id)); } } lc_item_adapter adapter = new lc_item_adapter(this, datas); @@ -154,17 +160,10 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList BPA_SILOSANDMATERIAL item = new BPA_SILOSANDMATERIAL(); item.silosID = currentSilo.id; item.materialID = ((selectitem_adapter)viewHolder).getItem(position).id;; - if ((currentSilo.materialName.getText() == "未设置")) { - if(QueryDB.AddSilosAndMaterial(item)){ //新增 - currentSilo.materialName.setText(((selectitem_adapter)viewHolder).getItem(position).name); - } - }else{ + if(QueryDB.UpdateSilosAndMaterial(item)){ //更新 currentSilo.materialName.setText(((selectitem_adapter)viewHolder).getItem(position).name); } - - } - } diff --git a/app/src/main/java/com/example/bpa/view/mode/lcMode.java b/app/src/main/java/com/example/bpa/view/mode/lcMode.java index f84e91c..b0dcd3f 100644 --- a/app/src/main/java/com/example/bpa/view/mode/lcMode.java +++ b/app/src/main/java/com/example/bpa/view/mode/lcMode.java @@ -11,14 +11,16 @@ public class lcMode extends BPA_SILOS { //料仓余料 public String silosmargin; + public String materialId; - public lcMode(String id, int num,String materialName, String silosmargin) { + + public lcMode(String id, int num,String materialName, String silosmargin,String materialId) { this.materialName = materialName; this.silosmargin = silosmargin; this.num = num; this.id = id; -// this.id = "123"; + this.materialId = materialId; } diff --git a/app/src/main/res/layout/from/layout/fragment_system_set.xml b/app/src/main/res/layout/from/layout/fragment_system_set.xml index 1dbb56c..35b0458 100644 --- a/app/src/main/res/layout/from/layout/fragment_system_set.xml +++ b/app/src/main/res/layout/from/layout/fragment_system_set.xml @@ -6,7 +6,11 @@ android:layout_height="match_parent" android:tag="系统设置" tools:context=".view.fragment.SystemSetFragment"> + +