예제 #1
0
 public ActionResult Show(string id)
 {
     int newsId = 0;
     if (!string.IsNullOrEmpty(id))
     {
         Int32.TryParse(id, out newsId);
     }
     SinglePageModel model = new SinglePageModel();
     model.SinglePage = singlePageService.GetSingPageById(id.ToString());
     if (model.SinglePage == null)
     {
         model.SinglePage = new SinglePage();
         model.SinglePage.Title = "该记录不存在或已被删除";
     }
     return View(model);
 }
예제 #2
0
        public static SinglePageModel Get(string serialno)
        {
            string sql = "select * from odnshop_singlepage where serialno = '" + serialno + "'";

            SinglePageModel info = null;

            DataTable dt = MySqlDbHelper.Query(sql).Tables[0];

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                info = PopulateModel(dr, new SinglePageModel());
            }

            return(info);
        }
예제 #3
0
        public static void Add(SinglePageModel model)
        {
            string sql = @"INSERT INTO odnshop_singlepage(serialno ,title ,content) VALUES (?serialno,?title,?content)";

            MySqlParameter[] parameters =
            {
                new MySqlParameter("?serialno", MySqlDbType.VarChar,  45),
                new MySqlParameter("?title",    MySqlDbType.VarChar, 200),
                new MySqlParameter("?content",  MySqlDbType.Text)
            };

            parameters[0].Value = model.serialno;
            parameters[1].Value = model.title;
            parameters[2].Value = model.content;

            MySqlDbHelper.ExecuteSql(sql, parameters);
        }
예제 #4
0
        private static SinglePageModel PopulateModel(DataRow dr, SinglePageModel entity)
        {
            if (dr == null)
            {
                return(null);
            }

            SinglePageModel baseEntity = (SinglePageModel)Activator.CreateInstance(entity.GetType());

            foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties())
            {
                try
                {
                    baseEntity.GetType().GetProperty(propertyInfo.Name).SetValue(baseEntity, dr[propertyInfo.Name], null);
                }
                catch { }
            }

            return(baseEntity);
        }
예제 #5
0
        public static void Update(SinglePageModel model)
        {
            string sql = @"update odnshop_singlepage set 
                            serialno = ?serialno,
                            title = ?title,
                            content = ?content where pageid = ?pageid";

            MySqlParameter[] parameters =
            {
                new MySqlParameter("?serialno", MySqlDbType.VarChar,  45),
                new MySqlParameter("?title",    MySqlDbType.VarChar, 200),
                new MySqlParameter("?content",  MySqlDbType.Text),
                new MySqlParameter("?pageid",   MySqlDbType.Int32, 11)
            };
            parameters[0].Value = model.serialno;
            parameters[1].Value = model.title;
            parameters[2].Value = model.content;
            parameters[3].Value = model.pageid;

            MySqlDbHelper.ExecuteSql(sql, parameters);
        }