Beispiel #1
0
        /// <summary>
        /// 修改指定的数据
        /// <param name="e">修改后的数据实体对象</param>
        /// <para>数据对应的主键必须在实例中设置</para>
        /// </summary>
        public void Update(ProBook e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand    _cmdUpdateProBook = cmdUpdateProBook.Clone() as MySqlCommand;

            _cmdUpdateProBook.Connection = oc;

            try
            {
                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }

                _cmdUpdateProBook.Parameters["@BookId"].Value       = e.BookId;
                _cmdUpdateProBook.Parameters["@BookName"].Value     = e.BookName;
                _cmdUpdateProBook.Parameters["@BookSize"].Value     = e.BookSize;
                _cmdUpdateProBook.Parameters["@BookType"].Value     = e.BookType;
                _cmdUpdateProBook.Parameters["@Introduction"].Value = e.Introduction;
                _cmdUpdateProBook.Parameters["@State"].Value        = (int)e.State;
                _cmdUpdateProBook.Parameters["@EditeTime"].Value    = DateTime.Now;
                _cmdUpdateProBook.Parameters["@BookCover"].Value    = (int)e.BookCover;

                _cmdUpdateProBook.ExecuteNonQuery();
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdUpdateProBook.Dispose();
                _cmdUpdateProBook = null;
                GC.Collect();
            }
        }
Beispiel #2
0
        public BookModel Bind(ProBook book, ViewModelBindOption bindOptions)
        {
            this.Id           = book.BookId;
            this.Name         = book.BookName;
            this.BookSize     = book.BookSize;
            this.BookType     = book.BookType;
            this.Introduction = book.Introduction;
            this.CreateTime   = book.CreateTime;
            this.EditeTime    = book.EditeTime;
            this.BookCover    = book.BookCover;

            if (ContainEnumType <BookBindType>(bindOptions.BookBindType, BookBindType.Pics))
            {
                this.Pics = PicModel.BindList(book.Pics, bindOptions);
            }
            if (ContainEnumType <BookBindType>(bindOptions.BookBindType, BookBindType.Author))
            {
                UserServiceClient       client  = new UserServiceClient();
                AdvancedResult <AdUser> userRes = client.GetUserInfoByID(book.AdUserId);
                if (userRes.Error == DataStructure.AppError.ERROR_SUCCESS && userRes.Data != null)
                {
                    this.Author = new UserModel().Bind(userRes.Data, bindOptions);
                }
            }

            return(this);
        }
Beispiel #3
0
        public AdvancedResult <int> AddBook(string bookname, BookSize booksize, BookCoverType bookcover, int booktype, string introduction, string token)
        {
            AdvancedResult <int> result = new AdvancedResult <int>();

            try
            {
                if (string.IsNullOrEmpty(bookname))
                {
                    result.Error = AppError.ERROR_BOOK_NOT_NULL;
                    return(result);
                }
                if (!CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
                else
                {
                    int userid = Convert.ToInt32(CacheManagerFactory.GetMemoryManager().Get(token));

                    //int userid = 5;
                    ProBook book = new ProBook();

                    book.BookName     = bookname.Trim();
                    book.BookSize     = booksize;
                    book.BookType     = booktype;
                    book.AdUserId     = userid;
                    book.BookCover    = bookcover;
                    book.Introduction = string.IsNullOrEmpty(introduction) ? string.Empty : introduction.Trim();

                    result.Data = ProBookAccessor.Instance.Insert(book);

                    result.Error = AppError.ERROR_SUCCESS;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            return(result);
        }
        public AdvancedResult<int> AddBook(string bookname, BookSize booksize,BookCoverType bookcover, int booktype, string introduction, string token)
        {
            AdvancedResult<int> result = new AdvancedResult<int>();
            try
            {
                if (string.IsNullOrEmpty(bookname))
                {
                    result.Error = AppError.ERROR_BOOK_NOT_NULL;
                    return result;
                }
                if (!CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
                else
                {
                    int userid = Convert.ToInt32(CacheManagerFactory.GetMemoryManager().Get(token));

                //int userid = 5;
                    ProBook book = new ProBook();

                    book.BookName = bookname.Trim();
                    book.BookSize = booksize;
                    book.BookType = booktype;
                    book.AdUserId = userid;
                    book.BookCover = bookcover;
                    book.Introduction = string.IsNullOrEmpty(introduction) ? string.Empty : introduction.Trim();

                    result.Data = ProBookAccessor.Instance.Insert(book);

                    result.Error = AppError.ERROR_SUCCESS;
                }
            }
            catch (Exception e)
            {
                result.Error = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            return result;
        }
Beispiel #5
0
        public RespResult EditBook(int bookid, string bookname, BookSize booksize, BookCoverType bookcover, int booktype, string introduction, string token)
        {
            RespResult result = new RespResult();

            try
            {
                if (string.IsNullOrEmpty(bookname))
                {
                    result.Error = AppError.ERROR_BOOK_NOT_NULL;
                    return(result);
                }

                if (!CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
                else
                {
                    ProBook book = new ProBook();
                    book.BookId       = bookid;
                    book.BookName     = bookname.Trim();
                    book.BookSize     = booksize;
                    book.BookType     = booktype;
                    book.BookCover    = bookcover;
                    book.Introduction = string.IsNullOrEmpty(introduction) ? string.Empty : introduction.Trim();
                    book.State        = StateType.Active;

                    ProBookAccessor.Instance.Update(book);

                    result.Error = AppError.ERROR_SUCCESS;
                }
            }
            catch (Exception e)
            {
                result.Error     = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 获取指定记录
        /// <param name="id">Id值</param>
        /// </summary>
        public ProBook Get(int BookId, StateType state)
        {
            ProBook         returnValue    = null;
            MySqlConnection oc             = ConnectManager.Create();
            MySqlCommand    _cmdGetProBook = cmdGetProBook.Clone() as MySqlCommand;

            _cmdGetProBook.Connection = oc;
            try
            {
                _cmdGetProBook.Parameters["@BookId"].Value = BookId;
                _cmdGetProBook.Parameters["@State"].Value  = (int)state;

                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }

                MySqlDataReader reader = _cmdGetProBook.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    returnValue = new ProBook().BuildSampleEntity(reader);
                }
                List <ResPic> returnValue_item = new List <ResPic>();
                returnValue_item = ResPicAccessor.Instance.Search(BookId, PicType.Book);
                returnValue.Pics = returnValue_item;
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdGetProBook.Dispose();
                _cmdGetProBook = null;
                GC.Collect();
            }
            return(returnValue);
        }
Beispiel #7
0
        /// <summary>
        /// 添加数据
        /// <param name="es">数据实体对象数组</param>
        /// <returns></returns>
        /// </summary>
        public int Insert(ProBook e)
        {
            MySqlConnection oc = ConnectManager.Create();
            MySqlCommand    _cmdInsertProBook = cmdInsertProBook.Clone() as MySqlCommand;
            int             returnValue       = 0;

            _cmdInsertProBook.Connection = oc;
            try
            {
                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }
                DateTime time = DateTime.Now;
                _cmdInsertProBook.Parameters["@BookName"].Value     = e.BookName;
                _cmdInsertProBook.Parameters["@BookSize"].Value     = (int)e.BookSize;
                _cmdInsertProBook.Parameters["@BookType"].Value     = e.BookType;
                _cmdInsertProBook.Parameters["@AdUserId"].Value     = e.AdUserId;
                _cmdInsertProBook.Parameters["@EditeTime"].Value    = time;
                _cmdInsertProBook.Parameters["@CreateTime"].Value   = time;
                _cmdInsertProBook.Parameters["@Introduction"].Value = e.Introduction;
                _cmdInsertProBook.Parameters["@BookCover"].Value    = (int)e.BookCover;

                _cmdInsertProBook.ExecuteNonQuery();
                returnValue = Convert.ToInt32(_cmdInsertProBook.LastInsertedId);

                return(returnValue);
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdInsertProBook.Dispose();
                _cmdInsertProBook = null;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 根据条件分页获取指定数据
        /// <param name="pageIndex">当前页</param>
        /// <para>索引从0开始</para>
        /// <param name="pageSize">每页记录条数</param>
        /// <para>记录数必须大于0</para>
        /// </summary>
        public PageEntity <ProBook> Search(Int32 AdUserId, StateType state, int pageIndex, int pageSize)
        {
            PageEntity <ProBook> returnValue         = new PageEntity <ProBook>();
            List <ProBook>       booklist            = new List <ProBook>();
            MySqlConnection      oc                  = ConnectManager.Create();
            MySqlCommand         _cmdLoadProBook     = cmdLoadProBook.Clone() as MySqlCommand;
            MySqlCommand         _cmdGetProBookCount = cmdGetProBookCount.Clone() as MySqlCommand;

            _cmdLoadProBook.Connection     = oc;
            _cmdGetProBookCount.Connection = oc;

            try
            {
                _cmdLoadProBook.Parameters["@PageIndex"].Value = pageIndex;
                _cmdLoadProBook.Parameters["@PageSize"].Value  = pageSize;
                _cmdLoadProBook.Parameters["@AdUserId"].Value  = AdUserId;
                _cmdLoadProBook.Parameters["@State"].Value     = (int)state;

                if (oc.State == ConnectionState.Closed)
                {
                    oc.Open();
                }

                MySqlDataReader reader = _cmdLoadProBook.ExecuteReader();
                while (reader.Read())
                {
                    ProBook book = new ProBook();
                    book = book.BuildSampleEntity(reader);
                    booklist.Add(book);
                }

                _cmdGetProBookCount.Parameters["@AdUserId"].Value = AdUserId;
                _cmdGetProBookCount.Parameters["@State"].Value    = (int)state;


                reader.Close();

                for (int i = 0; i < booklist.Count; i++)
                {
                    List <ResPic> returnValue_item = new List <ResPic>();
                    returnValue_item = ResPicAccessor.Instance.Search(booklist[i].BookId, PicType.Book);
                    booklist[i].Pics = returnValue_item;
                }

                returnValue.Items        = booklist;
                returnValue.PageIndex    = pageIndex;
                returnValue.PageSize     = pageSize;
                returnValue.RecordsCount = Convert.ToInt32(_cmdGetProBookCount.ExecuteScalar());
            }
            finally
            {
                oc.Close();
                oc.Dispose();
                oc = null;
                _cmdLoadProBook.Dispose();
                _cmdLoadProBook = null;
                _cmdGetProBookCount.Dispose();
                _cmdGetProBookCount = null;
                GC.Collect();
            }
            return(returnValue);
        }
        public RespResult EditBook(int bookid, string bookname, BookSize booksize, BookCoverType bookcover, int booktype, string introduction, string token)
        {
            RespResult result = new RespResult();
            try
            {
                if (string.IsNullOrEmpty(bookname))
                {
                    result.Error = AppError.ERROR_BOOK_NOT_NULL;
                    return result;
                }

                if (!CacheManagerFactory.GetMemoryManager().Contains(token))
                {
                    result.Error = AppError.ERROR_PERSON_NOT_LOGIN;
                }
                else
                {

                    ProBook book = new ProBook();
                    book.BookId = bookid;
                    book.BookName = bookname.Trim();
                    book.BookSize = booksize;
                    book.BookType = booktype;
                    book.BookCover = bookcover;
                    book.Introduction = string.IsNullOrEmpty(introduction) ? string.Empty : introduction.Trim();
                    book.State = StateType.Active;

                    ProBookAccessor.Instance.Update(book);

                    result.Error = AppError.ERROR_SUCCESS;
                }
            }
            catch (Exception e)
            {
                result.Error = AppError.ERROR_FAILED;
                result.ExMessage = e.ToString();
            }
            return result;
        }