📄 dtimeplan.cs
字号:
condition += " and Wednesday_Am=@Wednesday_Am_C";
cmd.Parameters.Add(new SqlParameter("@Wednesday_Am_C",searcher.WednesdayAm));
}
if(searcher.WednesdayPmIsValid)
{
condition += " and Wednesday_Pm=@Wednesday_Pm_C";
cmd.Parameters.Add(new SqlParameter("@Wednesday_Pm_C",searcher.WednesdayPm));
}
if(searcher.ThursdayAmIsValid)
{
condition += " and Thursday_Am=@Thursday_Am_C";
cmd.Parameters.Add(new SqlParameter("@Thursday_Am_C",searcher.ThursdayAm));
}
if(searcher.ThursdayPmIsValid)
{
condition += " and Thursday_Pm=@Thursday_Pm_C";
cmd.Parameters.Add(new SqlParameter("@Thursday_Pm_C",searcher.ThursdayPm));
}
if(searcher.FridayAmIsValid)
{
condition += " and Friday_Am=@Friday_Am_C";
cmd.Parameters.Add(new SqlParameter("@Friday_Am_C",searcher.FridayAm));
}
if(searcher.FridayPmIsValid)
{
condition += " and Friday_Pm=@Friday_Pm_C";
cmd.Parameters.Add(new SqlParameter("@Friday_Pm_C",searcher.FridayPm));
}
if(searcher.SaturdayAmIsValid)
{
condition += " and Saturday_Am=@Saturday_Am_C";
cmd.Parameters.Add(new SqlParameter("@Saturday_Am_C",searcher.SaturdayAm));
}
if(searcher.SaturdayPmIsValid)
{
condition += " and Saturday_Pm=@Saturday_Pm_C";
cmd.Parameters.Add(new SqlParameter("@Saturday_Pm_C",searcher.SaturdayPm));
}
if(condition != string.Empty)
{
condition=" where"+condition.Substring(4);
}
cmd.CommandText="update TimePlan set "+updateString.Substring(1)+condition;
return cmd.ExecuteNonQuery();
}
#endregion
#region 查询实体集合
/// <summary>
/// 根据查询对象构建过滤条件查询
/// </summary>
/// <param name="searcher">查询对象</param>
/// <returns>实体类对象列表</returns>
public ArrayList Select(TimePlanSearcher 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, TimePlanSearcher searcher)
{
SqlCommand cmd=connection.Command as SqlCommand;
return Select(cmd,searcher);
}
public ArrayList Select(SqlCommand command,TimePlanSearcher searcher)
{
string condition=string.Empty;
command.Parameters.Clear();
ArrayList entities = new ArrayList();
if(searcher.TimePlanIDIsValid)
{
condition += " and TimePlan_ID=@TimePlan_ID_C";
command.Parameters.Add(new SqlParameter("@TimePlan_ID_C",searcher.TimePlanID));
}
if(searcher.TimePlanNameIsValid)
{
condition += " and TimePlan_Name=@TimePlan_Name_C";
command.Parameters.Add(new SqlParameter("@TimePlan_Name_C",searcher.TimePlanName));
}
if(searcher.SundayAmIsValid)
{
condition += " and Sunday_Am=@Sunday_Am_C";
command.Parameters.Add(new SqlParameter("@Sunday_Am_C",searcher.SundayAm));
}
if(searcher.SundayPmIsValid)
{
condition += " and Sunday_Pm=@Sunday_Pm_C";
command.Parameters.Add(new SqlParameter("@Sunday_Pm_C",searcher.SundayPm));
}
if(searcher.MondayAmIsValid)
{
condition += " and Monday_Am=@Monday_Am_C";
command.Parameters.Add(new SqlParameter("@Monday_Am_C",searcher.MondayAm));
}
if(searcher.MondayPmIsValid)
{
condition += " and Monday_Pm=@Monday_Pm_C";
command.Parameters.Add(new SqlParameter("@Monday_Pm_C",searcher.MondayPm));
}
if(searcher.TuesdayAmIsValid)
{
condition += " and Tuesday_Am=@Tuesday_Am_C";
command.Parameters.Add(new SqlParameter("@Tuesday_Am_C",searcher.TuesdayAm));
}
if(searcher.TuesdayPmIsValid)
{
condition += " and Tuesday_Pm=@Tuesday_Pm_C";
command.Parameters.Add(new SqlParameter("@Tuesday_Pm_C",searcher.TuesdayPm));
}
if(searcher.WednesdayAmIsValid)
{
condition += " and Wednesday_Am=@Wednesday_Am_C";
command.Parameters.Add(new SqlParameter("@Wednesday_Am_C",searcher.WednesdayAm));
}
if(searcher.WednesdayPmIsValid)
{
condition += " and Wednesday_Pm=@Wednesday_Pm_C";
command.Parameters.Add(new SqlParameter("@Wednesday_Pm_C",searcher.WednesdayPm));
}
if(searcher.ThursdayAmIsValid)
{
condition += " and Thursday_Am=@Thursday_Am_C";
command.Parameters.Add(new SqlParameter("@Thursday_Am_C",searcher.ThursdayAm));
}
if(searcher.ThursdayPmIsValid)
{
condition += " and Thursday_Pm=@Thursday_Pm_C";
command.Parameters.Add(new SqlParameter("@Thursday_Pm_C",searcher.ThursdayPm));
}
if(searcher.FridayAmIsValid)
{
condition += " and Friday_Am=@Friday_Am_C";
command.Parameters.Add(new SqlParameter("@Friday_Am_C",searcher.FridayAm));
}
if(searcher.FridayPmIsValid)
{
condition += " and Friday_Pm=@Friday_Pm_C";
command.Parameters.Add(new SqlParameter("@Friday_Pm_C",searcher.FridayPm));
}
if(searcher.SaturdayAmIsValid)
{
condition += " and Saturday_Am=@Saturday_Am_C";
command.Parameters.Add(new SqlParameter("@Saturday_Am_C",searcher.SaturdayAm));
}
if(searcher.SaturdayPmIsValid)
{
condition += " and Saturday_Pm=@Saturday_Pm_C";
command.Parameters.Add(new SqlParameter("@Saturday_Pm_C",searcher.SaturdayPm));
}
if(condition != string.Empty)
{
condition=" where"+condition.Substring(4);
}
command.CommandText = "select * from TimePlan"+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())
{
TimePlan entity = DataReaderToEntity(dr);
entities.Add(entity);
}
}
return entities;
}
private void SetForeignKeyEntity(SqlCommand command, ref ArrayList entities)
{
//由外键获取相关实体
foreach(TimePlan entity in entities)
{
}
}
/// <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 TimePlan";
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 TimePlan";
return ExcuteSelectCommand(cmd);
}
#endregion
#region 查询单个实体
/// <summary>
/// 按主键字段查询特定实体
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>实体类对象</returns>
public TimePlan SelectSingle(object pkValue)
{
TimePlan 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 TimePlan SelectSingle(IConnection connection,object pkValue)
{
SqlCommand cmd=connection.Command as SqlCommand;
return SelectSingle(cmd,pkValue);
}
public TimePlan SelectSingle(SqlCommand command,object pkValue)
{
TimePlan entity=null;
command.Parameters.Clear();
command.CommandText = "select * from TimePlan where TimePlan_ID=@pk";
command.Parameters.Add(new SqlParameter("@pk",pkValue));
using (SqlDataReader dr = command.ExecuteReader())
{
if(dr.Read())
entity = DataReaderToEntity(dr);
}
//由外键获取相关实体
return entity;
}
#endregion
/// <summary>
/// 从DataReader中取出值生成实体对象
/// </summary>
/// <param name="searcher">查询对象</param>
/// <returns>过滤条件字符串</returns>
private TimePlan DataReaderToEntity(SqlDataReader dr)
{
TimePlan entity = new TimePlan ();
if(dr["TimePlan_ID"]!=System.DBNull.Value)
{
entity.TimePlanID=Convert.ToInt32(dr["TimePlan_ID"]);
}
if(dr["TimePlan_Name"]!=System.DBNull.Value)
{
entity.TimePlanName=dr["TimePlan_Name"].ToString();
}
if(dr["Sunday_Am"]!=System.DBNull.Value)
{
entity.SundayAm=Convert.ToBoolean(dr["Sunday_Am"]);
}
if(dr["Sunday_Pm"]!=System.DBNull.Value)
{
entity.SundayPm=Convert.ToBoolean(dr["Sunday_Pm"]);
}
if(dr["Monday_Am"]!=System.DBNull.Value)
{
entity.MondayAm=Convert.ToBoolean(dr["Monday_Am"]);
}
if(dr["Monday_Pm"]!=System.DBNull.Value)
{
entity.MondayPm=Convert.ToBoolean(dr["Monday_Pm"]);
}
if(dr["Tuesday_Am"]!=System.DBNull.Value)
{
entity.TuesdayAm=Convert.ToBoolean(dr["Tuesday_Am"]);
}
if(dr["Tuesday_Pm"]!=System.DBNull.Value)
{
entity.TuesdayPm=Convert.ToBoolean(dr["Tuesday_Pm"]);
}
if(dr["Wednesday_Am"]!=System.DBNull.Value)
{
entity.WednesdayAm=Convert.ToBoolean(dr["Wednesday_Am"]);
}
if(dr["Wednesday_Pm"]!=System.DBNull.Value)
{
entity.WednesdayPm=Convert.ToBoolean(dr["Wednesday_Pm"]);
}
if(dr["Thursday_Am"]!=System.DBNull.Value)
{
entity.ThursdayAm=Convert.ToBoolean(dr["Thursday_Am"]);
}
if(dr["Thursday_Pm"]!=System.DBNull.Value)
{
entity.ThursdayPm=Convert.ToBoolean(dr["Thursday_Pm"]);
}
if(dr["Friday_Am"]!=System.DBNull.Value)
{
entity.FridayAm=Convert.ToBoolean(dr["Friday_Am"]);
}
if(dr["Friday_Pm"]!=System.DBNull.Value)
{
entity.FridayPm=Convert.ToBoolean(dr["Friday_Pm"]);
}
if(dr["Saturday_Am"]!=System.DBNull.Value)
{
entity.SaturdayAm=Convert.ToBoolean(dr["Saturday_Am"]);
}
if(dr["Saturday_Pm"]!=System.DBNull.Value)
{
entity.SaturdayPm=Convert.ToBoolean(dr["Saturday_Pm"]);
}
return entity;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -