Browse Source

完成商品管理

master
fyf 1 year ago
parent
commit
ca74f25251
10 changed files with 677 additions and 4 deletions
  1. +6
    -2
      app/src/main/AndroidManifest.xml
  2. +71
    -0
      app/src/main/java/com/example/bpa/db/QueryDB.java
  3. +92
    -0
      app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java
  4. +5
    -0
      app/src/main/java/com/example/bpa/view/fragment/SystemCapabilitiesFragment.java
  5. +187
    -0
      app/src/main/java/com/example/bpa/view/from/spgl_activity.java
  6. +94
    -0
      app/src/main/res/layout/datatab/layout/sp_item.xml
  7. +1
    -0
      app/src/main/res/layout/datatab/values/strings.xml
  8. +219
    -0
      app/src/main/res/layout/from/layout/activity_spgl.xml
  9. BIN
     
  10. +2
    -2
      build.gradle

+ 6
- 2
app/src/main/AndroidManifest.xml View File

@@ -14,11 +14,15 @@
android:label="@string/app_name"
android:supportsRtl="false"
android:theme="@style/AppTheme"
android:requestLegacyExternalStorage="true"
tools:targetApi="31">
<activity
android:name=".view.from.wlgl_activity"
android:windowSoftInputMode="adjustPan|stateHidden"
android:name=".view.from.spgl_activity"
android:exported="false" />
<activity
android:name=".view.from.wlgl_activity"
android:exported="false"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".view.from.yfpf_activity"
android:exported="false" />


+ 71
- 0
app/src/main/java/com/example/bpa/db/QueryDB.java View File

@@ -396,6 +396,77 @@ public class QueryDB {
}
return data;
}
/**
* 判断商品数据是否存在
* @param name
* @return
*/
public static boolean GetGoodsIs(String name)
{
boolean isSucess=false;
String orderby=Desc_Time_Up;//出料顺序
String where="isDelete=? and name=?";
String[] args=new String[] { "0" ,name};
ArrayList<BPA_GOODS> data=new ArrayList<>();
ArrayList<Object> obj=Get(BPA_GOODS.class,where,args,orderby);
for (Object k:obj) {
data.add((BPA_GOODS)k);
}
return data.size()>0;
}

/**
* 根据排序查询商品
* @param sort
* @return
*/
public static BPA_GOODS GetGoodsSortIs(int sort)
{
boolean isSucess=false;
String orderby=Desc_Time_Up;//出料顺序
String where="isDelete=? and sort=?";
String[] args=new String[] { "0" ,sort+""};
BPA_GOODS data=null;
ArrayList<Object> obj=Get(BPA_GOODS.class,where,args,orderby);
for (Object k:obj) {
data=(BPA_GOODS)k;
}
return data;
}

/**
* 商品数据排序
* @param data 数据
* @param type 0 下移动 1 上移动
* @return
*/
public static void GetGoodsSort(BPA_GOODS data,int type)
{
if(type==0)
{
BPA_GOODS q_data= data;
BPA_GOODS h_data= GetGoodsSortIs(data.sort+1);
if(h_data!=null)
{
h_data.sort=h_data.sort-1;
UpdateGoods(h_data);
}
q_data.sort=q_data.sort+1;
UpdateGoods(q_data);

}else
{
BPA_GOODS q_data= GetGoodsSortIs(data.sort-1);
BPA_GOODS h_data= data;
if(q_data!=null)
{
q_data.sort=q_data.sort+1;
UpdateGoods(q_data);
}
h_data.sort=h_data.sort-1;
UpdateGoods(h_data);
}
}
//endregion

//region BPA_GOODSRECIPE 商品配方明细表


+ 92
- 0
app/src/main/java/com/example/bpa/view/adapter/sp_adapter.java View File

@@ -0,0 +1,92 @@
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.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.bpa.R;
import com.example.bpa.db.mode.BPA_GOODS;
import com.example.bpa.db.mode.BPA_MATERIAL;
import com.example.bpa.helper.T;
import com.example.bpa.view.inteface.MyClickListener;

import java.util.List;

/**
* 商品数据表格
*/
public class sp_adapter extends ArrayAdapter<BPA_GOODS> {
/**
* 内部点击事件
*/
private MyClickListener mListener;
private List<BPA_GOODS> datas;
public sp_adapter(@NonNull Context context, int resource, @NonNull List<BPA_GOODS> objects, MyClickListener listener) {
super(context, resource, objects);
mListener = listener;
datas=objects;
}
//每个子项被滚动到屏幕内的时候会被调用
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
BPA_GOODS bpa_goods = (BPA_GOODS) getItem(position);//得到当前项选中item实例
//为每一个子项加载设定的布局
View view = LayoutInflater.from(getContext()).inflate(R.layout.sp_item, parent, false);
//分别获取 image view 和 textview 的实例
TextView name = view.findViewById(R.id.name);
TextView sort = view.findViewById(R.id.sort);

Button button = view.findViewById(R.id.button_item);
Button button_up = view.findViewById(R.id.button_item_Up);
Button button_down = view.findViewById(R.id.button_item_Down);
// 设置要显示的图片和文字
name.setText(bpa_goods.name);
sort.setText(bpa_goods.sort+"");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try
{
mListener.clickListener(view,bpa_goods);
} catch (Exception e)
{
T.show(view.getContext(),"删除商品出错:"+e.getMessage());
}
}
});
button_up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try
{
mListener.clickListener(view,bpa_goods);
} catch (Exception e)
{
T.show(view.getContext(),"商品排序出错:"+e.getMessage());
}
}
});
button_down.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try
{
mListener.clickListener(view,bpa_goods);
} catch (Exception e)
{
T.show(view.getContext(),"商品排序出错:"+e.getMessage());
}
}
});
return view;
}
}

