using DongSuWei01.Models; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Services.Description; namespace DongSuWei01.Controllers { public class HomeController : Controller { Service st=new Service(); // GET: Stu public ActionResult Index() { return View(); } public ActionResult GetAll(int fId, int flightNo, string departureAirport, string arriveAirport) {//查询所有学生的控制器 string sql = "select * from stuInfo where 1=1"; string sql2 = "select * from stuInfo where 1=1"; if (fId != null)//模糊查询 { sql += "and departureAirport like'%" + departureAirport + "%'"; } if (flightNo != null) { sql += "and arriveAirport like'%" + arriveAirport + "%'"; } return Json(new { ciode = 0, mag = "执行成功", count = st.getAllStu(sql2).Count, data = st.getAllStu(sql) }); } public ActionResult Add(string fId, string flightNo, string departureAirport, string arriveAirport, string arriveTime, string price, string meals) {//添加控制器 string sql = "INSERT INTO flights VALUES('"+ fId + "','"+ flightNo + "','"+ departureAirport + "','"+ arriveAirport + "','"+ arriveTime + "','"+ price + "','"+meals+"')"; st.add(sql);//执行添加 return Redirect("index"); } } }
时间: 2024-02-14 21:11:12 浏览: 24
这是一个 ASP.NET MVC 的控制器代码,实现了查询和添加航班信息的功能。其中,GetAll 方法是查询所有航班信息的方法,参数包括出发机场、到达机场、航班号等条件,返回 JSON 格式的查询结果。Add 方法是添加航班信息的方法,将航班信息插入到数据库中。需要注意的是,这段代码中存在 SQL 注入的风险,应该对输入参数进行过滤和验证。
相关问题
using System.Collections.Generic;
using system.collections.generic; 是一个命名空间,它包含了许多泛型集合类,如List、Dictionary、Queue、Stack等等。这些集合类可以用来存储和操作不同类型的数据,提高了程序的灵活性和效率。在使用这些集合类时,需要在代码开头添加using system.collections.generic;语句,以便在程序中引用这个命名空间。
using system.collections.generic;
using system.collections.generic; 是一个命名空间,它包含了许多泛型集合类,如List、Dictionary、Queue、Stack等等。这些集合类可以用来存储和操作不同类型的数据,提高了程序的灵活性和效率。在使用这些集合类时,需要在代码开头添加using system.collections.generic;语句,以便在程序中引用这个命名空间。