コード例 #1
0
 /// <summary>Registers a specific <see cref="IExcelDataAdvice"/> object, i.e. stores
 /// additional information for a specific Excel cell property to improve the usability.
 /// </summary>
 /// <param name="value">The <see cref="IExcelDataAdvice"/> object to register, i.e. represents possible user input
 /// of a specific Excel cell to improve the useability.</param>
 /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns>
 /// <exception cref="ArgumentNullException">Thrown, if <paramref name="value"/> is <c>null</c>.</exception>
 public ItemAddedState Add(IExcelDataAdvice value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     return(ExcelDataAdvice.Pool.Add(value));
 }
コード例 #2
0
 /// <summary>Gets the <see cref="System.String"/> representation of a specific Excel drop down list, i.e. a semicolon separated <see cref="System.String"/>
 /// representation of the enumeration element names.
 /// </summary>
 /// <param name="dataAdvice">A data advice for a specific Excel cell, i.e. possible outcome.</param>
 /// <returns>A semicolon separated <see cref="System.String"/> representation of the enumeration element names or <c>null</c>.</returns>
 /// <remarks>In Excel a semicolon separated <see cref="System.String"/> representation of the possible cell inputs will be used to
 /// create a drop down list to improve the useability, therefore the list will be converted to a <see cref="System.String"/>.</remarks>
 internal string Create(IExcelDataAdvice dataAdvice)
 {
     if (dataAdvice != null)
     {
         return(String.Join(m_DropDownSeparator, dataAdvice.GetPossibleOutcome()));
     }
     return(null);
 }
コード例 #3
0
 /// <summary>Gets the <see cref="IExcelDataAdvice"/> object with respect to a specific position.
 /// </summary>
 /// <param name="rowIndex">The null-based index of the row.</param>
 /// <param name="columnIndex">The null-based index of the column.</param>
 /// <param name="dataAdvice">The <see cref="IExcelDataAdvice"/> object which contains possible outcome which is used to improve the useability of the GUI (output).</param>
 /// <returns>A value indicating whether <paramref name="dataAdvice"/> contains </returns>
 public bool TryGetDataAdvice(int rowIndex, int columnIndex, out IExcelDataAdvice dataAdvice)
 {
     if ((rowIndex < m_Data.Count) && (rowIndex >= 0) && (columnIndex < m_ColumnCount) && (columnIndex >= 0))
     {
         return(m_DataAdvice.TryGetValue(rowIndex * m_ColumnCount + columnIndex, out dataAdvice));
     }
     dataAdvice = null;
     return(false);
 }
コード例 #4
0
 /// <summary>Stores a <see cref="IExcelDataAdvice"/> object at a specific position.
 /// </summary>
 /// <param name="rowIndex">The null-based index of the row.</param>
 /// <param name="columnIndex">The null-based index of the column.</param>
 /// <param name="dataAdvice">The data advice, i.e. a collection of possible outcome to improve the useability of the GUI.
 /// <c>null</c> is allowed.</param>
 public void SetDataAdvice(int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice)
 {
     if (dataAdvice != null)
     {
         int key = rowIndex * m_ColumnCount + columnIndex;
         if (m_DataAdvice.ContainsKey(key))
         {
             m_DataAdvice[key] = dataAdvice;
         }
         else
         {
             m_DataAdvice.Add(key, dataAdvice);
         }
     }
 }
コード例 #5
0
 /// <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)
 {
     throw new InvalidOperationException("Property name/value collection not supported for this kind of Excel Range.");
 }
コード例 #6
0
 /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
 /// </summary>
 /// <typeparam name="T">The type of the output.</typeparam>
 /// <param name="rowIndex">The null-based index of the row.</param>
 /// <param name="columnIndex">The null-based index of the column.</param>
 /// <param name="value">The value (output).</param>
 /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c> (This parameter will be ignored in this implementation).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
 public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
 {
     if ((rowIndex < m_Data.Count) && (rowIndex >= 0) && (columnIndex < m_ColumnCount) && (columnIndex >= 0))
     {
         object data = m_Data[rowIndex][columnIndex];
         if ((data == null) || (data == Type.Missing) || (data is ExcelEmpty) || (data is ExcelMissing) || ((data is String) && (((string)data).Length == 0)))
         {
             value = default(T);
             return(ExcelCellValueState.EmptyOrMissingExcelCell);
         }
         else if (data is T)
         {
             value = (T)data;
             return(ExcelCellValueState.ProperValue);
         }
     }
     value = default(T);
     return(ExcelCellValueState.NoValidValue);
 }
コード例 #7
0
        /// <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 thisPropertyName;

            if (TryGetValue <string>(m_PropertyName, out thisPropertyName, (dataAdvice != null) ? dataAdvice.AsExcelDropDownListString() : null) == ExcelCellValueState.ProperValue)
            {
                if (propertyName.ToIDString() == thisPropertyName.ToIDString())
                {
                    m_GuidedExcelDataQuery.SetData(0, 0, propertyName);
                    m_GuidedExcelDataQuery.SetDataAdvice(0, 0, dataAdvice);
                    rowIndex = 0;
                    return(true);
                }
            }
            m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName);
            rowIndex = -1;
            return(false);
        }
コード例 #8
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (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="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if (typeof(T).IsEnum)
            {
                throw new ArgumentException("The type " + typeof(T).ToString() + " represents a enumeration which is not allowed.", "T");
            }

            if (rowIndex == 0)
            {
                ExcelCellValueState state = ExcelCellValueState.NoValidValue;

                if (columnIndex == 0)
                {
                    state = TryGetValue <T>(m_PropertyName, out value, (dataAdvice != null) ? dataAdvice.AsExcelDropDownListString() : null);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);
                }
                else if (columnIndex == 1)
                {
                    state = TryGetValue <T>(m_PropertyValue, out value, (dataAdvice != null) ? dataAdvice.AsExcelDropDownListString() : null);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);
                }
                else
                {
                    value = default(T);
                    state = ExcelCellValueState.NoValidValue;
                }

                if (state == ExcelCellValueState.ProperValue)
                {
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                }
                else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
                {
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                }
                return(state);
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #9
0
        /// <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> (This parameter will be ignored in this implementation).</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_Data.Count; j++)
            {
                object data = m_Data[j][0];
                if (data is String)
                {
                    if (((string)data).ToIDString() == idPropertyName)
                    {
                        rowIndex = j;
                        return(true);
                    }
                }
            }
            rowIndex = -1;
            return(false);
        }
コード例 #10
0
 /// <summary>Add a specific <see cref="IExcelDataAdvice"/> object into the <see cref="ExcelDataAdvicePool"/>.
 /// </summary>
 /// <param name="value">The excel data advice to register.</param>
 /// <returns>A value indicating whether <paramref name="value"/> has been inserted.</returns>
 internal ItemAddedState Add(IExcelDataAdvice value)
 {
     return(m_ExcelDataAdvice.Add(value));
 }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <summary>Gets the [optional] value of a specific Excel cell.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="value">On input this is a standard value; on exist this argument will be changed if and only if <paramref name="dataQuery"/> contains valid data at the desired position.</param>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been changed and set to some user input.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents an enumeration or if the user input at the desired position can not converted to <typeparamref name="T"/>.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static bool TryGetOptionalValue <T>(this IExcelDataQuery dataQuery, ref T value, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }

            T tempValue;
            ExcelCellValueState state = dataQuery.TryGetValue <T>(out tempValue, rowIndex, columnIndex, dataAdvice);

            if (state == ExcelCellValueState.NoValidValue)
            {
                throw new ArgumentException("No valid input '" + dataQuery.ToString(rowIndex, columnIndex) + "'" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            else if (state == ExcelCellValueState.ProperValue)
            {
                value = tempValue;
                return(true);
            }
            return(false);
        }
コード例 #13
0
        /// <summary>Gets the value of a specific cell.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <returns>The value of the cell at the desired position.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration or no valid input is given by the user.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static T GetValue <T>(this IExcelDataQuery dataQuery, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            T value;

            if (dataQuery.TryGetValue <T>(out value, rowIndex, columnIndex, dataAdvice) == ExcelCellValueState.ProperValue)
            {
                return(value);
            }
            throw new ArgumentException("No valid input '" + dataQuery.ToString(rowIndex, columnIndex) + "' at row: " + rowIndex + ", column: " + columnIndex + " found" + GetFormatedDataQueryName(dataQuery) + ".");
        }
コード例 #14
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (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="value"/> contains valid data.
        /// </returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if ((rowIndex == 0) && (columnIndex == 0))
            {
                m_GuidedExcelDataQuery.SetDataAdvice(0, 0, dataAdvice);

                if (ExcelDataConverter.IsEmptyCell(m_ExcelCellValue) == true)
                {
                    value = default(T);
                    m_GuidedExcelDataQuery.SetData(0, 0, typeof(T));
                    return(ExcelCellValueState.EmptyOrMissingExcelCell);
                }
                if (ExcelDataConverter.TryGetCellValue <T>(m_ExcelCellValue, out value) == true)
                {
                    m_GuidedExcelDataQuery.SetData(0, 0, value);
                    return(ExcelCellValueState.ProperValue);
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #15
0
        /// <summary>Gets the value of a specific property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="value">The value of the property (output).</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents the type of a specific enumeration.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static ExcelPropertyValueState TryGetPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, out T value, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            int rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                value = default(T);
                return(ExcelPropertyValueState.NoPropertyFound);
            }
            ExcelCellValueState state = dataQuery.TryGetValue <T>(out value, rowIndex, propertyValueColumnIndex, dataAdvice);

            if (state == ExcelCellValueState.ProperValue)
            {
                return(ExcelPropertyValueState.ProperProperty);
            }
            else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
            {
                return(ExcelPropertyValueState.ValueIsEmptyExcelCell);
            }
            else
            {
                return(ExcelPropertyValueState.NoValidValue);
            }
        }
コード例 #16
0
        /// <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");
            }

            if (m_ExcelCellValue is String)
            {
                string cellValue = (string)m_ExcelCellValue;
                if (propertyName.ToIDString() == cellValue.ToIDString())
                {
                    rowIndex = 0;
                    m_GuidedExcelDataQuery.SetData(0, 0, cellValue);
                    m_GuidedExcelDataQuery.SetDataAdvice(0, 0, dataAdvice);
                    return(true);
                }
            }
            m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName);
            rowIndex = -1;
            return(false);
        }