+ 5
- 0
app/src/main/java/com/example/bpa/view/fragment/SystemCapabilitiesFragment.java View File

@@ -27,6 +27,7 @@ import com.example.bpa.view.from.ddyjrz_activity;
import com.example.bpa.view.from.dzcjy_activity;
import com.example.bpa.view.from.lcsz_activity;
import com.example.bpa.view.from.lsjy_activity;
import com.example.bpa.view.from.spgl_activity;
import com.example.bpa.view.from.wlgl_activity;
import com.example.bpa.view.from.yfcl_activity;
import com.example.bpa.view.from.yfpf_activity;
@@ -70,6 +71,7 @@ public class SystemCapabilitiesFragment extends Fragment {

menuModes.clear();
menuModes.add(new MenuMode("物料管理",R.mipmap.wlgl));
menuModes.add(new MenuMode("商品管理",R.mipmap.spgl));
menuModes.add(new MenuMode("料仓设置",R.mipmap.lcsz));
menuModes.add(new MenuMode("电子秤校验",R.mipmap.dzcjy));
menuModes.add(new MenuMode("流速校验",R.mipmap.lsjy));
@@ -98,6 +100,9 @@ public class SystemCapabilitiesFragment extends Fragment {
case "物料管理":
intent = new Intent(view.getContext(), wlgl_activity.class);
break;
case "商品管理":
intent = new Intent(view.getContext(), spgl_activity.class);
break;
case "料仓设置":
intent = new Intent(view.getContext(), lcsz_activity.class);
break;


+ 187
- 0
app/src/main/java/com/example/bpa/view/from/spgl_activity.java View File

@@ -0,0 +1,187 @@
package com.example.bpa.view.from;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.bpa.R;
import com.example.bpa.config.ConfigName;
import com.example.bpa.db.QueryDB;
import com.example.bpa.db.mode.BPA_GOODS;
import com.example.bpa.db.mode.BPA_MATERIAL;
import com.example.bpa.helper.T;
import com.example.bpa.view.adapter.sp_adapter;
import com.example.bpa.view.adapter.wl_adapter;
import com.example.bpa.view.inteface.MyClickListener;

import java.util.ArrayList;

public class spgl_activity extends AppCompatActivity implements View.OnClickListener, MyClickListener {

//region 变量
/**
* 返回按钮
*/
ImageView gongneng_fanhui;
/**
* 标题设置
*/
TextView gongneng_title;

//endregion

//region 操作变量
/**
* 输入框
*/
TextView edittext;
/**
* 增加按钮
*/
Button buttonadd;
/**
* 表格显示
*/
ListView datatab;
/**
* 商品数据
*/
ArrayList<BPA_GOODS> bpa_goods=new ArrayList<>();
//endregion

//region 私有函数
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spgl);
Init();
initEvents();
}
//endregion

//region 公共函数

/**
* 初始化
*/
private void Init(){
gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui);
gongneng_title = this.findViewById(R.id.gongneng_title);
edittext= this.findViewById(R.id.edittext);
buttonadd= this.findViewById(R.id.buttonadd);
datatab= this.findViewById(R.id.datatab);
//通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据
String msg=getIntent().getStringExtra("data");
gongneng_title.setText(msg);
Initdata();
}

/**
* 初始化按钮事件
*/
private void initEvents() {
gongneng_fanhui.setOnClickListener(this);
buttonadd.setOnClickListener(this);
}

/**
* 初始化数据加载
*/
public void Initdata()
{
try{
bpa_goods= QueryDB.GetGoodsALL();
sp_adapter adapter = new sp_adapter(spgl_activity.this, R.layout.sp_item, bpa_goods,this);
datatab.setAdapter(adapter);
}catch(Exception e){

}
}
//endregion

