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 DevComponents.DotNetBar.Controls; using DevComponents.Editors; using System; using System.Collections.Generic; 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 DictService dictService = new DictServiceImpl(); DetectionItemService detectionItemService = new DetectionItemServiceImpl(); 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 = "无空闲通道"; } } // 关闭对话框 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 && !checkBox_count.Checked) { 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("添加")) { long deviceId = devService.add(devName, devCode, devTypeCode, devModel, devCustomComp, devCustomName, channelNo); if (deviceId != -1) { if (btnSave.Text.Equals("添加并开始检测")) { string stability = "-3"; string accuracy = "-3"; string bootFeature = "-3"; string ageRate = "-3"; string interval = ""; if (checkBox_startNow.Checked || startTime.Value == DateTime.Now) { if (checkBox_stability.Checked) { stability = "-1"; } if (checkBox_accuracy.Checked) accuracy = "-1"; if (checkBox_bootFeature.Checked) bootFeature = "-1"; if (checkBox_ageRate.Checked) ageRate = "-1"; } else { if (checkBox_stability.Checked) stability = "-2"; if (checkBox_accuracy.Checked) accuracy = "-2"; if (checkBox_bootFeature.Checked) bootFeature = "-2"; if (checkBox_ageRate.Checked) ageRate = "-2"; } 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"; } detectionItemService.add(deviceId, startTime.Value, endTime.Value, stability, accuracy, bootFeature, ageRate, interval,text_channelNo.Text); // 重新加载首页的通道状态 HomeCtrlForm.homeCtrlForm.LoadChannelStatus(); } // 添加成功,继续保存检测项目和开始时间 this.HideMaskAction(); } else { LogHelper.WriteErrorLog(this.GetType(), "添仪器[" + devName + "]失败"); } } else if (labelTitle.Text.Equals("修改")) { } } 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) { 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 != "") { btnSave.Text = "添加并开始检测"; checkBox_startNow.Enabled = true; groupBox1.Enabled = true; } else { btnSave.Text = "添加仪器"; groupBox1.Enabled = false; checkBox_startNow.Enabled = false; } } 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; } } }