using Casic.Birmm.RbFreqStandMeasure.home; 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.R_DevService.Dto; using Casic.Birmm.RbFreqStandMeasure.R_DevService.Service; using Casic.Birmm.RbFreqStandMeasure.R_DevService.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.Threading; 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 DictService dictService = new DictServiceImpl(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); CounterDetecInitService counterDetecInitService = new CounterDetecInitServiceImpl(); CounterDataService counterDataService = new CounterDataServiceImpl(); SensitivityService sensitivityService = new SensitivityServiceImpl(); public long deviceId = -1; public bool isInDetection = false; public Action HideMaskAction { get; set; } public AddDevDlg() { InitializeComponent(); List<Dict> dictList = dictService.getTypeListByCodeType("devType"); cbBox_devType.DataSource = dictList; cbBox_devType.DisplayMember = "Name"; cbBox_devType.ValueMember = "Code"; btnSave.Text = "保存"; if (HomeCtrlForm.channelFreeList.Count > 0) { cbBox_channelFree.Items.Add(""); foreach (string item in HomeCtrlForm.channelFreeList) { cbBox_channelFree.Items.Add(item); } } else { text_channelNo.WatermarkText = "无空闲通道"; groupBox1.Enabled = false; } } // 关闭对话框 private void btnAddDevCancel_Click(object sender, EventArgs e) { this.HideMaskAction(); } // 添加并开始检测 private void btnSave_Click(object sender, EventArgs e) { if (inputDevName.Text.Trim().Equals("")) { MessageBox.Show("请输入仪器名称!");return; } if (inputDevCode.Text.Trim().Equals("")) { MessageBox.Show("请输入仪器编号!"); return; } if (inputDevModel.Text.Trim().Equals("")) { MessageBox.Show("请输入仪器型号!"); return; } if (text_devType.Text.Trim().Equals("")) { MessageBox.Show("请选择仪器类型!"); return; } if (inputCustComp.Text.Trim().Equals("")) { MessageBox.Show("请输入送检单位!"); return; } if (inputCustName.Text.Trim().Equals("")) { MessageBox.Show("请输入联系人!"); return; } if (text_channelNo.Text.Trim() != "") { if (checkBox_stability.Checked && !radio_1s.Checked && !radio_10s.Checked && !radio_20s.Checked && !radio_100s.Checked) { MessageBox.Show("请选择频率稳定度采样时间!"); return; } if (!checkBox_accuracy.Checked && !checkBox_stability.Checked && !checkBox_ageRate.Checked && !checkBox_bootFeature.Checked) { MessageBox.Show("请选择检测项目!"); return; } } if (checkBox_accuracy.Checked || checkBox_stability.Checked || checkBox_ageRate.Checked || checkBox_bootFeature.Checked) { if (text_channelNo.Text.Trim() == "") { MessageBox.Show("请选择通道号!"); return; } } // 取得输入框的参数 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; string devTypeCode = cbBox_devType.SelectedValue.ToString(); string channelNo = text_channelNo.Text; // 初始化数据访问接口 DeviceService devService = new DeviceServiceImpl(); if (labelTitle.Text.Equals("添加")) { deviceId = devService.add(devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo); if (deviceId == -1) { LogHelper.WriteErrorLog(this.GetType(), "添加仪器[" + devName + "]失败"); MessageBox.Show("添加仪器[" + devName + "]失败","错误"); } } else if (labelTitle.Text.Equals("修改")) { devService.update(deviceId, devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo); } if (deviceId != -1 && !isInDetection) { // 打开串口 DetectionHelper detectionHelper = new DetectionHelper(); string portName = ConfigHelper.GetAppConfig("channel" + text_channelNo.Text).Split(' ')[0]; int band = Convert.ToInt32(ConfigHelper.GetAppConfig("channel" + text_channelNo.Text).Split(' ')[1]); SerialPort port = detectionHelper.portOpen(portName, band); DateTime startTime = picker_startTime.Value; DateTime endTime = picker_endTime.Value; string stability = "-3"; string accuracy = "-3"; string bootFeature = "-3"; string ageRate = "-3"; string interval = ""; if (checkBox_stability.Checked) { if (radio_1s.Checked) interval = "1"; else if (radio_10s.Checked) interval = "10"; else if (radio_20s.Checked) interval = "20"; else if (radio_100s.Checked) interval = "100"; stability = "-2"; if (checkBox_now.Checked || picker_startTime.Value == DateTime.Now) { stability = "-1"; detectionHelper.detecStability(deviceId, startTime, interval, port, true); } else { detectionHelper.detecStability(deviceId, startTime, interval, port, false); } } if (checkBox_accuracy.Checked) { accuracy = "-2"; if (checkBox_now.Checked || picker_startTime.Value == DateTime.Now) { accuracy = "-1"; detectionHelper.detecAccuracy(deviceId, port, endTime, true); } else { detectionHelper.detecAccuracy(deviceId, port, endTime, false); } } if (checkBox_bootFeature.Checked) { bootFeature = "-2"; if (checkBox_now.Checked || picker_startTime.Value == DateTime.Now) { bootFeature = "-1"; detectionHelper.detecBootFeature(deviceId, startTime, port, true); } else { detectionHelper.detecBootFeature(deviceId, startTime, port, false); } } if (checkBox_ageRate.Checked) { ageRate = "-2"; if (checkBox_now.Checked || picker_startTime.Value == DateTime.Now) { ageRate = "-1"; detectionHelper.detecAgeRate(deviceId, startTime, port, true); } else { detectionHelper.detecAgeRate(deviceId, startTime, port, false); } } //开始检测 detectionItemService.add(deviceId, startTime, endTime, stability, accuracy, bootFeature, ageRate, interval, channelNo); // 重新加载首页的通道状态 HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); } // 添加成功,继续保存检测项目和开始时间 this.HideMaskAction(); } private void btn_downChannelList_Click(object sender, EventArgs e) { cbBox_channelFree.DroppedDown = true; } private void groupBox4_Enter(object sender, EventArgs e) { cbBox_channelFree.DroppedDown = false; cbBox_devType.DroppedDown = false; } private void groupBox1_Enter(object sender, EventArgs e) { cbBox_channelFree.DroppedDown = false; cbBox_devType.DroppedDown = false; } private void btn_downTypeList_Click(object sender, EventArgs e) { cbBox_devType.DroppedDown = true; } private void checkBox_startNow_CheckedChanged(object sender, EventArgs e) { picker_startTime.Value = DateTime.Now; } private void cbBox_devType_SelectedIndexChanged(object sender, EventArgs e) { text_devType.Text = ((Dict)cbBox_devType.SelectedItem).Name; } private void cbBox_channelFree_SelectedIndexChanged(object sender, EventArgs e) { text_channelNo.Text = cbBox_channelFree.SelectedItem.ToString(); if (text_channelNo.Text.Equals("")) { groupBox1.Enabled = false; checkBox_accuracy.Checked = false; checkBox_stability.Checked = false; checkBox_ageRate.Checked = false; checkBox_bootFeature.Checked = false; } else { groupBox1.Enabled = true; } } private void checkBox13_CheckedChanged(object sender, EventArgs e) { } private void checkBox_stability_CheckedChanged(object sender, EventArgs e) { if (checkBox_stability.Checked) groupBox2.Enabled = true; else groupBox2.Enabled = false; } } }