Esempio n. 1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 | e.RowIndex < 0)
            {
                return;
            }

            if (dataGridView1.Columns[e.ColumnIndex].Name == columnConfig)
            {
                DataGridViewDisableButtonCell buttonCell =
                    (DataGridViewDisableButtonCell)dataGridView1.
                    Rows[e.RowIndex].Cells[columnConfig];

                if (buttonCell.Enabled)
                {
                    //MessageBox.Show(dataGridView1.Rows[e.RowIndex].
                    //    Cells[e.ColumnIndex].Value.ToString() +
                    //    " is enabled");

                    modbusmasterDeviceform form = new modbusmasterDeviceform();
                    ModbusMasterData       data = masterManage.modbusMastrList.ElementAt(e.RowIndex);
                    form.getMasterData(ref data);
                    form.ShowDialog();
                }
            }
        }
Esempio n. 2
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 | e.RowIndex < 0)
            {
                return;
            }

            if (dataGridView1.Columns[e.ColumnIndex].Name == columnConfig)
            {
                DataGridViewDisableButtonCell buttonCell =
                    (DataGridViewDisableButtonCell)dataGridView1.
                    Rows[e.RowIndex].Cells[columnConfig];

                if (buttonCell.Enabled)
                {
                    //MessageBox.Show(dataGridView1.Rows[e.RowIndex].
                    //    Cells[e.ColumnIndex].Value.ToString() +
                    //    " is enabled");

                    modbusmasterDeviceform form = new modbusmasterDeviceform();
                    ModbusMasterData       data = masterManage.modbusMastrList.ElementAt(e.RowIndex);
                    ModbusMasterManage     a    = masterManage;
                    int masterStartAddr         = masterManage.getMasterStartAddr();
                    form.getMasterData(ref data, masterStartAddr, a, e.RowIndex);
                    form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog();
                }
            }
            else if (dataGridView1.Columns[e.ColumnIndex].Name == columnDetail)
            {
                DataGridViewDisableButtonCell buttonCell =
                    (DataGridViewDisableButtonCell)dataGridView1.
                    Rows[e.RowIndex].Cells[columnConfig];
                if (buttonCell.Enabled)
                {
                    var modbusDeviceList = masterManage.modbusMastrList[e.RowIndex].modbusDeviceList;
                    var count            = 0;

                    dataGridView2.Rows.Clear();

                    for (int i = 0; i < modbusDeviceList.Count; i++)
                    {
                        count += modbusDeviceList[i].modbusChannelList.Count;
                    }

                    dataGridView2.RowCount += count;
                    //dataGridView2.AutoSize = true;
                    //dataGridView2.AllowUserToAddRows = false;
                    //dataGridView2.ColumnHeadersDefaultCellStyle.Alignment =
                    //    DataGridViewContentAlignment.MiddleCenter;

                    int j = 0;
                    foreach (var device in modbusDeviceList)
                    {
                        string deviceName = device.nameDev;
                        foreach (var channel in device.modbusChannelList)
                        {
                            string channelName = channel.nameChannel;
                            dataGridView2.Rows[j].Cells["设备名"].Value    = deviceName;
                            dataGridView2.Rows[j].Cells["通道名"].Value    = channelName;
                            dataGridView2.Rows[j].Cells["功能码"].Value    = dicMsg[channel.msgType];
                            dataGridView2.Rows[j].Cells["通道起始地址"].Value = channel.curChannelAddr + 3;
                            dataGridView2.Rows[j].Cells["长度"].Value     = channel.readLength;
                            dataGridView2.Rows[j].Cells["触发变量地址"].Value = channel.writeOffset;
                            dataGridView2.Rows[j].Cells["错误变量地址"].Value = channel.writeLength;

                            j++;
                        }
                    }
                }
            }
        }