コード例 #1
0
        private void btnBookDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvBookList.SelectedRows.Count > 0)
            {
                string bookID = this.dgvBookList.SelectedRows[0].Cells["colBID"].Value.ToString();

                DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable();
                string query = string.Format(" WHERE b_id = {0} ", bookID);
                if (this._dbHelper.DataSetBookFill(dtBooks, query) >= 0)
                {
                    dtBooks[0].Delete();

                    if (this._dbHelper.UpdateTableBook(dtBooks) >= 0)
                    {
                        MessageBox.Show("书籍删除成功", "操作提示");
                        RefreshBookList();
                        EmptyPanelTextBox();
                    }
                    else
                    {
                        MessageBox.Show("书籍删除失败,原因:系统操作存在问题", "操作提示");
                    }
                }
            }
        }
コード例 #2
0
        private void btnSearchBook_Click(object sender, EventArgs e)
        {
            string keywords = txtSearchKeywords.Text.Trim();

            if (string.IsNullOrEmpty(keywords))
            {
                MessageBox.Show("关键字不能为空", "操作提示");
                return;
            }

            DataSetLibrarySystem.bookDataTable dtBook = new DataSetLibrarySystem.bookDataTable();
            string query = string.Format(" WHERE title LIKE '%{0}%' OR author LIKE '%{0}%' ", keywords);

            if (this.dbHelper.DataSetBookFill(dtBook, query) >= 0)
            {
                this.lblOperateInfo.Text = string.Format("查询结果:符合要求记录共 {0} 条。", dtBook.Count);

                this.btnBorrowBook.Enabled = false;
                this.lblBookInfos.Text     = "";
                this.dgvBookList.SuspendLayout();
                this.dgvBookList.ClearSelection();
                this.dgvBookList.Rows.Clear();

                DataSetLibrarySystem.bookRow currentBook = dtBook.NewbookRow();
                for (int i = 0; i < dtBook.Rows.Count; i++)
                {
                    currentBook = (DataSetLibrarySystem.bookRow)dtBook.Rows[i];
                    this.dgvBookList.Rows.Add();
                    this.dgvBookList.Rows[i].Cells["colBID"].Value         = currentBook.b_id.ToString();
                    this.dgvBookList.Rows[i].Cells["colTitle"].Value       = currentBook.title.ToString();
                    this.dgvBookList.Rows[i].Cells["colAuthor"].Value      = currentBook.author.ToString();
                    this.dgvBookList.Rows[i].Cells["colPress"].Value       = currentBook.presscompany.ToString();
                    this.dgvBookList.Rows[i].Cells["colCategory"].Value    = currentBook.category.ToString();
                    this.dgvBookList.Rows[i].Cells["colPublishDate"].Value = currentBook.publishdate.ToString();
                    this.dgvBookList.Rows[i].Cells["colCount"].Value       = currentBook.count.ToString();
                    this.dgvBookList.Rows[i].Cells["colPosition"].Value    = currentBook.position.ToString();
                    this.dgvBookList.Rows[i].Cells["colAbstract"].Value    = currentBook._abstract.ToString();
                }

                this.dgvBookList.ResumeLayout();
            }
            else
            {
                this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。";
            }
        }
コード例 #3
0
        private void btnBookAdd_Click(object sender, EventArgs e)
        {
            if (this.dgvBookList.SelectedRows.Count > 0)
            {
                // 检查是否漏填信息
                if (!CheckPanelTextBoxFill())
                {
                    MessageBox.Show("请填写完整书籍信息", "操作提示");
                    return;
                }

                DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable();
                DataSetLibrarySystem.bookRow       newBook = dtBooks.NewbookRow();

                newBook.b_id         = -1;
                newBook.title        = this.txtTitle.Text.Trim();
                newBook.author       = this.txtAuthor.Text.Trim();
                newBook.presscompany = this.txtPress.Text.Trim();
                newBook.category     = this.txtCategory.Text.Trim();
                newBook.publishdate  = this.dtpPublishDate.Value;
                newBook.inlibdate    = this.dtpInlabDate.Value;
                newBook.count        = Convert.ToInt32(this.numCount.Value);
                newBook.position     = this.txtPosition.Text.Trim();
                newBook._abstract    = this.txtAbstract.Text.Trim();
                newBook.isbn         = this.txtISBN.Text.Trim();
                newBook.imageurl     = "";
                newBook.bookremark   = "";

                dtBooks.Rows.Add(newBook.ItemArray);

                if (this._dbHelper.UpdateTableBook(dtBooks) > 0)
                {
                    MessageBox.Show("书籍新增成功", "操作提示");
                    RefreshBookList();
                    EmptyPanelTextBox();
                }
                else
                {
                    MessageBox.Show("书籍新增失败,原因:系统操作存在问题", "操作提示");
                }
            }
        }
コード例 #4
0
        private void btnBookModify_Click(object sender, EventArgs e)
        {
            if (this.dgvBookList.SelectedRows.Count > 0)
            {
                // 检查是否漏填信息
                if (!CheckPanelTextBoxFill())
                {
                    MessageBox.Show("请填写完整书籍信息", "操作提示");
                    return;
                }

                string bookID = this.dgvBookList.SelectedRows[0].Cells["colBID"].Value.ToString();

                DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable();
                string query = string.Format(" WHERE b_id = {0} ", bookID);
                if (this._dbHelper.DataSetBookFill(dtBooks, query) >= 0)
                {
                    dtBooks[0].title        = this.txtTitle.Text.Trim();
                    dtBooks[0].author       = this.txtAuthor.Text.Trim();
                    dtBooks[0].presscompany = this.txtPress.Text.Trim();
                    dtBooks[0].category     = this.txtCategory.Text.Trim();
                    dtBooks[0].publishdate  = this.dtpPublishDate.Value;
                    dtBooks[0].inlibdate    = this.dtpInlabDate.Value;
                    dtBooks[0].count        = Convert.ToInt32(this.numCount.Value);
                    dtBooks[0].position     = this.txtPosition.Text.Trim();
                    dtBooks[0]._abstract    = this.txtAbstract.Text.Trim();
                    dtBooks[0].isbn         = this.txtISBN.Text.Trim();

                    if (this._dbHelper.UpdateTableBook(dtBooks) > 0)
                    {
                        MessageBox.Show("书籍修改成功", "操作提示");
                        RefreshBookList();
                    }
                    else
                    {
                        MessageBox.Show("书籍修改失败,原因:系统操作存在问题", "操作提示");
                    }
                }
            }
        }
コード例 #5
0
ファイル: DBHelper.cs プロジェクト: Ryan4G/librarysystem
        /// <summary>
        /// 填充数据表[Book]。
        /// </summary>
        /// <param name="dataTable">填充数据表</param>
        /// <param name="where">查询条件</param>
        /// <param name="top">前多少行</param>
        /// <param name="clearBeforeFill">是否填充前清空</param>
        /// <returns>查询记录数目</returns>
        public int DataSetBookFill(DataSetLibrarySystem.bookDataTable dataTable, string where = "", int top = 1000, bool clearBeforeFill = true)
        {
            int  returnValue = 0;
            bool success     = false;

            try
            {
                dataAdapterBookSelect.SelectCommand.CommandText = string.Format("SELECT TOP {0} b_id, title, author, isbn, abstract, category, "
                                                                                + "imageurl, presscompany, count, publishdate, inlibdate, position, bookremark FROM dbo.[book] {1} ", top, where);

                if (clearBeforeFill)
                {
                    dataTable.Clear();
                }

                returnValue = dataAdapterBookSelect.Fill(dataTable);
                success     = true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(success ? returnValue : -1);
        }
コード例 #6
0
        private void RefreshBorrowRecord()
        {
            this.dgvBorrowList.ClearSelection();
            this.btnReturnBook.Enabled = false;

            // 查询借阅书籍
            DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable();
            string query = string.Format(" WHERE uid = {0} ", this._dbHelper.CurrentUser.uid);

            if (this._dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) >= 0)
            {
                this.lblOperateInfo.Text = string.Format("查询结果: 共找到 {0} 条借阅记录。", dtBorrowRecord.Count);
                // 逾期费用
                float borrowFee = 0;
                // 是否逾期
                bool outOfDate = false;
                int  bookIndex = 0;

                this.dgvBorrowList.SuspendLayout();
                this.dgvBorrowList.Rows.Clear();
                this.txtBookID.Text       = "";
                this.numReturnCount.Value = 0;

                foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows)
                {
                    this.dgvBorrowList.Rows.Add();

                    int outDateCount = (DateTime.Now - row.validdate).Days;
                    if (outDateCount > 0)
                    {
                        outOfDate = true;

                        // 逾期费用:1元/天/本
                        borrowFee += Math.Abs(outDateCount) * 1.0f;
                        // 修改费用
                        row.fee    = Convert.ToDecimal(Math.Abs(outDateCount) * 1.0f);
                        row.status = "逾期";
                    }

                    this.dgvBorrowList.Rows[bookIndex].Cells["colBID"].Value = row.b_id;

                    // 书籍信息
                    DataSetLibrarySystem.bookDataTable dtCurrentBook = new DataSetLibrarySystem.bookDataTable();
                    query = string.Format(" WHERE b_id = {0} ", row.b_id);
                    if (this._dbHelper.DataSetBookFill(dtCurrentBook, query) > 0)
                    {
                        this.dgvBorrowList.Rows[bookIndex].Cells["colTitle"].Value  = dtCurrentBook[0].title;
                        this.dgvBorrowList.Rows[bookIndex].Cells["colAuthor"].Value = dtCurrentBook[0].author;
                    }
                    else
                    {
                        this.dgvBorrowList.Rows[bookIndex].Cells["colTitle"].Value  = "未知";
                        this.dgvBorrowList.Rows[bookIndex].Cells["colAuthor"].Value = "未知";
                    }

                    this.dgvBorrowList.Rows[bookIndex].Cells["colBorrowCount"].Value = row.borrowcount;
                    this.dgvBorrowList.Rows[bookIndex].Cells["colBorrowDate"].Value  = row.borrowdate.ToString("yyyy-MM-dd");
                    this.dgvBorrowList.Rows[bookIndex].Cells["colValidDate"].Value   = row.validdate.ToString("yyyy-MM-dd");
                    this.dgvBorrowList.Rows[bookIndex].Cells["colFee"].Value         = row.fee.ToString("F2");
                    bookIndex++;
                }

                this.dgvBorrowList.ResumeLayout();
            }
            else
            {
                this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。";
            }
        }
コード例 #7
0
        private void RefreshBookList()
        {
            string userInfo = "管理员信息\n\n欢迎您,{0}\n账户:{1}\n馆藏书籍:{2} 本\n已借出书籍:{3} 本";

            this.dgvBookList.ClearSelection();
            this.btnBookDelete.Enabled = false;
            this.btnBookModify.Enabled = false;

            int booksCount    = 0;
            int borrowedCount = 0;

            // 查询借阅书籍
            DataSetLibrarySystem.bookDataTable dtBooks = new DataSetLibrarySystem.bookDataTable();
            string query = "";

            if (this._dbHelper.DataSetBookFill(dtBooks, query) >= 0)
            {
                //this.lblOperateInfo.Text = string.Format("查询结果: 共找到 {0} 条借阅记录。", dtBorrowRecord.Count);
                int bookIndex = 0;

                this.dgvBookList.SuspendLayout();
                this.dgvBookList.Rows.Clear();

                foreach (DataSetLibrarySystem.bookRow row in dtBooks.Rows)
                {
                    this.dgvBookList.Rows.Add();
                    this.dgvBookList.Rows[bookIndex].Cells["colBID"].Value         = row.b_id;
                    this.dgvBookList.Rows[bookIndex].Cells["colTitle"].Value       = row.title;
                    this.dgvBookList.Rows[bookIndex].Cells["colAuthor"].Value      = row.author;
                    this.dgvBookList.Rows[bookIndex].Cells["colPress"].Value       = row.presscompany;
                    this.dgvBookList.Rows[bookIndex].Cells["colCategory"].Value    = row.category;
                    this.dgvBookList.Rows[bookIndex].Cells["colPublishDate"].Value = row.publishdate.ToString("yyyy-MM-dd");
                    this.dgvBookList.Rows[bookIndex].Cells["colInlabDate"].Value   = row.inlibdate.ToString("yyyy-MM-dd");
                    this.dgvBookList.Rows[bookIndex].Cells["colCount"].Value       = row.count;
                    this.dgvBookList.Rows[bookIndex].Cells["colPosition"].Value    = row.position;
                    this.dgvBookList.Rows[bookIndex].Cells["colAbstract"].Value    = row._abstract;
                    this.dgvBookList.Rows[bookIndex].Cells["colImageUrl"].Value    = row.imageurl;
                    this.dgvBookList.Rows[bookIndex].Cells["colISBN"].Value        = row.isbn;
                    bookIndex++;

                    // 书籍总量
                    booksCount += row.count;
                }

                this.dgvBookList.ResumeLayout();
            }
            else
            {
                //this.lblOperateInfo.Text = "查询失败,原因:系统操作发生错误。";
            }

            DataSetLibrarySystem.borrow_recordDataTable dtBorrowed = new DataSetLibrarySystem.borrow_recordDataTable();
            this._dbHelper.DataSetBorrowRecordFill(dtBorrowed);
            borrowedCount = dtBorrowed.Count;

            lblUserInfo.Text = string.Format(userInfo,
                                             this._dbHelper.CurrentUser.name,
                                             this._dbHelper.CurrentUser.account,
                                             booksCount,
                                             borrowedCount);
        }