📄 bumenlingyong.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 bumenlingyong : 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);
myConn.Open();
string sql = "select 物资编号 from 物资信息表";
SqlCommand myComm = new SqlCommand(sql, myConn);
myComm = new SqlCommand(sql, myConn);
SqlDataReader myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
while (myReader.Read())
this.DropDownListwuzibianhao.Items.Add(myReader.GetValue(0).ToString());
}
myReader.Close();
sql = "select 姓名 from 职工信息表";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
while (myReader.Read())
this.DropDownListlingyongren.Items.Add(myReader.GetValue(0).ToString());
}
myReader.Close();
sql = "select 姓名 from 职工信息表";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
while (myReader.Read())
this.DropDownListguanliyuan.Items.Add(myReader.GetValue(0).ToString());
}
myReader.Close();
sql = "select distinct 部门编号 from 部门信息表";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
while (myReader.Read())
this.DropDownListbumenbianhao.Items.Add(myReader.GetValue(0).ToString());
}
myReader.Close();
sql = "select 部门名称 from 部门信息表";
myComm = new SqlCommand(sql, myConn);
myReader = myComm.ExecuteReader();
if (!IsPostBack)
{
while (myReader.Read())
this.DropDownListbumenmingchen.Items.Add(myReader.GetValue(0).ToString());
}
myReader.Close();
myConn.Close();
}
protected void Buttonlfanhui_Click(object sender, EventArgs e)
{
this.Response.Redirect("物资出库.aspx");
}
protected void Buttonlshuru_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
string strcm = "select max(领用单编号) from 部门领用信息表 ";
myConn.Open();
SqlCommand cm = new SqlCommand(strcm, myConn);
int maxnum = (int)cm.ExecuteScalar() + 1;
this.TextBoxlingyongdanbianhao.Text = maxnum.ToString();
myConn.Close();
if (TextBoxlingyongdanbianhao.Text == "")
{
Response.Write("<script>alert('请填写领用单编号!');</script>");
}
else if (TextBoxlingyongshuliang.Text == "")
{
Response.Write("<script>alert('请输入领用数量!');</script>");
}
else if (this.TextBoxlingyongshijian.Text == "")
{
Response.Write("<script>alert('请输入领用时间!');</script>");
}
else
{
string strcmd = "select 物资数量 from 物资信息表 where 物资编号='" + this.DropDownListwuzibianhao.Text + "'";
myConn.Open();
SqlCommand cmd = new SqlCommand(strcmd, myConn);
int num = (int)cmd.ExecuteScalar();
myConn.Close();
if (num != 0)
{
string sql
= "insert into 部门领用信息表(领用单编号,物资编号,领用数量,领用人,管理员,部门编号,部门名称,领用时间) values('"
+ this.TextBoxlingyongdanbianhao.Text + "','" +
this.DropDownListwuzibianhao.Text + "','" +
this.TextBoxlingyongshuliang.Text + "','" +
this.DropDownListlingyongren.Text + "','" +
this.DropDownListguanliyuan.Text + "','" +
this.DropDownListbumenbianhao.Text + "','" +
this.DropDownListbumenmingchen.Text + "','" +
this.TextBoxlingyongshijian.Text + "');";
if (num < Convert.ToDouble(TextBoxlingyongshuliang.Text))
{
sql += "update 物资信息表 set 物资数量= 0 where 物资编号='" + this.DropDownListwuzibianhao.Text + "'";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.Response.Write("<script language=javascript>alert('数量不够,领用不足!')</script>");
}
else
{
sql += "update 物资信息表 set 物资数量=物资数量-" + this.TextBoxlingyongshuliang.Text
+ "where 物资编号='" + this.DropDownListwuzibianhao.Text + "'";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.Response.Write("<script language=javascript>alert('领用单输入成功!')</script>");
}
}
else
{
this.Response.Write("<script language=javascript>alert('此物资已用完,请补充!')</script>");
this.TextBoxlingyongdanbianhao.Text = "";
this.DropDownListwuzibianhao.Text = "1";
this.TextBoxlingyongshuliang.Text = "";
this.DropDownListbumenbianhao.Text = "1";
this.TextBoxlingyongshijian.Text = "";
}
}
}
protected void Buttonlshanchu_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
if (TextBoxlingyongdanbianhao.Text == "")
{
Response.Write("<script>alert('请填写领用单编号!');</script>");
}
else if (TextBoxlingyongshuliang.Text == "")
{
Response.Write("<script>alert('领用数量为空项,请先进行查询!');</script>");
}
else
{
string strcmd = "select 领用数量 from 部门领用信息表 where 领用单编号='" + this.TextBoxlingyongdanbianhao.Text + "'";
myConn.Open();
SqlCommand cmd = new SqlCommand(strcmd, myConn);
int nl = Convert.ToInt32(cmd.ExecuteScalar());
myConn.Close();
if (nl == Convert.ToDouble(TextBoxlingyongshuliang.Text))
{
string sql
= "delete from 部门领用信息表 where 领用单编号='" + this.TextBoxlingyongdanbianhao.Text + "'";
sql += "update 物资信息表 set 物资数量=物资数量+" + this.TextBoxlingyongshuliang.Text
+ "where 物资编号='" + this.DropDownListwuzibianhao.Text + "'";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.Response.Write("<script language=javascript>alert('领用单删除成功!')</script>");
this.TextBoxlingyongdanbianhao.Text="";
this.DropDownListwuzibianhao.Text="1";
this.TextBoxlingyongshuliang.Text="";
// this.DropDownListlingyongren.Text + "','" +
//this.DropDownListguanliyuan.Text + "','" +
//this.DropDownListbumenmingchen.Text + "','" +
this.DropDownListbumenbianhao.Text="1";
this.TextBoxlingyongshijian.Text = "";
}
else if (nl != Convert.ToDouble(TextBoxlingyongshuliang.Text))
{
this.Response.Write("<script language=javascript>alert('领用数量不正确或领用单编号错误,请先进行查找!')</script>");
}
}
}
protected void Buttonlxiugai_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
if (TextBoxlingyongdanbianhao.Text == "")
{
Response.Write("<script>alert('请填写领用单编号!');</script>");
}
else if (TextBoxlingyongshuliang.Text == "")
{
Response.Write("<script>alert('领用数量为空项,请先进行查找!');</script>");
}
else
{
string strcmd = "select 领用数量 from 部门领用信息表 where 领用单编号='" + this.TextBoxlingyongdanbianhao.Text + "'";
myConn.Open();
SqlCommand cmd = new SqlCommand(strcmd, myConn);
int nu = Convert.ToInt32(cmd.ExecuteScalar());
myConn.Close();
if (nu == Convert.ToDouble(TextBoxlingyongshuliang.Text))
{
string sql = "update 部门领用信息表 set 物资编号='" + this.DropDownListwuzibianhao.Text
+ "' , 领用人='" + this.DropDownListlingyongren.Text
+ "', 管理员='" + this.DropDownListguanliyuan.Text
+ "',部门编号='" + this.DropDownListbumenbianhao.Text
+ "',部门名称='" + this.DropDownListbumenmingchen.Text
+ "',领用时间='" + this.TextBoxlingyongshijian.Text
+ "' where 领用单编号='" + this.TextBoxlingyongdanbianhao.Text + "'";
SqlCommand myComm = new SqlCommand(sql, myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.Response.Write("<script language=javascript>alert('修改成功!')</script>");
}
else if (nu != Convert.ToDouble(TextBoxlingyongshuliang.Text))
{
this.Response.Write("<script language=javascript>alert('物资数量被修改或领用单编号错误,请先进行查找!')</script>");
}
}
}
protected void Buttonchazhao_Click(object sender, EventArgs e)
{
string myConnStr = "data source=.;database=物资管理系统;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(myConnStr);
if (TextBoxlingyongdanbianhao.Text == "")
{
Response.Write("<script>alert('请填写领用单编号!');</script>");
}
else
{
string strcmd = "select 物资编号,领用数量,领用人,管理员,部门编号,部门名称,领用时间 from 部门领用信息表 where 领用单编号='" + this.TextBoxlingyongdanbianhao.Text + "'";
myConn.Open();
SqlCommand cmd = new SqlCommand(strcmd, myConn);
// int nu = Convert.ToInt32(cmd.ExecuteScalar());
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
DropDownListwuzibianhao.Text = Convert.ToString(rdr["物资编号"]);
TextBoxlingyongshuliang.Text = Convert.ToString(rdr["领用数量"]);
DropDownListlingyongren.Text = Convert.ToString(rdr["领用人"]);
DropDownListguanliyuan.Text = Convert.ToString(rdr["管理员"]);
DropDownListbumenbianhao.Text = Convert.ToString(rdr["部门编号"]);
DropDownListbumenmingchen.Text = Convert.ToString(rdr["部门名称"]);
TextBoxlingyongshijian.Text = Convert.ToString(rdr["领用时间"]);
this.Response.Write("<script language=javascript>alert('查找成功!')</script>");
}
else
{
this.Response.Write("<script language=javascript>alert('不存在该项,请重新核对领用单编号!')</script>");
}
myConn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -