FrmDeviceConfig.cs 7.2 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 TSA_V.Common;
using TSA_V.DeviceLibrary;

namespace TSA_V
{
    public partial class FrmDeviceConfig : FrmBase
    {
        public FrmDeviceConfig()
        {
            InitializeComponent();

            List<string> typeList = new List<string>();
            this.cmbType.Items.Clear();
            typeList.AddRange(new string[] {
            "1=●",
            "2=✚",
            "3=┃",
            "4=━━",
            "5=□",
            "6=○",
            "7=极性_上方",
            "8=极性_下方",
            "9=极性_左方",
            "10=极性_右方"

            });
            foreach (string str in typeList)
            {
                cmbType.Items.Add(str);
            }
        }

        private void FrmLanguage_Load(object sender, EventArgs e)
        {
            LanguageProcess(); 
            this.chbISDebug.Checked = TSAVBean.IsDebug;
            this.chbDisBottomCylinder.Checked = TSAVBean.DisableBottomCylinder;
            this.chbDisSideCylinder.Checked = TSAVBean.DisableSideCylinder;
            this.txtKNDIP.Text = IOManager.KNDIP.ToString();
            this.txtKNDPort.Text = IOManager.KNDPort.ToString();
            LoadCom();
            SetScreen();
            cmbType.SelectedIndex = 0;
            int value= TSAVBean.DefaultPType - 1;
            if (cmbBoardList.Items.Count > value && value >= 0)
            {
                cmbBoardList.SelectedIndex = value;
            }
          
            numSizeX.Text = TSAVBean.DefaultPSize.ToString();
            numSizeY.Text = TSAVBean.DefaultPSize.ToString();
            txtAddr.Text = ConfigAppSettings.GetValue(Setting_Init.DCSServerAddr);
            if(MesUtil.CodeISOk&& MesUtil.CurrPCBCode != "")
            {
                txtCode.Text = MesUtil.CurrPCBCode;
            }
        }
        public void LoadCom()
        {
            cmbBoardList.DataSource = null;
            List<BoardInfo> list = new List<BoardInfo>(BoardManager.boardList);

            cmbTestProName.DataSource = list;
            cmbTestProName.DisplayMember = "boardName";
            cmbTestProName.ValueMember = "boardId";
            if (list.Count > 0)
            {
                cmbTestProName.SelectedIndex = 0;
            }

            list = new List<BoardInfo>(BoardManager.boardList);
            BoardInfo board = new BoardInfo();
            board.boardName = "--ALL--";
            board.boardId = -1;
            list.Insert(0, board);
            cmbBoardList.DataSource = list;
            cmbBoardList.DisplayMember = "boardName";
            cmbBoardList.ValueMember = "boardId";
            if (list.Count > 0)
            {
                cmbBoardList.SelectedIndex = 0;
            }
         
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

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

        private void SaveData()
        { 
            bool isDebug = chbISDebug.Checked;
            ConfigAppSettings.SaveValue(Setting_Init.IsDebug, isDebug);
            TSAVBean.IsDebug = isDebug;

            bool disBottom = chbDisBottomCylinder.Checked;
            ConfigAppSettings.SaveValue(Setting_Init.DisableBottomCylinder,disBottom);
            TSAVBean.DisableBottomCylinder = disBottom;
             
            bool disSide = chbDisSideCylinder.Checked;
            ConfigAppSettings.SaveValue(Setting_Init.DisableSideCylinder, disSide);
            TSAVBean.DisableSideCylinder = disSide;


            string server = txtAddr.Text.Trim();
            ConfigAppSettings.SaveValue(Setting_Init.DCSServerAddr, server);
            MesUtil.serverAddress = server;
            LogUtil.info($"保存配置成功: 调试{ isDebug },禁用底部气缸{disBottom},禁用侧挡气缸{disSide},地址{server} ");
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功"));
        }
        

        private void chbISDebug_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            BoardInfo board = new BoardInfo();
            board.boardId = -1;

            if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
            {
                board = (BoardInfo)cmbBoardList.SelectedItem;
            } 
            int pSizeX = FormUtil.GetIntValue(numSizeX);
            int pSizeY = FormUtil.GetIntValue(numSizeY);
            int pointType = cmbType.SelectedIndex + 1;
            int penWidth = (int)numPenWidth.Value;
            if (pSizeX.Equals(0))
            {
                MessageBox.Show(ResourceCulture.GetString("请输入正确的点大小")); 
                numSizeX.Focus();
                return;
            }
            if (pSizeY.Equals(0))
            {
                MessageBox.Show(ResourceCulture.GetString("请输入正确的点大小")); 
                numSizeY.Focus();
                return;
            }
            DialogResult result;
            if (board.boardId.Equals(-1))
            {
                result = MessageBox.Show(ResourceCulture.GetString("确定更新所有程序的组装点信息?"),
                    ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
            }
            else
            {
                result = MessageBox.Show(ResourceCulture.GetString("确定更新程序【{0}】的组装点信息", "确定更新程序【{0}】的组装点信息", board.boardName),
ResourceCulture.GetString(ResourceCulture.Sure, "确认"), MessageBoxButtons.YesNo);
            }
            if (result.Equals(DialogResult.Yes))
            {

                BoardManager.UpdatePointSize(board.boardId, pSizeX,pSizeY, pointType,penWidth);
                MessageBox.Show(ResourceCulture.GetString( "更改完成"));

            }
            else
            {
                MessageBox.Show(ResourceCulture.GetString( "已取消更改"));
            }
        
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            string serverAddress = txtAddr.Text.Trim();
            if (String.IsNullOrEmpty(serverAddress))
            {
                MessageBox.Show("请输入正确的接口地址");
            }
            BoardInfo board = new BoardInfo();
            board.boardId = -1; 
            if (cmbTestProName.Text != "" && cmbTestProName.SelectedIndex >= 0)
            {
                board = (BoardInfo)cmbTestProName.SelectedItem;
            }
            else
            {
                MessageBox.Show("请选择一个程序");
            }
            string barcode = txtCode.Text.Trim();
            DeviceStatus status = MesUtil.GetTestStatus(board, barcode);
            string result = HttpHelper.PostJson(serverAddress, new JsonParam( status));

            LogUtil.info("DCS地址【" + serverAddress + "】 返回值【" + result + "】");
             
        }
    }
}