specialitymanager.cs

来自「c#开发宝典 光盘内容。本光盘主要为书中的源程序」· CS 代码 · 共 71 行

CS
71
字号
using System;
using System.Data.OleDb;
using StudentsMIS.DataAccess;

namespace StudentsMIS.Business
{
	/// <summary>
	/// SpecialityManager 的摘要说明。
	/// </summary>
	public class SpecialityManager
	{
		public SpecialityManager()
		{
			
		}

    public int Insert(string specialityID,string specialityCollege,string specialityName)
    {
      OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Select speciality_ID From speciality Where speciality_ID=@SpecialityID");
      objCommand.Parameters.Add("@SpecialityID",specialityID);
      if(objCommand.ExecuteReader().HasRows)
      {
        CommandCloser.CloseOleDbCommand(objCommand);
        return 0;
      }
      objCommand = CommandBuilder.BuildOleDbCommand("Select speciality_name From speciality Where speciality_name=@SpecialityName And speciality_college=@SpecialityCollege");
      objCommand.Parameters.Add("@SpecialityName",specialityName);
      objCommand.Parameters.Add("@SpecialityCollege",specialityCollege);
      if(objCommand.ExecuteReader().HasRows)
      {
        CommandCloser.CloseOleDbCommand(objCommand);
        return 1;
      }
      objCommand = CommandBuilder.BuildOleDbCommand("INSERT INTO speciality(speciality_ID,speciality_name,speciality_college) VALUES(@SpecialityID,@SpecialityName,@SpecialityCollege)");
      objCommand.Parameters.Add("@SpecialityID",specialityID);
      objCommand.Parameters.Add("@SpecialityName",specialityName);
      objCommand.Parameters.Add("@SpecialityCollege",specialityCollege);
      objCommand.ExecuteNonQuery();
      CommandCloser.CloseOleDbCommand(objCommand);
      return 2;
    }

    public void Delete(string specialityID)
    {
      OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Delete From speciality Where speciality_ID=@SpecialityID");
      objCommand.Parameters.Add("@SpecialityID",specialityID);
      objCommand.ExecuteNonQuery();
      CommandCloser.CloseOleDbCommand(objCommand);
    }

    public int Update(string specialityID,string specialityCollege,string specialityName)
    {
      OleDbCommand objCommand = CommandBuilder.BuildOleDbCommand("Select speciality_name From speciality Where speciality_name=@SpecialityName And speciality_college=@SpecialityCollege");
      objCommand.Parameters.Add("@SpecialityName",specialityName);
      objCommand.Parameters.Add("@SpecialityCollege",specialityCollege);
      if(objCommand.ExecuteReader().HasRows)
      {
        CommandCloser.CloseOleDbCommand(objCommand);
        return 0;
      }
      objCommand = CommandBuilder.BuildOleDbCommand("Update speciality Set speciality_name=@SpecialityName,speciality_college=@SpecialityCollege Where speciality_ID=@SpecialityID");
      objCommand.Parameters.Add("@SpecialityName",specialityName);
      objCommand.Parameters.Add("@SpecialityCollege",specialityCollege);
      objCommand.Parameters.Add("@SpecialityID",specialityID);
      objCommand.ExecuteNonQuery();
      CommandCloser.CloseOleDbCommand(objCommand);
      return 1;
    }
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?