?? subjects.cs
字號:
?using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace StudentLibrary.Business
{
using StudentLibrary.DataAccess;
public class Subjects
{
private DataBaseOperate cDbObject = null;
private bool bConn = false;
public Subjects()
{
cDbObject = new DataBaseOperate();
bConn = false;
}
public Subjects(DataBaseOperate dbOperate)
{
cDbObject = dbOperate;
bConn = true;
}
/// <summary>
/// 功能:查詢科目信息
/// 由frmNewCourse類中的GetSubject()方法調用。
/// 由frmSubject類中的GetSubject()方法調用。
/// </summary>
/// <param name="SubjectId">科目編號</param>
/// <param name="SubjectName">科目名稱</param>
/// <returns>DataSet</returns>
public DataSet SelectSubject(
int iSubjectId,
string sSubjectName)
{
string sSql = "select * from Subject where 1 = 1";
if (iSubjectId != -1)
{
sSql += " and SubjectId = " + iSubjectId.ToString();
}
if (sSubjectName != "")
{
sSql += " and SubjectName like '%" + sSubjectName + "%'";
}
DataSet dataSet = new DataSet();
try
{
dataSet = cDbObject.Search(
sSql,
"Subject");
}
catch (Exception e)
{
throw e;
}
return dataSet;
}
/// <summary>
/// 功能: 刪除科目
/// 由frmSubject窗體的DeleteSubject()調用
/// </summary>
/// <param name="iSubjectId">SubjectID</param>
/// <returns>成功返回true</returns>
public bool DeleteSubject(
int iSubjectId)
{
string sSql =
" delete Subject"
+ " where SubjectId = " + iSubjectId.ToString();
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw (e);
}
return true;
}
/// <summary>
/// 功能:新建學科
/// 由frmSubject窗體的CreateSubject()方法調用
/// </summary>
/// <param name="sSubjectName">學科名</param>
/// <param name="sRemark">備注</param>
/// <returns>成功返回true</returns>
public bool InsertSubject(
string sSubjectName,
string sRemark)
{
string sSql =
"insert Subject("
+ " SubjectName"
+ ",Remark"
+ ")"
+ " values("
+ "'" + sSubjectName + "'"
+ ",'" + sRemark + "'"
+ ")";
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw e;
}
return true;
}
/// <summary>
/// 功能:更改學科
/// 由frmSubject窗體的UpdateSuject()方法調用
/// </summary>
/// <param name="iSubjectId">學科ID</param>
/// <param name="sSubjectName">學科名</param>
/// <param name="sRemark">備注</param>
/// <returns>成功返回true</returns>
public bool UpdateSubject(
int iSubjectId,
string sSubjectName,
string sRemark)
{
string sSql =
"update Subject set"
+ " SubjectName = '" + sSubjectName + "'"
+ ",Remark = '" + sRemark + "'"
+ " where SubjectId = " + iSubjectId;
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw (e);
}
return true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
/// <summary>
/// 關閉數據庫
/// </summary>
/// <param name="disposing"></param>
public virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
if (!bConn)
{
cDbObject.CloseDataBase();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -