📄 jiandaservices.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using ExamModel.Auto_Generated_Code;
namespace ExamDAL.Auto_Generated_Code
{
public class JiandaServices
{
//添加填空题
public static int AddJiandaProblem(Jianda jdPro)
{
string sql = "insert into Jianda (CourseID,Title,Answer)" +
"values(@courseId,@Title,@answer)";
try
{
OleDbParameter[] pare = new OleDbParameter[]
{
new OleDbParameter("@courseId",jdPro.JCourse.CID),//FK
new OleDbParameter("@Title",jdPro.JTitle),
new OleDbParameter("@answer",jdPro.Janswer)
};
return DBHelp.ExecuteCommand(sql, pare);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//更新简答题
public static bool UpdateJiandaProblem(Jianda jdPro)
{
try
{
string sql1 = "update Jianda set CourseID=" + jdPro.JCourse.CID + ",Title='" + jdPro.JTitle + "',Answer='" + jdPro.Janswer + "' where JiandaID=" + jdPro.JiandaID;
DBHelp.ExecuteCommand(sql1);
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//通过ID删除
public static bool DeleteJiandaById(int jdProid)
{
try
{
string sql = "Delete from Jianda where JiandaID=" + jdProid;
DBHelp.ExecuteCommand(sql);
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
//通过ID获得所有简答题
public static DataTable GetAllJiandaProblemId(string id)
{
string OleDb = "select JiandaID from Jianda where CourseID=" + id.ToString();
DataSet ds = DBHelp.GetDataSet(OleDb);
return ds.Tables[0];
}
//获得所有简答题列表
public static IList<Jianda> GetJudgeProblemByOleDb(string values, string id)
{
List<Jianda> list = new List<Jianda>();
string oleDb = "select * from Jianda where JiandaID in (" + values + ") and CourseID=" + id;
using (DataSet ds = DBHelp.GetDataSet(oleDb))
{
foreach (DataRow row in ds.Tables[0].Rows)
{
Jianda jianda = new Jianda();
jianda.JiandaID = (int)row["JiandaID"];
jianda.JCourse = CourseService.GetCourseById((int)row["CourseID"]);
jianda.JTitle = (string)row["Title"];
jianda.Janswer = (string)row["Answer"];
list.Add(jianda);
}
return list;
}
}
//通过科目名查询简答题题目
public static DataSet GetJiandaByCourseName(Course course)
{
string sql = "select * from Jianda where CourseID=" + course.CID;
return DBHelp.GetDataSet(sql);
}
//通过ID获得科目对象
public static Jianda GetJiandaproblemById(int jdId)
{
string sql = "select * from Jianda where JiandaID=" + jdId;
int courseId;
try
{
OleDbDataReader reader = DBHelp.GetReader(sql);
if (reader.Read())
{
Jianda jd = new Jianda();
jd.JiandaID = (int)reader["JiandaID"];
jd.JTitle = (string)reader["Title"];
jd.Janswer = (string)reader["Answer"];
courseId = (int)reader["CourseID"];//FK
reader.Close();
jd.JCourse = CourseService.GetCourseById(courseId);
return jd;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -