コード例 #1
0
        public bool Return(borrowbook SachMuon, bookDTO book, ReaderDTO reader)
        {
            string query2 = string.Empty;

            query2 += "IF NOT EXISTS(SELECT TOP 1 MaThe FROM THEDOCGIA WHERE MaThe= @MaThe) " + Environment.NewLine;
            query2 += "INSERT INTO MUONSACH (MaThe, MaSach) " + Environment.NewLine;
            query2 += "VALUES (@MaThe, @MaSach) ";
            query2 += "else " + Environment.NewLine;
            query2 += "begin " + Environment.NewLine;
            query2 += "DECLARE @dk INT " + Environment.NewLine;
            query2 += "DECLARE cursorProduct CURSOR FOR " + Environment.NewLine;
            query2 += "select DaMuon from SACH where MaSach = @MaSach " + Environment.NewLine;
            query2 += "Open cursorProduct FETCH NEXT FROM cursorProduct INTO @dk " + Environment.NewLine;
            query2 += "if @dk = 1 " + Environment.NewLine;
            query2 += "begin" + Environment.NewLine;
            query2 += "update SACH set DaMuon = 0 where MaSach = @MaSach " + Environment.NewLine;

            query2 += "UPDATE MUONSACH SET ";
            query2 += "NgayTraThucTe = @NgayTraThucTe ";
            query2 += "WHERE MaThe=@MaThe and MaSach = @MaSach " + Environment.NewLine;
            query2 += "end " + Environment.NewLine;
            query2 += "else " + Environment.NewLine;
            query2 += "INSERT INTO MUONSACH (MaThe, MaSach, NgayTraThucTe,MaMuonSach) " + Environment.NewLine;
            query2 += "VALUES (@MaThe, @MaSach, @NgayTraThucTe,@MaMuonSach) ";
            query2 += "end " + Environment.NewLine;
            using (SqlConnection con = new SqlConnection(@"server=" + Dns.GetHostName() + ";Trusted_Connection=yes;database=LIBMANAGEMENT;")) //Init connection to host
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query2;
                    cmd.Parameters.AddWithValue("@MaSach", book.MaSach);
                    cmd.Parameters.AddWithValue("@MaThe", reader.IdReader);
                    cmd.Parameters.AddWithValue("@MaMuonSach", SachMuon.Idborrowbook);
                    cmd.Parameters.AddWithValue("@NgayTraThucTe", SachMuon.NgayTraSachThuc);


                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public bool Tra(borrowbook SachMuon, bookDTO book, ReaderDTO reader)
        {
            bool re = br.Return(SachMuon, book, reader);

            return(re);
        }
コード例 #3
0
        public bool add(borrowbook SachMuon, bookDTO book, ReaderDTO reader)
        {
            bool re = br.Add(SachMuon, book, reader);

            return(re);
        }