コード例 #1
0
        public static ObservableCollection <Book> GetDeletedBooks()
        {
            ObservableCollection <Book> result = null;

            try
            {
                var reader = DataConnector.ExecuteQuery("select MaSach,TenSach,AnhBia,SoLuongTon,DonGia " +
                                                        "from Sach " +
                                                        "where BiXoa = 'true'");
                if (reader != null)
                {
                    result = new ObservableCollection <Book>();
                    while (reader.Read())
                    {
                        var id   = reader.GetInt32(0);
                        var item = new Book(id);
                        item.BeginInit();
                        item.Name      = (string)reader.GetValueDefault(1, null);
                        item.Image     = (string)reader.GetValueDefault(2, null);
                        item.Number    = (int)reader.GetValueDefault(3, 0);
                        item.Price     = (int)reader.GetValueDefault(4, 0);
                        item.IsDeleted = true;
                        foreach (var i in AuthorAdapter.GetAuthorsForBook(id))
                        {
                            item.Authors.Add(i);
                        }
                        foreach (var i in GenreAdapter.GetGenresForBook(id))
                        {
                            item.Genres.Add(i);
                        }
                        item.IsDeletedItem = item.IsDeleted;
                        item.EndInit();
                        result.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.Current.DataCantBeRead.Call(ex.Message);
            }
            return(result);
        }
コード例 #2
0
        public static ObservableCollection <Book> GetBooksForGenre(int genreid)
        {
            ObservableCollection <Book> result = null;

            try
            {
                var reader = DataConnector.ExecuteQuery("select s.MaSach,s.TenSach,s.AnhBia,s.SoLuongTon,s.DonGia,s.BiXoa " +
                                                        "from Sach s, ChiTietTheLoaiSach ct " +
                                                        "where s.MaSach = ct.MaSach and ct.MaTheLoai = " + genreid);
                if (reader != null)
                {
                    result = new ObservableCollection <Book>();
                    while (reader.Read())
                    {
                        var id   = reader.GetInt32(0);
                        var item = new Book(id);
                        item.BeginInit();
                        item.Name      = (string)reader.GetValueDefault(1, null);
                        item.Image     = (string)reader.GetValueDefault(2, null);
                        item.Number    = (int)reader.GetValueDefault(3, 0);
                        item.Price     = (int)reader.GetValueDefault(4, 0);
                        item.IsDeleted = (bool)reader.GetValueDefault(5, false);
                        foreach (var i in AuthorAdapter.GetAuthorsForBook(id))
                        {
                            item.Authors.Add(i);
                        }
                        foreach (var i in GenreAdapter.GetGenresForBook(id))
                        {
                            item.Genres.Add(i);
                        }
                        item.IsDeletedItem = item.IsDeleted;
                        item.EndInit();
                        result.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.Current.DataCantBeRead.Call(ex.Message);
            }
            return(result);
        }
コード例 #3
0
        public static Book GetBook(int id)
        {
            Book result = null;

            try
            {
                var reader = DataConnector.ExecuteQuery("select s.TenSach,s.AnhBia,s.SoLuongTon,s.DonGia,s.BiXoa " +
                                                        "from Sach s where s.MaSach = " + id);
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        var item = new Book(id);
                        item.BeginInit();
                        item.Name      = (string)reader.GetValueDefault(0, null);
                        item.Image     = (string)reader.GetValueDefault(1, null);
                        item.Number    = (int)reader.GetValueDefault(2, 0);
                        item.Price     = (int)reader.GetValueDefault(3, 0);
                        item.IsDeleted = (bool)reader.GetValueDefault(4, false);
                        foreach (var i in AuthorAdapter.GetAuthorsForBook(id))
                        {
                            item.Authors.Add(i);
                        }
                        foreach (var i in GenreAdapter.GetGenresForBook(id))
                        {
                            item.Genres.Add(i);
                        }
                        item.IsDeletedItem = item.IsDeleted;
                        item.EndInit();
                        result = item;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorManager.Current.DataCantBeRead.Call(ex.Message);
            }
            return(result);
        }