From cd744223d2beeb748a78db06768e647d6fcd0305 Mon Sep 17 00:00:00 2001 From: fyf Date: Tue, 4 Jul 2023 14:36:33 +0800 Subject: [PATCH] =?UTF-8?q?diy=E5=8A=9F=E8=83=BD=E6=99=9A=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonait/bnframework/common/db/QueryDB.java | 1 + .../home/adapter/gongxubuzhou_adapter.java | 28 ++- .../home/fragment/from/DiyActivity.java | 181 ++++++++++++++++-- .../home/fragment/mode/fragment_gx.java | 13 +- app/src/main/res/layout/activity_diy.xml | 107 ++++------- .../res/layout/datatab/layout/gx_item.xml | 1 + 6 files changed, 230 insertions(+), 101 deletions(-) diff --git a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java index 63ac1767..a3e0ec59 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java @@ -2388,6 +2388,7 @@ public class QueryDB { ((BPA_GOODSRECIPE) data).materialType = cursor.getInt((int) cursor.getColumnIndex("materialType")); ((BPA_GOODSRECIPE) data).processname = cursor.getString((int) cursor.getColumnIndex("processname")); ((BPA_GOODSRECIPE) data).processvalue = cursor.getString((int) cursor.getColumnIndex("processvalue")); + ((BPA_GOODSRECIPE) data).processms = cursor.getString((int) cursor.getColumnIndex("processms")); break; case "BPA_ORDER": data = new BPA_ORDER(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java index 7ef350e2..28c3e305 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java @@ -1,6 +1,7 @@ package com.bonait.bnframework.modules.home.adapter; import android.content.Context; +import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -24,6 +25,8 @@ public class gongxubuzhou_adapter extends ArrayAdapter { */ private MyClickListener mListener; private List datas; + + private int selectedPosition = -1;// 选中的位置 int resource1; public gongxubuzhou_adapter(@NonNull Context context, int resource, @NonNull List objects, MyClickListener listener) { super(context, resource, objects); @@ -31,6 +34,15 @@ public class gongxubuzhou_adapter extends ArrayAdapter { datas=objects; this.resource1=resource; } + + public int getSelectedPosition() + { + return selectedPosition; + } + + public void setSelectedPosition(int position) { + selectedPosition = position; + } //每个子项被滚动到屏幕内的时候会被调用 @NonNull @Override @@ -41,15 +53,15 @@ public class gongxubuzhou_adapter extends ArrayAdapter { //分别获取 image view 和 textview 的实例 TextView text = view.findViewById(R.id.text); - text.setText(lc.sort+"、"+lc.processms); - text.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - //view.setBackground(getContext().getResources().getDrawable(R.mipmap.hgr)); - if(mListener!=null) mListener.clickListener(view,lc); - } - }); + text.setText((position+1)+"、"+lc.processms); + if (selectedPosition == position) { + text.setSelected(true); + text.setTextColor(Color.WHITE); + } else { + text.setSelected(false); + text.setTextColor(Color.BLACK); + } return view; } } \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java index 56d4cfd3..a99c6281 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java @@ -5,6 +5,7 @@ import static com.bonait.bnframework.MainApplication.getContext; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.AttributeSet; @@ -13,6 +14,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; @@ -22,6 +24,7 @@ import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; @@ -29,6 +32,7 @@ import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.helper.MyImage; import com.bonait.bnframework.common.message.MessageManager; +import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; import com.bonait.bnframework.modules.home.adapter.lcsz_adapter; @@ -36,6 +40,7 @@ import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; import com.bonait.bnframework.modules.home.fragment.mode.item_gx; import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import com.youth.banner.Banner; import org.xmlpull.v1.XmlPullParser; @@ -54,6 +59,8 @@ import butterknife.OnClick; public class DiyActivity extends BaseActivity implements MyClickListener { @BindView(R.id.topbar) QMUITopBar mTopBar; + @BindView(R.id.edittext) + EditText edittext;//菜谱名称 @BindView(R.id.Banner_Main) Banner Banner_Main;//轮播图 //用于存放获取的图片 @@ -107,6 +114,14 @@ public class DiyActivity extends BaseActivity implements MyClickListener { //3.工序步骤 gxbz_adapter = new gongxubuzhou_adapter(getContext(), R.layout.gx_item, (List) bpa_goodsrecipes,this); datatab_gxbz.setAdapter(gxbz_adapter); + datatab_gxbz.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long l) { + // TODO Auto-generated method stub + gxbz_adapter.setSelectedPosition(position); + gxbz_adapter.notifyDataSetInvalidated(); + } + }); } /** * 根据选中工序id显示集合 @@ -147,18 +162,72 @@ public class DiyActivity extends BaseActivity implements MyClickListener { { } } + /** * 获取选中行的变量 * @return */ - int k=1; public BPA_GOODSRECIPE GetSelectItemFromValue() { BPA_GOODSRECIPE pf=new BPA_GOODSRECIPE(); - pf.processms="测试物料"; - pf.sort=k; - k++; - return pf; + try + { + String name= hrgx.getSelectedItem().toString(); + boolean IsVerify=true; + String description=""; + // 延迟,100|延迟,100|延迟,100|延迟,100| + String data=""; + String desc=""; + if(name.equals("液体料")) + { + pf.materialType=0; + for (int i = 0; i < gxchid.getChildCount(); i++) { + fragment_gx gongxu = (fragment_gx) gxchid.getChildAt(i); + String values= gongxu.GetValues(); + if(!values.isEmpty()) + { + data+=gongxu.model.name+","+values+"|"; + desc+=values+","; + } + } + + if(data.isEmpty()) + { + IsVerify=false; + description+="物料-不能为空,请勾选一个物料\n"; + } + }else + { + pf.materialType=1; + for (int i = 0; i < gxchid.getChildCount(); i++) { + fragment_gx gongxu = (fragment_gx) gxchid.getChildAt(i); + String values= gongxu.GetValues(); + if(values.isEmpty()) + { + IsVerify=false; + description+=gongxu.model.name +"-不能为空\n"; + }else + { + data+=gongxu.model.name+","+values+"|"; + desc+=values+","; + } + } + } + if(IsVerify) + { + pf.processname=name; + pf.processms= name+"("+desc.substring(0,desc.length()-1) +")"; + pf.processvalue=data.substring(0,data.length()-1); + return pf; + }else + { + ToastUtils.info("数据验证失败,原因:"+description); + return null; + } + }catch (Exception ex) + { + return null; + } } private void initTopBar() { mTopBar.setTitle("DIY模式"); @@ -202,35 +271,109 @@ public class DiyActivity extends BaseActivity implements MyClickListener { public void onViewClicked(View view) { switch (view.getId()) { case R.id.add_hrgx://添加工序 - bpa_goodsrecipes.add(GetSelectItemFromValue()); - gxbz_adapter.notifyDataSetChanged(); - ToastUtils.info("添加工序"); + BPA_GOODSRECIPE goodsrecipe= GetSelectItemFromValue(); + if(goodsrecipe!=null) + { + bpa_goodsrecipes.add(GetSelectItemFromValue()); + gxbz_adapter.notifyDataSetChanged(); + } break; case R.id.update_gx://修改工序 - - ToastUtils.info("修改工序"); + int index_update= gxbz_adapter.getSelectedPosition(); + if(index_update>=0 && index_update=0 && index_delete0) + { + BPA_GOODSRECIPE obj_up= (BPA_GOODSRECIPE)bpa_goodsrecipes.get(index_up); + bpa_goodsrecipes.remove(obj_up); + bpa_goodsrecipes.add(index_up-1,obj_up); + gxbz_adapter.notifyDataSetChanged(); + }else + { + ToastUtils.info("已经最顶部!"); + } break; case R.id.xiayi://下移 - - ToastUtils.info("下移"); + int index_down= gxbz_adapter.getSelectedPosition(); + if(index_down=0) + { + BPA_GOODSRECIPE obj_down= (BPA_GOODSRECIPE)bpa_goodsrecipes.get(index_down); + bpa_goodsrecipes.remove(obj_down); + bpa_goodsrecipes.add(index_down+1,obj_down); + gxbz_adapter.notifyDataSetChanged(); + }else + { + ToastUtils.info("已经最底部!"); + } break; case R.id.caozuomoshi://操作模式 ToastUtils.info("操作模式"); break; case R.id.shengchengcaipu://生成菜谱 + String name=edittext.getText().toString(); + if(name.isEmpty()) + { + ToastUtils.info("菜谱名称不能为空!"); + return; + }else + { + boolean isSucess= QueryDB.GetGoodsIs(name); + if(isSucess) + { + ToastUtils.info("菜谱名称已存在!"); + return; + } + //按钮点击 + String title = "生成菜谱操作提示!"; + String message = "请问客官确定要生成["+name+"]菜谱吗?"; + AlertDialogUtils.showDialog(view.getContext(), title, message, new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { + ArrayList goods=QueryDB.GetGoodsALL(); + BPA_GOODS good=new BPA_GOODS(); + good.name=name; + good.status=1; + good.sort=goods.size()+1; + good.maketime=60*3; + good.issc=0; + QueryDB.AddGoods(good); + for (int k=0;k + + + - + - - - - - - - + + - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:background="@drawable/input_bj" + android:hint="请输入菜谱名称" + android:inputType="text" + android:maxLines="1" + android:padding="3dp" + android:textSize="12dp" /> -