📄 wfselectlog.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WFselect : System.Web.UI.Page
{
protected System.Data.DataView dataView1;
protected System.Data.DataSet dataSet1;
protected System.Data.Odbc.OdbcCommand odbcSelectCommand1;
protected System.Data.Odbc.OdbcCommand odbcInsertCommand1;
protected System.Data.Odbc.OdbcCommand odbcUpdateCommand1;
protected System.Data.Odbc.OdbcCommand odbcDeleteCommand1;
protected System.Data.Odbc.OdbcDataAdapter odbcDataAdapter1;
protected System.Data.Odbc.OdbcConnection odbcConnection1;
protected System.Data.Odbc.OdbcCommand odbcCommand1;
public static int pageCount;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.DataGrid DataGrid1; //总页面数
public static int curPageIndex=1;
protected System.Web.UI.WebControls.Button btnQuery;
protected System.Web.UI.WebControls.Button btnClear;
//protected System.Web.UI.WebControls.DropDownList ddlUser;
protected System.Web.UI.WebControls.DropDownList ddlAction;
protected System.Web.UI.WebControls.LinkButton lbtnPrev;
protected System.Web.UI.WebControls.LinkButton lbtnNext;
protected System.Web.UI.WebControls.TextBox txtStartDate;
protected System.Web.UI.WebControls.TextBox txtEndDate;
protected System.Web.UI.WebControls.Label Label1;
protected System.Data.DataSet dsUser;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label9; //当前页面
private string selectstr ;
private string strUser ;
private string strUserName;
private string strDept;
private string strDeptName;
private string strCurDate;
private string strCurTime;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.WebControls.DropDownList ddlUser;
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid1.PageSize= Convert.ToInt32(TextBox4.Text);
strUser = (string)Session["strUser"];
strUserName = (string)Session["strUserName"];
strDept = (string)Session["strDept"];
strDeptName = (string)Session["strDeptName"];
if (!Page.IsPostBack)
{
strCurDate = DateTime.Now.ToString("yyyy'-'MM'-'dd");
strCurTime = DateTime.Now.ToString("HH':'mm");
add_menusto_DropDownList1();
add_Userto_ddlUser();
txtStartDate.Text=strCurDate;
txtEndDate.Text=strCurDate;
// btnQuery_Click(sender,e);
if (!Global.CheckUserValidation((string)Session["strRole"], Global.MENU_LOGER))
{
Response.Redirect("err_session.htm", true);
}
//Global.WriteLog(ref odbcConnection1, strUser,Global.MENU_LOGER,Global.ACTION_OTHER,"登陆");
selectdata();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataView1 = new System.Data.DataView();
this.dataSet1 = new System.Data.DataSet();
this.odbcSelectCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcInsertCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcUpdateCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcDeleteCommand1 = new System.Data.Odbc.OdbcCommand();
this.odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter();
this.odbcConnection1 = new System.Data.Odbc.OdbcConnection();
this.odbcCommand1 = new System.Data.Odbc.OdbcCommand();
this.dsUser = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dsUser)).BeginInit();
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
this.lbtnPrev.Click += new System.EventHandler(this.lbtnPrev_Click);
this.lbtnNext.Click += new System.EventHandler(this.lbtnNext_Click);
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// odbcDataAdapter1
//
this.odbcDataAdapter1.DeleteCommand = this.odbcDeleteCommand1;
this.odbcDataAdapter1.InsertCommand = this.odbcInsertCommand1;
this.odbcDataAdapter1.SelectCommand = this.odbcSelectCommand1;
this.odbcDataAdapter1.UpdateCommand = this.odbcUpdateCommand1;
//
// dsUser
//
this.dsUser.DataSetName = "NewDataSet";
this.dsUser.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dsUser)).EndInit();
}
#endregion
private void add_Userto_ddlUser()
{
string selectstr1;
selectstr1="SELECT manager_id ,name "+
"FROM t_manager";
connectionDB();
odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter ( selectstr1 ,odbcConnection1 ) ;
dataSet1 =new DataSet() ;
odbcDataAdapter1.Fill ( dataSet1 ,"t_manager" ) ;
ddlUser.DataValueField="manager_id";
ddlUser.DataTextField="name";
DataView dataView1= dataSet1.Tables ["t_manager" ].DefaultView ;
ddlUser.DataSource = dataView1 ;
ddlUser.DataBind();
ListItem Item = new ListItem();
Item.Text = "所有用户";
Item.Value ="all";
ddlUser.Items.Insert(0,Item);
}
private void add_menusto_DropDownList1()
{
string selectstr1;
selectstr1=" SELECT menu_id ,`desc` "+
"FROM t_sys_menu";
connectionDB();
odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter ( selectstr1 ,odbcConnection1 ) ;
dataSet1 =new DataSet() ;
odbcDataAdapter1.Fill ( dataSet1 , "t_sys_menu" ) ;
DropDownList1.DataValueField="menu_id";
DropDownList1.DataTextField="desc";
DataView dataView1= dataSet1.Tables [ "t_sys_menu" ].DefaultView ;
DropDownList1.DataSource = dataView1 ;
DropDownList1.DataBind() ;
ListItem Item = new ListItem();
Item.Text = "所有菜单";
Item.Value ="all";
DropDownList1.Items.Insert(0,Item);
}
private void connectionDB()
{
Global.OpenConnection(ref odbcConnection1);
}
private void closeDB()
{
odbcConnection1.Close();
}
private void btnQuery_Click(object sender, System.EventArgs e)
{
if ((!RangeValidator2.IsValid)||(txtStartDate.Text==""))
{
Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:起始日期格式不对!"")</script>");
return;
}
if ((!RangeValidator1.IsValid)||(txtEndDate.Text==""))
{
Page.RegisterStartupScript("alert", @"<script language=""javascript"">window.alert(""错误:结束日期格式不对!"")</script>");
return;
}
DataGrid1.CurrentPageIndex=0;
selectdata();
DataGrid1.HeaderStyle.Height=30;
}
private void selectdata()
{
string wherestr="";
if (txtStartDate.Text!="")
{
wherestr="time >= '"+txtStartDate.Text+"' and ";
}
if (txtEndDate.Text!="")
{
wherestr+="time <= '"+txtEndDate.Text+" 59:59:59"+"' and ";
}
if (ddlUser.SelectedValue!="all")
{
wherestr+="manager_id ='"+ddlUser.SelectedValue+"' and ";
}
if (ddlAction.SelectedValue!="all")
{
wherestr+="action ='"+ddlAction.SelectedValue+"' and ";
}
if (DropDownList1.SelectedValue!="all")
{
wherestr+="menu_id ='"+DropDownList1.SelectedValue+"'";
}
else
{
wherestr+="1=1";
}
// selectstr=" SELECT time as '时间', manager_id as '操作员', menu_id as '系统菜单', `action` as '动作', action_str as '详细信息'"+
// "FROM t_sys_log where " + wherestr+" order by time desc";
selectstr=" SELECT `time` , `manager_id`, `menu_id` , `action` , `action_str` "+
"FROM t_sys_log where " + wherestr+" order by time desc";
connectionDB();
odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter ( selectstr ,odbcConnection1 ) ;
dataSet1 =new DataSet() ;
odbcDataAdapter1.Fill ( dataSet1 , "t_sys_log" ) ;
//DataRow Dr;
foreach (DataRow Dr in dataSet1.Tables ["t_sys_log"].Rows)
{
for(int ii=0; ii<ddlUser.Items.Count;ii++ )
{
if (Dr["manager_id"].ToString()==ddlUser.Items[ii].Value)
{
Dr["manager_id"] = ddlUser.Items[ii].Text;
}
}
for(int ii=0; ii<DropDownList1.Items.Count;ii++ )
{
if (Dr["menu_id"].ToString()==DropDownList1.Items[ii].Value)
{
Dr["menu_id"] = DropDownList1.Items[ii].Text;
}
}
for(int ii=0; ii<ddlAction.Items.Count;ii++ )
{
if (Dr["action"].ToString()==ddlAction.Items[ii].Value)
{
Dr["action"] = ddlAction.Items[ii].Text;
}
}
}
DataView dataView1 = dataSet1.Tables [ "t_sys_log" ].DefaultView ;
DataGrid1.DataSource = dataView1 ;
DataGrid1.DataBind() ;
DataGrid1.HeaderStyle.Height=2;
//Global.WriteLog(ref odbcConnection1, strUser,Global.MENU_LOGER, Global.ACTION_OTHER,"selectstr");
odbcConnection1.Close();
PageIndexNbr();
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
selectdata();
PageIndexNbr();
}
private void PageIndexNbr()
{
Label7.Text = "第 " + (DataGrid1.CurrentPageIndex + 1).ToString() + " 页/共 " + DataGrid1.PageCount.ToString() + " 页";
}
private void btnClear_Click(object sender, System.EventArgs e)
{
// btnQuery_Click(sender,e);
txtStartDate.Text="";
txtEndDate.Text="";
ddlUser.SelectedIndex = 0;
ddlAction.SelectedIndex = 0;
}
private void lbtnNext_Click(object sender, System.EventArgs e)
{
if(DataGrid1.CurrentPageIndex< (DataGrid1.PageCount - 1))
{
DataGrid1.CurrentPageIndex += 1;
curPageIndex +=1;
}
selectdata();
PageIndexNbr();
odbcConnection1.Close();
}
private void lbtnPrev_Click(object sender, System.EventArgs e)
{
if(DataGrid1.CurrentPageIndex >0)
{
DataGrid1.CurrentPageIndex -= 1;
curPageIndex -=1;
}
selectdata();
PageIndexNbr();
odbcConnection1.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -