📄 commodity_open.aspx.cs
字号:
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;
using LoginCheckClass;//(类)验证用户是否登录
/// <summary>
/// 2008年7月19日 吕亚霓 编码
/// 2008年7月19日 测试
/// 2008年7月21日 添加登录验证功能
/// 2008年7月21日 测试登录验证功能
/// </summary>
public partial class _Default : System.Web.UI.Page
{
//页面加载时运行
protected void Page_Load(object sender, EventArgs e)
{
//调用LoginCheck类的check方法来判断用户是否登录
LoginCheck b = new LoginCheck();
b.check();
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
if (!IsPostBack) //判断是否为页面回传
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
//读取在Commodity_manage页面中建立的Session["Commodity_ID"]的值,用来确定页面读出tb_Commodity表中的哪条信息
command.Parameters.Add("@Commodity_ID", SqlDbType.Int).Value = (int)Session["Commodity_ID"];
//查询出所选商品的详细信息
command.CommandText = "SELECT CommodityName,ShortName,ProducePlace,Unit,Specs,PassNumber,PassList,CompanyID,Remark from tb_Commodity WHERE id=@Commodity_ID";
command.ExecuteNonQuery();
SqlDataReader reader = command.ExecuteReader();
//将取出的信息付给页面中各控件
while (reader.Read())
{
TextBox1.Text = reader.GetString(0); //商品名称
TextBox2.Text = reader.GetString(1); //商品简称
TextBox3.Text = reader.GetString(2); //产地
TextBox4.Text = reader.GetString(3); //单位
TextBox5.Text = reader.GetString(4); //规格
TextBox6.Text = reader.GetString(5); //批号
TextBox7.Text = reader.GetString(6); //批准文号
TextBox8.Text = reader.GetString(8); //备注
DropDownList1.SelectedValue = Convert.ToString(reader.GetInt32(7)); //供应商,绑定tb_company表中的companyName字段,筛选出type为供应商的内容
}
}
}
}
}
//若读取失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void AlertCommodity_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection connection = new SqlConnection(_connectString)) //建立连接
{
connection.Open(); //打开连接
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandType = CommandType.Text;
//从页面中读取各项需要的值,并赋予变量中
command.Parameters.Add("@Commodity_ID", SqlDbType.Int).Value = (int)Session["Commodity_ID"];
command.Parameters.Add("@CommodityName", SqlDbType.VarChar, 100).Value = TextBox1.Text;
command.Parameters.Add("@ShortName", SqlDbType.VarChar, 50).Value = TextBox2.Text;
command.Parameters.Add("@ProducePlace", SqlDbType.VarChar, 100).Value = TextBox3.Text;
command.Parameters.Add("@Unit", SqlDbType.VarChar, 20).Value = TextBox4.Text;
command.Parameters.Add("@Specs", SqlDbType.VarChar, 50).Value = TextBox5.Text;
command.Parameters.Add("@PassNumber", SqlDbType.VarChar, 50).Value = TextBox6.Text;
command.Parameters.Add("@PassList", SqlDbType.VarChar, 50).Value = TextBox7.Text;
command.Parameters.Add("@CompanyID", SqlDbType.Int).Value = int.Parse(DropDownList1.SelectedItem.Value);
command.Parameters.Add("@Remark", SqlDbType.VarChar, 500).Value = TextBox8.Text;
command.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = Session["UserName"];
command.Parameters.Add("@AddTime", SqlDbType.VarChar, 50).Value = Convert.ToString(DateTime.Now);
//更新数据库tb_Commodity表中id等于Session["Commodity_ID"]的数据的相应值
command.CommandText = "UPDATE tb_Commodity SET CommodityName=@CommodityName,ShortName=@ShortName,ProducePlace=@ProducePlace,Unit=@Unit,Specs=@Specs,PassNumber=@PassNumber,PassList=@PassList,CompanyID=@CompanyID,Remark=@Remark,UserName=@UserName,AddTime=@AddTime WHERE id=@Commodity_ID";
command.ExecuteNonQuery();
//更新成功后,以弹出对话框的形式给用户提示成功信息
Response.Write("<script language=javascript>alert('修改成功');opener.location.reload();window.close();</script>");
}
}
}
//若更新失败,则抛出异常信息
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>");
}
}
//使用db_sellConnectionString连接字符串
private static readonly string _connectString = System.Configuration.ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString;
protected void replaceCommodity_Click(object sender, EventArgs e)
{
}
//点击关闭按钮时,调用以下代码关闭当前弹出窗口
protected void closeCommodity_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close();</script>");
}
protected void DropDownList1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -