/// <summary> /// Gets a user interface object for the device. /// </summary> private bool GetDeviceView(Settings.KP kp, bool common, out KPView kpView) { try { string dllPath = Path.Combine(Environment.AppDirs.KPDir, kp.Dll); KPView commonKpView = Environment.GetKPView(dllPath); if (common) { kpView = commonKpView; } else { kpView = KPFactory.GetKPView(commonKpView.GetType(), kp.Number); kpView.KPProps = new KPView.KPProperties(CustomParams, kp.CmdLine); kpView.AppDirs = Environment.AppDirs; } return(true); } catch (Exception ex) { ScadaUiUtils.ShowError(ex.Message); Environment.ErrLog.WriteException(ex); kpView = null; return(false); } }
/// <summary> /// Displays the device properties. /// </summary> private void DisplayDevice(Settings.KP kp) { if (kp == null) { chkDeviceActive.Checked = false; chkDeviceBound.Checked = false; numDeviceNumber.Value = 0; txtDeviceName.Text = ""; cbDeviceDll.Text = ""; numDeviceAddress.Value = 0; txtDeviceCallNum.Text = ""; numDeviceTimeout.Value = 0; numDeviceDelay.Value = 0; dtpDeviceTime.Value = dtpDeviceTime.MinDate; dtpDevicePeriod.Value = dtpDevicePeriod.MinDate; txtDeviceCmdLine.Text = ""; } else { chkDeviceActive.Checked = kp.Active; chkDeviceBound.Checked = kp.Bind; numDeviceNumber.SetValue(kp.Number); txtDeviceName.Text = kp.Name; cbDeviceDll.Text = kp.Dll; numDeviceAddress.SetValue(kp.Address); txtDeviceCallNum.Text = kp.CallNum; numDeviceTimeout.SetValue(kp.Timeout); numDeviceDelay.SetValue(kp.Delay); dtpDeviceTime.SetTime(kp.Time); dtpDevicePeriod.SetTime(kp.Period); txtDeviceCmdLine.Text = kp.CmdLine; } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmDeviceData(Settings.KP kp, CommEnvironment environment) : this() { this.kp = kp ?? throw new ArgumentNullException("kp"); this.environment = environment ?? throw new ArgumentNullException("environment"); dataBox = new RemoteLogBox(lbDeviceData) { FullLogView = true }; }
private Settings.KP deviceBuf; // buffer to copy device /// <summary> /// Initializes a new instance of the class. /// </summary> public CtrlLineReqSequence() { InitializeComponent(); SetColumnNames(); changing = false; deviceBuf = null; CommLine = null; Environment = null; }
private void btnCopyDevice_Click(object sender, EventArgs e) { // copy the selected device if (GetSelectedItem(out ListViewItem item, out Settings.KP kp)) { btnPasteDevice.Enabled = true; deviceBuf = kp.Clone(); } lvReqSequence.Focus(); }
private void lvReqSequence_SelectedIndexChanged(object sender, EventArgs e) { // display the selected item properties changing = true; Settings.KP kp = lvReqSequence.SelectedItems.Count > 0 ? (Settings.KP)lvReqSequence.SelectedItems[0].Tag : null; DisplayDevice(kp); SetControlsEnabled(); changing = false; }
private Settings.KP deviceBuf; // buffer to copy device /// <summary> /// Initializes a new instance of the class. /// </summary> public CtrlLineReqSequence() { InitializeComponent(); numDeviceAddress.Maximum = int.MaxValue; SetColumnNames(); changing = false; deviceBuf = null; CommLine = null; Environment = null; CustomParams = null; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmDeviceData(Settings.KP kp, Settings.CommLine commLine, CommEnvironment environment) : this() { this.kp = kp ?? throw new ArgumentNullException("kp"); this.commLine = commLine ?? throw new ArgumentNullException("commLine"); this.environment = environment ?? throw new ArgumentNullException("environment"); dataBox = new RemoteLogBox(lbDeviceData) { FullLogView = true }; frmDeviceCommand = null; }
/// <summary> /// Creates a device settings based on the entity. /// </summary> public static Settings.KP CreateKP(Entities.KP kpEntity, BaseTable <Entities.KPType> kpTypeTable) { if (kpEntity == null) { throw new ArgumentNullException("kpEntity"); } Settings.KP kpSettings = new Settings.KP() { Number = kpEntity.KPNum }; Copy(kpEntity, kpSettings, kpTypeTable); return(kpSettings); }
/// <summary> /// Creates a node that represents the device. /// </summary> private TreeNode CreateDeviceNode(Settings.KP kp, CommEnvironment environment) { return(new TreeNode(string.Format(CommShellPhrases.DeviceNode, kp.Number, kp.Name)) { ImageKey = "comm_device.png", SelectedImageKey = "comm_device.png", Tag = new TreeNodeTag() { FormType = typeof(FrmDeviceData), FormArgs = new object[] { kp, environment }, RelatedObject = kp, NodeType = CommNodeType.Device } }); }
/// <summary> /// Gets the selected list view item and the corresponding device. /// </summary> private bool GetSelectedItem(out ListViewItem item, out Settings.KP kp) { if (lvReqSequence.SelectedItems.Count > 0) { item = lvReqSequence.SelectedItems[0]; kp = (Settings.KP)item.Tag; return(true); } else { item = null; kp = null; return(false); } }
/// <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); } } } } }
/// <summary> /// Creates a new list view item that represents a device. /// </summary> private ListViewItem CreateDeviceItem(Settings.KP kp, ref int index) { return(new ListViewItem(new string[] { (++index).ToString(), kp.Active ? "V" : " ", kp.Bind ? "V" : " ", kp.Number.ToString(), kp.Name, kp.Dll, kp.Address.ToString(), kp.CallNum, kp.Timeout.ToString(), kp.Delay.ToString(), kp.Time.ToString("T", Localization.Culture), kp.Period.ToString(), kp.CmdLine }) { Tag = kp }); }
/// <summary> /// Copies properties from the device entity to the device settings. /// </summary> public static void Copy(Entities.KP srcKP, Settings.KP destKP, BaseTable <Entities.KPType> kpTypeTable) { if (srcKP == null) { throw new ArgumentNullException("srcKP"); } if (destKP == null) { throw new ArgumentNullException("destKP"); } destKP.Name = srcKP.Name; destKP.Dll = kpTypeTable != null && kpTypeTable.Items.TryGetValue(srcKP.KPTypeID, out Entities.KPType kpType) ? kpType.DllFileName : ""; destKP.Address = srcKP.Address ?? 0; destKP.CallNum = srcKP.CallNum; }
/// <summary> /// Gets a user interface object for the device. /// </summary> public bool TryGetKPView(Settings.KP kp, bool common, SortedList <string, string> customParams, out KPView kpView, out string errMsg) { try { string dllPath = Path.Combine(AppDirs.KPDir, kp.Dll); kpView = common ? GetKPView(dllPath) : GetKPView(dllPath, kp.Number, new KPView.KPProperties(customParams, kp.CmdLine)); errMsg = null; return(true); } catch (Exception ex) { ErrLog.WriteException(ex); kpView = null; errMsg = ex.Message; return(false); } }
/// <summary> /// Adds the device to the request sequence. /// </summary> private void AddDevice(Settings.KP kp) { try { // add the device lvReqSequence.BeginUpdate(); int index = lvReqSequence.SelectedIndices.Count > 0 ? lvReqSequence.SelectedIndices[0] + 1 : lvReqSequence.Items.Count; lvReqSequence.Items.Insert(index, CreateDeviceItem(kp, ref index)).Selected = true; // update item numbers for (int i = index, cnt = lvReqSequence.Items.Count; i < cnt; i++) { lvReqSequence.Items[i].Text = (i + 1).ToString(); } } finally { lvReqSequence.EndUpdate(); numDeviceNumber.Focus(); OnSettingsChanged(); } }
/// <summary> /// Initializes a new instance of the class. /// </summary> public FrmDeviceCommand(Settings.KP kp, CommEnvironment environment) : this() { this.kp = kp ?? throw new ArgumentNullException("kp"); this.environment = environment ?? throw new ArgumentNullException("environment"); }