package com.bonait.bnframework.modules.home.fragment.mode;

import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class fragment_silos_cl extends LinearLayout {
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.update_lc)
    Button update_lc;
    @BindView(R.id.edittext_lc)
    EditText edittext_lc;
    private View root;
    public fragment_silos_cl(Context context, @Nullable AttributeSet attrs, BPA_SILOS _model) {
        super(context, attrs);
        root= LayoutInflater.from(context).inflate(R.layout.fragment_item_silos_cl, this);
        ButterKnife.bind(this, root);
        model=_model;
        name.setText("料仓" + model.num+"号");
    }
    public BPA_SILOS model=null;

    @OnClick({R.id.update_lc})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.update_lc:
                String text=edittext_lc.getText().toString();
                if(text.isEmpty())
                {
                    ToastUtils.warning("需求值为空！");
                    return;
                }

                int val1 = (int)Math.round((Double.parseDouble(text) * 10));

                Short val=(short)val1;
                ExecuteTheRecipe.WritePLC("料仓" + model.num + "需求值", val, new IWriteCallBack() {
                    @Override
                    public void onSuccess() {
                        ExecuteTheRecipe.WritePLC("料仓" + model.num + "下料",true,null);
                    }
                    @Override
                    public void onFailure(String ErrorMsg) {
                    }
                });
                ToastUtils.info("料仓" + model.num+"出料:"+text+"g");
                break;
        }
    }
}