FrmBoardList.cs 10.1 KB
using log4net; 
using URSoldering.DeviceLibrary;
using System;
using System.Collections.Generic; 
using System.Data;
using System.Drawing; 
using System.Linq;
using System.Reflection; 
using System.Windows.Forms;

namespace URSoldering.Client
{
    public partial class FrmBoardList : FrmBase
    {
        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmBoardList()
        {
            InitializeComponent();
        }

        private void FrmBoard_Load(object sender, EventArgs e)
        { 
            LoadCom();
        }
        private void LoadCom()
        {
            List<BoardInfo> newList = (from m in BoardManager.boardList orderby m.PartNumber ascending, m.boardName ascending select m).ToList<BoardInfo>();
            cmbBoardList.DataSource = null;
            cmbBoardList.DataSource = newList;
            cmbBoardList.DisplayMember = "boardName";
            cmbBoardList.ValueMember = "boardId";
            if (newList.Count > 0)
            {
                cmbBoardList.SelectedIndex = 0;
            }
            this.listPoint.Columns.Clear();
            ColumnHeader chName = new ColumnHeader();
            chName.Text = "焊点名称";   //设置列标题
            chName.Width = 150;    //设置列宽度
            chName.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            this.listPoint.Columns.Add(chName);    //将列头添加到ListView控件。
            //ColumnHeader chValue = new ColumnHeader();
            //chValue.Text = "预热温度";   //设置列标题
            //chValue.Width = 80;    //设置列宽度
            //chValue.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            //this.listPoint.Columns.Add(chValue);    //将列头添加到ListView控件。 
            ColumnHeader chStatus = new ColumnHeader();
            chStatus.Text = "焊接温度";   //设置列标题
            chStatus.Width = 80;    //设置列宽度
            chStatus.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            this.listPoint.Columns.Add(chStatus);    //将列头添加到ListView控件。
            ColumnHeader preSendwire = new ColumnHeader();
            preSendwire.Text = "初始送丝";   //设置列标题
            preSendwire.Width = 80;    //设置列宽度
            preSendwire.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            this.listPoint.Columns.Add(preSendwire);    //将列头添加到ListView控件。
            ColumnHeader sendWire = new ColumnHeader();
            sendWire.Text = "送丝量";   //设置列标题
            sendWire.Width = 60;    //设置列宽度
            sendWire.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            this.listPoint.Columns.Add(sendWire);    //将列头添加到ListView控件。
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
            {
                BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
                FrmBoardInfo frm = new FrmBoardInfo(board);
                this.Visible = false;
                frm.ShowDialog();
                this.Visible = true;
                LoadCom();
                preId = -1;
            }
            else
            {
                MessageBox.Show("请选择程序!");
            }
        }
        private int pointHight = 14;
        private void btnLook_Click(object sender, EventArgs e)
        {
            LoadBoard();

            this.panel1.Refresh();
        }

        private void LoadBoard()
        {
            if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
            {
                BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
                txtBoardName.Text = board.boardName;
                txtLength.Text = board.boardLength.ToString();
                txtWidth.Text = board.boardWidth.ToString();
                txtPointCount.Text = board.pointList.Count.ToString();
                txtMianji.Text = (board.boardLength * board.boardWidth).ToString();
                txtCode.Text = board.WareCode;
                loadPictureBoxSize(board);
                LoadPoint(board);
            }
        }
        int preId = -1;
        private void LoadPoint(BoardInfo board)
        {
            if (preId >= 0 && preId.Equals(board.boardId))
            {
                return;
            }
            preId = board.boardId;
            this.listPoint.Items.Clear();
            int i = 0;
            foreach (WeldPointInfo point in board.pointList)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.ImageIndex = i;

                lvi.Text = point.pointName; 
                lvi.SubItems.Add(point.weldTemperature.ToString());
                lvi.SubItems.Add((point.startSendWireSpeed * point.startSendWireTime).ToString());
                lvi.SubItems.Add((point.sendWireTime * point.sendWireSpeed).ToString());
                this.listPoint.Items.Add(lvi);
                i++;
            }

        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            FrmBoardInfo info = new FrmBoardInfo(null);
            this.Visible = false;
            info.ShowDialog();

            this.Visible = true;
            LoadCom();
            preId = -1;
        }

        private void cmbBoardList_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadBoard();
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
            {
                BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
               
                if (MessageBox.Show("确认要删除程序【" + board.boardName + "】吗?", "删除确认",
                  MessageBoxButtons.OKCancel,
                  MessageBoxIcon.Question).Equals(DialogResult.OK))
                {
                    BoardManager.Delete(board);
                    MessageBox.Show("删除程序【" + board.boardName + "】成功!");

                    LoadCom();
                    preId = -1;
                }
            }
            else
            {
                MessageBox.Show("请选择程序!");
            }
        }

        private void loadPictureBoxSize(BoardInfo board)
        {
            picBoard.SizeMode = PictureBoxSizeMode.StretchImage;

            List<WeldPointInfo> pointList = board.pointList;
            int width = board.boardWidth;
            int height = board.boardLength;
            int xishu = 10;

            picBoard.Width = width * xishu;
            picBoard.Height = height * xishu;
            if (picBoard.Width > panBoard.Width)
            {
                picBoard.Height = height * xishu * panBoard.Width / (width * xishu);
                picBoard.Width = panBoard.Width;
            }
            if (picBoard.Height > panBoard.Height)
            {
                picBoard.Width = width * xishu * panBoard.Height / (height * xishu);
                picBoard.Height = panBoard.Height;
            }

            int locationX = picBoard.Location.X;
            int locationY = picBoard.Location.Y;

            locationX = (panBoard.Size.Width - picBoard.Width) / 2;
            picBoard.Location = new Point(locationX, locationY);

            //显示点
            Graphics g = (picBoard).CreateGraphics();
            picBoard.Image = board.GetImage();
            picBoard.Refresh();

            //int orgType = board.orgType; 
            //double orgX = board.getImageOrgX();
            //double orgY = board.getImageOrgY();
            //Graphics grfx = picBoard.CreateGraphics();
            //float preX = 0;
            //float preY = 0;
            //int index = 0;
            //foreach (WeldPointInfo weld in pointList)
            //{
                //float x = (float)Math.Abs(weld.PositionX - orgX) * picBoard.Width / width - pointHight / 2;
                //float y = (float)Math.Abs(weld.PositionY - orgY) * picBoard.Width / width - pointHight / 2;
                //g.FillEllipse(Brushes.Red, x - pointHight / 2, y - pointHight / 2, pointHight, pointHight);
                //if (index > 0)
                //{
                //    Pen p = new Pen(Color.Red, 2); 
                //    //中间点
                //    float xCenter = (preX + x) / 2;
                //    float yCenter = (preY + y) / 2; 
                //    System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 8, true);
                //    Pen RedPen = new Pen(Color.Red, 2);
                //    RedPen.CustomEndCap = lineCap;

                //    grfx.DrawLine(RedPen, preX, preY, xCenter, yCenter);
                //    grfx.DrawLine(p, preX, preY, x, y);
                //}
                //preX = x;
                //preY = y;
                //index++;
                //g.FillEllipse(Brushes.Red, x, y, pointHight, pointHight);
            //}

            //g.Dispose();
        }

        private void FrmBoardList_Shown(object sender, EventArgs e)
        {
            LoadBoard();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
            {
                BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
                DialogResult result = MessageBox.Show("复制后的程序料号不变,是否确定复制?", "确定", MessageBoxButtons.YesNo);
                if (result.Equals(DialogResult.Yes))
                {
                    FrmBoardCopy copy = new FrmBoardCopy(board);
                    DialogResult saveResult = copy.ShowDialog();
                    if (saveResult.Equals(DialogResult.OK))
                    {
                        LoadCom();
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择程序!");
            }
        }

    }
}