欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF自动记录操作内容

程序员文章站 2022-06-26 19:54:40
...

数据里面记录了 2020-05-07 16:05:55 的时候登陆系统,如图
WPF自动记录操作内容
数据库存储过程的代码

IF(@type = 'Insert_LogManagement') 新增用户操作
BEGIN
    INSERT INTO SYS_ConLog
             ( UserID, LoginTime,ManipulatingContent,LoginEquipment,LoginIP)
    VALUES   ( @UserID, @LoginTime, @ManipulatingContent,@LoginEquipment,@LoginIP)
END

服务器的代码

DALPublic.DALMethod myDALMethod = new DALPublic.DALMethod();//实力化DAL

[OperationContract]//OperationContract(操作契约)
public int Insert_LogManagements(int UserID, DateTime LoginTime, string ManipulatingContent, string LoginEquipment, string LoginIP)
    {  
     //实例化对象数组(序列化参数)
        SqlParameter[] mySqlParameters = {
            //定义传递参数,以及传递参数的类型
            new SqlParameter("@type",SqlDbType.NChar),       
            new SqlParameter("@UserID",SqlDbType.Int),
            new SqlParameter("@LoginTime",SqlDbType.DateTime),
            new SqlParameter("@ManipulatingContent",SqlDbType.NVarChar),              
            new SqlParameter("@LoginEquipment",SqlDbType.NVarChar),
            new SqlParameter("@LoginIP",SqlDbType.NVarChar),
        };
        //给对象赋值
        mySqlParameters[0].Value = "Insert_LogManagement";
        mySqlParameters[1].Value = UserID;
        mySqlParameters[2].Value = DateTime.Now;
        mySqlParameters[3].Value = ManipulatingContent;
        mySqlParameters[4].Value = LoginEquipment;
        mySqlParameters[5].Value = LoginIP;            
        int count = myDALMethod.UpdateData("ZLK_DataBanks", mySqlParameters);
        return count;
    }

控制器的代码

BLL.FU_DataBanks.DataBanks.DataBanksClient myUC_Log = new BLL.FU_DataBanks.DataBanks.DataBanksClient();//实例化服务
//加载数据
private void Window_Loaded(object sender, RoutedEventArgs e)
 {
        TC = tab_Mains;//初始化静态选项卡
        string times = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //加载登录时间
        Dtime = times.ToString();           
        UserId = Convert.ToInt32(LoginWindow.btn_User.Rows[0]["UserID"]);          
        string Content = "登录系统";
        //【主机IP,主机名】
        LoginEquipment = Dns.GetHostName();//使用到dns类;
        IPAddress[] addressList = Dns.GetHostEntry(LoginEquipment).AddressList;
        LoginIP = null;
        foreach (IPAddress _ip in addressList)
        {  
          //判断是否是ipv4其中可以是ipv6
            if (_ip.AddressFamily.ToString().ToUpper() == "INTERNETWORK")
            {
                LoginIP = _ip.ToString();
            }
        }
    //【用户操作日志新增】
    myUC_Log.Insert_LogManagements(UserId, DateTime.Now, Content, LoginEquipment, LoginIP);
 }