FrmPointInfo.cs 10.6 KB
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 MetroFramework.Forms;
using TSA_V.DeviceLibrary;
using TSA_V.Common;
using PUSICANLibrary;
using TSA_V.LoadCSVLibrary;
using AccAOI;

namespace TSA_V
{
    public partial class FrmPointInfo : FrmBase
    {
        public delegate void NextDel(int index, SMTPointInfo smt=null);
        public event NextDel NextEvent;
        public bool IsUpdate = false;
        public SMTPointInfo smtPointInfo = new SMTPointInfo();
        public BoardInfo boardInfo = null;
        public string AoiProgramName = "";
        public Image PicImage = null; 
        public FrmPointInfo(string name, double x, double y, double nodex, double nodey)
        {
            InitializeComponent();
            loadPositionList();
            this.Text = "新增组装信息";
            this.txtNum.Enabled = true;
            this.txtName.Text = name; 
            //if (cmbPositionNumList.Items.Count > 0)
            //{
            //    cmbPositionNumList.SelectedIndex = 0;
            //}
            //this.txtRobotX.Text = nodex.ToString();
            //txtRobotY.Text = nodey.ToString();
            xyMoveControl1.ShowPointEvent += XyMoveControl1_ShowPointEvent;
            xyMoveControl1.XValue = nodex;
            xyMoveControl1.YValue = nodey;
            
            this.txtX.Text = x.ToString();
            this.txtY.Text = y.ToString();

        }

        private bool XyMoveControl1_ShowPointEvent(ProjectorPInfo p)
        { 
            FrmProjectorScreen.instance.ClearPoint();
            FrmProjectorScreen.instance.ShowPoint(p);
            return true;
        }

        private List<TSAVPosition> allPosition = new List<TSAVPosition>(CSVPositionReader<TSAVPosition>.allPositionMap.Values);
        private void loadPositionList()
        {

            //cmbPositionNumList.DataSource = null;
            //cmbPositionNumList.DataSource = allPosition;
            //cmbPositionNumList.DisplayMember = "PositionNum";
            //cmbPositionNumList.ValueMember = "PositionNum";
        }
         
        public List<SMTPointInfo> PointList = new List<SMTPointInfo>();
        public int CurrIndex = -1;
        public FrmPointInfo( BoardInfo board, List<SMTPointInfo> list, int currIndex,NextDel fun=null)
        {
            this.boardInfo = board;
            this.NextEvent += fun;
            InitializeComponent();
            if (list.Count <= 0 || (currIndex < 0) || (currIndex >= list.Count))
            {
                return;
            } 
            xyMoveControl1.ShowPointEvent += XyMoveControl1_ShowPointEvent;
            this.PointList = list;
            this.CurrIndex = currIndex;
            ShowPoint();
        }

