Newer
Older
RbFreqStand / RbFreqStandMeasure / home / HomeCtrlForm.cs
using Casic.Birmm.RbFreqStandMeasure.home;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure
{
    public partial class HomeCtrlForm : UserControl
    {
        int totalCount = 0;
        int currentPage = 1;
        int pageCount = 0;
        int limitCount = 5;
        DataTable devToBeTested = null;
        DataTable channels = null;

        #region 样式常量定影
        private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F84D7
        private readonly Font titleFont = new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel, 134);
        #endregion
        
        public HomeCtrlForm()
        {
            InitializeComponent();
        }

        private void HomeCtrlForm_Load(object sender, EventArgs e)
        {
            // 初始化表格标题栏
            InitTableDevList();

            // 加载待检测列表
            LoadDevToBeTested();

            // 初始化各通道样式
            InitTableChannel();
            LoadChannelStatus();
        }

        private void InitTableDevList()
        {
            tableToBeTested.Columns.Clear();
            tableToBeTested.Rows.Clear();

            // 添加标题栏
            Panel tableHeader = new Panel
            {
                BackColor = Color.White,
                Size = new Size(764, 32),
                Location = new Point(0, 0)
            };
            tableHeader.BackColor = titleBackColor;
            tableToBeTested.Controls.Add(tableHeader);

            // 仪器名称
            Label colDevName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器名称",
                Location = new Point(0, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevName);
            colDevName.BringToFront();

            // 仪器类型
            Label colDevType = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器类型",
                Location = new Point(100, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevType);
            colDevType.BringToFront();

            // 仪器编号
            Label colDevNo = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器编号",
                Location = new Point(200, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevNo);
            colDevNo.BringToFront();

            // 客户名称
            Label colCustomName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "客户名称",
                Location = new Point(300, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colCustomName);
            colCustomName.BringToFront();

            // 客户单位
            Label colCustomComp = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "客户单位",
                Location = new Point(400, 0),
                Size = new Size(120, 32)
            };
            tableToBeTested.Controls.Add(colCustomComp);
            colCustomComp.BringToFront();

            // 开始时间
            Label colStartTime = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "开始时间",
                Location = new Point(520, 0),
                Size = new Size(144, 32)
            };
            tableToBeTested.Controls.Add(colStartTime);
            colStartTime.BringToFront();

            // 通道号
            Label colChannelNo = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "通道号",
                Location = new Point(664, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colChannelNo);
            colChannelNo.BringToFront();

            totalCount = 0;
            currentPage = 1;
            pageCount = 0;
            limitCount = 4;
        }

        private void InitTableChannel()
        {
            tableChannel.Columns.Clear();
            tableChannel.Rows.Clear();

            // 添加标题栏
            Panel tableHeader = new Panel
            {
                BackColor = Color.White,
                Size = new Size(984, 30),
                Location = new Point(0, 0)
            };
            tableHeader.BackColor = titleBackColor;
            tableChannel.Controls.Add(tableHeader);

            // 通道号
            Label colChannelNo = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "#",
                Location = new Point(0, 0),
                Size = new Size(50, 30)
            };
            tableChannel.Controls.Add(colChannelNo);
            colChannelNo.BringToFront();

            // 仪器名称
            Label colDevName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器名称",
                Location = new Point(50, 0),
                Size = new Size(110, 30)
            };
            tableChannel.Controls.Add(colDevName);
            colDevName.BringToFront();

            // 仪器编号
            Label colDevNo = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器编号",
                Location = new Point(160, 0),
                Size = new Size(110, 30)
            };
            tableChannel.Controls.Add(colDevNo);
            colDevNo.BringToFront();

            // 客户名称
            Label colCustomName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "客户名称",
                Location = new Point(270, 0),
                Size = new Size(110, 30)
            };
            tableChannel.Controls.Add(colCustomName);
            colCustomName.BringToFront();

            // 开始时间
            Label colStartTime = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "开始时间",
                Location = new Point(380, 0),
                Size = new Size(120, 30)
            };
            tableChannel.Controls.Add(colStartTime);
            colStartTime.BringToFront();

            // 结束时间
            Label colEndTime = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "结束时间",
                Location = new Point(500, 0),
                Size = new Size(120, 30)
            };
            tableChannel.Controls.Add(colEndTime);
            colEndTime.BringToFront();

            // 状态
            Label colStatus = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "状态",
                Location = new Point(620, 0),
                Size = new Size(64, 30)
            };
            tableChannel.Controls.Add(colStatus);
            colStatus.BringToFront();

            // 频率稳定度
            Label colStablility = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "稳定度",
                Location = new Point(684, 0),
                Size = new Size(75, 30)
            };
            tableChannel.Controls.Add(colStablility);
            colStablility.BringToFront();

            // 频率准确度
            Label colAccuracy = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "准确度",
                Location = new Point(759, 0),
                Size = new Size(75, 30)
            };
            tableChannel.Controls.Add(colAccuracy);
            colAccuracy.BringToFront();

            // 开机特性
            Label colStartup = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "开机特性",
                Location = new Point(824, 0),
                Size = new Size(75, 30)
            };
            tableChannel.Controls.Add(colStartup);
            colStartup.BringToFront();

            // 日老化率
            Label colAgingRate = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "日老化率",
                Location = new Point(899, 0),
                Size = new Size(75, 30)
            };
            tableChannel.Controls.Add(colAgingRate);
            colAgingRate.BringToFront();
        }

        private void LoadDevToBeTested()
        {
            devToBeTested = new DataTable();
            
            devToBeTested.Columns.Add("devName", Type.GetType("System.String"));
            devToBeTested.Columns.Add("devType", Type.GetType("System.String"));
            devToBeTested.Columns.Add("devNo", Type.GetType("System.String"));
            devToBeTested.Columns.Add("customName", Type.GetType("System.String"));
            devToBeTested.Columns.Add("customComp", Type.GetType("System.String"));
            devToBeTested.Columns.Add("startTime", Type.GetType("System.DateTime"));
            devToBeTested.Columns.Add("channelNo", Type.GetType("System.String"));

            devToBeTested.Rows.Add("SF2001-1", "通用计数器", "00001", "203", "203", DateTime.Now);
            devToBeTested.Rows.Add("SF2001-2", "通用计数器", "00001", "203", "203", DateTime.Now);
            devToBeTested.Rows.Add("SF2001-3", "通用计数器", "00001", "203", "203", DateTime.Now);
            devToBeTested.Rows.Add("SF2001-4", "通用计数器", "00001", "203", "203", DateTime.Now);

            tableToBeTested.DataSource = devToBeTested;

            // width=984px
            tableToBeTested.Columns[0].Width = 100;
            tableToBeTested.Columns[1].Width = 100;
            tableToBeTested.Columns[2].Width = 100;
            tableToBeTested.Columns[3].Width = 100;
            tableToBeTested.Columns[4].Width = 120;
            tableToBeTested.Columns[5].Width = 144;
            tableToBeTested.Columns[6].Width = 100;

            tableToBeTested.Columns[0].ReadOnly = true;
            tableToBeTested.Columns[1].ReadOnly = true;
            tableToBeTested.Columns[2].ReadOnly = true;
            tableToBeTested.Columns[3].ReadOnly = true;
            tableToBeTested.Columns[4].ReadOnly = true;
            tableToBeTested.Columns[5].ReadOnly = true;
            tableToBeTested.Columns[6].ReadOnly = true;
        }

        private void LoadChannelStatus()
        {
            channels = new DataTable();

            channels.Columns.Add("channelNo", Type.GetType("System.String"));
            channels.Columns.Add("devName", Type.GetType("System.String"));
            channels.Columns.Add("devNo", Type.GetType("System.String"));
            channels.Columns.Add("customName", Type.GetType("System.String"));
            channels.Columns.Add("startTime", Type.GetType("System.DateTime"));
            channels.Columns.Add("endTime", Type.GetType("System.DateTime"));
            channels.Columns.Add("channelStatus", Type.GetType("System.String"));
            channels.Columns.Add("stablility", Type.GetType("System.String"));
            channels.Columns.Add("accuracy", Type.GetType("System.String"));
            channels.Columns.Add("startup", Type.GetType("System.String"));
            channels.Columns.Add("agingRate", Type.GetType("System.String"));

            channels.Rows.Add("1", "通用计数器", "00001", "航天203", DateTime.Now, DateTime.Now, "占用", 0.99, 0.00, 099, 0.434);
            channels.Rows.Add("2", "通用计数器", "00002", "李涛", DateTime.Now, DateTime.Now, "占用", 0.99, 0.00, 099, 0.434);
            channels.Rows.Add("3", "", "", "", null, null, "空闲", "", "", "", "");
            channels.Rows.Add("4", "通用计数器", "00003", "航天203", DateTime.Now, DateTime.Now, "占用", 0.99, 0.00, 099, 0.434);
            channels.Rows.Add("5", "通用计数器", "000016", "航天203", DateTime.Now, DateTime.Now, "占用", 0.99, 0.00, 099, 0.434);

            tableChannel.DataSource = channels;

            // width=764px
            tableChannel.Columns[0].Width = 50;
            tableChannel.Columns[1].Width = 110;
            tableChannel.Columns[2].Width = 110;
            tableChannel.Columns[3].Width = 110;
            tableChannel.Columns[4].Width = 120;
            tableChannel.Columns[5].Width = 120;
            tableChannel.Columns[6].Width = 64;
            tableChannel.Columns[7].Width = 75;
            tableChannel.Columns[8].Width = 75;
            tableChannel.Columns[9].Width = 75;
            tableChannel.Columns[10].Width = 75;

            tableChannel.Columns[0].ReadOnly = true;
            tableChannel.Columns[1].ReadOnly = true;
            tableChannel.Columns[2].ReadOnly = true;
            tableChannel.Columns[3].ReadOnly = true;
            tableChannel.Columns[4].ReadOnly = true;
            tableChannel.Columns[5].ReadOnly = true;
            tableChannel.Columns[6].ReadOnly = true;
            tableChannel.Columns[7].ReadOnly = true;
            tableChannel.Columns[8].ReadOnly = true;
            tableChannel.Columns[9].ReadOnly = true;
            tableChannel.Columns[10].ReadOnly = true;
        }

        private void tableToBeTested_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = tableToBeTested.CurrentCell.RowIndex;
            int colIndex = tableToBeTested.CurrentCell.ColumnIndex;
            if (colIndex == 6)
            {
                SetDevTestDlg devTestDlg = new SetDevTestDlg();
                devTestDlg.HideMaskAction += () =>
                {
                    this.HideMask();
                };
                this.ShowMask();
                devTestDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置
                devTestDlg.ShowDialog();
            }
            
        }

        private void tableChannel_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = tableToBeTested.CurrentCell.RowIndex;
            int colIndex = tableToBeTested.CurrentCell.ColumnIndex;

            SetDevChannelDlg channelDlg = new SetDevChannelDlg();
            channelDlg.HideMaskAction += () =>
            {
                this.HideMask();
            };
            this.ShowMask();
            channelDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置
            channelDlg.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();
            }
        }
    }
}