教务系统——班级管理——全部代码
来源:互联网 发布:obs视频录制软件 编辑:程序博客网 时间:2024/05/01 11:38
using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection();
//public void lianjie()
//{
// conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
// conn.Open();
//}
public string updateclass( string classid, string classname, string departmentname, string teacherid )
{
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
string str=null;
string sqlstr = "update TS_class set TS_Class_name=@classname,TS_Class_department=@departmentname,TS_Class_teacherid=@teacherid where TS_Class_id=@classid";
SqlCommand comm = new SqlCommand(sqlstr, conn);
try
{
comm.Parameters.Add(new SqlParameter("@classid", SqlDbType.VarChar, 50));
comm.Parameters.Add(new SqlParameter("@classname", SqlDbType.VarChar, 50));
comm.Parameters.Add(new SqlParameter("@departmentname", SqlDbType.VarChar , 50));
comm.Parameters.Add(new SqlParameter("@teacherid", SqlDbType.VarChar , 50));
comm.Parameters["@classid"].Value = classid;
comm.Parameters["@classname"].Value =classname ;
comm.Parameters["@departmentname"].Value = departmentname ;
comm.Parameters["@teacherid"].Value =teacherid ;
//comm.Connection.Open();
comm.ExecuteNonQuery();
str = "更新成功";
}
catch (Exception ex)
{
str = ex.Message;
}
comm.Connection.Close();
return str;
}
public DataSet Query(string selectstr)
{
DataSet ds = new DataSet();
try
{
SqlDataAdapter adp = new SqlDataAdapter(selectstr, conn);
adp.Fill(ds);
}
catch (Exception)
{
}
return ds;
}
public int NonQuery(string sqlstr)
{
int i = -1;
SqlCommand comm = new SqlCommand(sqlstr, conn);
//comm.Connection.Open();
try
{
i = comm.ExecuteNonQuery();
}
catch (Exception)
{
}
comm.Connection.Close();
return i;
}
public void TS_BindGrid()
{
//lianjie();
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
string sqlstr = "select * from TS_class";
DataSet ds = Query(sqlstr);
conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = (int)e.NewEditIndex;
TS_BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//lianjie();
string classid = GridView1.DataKeys[(int)e.RowIndex].Value.ToString();
string classname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string departmentname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string teacherid = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string str = updateclass( classid , classname, departmentname, teacherid);
conn.Close();
Label2.Text = str;
GridView1.EditIndex = -1;
TS_BindGrid();
}
protected void Button1_Click(object sender, EventArgs e)
{
//lianjie();
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select TS_Class_id,TS_Class_name,TS_department_name,TS_Teacher_name from TS_class,TS_department,TS_teacher where TS_class.TS_Class_department=TS_department.TS_department_id and TS_class.TS_Class_teacherid=TS_teacher.TS_Teacher_id and " + DropDownList1.SelectedValue + "='" + DropDownList2.Text + "'";
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
sda.Fill(ds);
conn.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//lianjie();
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select TS_Class_id,TS_Class_name,TS_department_name,TS_Teacher_name from TS_class,TS_department,TS_teacher where TS_class.TS_Class_department=TS_department.TS_department_id and TS_class.TS_Class_teacherid=TS_teacher.TS_Teacher_id";
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
sda.Fill(ds);
comm.ExecuteNonQuery();
conn.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
TS_BindGrid();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "班级")
{
DropDownList2.Items.Clear();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select TS_Class_name from TS_class ";
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
sda.Fill(ds);
conn.Close();
dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList2.Items.Add((string)(dt.Rows[i][0]));
}
}
if (DropDownList1.SelectedItem.Text == "系部")
{
DropDownList2.Items.Clear();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select distinct TS_department_name from TS_department ";
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = comm;
sda.Fill(ds);
conn.Close();
dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
DropDownList2.Items.Add((string)(dt.Rows[i][0]));
}
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
conn.ConnectionString = "Data Source=.;Initial Catalog=TeachingSystem;Integrated Security=True";
conn.Open();
string sqlstr = "delete from TS_class where TS_Class_id='" + GridView1.DataKeys[(int)e.RowIndex].Value + "'";
try
{
NonQuery(sqlstr);
Label2.Text = "删除成功!!";
}
catch (Exception ex)
{
Label2.Text = "删除失败" + ex.Message;
Label2.Style["color"] = "red";
}
conn.Close();
TS_BindGrid();
}
}
- 教务系统——班级管理——全部代码
- 经验分享——教务管理系统
- Python —爬取教务管理系统,个人成绩
- 教务系统——mysql课程设计
- 教务考试系统—监考后记
- 课程设计—班级个人信息管理系统
- 注册环节的AJAX验证———班级管理系统心得
- python爬虫——模拟登陆教务系统
- Python爬虫实战——模拟登录教务系统
- python爬虫——正方教务系统成绩查询
- 数据结构设计——班级个人信息管理系统
- 教务管理系统修复
- 教务管理系统流程图
- 教务管理系统雏形
- 简易教务管理系统
- 班级活动——看电影
- 班级管理系统
- 国庆节 班级管理系统
- 单例与static的一些讨论
- 计算机经典书籍
- [J2ME]url请求返回参数非法(java.lang.illegalArgument)
- JDK Logger指定配置文件
- memcpy 用法
- 教务系统——班级管理——全部代码
- 三年不重装:令电脑百毒不侵的13个妙招
- asterisk学习笔记8--voicemail
- 谈关于mysql中文模糊查找问题
- JAVA排序汇总
- VC编程中常使用的子函数
- openSUSE 11.2 KDE4.3下Totem无法开启音频设备的解决方法
- HGE系列之三 渐入佳境
- [Linux]GNU自动化工具(automake工具链)