/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.TeacherTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TeacherTable set "); strSql.Append("Username=@Username,"); strSql.Append("Password=@Password,"); strSql.Append("Name=@Name,"); strSql.Append("Sex=@Sex"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@Username", SqlDbType.VarChar, 50), new SqlParameter("@Password", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Sex", SqlDbType.NVarChar, 50), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.Username; parameters[1].Value = model.Password; parameters[2].Value = model.Name; parameters[3].Value = model.Sex; parameters[4].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.TeacherTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TeacherTable("); strSql.Append("Username,Password,Name,Sex)"); strSql.Append(" values ("); strSql.Append("@Username,@Password,@Name,@Sex)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Username", SqlDbType.VarChar, 50), new SqlParameter("@Password", SqlDbType.VarChar, 50), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Sex", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Username; parameters[1].Value = model.Password; parameters[2].Value = model.Name; parameters[3].Value = model.Sex; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.TeacherTable DataRowToModel(DataRow row) { Model.TeacherTable model = new Model.TeacherTable(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["Username"] != null) { model.Username = row["Username"].ToString(); } if (row["Password"] != null) { model.Password = row["Password"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Sex"] != null) { model.Sex = row["Sex"].ToString(); } } return(model); }
public override ActionResult Info(int id) { bool result = false; Model.TeacherTable model = teacher.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 = "请求条目不存在" })); } }
public ActionResult Create(Model.TeacherTable model) { bool result = false; if (!String.IsNullOrEmpty(model.Username) && !String.IsNullOrEmpty(model.Password) && !String.IsNullOrEmpty(model.Name)) { model.Password = encryptPwd(model.Password); var state = teacher.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 Model.TeacherTable GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,Username,Password,Name,Sex from TeacherTable "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Model.TeacherTable model = new Model.TeacherTable(); 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.TeacherTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.TeacherTable model) { return(dal.Add(model)); }