📄 editchaxun.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.OleDb;
public partial class include_Chaxun : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Leaveword"] != "pass")
{
Response.Redirect("../Default.aspx");
}
}
catch
{
Response.Redirect("../Default.aspx");
}
}
//按编号取货物信息
public OleDbDataReader Gethuobyhao(string sHuohao)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "SELECT * FROM Huowu WHERE Huohao='" + sHuohao + "'";
OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
OleDbDataReader dr = null;
try
{
myConnection.Open();
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
return dr;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (txtHuohao.Text.Trim().Length < 1)
{
lblError.Text = "请输入货物编号后再查询";
return;
}
OleDbDataReader dr= Gethuobyhao(txtHuohao.Text.ToString().Trim());
if (dr != null)
{
if (dr.Read())
{
txtDaozhan.Text = dr["Daozhan"].ToString();
txtHuoming.Text = dr["Huoming"].ToString();
txtJianshu.Text = dr["Jianshu"].ToString();
txtState.Text = dr["State"].ToString();
txtZhongliang.Text = dr["Zhongliang"].ToString();
lblError.Text = "";
}
else
{
lblError.Text = "对不起,查无此货号,请核对是否输入错误!";
txtDaozhan.Text = "";
txtHuoming.Text = "";
txtJianshu.Text = "";
txtState.Text = "";
txtZhongliang.Text = "";
}
}
}
public int Updatestate(string sHuohao,string sState)
{
int nResult = -1;
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "UPDATE Huowu SET State='" + sState + "' WHERE Huohao='" + sHuohao + "'";
OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
try
{
myConnection.Open();
nResult=myCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
return nResult;
}
protected void Button2_Click(object sender, EventArgs e)
{
string state = txtState.Text.ToString().Trim();
string huohao=txtHuohao.Text.ToString().Trim();
if(huohao.Length<1)
{
lblError.Text="请先输入货号查询";
return;
}
if(state.Length<1)
{
lblError.Text="请输入要修改的状态";
return;
}
int result=Updatestate(huohao,state);
if (result==1)
{
lblError.Text = "修改成功!";
}
else
{
lblError.Text = "无此订单!";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -