/// <summary> /// 更新一条数据 /// </summary> public bool Update(OnLineTest.Model.LogTest model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update LogTest set "); strSql.Append("UserId=@UserId,"); strSql.Append("LogTestStartTime=@LogTestStartTime,"); strSql.Append("LogTestEndTime=@LogTestEndTime,"); strSql.Append("PaperCodeId=@PaperCodeId,"); strSql.Append("DifficultyId=@DifficultyId,"); strSql.Append("LogTestScore=@LogTestScore"); strSql.Append(" where LogTestId=@LogTestId"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@LogTestStartTime", SqlDbType.DateTime), new SqlParameter("@LogTestEndTime", SqlDbType.DateTime), new SqlParameter("@PaperCodeId", SqlDbType.Int, 4), new SqlParameter("@DifficultyId", SqlDbType.Int, 4), new SqlParameter("@LogTestScore", SqlDbType.Int, 4), new SqlParameter("@LogTestId", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.LogTestStartTime; parameters[2].Value = model.LogTestEndTime; parameters[3].Value = model.PaperCodeId; parameters[4].Value = model.DifficultyId; parameters[5].Value = model.LogTestScore; parameters[6].Value = model.LogTestId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public OnLineTest.Model.LogTest DataRowToModel(DataRow row) { OnLineTest.Model.LogTest model = new OnLineTest.Model.LogTest(); if (row != null) { if (row["LogTestId"] != null && row["LogTestId"].ToString() != "") { model.LogTestId = int.Parse(row["LogTestId"].ToString()); } if (row["UserId"] != null && row["UserId"].ToString() != "") { model.UserId = int.Parse(row["UserId"].ToString()); } if (row["LogTestStartTime"] != null && row["LogTestStartTime"].ToString() != "") { model.LogTestStartTime = DateTime.Parse(row["LogTestStartTime"].ToString()); } if (row["LogTestEndTime"] != null && row["LogTestEndTime"].ToString() != "") { model.LogTestEndTime = DateTime.Parse(row["LogTestEndTime"].ToString()); } if (row["PaperCodeId"] != null && row["PaperCodeId"].ToString() != "") { model.PaperCodeId = int.Parse(row["PaperCodeId"].ToString()); } if (row["DifficultyId"] != null && row["DifficultyId"].ToString() != "") { model.DifficultyId = int.Parse(row["DifficultyId"].ToString()); } if (row["LogTestScore"] != null && row["LogTestScore"].ToString() != "") { model.LogTestScore = int.Parse(row["LogTestScore"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(OnLineTest.Model.LogTest model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into LogTest("); strSql.Append("UserId,LogTestStartTime,LogTestEndTime,PaperCodeId,DifficultyId,LogTestScore)"); strSql.Append(" values ("); strSql.Append("@UserId,@LogTestStartTime,@LogTestEndTime,@PaperCodeId,@DifficultyId,@LogTestScore)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@LogTestStartTime", SqlDbType.DateTime), new SqlParameter("@LogTestEndTime", SqlDbType.DateTime), new SqlParameter("@PaperCodeId", SqlDbType.Int, 4), new SqlParameter("@DifficultyId", SqlDbType.Int, 4), new SqlParameter("@LogTestScore", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.LogTestStartTime; parameters[2].Value = model.LogTestEndTime; parameters[3].Value = model.PaperCodeId; parameters[4].Value = model.DifficultyId; parameters[5].Value = model.LogTestScore; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public OnLineTest.Model.LogTest GetModel(int LogTestId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 LogTestId,UserId,LogTestStartTime,LogTestEndTime,PaperCodeId,DifficultyId,LogTestScore from LogTest "); strSql.Append(" where LogTestId=@LogTestId"); SqlParameter[] parameters = { new SqlParameter("@LogTestId", SqlDbType.Int, 4) }; parameters[0].Value = LogTestId; OnLineTest.Model.LogTest model = new OnLineTest.Model.LogTest(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }