FrmPointInfo.cs 13.1 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;
        internal bool updateOK = false; 
        internal SMTPointInfo smtPointInfo = new SMTPointInfo();
        internal BoardInfo boardInfo = null;
        internal string AoiProgramName = "";
        internal Image PicImage = null;

        internal bool isNewPoint = false;

        public FrmPointInfo(BoardInfo board, string name, double x, double y, double nodex, double nodey)
        {
            InitializeComponent();
            loadPositionList();
            this.boardInfo = board;
            isNewPoint = true;
            this.Text = "新增组装信息";
            this.txtTagNo.Text = name;
            updateFrom(true);
            xyMoveControl1.ShowPointEvent += XyMoveControl1_ShowPointEvent;
            xyMoveControl1.XValue = nodex;
            xyMoveControl1.YValue = nodey;
            
            this.txtX.Text = x.ToString();
            this.txtY.Text = y.ToString();


            string str7 = ResourceCulture.GetString(ResourceCulture.Type7, "极性_上方");
            string str8 = ResourceCulture.GetString(ResourceCulture.Type8, "极性_下方");
            string str9 = ResourceCulture.GetString(ResourceCulture.Type9, "极性_左方");
            string str10 = ResourceCulture.GetString(ResourceCulture.Type10, "极性_右方");
            string[] typeList = new string[] {
            "1=●",
            "2=✚",
            "3=┃",
            "4=━━",
            "5=□",
            "6=○",
            "7="+str7,
            "8="+str8,
            "9="+str9,
            "10="+str10

            };
            xyMoveControl1.loadTypeList(typeList);

        }
        private void updateFrom(bool isNew)
        {
            this.txtPn.Enabled = false;
            this.txtTagNo.Enabled = isNew;
            btnSaveAndNext.Visible = !isNew;
            this.txtPn.Visible = !isNew;
            cmbPnList.Visible = isNew;
            this.txtPn.Text = "";
            if (isNew)
            {

                List<string> pnList = new List<string>();
                List<ComponetInfo> list = CSVBomManager.GetComList(this.boardInfo.bomName);
                foreach (ComponetInfo obj in list)
                {
                    if (!pnList.Contains(obj.PN))
                    {
                        pnList.Add(obj.PN);
                    }
                }
                cmbPnList.Items.Clear();
                cmbPnList.DataSource = pnList;
            }

        }
        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();

            string str7 = ResourceCulture.GetString(ResourceCulture.Type7, "极性_上方");
            string str8 = ResourceCulture.GetString(ResourceCulture.Type8, "极性_下方");
            string str9 = ResourceCulture.GetString(ResourceCulture.Type9, "极性_左方");
            string str10 = ResourceCulture.GetString(ResourceCulture.Type10, "极性_右方");
            string[] typeList = new string[] {
            "1=●",
            "2=✚",
            "3=┃",
            "4=━━",
            "5=□",
            "6=○",
            "7="+str7,
            "8="+str8,
            "9="+str9,
            "10="+str10

            };
            xyMoveControl1.loadTypeList(typeList);
        }

        private void ShowPoint()
        {
            updateFrom(false);
            btnSave.Visible = true;
            this.smtPointInfo = PointList[CurrIndex];
            this.Text = "修改组装信息【" + smtPointInfo.PN + "】 ";
            loadPositionList();

            this.txtPn.Text = smtPointInfo.PN;

            //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.txtTagNo.Text = smtPointInfo.TagNo;
            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);
                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 (isNewPoint)
            {
                smtPointInfo = new SMTPointInfo();
                smtPointInfo.pointNum = boardInfo.GetNextPNum();
            }

            string pn = FormUtil.getValue(txtPn);
            if (pn.Equals(""))
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WriteName, "请输入物料编码!"));
                txtPn.Focus();
                return false;
            } 

            string tagNo = FormUtil.getValue(txtTagNo);
            if (tagNo.Equals(""))
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePartNumber, "请输入位号!"));
                txtTagNo.Focus();
                return false;
            }
            List<SMTPointInfo> pos = (from m in boardInfo.smtList where m.pointNum != smtPointInfo.pointNum && m.TagNo.Equals(tagNo) select m).ToList();
            if (pos.Count > 0)
            {
                MessageBox.Show(ResourceCulture.GetString(ResourceCulture.WritePartNumber, "请输入位号!"));
                txtTagNo.Text = smtPointInfo.TagNo;
                txtTagNo.Focus();
                return false;
            }
            smtPointInfo.PN = pn;
            smtPointInfo.TagNo = tagNo;
            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.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;
            }
            if (isNewPoint)
            {
                ComponetInfo com = CSVBomManager.GetCom(boardInfo.bomName, smtPointInfo);
                if (com != null)
                {
                    smtPointInfo.PositionNum = com.PositionNum;
                }
                boardInfo.smtList.Add(smtPointInfo); 
                this.DialogResult = DialogResult.OK;
                closeForm();
                return true;
            }
            else
            {
                if (String.IsNullOrEmpty(smtPointInfo.PositionNum))
                {
                    ComponetInfo com = CSVBomManager.GetCom(boardInfo.bomName, smtPointInfo);
                    if (com != null)
                    {
                        smtPointInfo.PositionNum = com.PositionNum;
                    }
                }
                if (this.PointList.Count > 0 && CurrIndex >= 0)
                {
                    PointList[CurrIndex] = smtPointInfo;
                }
                updateOK = 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();
        }

        private void cmbPnList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPnList.SelectedIndex >= 0)
            {
                txtPn.Text = cmbPnList.Text;
            }
        }
    }
}