Пример #1
0
 /// <summary>
 /// 获得数据列表
 /// </summary>
 public List<Model.Gallery> DataTableToList(DataTable dt)
 {
     List<Model.Gallery> modelList = new List<Model.Gallery>();
     int rowsCount = dt.Rows.Count;
     if (rowsCount > 0)
     {
         Model.Gallery model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new Model.Gallery();
             if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
             {
                 model.ID=int.Parse(dt.Rows[n]["ID"].ToString());
             }
             if(dt.Rows[n]["Name"]!=null && dt.Rows[n]["Name"].ToString()!="")
             {
             model.Name=dt.Rows[n]["Name"].ToString();
             }
             if(dt.Rows[n]["Description"]!=null && dt.Rows[n]["Description"].ToString()!="")
             {
             model.Description=dt.Rows[n]["Description"].ToString();
             }
             if(dt.Rows[n]["Autor"]!=null && dt.Rows[n]["Autor"].ToString()!="")
             {
                 model.Autor=int.Parse(dt.Rows[n]["Autor"].ToString());
             }
             if(dt.Rows[n]["CreateDate"]!=null && dt.Rows[n]["CreateDate"].ToString()!="")
             {
                 model.CreateDate=DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
             }
             if(dt.Rows[n]["UpdateDate"]!=null && dt.Rows[n]["UpdateDate"].ToString()!="")
             {
                 model.UpdateDate=DateTime.Parse(dt.Rows[n]["UpdateDate"].ToString());
             }
             if(dt.Rows[n]["Cover"]!=null && dt.Rows[n]["Cover"].ToString()!="")
             {
                 model.Cover=int.Parse(dt.Rows[n]["Cover"].ToString());
             }
             modelList.Add(model);
         }
     }
     return modelList;
 }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(galleryid.Value))
            {
                Model.Gallery gallery = new Model.Gallery();
                gallery.CreateDate = DateTime.Now;
                gallery.Autor = 1;
                gallery.Name = this.txtName.Text;
                gallery.Description = this.txtDescription.Text;
                galleryBll.Add(gallery);
            }
            else
            {
                int gid = -1;
                int.TryParse(this.galleryid.Value, out gid);
                Model.Gallery gallery = galleryBll.GetModel(gid);
                gallery.UpdateDate = DateTime.Now;
                gallery.Name = this.txtName.Text;
                gallery.Description = this.txtDescription.Text;
                galleryBll.Update(gallery);

            }
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Gallery GetModel(int ID)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 ID,Name,Description,Autor,CreateDate,UpdateDate,Cover from APP_Gallery ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.Int,4)
            };
            parameters[0].Value = ID;

            Model.Gallery model=new Model.Gallery();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
                {
                    model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Name"]!=null && ds.Tables[0].Rows[0]["Name"].ToString()!="")
                {
                    model.Name=ds.Tables[0].Rows[0]["Name"].ToString();
                }
                if(ds.Tables[0].Rows[0]["Description"]!=null && ds.Tables[0].Rows[0]["Description"].ToString()!="")
                {
                    model.Description=ds.Tables[0].Rows[0]["Description"].ToString();
                }
                if(ds.Tables[0].Rows[0]["Autor"]!=null && ds.Tables[0].Rows[0]["Autor"].ToString()!="")
                {
                    model.Autor=int.Parse(ds.Tables[0].Rows[0]["Autor"].ToString());
                }
                if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
                {
                    model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if(ds.Tables[0].Rows[0]["UpdateDate"]!=null && ds.Tables[0].Rows[0]["UpdateDate"].ToString()!="")
                {
                    model.UpdateDate=DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Cover"]!=null && ds.Tables[0].Rows[0]["Cover"].ToString()!="")
                {
                    model.Cover=int.Parse(ds.Tables[0].Rows[0]["Cover"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }