Exemple #1
0
        /// <summary>
        /// 按设定的条件执行搜索。
        /// </summary>
        /// <param name="pageNum">搜索指定页的设备。如果要搜索第2页及其之后页的数据,则应先设置 PageSize 属性。</param>
        /// <param name="isReverse">是否对排序信息 OrderInfos 中设定的排序条件执行倒序,如果该参数为 true 将导致整个搜索结果的先后顺序发生逆转,通常情况下应使用 false。</param>
        /// <param name="keepSource">是否保留所有设备至该搜索结果集合源的引用。当需要对设备进行进一步的数据查询操作,保留源引用可以提升查询性能。</param>
        /// <returns>符合条件的设备集合。</returns>
        public DeviceCollection Search(int pageNum, bool isReverse, bool keepSource)
        {
            base.PageNum = pageNum;

            DeviceCollection devices = new DeviceCollection(keepSource);

            try
            {
                System.Data.IDataReader dr = base.GetDataReader(isReverse);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        int intDeviceId = Function.ToInt(dr[Tables.Device.DeviceId]);

                        Device device = base.Application.GetDeviceInstance(intDeviceId);
                        if (device != null)
                        {
                            device.SetDataReader(dr);
                            if (this.Found != null)
                            {
                                if (keepSource)
                                {
                                    if (isReverse)
                                    {
                                        devices.Insert(0, device);
                                    }
                                    else
                                    {
                                        devices.Add(device);
                                    }
                                }
                                this.Found(device);
                            }
                            else
                            {
                                if (isReverse)
                                {
                                    devices.Insert(0, device);
                                }
                                else
                                {
                                    devices.Add(device);
                                }
                            }

                            device.DateRange = this.m_DateRange;
                        }
                        else
                        {
                            DeviceType deviceType = base.Application.DeviceTypeSort.GetDeviceType(Function.ToString(dr[Tables.Device.DeviceType]));
                            if (deviceType != null)
                            {
                                device = deviceType.CreateDevice();
                                device.SetApplication(base.Application);
                                device.SetDataReader(dr);

                                base.Application.SetDeviceInstance(device);

                                if (this.Found != null)
                                {
                                    if (keepSource)
                                    {
                                        if (isReverse)
                                        {
                                            devices.Insert(0, device);
                                        }
                                        else
                                        {
                                            devices.Add(device);
                                        }
                                    }
                                    this.Found(device);
                                }
                                else
                                {
                                    if (isReverse)
                                    {
                                        devices.Insert(0, device);
                                    }
                                    else
                                    {
                                        devices.Add(device);
                                    }
                                }

                                device.DateRange = this.m_DateRange;
                            }
                            else
                            {
                                throw new Exception("未发现类型为 " + Function.ToString(dr[Tables.Device.DeviceType]) + " 的设备。");
                            }
                        }
                    }
                    dr.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                base.DbConnection.Close();
            }

            return(devices);
        }