//region 点击事件
/**
* 本页面点击事件监听
*
* @param v
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.gongneng_fanhui://返回按钮
this.finish();
break;
case R.id.buttonadd://增加按钮点击
String name= edittext.getText().toString();
if(name.isEmpty()){
T.show(this, "商品名称不能为空!");
return;
}
if(QueryDB.GetGoodsIs(name)){
T.show(this, "商品名称重复,请重新输入后重试!");
return;
}
BPA_GOODS good=new BPA_GOODS();
good.name=name;
good.sort=bpa_goods.size()+1;
good.status=1;
good.deviceID= ConfigName.getInstance().DeviceId;
good.userID=ConfigName.getInstance().user.userID;
QueryDB.AddGoods(good);
T.show(this, "新增成功!");
Initdata();
break;
}
}

/**
* 接口方法,响应ListView按钮点击事件
*/
@Override
public void clickListener(View v,Object data) {
switch (v.getId())
{
case R.id.button_item://删除按钮
int sort=((BPA_GOODS)data).sort;
String id=((BPA_GOODS)data).id;
Log.i("日志",sort + "--- "+id);
QueryDB.DeleteGoods((BPA_GOODS)data);
Initdata();
for (BPA_GOODS k:bpa_goods) {
if(k.sort>sort)
{
QueryDB.GetGoodsSort(k,1);
}
}
Initdata();
break;
case R.id.button_item_Up://上移动按钮
BPA_GOODS good=(BPA_GOODS)data;
if(good.sort==1)
{
T.show(this, "已是最顶部!");
return;
}
QueryDB.GetGoodsSort((BPA_GOODS)data,1);
Initdata();
break;
case R.id.button_item_Down://下移动按钮
BPA_GOODS good2=(BPA_GOODS)data;
if(good2.sort==bpa_goods.size())
{
T.show(this, "已是最底部!");
return;
}
QueryDB.GetGoodsSort((BPA_GOODS)data,0);
Initdata();
break;
}
}
//endregion
}

+ 94
- 0
app/src/main/res/layout/datatab/layout/sp_item.xml View File

@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TableLayout
android:background="@mipmap/bgxz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:stretchColumns="0">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="回锅肉"
android:textColor="@color/foreground"
android:textSize="@dimen/textSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="回锅肉"
android:textColor="@color/foreground"
android:textSize="@dimen/textSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_item_Up"
android:text="上移"
android:background="@drawable/btn_button"
android:textSize="@dimen/textSize"
android:textColor="@color/foreground"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_width="60dp"
android:layout_height="26dp"
/>
<Button
android:id="@+id/button_item_Down"
android:text="下移"
android:background="@drawable/btn_button"
android:textSize="@dimen/textSize"
android:textColor="@color/foreground"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_width="60dp"
android:layout_height="26dp"
/>
<Button
android:id="@+id/button_item"
android:text="删除"
android:background="@drawable/btn_button"
android:textSize="@dimen/textSize"
android:textColor="@color/foreground"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_width="60dp"
android:layout_height="26dp"
/>
</LinearLayout>

</RelativeLayout>

</TableRow>
</TableLayout>
</RelativeLayout>

+ 1
- 0
app/src/main/res/layout/datatab/values/strings.xml View File

@@ -0,0 +1 @@
<resources></resources>

+ 219
- 0
app/src/main/res/layout/from/layout/activity_spgl.xml View File

@@ -0,0 +1,219 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@mipmap/dpbj"
tools:context=".view.from.spgl_activity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/test">
<ImageView
android:id="@+id/gongneng_fanhui"
android:layout_width="26dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:textSize="@dimen/TitleSize"
android:textColor="@color/titleforeground"
android:src="@mipmap/zj"
/>
<RelativeLayout
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/gongneng_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@color/white"
android:textSize="@dimen/textTitleSize"
android:textStyle="bold" />
<ImageView
android:layout_width="400dp"
android:layout_height="22dp"
android:layout_alignParentBottom="true"
android:src="@mipmap/tittle"
android:layout_marginLeft="5dp"
/>
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF03668F" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@mipmap/zs"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:src="@mipmap/zx"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@mipmap/ys"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:src="@mipmap/yx"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="名称:"
android:textSize="@dimen/textSize"
android:textColor="@color/foreground"/>
<EditText
android:id="@+id/edittext"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="text"
android:padding="3dp"
android:textColor="@color/foreground"
android:theme="@style/MyEditText1"
android:background="@drawable/round_corners_bg"
android:layout_marginLeft="5dp"
android:hint="请输入商品名称"
android:maxLines="1"
android:textSize="@dimen/textSize"/>
<Button
android:id="@+id/buttonadd"
android:text="新增"
android:background="@drawable/btn_button"
android:textSize="@dimen/textSize"
android:textColor="@color/foreground"
android:layout_marginLeft="5dp"
android:layout_gravity="center"
android:layout_width="60dp"
android:layout_height="26dp"
/>
</LinearLayout>

</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:background="@mipmap/bgbtbj"
android:layout_height="26dp">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF03668F" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#FF03668F" />
<TableLayout
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:stretchColumns="0">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="商品名称"
android:textColor="@color/dataGridColumnHeaderColor"
android:textSize="@dimen/textSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="排序"
android:textColor="@color/dataGridColumnHeaderColor"
android:textSize="@dimen/textSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="用户操作"
android:textColor="@color/dataGridColumnHeaderColor"
android:textSize="@dimen/textSize" />
</RelativeLayout>

</TableRow>
</TableLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/datatab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#00000000"
android:dividerHeight="3dp"
android:layout_marginTop="3dp"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

BIN
View File


+ 2
- 2
build.gradle View File

@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'com.android.application' version '7.0.0' apply false
id 'com.android.library' version '7.0.0' apply false
}

Loading…
Cancel
Save