feat: 添加功能开关控制页面并迁移PHP实现到ASP.NET
添加新的ASP.NET页面用于功能开关控制,包含前端界面和后端逻辑 删除旧的PHP实现文件,完成技术栈迁移
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<%@ 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>
|
||||
</head>
|
||||
<body>
|
||||
<h2>功能开关控制</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>
|
||||
<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>" %>
|
||||
</div>
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
</asp:Repeater>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Web;
|
||||
|
||||
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;";
|
||||
|
||||
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 id, name, description, status FROM features";
|
||||
SqlDataAdapter adapter = new SqlDataAdapter(querySql, conn);
|
||||
DataTable dt = new DataTable();
|
||||
adapter.Fill(dt);
|
||||
|
||||
FeaturesRepeater.DataSource = dt;
|
||||
FeaturesRepeater.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
// 连接SQL Server数据库(FreeTDS方式)
|
||||
$server = 'localhost';
|
||||
$database = 'your_database';
|
||||
$username = 'your_username';
|
||||
$password = 'your_password';
|
||||
|
||||
// 检查mssql扩展是否已加载
|
||||
if (!function_exists('mssql_connect')) {
|
||||
die('mssql 扩展未加载,请检查PHP配置并安装FreeTDS');
|
||||
}
|
||||
|
||||
$conn = mssql_connect($server, $username, $password);
|
||||
if (!$conn) {
|
||||
die('无法连接数据库: ' . mssql_get_last_message());
|
||||
}
|
||||
|
||||
if (!mssql_select_db($database, $conn)) {
|
||||
die('无法选择数据库: ' . mssql_get_last_message());
|
||||
}
|
||||
|
||||
// 处理开关操作
|
||||
if (isset($_GET['action']) && isset($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
$status = $_GET['action'] == 'enable' ? 1 : 0;
|
||||
|
||||
// 更新状态
|
||||
$sql = "UPDATE features SET status = $status WHERE id = '$id'";
|
||||
$result = mssql_query($sql, $conn);
|
||||
if (!$result) {
|
||||
die('更新失败: ' . mssql_get_last_message());
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
$logSql = "INSERT INTO operation_logs (feature_id, action, operation_time) VALUES ('$id', '{$_GET['action']}', GETDATE())";
|
||||
$logResult = mssql_query($logSql, $conn);
|
||||
if (!$logResult) {
|
||||
die('日志记录失败: ' . mssql_get_last_message());
|
||||
}
|
||||
}
|
||||
|
||||
// 查询功能列表
|
||||
$sql = "SELECT id, name, description, status FROM features";
|
||||
$stmt = mssql_query($sql, $conn);
|
||||
if (!$stmt) {
|
||||
die('查询失败: ' . mssql_get_last_message());
|
||||
}
|
||||
|
||||
// 微信HTML5页面
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<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>
|
||||
</head>
|
||||
<body>
|
||||
<h2>功能开关控制</h2>
|
||||
<?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)): ?>
|
||||
<div class="feature">
|
||||
<div class="feature-info">
|
||||
<div class="feature-name"><?php echo $row['name']; ?></div>
|
||||
<div class="feature-desc"><?php echo $row['description']; ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<?php if ($row['status']): ?>
|
||||
<a href="?action=disable&id=<?php echo $row['id']; ?>" class="toggle-btn disable">关闭</a>
|
||||
<span class="status">(已启用)</span>
|
||||
<?php else: ?>
|
||||
<a href="?action=enable&id=<?php echo $row['id']; ?>" class="toggle-btn enable">开启</a>
|
||||
<span class="status">(已禁用)</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
mssql_close($conn);
|
||||
?>
|
||||
Reference in New Issue
Block a user