From f38f086c1ba1257e8353a803ea82d11c23c05d81 Mon Sep 17 00:00:00 2001 From: NXX <447201003@qq> Date: Sat, 22 Apr 2023 16:23:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=99=E4=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/compiler.xml | 2 +- .idea/deploymentTargetDropDown.xml | 17 -- .idea/misc.xml | 10 +- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 3 +- .../main/java/com/example/bpa/app/ICSApp.java | 11 ++ .../main/java/com/example/bpa/db/QueryDB.java | 36 +++- .../com/example/bpa/db/file/DBHelper.java | 88 ++++++++-- .../java/com/example/bpa/db/file/Table.java | 37 +++- .../com/example/bpa/db/mode/BPA_MATERIAL.java | 4 + .../bpa/view/adapter/lc_item_adapter.java | 159 ++++++++++++++++++ .../bpa/view/adapter/selectitem_adapter.java | 41 +++++ .../example/bpa/view/dialog/lc_dialog.java | 130 ++++++++++++++ .../example/bpa/view/from/lcsz_activity.java | 135 +++++++++++++-- .../com/example/bpa/view/mode/lcMode.java | 25 +++ app/src/main/res/drawable/lcbg_border.xml | 11 ++ .../res/layout/Dialog/layout/lc_dialog.xml | 48 ++++++ .../layout/datatab/layout/selectitem_item.xml | 40 +++++ .../res/layout/datatab/values/strings.xml | 4 + .../res/layout/from/layout/activity_lcsz.xml | 39 ++++- .../main/res/layout/item/layout/lc_item.xml | 67 ++++++++ app/src/main/res/mipmap-xhdpi/dglc.png | Bin 0 -> 3743 bytes app/src/main/res/values/styles.xml | 11 ++ 23 files changed, 856 insertions(+), 63 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java create mode 100644 app/src/main/java/com/example/bpa/view/adapter/selectitem_adapter.java create mode 100644 app/src/main/java/com/example/bpa/view/dialog/lc_dialog.java create mode 100644 app/src/main/java/com/example/bpa/view/mode/lcMode.java create mode 100644 app/src/main/res/drawable/lcbg_border.xml create mode 100644 app/src/main/res/layout/Dialog/layout/lc_dialog.xml create mode 100644 app/src/main/res/layout/datatab/layout/selectitem_item.xml create mode 100644 app/src/main/res/layout/datatab/values/strings.xml create mode 100644 app/src/main/res/layout/item/layout/lc_item.xml create mode 100644 app/src/main/res/mipmap-xhdpi/dglc.png diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fb7f4a8..b589d56 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 46fc865..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index bdd9278..d86e80d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,10 +1,16 @@ - - + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index fc50c19..8d29209 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,7 @@ android { 'src/main/res/layout/from', 'src/main/res/layout/item', 'src/main/res/layout/toast', + 'src/main/res/layout/Dialog', 'src/main/res/layout', 'src/main/res' ] diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ee305eb..e4ceec7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,8 @@ tools:targetApi="31"> + android:exported="false" + android:configChanges="keyboard|keyboardHidden"/> 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 eb488a2..3c24abc 100644 --- a/app/src/main/java/com/example/bpa/app/ICSApp.java +++ b/app/src/main/java/com/example/bpa/app/ICSApp.java @@ -7,6 +7,7 @@ import android.util.Log; 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_USER; import com.example.bpa.helper.Json; import com.example.bpa.helper.SdCart; @@ -51,6 +52,16 @@ public class ICSApp extends Application { user.exp="管理员"; QueryDB.AddUser(user); } + + if(QueryDB.GetSilosALL().size() == 0) + { + for(int i=0;i<10;i++){ + BPA_SILOS silo=new BPA_SILOS(); + silo.id=java.util.UUID.randomUUID().toString(); + silo.num=i+1; + QueryDB.AddSilos(silo); + } + } } /** 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..d75a7a0 100644 --- a/app/src/main/java/com/example/bpa/db/QueryDB.java +++ b/app/src/main/java/com/example/bpa/db/QueryDB.java @@ -3,6 +3,7 @@ package com.example.bpa.db; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.util.Log; import com.example.bpa.config.ConfigName; import com.example.bpa.db.file.DBHelper; @@ -104,6 +105,17 @@ public class QueryDB { return data; } + public static BPA_MATERIAL GetMaterialbyid(String id){ + String orderby=Desc_Time_Up;//时间 + String where="isDelete=? and id=?"; + String[] args=new String[] { "0" ,id}; + BPA_MATERIAL data=new BPA_MATERIAL(); + ArrayList obj=Get(BPA_MATERIAL.class,where,args,orderby); + + return (BPA_MATERIAL)obj.get(0); + } + + /** * 判断物料数据是否存在 * @param name @@ -188,9 +200,9 @@ public class QueryDB { * add fengyoufu 20230413 * @param data */ - public static void UpdateSilosAndMaterial(BPA_SILOSANDMATERIAL data) + public static boolean UpdateSilosAndMaterial(BPA_SILOSANDMATERIAL data) { - Update(BPA_SILOSANDMATERIAL.class,data); + return Update(BPA_SILOSANDMATERIAL.class,data); } /** * 删除料仓物料关联 @@ -219,7 +231,7 @@ public class QueryDB { return data; } /** - * 根据料仓id查询物料 + * 根据料仓id查询物料ID * @param id * @return */ @@ -235,6 +247,23 @@ public class QueryDB { } return data; } + /** + * 根据料仓id查询物料ID + * @param id + * @return + */ + public static ArrayList GetMaterial(String id) + { + String orderby=Desc_Time_Up;//先按排序 创建时间倒序 + String where="isDelete=? and silosID=?"; + 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); + } + return data; + } //endregion //region BPA_GOODS 商品表 @@ -1037,6 +1066,7 @@ public class QueryDB { SQLiteDatabase db = helper.getWritableDatabase(); long delete=db.delete(c.getSimpleName(), "id = ?", new String[] { id }); + Log.d("Delete","行数:"+delete); db.close(); return delete>0; } diff --git a/app/src/main/java/com/example/bpa/db/file/DBHelper.java b/app/src/main/java/com/example/bpa/db/file/DBHelper.java index ee34974..8f88a33 100644 --- a/app/src/main/java/com/example/bpa/db/file/DBHelper.java +++ b/app/src/main/java/com/example/bpa/db/file/DBHelper.java @@ -20,6 +20,8 @@ import com.example.bpa.db.mode.BPA_SYSTEMSET; import com.example.bpa.db.mode.BPA_USER; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; /** * 数据库帮助类 @@ -67,7 +69,7 @@ public class DBHelper extends SQLiteOpenHelper { private void createTables(SQLiteDatabase db, ArrayList tables) { db.beginTransaction(); for (Table table : tables) { - db.execSQL(table.createSQL()); + db.execSQL(table.createSQL("")); } db.setTransactionSuccessful(); db.endTransaction(); @@ -78,32 +80,68 @@ public class DBHelper extends SQLiteOpenHelper { */ public void CreateTables() { - CreateTablesAll(BPA_MATERIAL.class);//物料表 - CreateTablesAll(BPA_SILOS.class);//料仓管理表 - CreateTablesAll(BPA_SILOSANDMATERIAL.class);//料仓物料关联表 - CreateTablesAll(BPA_GOODS.class);//商品表 - CreateTablesAll(BPA_GOODSRECIPE.class);//商品配方明细表 + CreateTablesAll(BPA_MATERIAL.class,"id");//物料表 + CreateTablesAll(BPA_SILOS.class,null);//料仓管理表 - CreateTablesAll(BPA_ORDER.class);//订单表 - CreateTablesAll(BPA_SUBORDER.class);//订单子表 + Map smMap = new HashMap(); + smMap.put("materialID","BPA_MATERIAL (id)"); + CreateRelationshipTables(BPA_SILOSANDMATERIAL.class,smMap);//料仓物料关联表 - CreateTablesAll(BPA_ALERTLOG.class);//预警日志表 - CreateTablesAll(BPA_LOG.class);//日志表 - CreateTablesAll(BPA_ORDERLOG.class);//订单制作记录表 - CreateTablesAll(BPA_ORDERLOGDESC.class);//订单制作记录描述表 + CreateTablesAll(BPA_GOODS.class,null);//商品表 + CreateTablesAll(BPA_GOODSRECIPE.class,null);//商品配方明细表 + + CreateTablesAll(BPA_ORDER.class,null);//订单表 + CreateTablesAll(BPA_SUBORDER.class,null);//订单子表 + + CreateTablesAll(BPA_ALERTLOG.class,null);//预警日志表 + CreateTablesAll(BPA_LOG.class,null);//日志表 + CreateTablesAll(BPA_ORDERLOG.class,null);//订单制作记录表 + CreateTablesAll(BPA_ORDERLOGDESC.class,null);//订单制作记录描述表 + + CreateTablesAll(BPA_SYSTEMSET.class,null);//系统设置表 + + CreateTablesAll(BPA_USER.class,null);//账户表 + CreateTablesAll(BPA_MENU.class,null);//菜单表 + CreateTablesAll(BPA_MENUANDUSER.class,null);//菜单用户关联表 + + ForeignKeys(); - CreateTablesAll(BPA_SYSTEMSET.class);//系统设置表 - CreateTablesAll(BPA_USER.class);//账户表 - CreateTablesAll(BPA_MENU.class);//菜单表 - CreateTablesAll(BPA_MENUANDUSER.class);//菜单用户关联表 } /** * 创建数据库表 * @param c */ - private void CreateTablesAll(Class c) + private void CreateTablesAll(Class c,String premarykey) { + if (premarykey == null){ + + premarykey=""; + } + SQLiteDatabase db =this.getWritableDatabase(); + db.beginTransaction(); + String TabName= c.getSimpleName();//表名称 + ArrayList
tables = new ArrayList
(); + Table t; + t = new Table(TabName); // 创建表名称 + for (Field field : c.getFields()){ + String name=field.getName(); + String type=field.getType().getSimpleName(); + if(type.equals("String") || type.equals("Date")) + { + type="text"; + } + t.addFeild(new Feild(name, type)); // 字段名称 + } + tables.add(t); + for (Table table : tables) { + db.execSQL(table.createSQL(premarykey)); + } + db.setTransactionSuccessful(); + db.endTransaction(); + } + + private void CreateRelationshipTables(Class c, Map map){ SQLiteDatabase db =this.getWritableDatabase(); db.beginTransaction(); String TabName= c.getSimpleName();//表名称 @@ -121,9 +159,23 @@ public class DBHelper extends SQLiteOpenHelper { } tables.add(t); for (Table table : tables) { - db.execSQL(table.createSQL()); + db.execSQL(table.createSQL(map)); } db.setTransactionSuccessful(); db.endTransaction(); } + /** + * 开启外键约束 + */ + private void ForeignKeys(){ + SQLiteDatabase db =this.getWritableDatabase(); + db.beginTransaction(); + db.execSQL("PRAGMA foreign_keys = 1"); + + db.setTransactionSuccessful(); + db.endTransaction(); + } + + + } diff --git a/app/src/main/java/com/example/bpa/db/file/Table.java b/app/src/main/java/com/example/bpa/db/file/Table.java index ac8a64e..dbeb7b2 100644 --- a/app/src/main/java/com/example/bpa/db/file/Table.java +++ b/app/src/main/java/com/example/bpa/db/file/Table.java @@ -3,6 +3,7 @@ package com.example.bpa.db.file; import android.util.Log; import java.util.ArrayList; +import java.util.Map; /** @@ -29,7 +30,7 @@ public class Table { this.feilds.add(feild); } - public String createSQL(){ + public String createSQL(String premarykey){ StringBuffer sb=new StringBuffer(); sb.append("CREATE TABLE "+this.name); sb.append("("); @@ -39,6 +40,8 @@ public class Table { sb.append(f.name); sb.append(" "); sb.append(f.type); + sb.append(" "); + if (premarykey.equals(f.name)) {sb.append("PRIMARY KEY");}//主键 sb.append(","); } sb.deleteCharAt(sb.length()-1); @@ -46,4 +49,36 @@ public class Table { Log.i("sql:",sb.toString()); return sb.toString(); } + + public String createSQL(Map params){ + StringBuffer sb=new StringBuffer(); + sb.append("CREATE TABLE "+this.name); + sb.append("("); + + ArrayList fs = this.feilds; + for(Feild f:fs){ + if (params.containsKey(f.name)) { + sb.append(f.name); + sb.append(" "); + sb.append(f.type); + sb.append(" "); + sb.append("REFERENCES"); + sb.append(" "); + sb.append(params.get(f.name)); + sb.append(" "); + sb.append("ON DELETE CASCADE"); + sb.append(","); + }else { + sb.append(f.name); + sb.append(" "); + sb.append(f.type); + sb.append(","); + } + + } + sb.deleteCharAt(sb.length()-1); + sb.append(")"); + Log.i("sql:",sb.toString()); + return sb.toString(); + } } diff --git a/app/src/main/java/com/example/bpa/db/mode/BPA_MATERIAL.java b/app/src/main/java/com/example/bpa/db/mode/BPA_MATERIAL.java index a73e452..84651e6 100644 --- a/app/src/main/java/com/example/bpa/db/mode/BPA_MATERIAL.java +++ b/app/src/main/java/com/example/bpa/db/mode/BPA_MATERIAL.java @@ -9,4 +9,8 @@ public class BPA_MATERIAL extends ModeBase { public String imgUrl; //物料名称 public String name; + + public String getNameValue() { + return name; + } } 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 new file mode 100644 index 0000000..076c837 --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java @@ -0,0 +1,159 @@ +package com.example.bpa.view.adapter; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.bpa.R; +import com.example.bpa.view.control.MainMeunAdapter; +import com.example.bpa.view.inteface.MyClickListener; +import com.example.bpa.view.mode.MenuMode; +import com.example.bpa.view.mode.lcMode; + +import java.util.List; + + +public class lc_item_adapter extends RecyclerView.Adapter { + + private final LayoutInflater mLayoutInflater; + private Context context; + private List list; + + public lc_item_adapter(Context context, List list) { + this.context = context; + this.list = list; + mLayoutInflater = LayoutInflater.from(context); + } + + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View inflate = mLayoutInflater.inflate(R.layout.lc_item, parent, false); + return new MyLCViewHolder(inflate); + + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + try { + if (holder instanceof MyLCViewHolder) { + MyLCViewHolder myViewHolder = (MyLCViewHolder) holder; + myViewHolder.materialName.setText(list.get(position).materialName); + myViewHolder.silosmargin.setText(list.get(position).silosmargin); + myViewHolder.num.setText(Integer.toString(list.get(position).num) ); + 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 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) { +// +// } +// +// +// +// +// }); + + } + } + catch (Exception e){ + e.printStackTrace(); + } + + } + + @Override + public int getItemCount() { + return list.size(); + } + + public static class MyLCViewHolder extends RecyclerView.ViewHolder { + public TextView materialName; + TextView num; + TextView silosmargin; + + public String id; + + public Spinner spinner; +// public String id; + public MyLCViewHolder(View view) { + super(view); + materialName = (TextView) view.findViewById(R.id.lc_item_materialName); + num = (TextView) view.findViewById(R.id.lc_item_num); + 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; + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/adapter/selectitem_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/selectitem_adapter.java new file mode 100644 index 0000000..f202430 --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/adapter/selectitem_adapter.java @@ -0,0 +1,41 @@ +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.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.view.inteface.MyClickListener; + +import java.util.List; + +public class selectitem_adapter extends ArrayAdapter { + + private List datas; + public selectitem_adapter(@NonNull Context context, int resource, @NonNull List objects) { + super(context, resource, objects); + + datas=objects; + } + //每个子项被滚动到屏幕内的时候会被调用 + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + BPA_MATERIAL bpa_material = (BPA_MATERIAL) getItem(position);//得到当前项选中item实例 + //为每一个子项加载设定的布局 + View view = LayoutInflater.from(getContext()).inflate(R.layout.selectitem_item, parent, false); + //分别获取 image view 和 textview 的实例 + TextView name = view.findViewById(R.id.name); + + // 设置要显示的图片和文字 + name.setText(bpa_material.name); + return view; + } +} diff --git a/app/src/main/java/com/example/bpa/view/dialog/lc_dialog.java b/app/src/main/java/com/example/bpa/view/dialog/lc_dialog.java new file mode 100644 index 0000000..7086089 --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/dialog/lc_dialog.java @@ -0,0 +1,130 @@ +package com.example.bpa.view.dialog; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.graphics.Point; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; + +import androidx.annotation.NonNull; + +import android.view.Display; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; + +import com.example.bpa.R; +import com.example.bpa.view.adapter.lc_item_adapter; + +import java.util.ArrayList; +import java.util.List; + + +public class lc_dialog extends Dialog implements View.OnClickListener{ + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + + private final LayoutInflater mLayoutInflater; + Spinner mSpinner; + Button mConfirm,mCancel; + List mDataList = new ArrayList(); + + private View.OnClickListener cancelListener, confirmListener; + + +// public lc_dialog setsMessage(){ +// +// } + + public lc_dialog( Context context,List list ) { + super(context); + this.mLayoutInflater = LayoutInflater.from(context); + mDataList = list; + } + + + public lc_dialog setsConfirm( View.OnClickListener listener) { + this.confirmListener = listener; + return this; + } + + public lc_dialog setsCancel(View.OnClickListener listener) { + + this.cancelListener = listener; + return this; + } + + + + // TODO: Rename and change types and number of parameters +// public static lc_dialog newInstance() { +// lc_dialog fragment = new lc_dialog(); +// Bundle args = new Bundle(); +// args.putString(ARG_PARAM1, param1); +// args.putString(ARG_PARAM2, param2); +// fragment.setArguments(args); +// return fragment; +// } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.lc_dialog); + getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + setCancelable(false); + + //自定义Dialog宽度 + WindowManager m = getWindow().getWindowManager(); + Display d = m.getDefaultDisplay(); + WindowManager.LayoutParams p = getWindow().getAttributes(); + Point size = new Point(); + d.getSize(size); + p.width = (int) ((size.x)*0.7); //设置为屏幕的0.7倍宽度 + getWindow().setAttributes(p); + + init(); + } + + + private void init() { + mSpinner = findViewById(R.id.material_select); + List m = new ArrayList(); + ArrayAdapter adapter = new ArrayAdapter(this.getContext(), android.R.layout.simple_list_item_1, android.R.id.text1, m); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + mSpinner.setAdapter(adapter); + mCancel = findViewById(R.id.cancel); + mConfirm = findViewById(R.id.confirm); + + mConfirm.setOnClickListener(this); + mCancel.setOnClickListener(this); + + } + + + + @Override + public void onClick(View v) { + switch (v.getId()){ + case R.id.confirm: + if(confirmListener != null){ + confirmListener.onClick(v); + } + break; + case R.id.cancel: + if(cancelListener != null){ + cancelListener.onClick(v); + } + break; + } + } + + +} + + 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 fb4d1ee..c79b9cf 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 @@ -1,18 +1,39 @@ package com.example.bpa.view.from; +import static android.media.CamcorderProfile.get; + import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.ListView; +import android.widget.Spinner; 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.db.mode.BPA_SILOSANDMATERIAL; +import com.example.bpa.view.adapter.lc_item_adapter; +import com.example.bpa.view.adapter.selectitem_adapter; +import com.example.bpa.view.control.ItemClickListener; +import com.example.bpa.view.control.MyLayoutManager; +import com.example.bpa.view.mode.lcMode; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * 料仓设置 */ -public class lcsz_activity extends AppCompatActivity implements View.OnClickListener{ +public class lcsz_activity extends AppCompatActivity implements View.OnClickListener { //region 变量 /** * 返回按钮 @@ -23,6 +44,15 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList */ TextView gongneng_title; //endregion + RecyclerView recyclerView; + //物料listview + ListView materiallist; + + + //物料列表 + ArrayList bpa_materials=new ArrayList<>(); + //当前选中的料仓id + lc_item_adapter.MyLCViewHolder currentSilo; //region 私有函数 @Override @@ -39,14 +69,50 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList /** * 初始化 */ - private void Init(){ + private void Init() { gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui); gongneng_title = this.findViewById(R.id.gongneng_title); //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 - String msg=getIntent().getStringExtra("data"); + String msg = getIntent().getStringExtra("data"); gongneng_title.setText(msg); + //横向排列 + recyclerView = this.findViewById(R.id.lc_view); + materiallist = this.findViewById(R.id.materials); + try { + //加载 recyclercview数据 + MyLayoutManager layout = new MyLayoutManager(); + //必须,防止recyclerview高度为wrap时测量item高度0 + layout.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layout); + List datas = new ArrayList(); + //获取料仓数据 + ArrayList bpa_silos =QueryDB.GetSilosALL(); + //加载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; + } + datas.add(new lcMode(silo.id,silo.num,m,"")); + } + } + lc_item_adapter adapter = new lc_item_adapter(this, datas); + + recyclerView.setAdapter(adapter); + + //加载listview 数据 + bpa_materials= QueryDB.GetMaterialALL(); + selectitem_adapter selectadapter = new selectitem_adapter(lcsz_activity.this, R.layout.selectitem_item, bpa_materials); + materiallist.setAdapter(selectadapter); + + } catch (Exception e) { + e.printStackTrace(); + } + + - ((TextView)this.findViewById(R.id.test_view)).setText(msg); } /** @@ -54,15 +120,61 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList */ private void initEvents() { gongneng_fanhui.setOnClickListener(this); + + recyclerView.addOnItemTouchListener(new ItemClickListener(recyclerView, new ItemClickListener.OnItemClickListener() { + @Override + public void onItemClick(View view, int position) { + RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position); + if (viewHolder instanceof lc_item_adapter.MyLCViewHolder) { + View listViewParent = (View) materiallist.getParent(); + listViewParent.setVisibility(View.VISIBLE); + currentSilo = null; + currentSilo = (lc_item_adapter.MyLCViewHolder) viewHolder; + + } + } + + @Override + public void onItemLongClick(View view, int position) { + + } + })); + //endregion + + //region materials点击事件 + materiallist.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + ArrayAdapter viewHolder = (ArrayAdapter)materiallist.getAdapter(); + if (viewHolder instanceof selectitem_adapter){ + View listViewParent = (View) materiallist.getParent(); + listViewParent.setVisibility(View.GONE); + if (currentSilo!=null){ + 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); + } + + } + + } + + + } + } + }); + //endregion + } - //endregion - //region 点击事件 - /** - * 本页面点击事件监听 - * - * @param v - */ @Override public void onClick(View v) { switch (v.getId()) { @@ -71,5 +183,4 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList break; } } - //endregion } \ No newline at end of file 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 new file mode 100644 index 0000000..f84e91c --- /dev/null +++ b/app/src/main/java/com/example/bpa/view/mode/lcMode.java @@ -0,0 +1,25 @@ +package com.example.bpa.view.mode; + +import com.example.bpa.db.mode.BPA_SILOS; + +import java.util.ArrayList; +import java.util.List; + +public class lcMode extends BPA_SILOS { + //物料名称 + public String materialName; + //料仓余料 + public String silosmargin; + + + + public lcMode(String id, int num,String materialName, String silosmargin) { + this.materialName = materialName; + this.silosmargin = silosmargin; + this.num = num; + this.id = id; +// this.id = "123"; + } + + +} diff --git a/app/src/main/res/drawable/lcbg_border.xml b/app/src/main/res/drawable/lcbg_border.xml new file mode 100644 index 0000000..826d326 --- /dev/null +++ b/app/src/main/res/drawable/lcbg_border.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/Dialog/layout/lc_dialog.xml b/app/src/main/res/layout/Dialog/layout/lc_dialog.xml new file mode 100644 index 0000000..e8aff93 --- /dev/null +++ b/app/src/main/res/layout/Dialog/layout/lc_dialog.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + +