punishmenttypemanager.cs
来自「c#开发宝典 光盘内容。本光盘主要为书中的源程序」· CS 代码 · 共 67 行
CS
67 行
using System;
using System.Data.OleDb;
using StudentsMIS.DataAccess;
namespace StudentsMIS.Business
{
/// <summary>
/// PunishmentTypeManager实现了对PunishmentTypes表的增、删、改。
/// </summary>
public class PunishmentTypeManager
{
public PunishmentTypeManager()
{
}
public int Insert(string id,string type)
{
OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Select * From punishmentTypes Where punishmentType_ID=@PunishmentTypeID");
objCommand.Parameters.Add("@PunishmentTypeID",id);
if(objCommand.ExecuteReader().HasRows)
{
CommandCloser.CloseOleDbCommand(objCommand);
return 0;
}
objCommand = CommandBuilder.BuildOleDbCommand("Select * From punishmentTypes Where punishmentType_name=@PunishmentTypeName");
objCommand.Parameters.Add("@PunishmentTypeName",type);
if(objCommand.ExecuteReader().HasRows)
{
CommandCloser.CloseOleDbCommand(objCommand);
return 1;
}
objCommand = CommandBuilder.BuildOleDbCommand("Insert Into punishmentTypes(punishmentType_ID,punishmentType_name) Values(@PunishmentTypeID,@PunishmentTypeName)");
objCommand.Parameters.Add("@PunishmentTypeID",id);
objCommand.Parameters.Add("@PunishmentTypeName",type);
objCommand.ExecuteNonQuery();
CommandCloser.CloseOleDbCommand(objCommand);
return 2;
}
public void Delete(string id)
{
OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Delete From punishmentTypes Where punishmentType_ID=@PunishmentTypeID");
objCommand.Parameters.Add("@PunishmentTypeID",id);
objCommand.ExecuteNonQuery();
CommandCloser.CloseOleDbCommand(objCommand);
}
public int Update(string id,string type)
{
OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Select * From punishmentTypes Where punishmentType_name=@PunishmentTypeName");
objCommand.Parameters.Add("@PunishmentTypeName",type);
if(objCommand.ExecuteReader().HasRows)
{
CommandCloser.CloseOleDbCommand(objCommand);
return 0;
}
objCommand = CommandBuilder.BuildOleDbCommand("Update punishmentTypes Set punishmentType_name=@PunishmentTypeName Where punishmentType_ID=@PunishmentTypeID");
objCommand.Parameters.Add("@PunishmentTypeName",type);
objCommand.Parameters.Add("@PunishmentTypeID",id);
objCommand.ExecuteNonQuery();
CommandCloser.CloseOleDbCommand(objCommand);
return 1;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?