コード例 #1
0
        // GET: Default
        public ActionResult Index()
        {
            string sql = "select * from CLASSBANJI c left join Stuinfo s on c.ClassID=s.CId";

            using (OracleConnection conn = DapperFactory.CrateOracleConnection())
            {
                var list = conn.Query <Stuinfo>(sql);
                return(View(list));
            }
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            string sql = "select * from CLASSBANJI c left join Stuinfo s on c.ClassID=s.CId where s.ID=" + id;

            using (OracleConnection conn = DapperFactory.CrateOracleConnection())
            {
                var list = conn.QueryFirst <Stuinfo>(sql);
                return(View(list));
            }
        }
コード例 #3
0
        public ActionResult EditModel(Stuinfo stu)
        {
            string sql = "UPDATE STUINFO set Name=:Name,Sex=:Sex,Age=:Age,Email=:Email,CId=:CId,AddTime=:AddTime where ID=:ID";

            using (OracleConnection conn = DapperFactory.CrateOracleConnection())
            {
                if (conn.Execute(sql, stu) < 0)
                {
                    ViewBag.Msg = "修改失败!";
                }
                return(RedirectToAction("Index"));
            }
        }
コード例 #4
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            string sql = "DELETE STUINFO WHERE ID=" + id;

            using (OracleConnection conn = DapperFactory.CrateOracleConnection())
            {
                if (conn.Execute(sql, id) < 0)
                {
                    ViewBag.Msg = "删除失败!";
                }
                return(RedirectToAction("Index"));
            }
        }
コード例 #5
0
        public ActionResult GetClassList()
        {
            string sql = "SELECT * FROM CLASSBANJI";

            using (OracleConnection conn = DapperFactory.CrateOracleConnection())
            {
                ViewData["classlist"] = conn.Query <CLASSBANJI>(sql).Select(w => new SelectListItem()
                {
                    Text = w.ClassNAME, Value = w.ClassID.ToString()
                }).ToList();
                return(View());
            }
        }
コード例 #6
0
 /// <summary>
 /// 添加操作
 /// </summary>
 /// <param name="stuinfo"></param>
 /// <returns></returns>
 public ActionResult AddStuinfo(Stuinfo stuinfo)
 {
     if (ModelState.IsValid)
     {
         string sql = "insert into Stuinfo(Name,Sex,Age,Email,CId,AddTime) VALUES(:Name,:Sex,:Age,:Email,:CId,:AddTime)";
         using (OracleConnection conn = DapperFactory.CrateOracleConnection())
         {
             stuinfo.AddTime = DateTime.Now;
             if (conn.Execute(sql, stuinfo) > 0)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ViewBag.Msg = "添加失败!";
                 return(View(stuinfo));
             }
         }
     }
     else
     {
         return(HttpNotFound());
     }
 }