📄 inputgsjj.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_gsjj : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Leaveword"].ToString() != "pass")
{
Response.Redirect("../Default.aspx");
}
}
catch
{
Response.Redirect("../Default.aspx");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string scmdText = "";
OleDbDataReader dr = null;
if (DropDownList1.SelectedIndex == 1)
{
FreeTextBox1.Visible = false;
FreeTextBox2.Visible = true;
scmdText = "SELECT Gsjj FROM Gsinfo";
dr = Getinfo(scmdText);
if (dr.Read())
{
FreeTextBox2.Text = dr["Gsjj"].ToString();
}
}
else
{
FreeTextBox1.Visible = true;
FreeTextBox2.Visible = false;
if (DropDownList1.SelectedIndex == 2)
{
scmdText = "SELECT Ysxl FROM Gsinfo";
dr = Getinfo(scmdText);
if (dr.Read())
{
FreeTextBox1.Text = dr["Ysxl"].ToString();
}
}
if (DropDownList1.SelectedIndex == 3)
{
scmdText = "SELECT Gszz FROM Gsinfo";
dr = Getinfo(scmdText);
if (dr.Read())
{
FreeTextBox1.Text = dr["Gszz"].ToString();
}
}
if (DropDownList1.SelectedIndex == 4)
{
scmdText = "SELECT Yjcc FROM Gsinfo";
dr = Getinfo(scmdText);
if (dr.Read())
{
FreeTextBox1.Text = dr["Yjcc"].ToString();
}
}
if (DropDownList1.SelectedIndex == 0)
{
FreeTextBox1.Text = FreeTextBox2.Text = "";
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string scmdText = "";
switch (DropDownList1.SelectedIndex.ToString())
{
case "0":
Errormsg.Text = "提交失败,请先选所要保存的项目!";
break;
case "1":
scmdText = "UPDATE Gsinfo SET Gsjj='" + FreeTextBox2.Text.ToString() + "'";
Updatetodata(FreeTextBox2.Text.ToString(), scmdText);
break;
case "2":
scmdText = "UPDATE Gsinfo SET Ysxl='" + FreeTextBox1.Text.ToString() + "'";
Updatetodata(FreeTextBox1.Text.ToString(), scmdText);
Errormsg.Text = "成功提交!";
break;
case "3":
scmdText = "UPDATE Gsinfo SET Gszz='" + FreeTextBox1.Text.ToString() + "'";
Updatetodata(FreeTextBox1.Text.ToString(), scmdText);
Errormsg.Text = "成功提交!";
break;
case "4":
scmdText = "UPDATE Gsinfo SET Yjcc='" + FreeTextBox1.Text.ToString() + "'";
Updatetodata(FreeTextBox1.Text.ToString(), scmdText);
Errormsg.Text = "成功提交!";
break;
default:
break;
}
}
//保存信息到数据库
private void Updatetodata(string sContent,string scmdText)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = scmdText;
OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
}
//从数据库提取信息
public OleDbDataReader Getinfo(string scmdText)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = scmdText;
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -