Beispiel #1
0
        protected void btnMuonSach_Click(object sender, EventArgs e)
        {
            muonsach ms = LayDuLieuTuForm();
            chucnag  cn = new chucnag();
            bool     kt = cn.CheckSoLuongSach(ms.MaSach, ms.SoLuong);

            if (kt)
            {
                bool exist = cn.CheckMuonSach(ms);
                if (exist)
                {
                    cn.UpdateMuonSach(ms);
                    lblThongBao.Text = "Mượn thành công";
                    cn.UpdateSoLuongSach(ms.MaSach, ms.SoLuong);
                }
                else
                {
                    bool result = cn.InsertMuonSach(ms);
                    if (result)
                    {
                        lblThongBao.Text = "Mượn thành công";
                        cn.UpdateSoLuongSach(ms.MaSach, ms.SoLuong);
                    }
                    else
                    {
                        lblThongBao.Text = "Có lỗi";
                    }
                }
            }
            else
            {
                lblThongBao.Text = "Số lượng sách thư viện không đủ";
            }
        }
Beispiel #2
0
        public muonsach LayDuLieuTuForm()
        {
            muonsach ms = new muonsach()
            {
                MaSV      = txtMaSinhVien.Text,
                MaCB      = txtMaCanBo.Text,
                MaSach    = txtMaSach.Text,
                SoLuong   = int.Parse(txtSoLuong.Text),
                NgayMuon  = DateTime.ParseExact(txtNgayMuon.Text, "dd/MM/yyyy", CultureInfo.InstalledUICulture),
                NgayTra   = DateTime.ParseExact(txtNgayTra.Text, "dd/MM/yyyy", CultureInfo.InstalledUICulture),
                TrangThai = Boolean.Parse(RadioButtonList1.SelectedValue)
            };

            return(ms);
        }
Beispiel #3
0
 public bool CheckMuonSach(muonsach ms)//Kiểm tra sách muốn mượn đã có trong lịch sử mượn?
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "select * from MuonSach where MaSV=@maSV and MaSach=@maSach and TrangThai=0 and NgayMuon=@ngaymuon and NgayTra=@ngaytra";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@maSV", ms.MaSV);
         cmd.Parameters.AddWithValue("@maSach", ms.MaSach);
         cmd.Parameters.AddWithValue("@ngaymuon", ms.NgayMuon);
         cmd.Parameters.AddWithValue("@ngaytra", ms.NgayTra);
         conn.Open();
         SqlDataReader dr = cmd.ExecuteReader();
         return(dr.Read());
     }
 }
Beispiel #4
0
 public bool UpdateMuonSach(muonsach ms)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "update MuonSach set SoLuong=SoLuong+@sl where MaSV=@maSV and MaSach=@maSach and NgayMuon=@ngaymuon and NgayTra=@ngaytra";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@maSV", ms.MaSV);
         cmd.Parameters.AddWithValue("@maSach", ms.MaSach);
         cmd.Parameters.AddWithValue("@sl", ms.SoLuong);
         cmd.Parameters.AddWithValue("@ngaymuon", ms.NgayMuon);
         cmd.Parameters.AddWithValue("@ngaytra", ms.NgayTra);
         conn.Open();
         int count = cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Beispiel #5
0
 public bool InsertMuonSach(muonsach ms)//Thêm lịch sử mượn sách
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "insert into MuonSach(MaSV,MaSach,SoLuong,NgayMuon,NgayTra,TrangThai) values(@masv,@masach,@sl,@ngaymuon,@ngaytra,@trangthai)";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@masach", ms.MaSach);
         cmd.Parameters.AddWithValue("@masv", ms.MaSV);
         cmd.Parameters.AddWithValue("@sl", ms.SoLuong);
         cmd.Parameters.AddWithValue("@ngaymuon", ms.NgayMuon);
         cmd.Parameters.AddWithValue("@ngaytra", ms.NgayTra);
         cmd.Parameters.AddWithValue("@trangthai", ms.TrangThai);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }