Пример #1
0
        /// <summary>
        /// 根据实体进行更新操作
        /// </summary>
        /// <param name="t">数据实体</param>
        /// <param name="primaryKey">库表主键</param>
        /// <returns></returns>
        public bool Update(T t, string primaryKey = "id")
        {
            bool isSuccess = true;

            try
            {
                WriteDataBase.BeginTransaction();
                isSuccess = WriteDataBase.Update(TableName, primaryKey, t) > 0;
                WriteDataBase.CompleteTransaction();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                isSuccess = false;
                WriteDataBase.CloseSharedConnection();
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
            return(isSuccess);
        }
Пример #2
0
        /// <summary>
        /// 根据实体进行删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual bool Delete(T t)
        {
            bool isSuccess = true;

            try
            {
                WriteDataBase.BeginTransaction();
                isSuccess = WriteDataBase.Delete(TableName, "id", t) > 0;
                WriteDataBase.CompleteTransaction();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                WriteDataBase.CloseSharedConnection();
                isSuccess = false;
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
            return(isSuccess);
        }
Пример #3
0
        /// <summary>
        /// 根据实体进行软删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool DeleteStatus(T t)
        {
            bool isSuccess = true;

            try
            {
                WriteDataBase.BeginTransaction();
                isSuccess = WriteDataBase.DeleteStatus(t) > 0;
                WriteDataBase.CompleteTransaction();
            }
            catch (Exception ex)
            {
                log.Info("Delete(T):" + ex);
                isSuccess = false;
                WriteDataBase.AbortTransaction();
                WriteDataBase.CloseSharedConnection();
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
            return(isSuccess);
        }
Пример #4
0
        /// <summary>
        /// 保存该实体
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Save(T t)
        {
            bool isSuccess = true;

            try
            {
                WriteDataBase.BeginTransaction();
                object obj = WriteDataBase.Insert(t);
                WriteDataBase.CompleteTransaction();
            }
            catch (Exception ex)
            {
                log.Info("Save:" + ex);
                isSuccess = false;
                WriteDataBase.AbortTransaction();
                WriteDataBase.CloseSharedConnection();
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
            return(isSuccess);
        }
Пример #5
0
        /// <summary>
        /// 保存实体 返回整形ID
        /// </summary>
        /// <param name="t">数据实体</param>
        /// <param name="primaryKey">库表主键</param>
        /// <returns></returns>
        public int Add(T t, string primaryKey = "id")
        {
            int isSuccess = 0;

            try
            {
                WriteDataBase.BeginTransaction();
                object obj = WriteDataBase.Insert(TableName, primaryKey, t);
                isSuccess = Convert.ToInt32(obj);
                WriteDataBase.CompleteTransaction();
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                isSuccess = 0;
                WriteDataBase.CloseSharedConnection();
                LogHelper.Error(ex);
            }
            finally
            {
                WriteDataBase.CloseSharedConnection();
            }
            return(isSuccess);
        }