Ejemplo n.º 1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <BookShop.Model.Book> DataTableToList(DataTable dt)
        {
            List <BookShop.Model.Book> modelList = new List <BookShop.Model.Book>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                BookShop.Model.Book model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BookShop.Model.Book();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    model.Title  = dt.Rows[n]["Title"].ToString();
                    model.Author = dt.Rows[n]["Author"].ToString();
                    if (dt.Rows[n]["PublisherId"].ToString() != "")
                    {
                        int PublisherId = int.Parse(dt.Rows[n]["PublisherId"].ToString());
                        model.Publisher = publisherServices.GetModel(PublisherId);
                    }
                    if (dt.Rows[n]["PublishDate"].ToString() != "")
                    {
                        model.PublishDate = DateTime.Parse(dt.Rows[n]["PublishDate"].ToString());
                    }
                    model.ISBN = dt.Rows[n]["ISBN"].ToString();
                    if (dt.Rows[n]["WordsCount"].ToString() != "")
                    {
                        model.WordsCount = int.Parse(dt.Rows[n]["WordsCount"].ToString());
                    }
                    if (dt.Rows[n]["UnitPrice"].ToString() != "")
                    {
                        model.UnitPrice = decimal.Parse(dt.Rows[n]["UnitPrice"].ToString());
                    }
                    model.ContentDescription = dt.Rows[n]["ContentDescription"].ToString();
                    model.AurhorDescription  = dt.Rows[n]["AurhorDescription"].ToString();
                    model.EditorComment      = dt.Rows[n]["EditorComment"].ToString();
                    model.TOC = dt.Rows[n]["TOC"].ToString();
                    if (dt.Rows[n]["CategoryId"].ToString() != "")
                    {
                        int CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString());
                        model.Category = categoryServices.GetModel(CategoryId);
                    }
                    if (dt.Rows[n]["Clicks"].ToString() != "")
                    {
                        model.Clicks = int.Parse(dt.Rows[n]["Clicks"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(BookShop.Model.Book model)
 {
     dal.Update(model);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(BookShop.Model.Book model)
 {
     return(dal.Add(model));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(BookShop.Model.Book model)
 {
     return(dal.Update(model));
 }