📄 stock_add.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 LoginCheckClass;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
LoginCheck a = new LoginCheck(); //对页面进行Session验证,防止非法用户直接通过URL进行登录
a.check();
TextBox2.Attributes["onchange"] = TextBox3.Attributes["onchange"] =
"javascript:getPrice();"; //引入JavaScript事件
TextBox4.Attributes["onchange"] = TextBox5.Attributes["onchange"] =
"javascript:getPrice();"; //引入JavaScript事件
if (!IsPostBack)
this.Label2.Text = Convert.ToString(Session["username"]); //通过Session获取用户名
}
//把页面中的内容添加至数据库db_Sell中的tb_Stock表
protected void AddBotton_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;
//使用SQL语句添加至数据库
command.Parameters.Add("@Number", SqlDbType.Int).Value = Int32.Parse(TextBox2.Text);
command.Parameters.Add("@FactPayment", SqlDbType.Int).Value = Int32.Parse(TextBox5.Text);
command.Parameters.Add("@SettlementType", SqlDbType.VarChar).Value = DropDownList2.Text;
command.Parameters.Add("@ManageMan", SqlDbType.VarChar).Value = TextBox8.Text;
command.Parameters.Add("@CompanyID", SqlDbType.Int).Value = Session["Compid"].ToString();//self
command.Parameters.Add("@CommodityID", SqlDbType.Int).Value = int.Parse(DropDownList1.Text);
command.Parameters.Add("@Price", SqlDbType.Int).Value = Int32.Parse(TextBox3.Text);
command.Parameters.Add("@Payment", SqlDbType.Int).Value = Request["TextBox4"];
command.Parameters.Add("@NoPayment", SqlDbType.Int).Value = Request["TextBox6"];
//command.Parameters.Add("@operator", SqlDbType.VarChar, 50).Value = operator.Text;
command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Session["UserName"];
command.Parameters.Add("@Type", SqlDbType.VarChar, 50).Value = "进货";
command.Parameters.Add("@StockTime", SqlDbType.DateTime).Value = data.Text;
command.CommandText = "Insert into tb_Stock(Number,FactPayment,StockDate,SettlementType,ManageMan,CompanyID,CommodityID,Pirce,Payment,NoPayment,UserName,AddTime,Type) Values(@Number,@FactPayment,@StockTime,@SettlementType,@ManageMan,@CompanyID,@CommodityID,@Price,@Payment,@NoPayment,@UserName,GETDATE(),@Type)";
command.ExecuteNonQuery();
//添加成功时提示“添加”成功
Response.Write(@"<script>alert('添加成功');</script>");
// 添加成功时清空各个TextBox内容
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox8.Text = "";
}
}
}
//抛出异常
catch (Exception ex)
{
Response.Write(@"<script>alert('系统错误');</script>"); //添加失败时提示“系统错误”
}
}
//实现商品名称和供应商的绑定
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//连接数据库
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
string id = DropDownList1.SelectedValue;
cmd.CommandText = "SELECT tb_Company.id,tb_Company.CompanyName FROM tb_Commodity INNER JOIN tb_Company ON tb_Commodity.CompanyID = tb_Company.id WHERE tb_Commodity.id =" + id; //SQl语句查询公司ID和公司名
cmd.Connection = con; //打开数据库
con.Open();
SqlDataReader reader = cmd.ExecuteReader(); //读取数据
if (reader.Read())
{
TextBox1.Text = reader["CompanyName"].ToString();
Session["Compid"] = reader["id"].ToString();
}
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
private static readonly string _connectString = System.Configuration.ConfigurationManager.ConnectionStrings["db_sellConnectionString"].ConnectionString;
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
protected void TextBox1_TextChanged1(object sender, EventArgs e)
{
}
//实现数据绑定
protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList1_SelectedIndexChanged(sender, e);
}
//TextBox1事件的定义
protected void TextBox1_TextChanged2(object sender, EventArgs e)
{
}
//TextBox5 事件的定义
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -