Example #1
0
        /// <summary>
        /// 填充数据表[Borrow_Record]。
        /// </summary>
        /// <param name="dataTable">填充数据表</param>
        /// <param name="where">查询条件</param>
        /// <param name="top">前多少行</param>
        /// <param name="clearBeforeFill">是否填充前清空</param>
        /// <returns>查询记录数目</returns>
        public int DataSetBorrowRecordFill(DataSetLibrarySystem.borrow_recordDataTable dataTable, string where = "", int top = 1000, bool clearBeforeFill = true)
        {
            int  returnValue = 0;
            bool success     = false;

            try
            {
                dataAdapterBorrow_RecordSelect.SelectCommand.CommandText = string.Format("SELECT TOP {0} uid, b_id, borrowcount, borrowdate, returndate, " +
                                                                                         "validdate, status, fee, reborrow FROM dbo.borrow_record {1} ", top, where);

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

                returnValue = dataAdapterBorrow_RecordSelect.Fill(dataTable);
                success     = true;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(success ? returnValue : -1);
        }
Example #2
0
        private void btnBorrowBook_Click(object sender, EventArgs e)
        {
            if (!this.dbHelper.CurrentUser.isUserLogin)
            {
                if (loginDialog.ShowDialog() != DialogResult.OK)
                {
                    MessageBox.Show("借书操作需要先登录账户!", "操作提示");
                }
                else
                {
                    this.dbHelper.CurrentUser.isUserLogin = true;
                }

                lblLoginStatus.Text = string.Format("状态:{0} {1}", this.dbHelper.CurrentUser.isUserLogin ? "已登录" : "未登录",
                                                    this.dbHelper.CurrentUser.isUserLogin ? (this.dbHelper.CurrentUser.isAdminRole ? "(管理员)" : "(用户)") : "");
            }

            if (this.dbHelper.CurrentUser.isUserLogin && this.dgvBookList.SelectedRows.Count > 0)
            {
                string bookId    = this.dgvBookList.SelectedRows[0].Cells["colBID"].Value.ToString();
                int    bookCount = 0;
                if (!int.TryParse(this.dgvBookList.SelectedRows[0].Cells["colCount"].Value.ToString(), out bookCount))
                {
                    bookCount = 0;
                }

                // 查询书籍是否被借完
                DataSetLibrarySystem.borrow_recordDataTable dtBorrowRecord = new DataSetLibrarySystem.borrow_recordDataTable();
                string query = string.Format(" WHERE b_id = {0} ", bookId);
                if (this.dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) >= 0)
                {
                    int borrowOutCount = 0;
                    foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows)
                    {
                        borrowOutCount += row.borrowcount;
                    }

                    if (borrowOutCount >= bookCount)
                    {
                        MessageBox.Show("该书籍在馆藏本均已借出,暂时无法借阅", "操作提示");
                        return;
                    }

                    // 可借阅,查询账户是否欠费
                    query = string.Format(" WHERE uid = {0} ", this.dbHelper.CurrentUser.uid);
                    // 逾期费用
                    float borrowFee = 0;
                    // 是否逾期
                    bool outOfDate = false;
                    // 是否已经借阅该书
                    bool alreadyHave = false;

                    if (this.dbHelper.DataSetBorrowRecordFill(dtBorrowRecord, query) > 0)
                    {
                        foreach (DataSetLibrarySystem.borrow_recordRow row in dtBorrowRecord.Rows)
                        {
                            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 = "逾期";
                            }

                            if (row.b_id.ToString() == bookId)
                            {
                                alreadyHave = true;
                            }
                        }
                    }

                    // 逾期提醒
                    if (outOfDate)
                    {
                        MessageBox.Show(string.Format("您的账户内存在逾期费用未结算,共 {0} 元,暂时无法借阅", borrowFee.ToString("F2")), "操作提示");
                        return;
                    }

                    // 已借阅
                    if (alreadyHave)
                    {
                        MessageBox.Show("您的已经借阅了该书,尚未归还,如需续借请前往[用户管理]操作", "操作提示");
                        return;
                    }

                    // 符合借阅条件
                    dtBorrowRecord.Clear();
                    DataSetLibrarySystem.borrow_recordRow newBorrowRecord = dtBorrowRecord.Newborrow_recordRow();
                    newBorrowRecord.uid         = this.dbHelper.CurrentUser.uid;
                    newBorrowRecord.b_id        = int.Parse(bookId);
                    newBorrowRecord.borrowcount = 1;
                    newBorrowRecord.borrowdate  = DateTime.Now;
                    // 借阅期限1个月
                    newBorrowRecord.returndate = newBorrowRecord.validdate = DateTime.Now.AddMonths(1);
                    newBorrowRecord.status     = "正常";
                    newBorrowRecord.fee        = 0;
                    newBorrowRecord.reborrow   = 0;

                    dtBorrowRecord.Rows.Add(newBorrowRecord.ItemArray);

                    if (this.dbHelper.UpdateTableBorrowRecord(dtBorrowRecord) >= 0)
                    {
                        MessageBox.Show("书籍借阅成功!", "操作提示");
                    }
                    else
                    {
                        MessageBox.Show("书籍借阅失败,系统操作存在问题,请联系管理员处理!", "操作提示");
                    }
                }
            }
        }