⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subjects.cs

📁 大二做的课程设计。一个学生信息管理系统
💻 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 + -