Newer
Older
RbFreqStand / RbFreqStandMeasure / info / AddDevDlg.cs
TAN YUE on 27 Mar 2021 2 KB 20210327 送检仪器查询功能
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl;
using Casic.Birmm.RbFreqStandMeasure.Tools;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure.info
{
    public partial class AddDevDlg : 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

        public Action HideMaskAction
        {
            get;
            set;
        }

        public AddDevDlg()
        {
            InitializeComponent();

            ((ComboBoxEx)this.Controls.Find("channelFree", true)[0]).SelectedIndex = 0;
        }

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

        // 添加并开始检测
        private void btnSave_Click(object sender, EventArgs e)
        {
            // 取得输入框的参数
            string devName = ((TextBoxX) this.Controls.Find("inputDevName", true)[0]).Text; 
            string devCode = ((TextBoxX) this.Controls.Find("inputDevCode", true)[0]).Text;
            string devModel = ((TextBoxX)this.Controls.Find("inputDevModel", true)[0]).Text;
            string devCustomComp = ((TextBoxX)this.Controls.Find("inputCustComp", true)[0]).Text;
            string devCustomName = ((TextBoxX)this.Controls.Find("inputCustName", true)[0]).Text;

            ComboBoxEx channels = (ComboBoxEx)this.Controls.Find("channelFree", true)[0];
            string channelNo = (string)((ComboItem)channels.SelectedItem).Value;

            // 初始化数据访问接口
            DeviceService devService = new DeviceServiceImpl();
            int id = devService.add(devName, devCode, "1", devModel, devCustomComp, devCustomName, channelNo);
            if (id >= 0)
            {
                // 添加成功,继续保存检测项目和开始时间
                this.HideMaskAction();
            }
            else
            {
                LogHelper.WriteErrorLog(this.GetType(), "添加设备[" + devName + "]失败");
            }
        }
    }
}