456 lines
14 KiB
C#
456 lines
14 KiB
C#
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
|
||
|
||
|
||
|
||
} |