| | |
| | | package com.lotaai.canguiayw; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.content.Context; |
| | | import android.graphics.Canvas; |
| | | import android.graphics.Color; |
| | |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.util.Log; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.Button; |
| | | import android.widget.ViewSwitcher; |
| | | |
| | | import androidx.core.content.ContextCompat; |
| | | import androidx.fragment.app.Fragment; |
| | |
| | | import com.bin.david.form.data.CellInfo; |
| | | import com.bin.david.form.data.column.Column; |
| | | import com.bin.david.form.data.format.IFormat; |
| | | import com.bin.david.form.data.format.bg.BaseCellBackgroundFormat; |
| | | import com.bin.david.form.data.format.bg.IBackgroundFormat; |
| | | import com.bin.david.form.data.format.bg.ICellBackgroundFormat; |
| | | import com.bin.david.form.data.format.selected.ISelectFormat; |
| | |
| | | import com.blankj.utilcode.util.LogUtils; |
| | | import com.blankj.utilcode.util.ScreenUtils; |
| | | import com.lotaai.canguiayw.common.SettingConfig; |
| | | import com.lotaai.canguiayw.device.DeviceMessage; |
| | | import com.lotaai.canguiayw.device.MessageType; |
| | | import com.lotaai.canguiayw.sqllitedb.GridModel; |
| | | import com.lotaai.canguiayw.sqllitedb.Order; |
| | | import com.lotaai.canguiayw.sqllitedb.OrderDetail; |
| | | import com.lotaai.canguiayw.sqllitedb.SqlliteDbManage; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | private View root; |
| | | private Context context; |
| | | private SmartTable setTable; |
| | | private SmartTable detailTable; |
| | | private ViewSwitcher bottomDetail; |
| | | private Button closeBtn; |
| | | private Button takeOutBtn; |
| | | private Order currentOrder; |
| | | |
| | | Column<String> gridNo = new Column<>("格子", "gridNo"); |
| | | Column<String> orderNo = new Column<>("订单号", "orderNo"); |
| | | Column<String> putIntime = new Column<>("放入时间", "putInDate"); |
| | | Column<String> xuhao = new Column<>("序号", "xuHao"); |
| | | |
| | | @Override |
| | | public void onCreate(Bundle savedInstanceState) { |
| | | EventBus.getDefault().register(this); |
| | | super.onCreate(savedInstanceState); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| | | public View onCreateView(LayoutInflater inflater, final ViewGroup container, |
| | | Bundle savedInstanceState) { |
| | | if (root == null) { |
| | | root = inflater.inflate(R.layout.framgment_selectorder, container, false); |
| | | } |
| | | context = container.getContext(); |
| | | bottomDetail = root.findViewById(R.id.bottom_detail); |
| | | detailTable = root.findViewById(R.id.detailtable); |
| | | closeBtn = root.findViewById(R.id.closeDetail); |
| | | takeOutBtn = root.findViewById(R.id.takeOut); |
| | | closeBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | if (detailTable != null) { |
| | | bottomDetail.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | }); |
| | | takeOutBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View view) { |
| | | //将格子释放 //将订单的格子号改为空 |
| | | if (currentOrder!=null && !"".equals(currentOrder.getGridNo())) { |
| | | GridModel model = SqlliteDbManage.getInstance().selectGridByGridNoStr(currentOrder.getGridNo()); |
| | | model.setState(0); |
| | | SqlliteDbManage.getInstance().addGrid(model); |
| | | currentOrder.setState(3); |
| | | SqlliteDbManage.getInstance().insertOrderInfo(currentOrder); |
| | | // mHandler.sendEmptyMessage(1); |
| | | initTableView(); |
| | | |
| | | LogUtils.i("订单:" + currentOrder.getOrderNo()); |
| | | }else { |
| | | LogUtils.i("没有订单"); |
| | | } |
| | | if (detailTable != null) { |
| | | bottomDetail.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | }); |
| | | initTableView(); |
| | | return root; |
| | | } |
| | | |
| | | public void initTableView(){ |
| | | Column<String> gridNo = new Column<>("格子", "gridNo"); |
| | | Column<String> orderNo = new Column<>("订单号", "orderNo"); |
| | | Column<String> putIntime = new Column<>("放入时间", "putInDate"); |
| | | Column<String> takeCode = new Column<>("取餐码", "takeCode"); |
| | | |
| | | List<Order> lists = SqlliteDbManage.getInstance().selectOrtdersByState(0); |
| | | |
| | | TableData<Order> tableData = new TableData<Order>("测试表格名字",lists,gridNo, orderNo, putIntime, takeCode); |
| | | public void initTableView() { |
| | | List<Order> lists = SqlliteDbManage.getInstance().selectOrtdersInGui(); |
| | | TableData<Order> tableData = null; |
| | | if (lists != null) { |
| | | tableData = new TableData<Order>("", lists, gridNo, orderNo, putIntime, xuhao); |
| | | }else { |
| | | tableData = new TableData<Order>("", new ArrayList<Order>(), gridNo, orderNo, putIntime, xuhao); |
| | | } |
| | | //设置数据 |
| | | setTable = root.findViewById(R.id.table); |
| | | setTable.getConfig().setShowTableTitle(false); |
| | | // // 设置表格标题名称文字样式 |
| | | // setTable.getConfig().setTableTitleStyle(new FontStyle(30, Color.GREEN)); |
| | | setTable.getConfig().setMinTableWidth(ScreenUtils.getScreenWidth()-20); |
| | | setTable.getConfig().setMinTableWidth(ScreenUtils.getScreenWidth() - 20); |
| | | // 设置表格标题文字样式 |
| | | setTable.getConfig().setColumnTitleStyle(new FontStyle(30,Color.WHITE)); |
| | | setTable.getConfig().setColumnTitleStyle(new FontStyle(30, Color.WHITE)); |
| | | |
| | | IBackgroundFormat backgroundFormat = new IBackgroundFormat() { |
| | | @Override |
| | |
| | | clickDetail(); |
| | | } |
| | | |
| | | public void clickDetail(){ |
| | | if (setTable!=null){ |
| | | public void clickDetail() { |
| | | if (setTable != null && setTable.getTableData() != null) { |
| | | setTable.getTableData().setOnRowClickListener(new TableData.OnRowClickListener() { |
| | | @Override |
| | | public void onClick(Column column, Object o, int col, int row) { |
| | | LogUtils.i("click row " + row); |
| | | final int rr = row; |
| | | public void onClick(Column column, Object o, int col, final int row) { |
| | | currentOrder = (Order) setTable.getTableData().getT().get(row); |
| | | showDetailTable(currentOrder); |
| | | LogUtils.i("click row:" + row + " col:" + col); |
| | | setTable.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat<CellInfo>() { |
| | | @Override |
| | | public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint) { |
| | | if(cellInfo.row!=rr){ |
| | | if (cellInfo.row != row) { |
| | | paint.setColor(Color.GRAY); |
| | | } else { |
| | | paint.setColor(getResources().getColor(R.color.cheng)); |
| | | } |
| | | else{ |
| | | paint.setColor(Color.BLUE); |
| | | } |
| | | canvas.drawRect(rect,paint); |
| | | canvas.drawRect(rect, paint); |
| | | mHandler.sendEmptyMessageDelayed(1, 200); |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private final Handler mHandler = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | mHandler.removeMessages(1); |
| | | setTable.notifyDataChanged(); |
| | | super.handleMessage(msg); |
| | | } |
| | | }; |
| | | |
| | | |
| | | public void showDetailTable(Order order) { |
| | | bottomDetail.setVisibility(View.VISIBLE); |
| | | Column<String> itemName = new Column<>("餐品", "itemName"); |
| | | Column<Integer> num = new Column<>("数量", "num"); |
| | | |
| | | List<OrderDetail> lists = SqlliteDbManage.getInstance().selectOrtderDetails(order.getOrderNo()); |
| | | TableData<OrderDetail> detailTableData = new TableData<OrderDetail>("", lists, itemName, num); |
| | | detailTable.getConfig().setShowTableTitle(false); |
| | | // // 设置表格标题名称文字样式 |
| | | // setTable.getConfig().setTableTitleStyle(new FontStyle(30, Color.GREEN)); |
| | | detailTable.getConfig().setMinTableWidth(750); |
| | | // 设置表格标题文字样式 |
| | | detailTable.getConfig().setColumnTitleStyle(new FontStyle(30, Color.WHITE)); |
| | | IBackgroundFormat backgroundFormat = new IBackgroundFormat() { |
| | | @Override |
| | | public void drawBackground(Canvas canvas, Rect rect, Paint paint) { |
| | | canvas.drawColor(getResources().getColor(R.color.DarkGray)); |
| | | } |
| | | }; |
| | | detailTable.getConfig().setColumnTitleBackground(backgroundFormat); |
| | | // 设置表格主体内容文字样式 |
| | | detailTable.getConfig().setContentStyle(new FontStyle(30, Color.WHITE)); |
| | | detailTable.getConfig().setShowXSequence(false); //去掉表格顶部字母 |
| | | detailTable.getConfig().setShowYSequence(false); //去掉左侧数字 |
| | | // 设置表格主标题 |
| | | detailTable.setTableData(detailTableData); |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.ASYNC) |
| | | public void recvCommand(DeviceMessage mssage) { |
| | | try { |
| | | if (mssage.getMessageType() == MessageType.NEWORDER.ordinal()) { |
| | | LogUtils.i("有新的订单进来"); |
| | | String orderNo = mssage.getMsgString(); |
| | | //首先要判断订单里面是否已经有了 |
| | | boolean isFind = false; |
| | | if (setTable.getTableData()!=null) { |
| | | List<Order> oldOrders = setTable.getTableData().getT(); |
| | | |
| | | if (oldOrders != null && oldOrders.size() > 0) { |
| | | for (int p = 0; p < oldOrders.size(); p++) { |
| | | Order t = oldOrders.get(p); |
| | | if (t.getOrderNo().equals(orderNo)) { |
| | | isFind = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (isFind == false) { |
| | | //查询订单信息 |
| | | Order orderInfo = SqlliteDbManage.getInstance().selectOrtder(orderNo); |
| | | List<Order> pp = new ArrayList<>(); |
| | | pp.add(orderInfo); |
| | | setTable.addData(pp, true); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | LogUtils.e(e); |
| | | } |
| | | } |
| | | } |