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

namespace CowainHmi.ProductionQty
{
    public partial class DlgProductionTimeEdit : Form
    {
        private int plcId;
        private List<string> timeAddrs;
        private List<string> shiftTimeDuration = new List<string>();
        public DlgProductionTimeEdit(int plcId, List<string> timeAddrs)
        {
            InitializeComponent();
            this.plcId = plcId;
            this.timeAddrs = timeAddrs;
            if (timeAddrs == null || timeAddrs.Count != 6)
            {
                MessageBox.Show("时间参数不正常", "提示");
                this.Close();
                return;
            }
          
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[0], this.txtStartA.Text);
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[1], this.txtEndA.Text);
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[2], this.txtStartB.Text);
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[3], this.txtEndB.Text);
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[4], this.txtStartC.Text);
            PCHMI.RT.SEND_SIEMENS_STRING(plcId, timeAddrs[5], this.txtEndC.Text);
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private async void DlgProductionTimeEdit_Load(object sender, EventArgs e)
        {
            foreach (string timeAddr in timeAddrs)
            {
                PCHMI.VL.GET_SIEMENS_STRING(plcId, timeAddr, 4);
            }
            await Task.Delay(300);
            foreach (string timeAddr in timeAddrs)
            {
                var t = PCHMI.VL.GET_SIEMENS_STRING(plcId, timeAddr, 4);
                shiftTimeDuration.Add(t);
            }
            this.txtStartA.Text = shiftTimeDuration[0];
            this.txtEndA.Text = shiftTimeDuration[1];
            this.txtStartB.Text = shiftTimeDuration[2];
            this.txtEndB.Text = shiftTimeDuration[3];
            this.txtStartC.Text = shiftTimeDuration[4];
            this.txtEndC.Text = shiftTimeDuration[5];
        }
    }
}
