📄 teacher_course.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 System.Data.SqlClient;
using jianke;
public partial class teacher_course : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Course_Bind();
Teacher_Bind();
}
}
public void Course_Bind()
{
SqlConnection Conn = DB.creatconnection();
Conn.Open();
SqlCommand cmd = new SqlCommand("select course_name,course_id from Course", Conn);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList1.DataSource = sdr;
this.DropDownList1.DataTextField = "course_name";
this.DropDownList1.DataValueField = "course_id";
this.DropDownList1.DataBind();
sdr.Close();
Conn.Close();
}
public void Teacher_Bind()
{
SqlConnection Conn = DB.creatconnection();
Conn.Open();
SqlCommand cmd = new SqlCommand("select teacher_name,teacher_id from Teacher", Conn);
SqlDataReader sdr = cmd.ExecuteReader();
this.DropDownList2.DataSource = sdr;
this.DropDownList2.DataTextField = "teacher_name";
this.DropDownList2.DataValueField = "teacher_id";
this.DropDownList2.DataBind();
sdr.Close();
Conn.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection Conn = DB.creatconnection();
Conn.Open();
Random rnd = new Random(); //随机函数
loop: int a = 1 + rnd.Next(6);
int b = 1 + rnd.Next(4);
int c = 1 + rnd.Next(3);
int d = 1 + rnd.Next(5);
int l = a * 1000 + b * 100 + c* 10 + d;
string Location = l.ToString(); // 上课地点
int w= 1 + rnd.Next(5);
string Week= "周"+w.ToString(); //上课周次
int t=1 + rnd.Next(5);
string Time=""; //上课时间
switch(t)
{
case 1:
Time="8:00-9:50";
break;
case 2 :
Time="10:10-12:00";
break;
case 3:
Time="15:00-16:50";
break;
case 4 :
Time="17:10-19:00";
break;
case 5:
Time="20:00-22:00";
break;
}
string tr = "Select * from Class where class_week=' " + Week + " ' and class_location='" + Location + "' and class_time= '" + Time+ "' ";
SqlCommand com= new SqlCommand(tr, Conn);
SqlDataReader dr = com.ExecuteReader();
if (!dr.Read())
{
dr.Close();
string s = " insert into Class(course_id,course_name,teacher_id,teacher_name,class_week,class_location,class_time)Values('" + this.DropDownList1.SelectedValue + " ','" + this.DropDownList1.SelectedItem.Text + " ','" + this.DropDownList2.SelectedValue + "','" + this.DropDownList2.SelectedItem.Text + "' , '" + Week + " ', '" + Location + "','" + Time + "' )";
SqlCommand cmd = new SqlCommand(s, Conn);
cmd.ExecuteNonQuery();
Conn.Close();
}
else
goto loop;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -