📄 students.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace StudentLibrary.Business
{
using StudentLibrary.DataAccess;
public class Students
{
private DataBaseOperate cDbObject = null;
private bool bConn = false;
public Students()
{
cDbObject = new DataBaseOperate();
bConn = false;
}
public Students(DataBaseOperate dbOperate)
{
cDbObject = dbOperate;
bConn = true;
}
public bool UpdateStudent(
int iStudentId,
string sStudentNo,
string sStudentName,
DateTime dBirthday,
int iGender,
int iClassId,
string sRemark)
{
string sSql =
"update Student"
+ " set"
+ " StudentNo = '" + sStudentNo + "'"
+ ",StudentName = '" + sStudentName + "'"
+ ",Birthday = '" + dBirthday.ToString() + "'"
+ ",Gender = " + iGender.ToString()
+ ",ClassId = " + iClassId.ToString()
+ ",Remark = '" + sRemark + "'"
+ " where StudentId = " + iStudentId.ToString();
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw (e);
}
return true;
}
public bool InsertStudent(
DateTime dBirthday,
int iGender,
int iClassId,
int iStatus,
string sStudentNO,
string sStudentName,
string sRemark)
{
string sSql =
"insert Student("
+ " StudentNO"
+ ",StudentName"
+ ",Gender"
+ ",Birthday"
+ ",ClassId"
+ ",Status"
+ ",Remark)"
+ " values("
+ "'" + sStudentNO + "'"
+ ",'" + sStudentName + "'"
+ "," + iGender.ToString()
+ ",'" + dBirthday.ToString() + "'"
+ "," + iClassId.ToString()
+ "," + iStatus.ToString()
+ ",'" + sRemark + "'"
+ ")";
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw e;
}
return true;
}
public DataSet SelectStudent(
int iStudentId,
string sStudentName,
string sStudentNo,
int iClassId)
{
string sSql =
"select a.*"
+ ",b.ClassName"
+ " from Student a"
+ ",Class b"
+ " where a.ClassId = b.ClassId";
if (iStudentId != -1)
{
sSql += " and a.StudentId = " + iStudentId;
}
if (sStudentName != "")
{
sSql += " and a.StudentName = '" + sStudentName + "'";
}
if (sStudentNo != "")
{
sSql += " and a.StudentNO = '" + sStudentNo + "'";
}
if (iClassId != -1)
{
sSql += " and a.ClassId = " + iClassId.ToString();
}
DataSet dataSet = new DataSet();
try
{
dataSet = cDbObject.Search(sSql, "Student");
}
catch (Exception e)
{
throw (new ApplicationException("操作数据库发生错误:" + e.Message));
}
return dataSet;
}
public bool DeleteStudent(
int iStudentId,
int iClassId)
{
string sSql =
"delete student where 1 = 1";
if (iStudentId != -1)
{
sSql += " and StudentId = " + iStudentId.ToString();
}
if (iClassId != -1)
{
sSql += " and ClassId = " + iClassId.ToString();
}
try
{
cDbObject.Execute(sSql);
}
catch (Exception e)
{
throw (new ApplicationException("操作数据库发生错误:" + e.Message));
}
return true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
public virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
if (!bConn)
{
cDbObject.CloseDataBase();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -