C#实现图书管理系统(课程设计)——第六步、还书界面及操作

C#实现图书管理系统(课程设计)——第六步、还书界面及操作

上一篇:查询界面

这里就和借书界面很像了,不多说了,链接:借书界面

(1)窗体设计

C#实现图书管理系统(课程设计)——第六步、还书界面及操作_第1张图片

(2)retnfro.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Util;
using System.Data.SqlClient;

namespace Retnf
{
    public class Retnfro
    {
        public Retnfro()
        { }
        public Boolean Retn(int tid, int bid)
        {
            bool flag = false;
            SqlConnection sqlCon;
            sqlCon = DbUtil.getConnection();
            sqlCon.Open();
            try
            {
                string sqldel = "delete from rent where 学号 = '" + tid + "' and 编号 = '" + bid + "'";
                SqlCommand command1 = new SqlCommand(sqldel, sqlCon);
                int result1 = command1.ExecuteNonQuery();
                string sqltwo = "update books set 剩余数量=剩余数量+1 where 编号='" + bid + "'";
                if (result1 == 1) 
                {
                    SqlCommand command2 = new SqlCommand(sqltwo, sqlCon);
                    int result2 = command2.ExecuteNonQuery();
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            catch (Exception ec)
            { }
            return flag;
        }
    }
}

(3)窗体代码retn.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using Retnf;


namespace LogIn
{
    public partial class retn : Form
    {
        public retn()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Sid = textBox1.Text;
            string Bid = textBox2.Text;
            bool flag;
            if(Sid =="" || Bid =="")
            { MessageBox.Show("请输入学号和编号"); return; }

            //实例化
            int bookid = System.Convert.ToInt32(Bid);
            int studentid = System.Convert.ToInt32(Sid);
            bookandstu bookstu = new bookandstu(bookid, studentid);

            if (!String.IsNullOrEmpty(Bid) && !String.IsNullOrEmpty(Sid))
            {
                Retnfro retn2 = new Retnfro();
                flag = retn2.Retn(bookstu.Tid, bookstu.Bid);
                if (flag)
                {
                    MessageBox.Show("还书成功");
                }
                else
                {
                    MessageBox.Show("失败");
                }
            }
        }
    }
}

下一篇:进库界面

你可能感兴趣的:(C#课程设计,c#,数据库)