private void cmdConnectionDelete_Click(object sender, EventArgs e) { if (lstConnectionList.SelectedItem != null) { cmdSave.Visible = false; cmdUndo.Visible = false; System.Windows.Forms.DialogResult res = MessageBox.Show("Are you sure that you want to delete the Connection : " + lstConnectionList.SelectedItem.ToString(), "Delete realy?", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { LockControls(); if (InternalConnectionList != null) { PLCConnectionConfiguration akConfig = null; foreach (var plcConnectionConfiguration in InternalConnectionList) { if (plcConnectionConfiguration.ConnectionName == lstConnectionList.SelectedItem.ToString()) { akConfig = plcConnectionConfiguration; } } if (akConfig != null) { InternalConnectionList.Remove(akConfig); } lstConnectionList.Items.Clear(); foreach (var plcConnectionConfiguration in InternalConnectionList) { lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName); } if (lstConnectionList.Items.Count > 0) { lstConnectionList.SelectedItem = lstConnectionList.Items[0]; lstLIBNODAVEConnectionType_SelectedIndexChanged(sender, e); } else { lstLIBNODAVEConnectionType.Enabled = false; } } else { PLCConnectionConfiguration.DeleteConfiguration(lstConnectionList.SelectedItem.ToString()); lstConnectionList.Items.Clear(); lstConnectionList.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames()); if (lstConnectionList.Items.Count > 0) { lstConnectionList.SelectedItem = lstConnectionList.Items[0]; lstLIBNODAVEConnectionType_SelectedIndexChanged(sender, e); } else { lstLIBNODAVEConnectionType.Enabled = false; } } } } }
private void ConnectionEditor_Load(object sender, EventArgs e) { LockControls(); foreach (string myType in Enum.GetNames(typeof(LibNodaveConnectionTypes))) { lstLIBNODAVEConnectionType.Items.Add(new EnumListItem(myType, (int)Enum.Parse(typeof(LibNodaveConnectionTypes), myType))); } foreach (string myType in Enum.GetNames(typeof(LibNodaveConnectionBusSpeed))) { lstLIBNODAVEBusSpeed.Items.Add(new EnumListItem(myType, (int)Enum.Parse(typeof(LibNodaveConnectionBusSpeed), myType))); } lstLIBNODAVELokalCOMPort.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames()); FillEntryPointsList(); if (InternalConnectionList != null) { foreach (var plcConnectionConfiguration in InternalConnectionList) { lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName); } } else { string[] Connections = PLCConnectionConfiguration.GetConfigurationNames(); if (Connections != null) { lstConnectionList.Items.AddRange(Connections); } } lblConnectionName.Text = DefaultConnectionName; lstConnectionList.Text = DefaultConnectionName; if (!ConnectionNameFixed && lstConnectionList.Items.Count <= 0) { lstLIBNODAVEConnectionType.Enabled = false; } else if (lstConnectionList.Items.Count > 0) { lstConnectionList.SelectedIndex = 0; } if (ConnectionNameFixed) { lstConnectionList.Visible = false; cmdConnectionAdd.Visible = false; cmdConnectionDelete.Visible = false; lblConnectionName.Visible = true; LoadSettings(); } }
private void cmdConnectionAdd_Click(object sender, EventArgs e) { string cfgName = ""; DialogResult ret = InputBox.Show("Enter Name...", "Enter the Name of the new Connection:", ref cfgName); if (ret == DialogResult.OK) { if (cfgName != "") { if (InternalConnectionList != null) { var akConfig = new PLCConnectionConfiguration(); akConfig.ConnectionName = cfgName; akConfig.ConfigurationType = LibNodaveConnectionConfigurationType.ObjectSavedConfiguration; InternalConnectionList.Add(akConfig); lstConnectionList.Items.Clear(); foreach (var plcConnectionConfiguration in InternalConnectionList) { lstConnectionList.Items.Add(plcConnectionConfiguration.ConnectionName); } lstConnectionList.SelectedItem = cfgName; lstLIBNODAVEConnectionType.Enabled = true; } else { PLCConnectionConfiguration tmp = new PLCConnectionConfiguration(cfgName); tmp.SaveConfiguration(); lstConnectionList.Items.Clear(); lstConnectionList.Items.AddRange(PLCConnectionConfiguration.GetConfigurationNames()); lstConnectionList.SelectedItem = cfgName; lstLIBNODAVEConnectionType.Enabled = true; } } } }