/// <summary>
        /// Converts the received row in a string.
        /// </summary>
        /// <param name="row">Data Row</param>
        private string GetRowAsText(DataRow row)
        {
            string lText = "";
            string lAux  = "";
            int    i     = 0;

            // For all the columns in the Row
            foreach (string attribute in mAttributeNames)
            {
                // Defined selection case
                if (mDefinedSelectionOptions[i] != null)
                {
                    lAux = "";
                    for (int j = 0; j < mDefinedSelectionOptions[i].Count; j++)
                    {
                        if (row[attribute].GetType() == typeof(System.DBNull))
                        {
                            if (mDefinedSelectionOptions[i][j].Key == null)
                            {
                                lAux += mDefinedSelectionOptions[i][j].Value;
                                break;
                            }
                        }
                        else
                        {
                            if (mDefinedSelectionOptions[i][j].Key != null &&
                                mDefinedSelectionOptions[i][j].Key.ToString() == row[attribute].ToString())
                            {
                                lAux += mDefinedSelectionOptions[i][j].Value;
                                break;
                            }
                        }
                    }

                    // Value not found in the defined selection set. Apply default
                    if (lAux == "" && row[attribute].GetType() != typeof(System.DBNull))
                    {
                        lAux = DefaultFormats.ApplyDisplayFormat(row[attribute], mTypeList[i]);
                    }
                }
                else
                {
                    lAux = DefaultFormats.ApplyDisplayFormat(row[attribute], mTypeList[i]);
                }
                i++;

                // Separates values with blank space
                if (lText != "")
                {
                    lText += " ";
                }
                lText += lAux;
            }

            return(lText);
        }
示例#2
0
        private string GetInfoFromOid(Oid oid, DisplaySetInformation supplementaryInfo)
        {
            if (oid == null)
            {
                return("");
            }

            // If no Supplementary information is requested, return the Oid values
            if (supplementaryInfo == null)
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));
            }

            // Query to obtain the supplementary information values
            string    displaySet = supplementaryInfo.DisplaySetItemsAsString();
            DataTable lDataTable = null;

            try
            {
                lDataTable = Logic.ExecuteQueryInstance(Logic.Agent, oid, displaySet);
            }
            catch
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));;
            }

            // No data, return empty string
            if (lDataTable == null || lDataTable.Rows.Count == 0)
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));
            }
            ;

            string lResult = "";

            foreach (DisplaySetItem lItem in supplementaryInfo.DisplaySetItems)
            {
                if (!lResult.Equals(""))
                {
                    lResult += " ";
                }

                lResult += DefaultFormats.ApplyDisplayFormat(lDataTable.Rows[0][lItem.Name], lItem.ModelType);
            }

            return(lResult);
        }
        /// <summary>
        /// Shows specified data on ListView.
        /// </summary>
        /// <param name="data">Data to show.</param>
        public void ShowData(DataTable data, List <Oid> selectedOids)
        {
            // Clear Instance selector.
            mValue.Clear();
            // Clear viewer.
            CleanData();

            if ((data != null) && (data.Rows.Count > 0))
            {
                // Load from the DataTable.
                List <DataColumn> displaySetColumns = Adaptor.ServerConnection.GetDisplaySetColumns(data);

                DataRow row = data.Rows[0];

                // Store the Oid
                mValue.Add(Adaptor.ServerConnection.GetLastOid(data));
                // Show data in the ListView
                int i = 0;
                foreach (DataColumn column in displaySetColumns)
                {
                    // Do not continue, if displaySetColumns contains more columns
                    // than elements defined in the ListView control.
                    if (i < mListViewIT.Items.Count)
                    {
                        if (mDefinedSelectionOptions[i] != null)
                        {
                            for (int j = 0; j < mDefinedSelectionOptions[i].Count; j++)
                            {
                                if ((mDefinedSelectionOptions[i][j].Key != null) && (mDefinedSelectionOptions[i][j].Key.ToString() == row.ItemArray[column.Ordinal].ToString()))
                                {
                                    mListViewIT.Items[i].SubItems[1].Text = mDefinedSelectionOptions[i][j].Value;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            mListViewIT.Items[i].SubItems[1].Text = DefaultFormats.ApplyDisplayFormat(row.ItemArray[column.Ordinal], mTypeList[i]);
                        }
                    }
                    i++;
                }
            }

            if (SelectionChanged != null)
            {
                // Obtain the keys to enable or disable the actions and navigations.
                List <string> actionsKeys     = new List <string>();
                List <string> navigationsKeys = new List <string>();
                try
                {
                    DataRow row = data.Rows[0];
                    actionsKeys.Add((string)row[Constants.ACTIONS_ACTIVATION_COLUMN_NAME]);
                    navigationsKeys.Add((string)row[Constants.NAVIGATIONS_ACTIVATION_COLUMN_NAME]);
                }
                catch
                {
                }
                // Raise the event.
                SelectionChanged(this, new SelectedChangedEventArgs(mValue, actionsKeys, navigationsKeys));
            }
        }