FrmBoardCopy.cs 4.7 KB

using log4net;
using URSoldering.Common;
using URSoldering.DeviceLibrary;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

using System.Windows.Forms;
using URSoldering.Common.util;
using System.IO;
using System.Drawing.Drawing2D;
using URSoldering.LoadCSVLibrary;

namespace URSoldering.Client
{
    public partial class FrmBoardCopy : FrmBase
    {
        private BoardInfo oldBoard = null;

        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public FrmBoardCopy(BoardInfo board)
        {
            oldBoard = board;
            InitializeComponent();
            this.Text = "复制程序【" + oldBoard.PartNumber + "】的程序";
        }
        private void FrmBoardInfo_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
             
            txtBoardName.Focus();
            LoadBoardInfo();
        }
       
        private void LoadBoardInfo()
        {
            string suffix = "副本";
            string newName = oldBoard.boardName + suffix;
            
            txtBoardName.Text = newName;
           
            //txtRobotZHighValue.Text = oldBoard.ZHighValue.ToString();
             
        }
         

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

        private void btnSave_Click(object sender, EventArgs e)
        { 
            try
            {
                string newName = FormUtil.getValue(txtBoardName);
                string newCode = FormUtil.getValue(txtCode); 
                if (newName.Equals(""))
                {
                    MessageBox.Show("请输入程序名称");
                    txtBoardName.Focus();
                    return;
                }
                //判断是否重名
                if (BoardManager.getBoardByName(newName) != null)
                {
                    MessageBox.Show("程序名称【" + newName + "】已存在,复制失败!");
                    return;
                } 

                BoardInfo newBoard = new BoardInfo();
                //newBoard.boardCode = oldBoard.boardCode;
                newBoard.boardId = BoardManager.GetNextId();
                newBoard.boardLength = oldBoard.boardLength;
                newBoard.boardWidth = oldBoard.boardWidth;
                newBoard.boardName = newName;
            
                newBoard.planNeedTime = oldBoard.planNeedTime;
                newBoard.pointList = new List<WeldPointInfo>(oldBoard.pointList);
                newBoard.solderCount = oldBoard.solderCount;
                newBoard.solderingCount = oldBoard.solderingCount;
                newBoard.solderingTime = oldBoard.solderingTime;
                newBoard.solderTime = oldBoard.solderTime;
                newBoard.imgName = oldBoard.imgName;
                //newBoard.orgType = oldBoard.orgType;
                //newBoard.originX = oldBoard.originX;
                //newBoard.originY = oldBoard.originY;
               newBoard.AoiFileName=oldBoard.AoiFileName;
                //newBoard.ZHighValue = newZHigh;
                try
                {
                    if (!oldBoard.imgName.Contains(oldBoard.boardName))
                    {
                        string oldName = oldBoard.imgName;
                        string newImgName = oldBoard.boardName + Path.GetExtension(oldName);

                        string configPath = ConfigAppSettings.GetValue(Setting_Init.BOARD_IMAGE_PATH);
                        string oldPath = Application.StartupPath + "/" + configPath + "/" + oldName;
                        string newPath = Application.StartupPath + "/" + configPath + "/" + newImgName;
                        if (File.Exists(oldPath))
                        {
                            File.Copy(oldPath, newPath, true);
                        }
                        newBoard.imgName = newImgName;
                        newBoard.myImage = null;
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error("更新程序名时更改图片出错:" + ex.ToString());
                }
                BoardManager.Add(newBoard);
                MessageBox.Show("新增程序【" + newName + "】成功!");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                LogUtil.error("保存复制的程序出错:" + ex.ToString());
            } 
        }
    }
}