using AR;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Project.Dialog
{
    public partial class fManualPrint0 : Form
    {
        public Class.Reel reelinfo = null;
        public string NewID { get; set; }

        [Flags]
        public enum eOpt : byte
        {
            reelid = 1,
            sid = 2,
            vlot = 4,
            vname = 8,
            partno = 16,
            qty = 32,
            mfg = 64,
        }

        public fManualPrint0()
        {
            InitializeComponent();
            SetControlStates(eOpt.reelid | eOpt.sid | eOpt.vlot | eOpt.vname | eOpt.partno | eOpt.qty | eOpt.mfg);
        }

        /// <summary>
        /// 사용하고자하는 컨트롤을 or 값으로 전달해주세요
        /// </summary>
        /// <param name="enabledOptions"></param>

        public fManualPrint0(eOpt enabledOptions)
        {
            InitializeComponent();
            SetControlStates(enabledOptions);
        }

        private void SetControlStates(eOpt enabledOptions)
        {
            tbRid.Enabled = enabledOptions.HasFlag(eOpt.reelid);
            tbRid.BackColor = tbRid.Enabled ? Color.White : Color.LightGray;

            tbSid.Enabled = enabledOptions.HasFlag(eOpt.sid);
            tbSid.BackColor = tbSid.Enabled ? Color.White : Color.LightGray;

            tbVLot.Enabled = enabledOptions.HasFlag(eOpt.vlot);
            tbVLot.BackColor = tbVLot.Enabled ? Color.White : Color.LightGray;

            tbVName.Enabled = enabledOptions.HasFlag(eOpt.vname);
            tbVName.BackColor = tbVName.Enabled ? Color.White : Color.LightGray;

            tbPartNo.Enabled = enabledOptions.HasFlag(eOpt.partno);
            tbPartNo.BackColor = tbPartNo.Enabled ? Color.White : Color.LightGray;

            tbQty.Enabled = enabledOptions.HasFlag(eOpt.qty);
            tbQty.BackColor = tbQty.Enabled ? Color.White : Color.LightGray;

            tbMFGDate.Enabled = enabledOptions.HasFlag(eOpt.mfg);
            tbMFGDate.BackColor = tbMFGDate.Enabled ? Color.White : Color.LightGray;
        }
        private void fNewReelID_Load(object sender, EventArgs e)
        {
            if (PUB.Result != null && PUB.Result.ItemDataC != null)
            {
                var vdata = PUB.Result.ItemDataC.VisionData;
                this.tbRid.Text = vdata.RID;
                this.tbVLot.Text = vdata.VLOT;
                this.tbVName.Text = vdata.VNAME;
                this.tbPartNo.Text = vdata.PARTNO;
                this.tbQty.Text = vdata.QTY;
                this.tbSid.Text = vdata.SID;
                this.tbMFGDate.Text = vdata.MFGDATE;
            }
            
        }

        private void btOK_Click(object sender, EventArgs e)
        {

            int qty = 0;
            int.TryParse(tbQty.Text, out qty);
            string rid, lot, manu, mfg, partnum, sid;
            rid = lot = manu = mfg = sid = partnum = "";
            rid = tbRid.Text.Trim();
            sid = tbSid.Text.Trim();
            mfg = tbMFGDate.Text.Trim();
            partnum = tbPartNo.Text.Trim();
            lot = tbVLot.Text.Trim();
            manu = tbVName.Text.Trim();
            reelinfo = new Class.Reel
            {
                id = rid,
                venderLot = lot,
                venderName = manu,
                mfg = mfg,
                PartNo = partnum,
                qty = qty,
                SID = sid,
            };
            DialogResult = DialogResult.OK;

        }

    }
}
