feat: 添加Web.config配置并更新E3_ycsys页面功能
- 新增Web.config文件配置数据库连接字符串 - 修改E3_ycsys.aspx.cs从配置文件中读取连接字符串 - 更新SQL查询语句和页面显示字段 - 简化页面样式并调整中英文显示
This commit is contained in:
+10
-23
@@ -1,36 +1,23 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="E3_ycsys.aspx.cs" Inherits="E3_ycsys" %>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head runat="server">
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>功能开关控制</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 0; padding: 15px; }
|
||||
.feature { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; }
|
||||
.feature-info { flex: 1; }
|
||||
.feature-name { font-weight: bold; margin-bottom: 5px; }
|
||||
.feature-desc { color: #666; font-size: 14px; }
|
||||
.toggle-btn { padding: 5px 10px; border-radius: 4px; border: none; color: white; cursor: pointer; }
|
||||
.enable { background-color: #4CAF50; }
|
||||
.disable { background-color: #f44336; }
|
||||
.status { margin-left: 10px; font-size: 14px; color: #666; }
|
||||
</style>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h2>功能开关控制</h2>
|
||||
<h2>E3_ycsys</h2>
|
||||
<asp:Repeater ID="FeaturesRepeater" runat="server">
|
||||
<ItemTemplate>
|
||||
<div class="feature">
|
||||
<div class="feature-info">
|
||||
<div class="feature-name"><%# Eval("name") %></div>
|
||||
<div class="feature-desc"><%# Eval("description") %></div>
|
||||
<div class="feature-name"><%# Eval("khdm") %></div>
|
||||
<div class="feature-desc"><%# Eval("khmc") %></div>
|
||||
</div>
|
||||
<div>
|
||||
<%# (int)Eval("status") == 1 ?
|
||||
"<a href='?action=disable&id=" + Eval("id") + "' class='toggle-btn disable'>关闭</a><span class='status'>(已启用)</span>" :
|
||||
"<a href='?action=enable&id=" + Eval("id") + "' class='toggle-btn enable'>开启</a><span class='status'>(已禁用)</span>" %>
|
||||
<%# (int)Eval("status") == 1 ?
|
||||
"<a href='?action=disable&id=" + Eval("khdm") + "' class='toggle-btn disable'>close</a><span class='status'>(opened)</span>" :
|
||||
"<a href='?action=enable&id=" + Eval("khdm") + "' class='toggle-btn enable'>open</a><span class='status'>(closed)</span>" %>
|
||||
</div>
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
|
||||
+9
-2
@@ -2,12 +2,19 @@ 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)
|
||||
{
|
||||
string connectionString = "Server=localhost;Database=your_database;User Id=your_username;Password=your_password;";
|
||||
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))
|
||||
{
|
||||
@@ -33,7 +40,7 @@ public partial class E3_ycsys : System.Web.UI.Page
|
||||
}
|
||||
|
||||
// 查询功能列表
|
||||
string querySql = "SELECT id, name, description, status FROM features";
|
||||
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);
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<connectionStrings>
|
||||
<add name="E3_ycsysConnection"
|
||||
connectionString="Data Source=162.14.110.130,2433;Initial Catalog=e3test;User ID=sa;Password=nKtb5HjpsWjk64YE;"
|
||||
providerName="System.Data.SqlClient" />
|
||||
</connectionStrings>
|
||||
<system.web>
|
||||
<compilation debug="true"
|
||||
tempDirectory="C:\temp\aspnet_temp" />
|
||||
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
|
||||
</system.web>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user