        private void ShowPoint()
        {
            this.smtPointInfo = PointList[CurrIndex];
            this.txtNum.Enabled = false;
            this.Text = "修改组装信息【" + smtPointInfo.pointName + "】 ";
            loadPositionList();

            this.txtName.Text = smtPointInfo.pointName;

            int index = -1;
            int selPosIndex = -1;
            foreach (TSAVPosition p in allPosition)
            {
                index++;
                if (p.PositionNum.Equals(smtPointInfo.PositionNum))
                {
                    selPosIndex = index;
                    break;
                }
            }
            index = -1; selPosIndex = -1;
            foreach (TSAVPosition p in allPosition)
            {
                index++;
                if (p.PositionNo.ToString().Equals(smtPointInfo.PositionNum))
                {
                    selPosIndex = index;
                    break;
                }
            } 
            //this.txtRobotX.Text = smpPointInfo.NodePositionX.ToString();
            //txtRobotY.Text = smpPointInfo.NodePositionY.ToString();
            xyMoveControl1.XValue = smtPointInfo.NodePositionX;
            xyMoveControl1.YValue = smtPointInfo.NodePositionY;
            xyMoveControl1.PointType = smtPointInfo.PointType;
            xyMoveControl1.PointSizeX = smtPointInfo.PointSizeX;
            xyMoveControl1.PointSizeY = smtPointInfo.PointSizeY;
            xyMoveControl1.PenWidth = smtPointInfo.PenWidth;
            xyMoveControl1.ShowText = smtPointInfo.ShowText;
            xyMoveControl1.ShowCurrPoint();
            this.txtX.Text = smtPointInfo.PositionX.ToString();
            this.txtY.Text = smtPointInfo.PositionY.ToString();
            this.txtNum.Text = smtPointInfo.PartNum;
            this.chbNeedCheck.Checked = smtPointInfo.NeedCheck;
            this.chbNeedSoldering.Checked = smtPointInfo.NeedSoldering;
            this.txtWeldTemp.Text = smtPointInfo.WeldTemp.ToString();
            this.txtWeldTime.Text = smtPointInfo.WeldTime.ToString();
            chbCheck.Checked = smtPointInfo.CheckOK;
            lblNotes.Text = "";
            if (boardInfo != null)
            {
                ComponetInfo com = CSVBomManager.GetCom(boardInfo.bomName, smtPointInfo.PartNum);
                if (com != null)
                {
                   lblNotes.Text = com.Notes;
                }
            } 

            if (CurrIndex < PointList.Count - 1)
            {
                btnSaveAndNext.Enabled = true;
            }
            else
            {
                btnSaveAndNext.Enabled = false;
            }
            if (CurrIndex > 0)
            {
                btnPre.Enabled = true;
            }
            else
            {
                btnPre.Enabled = false;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (saveInfo())
            {
                closeForm();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        private bool saveInfo()
        {
            //if (cmbPositionNumList.SelectedIndex < 0)
            //{
            //    MessageBox.Show(ResourceCulture.GetString(ResourceCulture.ChoiceComPosition, "请选择元器件所在位置!"));
            //    cmbPositionNumList.Focus();
            //    return false;
            //}
            string name = FormUtil.getValue(txtName);
            if (name.Equals(""))
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteName, "请输入物料编码!"));
                txtName.Focus();
                return false;
            }
            smtPointInfo.PartNum = FormUtil.getValue(txtNum);
            if (smtPointInfo.PartNum.Equals(""))
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePartNumber, "请输入位号!"));
                txtNum.Focus();
                return false;
            }

            smtPointInfo.pointName = name;

            smtPointInfo.PositionX = FormUtil.getDoubleValue(txtX);
            smtPointInfo.PositionY = FormUtil.getDoubleValue(txtY);
            smtPointInfo.NodePositionX = xyMoveControl1.XValue;
            smtPointInfo.NodePositionY = xyMoveControl1.YValue;
            smtPointInfo.PointType = xyMoveControl1.PointType;
            smtPointInfo.PointSizeX = xyMoveControl1.PointSizeX;
            smtPointInfo.PointSizeY = xyMoveControl1.PointSizeY;
            smtPointInfo.PenWidth = xyMoveControl1.PenWidth;
            smtPointInfo.ShowText = xyMoveControl1.ShowText;
            //smtPointInfo.NodePositionX = FormUtil.getDoubleValue(txtRobotX);
            //smtPointInfo.NodePositionY = FormUtil.getDoubleValue(txtRobotY);
            smtPointInfo.NeedSoldering = chbNeedSoldering.Checked;
            smtPointInfo.NeedCheck = chbNeedCheck.Checked;
            smtPointInfo.WeldTime = FormUtil.getDoubleValue(txtWeldTime);
            smtPointInfo.WeldTemp = FormUtil.GetIntValue(txtWeldTemp);
            smtPointInfo.CheckOK = chbCheck.Checked;
            if (smtPointInfo.NeedSoldering && smtPointInfo.WeldTemp <= 0)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteRightTemp, "请输入正确的焊接温度!"));
                return false;
            } if (smtPointInfo.NeedSoldering && smtPointInfo.WeldTime <= 0)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteRightTime,"请输入正确的焊接时间!"));
                return false;
            }
            //TSAVPosition position = (TSAVPosition)cmbPositionNumList.SelectedItem;
            //smtPointInfo.PositionNum = position.PositionNum;
            //    this.DialogResult = DialogResult.OK;
            if (this.PointList.Count > 0 && CurrIndex >= 0)
            {
                PointList[CurrIndex] = smtPointInfo;
            }
            IsUpdate = true;
            return true;
        }

        private void closeForm()
        {
            this.Close();
        }
     
        private void FrmPointInfo_Load(object sender, EventArgs e)
        {
            LanguageProcess();

            timer1.Enabled = true; 
        }
        

        private void timer1_Tick(object sender, EventArgs e)
        {
            xyMoveControl1.UpdateStatus();
        }

        private void FrmPointInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            timer1.Enabled = false;
        }

        private void FrmPointInfo_Shown(object sender, EventArgs e)
        {

            SetSkin(this);
        }

        public TSAVBean CSVPositionReader { get; set; }

        private void btnSaveAndNext_Click(object sender, EventArgs e)
        {
            if (saveInfo())
            {
                SMTPointInfo prePoint = PointList[CurrIndex];
                CurrIndex++;
                if (PointList.Count > CurrIndex)
                {
                    ShowPoint();
                    NextEvent?.Invoke(CurrIndex,prePoint);
                }
            }
        }

        
        private void btnPre_Click(object sender, EventArgs e)
        {
            CurrIndex--;
            if (CurrIndex < 0)
            {
                CurrIndex = 0;
            }
            if (PointList.Count > CurrIndex)
            {
                ShowPoint();
                NextEvent?.Invoke(CurrIndex);
            }
        }

        private void btnConfigAOI_Click(object sender, EventArgs e)
        {
            AccAOI.AOIResourceCulture.SetCurrentCulture(ResourceCulture.CurrLanguage);
            string path = Application.StartupPath + ConfigAppSettings.GetValue(Setting_Init.AOIFileConfig);
            FrmAoiSetting frm = new FrmAoiSetting(path+AoiProgramName, PicImage,path); 
            frm.ShowDialog();
        }
    }
}