コード例 #17
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (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="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if (typeof(T).IsEnum)
            {
                throw new ArgumentException("The type " + typeof(T).ToString() + " represents a enumeration which is not allowed.", "T");
            }
            if ((rowIndex >= 0) && (rowIndex < m_RowCount))
            {
                if (columnIndex == 0)
                {
                    if (dataAdvice != null)
                    {
                        m_PropertyNames.CreateDropdownList(0, rowIndex, dataAdvice.AsExcelDropDownListString());
                    }
                    m_SetOfUsedPropertyIndices.Add(rowIndex);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                    if (ExcelDataConverter.IsEmptyCell(m_PropertyNameArray[0, rowIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_PropertyNameArray[0, rowIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
                else if ((columnIndex >= 1) && (columnIndex < m_ColumnCount))
                {
                    if (dataAdvice != null)
                    {
                        m_PropertyValues.CreateDropdownList(columnIndex - 1, rowIndex, dataAdvice.AsExcelDropDownListString());
                    }
                    m_SetOfUsedPropertyIndices.Add(rowIndex);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                    if (ExcelDataConverter.IsEmptyCell(m_PropertyValueArray[columnIndex - 1, rowIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_PropertyValueArray[columnIndex - 1, rowIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #18
0
        /// <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 (rowIndex = 0; rowIndex < m_RowCount; rowIndex++)
            {
                string tablePropertyName = m_PropertyNameArray[0, rowIndex] as string;
                if ((tablePropertyName != null) && (tablePropertyName.Length > 0))
                {
                    tablePropertyName = tablePropertyName.ToIDString();
                    if (tablePropertyName == idPropertyName)
                    {
                        m_SetOfUsedPropertyIndices.Add(rowIndex);
                        m_GuidedExcelDataQuery.SetData(rowIndex, 0, propertyName);
                        m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, 0, dataAdvice);
                        return(true);
                    }
                }
            }
            m_UnusedOptionalPropertyNames.Add(propertyName);
            m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName);
            rowIndex = -1;
            return(false);
        }
コード例 #19
0
 /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
 /// </summary>
 /// <typeparam name="T">The type of the output.</typeparam>
 /// <param name="rowIndex">The null-based index of the row.</param>
 /// <param name="columnIndex">The null-based index of the column.</param>
 /// <param name="value">The value (output).</param>
 /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>. This parameter will be ignored in this implementation.</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.
 /// </returns>
 /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
 public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
 {
     value = default(T);
     return(ExcelCellValueState.EmptyOrMissingExcelCell);
 }
コード例 #20
0
 /// <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>. This parameter will be ignored in this implementation.</param>
 /// <returns>A value indicating whether <paramref name="rowIndex"/> contains valid data.
 /// </returns>
 public bool TryGetRowIndexOfPropertyName(string propertyName, out int rowIndex, IExcelDataAdvice dataAdvice = null)
 {
     rowIndex = -1;
     return(false);
 }
コード例 #21
0
        /// <summary>Gets the value of a specific [optional] property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="value">On input this is a standard value of the property; on exit this argument will be changed if and only if a property with
        /// name <paramref name="propertyName"/> exists and contains valid data.</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <returns>A value indicating whether <paramref name="value"/> has been changed with user input.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents the type of a specific enumeration or no <b>valid</b> user input is given, i.e.
        /// a property of name <paramref name="propertyName"/> exists but the value is non-empty and can not convert to <typeparamref name="T"/>.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        /// <remarks>Use this method if some standard values are available and the user has the option to change the standard setting.</remarks>
        public static bool TryGetOptionalPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, ref T value, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            T tempValue;
            ExcelPropertyValueState state = TryGetPropertyValue <T>(dataQuery, propertyName, out tempValue, dataAdvice, propertyValueColumnIndex);

            if (state == ExcelPropertyValueState.NoValidValue)
            {
                throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            else if (state == ExcelPropertyValueState.ProperProperty)
            {
                value = tempValue;
                return(true);
            }
            return(false);
        }
コード例 #22
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (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="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if ((rowIndex < RowCount) && (rowIndex >= 0) && (columnIndex < ColumnCount) && (columnIndex >= 0))
            {
                if (dataAdvice != null)
                {
                    m_HeaderRange.CreateDropdownList(rowIndex, columnIndex, dataAdvice.AsExcelDropDownListString());
                }
                m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                if (rowIndex < m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1)  // query the header
                {
                    if (ExcelDataConverter.IsEmptyCell(m_HeaderData[rowIndex, columnIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_HeaderData[rowIndex, columnIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
                else  // query below the header
                {
                    int adjRowIndex = rowIndex - (m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1);
                    if (ExcelDataConverter.IsEmptyCell(m_BelowHeaderData[adjRowIndex, columnIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_BelowHeaderData[adjRowIndex, columnIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #23
0
        /// <summary>Sets an optional property value, i.e. if a specific property value is available the value will be used
        /// to change the state of a specific object, otherwise the standard value will be use.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The property stream.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="trySetPropertyValue">A delegate which is used to set the value of the property for a specific object, if the property value is available.</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        /// <remarks>Use this method for properties which have some standard value if the user does not
        /// enter a specific value, for example the standard tolerance used for a optimizer algorithm is 1e-7 if the
        /// user does not enter a different value.</remarks>
        public static void SetOptionalPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, Func <T, bool> trySetPropertyValue, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            T propertyValue;
            ExcelPropertyValueState state = dataQuery.TryGetPropertyValue <T>(propertyName, out propertyValue, dataAdvice, propertyValueColumnIndex);

            if (state == ExcelPropertyValueState.ProperProperty)
            {
                if (trySetPropertyValue(propertyValue) == false)
                {
                    throw new ArgumentException("Invalid data for property '" + propertyName + "'" + GetFormatedDataQueryName(dataQuery) + ".");
                }
            }
            else if (state == ExcelPropertyValueState.NoValidValue)
            {
                throw new ArgumentException("Invalid data for property '" + propertyName + "'" + GetFormatedDataQueryName(dataQuery) + ".");
            }
        }
コード例 #24
0
        /// <summary>Gets the value of a specific required property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="tryGetPoolElement">A method to pick a specific object.</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param>
        /// <returns>The value of the property.</returns>
        /// <exception cref="ArgumentException">Thrown, if no property or valid value is given by the user.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static T GetRequiredPropertyPoolValue <T>(this IExcelDataQuery dataQuery, string propertyName, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }

            string objectName;
            ExcelPropertyValueState state = dataQuery.TryGetPropertyValue <String>(propertyName, out objectName, dataAdvice);

            if (state == ExcelPropertyValueState.NoPropertyFound)
            {
                throw new ArgumentException("No property with name '" + propertyName + " ' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            else if (state == ExcelPropertyValueState.NoValidValue)
            {
                throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            else if (state == ExcelPropertyValueState.ValueIsEmptyExcelCell)
            {
                throw new ArgumentException("Input required for property '" + propertyName + "'" + GetFormatedDataQueryName(dataQuery) + ".");
            }

            T value;

            if (tryGetPoolElement(objectName, out value) == true)
            {
                return(value);
            }
            throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
        }
コード例 #25
0
        /// <summary>Gets the value of a specific required property.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The <see cref="IExcelDataQuery"/> object.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="dataAdvice">A data advice for a the property value, i.e. possible outcome to improve the useability.</param>
        /// <param name="propertyValueColumnIndex">The null-based index of the column which contains the value.</param>
        /// <returns>The value of the property.</returns>
        /// <exception cref="ArgumentException">Thrown, if no property or valid value is given by the user or if
        /// <typeparamref name="T"/> represents the type of a specific enumeration.</exception>
        public static T GetRequiredPropertyValue <T>(this IExcelDataQuery dataQuery, string propertyName, IExcelDataAdvice dataAdvice = null, int propertyValueColumnIndex = 1)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            T   value;
            int rowIndex;

            if (dataQuery.TryGetRowIndexOfPropertyName(propertyName, out rowIndex) == false)
            {
                throw new ArgumentException("No property with name '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            if (dataQuery.TryGetValue <T>(out value, rowIndex, propertyValueColumnIndex, dataAdvice) == ExcelCellValueState.ProperValue)
            {
                return(value);
            }
            throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
        }
コード例 #26
0
        /// <summary>Gets the value of a specific pool with respect to a specific position of a <see cref="IExcelDataQuery"/> object.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param>
        /// <param name="tryGetPoolElement">A method to pick a specific object.</param>
        /// <param name="value">The value (output).</param>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data; or the Excel cell is empty.</returns>
        /// <exception cref="ArgumentException">Thrown, if the user input is invalid, i.e. the name of the pool item is not given its <see cref="System.String"/> representation.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static bool TryGetPoolValue <T>(this IExcelDataQuery dataQuery, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, out T value, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }

            string objectName;
            ExcelCellValueState state = dataQuery.TryGetValue <String>(out objectName, rowIndex, columnIndex, dataAdvice);

            if (state == ExcelCellValueState.ProperValue)
            {
                return(tryGetPoolElement(objectName, out value));
            }
            else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
            {
                value = default(T);
                return(false);
            }
            throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid input" + GetFormatedDataQueryName(dataQuery) + ".");
        }
コード例 #27
0
 /// <summary>Gets a specific <see cref="IExcelDataAdvice"/>.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value (output).</param>
 /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
 public bool TryGetValue(IdentifierString name, out IExcelDataAdvice value)
 {
     OnInitialize();
     return(m_ExcelDataAdvice.TryGetValue(name, out value));
 }
コード例 #28
0
        /// <summary>Gets the value of a specific pool with respect to a specific position of a <see cref="IExcelDataQuery"/> object.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param>
        /// <param name="tryGetPoolElement">A method to pick a specific object.</param>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param>
        /// <returns>The value.</returns>
        /// <exception cref="ArgumentException">Thrown, if the user input is invalid.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static T GetRequiredPoolValue <T>(this IExcelDataQuery dataQuery, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, int rowIndex = 0, int columnIndex = 0, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }

            string objectName;
            ExcelCellValueState state = dataQuery.TryGetValue <String>(out objectName, rowIndex, columnIndex, dataAdvice);

            T value;

            if (state == ExcelCellValueState.ProperValue)
            {
                if (tryGetPoolElement(objectName, out value) == true)
                {
                    return(value);
                }
                else
                {
                    throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid name" + GetFormatedDataQueryName(dataQuery) + ".");
                }
            }
            else if (state == ExcelCellValueState.EmptyOrMissingExcelCell)
            {
                throw new ArgumentException("Valid pool element name required" + GetFormatedDataQueryName(dataQuery) + ".");
            }
            throw new ArgumentException(dataQuery.ToString(rowIndex, columnIndex) + " is no valid input" + GetFormatedDataQueryName(dataQuery) + ".");
        }
コード例 #29
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (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="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if ((rowIndex < m_RowCount) && (rowIndex >= 0) && (columnIndex < m_ColumnCount) && (columnIndex >= 0))
            {
                m_SetOfUsedPropertyIndices.Add(rowIndex);

                if (dataAdvice != null)
                {
                    m_Range.CreateDropdownList(rowIndex, columnIndex, dataAdvice.AsExcelDropDownListString());
                }
                m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                if (ExcelDataConverter.IsEmptyCell(m_Data[rowIndex, columnIndex]) == true)
                {
                    value = default(T);
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                    return(ExcelCellValueState.EmptyOrMissingExcelCell);
                }
                else if (ExcelDataConverter.TryGetCellValue <T>(m_Data[rowIndex, columnIndex], out value) == true)
                {
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                    return(ExcelCellValueState.ProperValue);
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #30
0
        /// <summary>Gets the value of a specific pool with respect to a specific property name.
        /// </summary>
        /// <typeparam name="T">The type of the value.</typeparam>
        /// <param name="dataQuery">The data query, i.e. property name/value pairs.</param>
        /// <param name="propertyName">The name of the property to search.</param>
        /// <param name="tryGetPoolElement">A method to pick a specific object.</param>
        /// <param name="value">The value of the property (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome to improve the useability, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if the user input is invalid, i.e. the name of the pool item is not given in its <see cref="System.String"/> representation.</exception>
        /// <exception cref="ArgumentNullException">Thrown, if <paramref name="dataQuery"/> is <c>null</c>.</exception>
        public static bool TryGetPropertyPoolValue <T>(this IExcelDataQuery dataQuery, string propertyName, ExcelDataQuery.tTryGetPoolElement <T> tryGetPoolElement, out T value, IExcelDataAdvice dataAdvice = null)
        {
            if (dataQuery == null)
            {
                throw new ArgumentNullException("dataQuery");
            }
            string objectName;
            ExcelPropertyValueState state = dataQuery.TryGetPropertyValue <String>(propertyName, out objectName, dataAdvice);

            if (state == ExcelPropertyValueState.ProperProperty)
            {
                return(tryGetPoolElement(objectName, out value));
            }
            else if ((state == ExcelPropertyValueState.NoPropertyFound) || (state == ExcelPropertyValueState.ValueIsEmptyExcelCell))
            {
                value = default(T);
                return(false);
            }
            throw new ArgumentException("No valid input for property '" + propertyName + "' found" + GetFormatedDataQueryName(dataQuery) + ".");
        }