电影登录记录管理系统4[历史查看] 加强完整版
2012-09-19 17:05
435 查看
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 System.Configuration;
using System.Data.SqlClient;
namespace 电影记录管理系统
{
public partial class FrmLog : Form
{
public FrmLog()
{
InitializeComponent();
}
//连接字符串,获取配置文件中的连接路径
static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
private void FrmLog_Load(object sender, EventArgs e)
{
//FrmLog log = new FrmLog();
//log.GetExitTime();
//将用户信息添加到DataGridView里面
//log.AddLog();
AddLog();
//将数据显示出来
ShowMsg();
}
public void AddLog()
{
string sql = "insert into Log(User_Name,Situation,Time)values(@User_Name,@Situation,@Time)";
if (Form2.Uid == "" || Form2.Situation == "" || Form2.Time.ToString() == "")
{
MessageBox.Show("数据不能为空!");
return;
}
//向数据表中插入数据
SqlParameter[] param = {
new SqlParameter("@User_Name",Form2.Uid),
new SqlParameter("@Situation",Form2.Situation),
new SqlParameter("@Time",Form2.Time)
};
//利用sql来获取connStr的连接字符串
SqlConnection conn = new SqlConnection(connStr);
//创建一个cmd对象
SqlCommand cmd = new SqlCommand(sql,conn);
//打开数据库
conn.Open();
cmd.Parameters.AddRange(param);//向cmd中添加参数
int n = cmd.ExecuteNonQuery();
//关闭数据库
conn.Close();
}
public void ShowMsg()
{
string show = "select Id,User_Name,Situation,Time from Log";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(show,conn);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
dgvLog.DataSource = dt;
}
public void GetExitTime()
{
Form2.Time = DateTime.Now;
Form2.Situation = "退出";
}
private void btnExit_Click(object sender, EventArgs e)
{
//获取当前退出的时间
GetExitTime();
AddLog();
//直接退出系统
Application.Exit();
}
private void btnBack_Click(object sender, EventArgs e)
{
Form2 main = new Form2();
main.Show();
this.Hide();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace 电影记录管理系统
{
public partial class FrmLog : Form
{
public FrmLog()
{
InitializeComponent();
}
//连接字符串,获取配置文件中的连接路径
static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
private void FrmLog_Load(object sender, EventArgs e)
{
//FrmLog log = new FrmLog();
//log.GetExitTime();
//将用户信息添加到DataGridView里面
//log.AddLog();
AddLog();
//将数据显示出来
ShowMsg();
}
public void AddLog()
{
string sql = "insert into Log(User_Name,Situation,Time)values(@User_Name,@Situation,@Time)";
if (Form2.Uid == "" || Form2.Situation == "" || Form2.Time.ToString() == "")
{
MessageBox.Show("数据不能为空!");
return;
}
//向数据表中插入数据
SqlParameter[] param = {
new SqlParameter("@User_Name",Form2.Uid),
new SqlParameter("@Situation",Form2.Situation),
new SqlParameter("@Time",Form2.Time)
};
//利用sql来获取connStr的连接字符串
SqlConnection conn = new SqlConnection(connStr);
//创建一个cmd对象
SqlCommand cmd = new SqlCommand(sql,conn);
//打开数据库
conn.Open();
cmd.Parameters.AddRange(param);//向cmd中添加参数
int n = cmd.ExecuteNonQuery();
//关闭数据库
conn.Close();
}
public void ShowMsg()
{
string show = "select Id,User_Name,Situation,Time from Log";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(show,conn);
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
dgvLog.DataSource = dt;
}
public void GetExitTime()
{
Form2.Time = DateTime.Now;
Form2.Situation = "退出";
}
private void btnExit_Click(object sender, EventArgs e)
{
//获取当前退出的时间
GetExitTime();
AddLog();
//直接退出系统
Application.Exit();
}
private void btnBack_Click(object sender, EventArgs e)
{
Form2 main = new Form2();
main.Show();
this.Hide();
}
}
}
相关文章推荐
- 电影登录记录系统4[历史查看]
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- 实现记录和查看用户的系统登录和退出历史
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- Linux下查看/管理当前登录用户及用户操作历史记录
- 实现记录和查看用户的系统登录和退出历史和利用C#编写的网络聊天程序
- Linux下查看/管理当前登录用户及用户操作历史记录
- 跟老紫竹学Java-图书销售系统-管理界面:图书,入库,订单查看,历史数据等
- C#简易电影记录管理系统:开发六[数据搜索]