using Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace MeterModuleLibrary
{
    public partial class ucCarMeterInfo2 : UserControl
    {
        public ucCarMeterInfo2()
        {
            InitializeComponent();
        }

        public void setFormControlValue(MeterWorkCarActualFirst first)
        {
            txtPREDICTION_NO.Text = first.predictionNo;
            //检斤类型?????????????????
            txtBATCH_NO.Text = first.batchNo;
            txtMATTER_NAME.Text = first.matterName;
            txtFORWARDING_UNIT_NAME.Text = first.forwardingUnitName;
            txtRECEIVING_UINT_NAME.Text = first.receivingUintName;
            txtMETER_TYPE.Text = first.meterTypeName;
        }

        public PreTrackScale _preTrack { get; set; }

        public void setFormControlValue(PreTrackScale preTrack)
        {
            _preTrack = preTrack;
            txtPREDICTION_NO.Text = preTrack.predictionNo;
            //检斤类型?????????????????
            txtBATCH_NO.Text = preTrack.batchNo;
            txtMATTER_NAME.Text = preTrack.matterName;
            txtFORWARDING_UNIT_NAME.Text = preTrack.forwardingUnitName;
            txtRECEIVING_UINT_NAME.Text = preTrack.receivingUintName;
            txtMETER_TYPE.Text = preTrack.meterTypeName;

            //2021年5月10日界面显示单位，调整为T
            //lbWgt.Text = (preTrack.meterWeight == null ? 0 : preTrack.meterWeight / 1000) + "";
            if (("4".Equals(preTrack.valueFlag) && "销售出厂".Equals(preTrack.meterTypeName))
                || ("1".Equals(preTrack.valueFlag) && "采购进厂".Equals(preTrack.meterTypeName)))
            {
                lbWgt.Text = (preTrack.shipmentGrossWeight  == null ? 0 : Math.Round((double)preTrack.shipmentGrossWeight / 1000, 2)) + "";
            }
            else
            {
                lbWgt.Text = (preTrack.shipmentNetWeight == null ? 0 : Math.Round((double)preTrack.shipmentNetWeight / 1000, 2)) + "";
            }

            if (PbCache.limit != null && PbCache.limit.Count > 0)
            {
                List<MeterBaseLimitChemical> mblc = PbCache.limit.Where(s => s.matterNo == preTrack.matterNo).ToList();
                //该物料是危化品
                if (mblc.Count > 0)
                {
                    //2021年5月10日界面显示单位，调整为T
                    lbZL.Text = mblc[0].limitWeight == null ? "0" : Math.Round(mblc[0].limitWeight.Value / 1000, 2) + "";
                    cbWhp.Checked = true;

                    lbXZ.Text = mblc[0].limitTypeName;
                }
                else
                {
                    lbZL.Text = "0";
                    cbWhp.Checked = false;
                    lbXZ.Text = "";
                }
            }

            cbQy.Checked = !string.IsNullOrEmpty(preTrack.sampleNo);
        }

        public void setMeterType(string meterType)
        {
            txtMETER_TYPE.Text = meterType;
        }
    }
}