Beispiel #1
0
        public FrmConnectionEditor(int connectionIndex, BlockBase block, ControlModuleConnection connection)
        {
            InitializeComponent();
            Initialize();

            this.ConnectionIndex = connectionIndex;
            this.Block           = block;
            this.Connection      = connection;
        }
        private void Disconnect()
        {
            ControlModuleConnection connection = null;

            if (grdDataView.SelectedRowsCount <= 0)
            {
                MessageBox.Show("You must select the connection you want to disconnect.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                DataRowView drv = grdDataView.GetRow(grdDataView.GetSelectedRows()[0]) as DataRowView;
                if (drv != null)
                {
                    connection = Project.ControlModuleConnectionManager.GetByID((System.Int32)drv[0]);
                    if (connection != null)
                    {
                        if (MessageBox.Show("Are you sure you want to disconnect the selected connection?",
                                            Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return;
                        }

                        Project.ControlModuleConnectionManager.Unassign(connection.ID);

                        this.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("The connection cannot be read from current project and cannot be disconnected.",
                                        Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("ERROR storing data: " + ex.Message,
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Connect()
        {
            ControlModuleConnection connection = null;
            FrmConnectionEditor     form       = null;

            if (grdDataView.SelectedRowsCount <= 0)
            {
                MessageBox.Show("You must select the connection you want to connect.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                DataRowView drv = grdDataView.GetRow(grdDataView.GetSelectedRows()[0]) as DataRowView;
                if (drv != null)
                {
                    connection = Project.ControlModuleConnectionManager.GetByID((System.Int32)drv[0]);
                    if (connection != null)
                    {
                        form = new FrmConnectionEditor((System.Int32)drv[1], this.OwnerBlock, connection);
                    }
                    else
                    {
                        form = new FrmConnectionEditor((System.Int32)drv[1], this.OwnerBlock);
                    }

                    form.ShowDialog(this);
                    if (form.DialogResult == DialogResult.OK)
                    {
                        this.Refresh();
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("ERROR loading data: " + ex.Message,
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }