예제 #1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Class_Notice> DataTableToList(DataTable dt)
        {
            List<Model.Class_Notice> modelList = new List<Model.Class_Notice>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Class_Notice model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Class_Notice();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["ClassId"].ToString() != "")
                    {
                        model.ClassId = int.Parse(dt.Rows[n]["ClassId"].ToString());
                    }
                    model.Title = dt.Rows[n]["Title"].ToString();
                    model.Content = dt.Rows[n]["Content"].ToString();
                    if (dt.Rows[n]["Creater"].ToString() != "")
                    {
                        model.Creater = int.Parse(dt.Rows[n]["Creater"].ToString());
                    }
                    if (dt.Rows[n]["Display"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Display"].ToString() == "1") || (dt.Rows[n]["Display"].ToString().ToLower() == "true"))
                        {
                            model.Display = true;
                        }
                        else
                        {
                            model.Display = false;
                        }
                    }
                    if (dt.Rows[n]["Delflag"].ToString() != "")
                    {
                        if ((dt.Rows[n]["Delflag"].ToString() == "1") || (dt.Rows[n]["Delflag"].ToString().ToLower() == "true"))
                        {
                            model.Delflag = true;
                        }
                        else
                        {
                            model.Delflag = false;
                        }
                    }
                    if (dt.Rows[n]["CreateDate"].ToString() != "")
                    {
                        model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString());
                    }

                    modelList.Add(model);
                }
            }
            return modelList;
        }
예제 #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Class_Notice GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.Id, a.ClassId, a.Title, a.Content, a.Creater, a.Display, a.Delflag, a.CreateDate,b.RealName  ");
            strSql.Append("  from Class_Notice a left join Member_BaseInfo b on a.Creater = b.AccountId ");
            strSql.Append(" where ");
            strSql.Append(" a.Id = @Id  ");

            SqlParameter[] parameters = {
                                                new SqlParameter("@Id", SqlDbType.Int,4)
                            };
            parameters[0].Value = Id;

            Model.Class_Notice model = new Model.Class_Notice();
            DataSet ds = MSEntLibSqlHelper.ExecuteDataSetBySql(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ClassId"].ToString() != "")
                {
                    model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
                if (ds.Tables[0].Rows[0]["Creater"].ToString() != "")
                {
                    model.Creater = int.Parse(ds.Tables[0].Rows[0]["Creater"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Display"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Display"].ToString() == "1") || (ds.Tables[0].Rows[0]["Display"].ToString().ToLower() == "true"))
                    {
                        model.Display = true;
                    }
                    else
                    {
                        model.Display = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["Delflag"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["Delflag"].ToString() == "1") || (ds.Tables[0].Rows[0]["Delflag"].ToString().ToLower() == "true"))
                    {
                        model.Delflag = true;
                    }
                    else
                    {
                        model.Delflag = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                {
                    model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RealName"].ToString() != "")
                {
                    model.OrganTitle = ds.Tables[0].Rows[0]["RealName"].ToString();
                }

                return model;
            }
            else
            {
                return null;
            }
        }