示例#1
0
        void grid_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int[]            rows           = grid.Selection.GetSelectionRegion().GetRowsIndex();
            ModbusChannelImp chan           = (ModbusChannelImp)grid[rows[0], gridColName].Tag;
            string           oldname        = chan.Name;
            List <string>    forbiddenNames = new List <string>();

            for (int i = 1; i < grid.RowsCount; i++)
            {
                if (i != rows[0])
                {
                    forbiddenNames.Add(grid[i, gridColName].DisplayText);
                }
            }
            List <string> stations = new List <string>();

            for (int i = 1; i < stationGrid.RowsCount; i++)
            {
                stations.Add(((IModbusStation)stationGrid[i, stationGridColName].Tag).Name);
            }
            ModifyChannelForm mcc = new ModifyChannelForm(chan, forbiddenNames, stations, null);

            if ((chan = mcc.DoShow()) != null)
            {
                showChannel(rows[0], chan);
                grid.Invalidate();
            }
            else
            {
                return;
            }
        }
示例#2
0
        private void OnAddVariable(object sender, EventArgs e)
        {
            if (stationGrid.RowsCount > 1)
            {
                string var = GetUniqueVariableName();
                string statname;
                int [] sel = stationGrid.Selection.GetSelectionRegion().GetRowsIndex();
                if (sel.GetLength(0) > 0)
                {
                    if (sel[0] > 1)
                    {
                        statname = stationGrid[sel[0], stationGridColName].DisplayText;
                    }
                    else
                    {
                        statname = stationGrid[1, stationGridColName].DisplayText;
                    }
                }
                else
                {
                    statname = stationGrid[1, stationGridColName].DisplayText;
                }

                int[]         rows           = grid.Selection.GetSelectionRegion().GetRowsIndex();
                List <string> forbiddenNames = new List <string>();
                for (int i = 1; i < grid.RowsCount; i++)
                {
                    if (rows.Length > 0)
                    {
                        if (i != rows[0])
                        {
                            forbiddenNames.Add(grid[i, gridColName].DisplayText);
                        }
                    }
                    else
                    {
                        forbiddenNames.Add(grid[i, gridColName].DisplayText);
                    }
                }
                List <string> stations = new List <string>();
                for (int i = 1; i < stationGrid.RowsCount; i++)
                {
                    stations.Add(((IModbusStation)stationGrid[i, stationGridColName].Tag).Name);
                }

                ModbusChannelImp ch = (ModbusChannelImp)ChannelFactory.CreateChannel(var, plugin, typeof(int), statname, ModbusDataTypeEx.HoldingRegister, 1, 0,
                                                                                     ModbusDeviceDataType.Int, 1, ModbusConversionType.SwapNone, 0);
                ModifyChannelForm mcc = new ModifyChannelForm(ch, forbiddenNames, stations, statname);
                if ((ch = mcc.DoShow()) != null)
                {
                    AddVariable(ch);
                }
            }
            else
            {
                MessageBox.Show(StringConstants.CannotCreateVariable, StringConstants.Error);
            }
        }