Exemple #1
0
        public static string ExcuteSqlTranction(object objList, string tablename)
        {
            //这里有两种方法,一种,将大批量插入写入D层,解耦,同时使用实例化的DB连接串,不向外暴露,但是,一旦DAO层被重新生成,则更改起来较为麻烦
            //另一种,使用连接字符串,并进行加密,加密秘钥暂定"connKey",此方法方便写入APP.config,更换数据库方便

            //string conn = this.connectionString;
            DataTable dt = new DataTable();

            try
            {
                IList temp = (IList)objList;
                //将泛型转化成DataTable
                dt = ToDataTableTow(temp);

                //使用秘钥进行加密,秘钥可以分发给专门的人进行记录,在更改数据时留出输入秘钥的接口
                string conn = DESEncrypt.Encrypt(connectionString, "connKey");
                //输入秘钥进行解密
                string finalConn = DESEncrypt.Decrypt(conn, "connKey");

                UtilDAO.InsertEntities(finalConn, tablename, dt);
                return("OK");
            }
            catch (Exception ex)
            {
                return("NG,批量插入失败:" + ex);
                //throw ex;
            }
        }
        public void Remove(PM_ALT_BASE entity, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                //
                if (entity == null)
                {
                    returnMessage = "Input parameter [ALERT entity] can not be null.";
                    return;
                }
                if (!entity.AlertID.HasValue)
                {
                    returnMessage = "[ALERT ID] can not be null.";
                    return;
                }
                //
                entity.RowDeleted = true;
                entity.ModifiedOn = datetime;

                this.UpdateSome(entity);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
 public void Remove(PM_ALT_EVENT_TYPE entity, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [PM_ALT_EVENT_TYPE entity] can not be null.";
             return;
         }
         if (!entity.EventTypeID.HasValue)
         {
             returnMessage = "[EventTypeID] can not be null.";
             return;
         }
         //
         this.Delete(entity);
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }
Exemple #4
0
        //
        public void SaveBatch(IList <PM_ALT_LOG> logs, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);

            //
            try
            {
                if (logs == null)
                {
                    returnMessage = "Parameter [IList<ALERT_LOG> logs] can not be null.";
                    return;
                }

                #region check security
                //deleted by hans on 2018-6-12
                //SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                //if (identity == null)
                //{
                //    returnMessage = "[Authentication.Identity] is required.";
                //    return;
                //}
                #endregion

                foreach (PM_ALT_LOG log in logs)
                {
                    if (!log.LogPK.HasValue)
                    {
                        log.RowDeleted = false;
                        log.CreatedBy  = "system"; //identity.Name;
                        log.CreatedOn  = datetime;
                        this.Insert(log);
                    }
                    else
                    {
                        //scale.NotifiedCnt += 1;
                        if (string.IsNullOrEmpty(log.NotifiedBy))
                        {
                            log.NotifiedBy = "system"; // identity.Name;
                            log.NotifiedOn = datetime;
                        }
                        //
                        this.UpdateSome(log);
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        //
        public void SaveBatch(IList <PM_ALT_SCALE> scales, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);

            //
            #region check security
            //SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
            //if (identity == null)
            //{
            //    returnMessage = "[Authentication.Identity] is required.";
            //    return;
            //}
            #endregion
            //
            try
            {
                if (scales == null)
                {
                    returnMessage = "Parameter [IList<ALERT_SCALE> scales] can not be null.";
                    return;
                }
                //
                foreach (PM_ALT_SCALE scale in scales)
                {
                    if (!scale.ScalePK.HasValue)
                    {
                        scale.RowDeleted = false;
                        //scale.CreatedBy = identity.Name;
                        scale.CreatedOn = datetime;
                        this.Insert(scale);
                    }
                    else
                    {
                        // scale.ModifiedBy = identity.Name;
                        scale.ModifiedOn = datetime;
                        this.UpdateSome(scale);
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        //


        /// <summary>
        /// 保存预警消息
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="returnMessage"></param>
        public void SaveBatch(IList <PM_ALT_MESSAGE> entities, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);

            //
            try
            {
                if (entities == null)
                {
                    returnMessage = "Parameter [IList<EMAIL> entities] can not be null.";
                    return;
                }
                //
                //SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                //if (identity == null)
                //{
                //    returnMessage = "[Authentication.Identity] is required.";
                //    return;
                //}
                //
                foreach (PM_ALT_MESSAGE entity in entities)
                {
                    if (!entity.MsgPK.HasValue)
                    {
                        entity.RowDeleted = false;
                        entity.ModifiedOn = datetime;
                        this.Insert(entity);
                    }
                    else
                    {
                        entity.ModifiedOn = datetime;
                        this.UpdateSome(entity);
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        public void Restore(PM_ALT_NOTI_GROUP entity, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
                //
                if (entity == null)
                {
                    returnMessage = "Input parameter [NOTI_GROUP entity] can not be null.";
                    return;
                }
                if (!entity.NotiGroupID.HasValue)
                {
                    returnMessage = "[GROUP ID] can not be null.";
                    return;
                }
                if (string.IsNullOrEmpty(entity.GroupName))
                {
                    returnMessage = "[GROUP NAME] can not be empty.";
                    return;
                }
                //
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                //
                entity.ModifiedBy = identity.Name;
                entity.ModifiedOn = curUTCTime;
                entity.RowDeleted = false;

                this.UpdateSome(entity);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        public void Restore(PM_ALT_BASE entity, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                //
                if (entity == null)
                {
                    returnMessage = "Input parameter [ALERT entity] can not be null.";
                    return;
                }
                if (!entity.AlertID.HasValue)
                {
                    returnMessage = "[ALERT ID] can not be null.";
                    return;
                }

                #region check security
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                #endregion
                //
                entity.ModifiedBy = identity.Name;
                entity.ModifiedOn = datetime;
                entity.RowDeleted = false;

                this.UpdateSome(entity);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
Exemple #9
0
        public void Respond(PM_ALT_LOG log, out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);

            //
            try
            {
                if (log == null)
                {
                    returnMessage = "Parameter [ALERT_LOG log] can not be null.";
                    return;
                }
                if (!log.LogPK.HasValue)
                {
                    returnMessage = "Parameter [LogPK] can not be null.";
                    return;
                }
                //
                #region check security
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                #endregion
                //
                log.RespondedOn = datetime;
                this.UpdateSome(log);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
        /// <summary>
        /// 把DataTable插入数据库
        /// </summary>
        /// <param name="dt">DataTable数据</param>
        /// <param name="tablename">插入的表名</param>
        /// <returns></returns>
        public string ExcuteDataTableToDB(DataTable dt, string tablename)
        {
            //这里有两种方法,一种,将大批量插入写入D层,解耦,同时使用实例化的DB连接串,不向外暴露,但是,一旦DAO层被重新生成,则更改起来较为麻烦
            //另一种,使用连接字符串,并进行加密,加密秘钥暂定"connKey",此方法方便写入APP.config,更换数据库方便
            Database db   = DatabaseFactory.CreateDatabase(DatabaseEnum.SITBusinessDB);
            string   conn = db.ConnectionString;

            try
            {
                //使用秘钥进行加密,秘钥可以分发给专门的人进行记录,在更改数据时留出输入秘钥的接口
                conn = DESEncrypt.Encrypt(conn, "connKey");
                //输入秘钥进行解密
                string finalConn = DESEncrypt.Decrypt(conn, "connKey");

                UtilDAO.InsertEntities(finalConn, tablename, dt);
                return("OK");
            }
            catch (Exception ex)
            {
                return("NG,插入失败:" + ex);
                //throw ex;
            }
        }
 //
 public void Save(PM_ALT_EVENT_TYPE entity, IList <PM_ALT_EVENT_TYPE_GRP> mapDtls, EventTypeSaveOptions saveOptions, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         #region check
         if (saveOptions == null)
         {
             returnMessage = "Input parameter [EventTypeSaveOptions saveOptions] can not be null.";
             return;
         }
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [PM_ALT_EVENT_TYPE entity] can not be null.";
             return;
         }
         if (saveOptions.IsChangeMap)
         {
             if (mapDtls == null)
             {
                 returnMessage = "Input parameter [IList<PM_ALT_EVENT_TYPE_GRP> mapList] can not be null.";
                 return;
             }
         }
         //
         #region check security
         SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
         if (identity == null)
         {
             returnMessage = "[Authentication.Identity] is required.";
             return;
         }
         #endregion
         //
         #region check type
         if (string.IsNullOrEmpty(entity.EventTypeName))
         {
             returnMessage = "[entity.EventTypeName] is required.";
             return;
         }
         //
         if (!entity.EventTypeID.HasValue)
         {
             entity.EventTypeID = Guid.NewGuid();
             entity.CreatedBy   = identity.Name;
             entity.CreatedOn   = curUTCTime;
         }
         else
         {
             entity.ModifiedBy = identity.Name;
             entity.ModifiedOn = curUTCTime;
         }
         //
         if (string.IsNullOrEmpty(entity.CreatedBy))
         {
             entity.CreatedBy = identity.Name;
         }
         if (!entity.CreatedOn.HasValue)
         {
             entity.CreatedOn = curUTCTime;
         }
         #endregion
         //
         #region check dtls
         if (saveOptions.IsChangeMap)
         {
             foreach (PM_ALT_EVENT_TYPE_GRP dtl in mapDtls)
             {
                 if (!dtl.NotiEventGroupID.HasValue)
                 {
                     dtl.NotiEventGroupID = Guid.NewGuid();
                 }
                 if (!dtl.NotiGroupID.HasValue)
                 {
                     returnMessage = "Input parameter [NotiGroupID] can not be null.";
                     return;
                 }
                 if (!dtl.EventTypeID.HasValue)
                 {
                     returnMessage = "Input parameter [EventTypeID] can not be null.";
                     return;
                 }
             }
         }
         #endregion
         #endregion
         //
         #region save
         if (saveOptions.IsChangeType)
         {
             PM_ALT_EVENT_TYPE entityExisted = this.GetEntity(entity.EventTypeID.Value);
             if (entityExisted == null)
             {
                 if (null != this.GetEntity(entity.EventTypeName))
                 {
                     returnMessage = "The item with the same name has existed.";
                     return;
                 }
                 //
                 entity.ModifiedBy = null;
                 entity.ModifiedOn = null;
                 //
                 this.Insert(entity);
             }
             else
             {
                 this.UpdateSome(entity);
             }
         }
         //
         if (saveOptions.IsChangeMap)
         {
             _PM_ALT_EVENT_TYPE_GRPBO.SaveBatch(entity.EventTypeID.Value, mapDtls, out returnMessage);
             //
             if (!string.IsNullOrEmpty(returnMessage))
             {
                 return;
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }
        public void Save(PM_ALT_BASE entity, IList <PM_ALT_NOTI> notis, AlertSaveOptions saveOptions,
                         out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                //
                #region check
                #region check basic
                if (saveOptions == null)
                {
                    returnMessage = "Parameter [SaveOptions saveOptions] can not be null.";
                    return;
                }
                if (entity == null)
                {
                    returnMessage = "Input parameter [ALERT entity] can not be null.";
                    return;
                }
                if (!entity.AlertID.HasValue)
                {
                    returnMessage = "Input parameter [ALERT.AlertID] can not be null.";
                    return;
                }
                if (saveOptions.IsChangeNoti)
                {
                    if (notis == null)
                    {
                        returnMessage = "Input parameter [IList<ALERT_NOTI> notis] can not be null.";
                        return;
                    }
                }
                //
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                #endregion
                //
                #region check alert
                if (saveOptions.IsChangeAlert)
                {
                    if (string.IsNullOrEmpty(entity.AlertName))
                    {
                        returnMessage = "[ALERT Name] is required.";
                        return;
                    }
                    if (string.IsNullOrEmpty(entity.AlertAlias))
                    {
                        returnMessage = "[ALERT Alias] is required.";
                        return;
                    }
                    if (string.IsNullOrEmpty(entity.AlertObject))
                    {
                        returnMessage = "[ALERT Object] is required.";
                        return;
                    }

                    if (!_PM_ALT_BASEDAO.CheckDatabaseObject(entity.AlertObject))
                    {
                        returnMessage = "[ALERT Object] is invalid.";
                        return;
                    }
                    //
                    if (!entity.AlertID.HasValue)
                    {
                        entity.AlertID   = Guid.NewGuid();
                        entity.CreatedBy = identity.Name;
                        entity.CreatedOn = datetime;
                    }
                    else
                    {
                        entity.ModifiedBy = identity.Name;
                        entity.ModifiedOn = datetime;
                    }
                    //
                    if (!entity.RowDeleted.HasValue)
                    {
                        entity.RowDeleted = false;
                    }
                    if (string.IsNullOrEmpty(entity.CreatedBy))
                    {
                        entity.CreatedBy = identity.Name;
                    }
                    if (!entity.CreatedOn.HasValue)
                    {
                        entity.CreatedOn = datetime;
                    }
                }
                #endregion
                //

                #region check noti
                if (saveOptions.IsChangeNoti)
                {
                }
                #endregion

                #endregion


                //
                #region save
                //
                #region save alert
                if (saveOptions.IsChangeAlert)
                {
                    PM_ALT_BASE entityExisted = this.GetEntity(entity.AlertID.Value);
                    if (entityExisted == null)
                    {
                        if (null != this.GetEntity(entity.AlertName))
                        {
                            returnMessage = "The item with the same code has existed.";
                            return;
                        }
                        //
                        entity.ModifiedBy = null;
                        entity.ModifiedOn = null;
                        //
                        this.Insert(entity);
                    }
                    else
                    {
                        this.UpdateSome(entity);
                    }
                }
                #endregion
                //

                #region save noti
                if (saveOptions.IsChangeNoti)
                {
                    _PM_ALT_NOTIBO.SaveBatch(entity.AlertID.Value, notis, out returnMessage);
                    //
                    if (!string.IsNullOrEmpty(returnMessage))
                    {
                        return;
                    }
                }
                #endregion

                #endregion
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }
 //
 public void Save(PM_ALT_NOTI_GROUP entity, IList <PM_ALT_NOTI_GROUP_DETAIL> groupDtls, NotiGroupSaveOptions saveOptions, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         DateTime?curUTCTime = UtilDAO.GetDatabaseUtcDatetime();
         //
         #region check
         if (saveOptions == null)
         {
             returnMessage = "Input parameter [NotiGroupSaveOptions saveOptions] can not be null.";
             return;
         }
         //
         if (entity == null)
         {
             returnMessage = "Input parameter [NOTI_GROUP entity] can not be null.";
             return;
         }
         if (saveOptions.IsChangeGroupDtl)
         {
             if (groupDtls == null)
             {
                 returnMessage = "Input parameter [IList<NOTI_GROUP_DETAIL> grpDtlList] can not be null.";
                 return;
             }
         }
         //
         #region check security
         SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
         if (identity == null)
         {
             returnMessage = "[Authentication.Identity] is required.";
             return;
         }
         #endregion
         //
         #region check group
         if (string.IsNullOrEmpty(entity.GroupName))
         {
             returnMessage = "[entity.GroupName] is required.";
             return;
         }
         //
         if (!entity.NotiGroupID.HasValue)
         {
             entity.NotiGroupID = Guid.NewGuid();
             entity.CreatedBy   = identity.Name;
             entity.CreatedOn   = curUTCTime;
         }
         else
         {
             entity.ModifiedBy = identity.Name;
             entity.ModifiedOn = curUTCTime;
         }
         //
         if (string.IsNullOrEmpty(entity.CreatedBy))
         {
             entity.CreatedBy = identity.Name;
         }
         if (!entity.CreatedOn.HasValue)
         {
             entity.CreatedOn = curUTCTime;
         }
         #endregion
         //
         #region check dtls
         if (saveOptions.IsChangeGroupDtl)
         {
             foreach (PM_ALT_NOTI_GROUP_DETAIL dtl in groupDtls)
             {
                 if (!dtl.NotiGroupDetailID.HasValue)
                 {
                     dtl.NotiGroupDetailID = Guid.NewGuid();
                 }
                 if (!dtl.NotiGroupID.HasValue)
                 {
                     dtl.NotiGroupID = entity.NotiGroupID;
                 }
                 if (string.IsNullOrEmpty(dtl.MemberID))
                 {
                     returnMessage = "Input parameter [GroupDtl.Member] can not be null.";
                     return;
                 }
             }
         }
         #endregion
         #endregion
         //
         #region save
         if (saveOptions.IsChangeGroup)
         {
             PM_ALT_NOTI_GROUP entityExisted = this.GetEntity(entity.NotiGroupID.Value);
             if (entityExisted == null)
             {
                 if (null != this.GetEntity(entity.GroupName))
                 {
                     returnMessage = "The item with the same name has existed.";
                     return;
                 }
                 //
                 entity.ModifiedBy = null;
                 entity.ModifiedOn = null;
                 //
                 this.Insert(entity);
             }
             else
             {
                 this.UpdateSome(entity);
             }
         }
         //
         if (saveOptions.IsChangeGroupDtl)
         {
             _PM_ALT_NOTI_GROUP_DETAILBO.SaveBatch(entity.NotiGroupID.Value, groupDtls, out returnMessage);
             //
             if (!string.IsNullOrEmpty(returnMessage))
             {
                 return;
             }
         }
         #endregion
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }