FrmPutCom.cs 9.5 KB
using PUSICANLibrary;
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;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using TSA_V.LoadCSVLibrary;

namespace TSA_V
{
    public partial class FrmPutCom : FrmBase
    {

        private string bomName = "";
        private StockInfo Work = new StockInfo();
        private TSAVPosition currPosition = null;
        ComponetInfo currCom = new ComponetInfo();
        private List<ComponetInfo> oldConList = new List<ComponetInfo>();
        private List<ComponetInfo> comList = null;
        private int currIndex = 0;
        public FrmPutCom()
        {
            InitializeComponent();
        }
        private void FrmPutCom_Load(object sender, EventArgs e)
        {
            LanguageProcess();
            TSAVBean.IsInPut = true;
            Work.StartWork();
            SetScreen();
            timer1.Enabled = true;
        }

        public bool  SetOperateInfo(string bomName, List<ComponetInfo> list)
        {
            oldConList = list;
            comList = new List<ComponetInfo>();
            List<string> positinList = new List<string>();
            foreach (ComponetInfo obj in list)
            {
                if (positinList.Contains(obj.PositionNum))
                {

                }
                else
                {
                    positinList.Add(obj.PositionNum);
                    comList.Add(obj);
                }
            }

            //排序
            comList = (from m in comList orderby m.GetPosition() ascending select m).ToList();
            this.bomName = bomName;
            this.Text = "元器件库【" + bomName + "】备料中";
            LogUtil.info("开始备料:元器件库【" + bomName + "】");
            if (comList.Count <= 0)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ConotFindCom,"未找到需要备料的元器件!"));
                return false;
            }
            currIndex = 0;
            ShowCom();
            if (TSAVBean.Status <= TSAVStatus.Wait)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DeviceNotOk,"设备未连接,无法备料!"));
             return false ;
            }
            else if (TSAVBean.Status.Equals(TSAVStatus.Reset))
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.DeviceInReset,"设备正在重置中,请稍后再备料!"));
                return false;
            }
            return true;
        }

        private void ShowCom()
        {
            if (currIndex < 0)
            {
                currIndex = 0;
            }
            if (currIndex >= comList.Count)
            {
                currIndex = comList.Count - 1;
            }

            currCom = comList[currIndex];
            currPosition = CSVPositionReader<TSAVPosition>.GetPositonByNum(currCom.PositionNum);
            this.txtName.Text = currCom.ComponentName;
            this.txtNum.Text = currCom.ComCount.ToString();
            this.txtPartNum.Text = currCom.PartNum;
            this.txtPosition.Text = currCom.PositionNum;
            this.txtDes.Text = currCom.ComponentDes;
            if (CurrLanguage.Equals(ResourceCulture.China))
            {
                lblEndInfo.Text = "已完成" + currIndex + "个";
                this.lblLeftInfo.Text = "剩余" + (comList.Count - 1 - currIndex) + "个";
            }
            else
            {
                lblEndInfo.Text = "" + currIndex + "/" + (comList.Count - 1 - currIndex)   ;
                this.lblLeftInfo.Text = " ";
            }
            //lblEndInfo.Text = "已完成" + currIndex + "个";
            //this.lblLeftInfo.Text = "剩余" + (comList.Count - 1 - currIndex) + "个";
            LogUtil.info("正在备料中:元器件库【" + bomName + "】位号【" + currCom.PartNum + "】物料编号【" + currCom.ComponentName + "】料盘编号【" + currCom.PositionNum + "】");
            if (currIndex.Equals(0))
            {
                btnPre.Enabled = false;
                btnNext.Enabled = true;
            }
            else if (currIndex.Equals(comList.Count - 1))
            {
                btnPre.Enabled = true;
                btnNext.Enabled = false;
            }
            else
            {
                btnPre.Enabled = true;
                btnNext.Enabled = true;
            }
            if (currPosition == null)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.CanotFindPosition, "未找到物料编号【{0}】的坐标", currCom.PositionNum));
            }
            else if (TSAVBean.Status.Equals(TSAVStatus.Runing))
            {
                Work.MoveToBag(currPosition);
            }
        }
        private void btnPre_Click(object sender, EventArgs e)
        {
            if (!Work.IsWaitMove)
            {
                currIndex--;
                ShowCom();
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (!Work.IsWaitMove)
            {
                currIndex++;
                ShowCom();

            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            // 按快捷键Ctrl+S执行按钮的点击事件方法

            if (keyData.Equals(Keys.Up) || keyData.Equals(Keys.MButton | Keys.Space))
            {
                if (btnPre.Enabled)
                {
                    btnPre.PerformClick();
                }
                return true;
            }
            else if (keyData.Equals(Keys.Down) || keyData.Equals(Keys.Back | Keys.Space))
            {
                if (btnNext.Enabled)
                {
                    this.btnNext.PerformClick();
                }
                return true;
            }
            else if (keyData.Equals(Keys.Left) || keyData.Equals(Keys.LButton | Keys.MButton | Keys.Space))
            {
                if (btnPre.Enabled)
                {
                    btnPre.PerformClick();
                }
                return true;
            }
            else if (keyData.Equals(Keys.Right) || keyData.Equals(Keys.LButton | Keys.RButton | Keys.MButton | Keys.Space))
            {
                if (btnNext.Enabled)
                {
                    this.btnNext.PerformClick();
                }
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData); // 其他键按默认处理 
        }
        private void btnSaveCount_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            int newCount = FormUtil.GetIntValue(txtNum);
            if (newCount <= 0)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteNum,"请输入正确的数量!"));
                txtNum.Focus();
                return;
            }
            ComponetInfo com = comList[currIndex];

            //需要循环所有此库位的
            foreach (ComponetInfo obj in oldConList)
            {
                if (obj.PositionNum.Equals(com.PositionNum))
                {
                    obj.ComCount = newCount;
                }
            }

            CSVBomManager.SaveComponet(bomName, oldConList);
        }

        private void FrmPutCom_FormClosing(object sender, FormClosingEventArgs e)
        {
            LogUtil.info("结束备料:元器件库【" + bomName + "】");
            timer1.Enabled = false;
            if (TSAVBean.Status > TSAVStatus.Reset)
            {
                Work.StopWork();
            }
            TSAVBean.IsInPut = false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Work.IsWorking)
            {
                if (Work.IsWaitMove)
                {
                    lblMoveStr.Text =ResourceCulture.GetString( ResourceCulture.GetTextIdStr(ClassName, lblMoveStr.Name),"移动中");
                    CheckWorkWait();
                }
                else if (IOManager.IOValue(IOManager.Footrest_Single).Equals(IO_VALUE.HIGH))
                {
                    btnNext.PerformClick();
                }

                if (!Work.IsWaitMove)
                { 
                    lblMoveStr.Text = "已到位";
                }
            }
           
        }
        private void CheckWorkWait()
        {
            string waitMsg = "";
            List<WaitResultInfo> list = Work.waitList;
            //当等待超过一分钟时,需要打印提示 
            TimeSpan span = DateTime.Now - Work.LastSetpTime;

            bool isOk = WaitResultInfo.GetWaitResult(list, span,false, out waitMsg);
            if (isOk)
            {
                Work.EndWait();
            }
            else
            {
                if (span.TotalMinutes > 1)
                {
                    waitMsg = "等待【" + waitMsg + "】超时 已等待【" + span.TotalMinutes.ToString() + "】分钟,";
                    foreach (WaitResultInfo wait in list)
                    {
                        waitMsg = waitMsg + "\r\n" + wait.ToStr();
                    }
                    LogUtil.error(waitMsg);
                }
            }
        }

        private void FrmPutCom_Shown(object sender, EventArgs e)
        { 
        }

    }
}