📄 4部门信息管理.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;
public partial class _6部门 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
string sql = "select 部门编号 from 部门信息表";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
SqlDataReader myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
this.DropDownList1.Items.Add("");
while (myReader.Read())
{
this.DropDownList1.Items.Add(myReader.GetValue(0).ToString());
}
}
myReader.Close();
sql = "select 部门名称 from 部门信息表";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
this.DropDownList4.Items.Add("");
while (myReader.Read())
{
this.DropDownList4.Items.Add(myReader.GetValue(0).ToString());
}
}
myReader.Close();
myConn.Close();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
this.Response.Redirect("2物资信息盘点.aspx");
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
this.Response.Redirect("5职工信息管理.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
this.Response.Redirect("1首页.aspx");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
this.Response.Redirect("库存信息管理.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
string sql;
SqlCommand myComm;
SqlDataReader myReader;
if (this.DropDownList1.Text != "" || this.DropDownList4.Text != "")
{
myConn.Open();
if (this.DropDownList1.Text != "")
{
string bumenbianhao="" ;
sql = "select 部门编号 from 部门信息表 where 部门编号='" + this.DropDownList1.Text + "'";
SqlCommand myCom = new SqlCommand(sql, myConn);
SqlDataReader myReader1 = myCom.ExecuteReader();
DataTable d = new DataTable();
d.Columns.Add("部门编号", typeof(string));
if (myReader1.Read())
{
DataRow dr = d.NewRow();
dr[0] = myReader1.GetValue(0).ToString();
bumenbianhao = Convert.ToString(dr[0]);
}
myReader1.Close();
if (this.DropDownList1.Text != bumenbianhao)
this.Response.Write("<script language=javascript>alert('数据库中无此项记录!')</script>");
sql = "select 部门编号,部门名称,部门电话 from 部门信息表 where 部门编号 ='" + this.DropDownList1.Text + "'";
}
else
sql = "select 部门编号,部门名称,部门电话 from 部门信息表 where 部门名称 ='" + this.DropDownList4.Text + "'";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("部门编号", typeof(string));
dt.Columns.Add("部门名称", typeof(string));
dt.Columns.Add("部门电话", typeof(string));
while (myReader.Read())
{
DataRow dr = dt.NewRow();
dr[0] = myReader.GetValue(0).ToString();
dr[1] = myReader.GetValue(1).ToString();
dr[2] = myReader.GetValue(2).ToString();
dt.Rows.Add(dr);
}
this.GridView2.DataSource = new DataView(dt);
this.GridView2.DataBind();
myConn.Close();
}
else
{
Response.Write("<script>alert('请输入搜索项!')</script>");
}
}
protected void Button5_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
string sql;
if (this.TextBox2.Text != "")
{
sql = "update 部门信息表 set 部门编号='" + this.TextBox2.Text + "'";
if (this.DropDownList1.Text != "")
{
if (this.TextBox3.Text != "")
sql = sql + ", 部门名称='" + this.TextBox3.Text + "'";
if (this.TextBox1.Text != "")
sql = sql + ", 部门电话='" + this.TextBox1.Text + "'";
sql += "where 部门编号='" + this.DropDownList1.Text + "'";
}
else
{
if (this.TextBox3.Text != "")
sql = sql + ", 部门名称='" + this.TextBox3.Text + "'";
if (this.TextBox1.Text != "")
sql = sql + ", 部门电话='" + this.TextBox1.Text + "'";
sql += "where 部门名称='" + this.DropDownList4.Text + "'";
}
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
//this.DropDownList1.Items.Add(this.TextBox2.Text);
//this.Response.Write("<script language=javascript>alert('修改成功!')</script>");
Response.Write("<script>alert('修改成功!')</script>");
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.TextBox1.Text = "";
}
else
{
Response.Write("<script>alert('修改时,必须输入部门编号!如不清楚,可在搜索中填入部门名称,点击核对,进行查询。')</script>");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
if (this.TextBox2.Text != "")
{
myConn.Open();
string bumenbianhao="";
string msql = "select 部门编号 from 部门信息表 where 部门编号='" + this.TextBox2.Text + "'";
SqlCommand myCom = new SqlCommand(msql, myConn);
SqlDataReader myReader = myCom.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("部门编号", typeof(string));
if (myReader.Read())
{
DataRow dr = dt.NewRow();
dr[0] = myReader.GetValue(0).ToString();
bumenbianhao = Convert.ToString(dr[0]);
}
myReader.Close();
if (this.TextBox2.Text != bumenbianhao)
{
if (this.TextBox3.Text != "" && this.TextBox1.Text != "" )
{
string sql =
"insert into 部门信息表(部门编号,部门名称,部门电话)values('" + this.TextBox2.Text + "','" + this.TextBox3.Text + "','" + this.TextBox1.Text + "')";
SqlCommand myComm = new SqlCommand(sql, myConn);
//myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.DropDownList1.Items.Add(this.TextBox2.Text);
this.DropDownList4.Items.Add(this.TextBox3.Text);
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.TextBox1.Text = "";
//this.Response.Write("<scrip language=javascrip>alter('添加成功!')</script>");
Response.Write("<script>alert('添加成功!')</script>");
}
else
{
Response.Write("<script>alert('信息输入不完全!')</script>");
}
}
else
{
Response.Write("<script>alert('该部门编号已存在!')</script>");
}
myConn.Close();
}
else
{
Response.Write("<script>alert('信息输入不完全!')</script>");
}
}
protected void Button4_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;trusted_connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
string sql;
if (this.DropDownList1.Text != "" || this.DropDownList4.Text != "")
{
if (this.DropDownList1.Text != "")
sql = "delete from 部门信息表 where 部门编号='" + this.DropDownList1.Text + "'";
else
sql = "delete from 部门信息表 where 部门名称 ='" + this.DropDownList4.Text + "'";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
//this.Response.Write("<scrip language=javascrip>alter('!')</script>");
Response.Write("<script>alert('删除成功!')</script>");
}
else
{
Response.Write("<script>alert('请输入搜索项!')</script>");
}
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
this.Response.Redirect("3物资信息管理.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -