Example #1
0
        public List <Record> select(string searchSql)
        {
            String sql = " select BaseKey,TaskConfigId,XmlConfig from Record where 1>0 ";

            sql += searchSql;
            return(RecordRowMapper(dbConnection.ExecuteReader(sql)));
        }
Example #2
0
        public List <Factory> select(string searchSql)
        {
            String sql = " select BaseKey,FactoryName from Factory where 1>0 ";

            sql += searchSql;
            return(FactoryRowMapper(dbConnection.ExecuteReader(sql)));
        }
Example #3
0
        public List <ExamItem> select(string searchSql)
        {
            String sql = " select BaseKey,Item,FunCode,ParentId from ExamItem where 1>0 ";

            sql += searchSql;
            return(ExamItemRowMapper(dbConnection.ExecuteReader(sql)));
        }
Example #4
0
        public List <Devices> select(string searchSql)
        {
            String sql = " select BaseKey,TaskConfigId,Suite,Factory,Address,DeviceType from Devices where 1>0 ";

            sql += searchSql;
            return(DevicesRowMapper(dbConnection.ExecuteReader(sql)));
        }
Example #5
0
        private int getMaxKeyValue()
        {
            String      sql         = "select max(baseKey) from examType ";
            IDataReader dr          = dbConnection.ExecuteReader(sql);
            int         maxKeyValue = dr[0].ToString() == "" ? 1 : Convert.ToInt32(dr[0]) + 1;

            dr.Close();
            return(maxKeyValue);
        }
Example #6
0
        public List <DevicesType> select(string searchSql)
        {
            String sql = " select BaseKey,DeviceTypeName from DeviceType where 1>0 ";

            sql += searchSql;
            return(DeviceTypeRowMapper(dbConnection.ExecuteReader(sql)));
        }
Example #7
0
        private void Load()
        {
            AC.Base.Database.DbConnection dbConn = this.m_Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strSql = "SELECT * FROM " + Tables.TaskGroup.TableName;
                    System.Data.IDataReader dr = dbConn.ExecuteReader(strSql);
                    while (dr.Read())
                    {
                        TaskGroup _TaskGroup = new TaskGroup(this.m_Application);
                        _TaskGroup.SetDataReader(dr);
                        this.Add(_TaskGroup);
                    }
                    dr.Close();

                    strSql = "SELECT * FROM " + Tables.TaskConfig.TableName;
                    dr     = dbConn.ExecuteReader(strSql);
                    while (dr.Read())
                    {
                        TaskGroup _TaskGroup = this.GetById(Function.ToInt(dr[Tables.TaskConfig.TaskGroupId]));
                        if (_TaskGroup != null)
                        {
                            TaskType _TaskType = this.m_Application.TaskTypes.GetTaskType(Function.ToString(dr[Tables.TaskConfig.TaskType]));
                            if (_TaskType != null)
                            {
                                TaskConfig _TaskConfig = _TaskType.CreateTaskConfig(_TaskGroup);
                                _TaskConfig.SetDataReader(dr);
                                _TaskGroup.TaskConfigs.Add(_TaskConfig);
                            }
                        }
                    }
                    dr.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
        /// <summary>
        /// 设备曲线数据读取器。
        /// </summary>
        /// <param name="device">设备集合中的第一次访问的设备对象。</param>
        /// <param name="startDate">访问数据的起始日期,如果未设置过 DateRange 日期范围则以该日期作为数据筛选的起始日期。</param>
        /// <param name="endDate">访问数据的结束日期,如果未设置过 DateRange 日期范围则以该日期作为数据筛选的结束日期。</param>
        /// <param name="startTimeNum">曲线数据段的起始时间。</param>
        /// <param name="endTimeNum">曲线数据段的结束时间。</param>
        /// <param name="curvePoint">是否将曲线数据强制转换为指定的点数。如果该值为 0 则表示不转换,设备曲线数据点数使用各设备的默认值。</param>
        /// <param name="mergeOption">当转换后的点数小于目前曲线点数时,如何合并目前的数据。</param>
        /// <param name="splitOption">当转换后的点数大于目前曲线点数时,如何拆分目前的数据。</param>
        /// <param name="tableNameF">96及以下点数数据表名。</param>
        /// <param name="selectColumnNameF">96及以下点数数据表需要额外输出的字段,如无额外字段可传 null。</param>
        /// <param name="tableNameS">96以上点数数据表名。</param>
        public DeviceCurvePartDataReader(Device device, DateTime startDate, DateTime endDate, int startTimeNum, int endTimeNum, int curvePoint, CurveMergeOptions mergeOption, CurveSplitOptions splitOption, string tableNameF, string selectColumnNameF, string tableNameS)
        {
            this.m_CurvePoint  = curvePoint;
            this.m_FirstDevice = device;
            this.StartTimeNum  = startTimeNum;
            this.EndTimeNum    = endTimeNum;

            if (device.DateRange != null && device.DateRange.ContainsDay(startDate, endDate))
            {
                this.m_DateRange = device.DateRange;
            }
            else
            {
                this.m_DateRange = new DateRange(startDate, endDate);
            }

            string strDeviceIdWhereF = "";
            string strDeviceIdWhereS = "";

            if (device.Source != null && device.Source.Contains(device))
            {
                foreach (Device device1 in device.Source)
                {
                    CurvePointOptions _CurvePoint = this.GetDeviceCurvePoint(device1);
                    if (_CurvePoint <= CurvePointOptions.Point96 || (curvePoint > 0 && curvePoint < (int)CurvePointOptions.Point96))
                    {
                        strDeviceIdWhereF += "," + device1.DeviceId;
                    }
                    else
                    {
                        strDeviceIdWhereS += "," + device1.DeviceId;
                    }

                    if (device1.DateRange == null || device1.DateRange.UniqueId != this.m_DateRange.UniqueId)
                    {
                        device1.DateRange = this.m_DateRange;
                    }

                    this.SetReader(device1);
                }

                if (strDeviceIdWhereF.Length > 0)
                {
                    strDeviceIdWhereF = " IN (" + strDeviceIdWhereF.Substring(1) + ")";
                }
                if (strDeviceIdWhereS.Length > 0)
                {
                    strDeviceIdWhereS = " IN (" + strDeviceIdWhereS.Substring(1) + ")";
                }
            }
            else
            {
                CurvePointOptions _CurvePoint = this.GetDeviceCurvePoint(device);
                if (_CurvePoint <= CurvePointOptions.Point96 || (curvePoint > 0 && curvePoint < (int)CurvePointOptions.Point96))
                {
                    strDeviceIdWhereF = "=" + device.DeviceId;
                }
                else
                {
                    strDeviceIdWhereS = "=" + device.DeviceId;
                }

                if (device.DateRange == null || device.DateRange.UniqueId != this.m_DateRange.UniqueId)
                {
                    device.DateRange = this.m_DateRange;
                }

                this.SetReader(device);
            }

            AC.Base.Database.DbConnection dbConn = device.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    int    intStartPointF = CurvePointOptions.Point96.GetPointIndex(startTimeNum) + 1;
                    int    intEndPointF   = CurvePointOptions.Point96.GetPointIndex(endTimeNum) + 1;
                    string strSelectF     = "DateNum,DeviceId" + (selectColumnNameF != null && selectColumnNameF.Length > 0 ? "," + selectColumnNameF : "");
                    for (int intPointIndex = intStartPointF; intPointIndex <= intEndPointF; intPointIndex++)
                    {
                        strSelectF += ",Value" + intPointIndex;
                    }

                    foreach (DateRange.MonthlyForDayRange range in this.DateRange.GetMonthRanges())
                    {
                        if (strDeviceIdWhereF.Length > 0)
                        {
                            string strTableName = Database.DbConnection.GetMonthlyName(tableNameF, range.Date.Year, range.Date.Month);
                            if (dbConn.TableIsExist(strTableName))
                            {
                                string strSqlDate = range.GetSqlWhere("DateNum");
                                if (strSqlDate.Length > 0)
                                {
                                    strSqlDate = " AND " + strSqlDate;
                                }

                                string strSql = "SELECT " + strSelectF + " FROM " + strTableName + " WHERE DeviceId" + strDeviceIdWhereF + strSqlDate;
                                System.Data.IDataReader dr = dbConn.ExecuteReader(strSql);
                                while (dr.Read())
                                {
                                    Device            deviceF            = this.GetDevice(Function.ToInt(dr["DeviceId"]));
                                    CurvePointOptions _DeviceCurvePointF = this.GetDeviceCurvePoint(deviceF);
                                    if (_DeviceCurvePointF > CurvePointOptions.Point96)
                                    {
                                        _DeviceCurvePointF = CurvePointOptions.Point96;     //如果设备默认的曲线数据点数大于96点,则使用96点数据。
                                    }

                                    decimal?[] decValues     = new decimal?[_DeviceCurvePointF.GetPointCount(startTimeNum, endTimeNum)];
                                    int        intPointIndex = 0;
                                    for (int intIndex = intStartPointF; intIndex <= intEndPointF; intIndex++)
                                    {
                                        if (((intIndex - 1) % (96 / _DeviceCurvePointF.GetPointCount())) == 0)
                                        {
                                            decValues[intPointIndex++] = Function.ToDecimalNull(dr["Value" + intIndex]);
                                        }
                                    }

                                    if (curvePoint != 0 && curvePoint != (int)_DeviceCurvePointF)
                                    {
                                        //需要对曲线数据进行转换
                                        decValues          = CurvePartValue.ConvertTo(_DeviceCurvePointF, this.StartTimeNum, decValues, (CurvePointOptions)curvePoint, mergeOption, splitOption);
                                        _DeviceCurvePointF = (CurvePointOptions)curvePoint;
                                    }

                                    this.DoDataReaderF(deviceF, dr, _DeviceCurvePointF, decValues);
                                }
                                dr.Close();
                            }
                        }

                        if (strDeviceIdWhereS.Length > 0)
                        {
                            string strTableName = Database.DbConnection.GetMonthlyName(tableNameS, range.Date.Year, range.Date.Month);
                            if (dbConn.TableIsExist(strTableName))
                            {
                                string strSqlDate = range.GetSqlWhere("DateNum");
                                if (strSqlDate.Length > 0)
                                {
                                    strSqlDate = " AND " + strSqlDate;
                                }
                                strSqlDate += " AND TimeNum>=" + startTimeNum + " AND TimeNum<=" + endTimeNum;
                                string strSql = "SELECT * FROM " + strTableName + " WHERE DeviceId" + strDeviceIdWhereS + strSqlDate;
                                System.Data.IDataReader dr = dbConn.ExecuteReader(strSql);
                                while (dr.Read())
                                {
                                    this.DoDataReaderS(this.GetDevice(Function.ToInt(dr["DeviceId"])), dr);
                                }
                                dr.Close();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }

                if (curvePoint > 0 && strDeviceIdWhereS.Length > 0)
                {
                    //通知继承的曲线读取器转换分秒数据点数。
                    this.DoConvertS();
                }
            }
        }
Example #9
0
        /// <summary>
        /// 读取每年创建一张数据表的设备数据。
        /// </summary>
        /// <param name="device">设备集合中的第一次访问的设备对象。</param>
        /// <param name="startDate">访问数据的起始日期,如果未设置过 DateRange 日期范围则以该日期作为数据筛选的起始日期。</param>
        /// <param name="endDate">访问数据的结束日期,如果未设置过 DateRange 日期范围则以该日期作为数据筛选的结束日期。</param>
        /// <param name="tableName">数据所在的数据表名。</param>
        /// <param name="deviceIdColumnName">设备编号字段名。</param>
        /// <param name="dateNumColumnName">数据日期字段名,该字段储存的日期应该是 YYYYMMDD 格式的8位整型数字。</param>
        public DeviceMonthDataReader(Device device, DateTime startDate, DateTime endDate, string tableName, string deviceIdColumnName, string dateNumColumnName)
        {
            this.m_FirstDevice = device;

            if (device.DateRange != null && device.DateRange.ContainsMonth(startDate, endDate))
            {
                this.m_DateRange = device.DateRange;
            }
            else
            {
                this.m_DateRange = new DateRange(startDate, endDate);
            }

            string strDeviceIdWhere = "";

            if (device.Source != null && device.Source.Contains(device))
            {
                strDeviceIdWhere = " IN (" + device.Source.GetIdForString() + ")";

                foreach (Device device1 in device.Source)
                {
                    if (device1.DateRange == null || device1.DateRange.UniqueId != this.m_DateRange.UniqueId)
                    {
                        device1.DateRange = this.m_DateRange;
                    }

                    this.SetReader(device1);
                }
            }
            else
            {
                strDeviceIdWhere = "=" + device.DeviceId;

                if (device.DateRange == null || device.DateRange.UniqueId != this.m_DateRange.UniqueId)
                {
                    device.DateRange = this.m_DateRange;
                }

                this.SetReader(device);
            }

            AC.Base.Database.DbConnection dbConn = device.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    foreach (DateRange.YearlyForMonthRange range in this.DateRange.GetYearRanges())
                    {
                        string strTableName = Database.DbConnection.GetYearlyName(tableName, range.Date.Year);
                        if (dbConn.TableIsExist(strTableName))
                        {
                            string strSqlDate = range.GetSqlWhere(dateNumColumnName);
                            if (strSqlDate.Length > 0)
                            {
                                strSqlDate = " AND " + strSqlDate;
                            }
                            string strSql = "SELECT * FROM " + strTableName + " WHERE " + deviceIdColumnName + strDeviceIdWhere + strSqlDate;
                            System.Data.IDataReader dr = dbConn.ExecuteReader(strSql);
                            while (dr.Read())
                            {
                                this.DoDataReader(this.GetDevice(Function.ToInt(dr[deviceIdColumnName])), dr);
                            }
                            dr.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }