12 Replies Latest reply on Mar 22, 2018 3:21 AM by Eugene Lee

    OSIsoft.AF.UI.AFUOMDropDown

    Nocodes79

      I need to imlement some kind of UOM selector similar to the one used in PI System Explorer to select the UOM for an attribute.

       

      I found a control (OSIsoft.AF.UI.AFUOMDropDown) which should do the trick, but I could not find any hint about how to use it in documentation and pisquare. Anybody has used it?

      How can I get all the UOM's from the UOM Database (easily)?.

        • Re: OSIsoft.AF.UI.AFUOMDropDown
          Rick Davin

          Hi Nicola.

           

          I just tried playing around with the AFUOMDropDown control but had no luck.  There's no help in Live Library or in PIPC\help\AFUIRef.chm.

           

          You can get the items and populate your own list or combo boxes.  The UOMDatabase is a property of a PISystem object.  For a given UOMDatabase, you can inspect its UOMClasses and UOMs properties.

            • Re: OSIsoft.AF.UI.AFUOMDropDown
              Asle Frantzen

              Rick Davin wrote:

               

               

              I just tried playing around with the AFUOMDropDown control but had no luck. There's no help in Live Library or in PIPC\help\AFUIRef.chm.

               

              Using this opportunity to ask (again) for a blog post or best practises document on how to use the AF UI controls, which ones are the most common, how do they look, etc. OSIsoft is probably the only provider of a UI library where there controls aren't identified properly (with pictures in a documentation).

            • Re: OSIsoft.AF.UI.AFUOMDropDown
              Eugene Lee

              Hi Nicola,

               

              You will need to initialize the control like this.

              afuomDropDown1.InitializeObject(new PISystems().DefaultPISystem.UOMDatabase);

               

              Then, you can use AFSelection property during the SelectedIndexChanged event to get the UOM class. This object has properties such as Name and Abbreviation that you can use.

               

              1 of 1 people found this helpful
              • Re: OSIsoft.AF.UI.AFUOMDropDown
                Nocodes79

                Hi everybody,

                 

                now I have the same problem with OSIsoft.AF.UI.AFTypesDropDown, which I suppose that is the dropdown to select the type for the attribute and eventually an enumeration.

                 

                I tried to initialize as the AFUOMDropDown, but trying to feed other PI System variables, but I could not get it working.

                 

                How should it be iniitalized?

                  • Re: OSIsoft.AF.UI.AFUOMDropDown
                    Marcos Vainer Loeff

                    Hello,

                     

                    You should use an AFDatabase object as input:

                     

                                afTypesDropDown1.InitializeObject(new PISystems().DefaultPISystem.Databases.DefaultDatabase);
                    

                     

                    Hope it helps!

                    2 of 2 people found this helpful
                      • Re: OSIsoft.AF.UI.AFUOMDropDown
                        Nocodes79

                        Thank you Marcos!

                         

                        It was to expect, as it shows AFEnumerations which are defined in databases, but I still did not try for some strange reason.

                        • Re: OSIsoft.AF.UI.AFUOMDropDown
                          Nocodes79

                          Still with the same control OSIsoft.AF.UI.AFTypesDropDown.

                           

                          Now I am into getting the type of an attribute and select the corresponding type in the dropdown and getting the value from the drodown and setting the type of the attribute to the one selected in the dropdown.

                           

                          For basic types and object types it is quite easy using AFSelection property of the control, but I cannot get it working with arrays and enemeration sets. Any hint?

                            • Re: OSIsoft.AF.UI.AFUOMDropDown
                              Marcos Vainer Loeff

                              It is a little tricky, but I was able to do it!

                               

                                          var aftype = ((OSIsoft.AF.UI.AFType)afTypesDropDown1.AFSelection).OriginalObject;
                                          AFEnumerationSet enumSet = (AFEnumerationSet)aftype;
                              
                              2 of 2 people found this helpful
                                • Re: OSIsoft.AF.UI.AFUOMDropDown
                                  Nocodes79

                                  Thank you very much Marcos. Starting with your example I just did the following to detect an attribute type and show it in the drop down.

                                   

                                  First convert attribute type to correct AFType used in the control:

                                  public static OSIsoft.AF.UI.AFType GetTypeAttribute(AFAttributeTemplate attrToConvert)
                                          {
                                              OSIsoft.AF.UI.AFType returnType;
                                              if (attrToConvert.Type.IsArray)
                                              {
                                                  returnType = new OSIsoft.AF.UI.AFType(attrToConvert.Type, true);
                                              }
                                              else if (attrToConvert.TypeQualifier != null && attrToConvert.TypeQualifier.GetType() == typeof(AFEnumerationSet))
                                              {
                                                  returnType = new OSIsoft.AF.UI.AFType(attrToConvert.TypeQualifier);
                                              }
                                              else
                                              {
                                                  returnType = new OSIsoft.AF.UI.AFType(attrToConvert.Type);
                                              }
                                              return returnType;
                                          }
                                  

                                   

                                  Then, to show the type of the attribute in the dropdown

                                                  OSIsoft.AF.UI.AFType attrType = AFAttrTemplateCreateEdit.GetTypeAttribute(inputAttribute);
                                                  if (attrType.IsEnumerationValue)
                                                  {
                                                      afTypesDropDown.AFSelection = ((AFEnumerationSet) attrType.OriginalObject).Name;
                                                  }
                                                  else if (attrType.IsArray)
                                                  {
                                                      afTypesDropDown.AFSelection = attrType.ToString().Replace("[]", "");
                                                  }
                                                  else
                                                  {
                                                      afTypesDropDown.AFSelection = attrType.ToString();
                                                  }
                                  

                                   

                                   

                                  Finally I used the type eventually selected in the dropdown to set the type of the attribute whose type I want to edit:

                                              AFAttribute attribute2Edit =  //... get the attribute to edit type
                                              OSIsoft.AF.UI.AFType dropDownType = (OSIsoft.AF.UI.AFType)afTypesDropDown.AFSelection;
                                              if (dropDownType.IsEnumerationValue)
                                              {
                                                  attribute2Edit.Type = typeof(AFEnumerationValue);
                                                  attribute2Edit.TypeQualifier = (AFEnumerationSet)dropDownType.OriginalObject;
                                              }
                                              else if (dropDownType.IsArray)
                                              {
                                                  attribute2Edit.Type = dropDownType.VarType;
                                              }
                                              else
                                              {
                                                  attribute2Edit.Type = dropDownType.BaseType;
                                              }
                                  

                                  Hope it helps

                                  2 of 2 people found this helpful