⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operlogmanage.aspx.cs

📁 CRM管理系统 CRM管理系统
💻 CS
字号:
using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itsv.BLL;
using Itsv.BLL.SystemManage;
using Itsv.Model;


/// <summary>
/// 操作日志管理
/// </summary>
/// <remarks>
/// 完成人:刘建伟
/// 完成时间:2007-3-30
/// </remarks>
public partial class SystemManage_OperLogManage : PageBase
{
    private string strWhere;

    #region 邦定GridView的功能函数

    /// <summary>
    /// 邦定GridView的功能函数
    /// </summary>
    /// <param name="sortStr">排序字段</param>
    /// <param name="sortDirection">排序方向:Desc,Asc</param>
    /// <param name="strWhere">sql Where语句</param>
    /// <remarks>
    /// 完成人:刘建伟
    /// 完成时间:2007-3-30
    /// </remarks>
    private void BindOperlogmanage(string sortStr, string sortDirection, string strWhere)
    {
        user_actionBLL uaBLL = new user_actionBLL();
        strWhere = "1=1 " + strWhere;
        DataSet ds = uaBLL.GetList(strWhere);

        if (ds.Tables[0].Rows.Count == 0)
        {
            this.lblErrorStr.Text = "没有符合当前条件的数据!!";
            this.gvOperlogmanage.DataSource = ds.Tables[0];
            this.gvOperlogmanage.DataBind();
            this.lblErrorStr.Visible = true;
            return;
        }
        this.lblErrorStr.Visible = false;

        DataTable dt = ds.Tables[0];
        dt.Columns.Add("Count");
        DataView dv = dt.DefaultView;

        if (sortStr != null && sortStr != string.Empty)
        {
            dv.Sort = sortStr + " " + sortDirection;
        }
        else
        {
            dv.Sort = "id desc";
        }
        this.gvOperlogmanage.DataKeyNames = new string[1] { "id" };
        this.gvOperlogmanage.DataSource = dv;
        this.gvOperlogmanage.DataBind();
    }
    #endregion

    #region 功能函数
    /// <summary>
    /// 判断object是否为时间格式
    /// </summary>
    /// <param name="time"></param>
    /// <returns></returns>
    private bool IsDateTime(object time)
    {
        try
        {
            DateTime.Parse(time.ToString());
            return true;
        }
        catch
        {
            return false;
        }
    }

    /// <summary>
    /// 判断是否为数子
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public bool IsNumberic(object str)
    {
        try
        {
            int.Parse(str.ToString());
            return true;
        }
        catch
        {
            return false;
        }
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnDelete.Attributes.Add("onclick", "if( checkChk()){return confirm('确定将选中的记录删除吗?');};");
        this.btnDeleteAll.Attributes.Add("onclick", "return confirm('确定已经备份了全部信息吗?');");
        if (!Page.IsPostBack)
        {
            this.cldBegin.Text = DateTime.Now.AddMonths(-1).ToShortDateString();
            this.cldEnd.Text = DateTime.Now.ToShortDateString();
            if (Session["strWhereOperLog"] != null)
            {
                strWhere = Session["strWhereOperLog"].ToString();
            }
            else
            {
                strWhere = "and date_time >= '" + cldBegin.Text.Trim().Replace("'", "\"") + "' ";
                Session["strWhereOperLog"] = strWhere;
            }
            BindOperlogmanage("", "", strWhere);
            Session["direction"] = "";
            Session["sortStr"] = "";
        }
    }

    protected void gvOperlogmanage_Sorting(object sender, GridViewSortEventArgs e)
    {
        strWhere = Session["strWhereOperLog"].ToString();
        if (e.SortExpression != "")
        {
            Session["sortStr"] = e.SortExpression;
            if (Session["direction"] != null && Session["direction"].ToString() == "Desc")
            {
                Session["direction"] = "Asc";
            }
            else
            {
                Session["direction"] = "Desc";
            }
            BindOperlogmanage(Session["sortStr"].ToString(), Session["direction"].ToString(), strWhere);
        }
    }

    protected void gvOperlogmanage_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        strWhere = Session["strWhereOperLog"].ToString();
        this.gvOperlogmanage.PageIndex = e.NewPageIndex;
        BindOperlogmanage(Session["sortStr"].ToString(), Session["direction"].ToString(), strWhere);
    }

    protected void gvOperlogmanage_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Click")
        {
            TextBox tb = (TextBox)gvOperlogmanage.BottomPagerRow.FindControl("txtPages");
            if (tb == null || tb.Text.Trim().Length == 0 || !IsNumberic(tb.Text.Trim()))
            {
                return;
            }

            int page = Convert.ToInt32(tb.Text.Trim());

            if (page > gvOperlogmanage.PageCount)
            {
                page = gvOperlogmanage.PageCount;
            }
            if (page < 1)
            {
                page = 1;
            }

            this.gvOperlogmanage.PageIndex = page - 1;
            strWhere = Session["strWhereOperLog"].ToString();
            BindOperlogmanage(Session["sortStr"].ToString(), Session["direction"].ToString(), strWhere);
        }
    }
    /// <summary>
    /// 按开始与结束时间及操作人查询日志信息
    /// </summary>
    /// <remarks>
    /// 完成人:刘建伟
    /// 完成时间:2007-3-30
    /// </remarks>
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        //按开始与结束时间及操作人查询日志信息
        strWhere = null;

        System.Text.StringBuilder stbWhere = new System.Text.StringBuilder();

        if (this.cldBegin.Text.Trim().Length > 0)
        {
            if (IsDateTime(cldBegin.Text.Trim()))
            {
                stbWhere.Append("and date_time >= '" + DateTime.Parse(this.cldBegin.Text.Trim().Replace("'", "\"")).ToString("yyyy-MM-dd 00:00:00") + "' ");
            }
            else
            {
                this.msg = "日期格式输入不正确;\\r\\n";
            }
        }

        if (this.cldEnd.Text.Trim().Length > 0)
        {
            if (IsDateTime(cldEnd.Text.Trim()))
            {
                stbWhere.Append("and date_time <= '" + DateTime.Parse(this.cldEnd.Text.Trim().Replace("'", "\"")).ToString("yyyy-MM-dd 23:59:59") + "' ");
            }
            else
            {
                this.msg = "日期格式输入不正确;\\r\\n";
            }
        }

        if (this.operUser.Text.Trim().Length > 0)
        {
            stbWhere.Append(" and account like '%" + this.operUser.Text.Trim().Replace("'", "\"") + "%'");
        }

        Session["strWhereOperLog"] = stbWhere.ToString();
        strWhere = stbWhere.ToString();
        this.BindOperlogmanage(Session["sortStr"].ToString(), Session["direction"].ToString(), strWhere);
    }
    /// <summary>
    /// 清空查询条件,显示所有条目
    /// </summary>
    /// <remarks>
    /// 完成人:刘建伟
    /// 完成时间:2007-3-30
    /// </remarks>
    protected void btnShowAll_Click1(object sender, EventArgs e)
    {
        //清空查询条件,显示所有条目

        this.cldBegin.Text = DateTime.Now.AddMonths(-1).ToShortDateString();
        this.cldEnd.Text = DateTime.Now.ToShortDateString();
        strWhere = "and date_time >= '" + cldBegin.Text.Trim().Replace("'", "\"") + "' ";
        Session["strWhereOperLog"] = strWhere;

        Session["direction"] = "";
        Session["sortStr"] = "";
        this.BindOperlogmanage("", "", strWhere);
        this.operUser.Text = "";
    }

    protected void btnExcel_Click(object sender, EventArgs e)
    {
        if (Session["strWhereOperLog"] == null)
        {
            strWhere = "";
        }
        else
        {
            strWhere = Session["strWhereOperLog"].ToString();
        }
        Itsv.BLL.SystemManage.user_actionBLL uBLL = new user_actionBLL();
        DataSet dsUAList = uBLL.GetList("1=1 " + strWhere);
        if (dsUAList == null)
        {
            ShowMessage("对不起,没有符合条件的数据,请您重试!");
            return;
        }

        if (dsUAList.Tables[0].Rows.Count > 0)
        {
            DataTable dt = dsUAList.Tables[0];
            StringBuilder sb = new StringBuilder();
            sb.Append("<table cellspacing=\"0\" cellpadding=\"3\" rules=\"all\" border=\"1\" style=\"border-color:#E7E7FF;border-width:1px;border-style:None;width:100%;border-collapse:collapse;\">");
            sb.Append("<tr align=\"left\" style=\"color:#F7F7F7;background-color:#4A3C8C;font-weight:bold;\">");
            sb.Append("<th align=\"left\" scope=\"col\" style=\"width:50px;font-weight:bold;font-size:12px;\">操作人</th>");
            sb.Append("<th align=\"left\" scope=\"col\" style=\"width:150px;font-weight:bold;font-size:12px;\">操作人所属部门</th>");
            sb.Append("<th align=\"left\" scope=\"col\" style=\"width:200px;font-weight:bold;font-size:12px;\">操作内容</th>");
            sb.Append("<th align=\"left\" scope=\"col\" style=\"width:120px;font-weight:bold;font-size:12px;\">日志时间</th></tr>");
            foreach (DataRow dr in dt.Rows)
            {
                sb.Append("<tr style=\"font-size:12px;\">");
                sb.Append("<td>" + dr["account"].ToString() + "</td>");
                sb.Append("<td>" + dr["dept_name"].ToString() + "</td>");
                sb.Append("<td>" + dr["action"].ToString() + "</td>");
                sb.Append("<td>" + dr["date_time"].ToString() + "</td>");
                sb.Append("</tr>");
            }
            sb.Append("</table>");

            Response.ContentType = "application/vnd.ms-excel";
            Response.Charset = "";
            System.IO.StringWriter sw = new System.IO.StringWriter();
            sw.Write(sb.ToString());
            Response.Write(sw.ToString());
            Response.End();
        }
        else
        {
            ShowMessage("对不起,没有符合条件的数据,请您重试!");
        }
    }

    protected void gvOperlogmanage_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            CheckBox chk = (CheckBox)e.Row.FindControl("Allckb");
            if (chk != null)
            {
                chk.Attributes.Add("onclick", "setOperSpec();");
            }
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        strWhere = Session["strWhereOperLog"].ToString();
        user_actionBLL uaBLL = new user_actionBLL();
        for (int i = 0; i < this.gvOperlogmanage.Rows.Count; i++)
        {
            CheckBox cb = (CheckBox)this.gvOperlogmanage.Rows[i].FindControl("ckb");
            if (cb.Checked)
            {
                int cheselect = int.Parse(this.gvOperlogmanage.DataKeys[i].Value.ToString());
                uaBLL.Delete(cheselect);             
            }
        } 

        this.BindOperlogmanage(Session["sortStr"].ToString(),Session["direction"].ToString(), strWhere);
    }

    protected void btnDeleteAll_Click(object sender, EventArgs e)
    {
        user_actionBLL uaBLL = new user_actionBLL();
        try
        {
            if (uaBLL.TruncateTable())
            {
                ShowMessage("清空信息成功!");
                strWhere = Session["strWhereOperLog"].ToString();
                this.BindOperlogmanage(Session["sortStr"].ToString(), Session["direction"].ToString(), strWhere);
            }
            else
            {
                ShowMessage("清空失败!");
            }
        }
        catch
        {
            ShowMessage("清空失败!");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -