/// <summary>Gets the null-based row index of a specific property.
        /// </summary>
        /// <param name="propertyName">The name of the property to search (in the first column).</param>
        /// <param name="rowIndex">The null-based index of the row which contains the property (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="rowIndex"/> contains valid data.</returns>
        public bool TryGetRowIndexOfPropertyName(string propertyName, out int rowIndex, IExcelDataAdvice dataAdvice = null)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }
            string idPropertyName = propertyName.ToIDString();

            for (int j = 0; j < m_RowCount; j++)
            {
                if (m_Data[j, 0] is String)
                {
                    string cellName = (string)m_Data[j, 0];

                    if (cellName.ToIDString() == idPropertyName)
                    {
                        rowIndex = j;
                        if (dataAdvice != null)
                        {
                            ExcelLowLevel.CreateDropdownList(m_Range, rowIndex, 0, dataAdvice.AsExcelDropDownListString());
                        }
                        m_SetOfUsedPropertyIndices.Add(rowIndex);
                        m_GuidedExcelDataQuery.SetData(rowIndex, 0, cellName);
                        m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, 0, dataAdvice);
                        return(true);
                    }
                }
            }
            m_UnusedOptionalPropertyNames.Add(propertyName);
            m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName);
            rowIndex = -1;
            return(false);
        }
示例#2
0
 /// <summary>Finalize the current <see cref="IExcelDataQuery"/> instance.
 /// </summary>
 /// <param name="throwExceptionIfDataIsNotUsed">A value indicating whether an exception will be thrown, if some of the data are are not queried by the user.</param>
 /// <exception cref="ArgumentException">Thrown, if <paramref name="throwExceptionIfDataIsNotUsed"/> is <c>true</c> and a property or table entry has been detected which
 /// is not queried, i.e. not used.</exception>
 /// <remarks>Call this method before calling <see cref="IExcelDataQuery.AsCustomizeData()"/> to check the user input; perhaps the user has enter properties or values
 /// which are not used by the program and an exception will be shown to indicate wrong user input.</remarks>
 public void QueryCompleted(bool throwExceptionIfDataIsNotUsed = true)
 {
     if (throwExceptionIfDataIsNotUsed)
     {
         string unusedOptionalPropertyNameDropDownList = null;
         if (m_UnusedOptionalPropertyNames.Count > 0)
         {
             unusedOptionalPropertyNameDropDownList = m_UnusedOptionalPropertyNames.AsExcelDropDownListString();
         }
         for (int j = 0; j < m_RowCount; j++)
         {
             if (m_SetOfUsedPropertyIndices.Contains(j) == false)
             {
                 for (int k = 0; k < m_ColumnCount - 1; k++)
                 {
                     if (ExcelDataConverter.IsEmptyCell(m_PropertyNameArray[0, j]) == false)
                     {
                         throw new ArgumentException("Invalid property '" + m_PropertyNameArray[0, j] + "'.");
                     }
                     else if (ExcelDataConverter.IsEmptyCell(m_PropertyValueArray[k, j]) == false)
                     {
                         throw new ArgumentException("Invalid value '" + m_PropertyValueArray[k, j] + "'.");
                     }
                     else
                     {
                         ExcelLowLevel.CreateDropdownList(m_PropertyNames, 0, j, unusedOptionalPropertyNameDropDownList);
                     }
                 }
             }
         }
     }
 }