@@ -8,6 +8,7 @@ import com.example.bpa.config.ConfigName; | |||||
import com.example.bpa.db.QueryDB; | import com.example.bpa.db.QueryDB; | ||||
import com.example.bpa.db.mode.BPA_MATERIAL; | import com.example.bpa.db.mode.BPA_MATERIAL; | ||||
import com.example.bpa.db.mode.BPA_SILOS; | 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.db.mode.BPA_USER; | ||||
import com.example.bpa.helper.Json; | import com.example.bpa.helper.Json; | ||||
import com.example.bpa.helper.SdCart; | import com.example.bpa.helper.SdCart; | ||||
@@ -59,7 +60,11 @@ public class ICSApp extends Application { | |||||
BPA_SILOS silo=new BPA_SILOS(); | BPA_SILOS silo=new BPA_SILOS(); | ||||
silo.id=java.util.UUID.randomUUID().toString(); | silo.id=java.util.UUID.randomUUID().toString(); | ||||
silo.num=i+1; | silo.num=i+1; | ||||
BPA_SILOSANDMATERIAL sm = new BPA_SILOSANDMATERIAL(); | |||||
sm.silosID=silo.id; | |||||
sm.materialID= ""; | |||||
QueryDB.AddSilos(silo); | QueryDB.AddSilos(silo); | ||||
QueryDB.AddSilosAndMaterial(sm); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -90,6 +90,8 @@ public class QueryDB { | |||||
{ | { | ||||
return Delete(BPA_MATERIAL.class,data.id); | return Delete(BPA_MATERIAL.class,data.id); | ||||
} | } | ||||
/** | /** | ||||
* 获取所有物料信息 | * 获取所有物料信息 | ||||
* @return | * @return | ||||
@@ -114,7 +116,7 @@ public class QueryDB { | |||||
BPA_MATERIAL data=new BPA_MATERIAL(); | BPA_MATERIAL data=new BPA_MATERIAL(); | ||||
ArrayList<Object> obj=Get(BPA_MATERIAL.class,where,args,orderby); | ArrayList<Object> 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) | 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; | return data; | ||||
} | } | ||||
/** | /** | ||||
* 根据料仓id查询物料ID | |||||
* 根据物料id查询料仓ID | |||||
* @param id | * @param id | ||||
* @return | * @return | ||||
*/ | */ | ||||
public static ArrayList<String> GetMaterial(String id) | |||||
public static ArrayList<String> GetSilosLIst(String id) | |||||
{ | { | ||||
String orderby=Desc_Time_Up;//先按排序 创建时间倒序 | String orderby=Desc_Time_Up;//先按排序 创建时间倒序 | ||||
String where="isDelete=? and silosID=?"; | |||||
String where="isDelete=? and materialID=?"; | |||||
String[] args=new String[] { "0",id }; | String[] args=new String[] { "0",id }; | ||||
ArrayList<String> data=new ArrayList<>(); | ArrayList<String> data=new ArrayList<>(); | ||||
ArrayList<Object> obj=Get(BPA_SILOSANDMATERIAL.class,where,args,orderby); | ArrayList<Object> obj=Get(BPA_SILOSANDMATERIAL.class,where,args,orderby); | ||||
for (Object k:obj) { | for (Object k:obj) { | ||||
data.add(((BPA_SILOSANDMATERIAL)k).materialID); | |||||
data.add(((BPA_SILOSANDMATERIAL)k).silosID); | |||||
} | } | ||||
return data; | return data; | ||||
} | } | ||||
@@ -1275,6 +1277,54 @@ public class QueryDB { | |||||
db.close(); | db.close(); | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* 修改 | |||||
* @param c | |||||
* @param data | |||||
* @param where | |||||
* @return | |||||
*/ | |||||
private static boolean Update(Class c,Object data,String where) | |||||
{ | |||||
ContentValues cv = new ContentValues(); | |||||
Map<String, Object> 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 | * @param c | ||||
@@ -53,32 +53,8 @@ public class lc_item_adapter extends RecyclerView.Adapter<RecyclerView.ViewHolde | |||||
myViewHolder.silosmargin.setText(list.get(position).silosmargin); | myViewHolder.silosmargin.setText(list.get(position).silosmargin); | ||||
myViewHolder.num.setText(Integer.toString(list.get(position).num) ); | myViewHolder.num.setText(Integer.toString(list.get(position).num) ); | ||||
myViewHolder.id = list.get(position).id; | myViewHolder.id = list.get(position).id; | ||||
// myViewHolder.num.setText(list.get(position).num); | |||||
// myViewHolder.id = list.get(position).id; | |||||
// myViewHolder.spinner.setSelection(list.get(position).materiallist); | |||||
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(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<RecyclerView.ViewHolde | |||||
public String id; | public String id; | ||||
public Spinner spinner; | |||||
public String MaterialName; | |||||
// public String id; | // public String id; | ||||
public MyLCViewHolder(View view) { | public MyLCViewHolder(View view) { | ||||
super(view); | super(view); | ||||
materialName = (TextView) view.findViewById(R.id.lc_item_materialName); | materialName = (TextView) view.findViewById(R.id.lc_item_materialName); | ||||
num = (TextView) view.findViewById(R.id.lc_item_num); | num = (TextView) view.findViewById(R.id.lc_item_num); | ||||
silosmargin = (TextView) view.findViewById(R.id.lc_item_silosmargin); | silosmargin = (TextView) view.findViewById(R.id.lc_item_silosmargin); | ||||
spinner = (Spinner) view.findViewById(R.id.material_select); | |||||
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) { | |||||
} | |||||
}); | |||||
} | } | ||||
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; | |||||
} | |||||
} | } | ||||
@@ -90,12 +90,18 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList | |||||
//加载materials数据 | //加载materials数据 | ||||
if(bpa_silos.size()>0){ | if(bpa_silos.size()>0){ | ||||
for (BPA_SILOS silo : bpa_silos){ | 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); | 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(); | BPA_SILOSANDMATERIAL item = new BPA_SILOSANDMATERIAL(); | ||||
item.silosID = currentSilo.id; | item.silosID = currentSilo.id; | ||||
item.materialID = ((selectitem_adapter)viewHolder).getItem(position).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)){ //更新 | if(QueryDB.UpdateSilosAndMaterial(item)){ //更新 | ||||
currentSilo.materialName.setText(((selectitem_adapter)viewHolder).getItem(position).name); | currentSilo.materialName.setText(((selectitem_adapter)viewHolder).getItem(position).name); | ||||
} | } | ||||
} | |||||
} | } | ||||
@@ -11,14 +11,16 @@ public class lcMode extends BPA_SILOS { | |||||
//料仓余料 | //料仓余料 | ||||
public String silosmargin; | 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.materialName = materialName; | ||||
this.silosmargin = silosmargin; | this.silosmargin = silosmargin; | ||||
this.num = num; | this.num = num; | ||||
this.id = id; | this.id = id; | ||||
// this.id = "123"; | |||||
this.materialId = materialId; | |||||
} | } | ||||
@@ -6,7 +6,11 @@ | |||||
android:layout_height="match_parent" | android:layout_height="match_parent" | ||||
android:tag="系统设置" | android:tag="系统设置" | ||||
tools:context=".view.fragment.SystemSetFragment"> | tools:context=".view.fragment.SystemSetFragment"> | ||||
<TableLayout | |||||
android:layout_width="wrap_content" | |||||
android:layout_height="wrap_content"> | |||||
</TableLayout> | |||||
<Button | <Button | ||||
android:id="@+id/ConnectDevice" | android:id="@+id/ConnectDevice" | ||||
android:layout_width="wrap_content" | android:layout_width="wrap_content" | ||||
@@ -49,14 +49,6 @@ | |||||
</RelativeLayout> | </RelativeLayout> | ||||
<Spinner | |||||
android:id="@+id/material_select" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="20dp" | |||||
android:gravity="center" | |||||
android:spinnerMode="dialog" | |||||
android:visibility="gone"/> | |||||
<TextView | <TextView | ||||
android:id="@+id/lc_item_materialName" | android:id="@+id/lc_item_materialName" | ||||
android:layout_width="match_parent" | android:layout_width="match_parent" | ||||