using DevComponents.Editors.DateTimeAdv; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Casic.Birmm.RbFreqStandMeasure.info { public partial class InfoCtrlForm : UserControl { private DataTable devList = null; #region 样式常量定影 private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F64D7 private readonly Color tableForeColor = Color.White; private readonly Font titleFont = new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel, 134); #endregion public InfoCtrlForm() { InitializeComponent(); this.inputDevStatus.SelectedIndex = 0; // 初始化表格并加载数据 InitTableDevList(); LoadDevList(); } private void InitTableDevList() { tableDevList.Columns.Clear(); tableDevList.Rows.Clear(); // 添加标题栏 Panel tableHeader = new Panel { BackColor = tableForeColor, Size = new Size(964, 40), Location = new Point(0, 0) }; tableHeader.BackColor = titleBackColor; tableDevList.Controls.Add(tableHeader); // 序号 Label colNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "序号", Location = new Point(0, 0), Size = new Size(80, 40) }; tableDevList.Controls.Add(colNo); colNo.BringToFront(); // 登记时间 Label colRegTime = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "登记时间", Location = new Point(80, 0), Size = new Size(164, 40) }; tableDevList.Controls.Add(colRegTime); colRegTime.BringToFront(); // 仪器名称 Label colDevName = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器名称", Location = new Point(244, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevName); colDevName.BringToFront(); // 仪器型号 Label colDevType = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器类型", Location = new Point(364, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevType); colDevType.BringToFront(); // 仪器编号 Label colDevNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "仪器编号", Location = new Point(484, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevNo); colDevNo.BringToFront(); // 客户名称 Label colCustomName = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "客户名称", Location = new Point(604, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colCustomName); colCustomName.BringToFront(); // 设备状态 Label colDevStatus = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "设备状态", Location = new Point(724, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colDevStatus); colDevStatus.BringToFront(); // 通道号 Label colChannelNo = new Label { Font = titleFont, ForeColor = tableForeColor, TextAlign = ContentAlignment.MiddleCenter, BackColor = titleBackColor, AutoSize = false, Text = "通道号", Location = new Point(844, 0), Size = new Size(120, 40) }; tableDevList.Controls.Add(colChannelNo); colChannelNo.BringToFront(); } private void LoadDevList() { devList = new DataTable(); devList.Columns.Add("index", Type.GetType("System.String")); devList.Columns.Add("regTime", Type.GetType("System.DateTime")); devList.Columns.Add("devName", Type.GetType("System.String")); devList.Columns.Add("devType", Type.GetType("System.String")); devList.Columns.Add("devNo", Type.GetType("System.String")); devList.Columns.Add("customName", Type.GetType("System.String")); devList.Columns.Add("status", Type.GetType("System.String")); devList.Columns.Add("channelNo", Type.GetType("System.String")); devList.Rows.Add("1", DateTime.Now, "SF2001-1", "通用计数器", "00001", "李涛", "检测中", "1"); devList.Rows.Add("2", DateTime.Now, "SF2001-2", "通用计数器", "00002", "李涛", "检完", ""); devList.Rows.Add("3", DateTime.Now, "SF2001-3", "通用计数器", "00003", "李涛", "检完", ""); devList.Rows.Add("4", DateTime.Now, "SF2001-4", "通用计数器", "00004", "李涛", "待检", ""); tableDevList.DataSource = devList; // width=964px tableDevList.Columns[0].Width = 80; tableDevList.Columns[1].Width = 164; tableDevList.Columns[2].Width = 120; tableDevList.Columns[3].Width = 120; tableDevList.Columns[4].Width = 120; tableDevList.Columns[5].Width = 120; tableDevList.Columns[6].Width = 120; tableDevList.Columns[7].Width = 120; tableDevList.Columns[0].ReadOnly = true; tableDevList.Columns[1].ReadOnly = true; tableDevList.Columns[2].ReadOnly = true; tableDevList.Columns[3].ReadOnly = true; tableDevList.Columns[4].ReadOnly = true; tableDevList.Columns[5].ReadOnly = true; tableDevList.Columns[6].ReadOnly = true; tableDevList.Columns[7].ReadOnly = true; } private void btnAdd_Click(object sender, EventArgs e) { AddDevDlg addDevDlg = new AddDevDlg(); addDevDlg.HideMaskAction += () => { this.HideMask(); }; this.ShowMask(); addDevDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置 // 设置默认值 DateTimeInput startTimeInput = (DateTimeInput) addDevDlg.Controls.Find("startTime", true)[0]; startTimeInput.Value = DateTime.Now; DateTimeInput endTimeInput = (DateTimeInput)addDevDlg.Controls.Find("endTimeEst", true)[0]; endTimeInput.Value = DateTime.Now.AddDays(1); addDevDlg.ShowDialog(); } private MaskForm maskForm; private void ShowMask() { maskForm = new MaskForm(this.Parent.Parent.Location, this.Parent.Parent.Size); maskForm.Show(); } private void HideMask() { if (maskForm != null) { maskForm.Close(); } } } }