migrate to new git
This commit is contained in:
46
web/admin/user/email.aspx
Normal file
46
web/admin/user/email.aspx
Normal file
@@ -0,0 +1,46 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/Template003/MasterPage.master" AutoEventWireup="true" CodeFile="email.aspx.cs" Inherits="admin_user_email" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" Runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
|
||||
|
||||
<div class="content_box">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-heading">以下 * 欄位為必填欄位</div>
|
||||
<div class="panel-body form-horizontal" role="form">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"> * 公司信箱</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
<asp:TextBox id="email" runat="server" CssClass="form-control" ></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ControlToValidate="email" Display="Dynamic" SetFocusOnError="true" ErrorMessage="必填!" ID="v_email" runat="server" />
|
||||
<asp:RegularExpressionValidator ControlToValidate="email" Display="Dynamic" SetFocusOnError="true" ErrorMessage="您所輸入的Email格式有誤!" ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">BCC</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static" style="color:green">說明:設定密件請一行輸入一個E-mail。</p>
|
||||
<asp:TextBox id="bcc_mail" TextMode="MultiLine" Height="100" runat="server" CssClass="form-control" ></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-md-offset-2 col-sm-9 col-md-10">
|
||||
<asp:Label id="L_msg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
|
||||
<asp:Button id="Button1" runat="server" Text="儲存" OnClick="Button1_Click" CssClass="btn btn-outline-secondary" ></asp:Button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</asp:Content>
|
||||
|
||||
50
web/admin/user/email.aspx.cs
Normal file
50
web/admin/user/email.aspx.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
|
||||
public partial class admin_user_email : MyWeb.config
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) {
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
DataTable dt = sql.selectTable(db, p_name, "Select com_mail,bcc_mail from company where num=1");
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
email.Text = dt.Rows[0]["com_mail"].ToString();
|
||||
bcc_mail.Text = dt.Rows[0]["bcc_mail"].ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE company SET com_mail=?,bcc_mail=? WHERE num=1";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("com_mail", email.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("bcc_mail", bcc_mail.Text));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
L_msg.Text = "設定資料變更完成!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
50
web/admin/user/email.aspx.cs.exclude
Normal file
50
web/admin/user/email.aspx.cs.exclude
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
|
||||
public partial class admin_user_email : MyWeb.config
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) {
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
DataTable dt = sql.selectTable(db, p_name, "Select com_mail,bcc_mail from company where num=1");
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
email.Text = dt.Rows[0]["com_mail"].ToString();
|
||||
bcc_mail.Text = dt.Rows[0]["bcc_mail"].ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE company SET com_mail=?,bcc_mail=? WHERE num=1";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("com_mail", email.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("bcc_mail", bcc_mail.Text));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
L_msg.Text = "設定資料變更完成!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
web/admin/user/email.aspx.exclude
Normal file
46
web/admin/user/email.aspx.exclude
Normal file
@@ -0,0 +1,46 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/Template003/MasterPage.master" AutoEventWireup="true" CodeFile="email.aspx.cs" Inherits="admin_user_email" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" Runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
|
||||
|
||||
<div class="content_box">
|
||||
<div class="panel panel-default">
|
||||
|
||||
<div class="panel-heading">以下 * 欄位為必填欄位</div>
|
||||
<div class="panel-body form-horizontal" role="form">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label"> * 公司信箱</label>
|
||||
<div class="col-sm-10">
|
||||
|
||||
<asp:TextBox id="email" runat="server" CssClass="form-control" ></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ControlToValidate="email" Display="Dynamic" SetFocusOnError="true" ErrorMessage="必填!" ID="v_email" runat="server" />
|
||||
<asp:RegularExpressionValidator ControlToValidate="email" Display="Dynamic" SetFocusOnError="true" ErrorMessage="您所輸入的Email格式有誤!" ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">BCC</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static" style="color:green">說明:設定密件請一行輸入一個E-mail。</p>
|
||||
<asp:TextBox id="bcc_mail" TextMode="MultiLine" Height="100" runat="server" CssClass="form-control" ></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-md-offset-2 col-sm-9 col-md-10">
|
||||
<asp:Label id="L_msg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
|
||||
<asp:Button id="Button1" runat="server" Text="儲存" OnClick="Button1_Click" CssClass="btn btn-outline-secondary" ></asp:Button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</asp:Content>
|
||||
|
||||
137
web/admin/user/group_reg.aspx
Normal file
137
web/admin/user/group_reg.aspx
Normal file
@@ -0,0 +1,137 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="group_reg.aspx.cs" Inherits="admin_user_group_reg" %>
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="footer_script" runat="Server">
|
||||
<script type="text/javascript">
|
||||
//---------------------------------checkbox全選用---------------------------------------------------
|
||||
function Check2(parentChk, ChildId) {
|
||||
var oElements = document.getElementsByTagName("INPUT");
|
||||
var bIsChecked = parentChk.checked;
|
||||
|
||||
for (i = 0; i < oElements.length; i++) {
|
||||
if (IsCheckBox2(oElements[i]) &&
|
||||
IsMatch2(oElements[i].id, ChildId)) {
|
||||
oElements[i].checked = bIsChecked;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function IsMatch2(id, ChildId) {
|
||||
if (id.indexOf(ChildId) > -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function IsCheckBox2(chk) {
|
||||
if (chk.type == 'checkbox') return true;
|
||||
else return false;
|
||||
}
|
||||
$(window).ready(function () {
|
||||
var chk = $('#treeArea input[type=checkbox]');
|
||||
for (i = 0; i < chk.length; i++) {
|
||||
var t = $(chk[i]).attr('title').split('-');
|
||||
$(chk[i]).attr('title', '');
|
||||
$(chk[i]).attr('root', t[0]);
|
||||
$(chk[i]).attr('num', t[1]);
|
||||
}
|
||||
|
||||
$("#treeArea input[type=checkbox]").bind("click", function () {
|
||||
var root = $(this).attr('root');
|
||||
var num = $(this).attr('num');
|
||||
|
||||
if (root == "0") {
|
||||
var chk = $('#treeArea input[type=checkbox]');
|
||||
for (i = 0; i < chk.length; i++) {
|
||||
if ($(chk[i]).attr('root') == num) {
|
||||
$(chk[i]).prop("checked", this.checked);
|
||||
}
|
||||
}
|
||||
} else if (root != "0") {
|
||||
var chk = $('#treeArea input[type=checkbox]');
|
||||
for (i = 0; i < chk.length; i++) {
|
||||
if ($(chk[i]).attr('num') == root) {
|
||||
if (this.checked) {
|
||||
$(chk[i]).prop("checked", this.checked);
|
||||
} else {
|
||||
var n = 0;
|
||||
for (ii = 0; ii < chk.length; ii++) {
|
||||
if ($(chk[ii]).attr('root') == root && $(chk[ii]).is(":checked")) { n++; }
|
||||
}
|
||||
if (n == 0) {
|
||||
$(chk[i]).prop("checked", this.checked);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<nav class="mb-1">
|
||||
</nav>
|
||||
<nav class="mb-1">
|
||||
<asp:Button ID="edit" runat="server" Text="修改" OnClick="edit_Click" CssClass="btn btn-primary" />
|
||||
<asp:Button ID="add" runat="server" Text="新增" OnClick="add_Click" CssClass="btn btn-primary" />
|
||||
<asp:Button ID="goback" runat="server" Text="回列表" CausesValidation="false" Visible="false" OnClick="goback_Click" CssClass="btn btn-outline-secondary" />
|
||||
</nav>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
|
||||
<uc1:alert runat="server" ID="L_msg" Text="" />
|
||||
<div id="content" class="container-fluid pb-4">
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
<div class="card shadow-sm my-2" id="sec1">
|
||||
<div class="card-header">選擇權限 |
|
||||
<input type="checkbox" id="chkAll" name="chkAll" onclick="Check2(this, 'CheckBox')" /><label for="chkAll">全選</label></div>
|
||||
<div class="card-body">
|
||||
<asp:TreeView cssClass="aspxTree" ID="TreeView1" runat="server" ImageSet="Arrows" ShowCheckBoxes="All" SkipLinkText="" ShowLines="false" EnableTheming="False" ShowExpandCollapse="True">
|
||||
</asp:TreeView>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
<div class="card shadow-sm my-2">
|
||||
<div class="card-header">
|
||||
<div>群組資料<asp:Label ID="title_msg" runat="server" ></asp:Label></div>
|
||||
<div> <asp:Label ID="rootMsg" ForeColor="blue" runat="server" Font-Size="Smaller"></asp:Label></div>
|
||||
</div>
|
||||
<div class="card-body form-horizontal label-sm-right" role="form">
|
||||
<div>
|
||||
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-lg-3 col-form-label">* 群組代號</label>
|
||||
<div class="col-sm-10 col-lg-9">
|
||||
<asp:TextBox ID="g_name" MaxLength="3" runat="server" CssClass="form-control" placeholder="請輸入群組代號,不可重複" ToolTip="群組代號建立後不可變更"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="g_name" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-lg-3 col-form-label">* 群組名稱</label>
|
||||
<div class="col-sm-10 col-lg-9">
|
||||
<asp:TextBox ID="demo" runat="server" CssClass="form-control" placeholder="請輸入群組名稱"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="demo" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-3 col-md-offset-2 col-sm-9 col-md-10">
|
||||
<asp:HiddenField ID="HiddenField1" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
255
web/admin/user/group_reg.aspx.cs
Normal file
255
web/admin/user/group_reg.aspx.cs
Normal file
@@ -0,0 +1,255 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
|
||||
public partial class admin_user_group_reg : MyWeb.config
|
||||
{
|
||||
DataTable treeDt = new DataTable();
|
||||
const int LevelMax = MyWeb.item.KindLevelMax; //分類層數
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) {
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
L_msg.Text = "";
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin_group Where g_name=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("g_name", Request["num"]));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
g_name.Text = dt.Rows[0]["g_name"].ToString();
|
||||
if (dt.Rows[0]["g_name"].ToString() == "EZ")
|
||||
{
|
||||
rootMsg.Text = "注意:設計師模式群組無需勾選權限,重新登入即可獲得全部功能。";
|
||||
}
|
||||
demo.Text = dt.Rows[0]["demo"].ToString();
|
||||
HiddenField1.Value = dt.Rows[0]["items"].ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
g_name.ReadOnly = true;
|
||||
g_name.BorderWidth = 0;
|
||||
g_name.BackColor = System.Drawing.Color.Transparent;
|
||||
edit.Visible = true;
|
||||
goback.Visible = true;
|
||||
add.Visible = false;
|
||||
title_msg.Text = "修改";
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
edit.Visible = false;
|
||||
title_msg.Text = "新增";
|
||||
|
||||
|
||||
}
|
||||
|
||||
BuildTreeView();
|
||||
}
|
||||
}
|
||||
|
||||
protected void goback_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect("group_show.aspx" + (!isStrNull(Request["page"]) ? "?page=" + Request["page"] : ""));
|
||||
}
|
||||
|
||||
#region 建立TreeView選單
|
||||
|
||||
protected void TreeTopology()
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT num,title,root FROM item ORDER BY root, range";
|
||||
treeDt = sql.dataTable(sqlCmd);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close();
|
||||
sqlConn.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildTreeView() {
|
||||
TreeView1.Nodes.Clear();
|
||||
TreeTopology();
|
||||
BuildChild(0, TreeView1.Nodes);
|
||||
treeDt.Dispose();
|
||||
}
|
||||
|
||||
public void BuildChild(int RootUid, TreeNodeCollection Nodes, int Level=1)
|
||||
{
|
||||
string chkbox_value = "";
|
||||
if (HiddenField1.Value != "") {
|
||||
chkbox_value = "," + HiddenField1.Value;
|
||||
}
|
||||
|
||||
string powers = "," + admin.info.power;
|
||||
|
||||
DataTable dt = treeDt;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
if (row["root"].ToString() == RootUid.ToString())
|
||||
{
|
||||
string p = "," + row["num"].ToString() + ",";
|
||||
if (powers.IndexOf(p, 0) > -1 || admin.info.group == "EZ")
|
||||
{
|
||||
TreeNode NewNode = new TreeNode();
|
||||
NewNode.Text = row["title"].ToString();
|
||||
NewNode.Value = row["num"].ToString();
|
||||
NewNode.SelectAction = TreeNodeSelectAction.None;
|
||||
NewNode.ToolTip = row["root"].ToString() + "-" + row["num"].ToString();
|
||||
if (!isStrNull(Request["num"]) & chkbox_value.IndexOf(p, 0) > -1)
|
||||
{
|
||||
NewNode.Checked = true;
|
||||
}
|
||||
Nodes.Add(NewNode);
|
||||
if (Level+1<= LevelMax) { BuildChild((int)row["num"], NewNode.ChildNodes, Level + 1); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 修改
|
||||
|
||||
protected void edit_Click(object sender, EventArgs e)
|
||||
{
|
||||
string chk_data = chkData(); //取得勾選權限值
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE admin_group SET demo=?, items=? WHERE g_name=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("demo", demo.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("items", chk_data));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("g_name", Request["num"]));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
|
||||
if(admin.info.group != "EZ")
|
||||
{
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Update, "群組:" + g_name.Text);
|
||||
}
|
||||
|
||||
Response.Redirect("group_show.aspx" + (!isStrNull(Request["page"]) ? "?page=" + Request["page"] : ""));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//取得勾選權限值
|
||||
public string chkData()
|
||||
{
|
||||
|
||||
string chk_data = "";
|
||||
for (int i = 0; i < TreeView1.CheckedNodes.Count; i++)
|
||||
{
|
||||
string chk_data2 = "," + chk_data;
|
||||
//string chk = "," + TreeView1.CheckedNodes[i].Parent.ValuePath + ",";
|
||||
//if (chk_data2.IndexOf(chk, 0) == -1)
|
||||
//{
|
||||
// chk_data += TreeView1.CheckedNodes[i].Parent.ValuePath + ","; //取得主分類編號
|
||||
//}
|
||||
chk_data += TreeView1.CheckedNodes[i].Value.ToString() + ","; //取得勾選分類編號
|
||||
}
|
||||
return chk_data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 新增
|
||||
|
||||
protected void add_Click(object sender, EventArgs e)
|
||||
{
|
||||
L_msg.Text = "";
|
||||
string chk_data = chkData(); //取得勾選權限值
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin_group Where g_name=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("g_name", g_name.Text));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
L_msg.Type = alert_type.warning;
|
||||
L_msg.Text = "您所輸入的群組代號重覆";
|
||||
}
|
||||
else {
|
||||
sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "INSERT INTO admin_group (g_name, items, demo) VALUES (?, ?, ?)";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("g_name", g_name.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("items", chk_data));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("demo",demo.Text));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
|
||||
if (admin.info.group != "EZ")
|
||||
{
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Insert, "群組:" + g_name.Text);
|
||||
}
|
||||
|
||||
Response.Redirect("group_show.aspx");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text =ex.Message;
|
||||
L_msg.Type = alert_type.danger;
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
133
web/admin/user/group_show.aspx
Normal file
133
web/admin/user/group_show.aspx
Normal file
@@ -0,0 +1,133 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" EnableEventValidation = "false" CodeFile="group_show.aspx.cs" Inherits="admin_user_group_show" %>
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" Runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<div class="mb-2 mb-sm-0">
|
||||
<a href="group_reg.aspx" class="btn btn-primary">
|
||||
<i class="mdi mdi-plus"></i> 新增
|
||||
</a>
|
||||
<asp:LinkButton ID="del_all" runat="server" CssClass="btn btn-outline-danger" ToolTip="刪除勾選的資料"
|
||||
OnClientClick="return msgconfirm('是否確定刪除已勾選的管理者資料?',this);" OnClick="del_all_Click">
|
||||
<i class="mdi mdi-trash-can"></i> 刪除勾選
|
||||
</asp:LinkButton>
|
||||
</div>
|
||||
<div class="">
|
||||
<a href="#right_panel2" class="btn btn-primary d-none"
|
||||
data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
|
||||
<i class="mdi mdi-cog"></i>2</a>
|
||||
<a href="#right_panel3" class="btn btn-primary d-none"
|
||||
data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
|
||||
<i class="mdi mdi-cog"></i>3</a>
|
||||
<asp:LinkButton ID="excel" runat="server" Visible="true" CssClass="btn btn-outline-success" OnClick="excel_Click">
|
||||
<i class="mdi mdi-file-excel"></i> 匯出Excel
|
||||
</asp:LinkButton>
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
||||
<uc1:alert runat="server" ID="L_msg" Text=""/>
|
||||
<div id="content" class="container-fluid">
|
||||
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True"
|
||||
OnSelected="ObjectDataSource1_Selected" TypeName="Cus_GetSQL.Get_Data"
|
||||
SelectMethod="Get_ObjectDataSource_Val"
|
||||
SelectCountMethod="getRecordCount"
|
||||
MaximumRowsParameterName="maxinumRows" StartRowIndexParameterName="startRowIndex" SortParameterName="sortExpression">
|
||||
<SelectParameters>
|
||||
<asp:Parameter Name="TableName_val" Type="String" />
|
||||
<asp:Parameter Name="ColumnName_val" Type="String" />
|
||||
<asp:Parameter Name="OrderColumn_val" Type="String" />
|
||||
<asp:Parameter Name="Where_val" Type="String" />
|
||||
</SelectParameters>
|
||||
</asp:ObjectDataSource>
|
||||
<div id="print_data">
|
||||
<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover rounded bg-white shadow gridview"
|
||||
AutoGenerateColumns="False" DataKeyNames="g_name" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
|
||||
DataSourceID="ObjectDataSource1" GridLines="None" AllowPaging="True" PageSize="20" AllowSorting="True">
|
||||
<HeaderStyle CssClass="border-bottom border-secondary bg-light thead" />
|
||||
<Columns>
|
||||
<asp:TemplateField>
|
||||
<HeaderStyle CssClass="d-print-none" />
|
||||
<ItemStyle CssClass="d-print-none" />
|
||||
<HeaderTemplate>
|
||||
<input type="checkbox" id="chkAll" name="chkAll" class="form-check-input" onclick="checkListAll(this.checked)" />
|
||||
</HeaderTemplate>
|
||||
<ItemTemplate>
|
||||
<asp:CheckBox ID="chkSelect1" runat="server" CssClass="" />
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField DataField="g_name" HeaderText="群組代號" SortExpression="g_name" />
|
||||
<asp:BoundField DataField="demo" HeaderText="群組名稱" SortExpression="demo" />
|
||||
<asp:TemplateField HeaderText="">
|
||||
<HeaderStyle CssClass="d-print-none" />
|
||||
<ItemStyle CssClass="d-print-none text-end" />
|
||||
<ItemTemplate>
|
||||
<a href="group_reg.aspx?num=<%# Eval("g_name") %>&page=<%=GridView1.PageIndex%>"
|
||||
title="" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-pencil-box-outline"></i>修改</a>
|
||||
<asp:LinkButton ID="DelButton" runat="server" OnClick="DelButton_Click"
|
||||
OnClientClick="return msgconfirm('是否確定刪除這筆資料?',this);"
|
||||
CssClass="btn btn-outline-secondary btn-sm"><i class="mdi mdi-trash-can"></i>刪除</asp:LinkButton>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
</Columns>
|
||||
<PagerTemplate>
|
||||
<div class="navbar d-print-none py-0">
|
||||
<ul class="pagination m-0">
|
||||
<li class="page-item"><asp:LinkButton ID="FirstButton" runat="server" CommandName="Page" CommandArgument="First" CssClass="page-link">第一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="PreviousButton" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="page-link">上一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="NextButton" runat="server" CommandName="Page" CommandArgument="Next" CssClass="page-link">下一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="LastButton" runat="server" CommandName="Page" CommandArgument="Last" CssClass="page-link">最終頁</asp:LinkButton></li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<asp:Label ID="MessageLabel" runat="server" CssClass="badge text-dark" Text="選擇頁次:" />
|
||||
<asp:DropDownList ID="PageDropDownList" runat="server" CssClass="form-select form-select-sm"
|
||||
AutoPostBack="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" />
|
||||
<asp:Label ID="CurrentPageLabel" CssClass="badge text-dark border-end" runat="server" />
|
||||
<asp:Label ID="total_count" CssClass="badge text-dark me-2" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
</PagerTemplate>
|
||||
</asp:GridView>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content4" ContentPlaceHolderID="offCanvasRight" runat="Server">
|
||||
<div id="search_panel" alt="查詢群組資料">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">群組代號</label>
|
||||
<asp:TextBox ID="search1" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">群組名稱</label>
|
||||
<asp:TextBox ID="search2" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
<div class="mb-3 p-2 border-top">
|
||||
<asp:LinkButton ID="Button1" runat="server" OnClick="Button1_Click" CssClass="btn btn-outline-primary">
|
||||
<i class="mdi mdi-filter"></i> 搜尋</asp:LinkButton>
|
||||
<asp:LinkButton ID="Button_All" runat="server" OnClick="Button_All_Click" CssClass="btn btn-outline-secondary">
|
||||
<i class="mdi mdi-filter-remove"></i> 所有資料</asp:LinkButton>
|
||||
</div>
|
||||
</div>
|
||||
<div id="right_panel2" data-title="功能群組2">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">功能群組2</label>
|
||||
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlTextarea1" class="form-label">Example textarea</label>
|
||||
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div id="right_panel3" data-title="功能群組3">
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlInput1" class="form-label">功能群組3</label>
|
||||
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name@example.com">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="exampleFormControlTextarea1" class="form-label">Example textarea</label>
|
||||
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
393
web/admin/user/group_show.aspx.cs
Normal file
393
web/admin/user/group_show.aspx.cs
Normal file
@@ -0,0 +1,393 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using System.Linq;
|
||||
|
||||
public partial class admin_user_group_show : MyWeb.config
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["TableName_val"].DefaultValue = "[admin_group]";
|
||||
ObjectDataSource1.SelectParameters["ColumnName_val"].DefaultValue = "*";
|
||||
ObjectDataSource1.SelectParameters["OrderColumn_val"].DefaultValue = "g_name";
|
||||
if (admin.info.group != "EZ")
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = "g_name<>'EZ' and g_name<>'A'";
|
||||
}
|
||||
|
||||
//判斷修改完成後,是否有傳「頁數」的值回來
|
||||
if (!isStrNull(Request["page"]))
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
GridView1.PageIndex = Convert.ToInt32(Request["page"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Session["s_msg"] = null;
|
||||
Session["search1"] = null;
|
||||
Session["search2"] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Session["s_msg"] != null)
|
||||
{
|
||||
//L_msg.Text = Session["s_msg"].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//L_msg.Text = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region GridView相關
|
||||
|
||||
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
||||
{
|
||||
if (e.Exception != null)
|
||||
{
|
||||
e.ExceptionHandled = true;
|
||||
Response.Write(e.Exception.Message);
|
||||
}
|
||||
GridViewRow gvrPagerRow = GridView1.BottomPagerRow;
|
||||
}
|
||||
|
||||
protected void GridView1_DataBound(object sender, System.EventArgs e)
|
||||
{
|
||||
if (GridView1.Rows.Count == 0 & GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.DataBind();
|
||||
// 若有查到一筆以上的資料
|
||||
}
|
||||
else if (GridView1.PageCount > 0)
|
||||
{
|
||||
|
||||
GridView1.BottomPagerRow.Visible = true;
|
||||
|
||||
//在pagertemplate裡的控制項中寫入值
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
|
||||
|
||||
|
||||
|
||||
if ((pageList != null))
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i <= GridView1.PageCount - 1; i++)
|
||||
{
|
||||
int pageNumber = i + 1;
|
||||
ListItem item = new ListItem(pageNumber.ToString());
|
||||
|
||||
if (i == GridView1.PageIndex)
|
||||
{
|
||||
item.Selected = true;
|
||||
}
|
||||
|
||||
pageList.Items.Add(item);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Session["s_RecordTotalCount"] != null)
|
||||
{
|
||||
((Label)pagerRow.Cells[0].FindControl("total_count")).Text = "資料總數:<span class='text-primary'>" + Session["s_RecordTotalCount"] + "</span>";
|
||||
//取自 App_Code/Cus_GetSQL.vb 的 Session
|
||||
}
|
||||
|
||||
if ((pageLabel != null))
|
||||
{
|
||||
// 取得正確頁數及更新目前頁次
|
||||
int currentPage = GridView1.PageIndex + 1;
|
||||
pageLabel.Text = "目前頁數:<span class='text-primary'>" + currentPage.ToString() + "</span> / " + GridView1.PageCount.ToString() + "";
|
||||
|
||||
if (currentPage <= 1)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("FirstButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("PreviousButton")).Visible = false;
|
||||
}
|
||||
if (currentPage >= GridView1.PageCount)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("NextButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("LastButton")).Visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
L_msg.Type = alert_type.warning;
|
||||
L_msg.Text = "找不到符合條件資料!";
|
||||
}
|
||||
}
|
||||
|
||||
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
GridView1.PageIndex = pageList.SelectedIndex;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 條件搜尋
|
||||
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Session["search1"] = null;
|
||||
Session["s_msg"] = null;
|
||||
string s_msg = null; this.L_msg.Text = "";
|
||||
|
||||
ArrayList fs = new ArrayList();
|
||||
|
||||
if (admin.info.group != "EZ")
|
||||
{
|
||||
fs.Add("g_name<>'EZ' and g_name<>'A'");
|
||||
}
|
||||
if (search1.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search1.Text.Trim() + "',g_name)>0");
|
||||
s_msg += "群組代號 =【" + search1.Text.Trim() + "】";
|
||||
}
|
||||
if (search2.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search2.Text.Trim() + "',demo)>0");
|
||||
s_msg += "群組名稱 =【" + search2.Text.Trim() + "】";
|
||||
}
|
||||
if (s_msg != null)
|
||||
{
|
||||
Session["s_msg"] = "<strong>搜尋條件:</strong>" + s_msg;
|
||||
//L_msg.Text = Session["s_msg"].ToString();
|
||||
|
||||
Cus_SQL.SQL_Array find_str = new Cus_SQL.SQL_Array();
|
||||
Session["search1"] = find_str.sql_str(fs);
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
|
||||
if (GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.PageIndex = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.Redirect(Request.Url.AbsolutePath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void Button_All_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(Request.Url.AbsolutePath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 刪除
|
||||
|
||||
|
||||
protected void DelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LinkButton DelButton = (LinkButton)sender;
|
||||
GridViewRow oRow = (GridViewRow)DelButton.NamingContainer;
|
||||
int iRowIndex = oRow.RowIndex;
|
||||
string strID = Convert.ToString(GridView1.DataKeys[iRowIndex].Values[0]); //取得主索引(g_name)編號
|
||||
start_del_data(strID);
|
||||
|
||||
|
||||
Literal UserName = (Literal)oRow.FindControl("UserName");
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Delete, "群組:" + UserName.Text);
|
||||
|
||||
GridView1.DataBind();
|
||||
}
|
||||
|
||||
protected void del_all_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<string> x = new List<string>();
|
||||
for (int i = GridView1.Rows.Count - 1; i >= 0; i--)
|
||||
{
|
||||
CheckBox oCheckBox = (CheckBox)GridView1.Rows[i].Cells[GridView1.Columns.Count - 1].FindControl("chkSelect1");
|
||||
Literal UserName = (Literal)GridView1.Rows[i].Cells[GridView1.Columns.Count - 1].FindControl("UserName");
|
||||
if (oCheckBox.Checked)
|
||||
{
|
||||
x.Add(UserName.Text);
|
||||
start_del_data(Convert.ToString(GridView1.DataKeys[i].Values[0]));
|
||||
}
|
||||
}
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Delete, "群組:" + admin_log.LogViewBtn(x));
|
||||
|
||||
GridView1.DataBind();
|
||||
}
|
||||
|
||||
public void start_del_data(string num)
|
||||
{
|
||||
|
||||
var prod = _db.admin_group.AsEnumerable().Where(q => q.g_name == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.admin_group.Remove(prod);
|
||||
_db.SaveChanges(); //執行
|
||||
}
|
||||
// MyWeb.sql sql = new MyWeb.sql();
|
||||
//OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
//try
|
||||
//{
|
||||
// sqlConn.Open();
|
||||
// OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
// sqlCmd.CommandText = "Delete from admin_group Where g_name=?";
|
||||
// sqlCmd.Parameters.Add(new OleDbParameter("g_name", num));
|
||||
// sqlCmd.ExecuteNonQuery();
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// Response.Write(ex.Message);
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// sqlConn.Close(); sqlConn.Dispose();
|
||||
//}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 匯出Excel
|
||||
|
||||
protected void excel_Click(object sender, EventArgs e)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
using (var doc = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook))
|
||||
{
|
||||
var wb = doc.AddWorkbookPart();
|
||||
wb.Workbook = new Workbook();
|
||||
var sheets = wb.Workbook.AppendChild(new Sheets());
|
||||
|
||||
//建立第一個頁籤
|
||||
var ws = wb.AddNewPart<WorksheetPart>();
|
||||
ws.Worksheet = new Worksheet();
|
||||
sheets.Append(new Sheet()
|
||||
{
|
||||
Id = wb.GetIdOfPart(ws),
|
||||
SheetId = 1,
|
||||
Name = "群組資料"
|
||||
});
|
||||
|
||||
//設定欄寬
|
||||
var cu = new Columns();
|
||||
cu.Append(
|
||||
new Column { Min = 1, Max = 1, Width = 10, CustomWidth = true },
|
||||
new Column { Min = 2, Max = 2, Width = 15, CustomWidth = true }
|
||||
);
|
||||
ws.Worksheet.Append(cu);
|
||||
|
||||
//建立資料頁
|
||||
var sd = new SheetData();
|
||||
ws.Worksheet.AppendChild(sd);
|
||||
|
||||
//第一列資料
|
||||
var tr = new Row();
|
||||
tr.Append(
|
||||
new Cell() { CellValue = new CellValue("群組代號"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("群組名稱"), DataType = CellValues.String }
|
||||
);
|
||||
sd.AppendChild(tr);
|
||||
|
||||
//查詢要匯出的資料
|
||||
string table = ObjectDataSource1.SelectParameters["TableName_val"].DefaultValue;
|
||||
string column = ObjectDataSource1.SelectParameters["ColumnName_val"].DefaultValue;
|
||||
string sort = ObjectDataSource1.SelectParameters["OrderColumn_val"].DefaultValue;
|
||||
string query = ObjectDataSource1.SelectParameters["Where_val"].DefaultValue;
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT " + column + " FROM " + table;
|
||||
if (!isStrNull(query)) { sqlCmd.CommandText += " where " + query; }
|
||||
sqlCmd.CommandText += " order by " + sort;
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
List<string> x = new List<string>();
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
//新增資料列
|
||||
tr = new Row();
|
||||
tr.Append(
|
||||
new Cell() { CellValue = new CellValue(ValString(row["g_name"])), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(ValString(row["demo"])), DataType = CellValues.String }
|
||||
);
|
||||
sd.AppendChild(tr);
|
||||
|
||||
x.Add(ValString(row["g_name"]));
|
||||
}
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Excel, "群組:"+ admin_log.LogViewBtn(x));
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close();
|
||||
sqlConn.Dispose();
|
||||
}
|
||||
|
||||
//儲存文件(如果有要儲實體的檔案在upload才需要)
|
||||
//wb.Workbook.Save();
|
||||
}
|
||||
|
||||
HttpContext.Current.Response.Clear();
|
||||
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=群組資料.xlsx");
|
||||
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
|
||||
HttpContext.Current.Response.End();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
169
web/admin/user/index.aspx
Normal file
169
web/admin/user/index.aspx
Normal file
@@ -0,0 +1,169 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="index.aspx.cs" Inherits="admin_user_index" %>
|
||||
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<div class="mb-2 mb-sm-0">
|
||||
<a href="reg.aspx" class="btn btn-primary">
|
||||
<i class="mdi mdi-plus"></i> 新增
|
||||
</a>
|
||||
<asp:LinkButton ID="del_all" runat="server" CssClass="btn btn-outline-danger" ToolTip="刪除勾選的資料"
|
||||
OnClientClick="return msgconfirm('是否確定刪除已勾選的管理者資料?',this);" OnClick="del_all_Click">
|
||||
<i class="mdi mdi-trash-can"></i> 刪除勾選</asp:LinkButton>
|
||||
|
||||
</div>
|
||||
<div class="">
|
||||
|
||||
<asp:LinkButton ID="excel" runat="server" Visible="false" CssClass="btn btn-outline-primary" OnClick="excel_Click"><span class="fa-solid fa-file-excel"></span> 匯出Excel</asp:LinkButton>
|
||||
|
||||
</div>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
|
||||
<uc1:alert runat="server" ID="L_msg" Text="" />
|
||||
<div id="content" class="container-fluid">
|
||||
|
||||
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True"
|
||||
OnSelected="ObjectDataSource1_Selected" TypeName="Cus_GetSQL.Get_Data"
|
||||
SelectMethod="Get_ObjectDataSource_Val"
|
||||
SelectCountMethod="getRecordCount"
|
||||
MaximumRowsParameterName="maxinumRows" StartRowIndexParameterName="startRowIndex" SortParameterName="sortExpression">
|
||||
<SelectParameters>
|
||||
<asp:Parameter Name="TableName_val" Type="String" />
|
||||
<asp:Parameter Name="ColumnName_val" Type="String" />
|
||||
<asp:Parameter Name="OrderColumn_val" Type="String" />
|
||||
<asp:Parameter Name="Where_val" Type="String" />
|
||||
</SelectParameters>
|
||||
</asp:ObjectDataSource>
|
||||
<div id="print_data">
|
||||
|
||||
<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover rounded bg-white shadow gridview"
|
||||
AutoGenerateColumns="False" DataKeyNames="num" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
|
||||
DataSourceID="ObjectDataSource1" GridLines="None" AllowPaging="True" PageSize="20" AllowSorting="True">
|
||||
<HeaderStyle CssClass="border-bottom border-secondary bg-light thead" />
|
||||
|
||||
<Columns>
|
||||
|
||||
<asp:TemplateField>
|
||||
<HeaderStyle CssClass="hidden-print" />
|
||||
<ItemStyle CssClass="hidden-print" />
|
||||
<HeaderTemplate>
|
||||
<input type="checkbox" id="chkAll" name="chkAll" class="form-check-input" onclick="checkListAll(this.checked)" />
|
||||
</HeaderTemplate>
|
||||
<ItemTemplate>
|
||||
<asp:CheckBox ID="chkSelect1" runat="server" CssClass="" />
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
|
||||
|
||||
<asp:BoundField DataField="u_id" HeaderText="帳號" SortExpression="u_id" />
|
||||
<asp:TemplateField HeaderText="群組" SortExpression="power">
|
||||
<ItemTemplate>
|
||||
<%#get_my_group(Eval("power").ToString())%>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:BoundField DataField="u_name" HeaderText="姓名" SortExpression="u_name" />
|
||||
<asp:TemplateField HeaderText="登入時間" SortExpression="login_time">
|
||||
<ItemTemplate>
|
||||
<%# Eval("login_time") %>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
|
||||
<asp:BoundField DataField="login_ip" HeaderText="登入IP" SortExpression="login_ip" />
|
||||
<asp:TemplateField HeaderText="狀態" SortExpression="online">
|
||||
<ItemTemplate>
|
||||
<asp:DropDownList ID="online" runat="server" AutoPostBack="true" OnSelectedIndexChanged="online_SelectedIndexChanged" CssClass="form-select">
|
||||
<asp:ListItem Value="-1" Text="啟用"></asp:ListItem>
|
||||
<asp:ListItem Value="0" Text="停權"></asp:ListItem>
|
||||
</asp:DropDownList>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
|
||||
|
||||
<asp:TemplateField HeaderText="">
|
||||
<HeaderStyle CssClass="d-print-none" />
|
||||
<ItemStyle CssClass="d-print-none text-end" />
|
||||
<ItemTemplate>
|
||||
<a href="reg.aspx?num=<%# Eval("num") %>&page=<%=GridView1.PageIndex%>"
|
||||
title="" class="btn btn-outline-secondary btn-sm"><i class="mdi mdi-pencil-box-outline"></i>修改</a>
|
||||
<asp:LinkButton ID="DelButton" runat="server" OnClick="DelButton_Click"
|
||||
OnClientClick="return msgconfirm('是否確定刪除這筆資料?',this);"
|
||||
CssClass="btn btn-outline-secondary btn-sm"><i class="mdi mdi-trash-can"></i>刪除</asp:LinkButton>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
|
||||
|
||||
</Columns>
|
||||
<PagerTemplate>
|
||||
<div class="navbar d-print-none py-0">
|
||||
<ul class="pagination m-0">
|
||||
<li class="page-item"><asp:LinkButton ID="FirstButton" runat="server" CommandName="Page" CommandArgument="First" CssClass="page-link">第一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="PreviousButton" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="page-link">上一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="NextButton" runat="server" CommandName="Page" CommandArgument="Next" CssClass="page-link">下一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="LastButton" runat="server" CommandName="Page" CommandArgument="Last" CssClass="page-link">最終頁</asp:LinkButton></li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<asp:Label ID="MessageLabel" runat="server" CssClass="badge text-dark" Text="選擇頁次:" />
|
||||
<asp:DropDownList ID="PageDropDownList" runat="server" CssClass="form-select form-select-sm"
|
||||
AutoPostBack="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" />
|
||||
<asp:Label ID="CurrentPageLabel" CssClass="badge text-dark border-end" runat="server" />
|
||||
<asp:Label ID="total_count" CssClass="badge text-dark me-2" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</PagerTemplate>
|
||||
</asp:GridView>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content4" ContentPlaceHolderID="offCanvasRight" runat="Server">
|
||||
<div id="search_panel" alt="查詢使用者資料">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">帳號</label>
|
||||
<asp:TextBox ID="search1" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">姓名</label>
|
||||
<asp:TextBox ID="search2" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">群組</label>
|
||||
<asp:DropDownList ID="search3" runat="server" CssClass="form-select"></asp:DropDownList>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">登入日期</label>
|
||||
<div class="input-group">
|
||||
<asp:TextBox ID="start_day" runat="server" CssClass="form-control" type="date" autocomplete="off"
|
||||
data-date-format="yyyy-mm-dd"></asp:TextBox>
|
||||
<span class="input-group-text">~</span>
|
||||
<asp:TextBox ID="end_day" runat="server" CssClass="form-control" type="date" autocomplete="off"
|
||||
data-date-format="yyyy-mm-dd"></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">登入IP</label>
|
||||
<asp:TextBox ID="search5" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">狀態</label>
|
||||
<asp:DropDownList ID="search4" runat="server" CssClass="form-select">
|
||||
<asp:ListItem></asp:ListItem>
|
||||
<asp:ListItem Value="-1" Text="啟用"></asp:ListItem>
|
||||
<asp:ListItem Value="0" Text="停權"></asp:ListItem>
|
||||
</asp:DropDownList>
|
||||
</div>
|
||||
<div class="mb-3 p-2 border-top">
|
||||
<asp:LinkButton ID="Button1" runat="server" OnClick="Button1_Click" CssClass="btn btn-outline-primary">
|
||||
<i class="mdi mdi-filter"></i> 搜尋</asp:LinkButton>
|
||||
<asp:LinkButton ID="Button_All" runat="server" OnClick="Button_All_Click" CssClass="btn btn-outline-secondary">
|
||||
<i class="mdi mdi-filter-remove"></i> 所有資料</asp:LinkButton>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
456
web/admin/user/index.aspx.cs
Normal file
456
web/admin/user/index.aspx.cs
Normal file
@@ -0,0 +1,456 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
|
||||
public partial class admin_user_index : MyWeb.config
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
|
||||
ObjectDataSource1.SelectParameters["TableName_val"].DefaultValue = "[admin]";
|
||||
ObjectDataSource1.SelectParameters["ColumnName_val"].DefaultValue = "*";
|
||||
ObjectDataSource1.SelectParameters["OrderColumn_val"].DefaultValue = "num desc";
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = "power<>'EZ'";
|
||||
if (admin.info.group != "EZ")
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue += " and power <> 'A'";
|
||||
}
|
||||
|
||||
|
||||
add_group();
|
||||
|
||||
//判斷修改完成後,是否有傳「頁數」的值回來
|
||||
if (!isStrNull(Request["page"]))
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
GridView1.PageIndex = Convert.ToInt32(Request["page"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Session["s_msg"] = null;
|
||||
Session["search1"] = null;
|
||||
Session["search2"] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Session["s_msg"] != null)
|
||||
{
|
||||
// s_msg.Text = Session["s_msg"].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//s_msg.Text = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public string get_my_group(string power)
|
||||
{
|
||||
string group = "<font color=\"red\">不存在</font>";
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "select g_name,demo from admin_group where g_name=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("g_name", power));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
group = dt.Rows[0]["g_name"].ToString() + "." + dt.Rows[0]["demo"].ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
#region 抓權限群組
|
||||
|
||||
public void add_group() {
|
||||
|
||||
search3.Items.Add("");
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT g_name,demo FROM admin_group";
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; i < dt.Rows.Count; i++) {
|
||||
if (dt.Rows[i]["g_name"].ToString() != "EZ")
|
||||
{
|
||||
ListItem list;
|
||||
list = new ListItem(dt.Rows[i]["g_name"].ToString() + "." + dt.Rows[i]["demo"].ToString(), dt.Rows[i]["g_name"].ToString());
|
||||
if (dt.Rows[i]["g_name"].ToString() == "A")
|
||||
{
|
||||
if (admin.info.group == "EZ")
|
||||
{
|
||||
search3.Items.Add(list);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
search3.Items.Add(list);
|
||||
}
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GridView相關
|
||||
|
||||
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
||||
{
|
||||
if (e.Exception != null)
|
||||
{
|
||||
e.ExceptionHandled = true;
|
||||
Response.Write(e.Exception.Message);
|
||||
}
|
||||
GridViewRow gvrPagerRow = GridView1.BottomPagerRow;
|
||||
}
|
||||
|
||||
protected void GridView1_DataBound(object sender, System.EventArgs e)
|
||||
{
|
||||
if (GridView1.Rows.Count == 0 & GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.DataBind();
|
||||
// 若有查到一筆以上的資料
|
||||
}
|
||||
else if (GridView1.PageCount > 0)
|
||||
{
|
||||
|
||||
GridView1.BottomPagerRow.Visible = true;
|
||||
|
||||
//在pagertemplate裡的控制項中寫入值
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
|
||||
|
||||
|
||||
|
||||
if ((pageList != null))
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i <= GridView1.PageCount - 1; i++)
|
||||
{
|
||||
int pageNumber = i + 1;
|
||||
ListItem item = new ListItem(pageNumber.ToString());
|
||||
|
||||
if (i == GridView1.PageIndex)
|
||||
{
|
||||
item.Selected = true;
|
||||
}
|
||||
|
||||
pageList.Items.Add(item);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Session["s_RecordTotalCount"] != null)
|
||||
{
|
||||
((Label)pagerRow.Cells[0].FindControl("total_count")).Text = "資料總數:<font color='red'><b>" + Session["s_RecordTotalCount"] + "</b></font>";
|
||||
//取自 App_Code/Cus_GetSQL.vb 的 Session
|
||||
}
|
||||
|
||||
if ((pageLabel != null))
|
||||
{
|
||||
// 取得正確頁數及更新目前頁次
|
||||
int currentPage = GridView1.PageIndex + 1;
|
||||
pageLabel.Text = "目前頁數:<b><font color='red'>" + currentPage.ToString() + "</font> / " + GridView1.PageCount.ToString() + "</b>";
|
||||
|
||||
if (currentPage <= 1)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("FirstButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("PreviousButton")).Visible = false;
|
||||
}
|
||||
if (currentPage >= GridView1.PageCount)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("NextButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("LastButton")).Visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
L_msg.Type = alert_type.warning;
|
||||
L_msg.Text = "找不到符合條件資料!";
|
||||
}
|
||||
}
|
||||
|
||||
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
|
||||
DataRowView data = (DataRowView)e.Row.DataItem;
|
||||
|
||||
DropDownList online = (DropDownList)e.Row.FindControl("online");
|
||||
if ((bool)data["online"])
|
||||
{
|
||||
online.SelectedIndex = 0;
|
||||
}
|
||||
else {
|
||||
online.SelectedIndex = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
GridView1.PageIndex = pageList.SelectedIndex;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 狀態變更
|
||||
|
||||
protected void online_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
DropDownList online = (DropDownList)sender;
|
||||
GridViewRow oRow = (GridViewRow)online.NamingContainer;
|
||||
int iRowIndex = oRow.RowIndex;
|
||||
string strID = Convert.ToString(GridView1.DataKeys[iRowIndex].Values[0]); //取得主索引(num)編號
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "update admin set online=? where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("online", online.SelectedValue));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", strID));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
ScriptMsgTop("操作成功!", msgIcon.success);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ScriptMsgTop("操作失敗!", msgIcon.error);
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
GridView1.DataBind();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 條件搜尋
|
||||
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Session["search1"] = null;
|
||||
Session["s_msg"] = null;
|
||||
string s_msg = null; this.L_msg.Text = "";
|
||||
|
||||
ArrayList fs = new ArrayList();
|
||||
fs.Add("power<>'EZ'");
|
||||
if (admin.info.group != "EZ") { fs.Add("power<>'A'"); }
|
||||
|
||||
|
||||
if (search1.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search1.Text.Trim() + "',u_id)>0");
|
||||
s_msg += "帳號 =【" + search1.Text.Trim() + "】";
|
||||
}
|
||||
|
||||
if (search2.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search2.Text.Trim() + "',u_name)>0");
|
||||
s_msg += "姓名 =【" + search2.Text.Trim() + "】";
|
||||
}
|
||||
|
||||
if (search3.SelectedIndex > 0)
|
||||
{
|
||||
fs.Add("power = '" + search3.SelectedValue + "'");
|
||||
s_msg += "權限 =【" + search3.SelectedItem.Text + "】";
|
||||
}
|
||||
|
||||
if (search4.SelectedIndex > 0)
|
||||
{
|
||||
fs.Add("online = " + search4.SelectedValue);
|
||||
s_msg += "狀態 =【" + search4.SelectedItem.Text + "】";
|
||||
}
|
||||
|
||||
if (search5.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search5.Text.Trim() + "',login_ip)>0");
|
||||
s_msg += "登入ip =【" + search5.Text.Trim() + "】";
|
||||
}
|
||||
|
||||
if (selectDate(start_day) != DBNull.Value)
|
||||
{
|
||||
DateTime s1 = ValDate(start_day.Text);
|
||||
fs.Add("login_time >= '" + s1.ToString("yyyy-MM-dd") + "'");
|
||||
s_msg += "登入日期(起) =【" + start_day.Text + "】";
|
||||
}
|
||||
|
||||
if (selectDate(end_day) != DBNull.Value)
|
||||
{
|
||||
DateTime s2 = ValDate(end_day.Text);
|
||||
s2 = s2.AddDays(1);
|
||||
fs.Add("login_time < '" + s2.ToString("yyyy-MM-dd") + "'");
|
||||
s_msg += "登入日期(訖) =【" + end_day.Text + "】";
|
||||
}
|
||||
|
||||
if (s_msg != null)
|
||||
{
|
||||
Session["s_msg"] = "<span class=\"word9\">搜尋條件:</span>" + s_msg;
|
||||
//this.s_msg.Text = Session["s_msg"].ToString();
|
||||
|
||||
Cus_SQL.SQL_Array find_str = new Cus_SQL.SQL_Array();
|
||||
Session["search1"] = find_str.sql_str(fs);
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
|
||||
if (GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.PageIndex = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void Button_All_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(Request.Url.AbsolutePath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 刪除
|
||||
|
||||
protected void DelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LinkButton DelButton = (LinkButton)sender;
|
||||
GridViewRow oRow = (GridViewRow)DelButton.NamingContainer;
|
||||
int iRowIndex = oRow.RowIndex;
|
||||
string strID = Convert.ToString(GridView1.DataKeys[iRowIndex].Values[0]); //取得主索引(num)編號
|
||||
start_del_data(strID);
|
||||
|
||||
Literal UserName = (Literal)oRow.FindControl("UserName");
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Delete, "使用者:" + UserName.Text);
|
||||
|
||||
GridView1.DataBind();
|
||||
}
|
||||
|
||||
|
||||
protected void del_all_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<string> x = new List<string>();
|
||||
for (int i = GridView1.Rows.Count - 1; i >= 0; i--)
|
||||
{
|
||||
CheckBox oCheckBox = (CheckBox)GridView1.Rows[i].Cells[GridView1.Columns.Count - 1].FindControl("chkSelect1");
|
||||
Literal UserName = (Literal)GridView1.Rows[i].Cells[GridView1.Columns.Count - 1].FindControl("UserName");
|
||||
if (oCheckBox.Checked)
|
||||
{
|
||||
x.Add(UserName.Text);
|
||||
start_del_data(Convert.ToString(GridView1.DataKeys[i].Values[0]));
|
||||
}
|
||||
}
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Delete, "使用者:" + admin_log.LogViewBtn(x));
|
||||
|
||||
GridView1.DataBind();
|
||||
}
|
||||
|
||||
public void start_del_data(string num)
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "Delete from admin Where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", num));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 匯出Excel
|
||||
|
||||
protected void excel_Click(object sender, EventArgs e)
|
||||
{
|
||||
//請參考訂單系統的匯出
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
134
web/admin/user/log.aspx
Normal file
134
web/admin/user/log.aspx
Normal file
@@ -0,0 +1,134 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="log.aspx.cs" Inherits="admin_user_log1" %>
|
||||
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<div class="mb-2 mb-sm-0">
|
||||
</div>
|
||||
<div class="">
|
||||
<asp:LinkButton ID="excel" runat="server" CssClass="btn btn-outline-success" OnClick="excel_Click"><span class="glyphicon glyphicon-floppy-save"></span> 匯出Excel</asp:LinkButton>
|
||||
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
|
||||
<uc1:alert runat="server" ID="L_msg" Text="" />
|
||||
<div id="content" class="container-md">
|
||||
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="True"
|
||||
OnSelected="ObjectDataSource1_Selected" TypeName="Cus_GetSQL.Get_Data"
|
||||
SelectMethod="Get_ObjectDataSource_Val"
|
||||
SelectCountMethod="getRecordCount"
|
||||
MaximumRowsParameterName="maxinumRows" StartRowIndexParameterName="startRowIndex" SortParameterName="sortExpression">
|
||||
<SelectParameters>
|
||||
<asp:Parameter Name="TableName_val" Type="String" />
|
||||
<asp:Parameter Name="ColumnName_val" Type="String" />
|
||||
<asp:Parameter Name="OrderColumn_val" Type="String" />
|
||||
<asp:Parameter Name="Where_val" Type="String" />
|
||||
</SelectParameters>
|
||||
</asp:ObjectDataSource>
|
||||
<div id="print_data">
|
||||
<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover rounded bg-white shadow gridview"
|
||||
AutoGenerateColumns="False" DataKeyNames="num" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
|
||||
DataSourceID="ObjectDataSource1" GridLines="None" AllowPaging="True" PageSize="20" AllowSorting="True">
|
||||
<HeaderStyle CssClass="border-bottom border-secondary bg-light thead" />
|
||||
<Columns>
|
||||
|
||||
|
||||
|
||||
<asp:BoundField DataField="login_time" HeaderText="時間" SortExpression="login_time" />
|
||||
<asp:BoundField DataField="u_id" HeaderText="帳號" SortExpression="u_id" />
|
||||
|
||||
<asp:BoundField DataField="agent" HeaderText="裝置" SortExpression="agent" Visible="false" />
|
||||
|
||||
|
||||
<asp:BoundField DataField="login_ip" HeaderText="IP" SortExpression="login_ip" />
|
||||
<asp:TemplateField HeaderText="操作功能" SortExpression ="systems">
|
||||
<ItemTemplate>
|
||||
<%# !isStrNull(Eval("systems"))? GetEnumsDescription( (Model.admin_log.Systems) Eval("systems")) :"" %>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField HeaderText="操作行為" SortExpression ="status">
|
||||
<ItemTemplate>
|
||||
<asp:Label ID="status" runat="server" ></asp:Label>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField HeaderText="說明" SortExpression ="word">
|
||||
<ItemTemplate>
|
||||
<asp:Label ID="word" runat="server" ></asp:Label>
|
||||
</ItemTemplate>
|
||||
</asp:TemplateField>
|
||||
|
||||
|
||||
</Columns>
|
||||
<PagerTemplate>
|
||||
|
||||
<div class="navbar d-print-none py-0">
|
||||
<ul class="pagination m-0">
|
||||
<li class="page-item"><asp:LinkButton ID="FirstButton" runat="server" CommandName="Page" CommandArgument="First" CssClass="page-link">第一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="PreviousButton" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="page-link">上一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="NextButton" runat="server" CommandName="Page" CommandArgument="Next" CssClass="page-link">下一頁</asp:LinkButton></li>
|
||||
<li class="page-item"><asp:LinkButton ID="LastButton" runat="server" CommandName="Page" CommandArgument="Last" CssClass="page-link">最終頁</asp:LinkButton></li>
|
||||
</ul>
|
||||
|
||||
<div class="d-flex align-items-center">
|
||||
<asp:Label ID="MessageLabel" runat="server" CssClass="badge text-dark" Text="選擇頁次:" />
|
||||
<asp:DropDownList ID="PageDropDownList" runat="server" CssClass="form-select form-select-sm"
|
||||
AutoPostBack="true" OnSelectedIndexChanged="PageDropDownList_SelectedIndexChanged" />
|
||||
<asp:Label ID="CurrentPageLabel" CssClass="badge text-dark border-end" runat="server" />
|
||||
<asp:Label ID="total_count" CssClass="badge text-dark me-2" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</PagerTemplate>
|
||||
</asp:GridView>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content4" ContentPlaceHolderID="offCanvasRight" runat="Server">
|
||||
<div id="search_panel" alt="查詢LOG資料">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">帳號</label>
|
||||
<asp:TextBox ID="search1" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">IP</label>
|
||||
<asp:TextBox ID="search2" runat="server" CssClass="form-control" placeholder="可輸入關鍵字查詢"></asp:TextBox>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">操作功能</label>
|
||||
<asp:DropDownList ID="search4" runat="server" CssClass="form-select ">
|
||||
<asp:ListItem></asp:ListItem>
|
||||
|
||||
</asp:DropDownList>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">操作行為</label>
|
||||
<asp:DropDownList ID="search3" runat="server" CssClass="form-select ">
|
||||
<asp:ListItem></asp:ListItem>
|
||||
|
||||
</asp:DropDownList>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">日期</label>
|
||||
<div class="input-group">
|
||||
<asp:TextBox ID="start_day" runat="server" CssClass="form-control datepicker" autocomplete="off" TextMode="Date"></asp:TextBox>
|
||||
<span class="input-group-text">~</span>
|
||||
<asp:TextBox ID="end_day" runat="server" CssClass="form-control datepicker" autocomplete="off" TextMode="Date"></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 p-2 border-top">
|
||||
<asp:LinkButton ID="Button1" runat="server" OnClick="Button1_Click" CssClass="btn btn-outline-primary">
|
||||
<i class="mdi mdi-filter"></i> 搜尋</asp:LinkButton>
|
||||
<asp:LinkButton ID="Button_All" runat="server" OnClick="Button_All_Click" CssClass="btn btn-outline-secondary">
|
||||
<i class="mdi mdi-filter-remove"></i> 所有資料</asp:LinkButton>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
360
web/admin/user/log.aspx.cs
Normal file
360
web/admin/user/log.aspx.cs
Normal file
@@ -0,0 +1,360 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
public partial class admin_user_log1 : MyWeb.config
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (!IsPostBack)
|
||||
{
|
||||
|
||||
ObjectDataSource1.SelectParameters["TableName_val"].DefaultValue = "[admin_log]";
|
||||
ObjectDataSource1.SelectParameters["ColumnName_val"].DefaultValue = "*";
|
||||
ObjectDataSource1.SelectParameters["OrderColumn_val"].DefaultValue = "num desc";
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = "";
|
||||
|
||||
InitEnumsOptions<Model.admin_log.Status>(search3);
|
||||
InitEnumsOptions<Model.admin_log.Systems>(search4);
|
||||
|
||||
//判斷修改完成後,是否有傳「頁數」的值回來
|
||||
if (!isStrNull(Request["page"]))
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
GridView1.PageIndex = Convert.ToInt32(Request["page"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Session["s_msg"] = null;
|
||||
Session["search1"] = null;
|
||||
Session["search2"] = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Session["search1"] != null)
|
||||
{
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Session["s_msg"] != null)
|
||||
{
|
||||
// s_msg.Text = Session["s_msg"].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
//s_msg.Text = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region GridView相關
|
||||
|
||||
protected void ObjectDataSource1_Selected(object sender, ObjectDataSourceStatusEventArgs e)
|
||||
{
|
||||
if (e.Exception != null)
|
||||
{
|
||||
e.ExceptionHandled = true;
|
||||
Response.Write(e.Exception.Message);
|
||||
}
|
||||
GridViewRow gvrPagerRow = GridView1.BottomPagerRow;
|
||||
}
|
||||
|
||||
protected void GridView1_DataBound(object sender, System.EventArgs e)
|
||||
{
|
||||
if (GridView1.Rows.Count == 0 & GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.DataBind();
|
||||
// 若有查到一筆以上的資料
|
||||
}
|
||||
else if (GridView1.PageCount > 0)
|
||||
{
|
||||
|
||||
GridView1.BottomPagerRow.Visible = true;
|
||||
|
||||
//在pagertemplate裡的控制項中寫入值
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
Label pageLabel = (Label)pagerRow.Cells[0].FindControl("CurrentPageLabel");
|
||||
|
||||
|
||||
|
||||
if ((pageList != null))
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i <= GridView1.PageCount - 1; i++)
|
||||
{
|
||||
int pageNumber = i + 1;
|
||||
ListItem item = new ListItem(pageNumber.ToString());
|
||||
|
||||
if (i == GridView1.PageIndex)
|
||||
{
|
||||
item.Selected = true;
|
||||
}
|
||||
|
||||
pageList.Items.Add(item);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Session["s_RecordTotalCount"] != null)
|
||||
{
|
||||
((Label)pagerRow.Cells[0].FindControl("total_count")).Text = "資料總數:<font color='red'><b>" + Session["s_RecordTotalCount"] + "</b></font>";
|
||||
//取自 App_Code/Cus_GetSQL.vb 的 Session
|
||||
}
|
||||
|
||||
if ((pageLabel != null))
|
||||
{
|
||||
// 取得正確頁數及更新目前頁次
|
||||
int currentPage = GridView1.PageIndex + 1;
|
||||
pageLabel.Text = "目前頁數:<b><font color='red'>" + currentPage.ToString() + "</font> / " + GridView1.PageCount.ToString() + "</b>";
|
||||
|
||||
if (currentPage <= 1)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("FirstButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("PreviousButton")).Visible = false;
|
||||
}
|
||||
if (currentPage >= GridView1.PageCount)
|
||||
{
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("NextButton")).Visible = false;
|
||||
((LinkButton)pagerRow.Cells[0].FindControl("LastButton")).Visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
L_msg.Type = alert_type.warning;
|
||||
L_msg.Text = "找不到符合條件資料!";
|
||||
}
|
||||
}
|
||||
|
||||
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
|
||||
{
|
||||
if (e.Row.RowType == DataControlRowType.DataRow)
|
||||
{
|
||||
DataRowView row = (DataRowView)e.Row.DataItem;
|
||||
|
||||
Model.admin_log.Status myStatus = (Model.admin_log.Status)Val(row["status"]);
|
||||
Label status = (Label)e.Row.FindControl("status");
|
||||
status.Text = GetEnumsDescription(myStatus);
|
||||
|
||||
|
||||
|
||||
Model.admin_log.Detail LoginDetail = (Model.admin_log.Detail)Val(row["word"]);
|
||||
Label word = (Label)e.Row.FindControl("word");
|
||||
word.Text = ValString(row["word"]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
GridViewRow pagerRow = GridView1.BottomPagerRow;
|
||||
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
|
||||
GridView1.PageIndex = pageList.SelectedIndex;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 條件搜尋
|
||||
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Session["search1"] = null;
|
||||
Session["s_msg"] = null;
|
||||
string s_msg = null; this.L_msg.Text = "";
|
||||
|
||||
ArrayList fs = new ArrayList();
|
||||
|
||||
|
||||
if (search1.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search1.Text.Trim() + "',u_id)>0");
|
||||
s_msg += "帳號 =【" + search1.Text.Trim() + "】";
|
||||
}
|
||||
|
||||
if (search2.Text.Trim() != "")
|
||||
{
|
||||
fs.Add("CHARINDEX(N'" + search2.Text.Trim() + "',login_ip)>0");
|
||||
s_msg += "登入ip =【" + search2.Text.Trim() + "】";
|
||||
}
|
||||
|
||||
if (search3.SelectedIndex > 0)
|
||||
{
|
||||
fs.Add("status = " + search3.SelectedValue);
|
||||
s_msg += "事件 =【" + search3.SelectedItem.Text + "】";
|
||||
}
|
||||
|
||||
if (search4.SelectedIndex > 0)
|
||||
{
|
||||
fs.Add("systems = " + search4.SelectedValue);
|
||||
s_msg += "系統 =【" + search4.SelectedItem.Text + "】";
|
||||
}
|
||||
if (selectDate(start_day) != DBNull.Value)
|
||||
{
|
||||
DateTime s1 = ValDate(start_day.Text);
|
||||
fs.Add("login_time >= '" + s1.ToString("yyyy-MM-dd") + "'");
|
||||
s_msg += "登入日期(起) =【" + start_day.Text + "】";
|
||||
}
|
||||
|
||||
if (selectDate(end_day) != DBNull.Value)
|
||||
{
|
||||
DateTime s2 = ValDate(end_day.Text);
|
||||
s2 = s2.AddDays(1);
|
||||
fs.Add("login_time < '" + s2.ToString("yyyy-MM-dd") + "'");
|
||||
s_msg += "登入日期(訖) =【" + end_day.Text + "】";
|
||||
}
|
||||
|
||||
if (s_msg != null)
|
||||
{
|
||||
Session["s_msg"] = "<span class=\"word9\">搜尋條件:</span>" + s_msg;
|
||||
//this.s_msg.Text = Session["s_msg"].ToString();
|
||||
|
||||
Cus_SQL.SQL_Array find_str = new Cus_SQL.SQL_Array();
|
||||
Session["search1"] = find_str.sql_str(fs);
|
||||
ObjectDataSource1.SelectParameters["Where_val"].DefaultValue = ValString(Session["search1"]);
|
||||
|
||||
if (GridView1.PageCount > 0)
|
||||
{
|
||||
GridView1.PageIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected void Button_All_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect(Request.Url.AbsolutePath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 匯出Excel
|
||||
|
||||
protected void excel_Click(object sender, EventArgs e)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
using (var doc = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook))
|
||||
{
|
||||
var wb = doc.AddWorkbookPart();
|
||||
wb.Workbook = new Workbook();
|
||||
var sheets = wb.Workbook.AppendChild(new Sheets());
|
||||
|
||||
//建立第一個頁籤
|
||||
var ws = wb.AddNewPart<WorksheetPart>();
|
||||
ws.Worksheet = new Worksheet();
|
||||
sheets.Append(new Sheet()
|
||||
{
|
||||
Id = wb.GetIdOfPart(ws),
|
||||
SheetId = 1,
|
||||
Name = "登入記錄"
|
||||
});
|
||||
|
||||
//設定欄寬
|
||||
var cu = new Columns();
|
||||
cu.Append(
|
||||
new Column { Min = 1, Max = 1, Width = 25, CustomWidth = true },
|
||||
new Column { Min = 2, Max = 3, Width = 10, CustomWidth = true },
|
||||
new Column { Min = 4, Max = 4, Width = 15, CustomWidth = true },
|
||||
new Column { Min = 5, Max = 5, Width = 15, CustomWidth = true }
|
||||
);
|
||||
ws.Worksheet.Append(cu);
|
||||
|
||||
//建立資料頁
|
||||
var sd = new SheetData();
|
||||
ws.Worksheet.AppendChild(sd);
|
||||
|
||||
//第一列資料
|
||||
var tr = new Row();
|
||||
tr.Append(
|
||||
new Cell() { CellValue = new CellValue("時間"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("帳號"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("裝置"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("IP"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("系統"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("事件"), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue("狀態"), DataType = CellValues.String }
|
||||
);
|
||||
sd.AppendChild(tr);
|
||||
|
||||
//查詢要匯出的資料
|
||||
string table = ObjectDataSource1.SelectParameters["TableName_val"].DefaultValue;
|
||||
string column = ObjectDataSource1.SelectParameters["ColumnName_val"].DefaultValue;
|
||||
string sort = ObjectDataSource1.SelectParameters["OrderColumn_val"].DefaultValue;
|
||||
string query = ObjectDataSource1.SelectParameters["Where_val"].DefaultValue;
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT " + column + " FROM " + table;
|
||||
if (!isStrNull(query)) { sqlCmd.CommandText += " where " + query; }
|
||||
sqlCmd.CommandText += " order by " + sort;
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
//新增資料列
|
||||
tr = new Row();
|
||||
tr.Append(
|
||||
new Cell() { CellValue = new CellValue(ValString(row["login_time"])), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(ValString(row["u_id"])), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(ValString(row["agent"])), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(ValString(row["login_ip"])), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(!isStrNull(row["systems"])? GetEnumsDescription((Model.admin_log.Systems)Val(row["systems"])):"" ), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(GetEnumsDescription((Model.admin_log.Status)Val(row["status"])) ), DataType = CellValues.String },
|
||||
new Cell() { CellValue = new CellValue(ValString(row["word"])), DataType = CellValues.String }
|
||||
);
|
||||
sd.AppendChild(tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close();
|
||||
sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HttpContext.Current.Response.Clear();
|
||||
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=登入記錄.xlsx");
|
||||
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
|
||||
HttpContext.Current.Response.End();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
66
web/admin/user/pass_edit.aspx
Normal file
66
web/admin/user/pass_edit.aspx
Normal file
@@ -0,0 +1,66 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="pass_edit.aspx.cs" Inherits="admin_user_pass_edit" %>
|
||||
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<nav class="mb-1">
|
||||
</nav>
|
||||
<nav class="mb-1">
|
||||
<asp:Button ID="edit" runat="server" Text="變更密碼" OnClick="edit_Click" CssClass="btn btn-primary" />
|
||||
|
||||
</nav>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
|
||||
|
||||
<uc1:alert runat="server" ID="L_msg" Text="" />
|
||||
<div id="content" class="container-fluid">
|
||||
<div class="card shadow-sm my-3">
|
||||
<div class="card-header">
|
||||
變更後端使用者密碼
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<div>
|
||||
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 帳號</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static">
|
||||
<asp:Label ID="L_u_id" runat="server"></asp:Label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 新密碼</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="Password" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
<asp:RegularExpressionValidator ControlToValidate="Password" Display="Dynamic" ID="psdRule" runat="server" SetFocusOnError="true" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 確認新密碼</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="ConfirmPassword" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator
|
||||
ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" Display="Dynamic" SetFocusOnError="true"
|
||||
ErrorMessage="必填!"></asp:RequiredFieldValidator>
|
||||
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" Display="Dynamic" SetFocusOnError="true"
|
||||
ControlToValidate="ConfirmPassword" ErrorMessage="密碼和確認密碼必須相符。"></asp:CompareValidator>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</asp:Content>
|
||||
|
||||
91
web/admin/user/pass_edit.aspx.cs
Normal file
91
web/admin/user/pass_edit.aspx.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
|
||||
|
||||
public partial class admin_user_pass_edit : MyWeb.config
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) {
|
||||
|
||||
MyWeb.security security = new MyWeb.security();
|
||||
psdRule.ValidationExpression = security.PasswordValidator();
|
||||
psdRule.ErrorMessage = security.PasswordNotice();
|
||||
if (isStrNull(psdRule.ValidationExpression))
|
||||
psdRule.Visible = false;
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin Where u_id=? and num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_id", admin.info.u_id));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", admin.info.num));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
L_u_id.Text = dt.Rows[0]["u_id"].ToString();
|
||||
|
||||
|
||||
ViewState["num"] = dt.Rows[0]["num"].ToString();
|
||||
}
|
||||
else {
|
||||
ScriptMsg2("無此帳號!", "../index2.aspx", msgIcon.error);
|
||||
//Response.Redirect("../index2.aspx");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#region 資料修改
|
||||
|
||||
#endregion
|
||||
|
||||
protected void edit_Click(object sender, EventArgs e)
|
||||
{
|
||||
L_msg.Text = "";
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE admin SET u_password=? WHERE num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_password", encrypt.EncryptAutoKey(Password.Text)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", ViewState["num"].ToString()));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
L_msg.Type = alert_type.success;
|
||||
L_msg.Text = "資料修改成功,新的密碼將於下次登錄生效!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text = ex.Message;
|
||||
L_msg.Type = alert_type.danger;
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
232
web/admin/user/reg.aspx
Normal file
232
web/admin/user/reg.aspx
Normal file
@@ -0,0 +1,232 @@
|
||||
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="reg.aspx.cs" Inherits="admin_user_reg" %>
|
||||
|
||||
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="footer_script" runat="Server">
|
||||
<link href="../../App_Script/bootstrap_toggle/css/bootstrap-toggle.min.css" rel="stylesheet" />
|
||||
<script src="../../App_Script/bootstrap_toggle/js/bootstrap-toggle.min.js"></script>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
|
||||
<div class="scroll-nav nav nav-tabs mb-2 mb-sm-0 d-none d-sm-flex">
|
||||
</div>
|
||||
<div class="">
|
||||
<asp:Button ID="edit" runat="server" Text="修改" OnClick="edit_Click" CssClass="btn btn-primary" />
|
||||
<asp:Button ID="add" runat="server" Text="新增" OnClick="add_Click" CssClass="btn btn-primary" />
|
||||
<asp:Button ID="goback" runat="server" Text="回列表" CausesValidation="false" Visible="false" OnClick="goback_Click" CssClass="btn btn-outline-secondary" />
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
|
||||
<uc1:alert runat="server" ID="L_msg" Text="" />
|
||||
<div id="content" class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-7">
|
||||
<div class="card shadow-sm my-3">
|
||||
<div class="card-header">
|
||||
後端使用者資料
|
||||
</div>
|
||||
<div class="card-body label-sm-right">
|
||||
<div>
|
||||
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 帳號</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="UserName" MaxLength="25" runat="server" CssClass="form-control" placeholder="請輸入帳號"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="UserName" Display="Dynamic" ErrorMessage="必填!" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
<asp:RegularExpressionValidator ControlToValidate="UserName" Display="Dynamic" SetFocusOnError="true" ErrorMessage="請輸入英文或數字!" ID="RegularExpressionValidator2" runat="server" ValidationExpression="^[A-Za-z0-9]+$" />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<asp:PlaceHolder ID="PlaceHolder3" runat="server">
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 密碼</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="Password" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control" placeholder="請輸入密碼"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" Display="Dynamic" SetFocusOnError="true" ErrorMessage="必填!"></asp:RequiredFieldValidator>
|
||||
<asp:RegularExpressionValidator ControlToValidate="Password" Display="Dynamic" ID="psdRule" runat="server" SetFocusOnError="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 確認密碼</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="ConfirmPassword" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control" placeholder="再次輸入密碼"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" ErrorMessage="密碼和確認密碼必須相符。" Display="Dynamic" SetFocusOnError="true"></asp:CompareValidator>
|
||||
</div>
|
||||
</div>
|
||||
</asp:PlaceHolder>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 所屬群組</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:DropDownList ID="group" runat="server" CssClass="form-select">
|
||||
</asp:DropDownList>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="group" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 姓名</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="user_name" MaxLength="25" runat="server" CssClass="form-control" placeholder="請輸入姓名"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="user_name" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible="false">
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 性別</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:DropDownList ID="sex" runat="server" CssClass="form-select">
|
||||
<asp:ListItem Selected="True" Value="男">男</asp:ListItem>
|
||||
<asp:ListItem Value="女">女</asp:ListItem>
|
||||
</asp:DropDownList>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="sex" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">生日</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="birthday" CssClass="form-control datepicker" autocomplete="off" runat="server" Style="width: auto" data-date-format="yyyy-mm-dd"></asp:TextBox>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">電話</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="phone1" MaxLength="25" runat="server" CssClass="form-control"></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">行動電話</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="phone2" MaxLength="25" runat="server" CssClass="form-control"></asp:TextBox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">E-mail</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="email" MaxLength="100" runat="server" CssClass="form-control"></asp:TextBox>
|
||||
<asp:RegularExpressionValidator ControlToValidate="email" Display="Dynamic" SetFocusOnError="true" ErrorMessage="格式有誤!" ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">備註說明</label>
|
||||
<div class="col-sm-10">
|
||||
<asp:TextBox ID="demo" runat="server" CssClass="form-control"></asp:TextBox>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</asp:PlaceHolder>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-2 col-form-label">* 狀態</label>
|
||||
<div class="col-sm-10">
|
||||
<label class="col-form-control">
|
||||
<input type="checkbox" id="online" runat="server"
|
||||
data-toggle="toggle" data-on="啟用" data-off="停權" data-onstyle="success" />
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<asp:PlaceHolder ID="PlaceHolder2" runat="server" Visible="false">
|
||||
<div class="card shadow-sm my-3">
|
||||
<div class="card-header">
|
||||
密碼變更
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-3 col-form-label">* 新密碼</label>
|
||||
<div class="col-sm-9">
|
||||
<asp:TextBox ID="u_password" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ValidationGroup="chpws" ID="RequiredFieldValidator3" runat="server" ControlToValidate="u_password" ErrorMessage="必填!" Display="Dynamic"></asp:RequiredFieldValidator>
|
||||
<asp:RegularExpressionValidator ControlToValidate="u_password" Display="Dynamic" ID="psdRule2" runat="server" SetFocusOnError="true" ValidationGroup="chpws" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-3 col-form-label">* 確認密碼</label>
|
||||
<div class="col-sm-9">
|
||||
<asp:TextBox ID="u_password2" MaxLength="25" runat="server" TextMode="Password" CssClass="form-control"></asp:TextBox>
|
||||
<asp:RequiredFieldValidator ValidationGroup="chpws" ID="RequiredFieldValidator4" runat="server" ControlToValidate="u_password2" ErrorMessage="必填!" Display="Dynamic"></asp:RequiredFieldValidator>
|
||||
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="u_password" ControlToValidate="u_password2" ErrorMessage="密碼和確認密碼必須相符。" Display="Dynamic"></asp:CompareValidator>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<div class="col-12">
|
||||
<asp:LinkButton ID="chpws_bt" runat="server" ValidationGroup="chpws" OnClick="chpws_bt_Click" CssClass="btn btn-outline-primary"><i class="mdi mdi-key-variant"></i> 變更密碼</asp:LinkButton>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</asp:PlaceHolder>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<div class="card shadow-sm my-3">
|
||||
<div class="card-header">
|
||||
Google Authenticator 綁定
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row mb-1">
|
||||
<div class="col-md-6">
|
||||
<asp:Button ID="btn_bindgen" runat="server" OnClick="btn_bindgen_Click"
|
||||
class="btn btn-primary" Text="產生綁定碼"/>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-check">
|
||||
<asp:CheckBox CssClass=""
|
||||
id="chkGauthEnabled" runat="server" Text="啟用"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 mt-2">
|
||||
<h5>QR-Code</h5>
|
||||
<div>
|
||||
<asp:Image id="qrcode" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<h5>驗證測試:</h5>
|
||||
<label class="col-sm-2 col-form-label">驗證碼</label>
|
||||
<div class="col-10">
|
||||
<div class="input-group mb-3">
|
||||
<asp:TextBox type="text" ID="txtValid" runat="server" CssClass="form-control"
|
||||
placeholder="驗證碼" aria-label="驗證碼"/>
|
||||
<asp:Button ID="btnValid" runat="server" CssClass="btn btn-primary" Text="驗證" OnClick="btnValid_Click" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
驗證結果:<asp:Label ID="valid_result" runat="server" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<div class="col-12">
|
||||
<hr />
|
||||
<h5>綁定資訊:</h5>
|
||||
<ul>
|
||||
<li>使用者帳號: <span> <asp:Literal ID="txtUser" runat="server"></asp:Literal> </span></li>
|
||||
<li>網站代號: <span> <asp:Literal ID="txtWebKey" runat="server"></asp:Literal> </span></li>
|
||||
<li>使用者密碼: <span> <asp:Literal ID="txtPassword" runat="server"></asp:Literal> </span></li>
|
||||
<li>動態密鑰: <span> <asp:Literal ID="txtSecretKey" runat="server"></asp:Literal> </span></li>
|
||||
<li>setupCode: <span> <asp:Literal ID="txtSetupCode" runat="server"></asp:Literal> </span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</asp:Content>
|
||||
|
||||
387
web/admin/user/reg.aspx.cs
Normal file
387
web/admin/user/reg.aspx.cs
Normal file
@@ -0,0 +1,387 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Configuration;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
public partial class admin_user_reg : MyWeb.config
|
||||
{
|
||||
public GoogleAuth gauth;
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack) {
|
||||
MyWeb.security security = new MyWeb.security();
|
||||
psdRule.ValidationExpression = security.PasswordValidator();
|
||||
psdRule.ErrorMessage = security.PasswordNotice();
|
||||
if (isStrNull(psdRule.ValidationExpression))
|
||||
psdRule.Visible = false;
|
||||
|
||||
psdRule2.ValidationExpression = security.PasswordValidator();
|
||||
psdRule2.ErrorMessage = security.PasswordNotice();
|
||||
if (isStrNull(psdRule2.ValidationExpression))
|
||||
psdRule2.Visible = false;
|
||||
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin Where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
UserName.Text = dt.Rows[0]["u_id"].ToString();
|
||||
UserName.ReadOnly = true;
|
||||
//UserName.BorderStyle = BorderStyle.None;
|
||||
//UserName.BackColor = System.Drawing.Color.Transparent;
|
||||
PlaceHolder3.Visible = false;
|
||||
PlaceHolder2.Visible = true;
|
||||
user_name.Text = dt.Rows[0]["u_name"].ToString();
|
||||
sex.SelectedValue = dt.Rows[0]["sex"].ToString();
|
||||
if (dt.Rows[0]["birthday"] != DBNull.Value)
|
||||
{
|
||||
birthday.Text = ValDate(dt.Rows[0]["birthday"]).ToString("yyyy-MM-dd");
|
||||
}
|
||||
|
||||
phone1.Text = dt.Rows[0]["phone1"].ToString();
|
||||
phone2.Text = dt.Rows[0]["phone2"].ToString();
|
||||
email.Text = dt.Rows[0]["email"].ToString();
|
||||
demo.Text = dt.Rows[0]["demo"].ToString();
|
||||
|
||||
edit.Visible = true;
|
||||
goback.Visible = true;
|
||||
add.Visible = false;
|
||||
|
||||
online.Checked = ((bool)dt.Rows[0]["online"] ? true : false);
|
||||
chkGauthEnabled.Checked = false;
|
||||
if(dt.Rows[0]["gauth_enabled"]!=DBNull.Value)
|
||||
{
|
||||
chkGauthEnabled.Checked=(bool)dt.Rows[0]["gauth_enabled"];
|
||||
}
|
||||
|
||||
|
||||
add_group(dt.Rows[0]["power"].ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
online.Checked = true;
|
||||
edit.Visible = false;
|
||||
|
||||
add_group("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void goback_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
||||
}
|
||||
|
||||
#region 抓權限群組
|
||||
|
||||
public void add_group(string power)
|
||||
{
|
||||
|
||||
group.Items.Add( new ListItem("請選擇", ""));
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT g_name,demo FROM admin_group";
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; i < dt.Rows.Count; i++) {
|
||||
if (dt.Rows[i]["g_name"].ToString() != "EZ")
|
||||
{
|
||||
ListItem list;
|
||||
list = new ListItem(dt.Rows[i]["g_name"].ToString() + "." + dt.Rows[i]["demo"].ToString(), dt.Rows[i]["g_name"].ToString());
|
||||
if (power == dt.Rows[i]["g_name"].ToString())
|
||||
{
|
||||
list.Selected = true;
|
||||
}
|
||||
if (dt.Rows[i]["g_name"].ToString() == "A")
|
||||
{
|
||||
if (admin.info.group == "EZ")
|
||||
{
|
||||
group.Items.Add(list);
|
||||
}
|
||||
}
|
||||
else {
|
||||
group.Items.Add(list);
|
||||
}
|
||||
}
|
||||
else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 資料修改
|
||||
|
||||
protected void edit_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE admin SET u_name=?, sex=?, birthday=?, phone1=?, phone2=?, "+
|
||||
" email=?, demo=?, power=?, online=?, gauth_enabled=? WHERE num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_name", user_name.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("sex", sex.SelectedValue));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("birthday", selectDate(birthday)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("phone1", phone1.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("phone2", phone2.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("email", email.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("demo", demo.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("power", group.SelectedValue));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("online", (online.Checked ? 1 : 0)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("gauth_enabled", (chkGauthEnabled.Checked ? 1 : 0)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Update,"使用者:"+ UserName.Text);
|
||||
|
||||
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write(ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 資料新增
|
||||
|
||||
protected void add_Click(object sender, EventArgs e)
|
||||
{
|
||||
L_msg.Text = "";
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin Where u_id=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_id", UserName.Text));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
L_msg.Type = alert_type.warning;
|
||||
L_msg.Text = "您所輸入的帳號重覆";
|
||||
}
|
||||
else {
|
||||
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
string cu = "u_id,u_password,u_name,sex,birthday,phone1,phone2,email,power,demo,kind,online";
|
||||
|
||||
sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "INSERT INTO admin (" + cu + ")";
|
||||
sqlCmd.CommandText += " VALUES (" + sql.mark(cu) + ")";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_id", UserName.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_password", encrypt.EncryptAutoKey(Password.Text)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_name", user_name.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("sex", sex.SelectedValue));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("birthday", selectDate(birthday)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("phone1", phone1.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("phone2", phone2.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("email", email.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("power", group.SelectedValue));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("demo", demo.Text));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("kind", "管理者"));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("online", (online.Checked ? 1 : 0)));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Insert, "使用者:" + UserName.Text);
|
||||
|
||||
Response.Redirect("index.aspx");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text = ex.Message;
|
||||
L_msg.Type = alert_type.danger;
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 變更密碼
|
||||
|
||||
protected void chpws_bt_Click(object sender, EventArgs e)
|
||||
{
|
||||
L_msg.Text = "";
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "UPDATE admin SET u_password=? where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("u_password", encrypt.EncryptAutoKey(u_password.Text)));
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
sqlCmd.ExecuteNonQuery();
|
||||
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Power, (int)Model.admin_log.Status.Update, "變更密碼:" + UserName.Text);
|
||||
|
||||
L_msg.Type = alert_type.success;
|
||||
L_msg.Text = "密碼變更成功";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Type = alert_type.danger;
|
||||
L_msg.Text = "密碼變更失敗";
|
||||
}
|
||||
finally
|
||||
{
|
||||
sqlConn.Close(); sqlConn.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
protected void btn_bindgen_Click(object sender, EventArgs e)
|
||||
{
|
||||
gauth = new GoogleAuth();
|
||||
|
||||
//gauth.User = "user";
|
||||
//gauth.Password = "pass";
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin Where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
var r = dt.Rows[0];
|
||||
gauth.SecretKey = "SecKey";
|
||||
gauth.User = r["u_id"].ToString();
|
||||
gauth.Password = r["u_password"].ToString();
|
||||
gauth.SecretKey = randKey(20);
|
||||
|
||||
System.Drawing.Image img = gauth.CreateSecretKeyAndQrCode();
|
||||
string base64 = gauth.ImageToBase64(img);
|
||||
qrcode.ImageUrl = base64;
|
||||
|
||||
txtUser.Text = gauth.User;
|
||||
txtPassword.Text = gauth.Password;
|
||||
txtWebKey.Text = gauth.WebKey;
|
||||
txtSecretKey.Text = gauth.SecretKey;
|
||||
txtSetupCode.Text = gauth.setupCode.ManualEntryKey;
|
||||
|
||||
//update: gauth_key , gauth_enabled
|
||||
OleDbCommand updCmd = new OleDbCommand("", sqlConn);
|
||||
updCmd.CommandText = "update admin set gauth_key=? , gauth_enabled=1 Where num=?";
|
||||
updCmd.Parameters.Add(new OleDbParameter("gauth_key", gauth.SecretKey));
|
||||
updCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
int updr = updCmd.ExecuteNonQuery();
|
||||
chkGauthEnabled.Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void btnValid_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Get User Info
|
||||
MyWeb.sql sql = new MyWeb.sql();
|
||||
OleDbConnection sqlConn = sql.conn(db, p_name);
|
||||
try
|
||||
{
|
||||
sqlConn.Open();
|
||||
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
|
||||
sqlCmd.CommandText = "SELECT * FROM admin Where num=?";
|
||||
sqlCmd.Parameters.Add(new OleDbParameter("num", Request["num"]));
|
||||
DataTable dt = sql.dataTable(sqlCmd);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
var userr=dt.Rows[0];
|
||||
|
||||
// GAuth
|
||||
gauth = new GoogleAuth();
|
||||
gauth.User = userr["u_id"].ToString();
|
||||
gauth.Password = userr["u_password"].ToString();
|
||||
gauth.SecretKey = userr["gauth_key"].ToString();
|
||||
//gauth.setupCode.ManualEntryKey = txtSetupCode.Text;
|
||||
|
||||
string ValidateCode = txtValid.Text;
|
||||
bool r = gauth.ValidateGoogleAuthCode(ValidateCode);
|
||||
valid_result.Text = r ? "(Y)通過驗證" : "(X)未通過驗證";
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user