private DeptInfo BuildEntity() { DeptInfo dept = new DeptInfo(); dept.ID = GetFormInteger("id", -1); dept.Name = Request.Form["name"]; return dept; }
public static bool Save(DeptInfo dept) { bool success = false; if (DeptDao.Exist(dept.ID)) { success = DeptDao.Update(dept); } else { success = DeptDao.Add(dept); } return success; }
public static bool Add(DeptInfo dept) { SqlParameter[] parameters = new SqlParameter[4]; parameters[0] = new SqlParameter("@ID", SqlDbType.Int); parameters[0].Value = dept.ID; parameters[1] = new SqlParameter("@Name", SqlDbType.VarChar, 50); parameters[1].Value = dept.Name; parameters[2] = new SqlParameter("@UpID", SqlDbType.Int); parameters[2].Value = dept.UpID; parameters[3] = new SqlParameter("@Level", SqlDbType.Int); parameters[3].Value = dept.Level; StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO DeptInfo (deptId, deptName, upID, [level])"); sql.AppendLine("VALUES (@ID, @Name, @UpID, @Level)"); int rowCount = helper.ExecuteNonQuery(sql.ToString(), parameters.ToArray()); return rowCount > 0; }
public static bool Update(DeptInfo dept) { SqlParameter[] parameters = new SqlParameter[4]; parameters[0] = new SqlParameter("@ID", SqlDbType.Int); parameters[0].Value = dept.ID; parameters[1] = new SqlParameter("@Name", SqlDbType.VarChar, 50); parameters[1].Value = dept.Name; parameters[2] = new SqlParameter("@UpID", SqlDbType.Int); parameters[2].Value = dept.UpID; parameters[3] = new SqlParameter("@Level", SqlDbType.Int); parameters[3].Value = dept.Level; StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE DeptInfo SET deptName = @Name, upID = @UpID, [level] = @Level"); sql.AppendLine("WHERE deptId = @ID"); int rowCount = helper.ExecuteNonQuery(sql.ToString(), parameters.ToArray()); return rowCount > 0; }