博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
操作日志的生成和综合搜索
阅读量:6078 次
发布时间:2019-06-20

本文共 6274 字,大约阅读时间需要 20 分钟。

一:截图

二:OperationLogDAL.cs源代码

using System;using System.Collections.Generic;using System.Linq;using System.Text;using HRMSys.Model;using System.Data;using System.Data.SqlClient;namespace HRMSys.DAL{    public class OperationLogDAL    {        ///         /// 将数据库的格式转换为object对象的字段格式        ///         ///         /// 
public OperationLog Tomodel(DataRow row) { OperationLog log=new OperationLog(); log.Id=(Guid)row["Id"]; log.OperatorId = (Guid)row["OperatorId"]; log.MakeDate=(DateTime)row["MakeDate"]; log.ActionDesc = (string)row["ActionDesc"]; log.LoginUser = (string)sqlhelper.FromDbValue(row["LoginUser"]); return log; } /// /// 插入一条操作记录 /// /// /// public void InsertLog(Guid OperatorId, string loginUser, string ActionDesc) { sqlhelper.ExecuteNon(@"insert into T_OperationLog(Id,OperatorId,MakeDate,ActionDesc,LoginUser) values(newid(),@OperatorId,getdate(),@ActionDesc,@LoginUser)", new SqlParameter("@ActionDesc", ActionDesc), new SqlParameter("@OperatorId", OperatorId), new SqlParameter("@LoginUser", loginUser));//这里是values,不是value } /// /// 插入一条操作记录 /// /// /// public void InsertLog(Guid OperatorId, string ActionDesc) { sqlhelper.ExecuteNon(@"insert into T_OperationLog(Id,OperatorId,MakeDate,ActionDesc) values(newid(),@OperatorId,getdate(),@ActionDesc)", new SqlParameter("@ActionDesc", ActionDesc), new SqlParameter("@OperatorId", OperatorId) );//这里是values,不是value } /// /// 得到综合查询的OperationLog数组 /// /// /// ///
public OperationLog[] Search(string sql, SqlParameter[] sqlparameters) { DataTable table = sqlhelper.datatable(sql, sqlparameters); //OperationLog[] log=new OperationLog[table.Rows.Count](); OperationLog[] log = new OperationLog[table.Rows.Count];//不需要再加小括号了 for (int i = 0; i < table.Rows.Count; i++) { log[i] =Tomodel( table.Rows[i]); } return log; } }}

三:OperationLog.cs源代码

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace HRMSys.Model{    public class OperationLog    {        public Guid Id { get; set; }        public Guid OperatorId { get; set; }        public DateTime MakeDate { get; set; }        public String ActionDesc { get; set; }        public string LoginUser { get; set; }    }}

四:OperationLogList.cs源代码

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace HRMSys.Model{    public class OperationLogList    {        public Guid Id { get; set; }        public string OperatorName { get; set; }        public DateTime MakeDate { get; set; }        public String ActionDesc { get; set; }        public string LoginUser { get; set; }    }}

五:OperationSearchLog.cs界面和源代码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using HRMSys.DAL;using System.Data.SqlClient;using HRMSys.Model;namespace HYMSys.UI.SystemMgr{    public partial class OperationSearchLog : Form    {        public OperationSearchLog()        {            InitializeComponent();        }        ///         /// 载入事件,给窗口填值        ///         ///         ///         private void OperationSearchLog_Load(object sender, EventArgs e)        {            OperatorDAL dal = new OperatorDAL();            Operator op = new Operator();            cb_operator.DataSource = dal.GetListNotDelete();            //cb_operator.SelectedValue = op.Id;            //cb_operator.ValueMember = op.UserName;            //cb_operator.SelectedValue = "Id";            //cb_operator.ValueMember = "UserName";            cb_operator.ValueMember = "Id";            cb_operator.DisplayMember = "UserName";            dtp_startdate.Value = DateTime.Today.AddDays(-5);            dtp_enddate.Value = DateTime.Today;                   }        ///         /// 综合查询        ///         ///         ///         private void btn_search_Click(object sender, EventArgs e)        {            List
whereList = new List
(); List
parametersList = new List
(); //if(chb_operator.CheckState==true)错误的 if(chb_operator.Checked==true) { whereList.Add("OperatorId=@OperatorId"); parametersList.Add(new SqlParameter("@OperatorId", cb_operator.SelectedValue));//不能用cb_operator.text } if (chb_date.Checked == true) { whereList.Add("MakeDate>=@dtp_startdate and MakeDate<=@dtp_enddate"); parametersList.Add(new SqlParameter("@dtp_startdate", dtp_startdate.Value));//不能用dtp_startdate parametersList.Add(new SqlParameter("@dtp_enddate", dtp_enddate.Value)); } if (chb_desc.Checked == true) { whereList.Add("ActionDesc like @ActionDesc"); parametersList.Add(new SqlParameter("@ActionDesc","%"+tb_desc.Text+"%")); } if (whereList.Count <= 0) { MessageBox.Show("至少选择一个查询条件");//防止查询出的结果过多 return; } string whereSql = string.Join(" and ", whereList); string sql = "select * from T_OperationLog " ; if (whereSql.Length > 0) { sql = sql + " where " + whereSql; } OperationLogDAL dal = new OperationLogDAL(); dgv_logResult.DataSource = dal.Search(sql, parametersList.ToArray()); // .DataSource = dal.Search(Sql, parameter); } }}

转载地址:http://feqgx.baihongyu.com/

你可能感兴趣的文章
Virtualbox中Linux添加新磁盘并创建分区
查看>>
Spring ConfigurationClassPostProcessor Bean解析及自注册过程
查看>>
一步步教你轻松学主成分分析PCA降维算法
查看>>
socket bind 随机端口
查看>>
iOS 字典自动生成模型
查看>>
读jQuery之十(事件模块概述)
查看>>
仅img元素创建后不添加到文档中会执行onload事件
查看>>
全球知名汽车公司品牌
查看>>
Linux SSH远程文件/目录传输命令scp
查看>>
黄聪:WordPress判断当前用户是否为管理员登录
查看>>
Android service binder aidl 关系
查看>>
Redis数据结构详解(一)
查看>>
MySql配置方法,批处理进行MySql配置
查看>>
UE4 Class Naming Prefixes
查看>>
30个优秀的网站导航菜单设计案例
查看>>
Eclipse Tips(3):Template
查看>>
Win32 API消息函数:GetMessagePos
查看>>
跟小静读CLR via C#(17)--接口
查看>>
C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮
查看>>
[Z]一个轻松制作和处理矢量图的工具和方法
查看>>