private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                errorProvider1.Clear();
                if (string.IsNullOrEmpty(txtChannelName.Text) ||
                    string.IsNullOrWhiteSpace(txtChannelName.Text))
                {
                    errorProvider1.SetError(txtChannelName, "The channel name is empty");
                    return;
                }
                DIEthernet die = null;

                die = new DIEthernet
                {
                    ChannelName    = txtChannelName.Text,
                    ChannelTypes   = "OPC",
                    CPU            = serversComboBox.Text,
                    Rack           = 0,
                    Slot           = 0,
                    IPAddress      = "127.0.0.1",
                    Port           = 502,
                    ConnectionType = "Ethernet",
                    Mode           = serverTextBox.Text
                };

                if (ch == null)
                {
                    die.ChannelId = objChannelManager.Channels.Count + 1;
                    die.Devices   = new List <Device>();
                    if (eventChannelChanged != null)
                    {
                        eventChannelChanged(die, true);
                    }
                    //this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Add Channel");
                }
                else
                {
                    die.ChannelId = ch.ChannelId;
                    die.Devices   = ch.Devices;
                    if (eventChannelChanged != null)
                    {
                        eventChannelChanged(die, false);
                    }
                    //this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Editor Channel");
                }

                btnNext.Text     = "Finish";
                btnBlack.Enabled = true;
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtDeviceName.Text) ||
                    string.IsNullOrWhiteSpace(txtDeviceName.Text))
                {
                    DxErrorProvider1.SetError(txtDeviceName, "The device name is empty");
                }
                else
                {
                    DxErrorProvider1.Clear();
                    if (dv == null)
                    {
                        Device dvNew = new Device
                        {
                            DeviceId    = ch.Devices.Count + 1,
                            SlaveId     = (short)txtSlaveId.Value,
                            DeviceName  = txtDeviceName.Text,
                            Description = txtDesp.Text,
                            DataBlocks  = new List <DataBlock>()
                        };
                        EventscadaLogger?.Invoke(1, "DeviceManager", $"{DateTime.Now}", "Add Device");

                        if (eventDeviceChanged != null)
                        {
                            eventDeviceChanged(dvNew, true);
                        }
                    }
                    else
                    {
                        dv.SlaveId     = (short)txtSlaveId.Value;
                        dv.DeviceName  = txtDeviceName.Text;
                        dv.Description = txtDesp.Text;
                        EventscadaLogger?.Invoke(1, "DeviceManager", $"{DateTime.Now}", "Editor Device");

                        if (eventDeviceChanged != null)
                        {
                            eventDeviceChanged(dv, false);
                        }
                    }
                    Close();
                }
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
        }
        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                errorProvider1.Clear();
                if (string.IsNullOrEmpty(txtChannelName.Text) ||
                    string.IsNullOrWhiteSpace(txtChannelName.Text))
                {
                    errorProvider1.SetError(txtChannelName, "The channel name is empty");
                    return;
                }
                string ConnType = $"{cboxConnType.SelectedItem}";
                TabControlSiemens.SelectedIndex = cboxConnType.SelectedIndex;
                errorProvider1.Clear();
                switch (ConnType)
                {
                case "SerialPort":
                    if ("Finish".Equals(btnNext.Text))
                    {
                        DISerialPort dis = new DISerialPort()
                        {
                            ChannelId    = objChannelManager.Channels.Count + 1,
                            ChannelName  = txtChannelName.Text,
                            ChannelTypes = _DriverTypes,
                            CPU          = $"{cboxModel.Text}",
                            PortName     = $"{cboxPort.SelectedItem}",
                            BaudRate     = int.Parse($"{cboxBaudRate.SelectedItem}"),
                            DataBits     = int.Parse($"{cboxDataBits.SelectedItem}"),
                            StopBits     = (StopBits)System.Enum.Parse(typeof(StopBits), $"{cboxStopBits.SelectedItem}"),
                            Parity       = (Parity)System.Enum.Parse(typeof(Parity), $"{cboxParity.SelectedItem}"),
                            Handshake    = (Handshake)System.Enum.Parse(typeof(Handshake),
                                                                        $"{cboxHandshake.SelectedItem}"),
                            ConnectionType = ConnType,
                            Mode           = $"PPI",
                            Description    = txtDesc.Text
                        };
                        if (ch == null)
                        {
                            dis.ChannelId = objChannelManager.Channels.Count + 1;

                            if (eventChannelChanged != null)
                            {
                                eventChannelChanged(dis, true);
                            }

                            EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Add Channel");
                        }
                        else
                        {
                            dis.ChannelId = ch.ChannelId;
                            dis.Devices   = ch.Devices;

                            if (eventChannelChanged != null)
                            {
                                eventChannelChanged(dis, false);
                            }

                            EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Editor Channel");
                        }
                        Close();
                    }
                    btnNext.Text     = "Finish";
                    btnBlack.Enabled = true;

                    break;

                case "Ethernet":
                    if ("Finish".Equals(btnNext.Text))
                    {
                        DIEthernet die = null;

                        die = new DIEthernet()
                        {
                            ChannelName    = txtChannelName.Text,
                            ChannelTypes   = _DriverTypes,
                            CPU            = $"{cboxModel.Text}",
                            Rack           = (short)txtRack.Value,
                            Slot           = int.Parse($"{ txtSlot.Value}"),
                            IPAddress      = txtIPAddress.Text,
                            Port           = (short)txtPort.Value,
                            ConnectionType = ConnType,
                            Mode           = $"TCP",
                        };

                        if (ch == null)
                        {
                            die.ChannelId = objChannelManager.Channels.Count + 1;
                            die.Devices   = new List <Device>();
                            eventChannelChanged?.Invoke(die, true);
                            EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Add Channel");
                        }
                        else
                        {
                            die.ChannelId = ch.ChannelId;
                            die.Devices   = ch.Devices;
                            eventChannelChanged?.Invoke(die, false);
                            EventscadaLogger?.Invoke(1, "ChannelManager", $"{DateTime.Now}", "Editor Channel");
                        }
                        Close();
                    }
                    btnNext.Text     = "Finish";
                    btnBlack.Enabled = true;

                    break;
                }
            }
            catch (Exception ex)
            {
                EventscadaException?.Invoke(GetType().Name, ex.Message);
            }
        }