📄 dcourseteacherchanging.cs
字号:
/// <param name="newValues">要更新的新值</param>
/// <returns>影响的记录行数</returns>
public int Update(IConnection connection, CourseTeacherChangingSearcher searcher, CourseTeacherChangingSearcher newValues)
{
string updateString = string.Empty;
string condition = string.Empty;
SqlCommand cmd = connection.Command as SqlCommand;
cmd.Parameters.Clear();
if (newValues.TeachPlanIDIsValid)
{
updateString += ",TeachPlan_ID=@TeachPlan_ID_V";
cmd.Parameters.Add(new SqlParameter("@TeachPlan_ID_V", newValues.TeachPlanID));
}
if (newValues.TeacherIDIsValid)
{
updateString += ",Teacher_ID=@Teacher_ID_V";
cmd.Parameters.Add(new SqlParameter("@Teacher_ID_V", newValues.TeacherID));
}
if (newValues.InureDateIsValid)
{
updateString += ",Inure_Date=@Inure_Date_V";
cmd.Parameters.Add(new SqlParameter("@Inure_Date_V", newValues.InureDate));
}
if (searcher.TeachPlanIDIsValid)
{
condition += " and TeachPlan_ID=@TeachPlan_ID_C";
cmd.Parameters.Add(new SqlParameter("@TeachPlan_ID_C", searcher.TeachPlanID));
}
if (searcher.TeacherIDIsValid)
{
condition += " and Teacher_ID=@Teacher_ID_C";
cmd.Parameters.Add(new SqlParameter("@Teacher_ID_C", searcher.TeacherID));
}
if (searcher.InureDateIsValid)
{
condition += " and Inure_Date=@Inure_Date_C";
cmd.Parameters.Add(new SqlParameter("@Inure_Date_C", searcher.InureDate));
}
if (condition != string.Empty)
{
condition = " where" + condition.Substring(4);
}
cmd.CommandText = "update CourseTeacherChanging set " + updateString.Substring(1) + condition;
return cmd.ExecuteNonQuery();
}
#endregion
#region 查询实体集合
/// <summary>
/// 根据查询对象构建过滤条件查询
/// </summary>
/// <param name="searcher">查询对象</param>
/// <returns>实体类对象列表</returns>
public ArrayList Select(CourseTeacherChangingSearcher searcher)
{
ArrayList entities = new ArrayList();
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
entities = Select(cmd, searcher);
}
}
return entities;
}
/// <summary>
/// 使用事务并且依据查询对象构建过滤条件查询
/// </summary>
/// <param name="connection">实现共享Command的对象</param>
/// <param name="searcher">查询对象</param>
/// <returns>实体类对象列表</returns>
public ArrayList Select(IConnection connection, CourseTeacherChangingSearcher searcher)
{
SqlCommand cmd = connection.Command as SqlCommand;
return Select(cmd, searcher);
}
public ArrayList Select(SqlCommand command, CourseTeacherChangingSearcher searcher)
{
string condition = string.Empty;
command.Parameters.Clear();
ArrayList entities = new ArrayList();
if (searcher.TeachPlanIDIsValid)
{
condition += " and TeachPlan_ID=@TeachPlan_ID_C";
command.Parameters.Add(new SqlParameter("@TeachPlan_ID_C", searcher.TeachPlanID));
}
if (searcher.TeacherIDIsValid)
{
condition += " and Teacher_ID=@Teacher_ID_C";
command.Parameters.Add(new SqlParameter("@Teacher_ID_C", searcher.TeacherID));
}
if (searcher.InureDateIsValid)
{
condition += " and Inure_Date=@Inure_Date_C";
command.Parameters.Add(new SqlParameter("@Inure_Date_C", searcher.InureDate));
}
if (condition != string.Empty)
{
condition = " where" + condition.Substring(4);
}
command.CommandText = "select * from CourseTeacherChanging" + condition;
return ExcuteSelectCommand(command);
}
/// <summary>
/// 执行Command获取对象列表
/// </summary>
/// <param name="cmd">Command对象</param>
/// <returns>实体类对象列表</returns>
private ArrayList ExcuteSelectCommand(SqlCommand cmd)
{
ArrayList entities = new ArrayList();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
CourseTeacherChanging entity = DataReaderToEntity(dr);
entities.Add(entity);
}
}
SetForeignKeyEntity(cmd, ref entities);
return entities;
}
private void SetForeignKeyEntity(SqlCommand command, ref ArrayList entities)
{
//由外键获取相关实体
DTeachPlan dTeachPlan = new DTeachPlan();
DEmployee dEmployee = new DEmployee();
foreach (CourseTeacherChanging entity in entities)
{
entity.TeachPlan = dTeachPlan.SelectSingle(command, entity.TeachPlanID);
entity.Employee = dEmployee.SelectSingle(command, entity.TeacherID);
}
}
/// <summary>
/// 查询所有实体
/// </summary>
/// <returns>实体类对象列表</returns>
public ArrayList Select()
{
ArrayList entities = new ArrayList();
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from CourseTeacherChanging";
entities = ExcuteSelectCommand(cmd);
}
return entities;
}
}
/// <summary>
/// 使用事务查询查询所有实体
/// </summary>
/// <param name="connection">实现共享Command的对象</param>
/// <param name="searcher">查询对象</param>
/// <returns>实体类对象列表</returns>
public ArrayList Select(IConnection connection)
{
ArrayList entities = new ArrayList();
SqlCommand cmd = connection.Command as SqlCommand;
cmd.Parameters.Clear();
cmd.CommandText = "select * from CourseTeacherChanging";
return ExcuteSelectCommand(cmd);
}
#endregion
#region 查询单个实体
/// <summary>
/// 按主键字段查询特定实体
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>实体类对象</returns>
public CourseTeacherChanging SelectSingle(object pkValue)
{
CourseTeacherChanging entity = null;
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
entity = SelectSingle(cmd, pkValue);
}
}
return entity;
}
/// <summary>
/// 使用事务并按主键字段查询特定实体
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>实体类对象</returns>
public CourseTeacherChanging SelectSingle(IConnection connection, object pkValue)
{
SqlCommand cmd = connection.Command as SqlCommand;
return SelectSingle(cmd, pkValue);
}
public CourseTeacherChanging SelectSingle(SqlCommand command, object pkValue)
{
CourseTeacherChanging entity = null;
command.Parameters.Clear();
command.CommandText = "select * from CourseTeacherChanging where =@pk";
command.Parameters.Add(new SqlParameter("@pk", pkValue));
using (SqlDataReader dr = command.ExecuteReader())
{
if (dr.Read())
entity = DataReaderToEntity(dr);
}
//由外键获取相关实体
DTeachPlan dTeachPlan = new DTeachPlan();
DEmployee dEmployee = new DEmployee();
entity.TeachPlan = dTeachPlan.SelectSingle(command, entity.TeachPlanID);
entity.Employee = dEmployee.SelectSingle(command, entity.TeacherID);
return entity;
}
#endregion
/// <summary>
/// 从DataReader中取出值生成实体对象
/// </summary>
/// <param name="searcher">查询对象</param>
/// <returns>过滤条件字符串</returns>
private CourseTeacherChanging DataReaderToEntity(SqlDataReader dr)
{
CourseTeacherChanging entity = new CourseTeacherChanging();
if (dr["TeachPlan_ID"] != System.DBNull.Value)
{
entity.TeachPlanID = Convert.ToInt32(dr["TeachPlan_ID"]);
}
if (dr["Teacher_ID"] != System.DBNull.Value)
{
entity.TeacherID = Convert.ToInt32(dr["Teacher_ID"]);
}
if (dr["Inure_Date"] != System.DBNull.Value)
{
entity.InureDate = Convert.ToDateTime(dr["Inure_Date"]);
}
return entity;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -