在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#网络编程 → .Net排课系统

.Net排课系统

C#网络编程

下载此实例
  • 开发语言:C#
  • 实例大小:4.60M
  • 下载次数:192
  • 浏览次数:1243
  • 发布时间:2017-08-19
  • 实例类别:C#网络编程
  • 发 布 人:chironn
  • 文件格式:.zip
  • 所需积分:5
 相关标签: 排课系统 自动排课 .NET

实例介绍

【实例简介】.net制作的排课系统
【实例截图】
【核心代码】using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using NPOI;
using NPOI.HSSF;
using NPOI.HPSF;
using NPOI.SS;
using NPOI.Util;
using NPOI.SS.Util;

namespace 排课系统.admin
{
    public partial class courseplan : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["username"] == null)
                {
                    WebMessageBox.Show("请登录", "../Default.aspx");
                }else

                Label1.Text = Session["username"].ToString();

                DataTable dt1 = Operation.getDatatable("select DISTINCT major from t_courseplan");
                DropDownList1.DataSource = dt1;//设置数据源
                DropDownList1.DataTextField = "major";//设置所要读取的数据表里的列名
                DropDownList1.DataBind();//数据绑定

                DataTable dt2 = Operation.getDatatable("select DISTINCT grade from t_courseplan");
                DropDownList2.DataSource = dt2;//设置数据源
                DropDownList2.DataTextField = "grade";//设置所要读取的数据表里的列名
                DropDownList2.DataBind();//数据绑定
                //绑定
                bind();
            }
        }
        public void bind()
        {
            string sqlstr = "select * from t_courseplan where (coursename like '%" this.findinfo.Text "%' OR LEN('" this.findinfo.Text "')=0) and major='"
               DropDownList1.SelectedValue.ToString() "' and grade='" DropDownList2.SelectedValue.ToString() "'";
            GridView1.DataSource = Operation.getDatatable(sqlstr);
            GridView1.DataKeyNames = new string[] { "id" };//主键
            GridView1.DataBind();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            bind();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sqlstr = "delete from t_courseplan where id='" GridView1.DataKeys[e.RowIndex].Value.ToString() "'";
            Operation.runSql(sqlstr);
            bind();
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            bind();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            float ss;
            if (!float.TryParse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim(), out ss))
            {
                WebMessageBox.Show("请输入有效学分"); return;
            }
            int tt;
            if (!int.TryParse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim(), out tt))
            {
                WebMessageBox.Show("请输入有效总学时"); return;
            }
            int tt1;
            if (!int.TryParse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim(), out tt1))
            {
                WebMessageBox.Show("请输入有效讲授学时"); return;
            }
            int tt2;
            if (!int.TryParse(((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim(), out tt2))
            {
                WebMessageBox.Show("请输入有效实验学时"); return;
            }
            if (tt1 tt2 > tt)
            {
                WebMessageBox.Show("总学时需要大于讲授学时与实验学时之和"); return;
            }
            Operation.runSql("update t_courseplan set coursename='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim()
                "',khtype='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()
                "',score='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim()
                "',xueshiall='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim()
                "',xueshijiangshou='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim()
                "',xueshishiyan='" ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim()
                "' where id='" GridView1.DataKeys[e.RowIndex].Value.ToString() "'");
            GridView1.EditIndex = -1;
            bind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            bind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            //重新绑定 
            bind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //新增
            Response.Redirect("courseplanadd.aspx");
        }


        protected void Button2_Click(object sender, EventArgs e)
        {
                //导入
                if (FileUpload1.FileName.Length < 1)
                {
                    WebMessageBox.Show("请选择规范化excel文件"); return;
                }
                if (Path.GetExtension(FileUpload1.FileName).ToLower() != ".xls" && Path.GetExtension(FileUpload1.FileName).ToLower() != ".xlsx")
                {
                    WebMessageBox.Show("请选择规范化excel文件"); return;
                }

                IWorkbook workbook = null; FileStream fs = null;
                ISheet sheet = null;

                string filepath =Server.MapPath("~//upload//") FileUpload1.FileName;  //Server.MapPath("~//upload//")
                if (File.Exists(filepath))
                    File.Delete(filepath);
                FileUpload1.SaveAs(filepath);

                fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);//new FileStream(fileName, FileMode.Open, FileAccess.Read);
                if (Path.GetExtension(filepath).ToLower() == ".xlsx") // 2007版本
                    workbook = new XSSFWorkbook(fs);
                else if (Path.GetExtension(filepath).ToLower() == ".xls") // 2003版本
                    workbook = new HSSFWorkbook(fs);
                if (workbook == null)
                {
                    WebMessageBox.Show("导入excel文件失败"); return;
                }
                sheet = workbook.GetSheetAt(0);  // 读取sheet
                int count = 0;
                if (sheet != null)
                {
                    string major = "", grade = "", nums = "", temp;  // 记录当前的专业 年级 专业人数
                    //最后一列的标号
                    int rowCount = sheet.LastRowNum; // 行数
                    //WebMessageBox.Show(rowCount.ToString());
                    for (int i = 0; i <= rowCount; i)
                    {
                        IRow row = sheet.GetRow(i);
                        if (row == null) continue; //没有数据的行默认是null       
                        
                        int cellCount = row.LastCellNum;
                        if (cellCount < 1) continue; //没有数据的行默认是null 
                        if (row.GetCell(0) == null) continue; //没有数据的行默认是null

                        temp = row.GetCell(0).ToString();
                        if (temp.IndexOf("专业") >= 0 && temp.IndexOf("级") >= 0 && temp.IndexOf("人数") >= 0)
                        {
                            //WebMessageBox.Show(temp);
                            // 新专业 更新
                            grade = temp.Substring(0, temp.IndexOf("级")).Trim();
                            //temp.Remove(0, temp.IndexOf(":") 1);
                            major = temp.Substring(temp.IndexOf("级") 2, temp.IndexOf("专业") - temp.IndexOf("级") -2).Trim();
                            //temp = temp.Substring(temp.IndexOf("人数") 1);
                            nums = temp.Substring(temp.IndexOf("人数") 3).Trim();
                        }
                        else
                        {
                            // 如果是数据行 则开始判断
                            if (major == "" || grade == "") continue;
                            if (temp.IndexOf("课程") >= 0 || temp.IndexOf("代码") >= 0)
                            {
                                //这里新数据库 专业数据表
                                if (Operation.getDatatable("select * from t_major where name='" major "'").Rows.Count < 1)
                                {
                                    int tt = 0;
                                    int.TryParse(nums, out tt);
                                    Operation.runSql("insert into t_major(name,remark,nums) values('" major "','" major "','" tt.ToString() "')");
                                }
                            }
                            else
                            {
                                // 教学计划数据
                                if (cellCount < 9) continue;
                                string sql = "select * from t_courseplan where major='" major "' and grade='" grade "' and courseid='" temp.Trim() "'";
                                if (Operation.getDatatable(sql).Rows.Count > 0)
                                    continue;
                                sql = "insert into t_courseplan(courseid,coursename,khtype,score,xueshiall,xueshijiangshou,xueshishiyan,major,grade) values('"
                                row.GetCell(0).ToString() "','" row.GetCell(1).ToString() "','" row.GetCell(2).ToString() "','" row.GetCell(3).ToString() "','"
                                row.GetCell(4).ToString() "','" row.GetCell(5).ToString() "','" row.GetCell(6).ToString() "','" major "','" grade "')";
                                Operation.runSql(sql);
                                count ;
                            }
                        }
                    }
                    WebMessageBox.Show("导入完成,成功导入数据记录共" count "条","courseplan.aspx");
                }
                else
                {
                    WebMessageBox.Show("excel表没有数据");
                }

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

实例下载地址

.Net排课系统

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 梦溪浮萍 发表于: 2019-11-09 11:15 04
点击自动排课为什么没变化

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警