最高借书时间

时间:2019-03-11 18:21:51

标签: c#

我正在尝试让用户借阅最大书籍以及借书的期限,我使用datagridview,MessageBox指示用户处于最大借阅或期限,以及添加按钮的时间借书的数量。

到目前为止,这里是代码,还有其他方法可以使用或使用最大借位代码吗?

private void button3_Click(object sender, EventArgs e)
{
    try
    {
        kae.OpenConnection();

        bc.Fullname = firstname.Text;
        bc.Type = writertext.Text;
        bc.Title = titletext.Text;

        if (bc.Fullname == "" || bc.Type == "" || bc.Title == "")
        {
            MessageBox.Show("Please complete the details!");
            kae.CloseConnection();
        }
        else
        {
            string query = "SELECT * FROM Borrowing_Process WHERE Fullname = '" + bc.Fullname + "' AND Type = '" + bc.Type + "'";
            OleDbDataReader reader = kae.DataReader(query);

            int count = 0;
            while (reader.Read())
            {
                count = count + 1;
            }
            if (count == 1)
            {
                string query2 = "SELECT NumberOfBooks FROM borrowing_details WHERE Fullname = '" + bc.Fullname + "'";
                OleDbDataReader reader2 = kae.DataReader(query2);

                int count2 = 0;
                while (reader2.Read())
                {
                    count2 = count2 + 1;
                }
                if (count2 >= 3)
                {
                    MessageBox.Show("You have reached maximum number of books allowed!");
                    kae.CloseConnection();
                }
                else
                {
                    MessageBox.Show("Can borrow book!");
                    DateTime db = this.dtpAddDateBorrow.Value.Date;
                    DateTime dd = this.dtpAddDueDate.Value.Date;
                    numberofbook = numberofbook + 1;

                    string query3 = "INSERT INTO borrowing_details (Fullname, Type, Title, DateBorrow, DueDate, NumberOfBooks) VALUES ('" + bc.Fullname + "', '" + bc.Type + "', '" + bc.Title + "', #" + db.ToShortDateString() + "#, #" + dd.ToShortDateString() + "#, '" + numberofbook + "')";
                    cc.ExecuteQueries(query3);

                    MessageBox.Show("New Add Borrowing Successfully!");

                    txtAddBorrowerFullname.Text = "";
                    cboAddBorrowerType.SelectedIndex = -1;
                    txtAddBookTitle.Text = "";
                    dtpAddDateBorrow.Format = DateTimePickerFormat.Custom;
                    dtpAddDueDate.Format = DateTimePickerFormat.Custom;

                    cc.CloseConnection();
                }
            }
            else if (count == 0)
            {
                MessageBox.Show("Borrower is not exist! Please register to borrow book.");
                cc.CloseConnection();
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error" + ex);
        cc.CloseConnection();
    }

0 个答案:

没有答案