Example #1
0
        /// <summary>
        /// 删除当前任务组。
        /// </summary>
        public void Delete()
        {
            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    //还需添加删除任务日志的代码

                    string strSql;
                    strSql = "Delete From " + Tables.TaskConfig.TableName + " Where " + Tables.TaskConfig.TaskGroupId + "=" + this.TaskGroupId;
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "Delete From " + Tables.TaskGroup.TableName + " Where " + Tables.TaskGroup.TaskGroupId + "=" + this.TaskGroupId;
                    dbConn.ExecuteNonQuery(strSql);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// 删除分类。
        /// </summary>
        public virtual void Delete()
        {
            foreach (Classify children in this.Children)
            {
                children.Delete();
            }

            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strSql;

                    strSql = "Delete From " + Tables.ClassifyDeviceAll.TableName + " Where " + Tables.ClassifyDeviceAll.ClassifyId + "=" + this.ClassifyId;
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "Delete From " + Tables.ClassifyDevice.TableName + " Where " + Tables.ClassifyDevice.ClassifyId + "=" + this.ClassifyId;
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "Delete From " + Tables.Classify.TableName + " Where " + Tables.Classify.ClassifyId + "=" + this.ClassifyId;
                    dbConn.ExecuteNonQuery(strSql);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #3
0
 internal void SaveSqlToDb()
 {
     if (SaveSQL != null)
     {
         AC.Base.Database.DbConnection dbConn = this.Device.Application.GetDbConnection();
         if (dbConn != null)
         {
             try
             {
                 foreach (string strSql in this.SaveSQL)
                 {
                     dbConn.ExecuteNonQuery(strSql);
                 }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             finally
             {
                 dbConn.Close();
             }
         }
     }
 }
Example #4
0
        /// <summary>
        /// 保存日志附加的字符串值。
        /// </summary>
        /// <param name="code">属性类型,通常使用搜索筛选器的类名。</param>
        /// <param name="ordinalNumber">序号,用于存储同一属性的多个值。</param>
        /// <param name="dataValue">数据值,长度在 250 个字符之内。</param>
        protected void Save(string code, int ordinalNumber, string dataValue)
        {
            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                string strTableName = Tables.LogString.GetTableName(this.LogTime);
                if (dbConn.TableIsExist(strTableName) == false)
                {
                    dbConn.CreateTable(typeof(Tables.LogString), strTableName);
                }

                try
                {
                    string strSql = this.LogId + "," + Function.SqlStr(code, 250) + "," + ordinalNumber + "," + Function.SqlStr(dataValue, 250);
                    strSql = "INSERT INTO " + strTableName + " (" + Tables.LogString.LogId + "," + Tables.LogString.Code + "," + Tables.LogString.OrdinalNumber + "," + Tables.LogString.DataValue + ") VALUES (" + strSql + ")";
                    dbConn.ExecuteNonQuery(strSql);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #5
0
        /// <summary>
        /// 删除当前任务。
        /// </summary>
        public void Delete()
        {
            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    //删除任务
                    string strSql;
                    strSql = "Delete From " + Tables.TaskConfig.TableName + " Where " + Tables.TaskConfig.TaskConfigId + "=" + this.TaskConfigId;
                    dbConn.ExecuteNonQuery(strSql);

                    //删除任务日志(当年)
                    strSql = "Delete From " + Tables.TaskLog.GetTableName(DateTime.Today) + " Where " + Tables.TaskLog.TaskConfigId + "=" + this.TaskConfigId;
                    dbConn.ExecuteNonQuery(strSql);

                    //删除任务运行日志
                    //strSql = "Delete From " + Tables.TaskRunLog.GetTableName(DateTime.Today) + " Where " + Tables.TaskRunLog.TaskConfigId + "=" + this.TaskConfigId;
                    //dbConn.ExecuteNonQuery(strSql);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #6
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();
                }
            }
        }
Example #7
0
 /// <summary>
 /// 保存长文本数值
 /// </summary>
 /// <param name="serialNumber">序号</param>
 /// <param name="dataValue">长文本数值</param>
 protected void SaveText(int serialNumber, string dataValue)
 {
     AC.Base.Database.DbConnection dbConn = this.Device.Application.GetDbConnection();
     if (dbConn != null)
     {
         try
         {
             string strSql = this.Device.DeviceId + "," + Function.SqlStr(this.GetType().FullName) + "," + serialNumber + "," + Function.SqlStr(dataValue);
             strSql = "INSERT INTO " + Tables.DevicePropertyText.TableName + " (" + Tables.DevicePropertyText.DeviceId + "," + Tables.DevicePropertyText.PropertyType + "," + Tables.DevicePropertyText.SerialNumber + "," + Tables.DevicePropertyText.DataValue + ") VALUES (" + strSql + ")";
             dbConn.ExecuteNonQuery(strSql);
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             dbConn.Close();
         }
     }
 }
Example #8
0
        /// <summary>
        /// 删除该属性数据。
        /// </summary>
        internal void Delete()
        {
            AC.Base.Database.DbConnection dbConn = this.Device.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strSql;

                    strSql = "DELETE FROM " + Tables.DevicePropertyInt.TableName + " WHERE " + Tables.DevicePropertyInt.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyInt.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "DELETE FROM " + Tables.DevicePropertyLong.TableName + " WHERE " + Tables.DevicePropertyLong.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyLong.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "DELETE FROM " + Tables.DevicePropertyDecimal.TableName + " WHERE " + Tables.DevicePropertyDecimal.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyDecimal.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "DELETE FROM " + Tables.DevicePropertyString.TableName + " WHERE " + Tables.DevicePropertyString.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyString.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "DELETE FROM " + Tables.DevicePropertyText.TableName + " WHERE " + Tables.DevicePropertyText.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyText.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);

                    strSql = "DELETE FROM " + Tables.DevicePropertyBytes.TableName + " WHERE " + Tables.DevicePropertyBytes.DeviceId + "=" + this.Device.DeviceId + " AND " + Tables.DevicePropertyBytes.PropertyType + "=" + Function.SqlStr(this.GetType().FullName);
                    dbConn.ExecuteNonQuery(strSql);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #9
0
        /// <summary>
        /// 保存二进制数值
        /// </summary>
        /// <param name="serialNumber">序号</param>
        /// <param name="dataValue">二进制数值</param>
        protected void SaveBytes(int serialNumber, byte[] dataValue)
        {
            AC.Base.Database.DbConnection dbConn = this.Device.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    System.Data.IDbDataParameter parDeviceId = (System.Data.IDbDataParameter)dbConn.GetNewDbDataParameter();
                    parDeviceId.ParameterName = "@" + Tables.DevicePropertyBytes.DeviceId;
                    parDeviceId.Value         = this.Device.DeviceId;

                    System.Data.IDbDataParameter parPropertyType = (System.Data.IDbDataParameter)dbConn.GetNewDbDataParameter();
                    parPropertyType.ParameterName = "@" + Tables.DevicePropertyBytes.PropertyType;
                    parPropertyType.Value         = Function.SqlStr(this.GetType().FullName);

                    System.Data.IDbDataParameter parSerialNumber = (System.Data.IDbDataParameter)dbConn.GetNewDbDataParameter();
                    parSerialNumber.ParameterName = "@" + Tables.DevicePropertyBytes.SerialNumber;
                    parSerialNumber.Value         = serialNumber;

                    System.Data.IDbDataParameter parDataValue = (System.Data.IDbDataParameter)dbConn.GetNewDbDataParameter();
                    parDataValue.ParameterName = "@" + Tables.DevicePropertyBytes.DataValue;
                    parDataValue.Value         = dataValue;

                    string strSql = "@" + Tables.DevicePropertyBytes.DeviceId + "," + "@" + Tables.DevicePropertyBytes.PropertyType + "," + "@" + Tables.DevicePropertyBytes.SerialNumber + "," + "@" + Tables.DevicePropertyBytes.DataValue;
                    strSql = "INSERT INTO " + Tables.DevicePropertyBytes.TableName + " (" + Tables.DevicePropertyBytes.DeviceId + "," + Tables.DevicePropertyBytes.PropertyType + "," + Tables.DevicePropertyBytes.SerialNumber + "," + Tables.DevicePropertyBytes.DataValue + ") VALUES (" + strSql + ")";
                    dbConn.ExecuteNonQuery(strSql, -1, System.Data.CommandType.Text, parDeviceId, parPropertyType, parSerialNumber, parDataValue);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #10
0
        /// <summary>
        /// 保存任务组。
        /// </summary>
        public void Save()
        {
            if (this.Name == null || this.Name.Length == 0)
            {
                throw new Exception("任务组名称必须输入。");
            }

            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    if (this.TaskGroupId == 0)
                    {
                        string strSql = "SELECT MAX(" + Tables.TaskGroup.TaskGroupId + ") FROM " + Tables.TaskGroup.TableName;
                        this.TaskGroupId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        strSql = this.TaskGroupId + "," + Function.SqlStr(this.Name, 250);
                        strSql = "INSERT INTO " + Tables.TaskGroup.TableName + " (" + Tables.TaskGroup.TaskGroupId + "," + Tables.TaskGroup.Name + ") VALUES (" + strSql + ")";
                        dbConn.ExecuteNonQuery(strSql);
                    }
                    else
                    {
                        string strSql = "UPDATE " + Tables.TaskGroup.TableName + " Set " + Tables.TaskGroup.Name + "=" + Function.SqlStr(this.Name, 250) + " Where " + Tables.TaskGroup.TaskGroupId + "=" + this.TaskGroupId;
                        dbConn.ExecuteNonQuery(strSql);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #11
0
 public DevicesTypeDao(ApplicationClass application)
 {
     dbConnection = application.GetDbConnection();
 }
Example #12
0
 public RecordDao(ApplicationClass application)
 {
     dbConnection = application.GetDbConnection();
 }
Example #13
0
        /// <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 #14
0
        /// <summary>
        /// 保存当前任务信息。
        /// </summary>
        public void Save()
        {
            if (this.Name == null || this.Name.Length == 0)
            {
                throw new Exception("任务名称必须输入。");
            }
            else if (this.Group == null)
            {
                throw new Exception("必须设置任务所属的任务组。");
            }
            else if (this.Period == null)
            {
                throw new Exception("必须配置任务的运行周期。");
            }

            AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strConfig = null;
                    System.Xml.XmlDocument xmlDoc   = new System.Xml.XmlDocument();
                    System.Xml.XmlNode     xnConfig = xmlDoc.CreateElement(this.GetType().Name);
                    xmlDoc.AppendChild(xnConfig);

                    System.Xml.XmlNode xnPeriodType = xmlDoc.CreateElement("PeriodType");
                    xnPeriodType.InnerText = this.Period.GetType().FullName;
                    xnConfig.AppendChild(xnPeriodType);

                    System.Xml.XmlNode xnPeriodConfig = this.Period.GetTaskPeriodConfig(xmlDoc);
                    if (xnPeriodConfig != null)
                    {
                        System.Xml.XmlNode xnPeriod = xmlDoc.CreateElement("Period");
                        xnPeriod.AppendChild(xnPeriodConfig);
                        xnConfig.AppendChild(xnPeriod);
                    }

                    System.Xml.XmlNode xnMaxRunTime = xmlDoc.CreateElement("MaxRunTime");
                    xnMaxRunTime.InnerText = this.MaxRunTime.ToString();
                    xnConfig.AppendChild(xnMaxRunTime);

                    System.Xml.XmlNode xnRetryProgress = xmlDoc.CreateElement("RetryProgress");
                    xnRetryProgress.InnerText = this.RetryProgress.ToString();
                    xnConfig.AppendChild(xnRetryProgress);

                    System.Xml.XmlNode xnIsUnqualifiedRetry = xmlDoc.CreateElement("IsUnqualifiedRetry");
                    xnIsUnqualifiedRetry.InnerText = this.IsUnqualifiedRetry.ToString();
                    xnConfig.AppendChild(xnIsUnqualifiedRetry);

                    System.Xml.XmlNode xnRetryInterval = xmlDoc.CreateElement("RetryInterval");
                    for (int i = 0; i < this.RetryInterval.Length; i++)
                    {
                        System.Xml.XmlNode xnRetryIntervalChild = xmlDoc.CreateElement(string.Format("Interval{0}", i + 1));
                        xnRetryIntervalChild.InnerText = this.RetryInterval[i].ToString();
                        xnRetryInterval.AppendChild(xnRetryIntervalChild);
                    }
                    xnConfig.AppendChild(xnRetryInterval);

                    System.Xml.XmlNode xnTaskConfig = this.GetTaskConfig(xmlDoc);
                    if (xnTaskConfig != null)
                    {
                        System.Xml.XmlNode xn = xmlDoc.CreateElement("TaskConfig");
                        xn.AppendChild(xnTaskConfig);
                        xnConfig.AppendChild(xn);
                    }

                    strConfig = xmlDoc.OuterXml;

                    if (this.TaskConfigId == 0)
                    {
                        string strSql = "SELECT MAX(" + Tables.TaskConfig.TaskConfigId + ") FROM " + Tables.TaskConfig.TableName;
                        this.TaskConfigId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        strSql = this.TaskConfigId + "," + Function.SqlStr(this.TaskType.Code, 250) + "," + Function.SqlStr(this.Name, 250) + "," + this.Group.TaskGroupId + "," + Function.BoolToByte(this.Enable) + "," + Function.SqlStr(strConfig);
                        strSql = "INSERT INTO " + Tables.TaskConfig.TableName + " (" + Tables.TaskConfig.TaskConfigId + "," + Tables.TaskConfig.TaskType + "," + Tables.TaskConfig.Name + "," + Tables.TaskConfig.TaskGroupId + "," + Tables.TaskConfig.EnableAuto + "," + Tables.TaskConfig.XMLConfig + ") VALUES (" + strSql + ")";
                        dbConn.ExecuteNonQuery(strSql);

                        this.Group.TaskConfigs.Add(this);
                    }
                    else
                    {
                        string strSql = "UPDATE " + Tables.TaskConfig.TableName + " Set " + Tables.TaskConfig.Name + "=" + Function.SqlStr(this.Name, 250) + "," + Tables.TaskConfig.EnableAuto + "=" + Function.BoolToByte(this.Enable) + "," + Tables.Device.XMLConfig + "=" + Function.SqlStr(strConfig) + " Where " + Tables.TaskConfig.TaskConfigId + "=" + this.TaskConfigId;
                        dbConn.ExecuteNonQuery(strSql);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }
Example #15
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();
                }
            }
        }
Example #16
0
        /// <summary>
        /// 保存分类。
        /// </summary>
        public virtual void Save()
        {
            if (this.Name == null || this.Name.Trim().Length == 0)
            {
                throw new Exception("未设置分类名称。");
            }
            else
            {
                //配置信息
                System.Xml.XmlDocument xmlDoc   = new System.Xml.XmlDocument();
                System.Xml.XmlNode     xnConfig = xmlDoc.CreateElement(this.GetType().Name);
                xmlDoc.AppendChild(xnConfig);

                System.Xml.XmlNode xnEnabledDevice = xmlDoc.CreateElement("EnabledDevice");
                xnEnabledDevice.InnerText = Function.BoolToByte(this.EnabledDevice).ToString();
                xnConfig.AppendChild(xnEnabledDevice);

                if (this.DeviceFilters != null && this.DeviceFilters.Count > 0)
                {
                    System.Xml.XmlNode xnDeviceFilters = xmlDoc.CreateElement("DeviceFilters");
                    xnDeviceFilters.AppendChild(this.DeviceFilters.GetFilterConfig(xmlDoc));
                    xnConfig.AppendChild(xnDeviceFilters);
                }

                System.Xml.XmlNode xnClassifyConfig = this.GetClassifyConfig(xmlDoc);
                if (xnClassifyConfig != null)
                {
                    xnConfig.AppendChild(xnClassifyConfig);
                }

                string strConfig = xmlDoc.OuterXml;

                //插入或更新
                string strSql;
                if (this.ClassifyId == 0)
                {
                    AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
                    if (dbConn != null)
                    {
                        strSql          = "SELECT MAX(" + Tables.Classify.ClassifyId + ") FROM " + Tables.Classify.TableName;
                        this.ClassifyId = Function.ToInt(dbConn.ExecuteScalar(strSql)) + 1;

                        try
                        {
                            if (this.OrdinalNumber == 0)
                            {
                                this.OrdinalNumber = this.ClassifyId;
                            }

                            strSql = this.ClassifyId + "," + Function.SqlStr(this.ClassifyType.Code, 250) + "," + (this.Parent == null ? 0 : this.Parent.ClassifyId) + "," + Function.SqlStr(this.Name, 250) + "," + Function.SqlStr(this.NameShortcut, 250) + "," + Function.SqlStr(this.Identifier, 250) + "," + this.OrdinalNumber + "," + Function.SqlStr(strConfig);
                            strSql = "INSERT INTO " + Tables.Classify.TableName + " (" + Tables.Classify.ClassifyId + "," + Tables.Classify.ClassifyType + "," + Tables.Classify.ParentId + "," + Tables.Classify.Name + "," + Tables.Classify.NameShortcut + "," + Tables.Classify.Identifier + "," + Tables.Classify.OrdinalNumber + "," + Tables.Classify.XMLConfig + ") VALUES (" + strSql + ")";
                            dbConn.ExecuteNonQuery(strSql);

                            if (this.Parent != null)
                            {
                                this.Parent.Children.Add(this);
                            }
                        }
                        finally
                        {
                            dbConn.Close();
                        }
                    }
                }
                else
                {
                    AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection();
                    if (dbConn != null)
                    {
                        try
                        {
                            strSql = "UPDATE " + Tables.Classify.TableName + " Set " + Tables.Classify.Name + "=" + Function.SqlStr(this.Name, 250) + "," + Tables.Device.NameShortcut + "=" + Function.SqlStr(this.NameShortcut, 250) + "," + Tables.Classify.Identifier + "=" + Function.SqlStr(this.Identifier, 250) + "," + Tables.Classify.OrdinalNumber + "=" + this.OrdinalNumber + "," + Tables.Classify.XMLConfig + "=" + Function.SqlStr(strConfig) + " Where " + Tables.Classify.ClassifyId + "=" + this.ClassifyId;
                            dbConn.ExecuteNonQuery(strSql);
                        }
                        finally
                        {
                            dbConn.Close();
                        }
                    }
                }
            }
        }
Example #17
0
File: Task.cs Project: jujianfei/AC
        //任务运行完成后必须调用该方法
        private void Save()
        {
            this.StopTime = DateTime.Now;
            AC.Base.Database.DbConnection dbConn = this.Config.Application.GetDbConnection();
            if (dbConn != null)
            {
                try
                {
                    string strTableName = Tables.TaskRunLog.GetTableName(this.Log.LogTime);
                    if (dbConn.TableIsExist(strTableName) == false)
                    {
                        dbConn.CreateTable(typeof(Tables.TaskRunLog), strTableName);
                    }
                    string strConfig = null;
                    System.Xml.XmlDocument xmlDoc   = new System.Xml.XmlDocument();
                    System.Xml.XmlNode     xnConfig = this.GetTaskRunConfig(xmlDoc);
                    if (xnConfig != null)
                    {
                        xmlDoc.AppendChild(xnConfig);
                        strConfig = xmlDoc.OuterXml;
                    }
                    this.TimeStr = this.Log.LogId.ToString() + "_" + this.RetryTimes;

                    string strSql = Function.SqlStr(this.Log.LogId.ToString()) + "," +
                                    this.RetryTimes + "," +
                                    this.StartTime.Ticks + "," +
                                    this.StopTime.Ticks + "," +
                                    (this.StopTime - this.StartTime).TotalMilliseconds + "," +
                                    ((int)this.State) + "," +
                                    this.Progress + "," +
                                    Function.SqlStr(this.taskName) + "," +
                                    Function.SqlStr(this.TimeStr) + "," +
                                    Function.SqlStr(strConfig);

                    strSql = "INSERT INTO " + strTableName + " (" + Tables.TaskRunLog.TaskLogId + "," + Tables.TaskRunLog.RetryTimes + "," + Tables.TaskRunLog.StartTime + "," + Tables.TaskRunLog.StopTime + "," + Tables.TaskRunLog.TimeSpan + "," + Tables.TaskRunLog.TaskState + "," + Tables.TaskRunLog.TaskProgress + "," + Tables.TaskRunLog.DeviceName + "," + Tables.TaskRunLog.TimeStr + "," + Tables.TaskRunLog.XMLConfig + ") VALUES (" + strSql + ")";
                    dbConn.ExecuteNonQuery(strSql);

                    strTableName = Tables.TaskLog.GetTableName(this.Log.LogTime);
                    strSql       = "UPDATE " + strTableName + " Set " + Tables.TaskLog.RetryTimes + "=" + this.RetryTimes + "," + Tables.TaskLog.LastProgress + "=" + this.Progress + " Where " + Tables.TaskLog.TaskLogId + "=" + Function.SqlStr(this.Log.LogId.ToString());
                    dbConn.ExecuteNonQuery(strSql);

                    if (this.ExceptionInfos.Count > 0)
                    {
                        strTableName = Tables.TaskExceptionLog.GetTableName(this.Log.LogTime);
                        if (dbConn.TableIsExist(strTableName) == false)
                        {
                            dbConn.CreateTable(typeof(Tables.TaskExceptionLog), strTableName);
                        }

                        for (int intIndex = 0; intIndex < this.ExceptionInfos.Count; intIndex++)
                        {
                            strSql = this.Log.LogId + "," + this.RetryTimes + "," + (intIndex + 1) + "," + this.ExceptionInfos[intIndex].ExceptionTime.Ticks + "," + Function.SqlStr(this.ExceptionInfos[intIndex].ExceptionInfo);
                            strSql = "INSERT INTO " + strTableName + " (" + Tables.TaskExceptionLog.TaskLogId + "," + Tables.TaskExceptionLog.RetryTimes + "," + Tables.TaskExceptionLog.ExceptionId + "," + Tables.TaskExceptionLog.ExceptionTime + "," + Tables.TaskExceptionLog.XMLConfig + ") VALUES (" + strSql + ")";
                            dbConn.ExecuteNonQuery(strSql);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.OnException(ex);
                }
                finally
                {
                    dbConn.Close();
                }
            }

            this.Log.Tasks.Add(this);

            if (this.Stopped != null)
            {
                try
                {
                    this.Stopped(this);
                }
                catch (Exception ex)
                {
                    this.OnException(ex.Message);
                }
            }
        }
Example #18
0
 public FactoryDao(ApplicationClass application)
 {
     dbConnection = application.GetDbConnection();
 }
Example #19
0
 public ExamItemDao(ApplicationClass application)
 {
     dbConnection = application.GetDbConnection();
 }