# Conflicts: # app/src/main/java/com/example/bpa/db/QueryDB.javamaster
@@ -36,9 +36,9 @@ public class BusinessServer { | |||
@Override | |||
public void Run() throws InterruptedException { | |||
while (Commoditys.size() > 0) { | |||
Commoditys.poll(); | |||
String GoodId = Commoditys.poll(); | |||
ArrayList<ResGoodsRecipe> goods = QueryDB.GetGoodsSrecipeList(GoodId); | |||
ArrayList<ResGoodsRecipe> goods = QueryDB.GetGoodsSrecipeList(""); | |||
} | |||
Thread.sleep(1000); | |||
} | |||
@@ -0,0 +1,12 @@ | |||
package com.example.bpa.config; | |||
/** | |||
* 消息名称管理枚举 | |||
*/ | |||
public enum MessageName { | |||
Common,//通用消息 | |||
PF_From_Close,//配方界面关闭通知 | |||
Click | |||
} |
@@ -1,11 +1,15 @@ | |||
package com.example.bpa.view.adapter; | |||
import android.content.Context; | |||
import android.text.Editable; | |||
import android.text.TextWatcher; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.AdapterView; | |||
import android.widget.ArrayAdapter; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.Spinner; | |||
import android.widget.SpinnerAdapter; | |||
import android.widget.TextView; | |||
@@ -30,11 +34,11 @@ public class pf_adapter extends ArrayAdapter<ResGoodsRecipe> { | |||
* 内部点击事件 | |||
*/ | |||
private MyClickListener mListener; | |||
private List<ResGoodsRecipe> datas; | |||
private ArrayList<ResGoodsRecipe> datas= new ArrayList<>(); | |||
ArrayList<String> wuliao=new ArrayList<>(); | |||
public pf_adapter(@NonNull Context context, int resource, @NonNull List<ResGoodsRecipe> objects, ArrayList<BPA_MATERIAL> wl, MyClickListener listener) { | |||
ArrayList<BPA_MATERIAL> wllist=new ArrayList<>(); | |||
public pf_adapter(@NonNull Context context, int resource, @NonNull ArrayList<ResGoodsRecipe> objects, ArrayList<BPA_MATERIAL> wl, MyClickListener listener) { | |||
super(context, resource, objects); | |||
mListener = listener; | |||
datas=objects; | |||
@@ -45,6 +49,7 @@ public class pf_adapter extends ArrayAdapter<ResGoodsRecipe> { | |||
{ | |||
wuliao.add(me.name); | |||
} | |||
wllist=wl; | |||
} | |||
} | |||
//每个子项被滚动到屏幕内的时候会被调用 | |||
@@ -56,13 +61,13 @@ public class pf_adapter extends ArrayAdapter<ResGoodsRecipe> { | |||
View view = LayoutInflater.from(getContext()).inflate(R.layout.pf_item, parent, false); | |||
//分别获取 image view 和 textview 的实例 | |||
Spinner name = view.findViewById(R.id.name); | |||
TextView sort = view.findViewById(R.id.sort); | |||
TextView value = view.findViewById(R.id.value); | |||
EditText sort = view.findViewById(R.id.sort); | |||
EditText value = view.findViewById(R.id.value); | |||
Button button = view.findViewById(R.id.button_item); | |||
// 设置要显示的图片和文字 | |||
ArrayAdapter mAdapter = new android.widget.ArrayAdapter<String>(view.getContext(), | |||
android.R.layout.simple_spinner_item); | |||
mAdapter.addAll(wuliao); | |||
ArrayAdapter mAdapter = new ArrayAdapter<String>(view.getContext(), | |||
R.layout.my_text_view,wuliao); | |||
//mAdapter.addAll(wuliao); | |||
name.setAdapter(mAdapter); | |||
if(resGoodsRecipe.materialName!=null && !resGoodsRecipe.materialName.isEmpty()) | |||
@@ -76,8 +81,10 @@ public class pf_adapter extends ArrayAdapter<ResGoodsRecipe> { | |||
} | |||
} | |||
} | |||
value.setText(resGoodsRecipe.value+""); | |||
sort.setText(resGoodsRecipe.sort+""); | |||
sort.setTag(resGoodsRecipe.id); | |||
button.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View view) { | |||
@@ -90,6 +97,97 @@ public class pf_adapter extends ArrayAdapter<ResGoodsRecipe> { | |||
} | |||
} | |||
}); | |||
sort.addTextChangedListener(new TextWatcher() { | |||
@Override | |||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |||
} | |||
@Override | |||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |||
} | |||
@Override | |||
public void afterTextChanged(Editable editable) { | |||
String so=sort.getText().toString().trim().toString(); | |||
if(so.isEmpty()) | |||
{ | |||
T.show(view.getContext(), "不能为空!"); | |||
return; | |||
} | |||
resGoodsRecipe.sort=Integer.parseInt(so); | |||
datas.set(position,resGoodsRecipe); | |||
} | |||
}); | |||
value.addTextChangedListener(new TextWatcher() { | |||
@Override | |||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |||
} | |||
@Override | |||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |||
} | |||
@Override | |||
public void afterTextChanged(Editable editable) { | |||
String so=value.getText().toString().trim().toString(); | |||
if(so.isEmpty()) | |||
{ | |||
T.show(view.getContext(), "不能为空!"); | |||
return; | |||
} | |||
resGoodsRecipe.value=Integer.parseInt(so); | |||
datas.set(position,resGoodsRecipe); | |||
} | |||
}); | |||
name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |||
@Override | |||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { | |||
int index=name.getSelectedItemPosition(); | |||
if(index>=0) | |||
{ | |||
BPA_MATERIAL wljh= wllist.get(name.getSelectedItemPosition()); | |||
resGoodsRecipe.materialName=wljh.name; | |||
resGoodsRecipe.materialID=wljh.id; | |||
datas.set(position,resGoodsRecipe); | |||
}else | |||
{ | |||
T.show(view.getContext(), "不能为空!"); | |||
return; | |||
} | |||
} | |||
@Override | |||
public void onNothingSelected(AdapterView<?> adapterView) { | |||
int index=name.getSelectedItemPosition(); | |||
if(index>=0) | |||
{ | |||
BPA_MATERIAL wljh= wllist.get(name.getSelectedItemPosition()); | |||
resGoodsRecipe.materialName=wljh.name; | |||
resGoodsRecipe.materialID=wljh.id; | |||
datas.set(position,resGoodsRecipe); | |||
}else | |||
{ | |||
resGoodsRecipe.materialName=""; | |||
resGoodsRecipe.materialID=""; | |||
datas.set(position,resGoodsRecipe); | |||
T.show(view.getContext(), "不能为空!"); | |||
return; | |||
} | |||
} | |||
}); | |||
return view; | |||
} | |||
/** | |||
* 获取数据 | |||
* @return | |||
*/ | |||
public ArrayList<ResGoodsRecipe> GetDatas() | |||
{ | |||
return datas; | |||
} | |||
} |
@@ -48,6 +48,7 @@ public class sp_adapter extends ArrayAdapter<BPA_GOODS> { | |||
Button button_up = view.findViewById(R.id.button_item_Up); | |||
Button button_down = view.findViewById(R.id.button_item_Down); | |||
Button button_update = view.findViewById(R.id.button_item_update); | |||
Button button_xf = view.findViewById(R.id.button_xf); | |||
// 设置要显示的图片和文字 | |||
name.setText(bpa_goods.name); | |||
@@ -101,6 +102,18 @@ public class sp_adapter extends ArrayAdapter<BPA_GOODS> { | |||
} | |||
} | |||
}); | |||
button_xf.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; | |||
} | |||
} |
@@ -6,24 +6,30 @@ import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import android.widget.ImageView; | |||
import android.widget.LinearLayout; | |||
import android.widget.ListView; | |||
import android.widget.Spinner; | |||
import android.widget.TextView; | |||
import com.example.bpa.R; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.config.MessageName; | |||
import com.example.bpa.db.QueryDB; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.db.mode.BPA_GOODSRECIPE; | |||
import com.example.bpa.db.mode.BPA_MATERIAL; | |||
import com.example.bpa.helper.Json; | |||
import com.example.bpa.helper.T; | |||
import com.example.bpa.message.MessageManager; | |||
import com.example.bpa.view.adapter.pf_adapter; | |||
import com.example.bpa.view.adapter.sp_adapter; | |||
import com.example.bpa.view.inteface.MyClickListener; | |||
import com.example.bpa.view.mode.ResGoodsRecipe; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
public class add_pf_activity extends AppCompatActivity implements View.OnClickListener, MyClickListener { | |||
//region 变量 | |||
@@ -67,6 +73,7 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
* wulaipo | |||
*/ | |||
ArrayList<BPA_MATERIAL> wuliao=new ArrayList<>(); | |||
pf_adapter adapter=null; | |||
//endregion | |||
//region 私有函数 | |||
@@ -95,13 +102,15 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
String msg = getIntent().getStringExtra("title"); | |||
String data = getIntent().getStringExtra("data"); | |||
if (!data.isEmpty()) { | |||
T.show(this, data); | |||
good = new Json<BPA_GOODS>().jsonToobject(BPA_GOODS.class, data); | |||
edittext.setText(good.name); | |||
} | |||
gongneng_title.setText(msg); | |||
Initdata(); | |||
bpa_goods= QueryDB.GetGoodsALL(); | |||
wuliao=QueryDB.GetMaterialALL(); | |||
Initdata(); | |||
} | |||
/** | |||
@@ -121,7 +130,9 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
try { | |||
if (good != null)//修改 | |||
{ | |||
bpa_pf= QueryDB.GetGoodsSrecipeList(good.id); | |||
T.show(this, "查询物料数据" +good.id); | |||
bpa_pf= QueryDB.GetGoodsSrecipeList(good.id); | |||
DataTab(); | |||
} | |||
} catch (Exception e) { | |||
@@ -133,7 +144,7 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
*/ | |||
public void DataTab() | |||
{ | |||
pf_adapter adapter = new pf_adapter(add_pf_activity.this, R.layout.pf_item, bpa_pf,wuliao,this); | |||
adapter = new pf_adapter(add_pf_activity.this, R.layout.pf_item, bpa_pf,wuliao,this); | |||
datatab.setAdapter(adapter); | |||
} | |||
//endregion | |||
@@ -152,13 +163,29 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
this.finish(); | |||
break; | |||
case R.id.buttonaddwuliao://新增空白行 | |||
ResGoodsRecipe recipe=new ResGoodsRecipe(); | |||
ResGoodsRecipe recipe=new ResGoodsRecipe();//new 一个空对象 | |||
if(adapter!=null) bpa_pf=adapter.GetDatas(); | |||
recipe.sort=bpa_pf.size()+1; | |||
bpa_pf.add(recipe); | |||
DataTab(); | |||
break; | |||
case R.id.buttonsave://保存按钮点击 | |||
if(bpa_pf.size()<=0) | |||
if(adapter==null || bpa_pf.size()<=0) | |||
{ | |||
T.show(this, "配方不能为空!"); | |||
return; | |||
} | |||
bpa_pf=adapter.GetDatas(); | |||
for (int i=0;i<bpa_pf.size();i++){ | |||
ResGoodsRecipe pe=bpa_pf.get(i); | |||
if(pe.materialName.isEmpty()) | |||
{ | |||
T.show(this, "第"+i+"行,物料不能为空!"); | |||
return; | |||
} | |||
} | |||
List<ResGoodsRecipe> kd= bpa_pf; | |||
if(kd.size()<=0) | |||
{ | |||
T.show(this, "配方信息不能为空!"); | |||
return; | |||
@@ -188,7 +215,7 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
QueryDB.DeleteGoodsSrecipeList(good.id); | |||
} | |||
for (ResGoodsRecipe item:bpa_pf) | |||
for (ResGoodsRecipe item:kd) | |||
{ | |||
BPA_GOODSRECIPE da=new BPA_GOODSRECIPE(); | |||
da.goodsID = good.id; | |||
@@ -200,6 +227,7 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
QueryDB.AddGoodsSrecipe(da); | |||
} | |||
T.show(this, "操作成功!"); | |||
MessageManager.getInstance().sendMessage(MessageName.PF_From_Close.name(),"Close"); | |||
this.finish(); | |||
break; | |||
} | |||
@@ -210,16 +238,39 @@ public class add_pf_activity extends AppCompatActivity implements View.OnClickLi | |||
*/ | |||
@Override | |||
public void clickListener(View v, Object data) { | |||
ResGoodsRecipe wl=(ResGoodsRecipe)data; | |||
switch (v.getId()) { | |||
case R.id.button_item://删除 | |||
bpa_pf.remove(data); | |||
bpa_pf.remove(wl); | |||
DataTab(); | |||
break; | |||
case R.id.button_item_Up://上移动 | |||
if(wl.sort==1) | |||
{ | |||
T.show(this, "已是最顶部!"); | |||
return; | |||
} | |||
int dq=wl.sort; | |||
ResGoodsRecipe qt= bpa_pf.get(dq-1); | |||
qt.sort=dq; | |||
wl.sort=dq-1; | |||
bpa_pf.set(dq,qt); | |||
bpa_pf.set(dq-1,wl); | |||
DataTab(); | |||
break; | |||
case R.id.button_item_Down://下移动 | |||
if(wl.sort==bpa_pf.size()) | |||
{ | |||
T.show(this, "已是最底部!"); | |||
return; | |||
} | |||
int dq1=wl.sort; | |||
ResGoodsRecipe qt1= bpa_pf.get(dq1+1); | |||
qt1.sort=dq1; | |||
wl.sort=dq1+1; | |||
bpa_pf.set(dq1,qt1); | |||
bpa_pf.set(dq1+1,wl); | |||
DataTab(); | |||
break; | |||
} | |||
} | |||
@@ -6,17 +6,22 @@ import android.content.Intent; | |||
import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.View; | |||
import android.widget.AdapterView; | |||
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.app.BusinessServer; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.config.MessageName; | |||
import com.example.bpa.db.QueryDB; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.helper.Json; | |||
import com.example.bpa.helper.T; | |||
import com.example.bpa.message.MessageLooper; | |||
import com.example.bpa.message.MessageManager; | |||
import com.example.bpa.view.adapter.sp_adapter; | |||
import com.example.bpa.view.inteface.MyClickListener; | |||
@@ -75,7 +80,8 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList | |||
//通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 | |||
String msg=getIntent().getStringExtra("data"); | |||
gongneng_title.setText(msg); | |||
Initdata(); | |||
Initdata();//初始化数据 | |||
RegisterMessage();//消息中心事件接收 | |||
} | |||
/** | |||
@@ -165,11 +171,61 @@ public class yfpf_activity extends AppCompatActivity implements View.OnClickList | |||
break; | |||
case R.id.button_item_update://修改按钮 | |||
Intent intent = new Intent(this, add_pf_activity.class); | |||
intent.putExtra("title", "新建配方"); | |||
intent.putExtra("title", "修改配方"); | |||
intent.putExtra("data",new Json().objectToJson(BPA_GOODS.class,data)); | |||
startActivity(intent); | |||
break; | |||
case R.id.button_xf://下发按钮 | |||
BusinessServer.get().AddCommodity(((BPA_GOODS)data).id); | |||
T.show(this, "下发成功!"); | |||
break; | |||
} | |||
} | |||
//endregion | |||
//region 接收事件 | |||
public void RegisterMessage() | |||
{ | |||
//配方界面关闭事件 | |||
MessageManager.getInstance().registerMessageReceiver(this, MessageName.PF_From_Close.name(), new MessageLooper.OnMessageListener() { | |||
@Override | |||
public void onMessage(Object msg) { | |||
if (msg != null) { | |||
if(msg.equals("Close")) | |||
{ | |||
Initdata(); | |||
} | |||
}else | |||
{ | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
MessageManager.getInstance().registerMessageReceiver(this, MessageName.PF_From_Close.name(), new MessageLooper.OnMessageListener() { | |||
@Override | |||
public void onMessage(Object msg) { | |||
if (msg != null) { | |||
if(msg.equals("Close")) | |||
{ | |||
Initdata(); | |||
} | |||
}else | |||
{ | |||
runOnUiThread(new Runnable() { | |||
@Override | |||
public void run() { | |||
T.show(yfpf_activity.this,"服务器异常,请稍后重试!"); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
} | |||
//endregion | |||
} |
@@ -22,17 +22,16 @@ | |||
<Spinner | |||
android:id="@+id/name" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_height="match_parent" | |||
android:layout_centerVertical="true" | |||
android:layout_marginLeft="20dp" | |||
android:layout_alignParentLeft="true" | |||
android:inputType="text" | |||
android:padding="3dp" | |||
android:textColor="@color/foreground" | |||
android:theme="@style/MyEditText1" | |||
android:spinnerMode="dropdown" | |||
android:background="@drawable/round_corners_bg" | |||
android:hint="请输入序号" | |||
android:maxLines="1" | |||
android:textColor="@color/foreground" | |||
android:textSize="@dimen/textSize"/> | |||
</RelativeLayout> | |||
<RelativeLayout | |||
@@ -47,6 +46,7 @@ | |||
android:layout_marginLeft="20dp" | |||
android:layout_alignParentLeft="true" | |||
android:inputType="text" | |||
android:digits="0123456789" | |||
android:padding="3dp" | |||
android:textColor="@color/foreground" | |||
android:theme="@style/MyEditText1" | |||
@@ -67,6 +67,7 @@ | |||
android:layout_marginLeft="20dp" | |||
android:layout_alignParentLeft="true" | |||
android:inputType="text" | |||
android:digits="0123456789" | |||
android:padding="3dp" | |||
android:textColor="@color/foreground" | |||
android:theme="@style/MyEditText1" | |||
@@ -63,7 +63,7 @@ | |||
<RelativeLayout | |||
android:layout_width="0dp" | |||
android:layout_height="match_parent" | |||
android:layout_weight="2"> | |||
android:layout_weight="2.3"> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
@@ -111,6 +111,17 @@ | |||
android:layout_width="60dp" | |||
android:layout_height="26dp" | |||
/> | |||
<Button | |||
android:id="@+id/button_xf" | |||
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> | |||