diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ee305eb..707bd19 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ tools:targetApi="31"> materials= QueryDB.GetMaterialALL(); + + BPA_SILOSANDMATERIAL al=new BPA_SILOSANDMATERIAL(); + al.silosID="1231333"; + al.materialID=materials.get(0).id; + QueryDB.AddSilosAndMaterial(al); + } /** * 测试数据库 新增 修改 删除 */ 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 4c44a8d..cea56ef 100644 --- a/app/src/main/java/com/example/bpa/db/QueryDB.java +++ b/app/src/main/java/com/example/bpa/db/QueryDB.java @@ -23,6 +23,7 @@ import com.example.bpa.db.mode.BPA_SYSTEMSET; import com.example.bpa.db.mode.BPA_USER; import com.example.bpa.db.mode.ModeBase; import com.example.bpa.helper.Tools; +import com.example.bpa.view.mode.ResSilosMode; import java.lang.reflect.Field; import java.text.SimpleDateFormat; @@ -122,6 +123,26 @@ public class QueryDB { } return data.size()>0; } + + /** + * 物料ID查询物料信息 + * @param id + * @return + */ + public static BPA_MATERIAL GetMaterialID(String id) + { + BPA_MATERIAL bpa_material=null; + boolean isSucess=false; + String orderby=Desc_Time_Up;//出料顺序 + String where="isDelete=? and id=?"; + String[] args=new String[] { "0" ,id}; + ArrayList data=new ArrayList<>(); + ArrayList obj=Get(BPA_MATERIAL.class,where,args,orderby); + for (Object k:obj) { + bpa_material=(BPA_MATERIAL)k; + } + return bpa_material; + } //endregion //region BPA_SILOS 料仓管理表 @@ -170,6 +191,98 @@ public class QueryDB { } return data; } + /** + * 获取料仓数据 + * @return + */ + public static ArrayList GetSilos() + { + ArrayList data=new ArrayList<>(); + //1.获取料仓数据 + ArrayList silos=GetSilosALL(); + //2.获取物料 + ArrayList materials= GetMaterialALL(); + //3.获取返回数据 + for (BPA_SILOS k:silos) { + ResSilosMode par=new ResSilosMode(); + par.id=k.id; + par.createTime=k.createTime; + par.updateTime=k.updateTime; + par.deleteTime=k.deleteTime; + par.deviceID=k.deviceID; + par.userID=k.userID; + par.isDelete=k.isDelete; + par.exp=k.exp; + + par.num=k.num; + par.name=k.name; + par.warningValue=k.warningValue; + par.thrsoleValue=k.thrsoleValue; + par.plcValue=k.plcValue; + par.bValue=k.bValue; + par.jValue=k.jValue; + par.status=k.status; + par.Sort=k.Sort; + + ArrayList gx= GetMaterialList(k.id); + if(!gx.isEmpty() && gx.size()>0) + { + String wlid= gx.get(0); + if(!wlid.isEmpty()) + { + BPA_MATERIAL wl=null; + for (BPA_MATERIAL m:materials) { + if(m.id.equals(wlid)) + { + wl=m; + break; + } + } + if(wl!=null) + { + par.materialID=wl.id; + par.materialimgUrl=wl.imgUrl; + par.materialname=wl.name; + } + } + } + + par.dvalue=0; + data.add(par); + } + return data; + } + /** + * 根据ID查询料仓管理 + * @return + */ + public static BPA_SILOS GetSilosID(String id) + { + BPA_SILOS data=null; + String orderby=Desc_Sort_Up+','+Desc_Time_Up;//先按排序 创建时间倒序 + String where="isDelete=? and id=?"; + String[] args=new String[] { "0",id }; + ArrayList obj=Get(BPA_SILOS.class,where,args,orderby); + for (Object k:obj) { + data=(BPA_SILOS)k; + } + return data; + } + + /** + * 修改校准值 + * @param id + * @param data + */ + public static void UpdateJYZ(String id, int data) + { + BPA_SILOS silos= GetSilosID(id); + if(silos!=null) + { + silos.jValue=data; + Update(BPA_SILOS.class,silos); + } + } //endregion //region BPA_SILOSANDMATERIAL 料仓物料关联表 @@ -993,25 +1106,28 @@ public class QueryDB { if (id.isEmpty()) return false; for (String key : map.keySet()) { - Object value = map.get(key); - if(value instanceof String) + if(!key.equals("id")) { - 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()); + 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) // { @@ -1019,7 +1135,6 @@ public class QueryDB { // } } SQLiteDatabase db = helper.getWritableDatabase(); - long insert = db.insert(c.getSimpleName(), null, cv); db.update(c.getSimpleName(),cv,"id = ?", new String[] { id }); db.close(); return true; diff --git a/app/src/main/java/com/example/bpa/view/adapter/lsjy_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/lsjy_adapter.java new file mode 100644 index 0000000..2ee855a --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/adapter/lsjy_adapter.java @@ -0,0 +1,69 @@ +package com.example.bpa.view.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.bpa.R; +import com.example.bpa.db.mode.BPA_MATERIAL; +import com.example.bpa.helper.T; +import com.example.bpa.view.inteface.MyClickListener; +import com.example.bpa.view.mode.ResSilosMode; + +import java.util.List; + +/** + * 流速校验DataTab + */ +public class lsjy_adapter extends ArrayAdapter { + /** + * 内部点击事件 + */ + private MyClickListener mListener; + private List datas; + public lsjy_adapter(@NonNull Context context, int resource, @NonNull List objects, MyClickListener listener) { + super(context, resource, objects); + mListener = listener; + datas=objects; + } + //每个子项被滚动到屏幕内的时候会被调用 + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + ResSilosMode resSilosMode = (ResSilosMode) getItem(position);//得到当前项选中item实例 + //为每一个子项加载设定的布局 + View view = LayoutInflater.from(getContext()).inflate(R.layout.lsjy_item, parent, false); + //分别获取 image view 和 textview 的实例 + TextView name = view.findViewById(R.id.name); + TextView lc_num = view.findViewById(R.id.lc_num); + TextView lc_bzls = view.findViewById(R.id.lc_bzls); + TextView lc_xyls = view.findViewById(R.id.lc_xyls); + Button button = view.findViewById(R.id.button_item); + // 设置要显示的图片和文字 + name.setText(resSilosMode.materialname); + lc_num.setText(""+resSilosMode.num); + lc_bzls.setText(""+resSilosMode.bValue); + lc_xyls.setText(""+resSilosMode.jValue); + + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try + { + mListener.clickListener(view,resSilosMode); + } catch (Exception e) + { + T.show(view.getContext(),"校验流速出错:"+e.getMessage()); + } + } + }); + return view; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/from/dzcjy_activity.java b/app/src/main/java/com/example/bpa/view/from/dzcjy_activity.java index eefcf4e..579a718 100644 --- a/app/src/main/java/com/example/bpa/view/from/dzcjy_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/dzcjy_activity.java @@ -1,13 +1,24 @@ package com.example.bpa.view.from; import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.example.bpa.R; +import com.example.bpa.helper.T; +import com.example.bpa.view.control.ItemClickListener; +import com.example.bpa.view.control.MainMeunAdapter; +import com.example.bpa.view.control.MyLayoutManager; +import com.example.bpa.view.mode.MenuMode; + +import java.util.ArrayList; +import java.util.List; + /** * 电子秤校验 */ @@ -21,6 +32,9 @@ public class dzcjy_activity extends AppCompatActivity implements View.OnClickLis * 标题设置 */ TextView gongneng_title; + RecyclerView recyclerView; + MainMeunAdapter adapter; + List menuModes = new ArrayList<>(); //endregion //region 私有函数 @@ -45,7 +59,46 @@ public class dzcjy_activity extends AppCompatActivity implements View.OnClickLis String msg=getIntent().getStringExtra("data"); gongneng_title.setText(msg); - ((TextView)this.findViewById(R.id.test_view)).setText(msg); + recyclerView = this.findViewById(R.id.recycler_view); + + menuModes.clear(); + menuModes.add(new MenuMode("设置最大称重",R.mipmap.zuidachengzhong)); + menuModes.add(new MenuMode("设置分度参数",R.mipmap.shezhifenducanshu)); + menuModes.add(new MenuMode("归零",R.mipmap.guiling)); + menuModes.add(new MenuMode("设置标准重量",R.mipmap.biaozhunzhongliang)); + menuModes.add(new MenuMode("称重校验",R.mipmap.chengzhongjiaoyan)); + + MyLayoutManager layout = new MyLayoutManager(); + //必须,防止recyclerview高度为wrap时测量item高度0 + layout.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layout); + adapter = new MainMeunAdapter(this, menuModes); + recyclerView.setAdapter(adapter); + recyclerView.addOnItemTouchListener(new ItemClickListener(recyclerView, new ItemClickListener.OnItemClickListener() { + @Override + public void onItemClick(View view, int position) { + TextView textView = (TextView) view.findViewById(R.id.meun_textview); + T.show(view.getContext(),"打开窗体:"+ textView.getText().toString()); + switch (textView.getText().toString()) + { + case "设置最大称重": + break; + case "设置分度参数": + break; + case "归零": + break; + case "设置标准重量": + break; + case "称重校验": + default: + break; + } + } + @Override + public void onItemLongClick(View view, int position) { + + } + })); } /** diff --git a/app/src/main/java/com/example/bpa/view/from/lsjy_activity.java b/app/src/main/java/com/example/bpa/view/from/lsjy_activity.java index 3c39472..375f0d5 100644 --- a/app/src/main/java/com/example/bpa/view/from/lsjy_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/lsjy_activity.java @@ -4,14 +4,25 @@ import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import com.example.bpa.R; +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.helper.T; +import com.example.bpa.view.adapter.lsjy_adapter; +import com.example.bpa.view.adapter.wl_adapter; +import com.example.bpa.view.inteface.MyClickListener; +import com.example.bpa.view.mode.ResSilosMode; + +import java.util.ArrayList; /** * 流速校验 */ -public class lsjy_activity extends AppCompatActivity implements View.OnClickListener{ +public class lsjy_activity extends AppCompatActivity implements View.OnClickListener, MyClickListener { //region 变量 /** * 返回按钮 @@ -21,6 +32,14 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList * 标题设置 */ TextView gongneng_title; + /** + * 表格显示 + */ + ListView datatab; + /** + * 料仓数据 + */ + ArrayList resSilosModes=new ArrayList<>(); //endregion //region 私有函数 @@ -41,11 +60,11 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList private void Init(){ gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui); gongneng_title = this.findViewById(R.id.gongneng_title); + datatab= this.findViewById(R.id.datatab); //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 String msg=getIntent().getStringExtra("data"); gongneng_title.setText(msg); - - ((TextView)this.findViewById(R.id.test_view)).setText(msg); + Initdata(); } /** @@ -54,6 +73,20 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList private void initEvents() { gongneng_fanhui.setOnClickListener(this); } + + /** + * 初始化数据加载 + */ + public void Initdata() + { + try{ + resSilosModes= QueryDB.GetSilos(); + lsjy_adapter adapter = new lsjy_adapter(lsjy_activity.this, R.layout.lsjy_item, resSilosModes,this); + datatab.setAdapter(adapter); + }catch(Exception e){ + + } + } //endregion //region 点击事件 @@ -70,5 +103,21 @@ public class lsjy_activity extends AppCompatActivity implements View.OnClickList break; } } + int k=404; + /** + * 接口方法,响应ListView按钮点击事件 + */ + @Override + public void clickListener(View v,Object data) { + switch (v.getId()) + { + case R.id.button_item://校验 + k=k+1; + T.show(this,((ResSilosMode)data).id); + QueryDB.UpdateJYZ(((ResSilosMode)data).id,k); + Initdata(); + break; + } + } //endregion } \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java b/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java index d89803b..e7e3d9f 100644 --- a/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java @@ -35,8 +35,10 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList * 标题设置 */ TextView gongneng_title; - //edittext buttonadd ListView datatab + //endregion + + //region 操作变量 /** * 输入框 */ @@ -53,8 +55,6 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList * 物料数据 */ ArrayList bpa_materials=new ArrayList<>(); - //region 操作变量 - //endregion //region 私有函数 diff --git a/app/src/main/java/com/example/bpa/view/mode/ResSilosMode.java b/app/src/main/java/com/example/bpa/view/mode/ResSilosMode.java new file mode 100644 index 0000000..c9dc1db --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/mode/ResSilosMode.java @@ -0,0 +1,14 @@ +package com.example.bpa.view.mode; + +import com.example.bpa.db.mode.BPA_SILOS; + +public class ResSilosMode extends BPA_SILOS { + //物料ID + public String materialID; + //物料图片路径 + public String materialimgUrl; + //物料名称 + public String materialname; + //当前余量 + public int dvalue; +} diff --git a/app/src/main/res/layout/datatab/layout/lsjy_item.xml b/app/src/main/res/layout/datatab/layout/lsjy_item.xml new file mode 100644 index 0000000..ee594bf --- /dev/null +++ b/app/src/main/res/layout/datatab/layout/lsjy_item.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + +