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

📄 autocourse.aspx.cs

📁 guan yu pai ke xi tong de ruan jian
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Y2T03.CourseScheduler.CourseBLL;
using Y2T03.CourseScheduler.CourseModel;

public partial class AutoCourse : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ListItem item = new ListItem("所有班级", "0");
            this.ddlGetNormalClasses.DataSource = this.odsGetNormalClasses; //设置数据源为 对象(查询所有状态为 0 的班级)
            this.ddlGetNormalClasses.DataBind();    //绑定数据源
            this.ddlGetNormalClasses.Items.Insert(0, item); //在第一列插入 "所有班级" ;
            this.ddlGetNormalClasses.AutoPostBack = true;   //设置数据回发 (如果要根据Dropdownlist进行查询,则必须设置为 True)

            IList<WeekCourse> list = AutoCourseBLL.GetWeekCourses();
            this.grvAutoCourse.DataSource = list;   //设置数据源
            this.grvAutoCourse.DataBind();  //绑定数据源
        }
        else if (this.ddlGetNormalClasses.SelectedIndex == 0)
        {
            IList<WeekCourse> list = AutoCourseBLL.GetWeekCourses();
            this.grvAutoCourse.DataSource = list;
            this.grvAutoCourse.DataBind();
        }
        else
        {
            this.grvAutoCourse.DataSource = this.odsGetWeekCoursesByClassCode;
            this.grvAutoCourse.DataBind();
        }
    }

    /// <summary>
    /// 弹出操作结果
    /// </summary>
    /// <param name="message">弹出对话框信息内容</param>
    protected void PopupMessage(string message)
    {
        try
        {
            ClientScriptManager csm = this.Page.ClientScript;   // 获取管理客户端脚本的方法
            Type type = this.GetType();     // 获取类型
            string csKey = "PopupMessage";  // 设置消息

            //
            // 判断是否已经注册了启动脚本
            //
            if (!csm.IsStartupScriptRegistered(type, csKey))
            {
                string script = string.Format("alert('{0}');", message);    //格式化输出弹出消息的内容
                csm.RegisterStartupScript(type, csKey, script, true);   //注册启动脚本
            }
        }
        catch (Exception ex)
        {
            string err = ex.Message;
        }
    }
    /// <summary>
    /// 鼠标指到行的时候设置其颜色
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grvAutoCourse_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='#00BFFF'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");
            }

        }
        catch (Exception ex)
        {
            string err = ex.Message;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void trvAutoCourse_SelectedNodeChanged(object sender, EventArgs e)
    {
        try
        {
            int node = int.Parse(this.trvAutoCourse.SelectedValue.ToString());
            //排课
            if (node == 0)
            {
                this.grvAutoCourse.Columns.Clear();

                IList<WeekCourse> list = AutoCourseBLL.GetCommonWeekCourse();

                if (list[list.Count - 1].ClassRoom.RoomId == 0)
                {
                    PopupMessage("教室不足,还有班级尚未排课!!!");
                }

                this.grvAutoCourse.DataSource = list;
                this.grvAutoCourse.DataBind();
            }
            if (node == 1)
            {
                PopupMessage("此功能尚没完善,不能操作!");
            }
            if (node == 2)
            {
                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "GB2312";
                Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
                //gaoyang [10/21/2006] 经测试如果设置为 GetEncoding("GB2312"),导出的文件将会出现乱码。
                Response.ContentEncoding = System.Text.Encoding.UTF8;

                //设置输出文件类型为excel文件。 
                Response.ContentType = "application/ms-excel";
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                this.grvAutoCourse.RenderControl(oHtmlTextWriter);/////
                Response.Output.Write(oStringWriter.ToString());
                Response.Flush();
                Response.End();
            }
        }
        catch (Exception ex)
        {
            string err = ex.Message;
        }
    }
    /// <summary>
    /// 在EXCEL导出的时候必须重写该方法
    /// </summary>
    /// <param name="control"></param>
    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
}

⌨️ 快捷键说明

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