diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b5d48003..7dd48c50 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,6 +28,9 @@ android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning" tools:node="merge"> + diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java b/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java index 727eae54..8e52437e 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/MessageName.java @@ -17,4 +17,6 @@ public interface MessageName { String DeleteGood="DeleteGood";//删除菜品 String ScGood="ScGood";//收藏菜品 + String ClickGood="ClickGood";//点击商品 + } 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 a3e0ec59..80d8a58c 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 @@ -737,6 +737,25 @@ public class QueryDB { return data.size() > 0; } + /** + * 判断商品数据是否存在 + * + * @param name + * @return + */ + public static boolean GetGoodsIs(String name,String id) { + boolean isSucess = false; + String orderby = Desc_Time_Up;//出料顺序 + String where = "isDelete=? and name=? and id!=?"; + String[] args = new String[]{"0", name,id}; + ArrayList data = new ArrayList<>(); + ArrayList obj = Get(BPA_GOODS.class, where, args, orderby); + for (Object k : obj) { + data.add((BPA_GOODS) k); + } + return data.size() > 0; + } + /** * 判断商品数据是否存在 * @@ -856,7 +875,24 @@ public class QueryDB { } return data; } - + /** + * 根据商品id查询配方信息 + * + * @param id + * @return + */ + public static ArrayList GetGoodsSrecipeID(String id) { + String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序 + String where = "isDelete=? and goodsID=?"; + String[] args = new String[]{"0", id}; + ArrayList data = new ArrayList<>(); + ArrayList obj = Get(BPA_GOODSRECIPE.class, where, args, orderby); + for (Object item : obj) { + BPA_GOODSRECIPE k = (BPA_GOODSRECIPE) item; + data.add(k); + } + return data; + } /** * 根据商品id查询配方信息 * diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java index 11566504..008dad4d 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java @@ -3,6 +3,8 @@ package com.bonait.bnframework.modules.home.fragment.from; import static com.bonait.bnframework.MainApplication.getContext; import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; import android.os.Bundle; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -117,6 +119,24 @@ public class CpActivity extends BaseActivity { } } }); + + /** + * 点击菜品 + */ + MessageManager.getInstance().registerMessageReceiver(this, MessageName.ClickGood, new MessageLooper.OnMessageListener() { + @Override + public void onMessage(Object msg) { + if (msg != null) { + SectionItem item=(SectionItem)msg; + String goodid=item.getAccount();//商品id + // 跳转到登录页面 + Intent intent = new Intent(getContext(), DiyUpdateActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra("id",goodid); + startActivity(intent); + } + } + }); } protected QMUIStickySectionAdapter createAdapter() { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java new file mode 100644 index 00000000..e24a022f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java @@ -0,0 +1,413 @@ +package com.bonait.bnframework.modules.home.fragment.from; + +import static com.bonait.bnframework.MainApplication.getContext; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.Spinner; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.base.BaseActivity; +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; +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.utils.AlertDialogUtils; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; +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 java.net.IDN; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class DiyUpdateActivity extends BaseActivity { + + @BindView(R.id.topbar) + QMUITopBar mTopBar; + @BindView(R.id.edittext) + EditText edittext;//菜谱名称 + @BindView(R.id.Banner_Main) + Banner Banner_Main;//轮播图 + //用于存放获取的图片 + List Banner_list = new ArrayList<>(); + + @BindView(R.id.hrgx) + Spinner hrgx;//工序 + Map hrgx_map = new LinkedHashMap<>(); + + @BindView(R.id.gxchid) + LinearLayout gxchid;//工序子集 + + @BindView(R.id.datatab_gxbz) + ListView datatab_gxbz;//工序步骤 + public gongxubuzhou_adapter gxbz_adapter=null; + /** + * 工序步骤 + */ + public ArrayList bpa_goodsrecipes=new ArrayList<>(); + + /** + * 当前商品 + */ + public BPA_GOODS good=null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_diy_update); + ButterKnife.bind(this); + initTopBar(); + initData(); + SetGood(); + } + private void initData() + { + //1.初始化轮播图 + Drawable_Get(Banner_list); + //2.初始化工序 + ArrayList data= QueryDB.GetProcessALL(); + for (BPA_PROCESS item:data) + { + hrgx_map.put(item.name,item.id); + } + ArrayAdapter adapter_kk = new ArrayAdapter<>(getContext(), R.layout.spinner_text_item, new ArrayList<>(hrgx_map.keySet())); + adapter_kk.setDropDownViewResource(R.layout.spinner_dropdown_item); + hrgx.setAdapter(adapter_kk); + hrgx.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + String id= hrgx_map.get(hrgx.getSelectedItem().toString()); + SelectItemFrom(id); + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + //3.工序步骤 + gxbz_adapter = new gongxubuzhou_adapter(getContext(), R.layout.gx_item, (List) bpa_goodsrecipes,null); + 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(); + } + }); + } + + /** + * 设置当前商品 + * @param + */ + public void SetGood() + { + try + { + Intent intent = getIntent(); + String id = intent.getStringExtra("id"); + if(!id.isEmpty()) + { + good=QueryDB.GetGoodsId(id); + if(good!=null) + { + bpa_goodsrecipes.clear(); + ArrayList goodsrecipes=QueryDB.GetGoodsSrecipeID(good.id); + for (BPA_GOODSRECIPE item :goodsrecipes) + { + bpa_goodsrecipes.add(item); + } + edittext.setText(good.name); + gxbz_adapter.notifyDataSetChanged();//刷新商品配方 + } + } + }catch (Exception ex) + { + + } + } + /** + * 根据选中工序id显示集合 + * @param id + */ + public void SelectItemFrom(String id) + { + try + { + gxchid.removeAllViews(); + ArrayList mode= QueryDB.GetProcessModelProcessID(id); + if(mode.size()>0)//工序 + { + for (BPA_PROCESSModel item : mode) + { + item_gx gx=new item_gx(); + gx.datatype=item.datatype; + gx.name=item.name; + gx.data=item.data; + gx.IsWL=false; + fragment_gx gongxu=new fragment_gx(this,null,gx); + gxchid.addView(gongxu); + } + }else //物料 + { + ArrayList materials= QueryDB.GetMaterialALL(); + for (BPA_MATERIAL item2 : materials) + { + item_gx gx=new item_gx(); + gx.datatype=0;//液体料都是数字 + gx.name=item2.name; + gx.IsWL=true; + fragment_gx gongxu=new fragment_gx(this,null,gx); + gxchid.addView(gongxu); + } + } + }catch (Exception ex) + { + } + } + + /** + * 获取选中行的变量 + * @return + */ + public BPA_GOODSRECIPE GetSelectItemFromValue() + { + BPA_GOODSRECIPE pf=new BPA_GOODSRECIPE(); + 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("菜谱信息修改"); + mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + finish(); + } + }); + } + /** + * 获取图片存放到list中 + * @param arrayList + */ + private void Drawable_Get(List arrayList) { + //从drawable文件夹下获取到事先准备的图片,在这里演示三张图片 + Drawable drawable = getResources().getDrawable(R.mipmap.hgr); + Drawable drawable1 = getResources().getDrawable(R.mipmap.hgr); + Drawable drawable2 = getResources().getDrawable(R.mipmap.hgr); + //把他们存放到一个list集合中 + arrayList.add(drawable); + arrayList.add(drawable1); + arrayList.add(drawable2); + //调用轮播图设置方法 + Banner_Set(Banner_list); + } + /** + * 将图片存放到轮播图中 + * @param arrayList + */ + private void Banner_Set(List arrayList) { + //这是设置轮播图的关键位置,setImages(list) 设置轮播图的图片资源 + //setImageLoader(一个实体类)用于加载图片到手机页面上显示 + Banner_Main.setImages(Banner_list).setImageLoader(new MyImage()).start(); + } + /** + * 点击事件 + * @param view + */ + @OnClick({R.id.add_hrgx,R.id.update_gx,R.id.delete_gx,R.id.shangyi,R.id.xiayi,R.id.shengchengcaipu}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.add_hrgx://添加工序 + BPA_GOODSRECIPE goodsrecipe= GetSelectItemFromValue(); + if(goodsrecipe!=null) + { + bpa_goodsrecipes.add(GetSelectItemFromValue()); + gxbz_adapter.notifyDataSetChanged(); + } + break; + case R.id.update_gx://修改工序 + 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://下移 + 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.shengchengcaipu://保存菜谱 + String name=edittext.getText().toString(); + if(name.isEmpty()) + { + ToastUtils.info("菜谱名称不能为空!"); + return; + }else + { + boolean isSucess= QueryDB.GetGoodsIs(name,good.id); + 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) { + good.name=name; + QueryDB.UpdateGoods(good); + ArrayList pe=QueryDB.GetGoodsSrecipeID(good.id); + for (BPA_GOODSRECIPE item:pe) + { + QueryDB.DeleteGoodsSrecipe(item); + } + for (int k=0;k + + + + + + + + + + + + + + + + + + + + +