程序如下:
public partial class MaterialChange : System.Web.UI.Page
{
SqlConnection MyConnection = new SqlConnection(@"Data Source=MICROSOF-F32539\SQLEXPRESS;Initial Catalog=WZGL;Integrated Security=True");
string mid = "";
string tempid = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
String id = Request.QueryString["uid"].ToString();
tempid = id;
String materialid = Request.QueryString["mid"].ToString();
String mainstorehousename = Request.QueryString["mname"].ToString();
String storehousename = Request.QueryString["sname"].ToString();
string aid = id.ToString().Substring(2, 36);
string man = mainstorehousename;
string stn = storehousename;
string maid = materialid;
//Response.Write(man + stn + maid);
if (Session["userLogin"].ToString() != "true")
{
Response.Redirect("Login.aspx");
}
Contents en = new Contents();
en.GetMenu(uMenu, id, MyConnection);
GetMsg(maid,man,stn);
}
public void GetMsg(string c, string mn, string sn)
{
try
{
if (MyConnection.State.ToString().Equals("Close"))
{
MyConnection.Open();
}
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = "SELECT * FROM Material INNER JOIN MaterialType ON Material.materialTypeID = MaterialType.materialTypeID INNER JOIN Unit ON Material.unitID = Unit.unitID INNER JOIN Material_SecondStoreHouse ON Material.materialID = Material_SecondStoreHouse.materialID INNER JOIN SecondStoreHouse ON Material_SecondStoreHouse.storehouseID = SecondStoreHouse.storehouseID INNER JOIN FirstStoreHouse ON SecondStoreHouse.mainstorehouseID = FirstStoreHouse.mainstorehouseID where materialCode = '" + c + "' and mainstorehouseName = '" + mn + "' and storehouseName = '" + sn + "'";
SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
DataSet ds = new DataSet();
objAdapter.Fill(ds, "NewMsg"); if (ds.Tables["NewMsg"].Rows.Count > 0)
{
TextBoxCode.Text = c;
TextBoxMask.Text = ds.Tables["NewMsg"].Rows[0]["materialMask"].ToString();
TextBoxPrice.Text = ds.Tables["NewMsg"].Rows[0]["unitPrice"].ToString();
string unitname = ds.Tables["NewMsg"].Rows[0]["unitName"].ToString();
string mtype = ds.Tables["NewMsg"].Rows[0]["type"].ToString();
string zkn = ds.Tables["NewMsg"].Rows[0]["mainstorehouseName"].ToString();
string ejkn = ds.Tables["NewMsg"].Rows[0]["storehouseName"].ToString();
mid = ds.Tables["NewMsg"].Rows[0]["materialID"].ToString();
//string pid = ds.Tables["NewMsg"].Rows[0]["pictureID"].ToString(); GetUnit(unitname);
GetType(mtype);
GetSecond(ejkn);
GetMainName(zkn); //ImageButtonPicture.PostBackUrl = "MaterialPicture.aspx?id=" + pid + "";
} }
catch (Exception e)
{
Response.Write(e.Message);
}
finally
{
MyConnection.Close();
}
}
..........
public void UpdateMaterial(string m, string tid, string unid, string up)
{
try
{
MyConnection.Open();
//SqlCommand MyCommand = MyConnection.CreateCommand();
string sql = "Update Material set materialMask = '" + m + "', materialTypeID = '" + tid + "', unitID = '" + unid + "', unitPrice = '" + up + "' where materialID = '" + mid + "'";
SqlCommand MyCommand = new SqlCommand(sql, MyConnection);
//MyCommand.CommandText = "Update Material set materialMask = '" + m + "', materialTypeID = '" + tid + "', unitID = '" + unid + "', unitPrice = '" + up + "' where materialID = '" + mid + "'";
//Response.Write(MyCommand.CommandText);
SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
MyCommand.ExecuteNonQuery();
//objAdapter.UpdateCommand = MyCommand;
//DataSet ds = new DataSet();
//objAdapter.Fill(ds, "Material");
//objAdapter.Update(ds, "Material");
//ds.AcceptChanges(); Response.Write("<script>alert('物资表修改成功!')</script>");
}
catch (Exception fsid)
{
Response.Write(fsid.Message);
}
finally
{
MyConnection.Close();
}
}
public void UpdateMaterial_Second(string sid)
{
try
{
MyConnection.Open();
string sql1 = "Update Material_SecondStoreHouse set storehouseID = '" + sid + "' where materialID = '" + mid + "'";
SqlCommand MyCommand = new SqlCommand(sql1,MyConnection);
MyCommand.ExecuteNonQuery();
//SqlCommand MyCommand = MyConnection.CreateCommand();
//MyCommand.CommandText = "Update Material_SecondStoreHouse set storehouseID = '" + sid + "' where materialID = '" + mid + "'";
//SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
//SqlCommandBuilder builder = new SqlCommandBuilder(objAdapter);
//DataSet ds = new DataSet();
//objAdapter.Fill(ds, "UpdateMaterial_Second");
//objAdapter.Update(ds, "UpdateMaterial_Second"); Response.Write("<script>alert('中间表修改成功!')</script>");
}
catch (Exception fsid)
{
Response.Write(fsid.Message);
}
finally
{
MyConnection.Close();
}
}
protected void ButtonConfirm_Click(object sender, EventArgs e)
{
//string code = "";
string type = "";
string mainstore = "";
string secondstore = "";
string price = "";
string mask = "";
string unit = "";
string newunitid = "";
string newtypeid = "";
string newmainid = "";
string newsecondid = ""; //code = TextBoxCode.Text;
mask = TextBoxMask.Text;
price = TextBoxPrice.Text;
Response.Write(price);
mainstore = DropDownListMainStore.SelectedItem.Text;
secondstore = DropDownListSecondStore.SelectedItem.Text;
type = DropDownListType.SelectedItem.Text;
unit = DropDownListUnit.SelectedItem.Text; newunitid = SearchUnit(unit);
newtypeid = SearchMaterialTypeID(type);
newmainid = SearchFirstStoreID(mainstore);
newsecondid = SearchSecondStoreID(secondstore,newmainid);
UpdateMaterial(mask,newtypeid,newunitid,price);
UpdateMaterial_Second(newsecondid); Response.Write("<script>alert('物资修改成功!')</script>");
Response.Write("window.location.replace( 'MaterialDeleteAndChange.aspx?uid=" + tempid + "'); ");
}
protected void ImageButtonPicture_Click(object sender, ImageClickEventArgs e)
{
string mcode = ""; mcode = TextBoxCode.Text; Response.Redirect("MaterialPicture.aspx?code=" + mcode + "");
}
}(我在page_load中获取上一页的值然后赋值给该页从而显示就信息,用户输入并修改好,按按钮更新信息,但发现获取不了新值)
public partial class MaterialChange : System.Web.UI.Page
{
SqlConnection MyConnection = new SqlConnection(@"Data Source=MICROSOF-F32539\SQLEXPRESS;Initial Catalog=WZGL;Integrated Security=True");
string mid = "";
string tempid = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
String id = Request.QueryString["uid"].ToString();
tempid = id;
String materialid = Request.QueryString["mid"].ToString();
String mainstorehousename = Request.QueryString["mname"].ToString();
String storehousename = Request.QueryString["sname"].ToString();
string aid = id.ToString().Substring(2, 36);
string man = mainstorehousename;
string stn = storehousename;
string maid = materialid;
//Response.Write(man + stn + maid);
if (Session["userLogin"].ToString() != "true")
{
Response.Redirect("Login.aspx");
}
Contents en = new Contents();
en.GetMenu(uMenu, id, MyConnection);
GetMsg(maid,man,stn);
}
public void GetMsg(string c, string mn, string sn)
{
try
{
if (MyConnection.State.ToString().Equals("Close"))
{
MyConnection.Open();
}
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = "SELECT * FROM Material INNER JOIN MaterialType ON Material.materialTypeID = MaterialType.materialTypeID INNER JOIN Unit ON Material.unitID = Unit.unitID INNER JOIN Material_SecondStoreHouse ON Material.materialID = Material_SecondStoreHouse.materialID INNER JOIN SecondStoreHouse ON Material_SecondStoreHouse.storehouseID = SecondStoreHouse.storehouseID INNER JOIN FirstStoreHouse ON SecondStoreHouse.mainstorehouseID = FirstStoreHouse.mainstorehouseID where materialCode = '" + c + "' and mainstorehouseName = '" + mn + "' and storehouseName = '" + sn + "'";
SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
DataSet ds = new DataSet();
objAdapter.Fill(ds, "NewMsg"); if (ds.Tables["NewMsg"].Rows.Count > 0)
{
TextBoxCode.Text = c;
TextBoxMask.Text = ds.Tables["NewMsg"].Rows[0]["materialMask"].ToString();
TextBoxPrice.Text = ds.Tables["NewMsg"].Rows[0]["unitPrice"].ToString();
string unitname = ds.Tables["NewMsg"].Rows[0]["unitName"].ToString();
string mtype = ds.Tables["NewMsg"].Rows[0]["type"].ToString();
string zkn = ds.Tables["NewMsg"].Rows[0]["mainstorehouseName"].ToString();
string ejkn = ds.Tables["NewMsg"].Rows[0]["storehouseName"].ToString();
mid = ds.Tables["NewMsg"].Rows[0]["materialID"].ToString();
//string pid = ds.Tables["NewMsg"].Rows[0]["pictureID"].ToString(); GetUnit(unitname);
GetType(mtype);
GetSecond(ejkn);
GetMainName(zkn); //ImageButtonPicture.PostBackUrl = "MaterialPicture.aspx?id=" + pid + "";
} }
catch (Exception e)
{
Response.Write(e.Message);
}
finally
{
MyConnection.Close();
}
}
..........
public void UpdateMaterial(string m, string tid, string unid, string up)
{
try
{
MyConnection.Open();
//SqlCommand MyCommand = MyConnection.CreateCommand();
string sql = "Update Material set materialMask = '" + m + "', materialTypeID = '" + tid + "', unitID = '" + unid + "', unitPrice = '" + up + "' where materialID = '" + mid + "'";
SqlCommand MyCommand = new SqlCommand(sql, MyConnection);
//MyCommand.CommandText = "Update Material set materialMask = '" + m + "', materialTypeID = '" + tid + "', unitID = '" + unid + "', unitPrice = '" + up + "' where materialID = '" + mid + "'";
//Response.Write(MyCommand.CommandText);
SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
MyCommand.ExecuteNonQuery();
//objAdapter.UpdateCommand = MyCommand;
//DataSet ds = new DataSet();
//objAdapter.Fill(ds, "Material");
//objAdapter.Update(ds, "Material");
//ds.AcceptChanges(); Response.Write("<script>alert('物资表修改成功!')</script>");
}
catch (Exception fsid)
{
Response.Write(fsid.Message);
}
finally
{
MyConnection.Close();
}
}
public void UpdateMaterial_Second(string sid)
{
try
{
MyConnection.Open();
string sql1 = "Update Material_SecondStoreHouse set storehouseID = '" + sid + "' where materialID = '" + mid + "'";
SqlCommand MyCommand = new SqlCommand(sql1,MyConnection);
MyCommand.ExecuteNonQuery();
//SqlCommand MyCommand = MyConnection.CreateCommand();
//MyCommand.CommandText = "Update Material_SecondStoreHouse set storehouseID = '" + sid + "' where materialID = '" + mid + "'";
//SqlDataAdapter objAdapter = new SqlDataAdapter(MyCommand);
//SqlCommandBuilder builder = new SqlCommandBuilder(objAdapter);
//DataSet ds = new DataSet();
//objAdapter.Fill(ds, "UpdateMaterial_Second");
//objAdapter.Update(ds, "UpdateMaterial_Second"); Response.Write("<script>alert('中间表修改成功!')</script>");
}
catch (Exception fsid)
{
Response.Write(fsid.Message);
}
finally
{
MyConnection.Close();
}
}
protected void ButtonConfirm_Click(object sender, EventArgs e)
{
//string code = "";
string type = "";
string mainstore = "";
string secondstore = "";
string price = "";
string mask = "";
string unit = "";
string newunitid = "";
string newtypeid = "";
string newmainid = "";
string newsecondid = ""; //code = TextBoxCode.Text;
mask = TextBoxMask.Text;
price = TextBoxPrice.Text;
Response.Write(price);
mainstore = DropDownListMainStore.SelectedItem.Text;
secondstore = DropDownListSecondStore.SelectedItem.Text;
type = DropDownListType.SelectedItem.Text;
unit = DropDownListUnit.SelectedItem.Text; newunitid = SearchUnit(unit);
newtypeid = SearchMaterialTypeID(type);
newmainid = SearchFirstStoreID(mainstore);
newsecondid = SearchSecondStoreID(secondstore,newmainid);
UpdateMaterial(mask,newtypeid,newunitid,price);
UpdateMaterial_Second(newsecondid); Response.Write("<script>alert('物资修改成功!')</script>");
Response.Write("window.location.replace( 'MaterialDeleteAndChange.aspx?uid=" + tempid + "'); ");
}
protected void ImageButtonPicture_Click(object sender, ImageClickEventArgs e)
{
string mcode = ""; mcode = TextBoxCode.Text; Response.Redirect("MaterialPicture.aspx?code=" + mcode + "");
}
}(我在page_load中获取上一页的值然后赋值给该页从而显示就信息,用户输入并修改好,按按钮更新信息,但发现获取不了新值)
解决方案 »
- 数据库内bool类型的值如何显示在datagridview中combobox上
- 求助,如何从xml中删除和修改带ID的元素
- 帮帮忙啊 这个问题我怎么想都不知道出在哪里 有谁帮帮忙 谢谢了
- msmq 如何设置超时时间?
- 我问别人用什么来画UML图,并且生成C# 2。0的代码,有的人说用EA,大家知道EA是什么吗?
- 如何在C#设置控件显示的层次。
- 使用C#开发使用sql server2010哪个版本比较适合?
- gridview中如何让一个表头列中包含多个字段?
- datalist文问题??
- WPF中PasswordBox的属性PasswordChar如何替换成图片?
- winform中如何重新控件的visible属性
- 弱弱的问问??
把数据加载写在if(ispostback){}中,在试试。。
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
//....your code
}
}