PRODUCT.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Xml.Serialization;
using System.IO;
using System.Data;
/// <summary>
/// Summary description for Books
/// </summary>
///
public class Book
{
private int id;
private string title;
private string author;
private int publishDate;
private string pictureUrl;
private int price;
private int stock;
private string genre;
private string summary;
public Book()
{
}
public Book(int id, string title, string author, int publishDate, string pictureUrl, int price, int stock, string genre, string summary)
{
Id = id;
Title = title;
Author = author;
PublishDate = publishDate;
PictureUrl = pictureUrl;
Price = price;
Stock = stock;
Genre = genre;
Summary = summary;
}
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
public string Author
{
get
{
return author;
}
set
{
author = value;
}
}
public int PublishDate
{
get
{
return publishDate;
}
set
{
publishDate = value;
}
}
public string PictureUrl
{
get
{
return pictureUrl;
}
set
{
pictureUrl = value;
}
}
public int Price
{
get
{
return price;
}
set
{
price = value;
}
}
public int Stock
{
get
{
return stock;
}
set
{
stock = value;
}
}
public string Genre
{
get
{
return genre;
}
set
{
genre = value;
}
}
public string Summary
{
get
{
return summary;
}
set
{
summary = value;
}
}
}
public class Books : ICollection
{
public string CollectionName;
private ArrayList bookArray = new ArrayList();
public Book this[int index]
{
get { return (Book)bookArray[index]; }
}
public void CopyTo(Array a, int index)
{
bookArray.CopyTo(a, index);
}
public int Count
{
get { return bookArray.Count; }
}
public object SyncRoot
{
get { return this; }
}
public bool IsSynchronized
{
get { return false; }
}
public IEnumerator GetEnumerator()
{
return bookArray.GetEnumerator();
}
public void Add(Book newBook)
{
bookArray.Add(newBook);
}
public void SerializeCollection(string filename)
{
WebService w = new WebService();
Books b2 = new Books();
// Note that only the collection is serialized -- not the
// CollectionName or any other public property of the class.
b2.CollectionName = "Books";
//Book John100 = new Book("John", "100xxx");
DataTable dt = w.GetD("SELECT * FROM books", "books");
for (int i = 0; i < dt.Rows.Count; i++)
{
Book b1 = w.BuildBookById(i+1);
b2.Add(b1);
}
XmlSerializer x = new XmlSerializer(typeof(Books));
TextWriter writer = new StreamWriter(filename);
x.Serialize(writer, b2);
writer.Close();
}