コード例 #1
0
        /// <summary>
        /// Get the value of the first item within the collection.
        /// </summary>
        /// <typeparam name="TItemModel">Item type with the collection.</typeparam>
        /// <typeparam name="TResult">The result type to return.</typeparam>
        /// <param name="items">The collection of item model types</param>
        /// <param name="itemModelPropertyName">The item model property name to match</param>
        /// <returns>The first value within the collection.</returns>
        public static TResult GetFirstValue <TItemModel, TResult>(IList items, string itemModelPropertyName)
        {
            TResult value = default(TResult);

            if (items.Count > 0)
            {
                // Create the enumerator.
                System.Collections.IEnumerator dataObjects = items.GetEnumerator();

                // Iterate through the collection.
                while (dataObjects.MoveNext())
                {
                    // Get the current object.
                    object     currentDataObject = dataObjects.Current;
                    TItemModel itemType          = (TItemModel)currentDataObject;

                    // Get the property value.
                    value = ((TResult)itemType.GetType().GetProperty(itemModelPropertyName).GetValue(itemType, null));
                    break;
                }
                dataObjects.Reset();
            }

            // Return the value.
            return(value);
        }
コード例 #2
0
        public static void AddCustomXmlPart(Excel.Workbook workbook, string namespaceName, string xmlString)
        {
            System.Collections.IEnumerator enumerator = workbook.CustomXMLParts.SelectByNamespace(namespaceName).GetEnumerator();
            enumerator.Reset();

            if (!(enumerator.MoveNext())) // false if XmlPart already exists
            {
                Office.CustomXMLPart p = workbook.CustomXMLParts.Add(xmlString);
            }
        }
コード例 #3
0
        /// <summary>
        /// Data grid selected changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Create the enumerator.
            System.Collections.IEnumerator dataObjects = e.AddedItems.GetEnumerator();

            // Iterate through the collection.
            while (dataObjects.MoveNext())
            {
                object currentDataObject = dataObjects.Current;
                _selectedRecord = currentDataObject;
            }
            dataObjects.Reset();

            // Send a single that the slected record has changed.
            if (OnSelectedRecordChanged != null)
            {
                OnSelectedRecordChanged(this, new EventArgs());
            }
        }
コード例 #4
0
ファイル: Operation.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Get the selected index list bindings.
        /// </summary>
        /// <typeparam name="TItemModel">Item type with the collection.</typeparam>
        /// <typeparam name="TDataModel">The data model from the collection</typeparam>
        /// <param name="items">The collection of item model types</param>
        /// <param name="itemModelPropertyName">The item model property name to match</param>
        /// <param name="dataModel">The data model instance.</param>
        /// <param name="dataModelPropertyName">The data model property name to match.</param>
        /// <returns>The selected index from the item collection.</returns>
        public static int GetSelectedIndex <TItemModel, TDataModel>(
            ItemCollection items, string itemModelPropertyName, TDataModel dataModel, string dataModelPropertyName)
        {
            int selectedIndex = -1;

            if (items.Count > 0)
            {
                // Create the enumerator.
                System.Collections.IEnumerator dataObjects = items.SourceCollection.GetEnumerator();

                // Iterate through the collection.
                while (dataObjects.MoveNext())
                {
                    // Get the current object.
                    object     currentDataObject = dataObjects.Current;
                    TItemModel itemType          = (TItemModel)currentDataObject;

                    try
                    {
                        // Find the first occurence of the income type match.
                        if (itemType.GetType().GetProperty(itemModelPropertyName).GetValue(itemType, null).ToString().ToLower() ==
                            dataModel.GetType().GetProperty(dataModelPropertyName).GetValue(dataModel, null).ToString().ToLower())
                        {
                            // Set the index of the item
                            selectedIndex = items.IndexOf(currentDataObject);
                            break;
                        }
                    }
                    catch { }
                }
                dataObjects.Reset();
            }

            // Return the index.
            return(selectedIndex);
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 public void Reset()
 {
     wrapped.Reset();
 }
コード例 #6
0
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void Reset()
 {
     baseEnumerator.Reset();
 }
コード例 #7
0
ファイル: Config.cs プロジェクト: tzvis1/winforms-demos
 public void Reset()
 {
     iEnBase.Reset();
 }
コード例 #8
0
        //************************************************************************
        /// <summary>
        /// Data Class内容LOG输出
        /// <param name="argLoglevel">LOG级别</param>
        /// <param name="argFqcn">Class名</param>
        /// <param name="argMethodName">method名</param>
        /// <param name="argDataName">Data名</param>
        /// <param name="argDataObject">dataobject</param>
        /// <param name="argUserID">用户名</param>
        /// <param name="argIpAddress">IPAddress</param>
        /// </summary>
        //************************************************************************
        private void WriteDataLog(LogLevelEnum argLoglevel, string argFqcn, string argMethodName, string argDataName, object argDataObject)
        {
            string strMessage = "";

            // Data Object为null时、NULL输出返回
            if (argDataObject == null)
            {
                strMessage = argDataName + "\t" + "NULL";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);
                return;
            }

            #region 反射写出数据
            // object的类型取得
            Type classType = argDataObject.GetType();

            // 基本型时
            if (isBaseType(classType))
            {
                // 基本型时
                strMessage  = argDataName + "\t" + "[" + classType.Name + "]";
                strMessage += "\t" + "[" + argDataObject.ToString() + "]";

                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);
                return;
            }

            // Array时
            if (classType.IsArray)
            {
                long[] indexArray = null;;

                int intArrayLength = ((Array)argDataObject).Length;
                for (int index = 0; index < intArrayLength; index++)
                {
                    indexArray = getArrayMember((Array)argDataObject, index);
                    object arrayObj = ((Array)argDataObject).GetValue(indexArray);

                    // Array的名称取得
                    string objName = argDataName + "[" + indexArray[0].ToString();
                    for (int i = 1; i < indexArray.Length; i++)
                    {
                        objName += "," + indexArray[i].ToString();
                    }
                    objName += "]";

                    // Array的名称为NUll时
                    if (arrayObj == null)
                    {
                        strMessage  = objName + "\t" + "[" + argDataObject.GetType().GetElementType().Name + "]";
                        strMessage += "\t" + "NULL";
                        WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);
                    }
                    else
                    {
                        WriteDataLog(argLoglevel, argFqcn, argMethodName, objName, arrayObj);
                    }
                }
                return;
            }

            string strSpace = "";
            for (int temp = 0; temp < argDataName.Length; temp++)
            {
                if (argDataName.Substring(temp, 1) == " ")
                {
                    strSpace += " ";
                }
                else if (argDataName.Substring(temp, 1) == " ")
                {
                    strSpace += " ";
                }
                else
                {
                    break;
                }
            }
            strSpace += "   ";

            // Hashtable 时
            if (classType.Name == "Hashtable")
            {
                Hashtable ht = (Hashtable)argDataObject;
                System.Collections.IEnumerator keyEnum = ht.Keys.GetEnumerator();
                int count = ht.Count;
                keyEnum.Reset();
                strMessage = argDataName + "----------------------";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                for (int i = 0; i < count; i++)
                {
                    keyEnum.MoveNext();
                    object hashKey   = keyEnum.Current; // Key
                    object hashValue = ht[hashKey];     // Value
                    WriteDataLog(argLoglevel, argFqcn, argMethodName, strSpace + hashKey.ToString(), hashValue);
                }
                return;
            }

            // ArrayList时
            if (classType.Name == "ArrayList")
            {
                ArrayList at    = (ArrayList)argDataObject;
                int       count = at.Count;
                strMessage = argDataName + "----------------------";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                for (int i = 0; i < count; i++)
                {
                    WriteDataLog(argLoglevel, argFqcn, argMethodName, strSpace + "[" + i.ToString() + "]", at[i].ToString());
                }
                return;
            }

            // DataSet时
            if (classType.Name == "DataSet" || classType.BaseType.Name == "DataSet")
            {
                strMessage = argDataName + "----------------------";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                foreach (DataTable myDataTable in ((DataSet)argDataObject).Tables)
                {
                    strMessage = strSpace + "Table名:" + "\t" + "[" + myDataTable.TableName + "]";
                    WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                    int intCurrentRow = 0;
                    foreach (DataRow myRow in myDataTable.Rows)
                    {
                        foreach (DataColumn myColumn in myDataTable.Columns)
                        {
                            WriteDataLog(argLoglevel, argFqcn, argMethodName, strSpace + myColumn.ColumnName + "[" + intCurrentRow.ToString() + "]", myRow[myColumn]);
                        }
                        intCurrentRow++;
                    }
                }
                return;
            }

            // DataTable时
            if (classType.Name == "DataTable" || classType.BaseType.Name == "DataTable")
            {
                strMessage = argDataName + "----------------------";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                DataTable myDataTable = (DataTable)argDataObject;

                strMessage = strSpace + "Table名:" + "\t" + "[" + myDataTable.TableName + "]";
                WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

                int intCurrentRow = 0;
                foreach (DataRow myRow in myDataTable.Rows)
                {
                    foreach (DataColumn myColumn in myDataTable.Columns)
                    {
                        WriteDataLog(argLoglevel, argFqcn, argMethodName, strSpace + myColumn.ColumnName + "[" + intCurrentRow.ToString() + "]", myRow[myColumn]);
                    }
                    intCurrentRow++;
                }
                return;
            }

            // 基本型、array、Hashtable以外时
            strMessage = argDataName + "----------------------";
            WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);

            System.Reflection.PropertyInfo[]    pi             = classType.GetProperties();
            System.Reflection.MemberInfo[]      classMembInfo  = classType.GetMembers();
            System.Reflection.FieldInfo[]       classFieldInfo = classType.GetFields();
            System.Reflection.ConstructorInfo[] classConstInfo = classType.GetConstructors();
            // 各属性输出
            foreach (System.Reflection.PropertyInfo tpi in pi)
            {
                if (tpi.GetValue(argDataObject, null) == null)
                {
                    strMessage  = strSpace + tpi.Name + "\t" + "[" + tpi.PropertyType.Name + "]";
                    strMessage += "\t" + "NULL";
                    WriteLogFile(argLoglevel, argFqcn, argMethodName, strMessage, null);
                }
                else
                {
                    WriteDataLog(argLoglevel, argFqcn, argMethodName, strSpace + tpi.Name, tpi.GetValue(argDataObject, null));
                }
            }
            #endregion
        }
コード例 #9
0
 public void Reset()
 {
     _enumerator.Reset();
 }
コード例 #10
0
ファイル: DataAccess.xaml.cs プロジェクト: jamecook/projects
        /// <summary>
        /// Delete the data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Should the delete continue or be cancelled
                if (OnBeforeDelete != null)
                {
                    Nequeo.Custom.OperationArgs operation = new Nequeo.Custom.OperationArgs(false);
                    OnBeforeDelete(this, operation);

                    // Cancel operation if true.
                    if (operation.Cancel)
                    {
                        return;
                    }
                }

                // Build the current data object type and
                // the  select data model generic type.
                Type dataType = Type.GetType(ConnectionTypeModel.DataObjectTypeName, true, true);
                Type dataAccessProviderType = Type.GetType(ConnectionTypeModel.DataAccessProvider, true, true);
                Type listGenericType        = typeof(DeleteDataGenericBase <>);

                // Create the generic type parameters
                // and create the genric type.
                Type[] typeArgs = { dataType };
                Type   listGenericTypeConstructor = listGenericType.MakeGenericType(typeArgs);

                // Add the genric tyoe contructor parameters
                // and create the generic type instance.
                object[] parameters = new object[] {
                    ConnectionTypeModel.DatabaseConnection,
                    ConnectionTypeModel.ConnectionType,
                    ConnectionTypeModel.ConnectionDataType,
                    ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType))
                };
                object listGeneric = Activator.CreateInstance(listGenericTypeConstructor, parameters);

                // If the data model is enumerable
                if (DataModel is System.Collections.IEnumerable)
                {
                    // Cast the data object type as an enumerable object,
                    // get the enumerator.
                    System.Collections.IEnumerable items       = (System.Collections.IEnumerable)DataModel;
                    System.Collections.IEnumerator dataObjects = items.GetEnumerator();
                    List <PropertyInfo>            properties  = dataType.GetProperties().ToList();

                    // Iterate through the collection.
                    while (dataObjects.MoveNext())
                    {
                        object currentDataObject = dataObjects.Current;

                        // Get the current object.
                        Object[] args = new Object[]
                        {
                            currentDataObject
                        };

                        // Add the current data row to the
                        // business object collection.
                        object ret = listGeneric.GetType().InvokeMember("DeleteItem",
                                                                        BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                                        BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                                        null, listGeneric, args);
                    }
                    dataObjects.Reset();
                }
                else
                {
                    // Get the current object.
                    Object[] args = new Object[]
                    {
                        DataModel
                    };

                    // Add the current data row to the
                    // business object collection.
                    object ret = listGeneric.GetType().InvokeMember("DeleteItem",
                                                                    BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                                    BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                                    null, listGeneric, args);
                }

                if (OnDelete != null)
                {
                    OnDelete(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                string inner = ex.InnerException != null ? ex.InnerException.Message : string.Empty;
                if (OnDeleteError != null)
                {
                    OnDeleteError(this, new Nequeo.Custom.MessageArgs(ex.Message + " " + inner));
                }
            }
        }
コード例 #11
0
ファイル: XLSX.cs プロジェクト: soravroyal/EPRTR
 public void Reset()
 {
     iterator.Reset();
 }
コード例 #12
0
ファイル: FeatLyrFrm.cs プロジェクト: QingleCheng/WindowDemo
        /// <summary>
        /// 按下"添加所有值"按钮后,让table按当前字段的值进行排序,并把信息添加到listView里面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUniValueAddAllValues_Click(object sender, EventArgs e)
        {
            try
            {
                string currentFieldName = this.cbbUniValueField.Text;                                             //当前字段名

                string currentFieldType     = this.lsvFields.FindItemWithText(currentFieldName).SubItems[2].Text; //当前字段类型
                bool   currentTypeIsNumeric = false;                                                              //判断当前字段类型是否为数字类型
                if (currentFieldType == "Short Integer" || currentFieldType == "Long Integer" || currentFieldType == "Float" || currentFieldType == "Double")
                {
                    currentTypeIsNumeric = true;
                }

                this.lsvUniqueValue.Items.Clear();

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable     pTable     = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table  = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field  = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues; //唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;                               //唯一值的个数

                //table中当前字段有值(不为null)的row的个数,并把信息添加到listView的第一行
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.AddField(currentFieldName);
                int valueSum = pTable.RowCount(pQueryFilter);
                this.lsvUniqueValue.Items.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(valueSum.ToString());

                //循环把信息添加到listView里
                int    i            = 1;    //注意!是从1开始,因为第一行已经被占用
                string currentValue = null; //指示当前的值
                //IDataStatistics pUniValueStatistics = new DataStatisticsClass();
                int currentValueCount;
                for (pEnumeratorUniqueValues.Reset(); pEnumeratorUniqueValues.MoveNext(); i++)
                {
                    currentValue = pEnumeratorUniqueValues.Current.ToString();//当前值
                    this.lsvUniqueValue.Items.Add(currentValue);
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValue);
                    //需要这个if的原因是SQL语句中数字和非数字的写法不一样
                    if (currentTypeIsNumeric)
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + currentValue;
                    }
                    else
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + "'" + currentValue + "'";
                    }
                    currentValueCount = pTable.RowCount(pQueryFilter);//table中该字段是当前值的row的个数
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValueCount.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }