Beispiel #1
0
        public bool InsertToHistoryDataTable(List <OPCItemData> itemDataList, out string errMsg)
        {
            errMsg = string.Empty;

            #region 检查数据连接设置
            if (ServerName.Trim() == string.Empty ||
                UserName.Trim() == string.Empty ||
                Password.Trim() == string.Empty ||
                NewDataTableName.Trim() == string.Empty)
            {
                errMsg = "数据库连接设置无效";
                OPCLog.Error("数据库连接设置无效");
                return(false);
            }
            if (this.m_dal == null)
            {
                switch (DatabaseType)
                {
                case OPCUtils.DatabaseType.MSSQLServer:
                    this.m_dal = new OPCClientMSSQLDAL(ServerName, DatabaseName, UserName, Password);
                    break;

                case OPCUtils.DatabaseType.Oracle:
                    this.m_dal = new OPCClientOracleDAL(ServerName, UserName, Password);
                    break;

                default:
                    break;
                }
                if (!this.m_dal.CreateConnection(out errMsg))
                {
                    return(false);
                }
            }
            #endregion
            //OPCUtils.LogDataChangeTime("数据刷新-插入历史数据-插入数据表-获取数据实体");
            List <OPCClientItemEntity> itemEntities = GetEntities(itemDataList);

            //OPCUtils.LogDataChangeTime("数据刷新-插入历史数据-插入数据表-开始插入");
            foreach (OPCClientItemEntity itemEntity in itemEntities)
            {
                //OPCUtils.LogDataChangeTime("数据刷新-插入历史数据-插入数据表-插入实体");
                string dalErr = string.Empty;
                if (!this.m_dal.InsertItem(HistoryDataTableName, itemEntity, out dalErr))
                {
                    errMsg = dalErr;
                }
            }
            //OPCUtils.LogDataChangeTime("数据刷新-插入历史数据-插入数据表-结束插入");
            return(true);
        }
Beispiel #2
0
 public void RefreshDBConnectionSetting()
 {
     this.m_dal = null;
 }
Beispiel #3
0
        public bool UpdateNewDataTable(List <OPCItemData> itemDataList, out string errMsg)
        {
            //MessageBox.Show("NewDataTable ItemDataList: " + itemDataList.Count.ToString());
            errMsg = string.Empty;

            #region 检查数据连接设置
            if (ServerName.Trim() == string.Empty ||
                UserName.Trim() == string.Empty ||
                Password.Trim() == string.Empty ||
                NewDataTableName.Trim() == string.Empty)
            {
                errMsg = "数据库连接设置无效";
                OPCLog.Error("数据库连接设置无效");
                return(false);
            }
            if (this.m_dal == null)
            {
                switch (DatabaseType)
                {
                case OPCUtils.DatabaseType.MSSQLServer:
                    this.m_dal = new OPCClientMSSQLDAL(ServerName, DatabaseName, UserName, Password);
                    break;

                case OPCUtils.DatabaseType.Oracle:
                    this.m_dal = new OPCClientOracleDAL(ServerName, UserName, Password);
                    break;

                default:
                    break;
                }
                if (!this.m_dal.CreateConnection(out errMsg))
                {
                    return(false);
                }
            }
            #endregion

            #region 清空原有实时数据

            /*
             * if (!this.m_dal.ClearItems(NewDataTableName, out errMsg))
             * {
             *  return false;
             * }
             */
            #endregion

            List <OPCClientItemEntity> itemEntities = GetEntities(itemDataList);

            foreach (OPCClientItemEntity itemEntity in itemEntities)
            {
                string dalErr = string.Empty;
                string status = this.m_dal.QueryItemDataStatus(NewDataTableName, itemEntity, out dalErr);
                if (status != string.Empty)
                {
                    SyncSensorStatus(itemEntity, status);
                }
                if (!this.m_dal.DeleteItem(NewDataTableName, itemEntity, out dalErr) ||
                    !this.m_dal.InsertItem(NewDataTableName, itemEntity, out dalErr))
                {
                    errMsg = dalErr;
                }
            }

            return(true);
        }