コード例 #1
0
ファイル: FrmCommImport.cs プロジェクト: zuoyangithub/scada
        /// <summary>
        /// Imports communication lines and devices.
        /// </summary>
        private void Import(out bool noData)
        {
            noData            = true;
            ImportedCommLines = new List <Settings.CommLine>();
            ImportedDevices   = new List <Settings.KP>();
            Settings settings = instance.CommApp.Settings;

            foreach (TreeNode commLineNode in treeView.Nodes)
            {
                if (commLineNode.Checked)
                {
                    CommLine          commLineEntity   = (CommLine)commLineNode.Tag;
                    Settings.CommLine commLineSettings = CommLineSettings;

                    if (commLineSettings == null)
                    {
                        // import communication line
                        noData                  = false;
                        commLineSettings        = SettingsConverter.CreateCommLine(commLineEntity);
                        commLineSettings.Parent = settings;
                        settings.CommLines.Add(commLineSettings);
                        ImportedCommLines.Add(commLineSettings);
                    }

                    foreach (TreeNode kpNode in commLineNode.Nodes)
                    {
                        if (kpNode.Checked)
                        {
                            // import device
                            noData = false;
                            KP          kpEntity   = (KP)kpNode.Tag;
                            Settings.KP kpSettings = SettingsConverter.CreateKP(kpEntity,
                                                                                project.ConfigBase.KPTypeTable);
                            kpSettings.Parent = commLineSettings;

                            if (commEnvironment.TryGetKPView(kpSettings, true, null, out KPView kpView, out string errMsg))
                            {
                                kpSettings.SetReqParams(kpView.DefaultReqParams);
                            }

                            commLineSettings.ReqSequence.Add(kpSettings);
                            ImportedDevices.Add(kpSettings);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: FrmDeviceAdd.cs プロジェクト: zuoyangithub/scada
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ValidateFields() && CheckFeasibility(out Comm.Settings.CommLine commLineSettings))
            {
                // create a new device
                int commLineNum = (int)cbCommLine.SelectedValue;
                KP  kpEntity    = new KP
                {
                    KPNum       = Convert.ToInt32(numKPNum.Value),
                    Name        = txtName.Text,
                    KPTypeID    = (int)cbKPType.SelectedValue,
                    Address     = txtAddress.Text == "" ? null : (int?)int.Parse(txtAddress.Text),
                    CallNum     = txtCallNum.Text,
                    CommLineNum = commLineNum > 0 ? (int?)commLineNum : null,
                    Descr       = txtDescr.Text
                };

                // insert the device in the configuration database
                project.ConfigBase.KPTable.AddItem(kpEntity);
                project.ConfigBase.KPTable.Modified = true;

                // insert the line in the Communicator settings
                if (chkAddToComm.Checked && cbInstance.SelectedItem is Instance instance)
                {
                    if (instance.CommApp.Enabled)
                    {
                        KPSettings        = SettingsConverter.CreateKP(kpEntity, project.ConfigBase.KPTypeTable);
                        KPSettings.Parent = commLineSettings;
                        commLineSettings.ReqSequence.Add(KPSettings);
                        CommLineSettings = commLineSettings;
                    }

                    InstanceName = recentSelection.InstanceName = instance.Name;
                }

                recentSelection.CommLineNum = commLineNum;
                recentSelection.KPNum       = kpEntity.KPNum;
                recentSelection.KPTypeID    = kpEntity.KPTypeID;
                DialogResult = DialogResult.OK;
            }
        }