public override ActionResult Info(int id) { bool result = false; Model.ExamTable model = exam.GetModel(id); if (model != null) { result = true; } if (result) { return(this.Json(new { result = 1, data = model }, JsonRequestBehavior.AllowGet)); } else { return(this.Json(new { result = 0, msg = "请求条目不存在" })); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.ExamTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ExamTable set "); strSql.Append("Teacher=@Teacher,"); strSql.Append("Major=@Major,"); strSql.Append("Start=@Start,"); strSql.Append("Last=@Last,"); strSql.Append("Filepath=@Filepath,"); strSql.Append("Nowstate=@Nowstate"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Teacher", SqlDbType.VarChar, 50), new SqlParameter("@Major", SqlDbType.NVarChar, 50), new SqlParameter("@Start", SqlDbType.VarChar, 50), new SqlParameter("@Last", SqlDbType.Int, 4), new SqlParameter("@Filepath", SqlDbType.NVarChar, 50), new SqlParameter("@Nowstate", SqlDbType.NVarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Teacher; parameters[1].Value = model.Major; parameters[2].Value = model.Start; parameters[3].Value = model.Last; parameters[4].Value = model.Filepath; parameters[5].Value = model.Nowstate; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public ActionResult Start(Model.ExamTable model) { bool result = false; if (!String.IsNullOrEmpty(model.Teacher) && !String.IsNullOrEmpty(model.Major)) { model.Nowstate = "已开启"; result = exam.Update(model); if (result) { result = true; } } if (result) { return(this.Json(new { result = 1, data = "" })); } else { return(this.Json(new { result = 0, msg = "开启失败" })); } }
public ActionResult Create(Model.ExamTable model) { bool result = false; if (!String.IsNullOrEmpty(model.Teacher) && !String.IsNullOrEmpty(model.Major)) { BLL.ExamTable exam = new BLL.ExamTable(); model.Nowstate = "未开启"; var state = exam.Add(model); if (state != 0) { result = true; } } if (result) { return(this.Json(new { result = 1, data = "" })); } else { return(this.Json(new { result = 0, msg = "新建失败" })); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.ExamTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ExamTable("); strSql.Append("Teacher,Major,Start,Last,Filepath,Nowstate)"); strSql.Append(" values ("); strSql.Append("@Teacher,@Major,@Start,@Last,@Filepath,@Nowstate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Teacher", SqlDbType.VarChar, 50), new SqlParameter("@Major", SqlDbType.NVarChar, 50), new SqlParameter("@Start", SqlDbType.VarChar, 50), new SqlParameter("@Last", SqlDbType.Int, 4), new SqlParameter("@Filepath", SqlDbType.NVarChar, 50), new SqlParameter("@Nowstate", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Teacher; parameters[1].Value = model.Major; parameters[2].Value = model.Start; parameters[3].Value = model.Last; parameters[4].Value = model.Filepath; parameters[5].Value = model.Nowstate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.ExamTable DataRowToModel(DataRow row) { Model.ExamTable model = new Model.ExamTable(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Teacher"] != null) { model.Teacher = row["Teacher"].ToString(); } if (row["Major"] != null) { model.Major = row["Major"].ToString(); } if (row["Start"] != null) { model.Start = row["Start"].ToString(); } if (row["Last"] != null && row["Last"].ToString() != "") { model.Last = int.Parse(row["Last"].ToString()); } if (row["Filepath"] != null) { model.Filepath = row["Filepath"].ToString(); } if (row["Nowstate"] != null) { model.Nowstate = row["Nowstate"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.ExamTable GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Teacher,Major,Start,Last,Filepath,Nowstate from ExamTable "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Model.ExamTable model = new Model.ExamTable(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.ExamTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.ExamTable model) { return(dal.Add(model)); }