FrmDeviceConfig.cs 8.4 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();

            string[] typeList = ResourceCulture.GetPTypes() ;
            this.cmbType.Items.Clear();
            //typeList.AddRange(new string[] {
            //"1=●",
            //"2=✚",
            //"3=┃",
            //"4=━━",
            //"5=□",
            //"6=○"

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

        private void FrmLanguage_Load(object sender, EventArgs e)
        {
            LanguageProcess(); 
            this.chbISDebug.Checked = Setting_NInit.App_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= Setting_NInit.Device_DefaultPointType - 1;
            if (cmbBoardList.Items.Count > value && value >= 0)
            {
                cmbBoardList.SelectedIndex = value;
            }
          
            numSizeX.Text = Setting_NInit.Device_DefaultPointSize.ToString();
            numSizeY.Text = Setting_NInit.Device_DefaultPointSize.ToString();
            txtAddr.Text =Setting_NInit.App_DCSServerAddr ;
            if(MesUtil.CodeISOk&& MesUtil.CurrPCBCode != "")
            {
                txtCode.Text = MesUtil.CurrPCBCode;
            }

            if (IOBase.NoLine) {
                chbDisBottomCylinder.Visible = false;
                chbDisSideCylinder.Visible = false;
            }
            chbAlarmT.Checked = Setting_NInit.Set_AlarmSound;
            chbMouse.Checked = Setting_NInit.Set_CursorProcess;
            chbWorkT.Checked = Setting_NInit.Set_TipSound;
            cheDisCount.Checked = Setting_NInit.Device_UsePNCount;
        }
        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);
           
            Setting_NInit.App_IsDebug = isDebug;

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


            string server = txtAddr.Text.Trim();
            //ConfigAppSettings.SaveValue(Setting_Init.DCSServerAddr, server);
            Setting_NInit.App_DCSServerAddr = server;
            Setting_NInit.Set_AlarmSound = chbAlarmT.Checked;
            Setting_NInit.Set_TipSound = chbWorkT.Checked;
            Setting_NInit.Set_CursorProcess = chbMouse.Checked;
            Setting_NInit.Device_UsePNCount=cheDisCount.Checked;
            LogUtil.info($"保存配置成功: 调试{ isDebug },禁用底部气缸{disBottom},禁用侧挡气缸{disSide},地址{server} ," +
                $"报警提示{Setting_NInit.Set_AlarmSound.Val},工作音效{Setting_NInit.Set_TipSound.Val},鼠标限制{Setting_NInit.Set_CursorProcess.Val}, " +
                $"启用元器件计数:{Setting_NInit.Device_UsePNCount}");
            MessageBox.Show(ResourceCulture.GetString(ResourceCulture.SaveOk, "保存成功"));
        }
    
        

        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(ResourceCulture.GetString("请输入正确的接口地址"));
            }
            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 + "】");
             
        }

        private void label2_Click(object sender, EventArgs e)
        {
            try
            {
                ConfigHelper.AdvanceConfigForm.ShowEditDialog(this);
                LogUtil.info("用户点击隐藏配置");
            }
            catch (Exception ex)
            {
                LogUtil.error(ex.ToString());
            }
        }
    }
}