Newer
Older
RbFreqStand / RbFreqStandMeasure / info / ReDetecDlg.cs
yangqianqian on 19 May 2021 5 KB s
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl;
using Casic.Birmm.RbFreqStandMeasure.tools;
using Casic.Birmm.RbFreqStandMeasure.Tools;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure.info
{
    public partial class ReDetecDlg : Form
    {
        #region 无边框拖动效果/最小化窗口/关闭窗口
        [DllImport("user32.dll")]//拖动无窗体的控件
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            //拖动窗体
            ReleaseCapture();
            SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }
        #endregion

        DictService dictService = new DictServiceImpl();
        DetectionItemService detectionItemService = new DetectionItemServiceImpl();
        public string detectType = "";
        public long deviceId=-1;
        public long detectionItemId = -1;
        public static string channelNoReDetec = "";

        public Action HideMaskAction
        {
            get;
            set;
        }

        public ReDetecDlg(DataGridView dataGridView)
        {
            InitializeComponent();
            

            if (HomeCtrlForm.channelFreeList.Count > 0)
            {
                cbBox_channelFree.Items.Add("");
                foreach (string item in HomeCtrlForm.channelFreeList)
                {
                    cbBox_channelFree.Items.Add(item);
                }
            }
            else
            {
                //text_channelNo.WatermarkText = "无空闲通道";
            }
         

        }

        // 关闭对话框
        private void btnAddDevCancel_Click(object sender, EventArgs e)
        {
            this.HideMaskAction();
        }

        private void btn_downChannelList_Click(object sender, EventArgs e)
        {
            cbBox_channelFree.DroppedDown = true;
        }

        private void cbBox_channelFree_SelectedIndexChanged(object sender, EventArgs e)
        {
            text_channelNo.Text = cbBox_channelFree.SelectedItem.ToString();

        }

        private void btnExitDev_Click(object sender, EventArgs e)
        {
            this.HideMaskAction();
        }

        private void roundButton1_Click(object sender, EventArgs e)
        {
            this.HideMaskAction();
        }

        private void btn_reDetec_Click(object sender, EventArgs e)
        {
            btn_reDetec.Enabled = false;
            roundButton1.Enabled = false;
            string portName = ConfigHelper.GetAppConfig("channel" + text_channelNo.Text).Split(' ')[0];
            int band = Convert.ToInt32(ConfigHelper.GetAppConfig("channel" + text_channelNo.Text).Split(' ')[1]);

            channelNoReDetec = text_channelNo.Text;

            
            // 打开串口
            SerialPort port = RbFreqStdMeas.portList[Convert.ToInt32(channelNoReDetec) - 1];
            if (port.IsOpen) port.Close();
            port.PortName = portName;
            port.BaudRate = band;
            port.Parity = Parity.None;
            port.DataBits = 8;
            port.StopBits = StopBits.One;
            port.Handshake = Handshake.None;
            port.ReadTimeout = -1;
            port.WriteTimeout = 3000;
            try
            {
                port.Open();
                if (!port.IsOpen)
                {
                    MessageBox.Show("无法打开通道"+ channelNoReDetec + ",检测失败!");
                    btn_reDetec.Enabled = true;
                    roundButton1.Enabled = true;
                    return;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("无法打开通道" + channelNoReDetec + ",检测失败!");
                btn_reDetec.Enabled = true;
                roundButton1.Enabled = true;
                return;
            }
            DetectionHelper detectionHelper = new DetectionHelper();

            if (DetectionHelper.detectionHelper.getFrequencyData(port, true).Equals(""))
            {
                MessageBox.Show("请连接仪器到通道[" + channelNoReDetec + "]!");
                btn_reDetec.Enabled = true;
                roundButton1.Enabled = true;
                return;
            }

            // 初始化数据访问接口
            DeviceService devService = new DeviceServiceImpl();


            detectionHelper.detectionItemId = detectionItemId;
            //开始检测
            if (label1.Text.Contains("稳定"))
            {
                string interval = label1.Text.Split(' ')[2].Replace("s","");
                detectionHelper.detecStability(deviceId, DateTime.Now.ToString("yyyy-MM-dd"), interval, port, true, true);
            }
            else
            {
                detectionHelper.detecAccuracy(deviceId, port, DateTime.Now.ToString("yyyy-MM-dd"), true, true);
            }
            DetailDlg.label_redetecting.Visible = true;

            btn_reDetec.Enabled = true;
            roundButton1.Enabled = true;
            this.HideMaskAction();
        }
    }
}