c335dc8a80
- 新增Web.config文件配置数据库连接字符串 - 修改E3_ycsys.aspx.cs从配置文件中读取连接字符串 - 更新SQL查询语句和页面显示字段 - 简化页面样式并调整中英文显示
52 lines
2.2 KiB
C#
52 lines
2.2 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Web;
|
|
using System.Configuration;
|
|
|
|
public partial class E3_ycsys : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
var connString = ConfigurationManager.ConnectionStrings["E3_ycsysConnection"];
|
|
string connectionString = connString != null ? connString.ConnectionString : null;
|
|
|
|
if(string.IsNullOrEmpty(connectionString))
|
|
{
|
|
throw new Exception("请在Web.config中配置名为'E3_ycsysConnection'的连接字符串");
|
|
}
|
|
|
|
using (SqlConnection conn = new SqlConnection(connectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
// 处理开关操作
|
|
if (!string.IsNullOrEmpty(Request.QueryString["action"]) && !string.IsNullOrEmpty(Request.QueryString["id"]))
|
|
{
|
|
string id = Request.QueryString["id"];
|
|
int status = Request.QueryString["action"] == "enable" ? 1 : 0;
|
|
|
|
string sql = "UPDATE features SET status = @status WHERE id = @id";
|
|
SqlCommand cmd = new SqlCommand(sql, conn);
|
|
cmd.Parameters.AddWithValue("@status", status);
|
|
cmd.Parameters.AddWithValue("@id", id);
|
|
cmd.ExecuteNonQuery();
|
|
|
|
string logSql = "INSERT INTO operation_logs (feature_id, action, operation_time) VALUES (@id, @action, GETDATE())";
|
|
SqlCommand logCmd = new SqlCommand(logSql, conn);
|
|
logCmd.Parameters.AddWithValue("@id", id);
|
|
logCmd.Parameters.AddWithValue("@action", Request.QueryString["action"]);
|
|
logCmd.ExecuteNonQuery();
|
|
}
|
|
|
|
// 查询功能列表
|
|
string querySql = "SELECT khdm,khmc,cast(ycsys.flag1 as int) as status FROM kehu1 inner join ycsys on kehu1.khdm=ycsys.dm";
|
|
SqlDataAdapter adapter = new SqlDataAdapter(querySql, conn);
|
|
DataTable dt = new DataTable();
|
|
adapter.Fill(dt);
|
|
|
|
FeaturesRepeater.DataSource = dt;
|
|
FeaturesRepeater.DataBind();
|
|
}
|
|
}
|
|
} |