Example #1
0
 /// <summary>
 /// Read Item
 /// </summary>
 private void ReadItem()
 {
     if (itemsListView.SelectedItems.Count > 0)
     {
         ListViewItem firstSelectedItem = itemsListView.SelectedItems[0];
         if (firstSelectedItem == null)
         {
             return;
         }
         if (firstSelectedItem.Tag == null)
         {
             return;
         }
         string itemText = firstSelectedItem.Text;
         DaItem daItem   = firstSelectedItem.Tag as DaItem;
         if (daItem == null)
         {
             return;
         }
         if (serviceWindow == null)
         {
             return;
         }
         ValueQT itemValues;
         bool    result = serviceWindow.ReadDaItem(daItem, out itemValues);
         if (result)
         {
             firstSelectedItem.SubItems.Clear();
             firstSelectedItem.Text = itemText;
             firstSelectedItem.Tag  = daItem;
             if (daItem.AccessRights != EnumAccessRights.WRITEABLE && itemValues != null)
             {
                 firstSelectedItem.SubItems.Add(ValueConverter.ArrayToString(itemValues));
                 firstSelectedItem.SubItems.Add(itemValues.Quality.ToString());
                 firstSelectedItem.SubItems.Add(ValueConverter.DateTimeOptions(itemValues.TimeStamp));
             }
             else
             {
                 firstSelectedItem.SubItems.Add("");
                 firstSelectedItem.SubItems.Add("");
                 firstSelectedItem.SubItems.Add("");
             }
             firstSelectedItem.SubItems.Add(daItem.DaSubscription.DaSession.Url);
             firstSelectedItem.SubItems.Add(daItem.DaSubscription.Name);
         }
         if (result)
         {
             serviceWindow.Show(this.dockPanel);
         }
     }
 }
Example #2
0
 /// <summary>
 /// Update list view items if are an item form the collection
 /// </summary>
 /// <param name="aDaSubscription"></param>
 /// <param name="items"></param>
 /// <param name="values"></param>
 /// <param name="results"></param>
 public void DataChanged(DaSubscription aDaSubscription, DaItem[] items, ValueQT[] values, int[] results)
 {
     foreach (ListViewItem listViewItem in itemsListView.Items)
     {
         if (listViewItem == null)
         {
             continue;
         }
         if (listViewItem.Tag == null)
         {
             continue;
         }
         DaItem daItem = listViewItem.Tag as DaItem;
         if (daItem == null)
         {
             continue;
         }
         string itemText = listViewItem.Text;
         for (int i = 0; i < items.Length; i++)
         {
             if (daItem == items[i])
             {
                 if (ResultCode.SUCCEEDED(results[i]))
                 {
                     listViewItem.SubItems.Clear();
                     listViewItem.Text = itemText;
                     listViewItem.Tag  = daItem;
                     if (daItem.AccessRights != EnumAccessRights.WRITEABLE && values[i] != null)
                     {
                         listViewItem.SubItems.Add(ValueConverter.ArrayToString(values[i]));
                         listViewItem.SubItems.Add(values[i].Quality.ToString());
                         listViewItem.SubItems.Add(ValueConverter.DateTimeOptions(values[i].TimeStamp));
                     }
                     else
                     {
                         listViewItem.SubItems.Add("");
                         listViewItem.SubItems.Add("");
                         listViewItem.SubItems.Add("");
                     }
                     listViewItem.SubItems.Add(daItem.DaSubscription.DaSession.Url);
                     listViewItem.SubItems.Add(daItem.DaSubscription.Name);
                 }
             }
         }
     }
 }
Example #3
0
        /// <summary>
        /// Add List View Items
        /// </summary>
        /// <param name="item"></param>
        /// <param name="itemValuesO"></param>
        private void AddListViewItem(DaItem item, ValueQT itemValues)
        {
            ListViewItem listViewItem = new ListViewItem(item.Id);

            if (item.AccessRights != EnumAccessRights.WRITEABLE && itemValues != null)
            {
                listViewItem.SubItems.Add(ValueConverter.ArrayToString(itemValues));
                listViewItem.SubItems.Add(itemValues.Quality.ToString());
                listViewItem.SubItems.Add(ValueConverter.DateTimeOptions(itemValues.TimeStamp));
            }
            else
            {
                listViewItem.SubItems.Add("");
                listViewItem.SubItems.Add("");
                listViewItem.SubItems.Add("");
            }
            listViewItem.SubItems.Add(item.DaSubscription.DaSession.Url);
            listViewItem.SubItems.Add(item.DaSubscription.Name);
            listViewItem.Tag = item;
            SetItemImage(item.CurrentState, listViewItem);
            itemsListView.Items.Add(listViewItem);
            item.StateChangeCompleted -= new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted);
            item.StateChangeCompleted += new Softing.OPCToolbox.Client.StateChangeEventHandler(item_StateChangeCompleted);
        }
 /// <summary>
 /// Fill Read Service Data
 /// </summary>
 /// <param name="itemId"></param>
 /// <param name="hasReadRights"></param>
 /// <param name="itemValues"></param>
 /// <returns></returns>
 private Helper.CustomProperties FillReadService(string itemId, bool hasReadRights, ValueQT itemValues)
 {
     //display the read values
     Helper.CustomProperties readServiceColl = new DemoClient.Helper.CustomProperties();
     Helper.CustomProperty   customProperty  = new DemoClient.Helper.CustomProperty("Item Id",
                                                                                    "System.String", null, null, itemId);
     customProperty.Attributes = new Attribute[] {
         ReadOnlyAttribute.Yes
     };
     readServiceColl.Properties.Add(customProperty);
     if (hasReadRights && itemValues != null)
     {
         customProperty = new DemoClient.Helper.CustomProperty("Value",
                                                               "System.String", null, null, ValueConverter.ArrayToString(itemValues));
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
         customProperty = new DemoClient.Helper.CustomProperty("Quality",
                                                               "System.String", null, null, itemValues.Quality.ToString());
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
         customProperty = new DemoClient.Helper.CustomProperty("Time Stamp",
                                                               "System.String", null, null, ValueConverter.DateTimeOptions(itemValues.TimeStamp));
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
     }
     else
     {
         //there are no read values, fiil data with empty strings
         customProperty = new DemoClient.Helper.CustomProperty("Value",
                                                               "System.String", null, null, "");
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
         customProperty = new DemoClient.Helper.CustomProperty("Quality",
                                                               "System.String", null, null, "");
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
         customProperty = new DemoClient.Helper.CustomProperty("Time Stamp",
                                                               "System.String", null, null, "");
         customProperty.Attributes = new Attribute[] {
             ReadOnlyAttribute.Yes
         };
         readServiceColl.Properties.Add(customProperty);
     }
     return(readServiceColl);
 }
        /// <summary>
        /// Fill Write Service
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="hasWriteAccess"></param>
        /// <param name="itemValue"></param>
        private Helper.CustomProperties FillWriteService(string itemId, Type itemDataType, bool hasWriteAccess, ValueQT itemValues)
        {
            Helper.DataTypes dataTypeHelper = new DataTypes();

            Helper.CustomProperties writeServiceColl = new DemoClient.Helper.CustomProperties();
            Helper.CustomProperty   customProperty   = new DemoClient.Helper.CustomProperty("Item Id",
                                                                                            "System.String", null, null, itemId);
            customProperty.Attributes = new Attribute[] {
                ReadOnlyAttribute.Yes
            };
            writeServiceColl.Properties.Add(customProperty);

            //create the DaItem value
            if (!itemValues.Data.GetType().IsArray)
            {
                //the DaItem VALUE is not an array
                customProperty = new DemoClient.Helper.CustomProperty("Value",
                                                                      "System.String", null, null, ValueConverter.ArrayToString(itemValues));
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);

                dataTypeHelper.Type = itemDataType;
                customProperty      = new DemoClient.Helper.CustomProperty("Data Type",
                                                                           dataTypeHelper.RequiredDataTypes.Values.GetType().ToString(), null, null, dataTypeHelper.NativeDataType,
                                                                           typeof(Helper.DataTypeEditor), typeof(Helper.DataTypeEditor));
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);

                customProperty = new DemoClient.Helper.CustomProperty("Start Index",
                                                                      "System.String", null, null, "");
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);
            }
            else
            {
                //DaItem VALUE is an Array
                customProperty = new DemoClient.Helper.CustomProperty("Value",
                                                                      "System.String", null, null, ValueConverter.DataToString(itemValues));
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);

                Array dataArray = itemValues.Data as Array;

                if (dataArray.GetLowerBound(0) == 0)
                {
                    dataTypeHelper.Type = itemDataType;
                    customProperty      = new DemoClient.Helper.CustomProperty("Data Type",
                                                                               dataTypeHelper.RequiredDataTypes.Values.GetType().ToString(), null, null, dataTypeHelper.NativeDataType,
                                                                               typeof(Helper.DataTypeEditor), typeof(Helper.DataTypeEditor));
                }
                else
                {
                    string dataType = dataArray.GetType().ToString();
                    dataType            = dataType.Remove(dataType.IndexOf('*'));
                    dataTypeHelper.Type = System.Type.GetType(dataType);
                    customProperty      = new DemoClient.Helper.CustomProperty("Data Type",
                                                                               dataTypeHelper.RequiredDataTypes.Values.GetType().ToString(), null, null, dataTypeHelper.NativeDataType,
                                                                               typeof(Helper.DataTypeEditor), typeof(Helper.DataTypeEditor));
                }
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);

                customProperty = new DemoClient.Helper.CustomProperty("Start Index",
                                                                      "System.Int32", null, null, dataArray.GetLowerBound(0));
                if (!hasWriteAccess)
                {
                    customProperty.Attributes = new Attribute[] {
                        ReadOnlyAttribute.Yes
                    };
                }
                writeServiceColl.Properties.Add(customProperty);
            }
            return(writeServiceColl);
        }