毕业设计-视频监控系统代码_第1页
毕业设计-视频监控系统代码_第2页
毕业设计-视频监控系统代码_第3页
毕业设计-视频监控系统代码_第4页
毕业设计-视频监控系统代码_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

附录一登录界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceMyVideo{publicpartialclassfrmLogin:Form{publicfrmLogin(){InitializeComponent();}privatevoidfrmLogin_Load(objectsender,EventArgse){this.timer1.Start();//启动时间}//确定privatevoidbtQueding_Click(objectsender,EventArgse){if(tbName.Text.Trim()!=""&&tbPas.Text.Trim()!="")//信息输入框都不为空{stringLJ=@"DataSource=PC-20150826CYWO;InitialCatalog=MyData;IntegratedSecurity=True";//建立连接SqlConnectionconn=newSqlConnection(LJ);SqlCommandcomm=conn.CreateCommand();//实例化数据库的操作命令conn.Open();if(rbStudent.Checked)//学生{stringsql="selectsno,spass,snamefromstudentwhere(sno='"+tbName.Text+"')";comm.CommandText=sql;SqlDataReaderdatar=comm.ExecuteReader();//使SqlDataReader前进到下一条记录。返回一个bool值,如果为真跳出循环while(datar.Read()){//读取数据库的内容,并与输入的进行比较;判断用户输入是否正确if(datar["spass"].ToString().Trim()!=tbPas.Text.Trim()){MessageBox.Show("密码不正确,请重新输入!");tbPas.Focus();//焦点:使光标聚焦在文本输入框return;}else{Form1f1=newForm1();this.Hide();//this.Close();f1.ShowDialog();//信息正确,界面跳转}}datar.Close();}elseif(rbTeacher.Checked)//老师{stringsql="selecttno,tpass,tnamefromteacherwhere(tno='"+tbName.Text+"')";comm.CommandText=sql;SqlDataReaderdatar=comm.ExecuteReader();while(datar.Read()){//判断用户输入是否正确if(datar["tpass"].ToString().Trim()!=tbPas.Text.Trim()){MessageBox.Show("用户名或密码不正确,请重新输入!");tbPas.Focus();return;}else{Form1f1=newForm1();this.Hide();//this.Close();f1.ShowDialog();}}datar.Close();}elseif(rbAdmin.Checked)//管理员{stringsql="SELECTadminname,adminpass,adminIDFROMadminWHERE(adminID='"+tbName.Text+"')";comm.CommandText=sql;SqlDataReaderdatar=comm.ExecuteReader();while(datar.Read()){if(datar["adminpass"].ToString().Trim()!=tbPas.Text.Trim()){MessageBox.Show("密码不正确,请重新输入!");tbPas.Focus();return;}else{AdminLoginf2=newAdminLogin();this.Hide();f2.ShowDialog();}}datar.Close();}tbName.Text="";//用户信息错误,信息清除tbPas.Text="";}else{MessageBox.Show("用户或密码不能为空!");tbName.Focus();return;}}//取消privatevoidbtQuxiao_Click(objectsender,EventArgse){if(MessageBox.Show("你确定退出系统吗?","系统提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation)==DialogResult.OK){Application.Exit();}}//时间显示privatevoidtimer1_Tick(objectsender,EventArgse){time.Text="当前时间为:"+DateTime.Now.ToLongDateString()+""+DateTime.Now.ToLongTimeString();//字幕滚动#regionthis.time.Left-=3;if(this.time.Left<0){this.time.Left=this.Width-200;}#endregion}}}附录二信息维护界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceMyVideo{publicpartialclassAdminLogin:Form{publicAdminLogin(){InitializeComponent();}publicstaticstringsql="DataSource=PC-20150826CYWO;InitialCatalog=MyData;IntegratedSecurity=True";inttab_num=1;//学生工号改变选择tab1privatevoidrbxsxh_CheckedChanged(objectsender,EventArgse){this.tabControl1.SelectedIndex=0;}//教师工号改变选择tab2privatevoidrbjsgh_CheckedChanged(objectsender,EventArgse){this.tabControl1.SelectedIndex=1;}privatevoidtabControl1_SelectedIndexChanged(objectsender,EventArgse){if(tabControl1.SelectedTab.Name=="tabPage1"){tab_num=1;}elseif(tabControl1.SelectedTab.Name=="tabPage2"){tab_num=2;}}privatevoidAdminLogin_Load(objectsender,EventArgse){this.teacherTableAdapter.Fill(this.myDataTeacher.teacher);this.studentTableAdapter.Fill(this.myDataDataStudent.student);}//查询按钮privatevoidbt_search_Click(objectsender,EventArgse){if(tbSearch.Text.Trim()!=""){search();}else{MessageBox.Show("查询条件不能为空");}}//查询privatevoidsearch(){stringsql_student="select*fromStudentwhere1=1";stringsql_teacher="select*fromteacherwhere1=1";if(rbxsxh.Checked)//学生学号{if(tbSearch.Text.Trim()!=""){sql_student+="andsnolike'%"+tbSearch.Text.Trim()+"%'";}dataGridView1.DataSource=MyMeans.GetDataset(sql_student,"Student").Tables["Student"];}elseif(rbjsgh.Checked)//教学工号{if(tbSearch.Text.Trim()!=""){sql_teacher+="andtnolike'%"+tbSearch.Text.Trim()+"%'";}dataGridView2.DataSource=MyMeans.GetDataset(sql_teacher,"teacher").Tables["teacher"];}}//添加学生信息privatevoidbutton3_Click(objectsender,EventArgse){if(textBox2.Text==""&&textBox3.Text==""&&textBox4.Text==""){MessageBox.Show("请完善学生信息");}else{SqlConnectionconn=newSqlConnection(sql);conn.Open();SqlCommandcomm=newSqlCommand(sql,conn);if(tab_num==1){stringsql1="selectsnofromStudentwheresno='"+textBox2.Text.Trim()+"'";comm.CommandText=sql1;SqlDataReaderdatar=comm.ExecuteReader();if(datar.Read()){MessageBox.Show("该学生信息已经存在");}else{stringsql_xuan="InsertintoStudent(sno,sname,spass)values('"+ textBox2.Text.Trim()+"','"+textBox3.Text.Trim()+"','"+ textBox4.Text.Trim()+"')";MyMeans.Sqlexcute(sql_xuan);MessageBox.Show("数据保存成功","系统提示");relogin();}}elseif(tab_num==2){stringsql2="selecttnofromteacherwheretno='"+textBox2.Text.Trim()+"'";comm.CommandText=sql2;SqlDataReaderdatar=comm.ExecuteReader();if(datar.Read()){MessageBox.Show("该教师信息已经存在");}else{stringsql_xuan="Insertintoteacher(tno,tname,tpass)values('"+textBox2.Text.Trim()+"','"+textBox3.Text.Trim()+"','"+textBox4.Text.Trim()+"')";MyMeans.Sqlexcute(sql_xuan);MessageBox.Show("数据保存成功","系统提示");relogin();}}textBox2.Text="";textBox3.Text="";textBox4.Text="";conn.Close();}}//删除信息privatevoidbutton4_Click(objectsender,EventArgse){if(textBox2.Text==""){MessageBox.Show("请填写删除学生学号或教师工号");}else{if(tab_num==1){stringsql_tui="deletefromStudentwheresno='"+textBox2.Text+"'";MyMeans.Sqlexcute(sql_tui);}elseif(tab_num==2){stringsql_tui="deletefromteacherwheretno='"+textBox2.Text+"'";MyMeans.Sqlexcute(sql_tui);}MessageBox.Show("数据删除成功","系统提示");relogin();textBox2.Text="";textBox3.Text="";textBox4.Text="";}}//修改学生信息privatevoidbutton5_Click(objectsender,EventArgse){if(textBox2.Text==""&&textBox3.Text==""&&textBox4.Text==""){MessageBox.Show("请完善所要修改的信息");}else{SqlConnectionconn=newSqlConnection(sql);conn.Open();SqlCommandcomm=newSqlCommand(sql,conn);if(tab_num==1){stringsql1="selectsno,sname,spassfromStudentwheresno='"+textBox2.Text.Trim()+"'andsname='"+textBox3.Text.Trim()+"'andspass='"+textBox4.Text.Trim()+"'";comm.CommandText=sql1;SqlDataReaderdatar=comm.ExecuteReader();if(datar.Read()){MessageBox.Show("该学生信息一样,修改无效");}else{stringsql_tui="deletefromStudentwheresno='"+textBox2.Text+"'";MyMeans.Sqlexcute(sql_tui);stringsql_xuan="InsertintoStudent(sno,sname,spass)values('"+textBox2.Text.Trim()+"','"+textBox3.Text.Trim()+"','"+textBox4.Text.Trim()+"')";MyMeans.Sqlexcute(sql_xuan);relogin();MessageBox.Show("数据保存成功","系统提示");}}elseif(tab_num==2){stringsql2="selecttno,tname,tpassfromteacherwheretno='"+textBox2.Text.Trim()+"'andtname='"+textBox3.Text.Trim()+"'andtpass='"+textBox4.Text.Trim()+"'";comm.CommandText=sql2;SqlDataReaderdatar=comm.ExecuteReader();if(datar.Read()){MessageBox.Show("该教师信息一样,修改无效");}else{stringsql_tui="deletefromteacherwheretno='"+textBox2.Text+"'";MyMeans.Sqlexcute(sql_tui);stringsql_xuan="Insertintoteacher(tno,tname,tpass)values('"+textBox2.Text.Trim()+"','"+textBox3.Text.Trim()+"','"+textBox4.Text.Trim()+"')";MyMeans.Sqlexcute(sql_xuan);relogin();MessageBox.Show("数据保存成功","系统提示");}}textBox2.Text="";textBox3.Text="";textBox4.Text="";conn.Close();}}//删除多行信息privatevoidbutton6_Click(objectsender,EventArgse){stringsql="DataSource=PC-20150826CYWO;InitialCatalog=MyData;IntegratedSecurity=True";SqlConnectionconn=newSqlConnection(sql);conn.Open();//打開連接SqlCommandcmd=conn.CreateCommand();if(this.dataGridView1.SelectedRows.Count>0&&tab_num==1){DialogResultdr=MessageBox.Show("确定删除选中的记录?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);if(dr==DialogResult.OK){//遍历所选中的dataGridView记录行foreach(DataGridViewRowrowinthis.dataGridView1.SelectedRows){//取dataGridView1中的第一列的值stringstrN=row.Cells[0].Value.ToString();stringsql1="deletefromstudentwheresno='"+strN+"'";cmd.CommandText=sql1;cmd.ExecuteNonQuery();//执行删除}}}elseif(this.dataGridView2.SelectedRows.Count>0&&tab_num==2){DialogResultdr=MessageBox.Show("确定删除选中的记录?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);if(dr==DialogResult.OK){//遍历所选中的dataGridView记录行foreach(DataGridViewRowrowinthis.dataGridView2.SelectedRows){//取dataGridView1中的第一列的值stringstrN=row.Cells[0].Value.ToString();stringsql1="deletefromteacherwheretno='"+strN+"'";cmd.CommandText=sql1;cmd.ExecuteNonQuery();//执行删除}}}conn.Close();//关闭连接conn=null;//释放资源//删除后执行刷新操作relogin();}privatevoiddataGridView1_CellMouseClick(objectsender,DataGridViewCellMouseEventArgse){if(e.RowIndex>=0){textBox2.Text=dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();textBox3.Text=dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();textBox4.Text=dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();}}privatevoiddataGridView2_CellMouseClick(objectsender,DataGridViewCellMouseEventArgse){if(e.RowIndex>=0){textBox2.Text=dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString();textBox3.Text=dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString();textBox4.Text=dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString();}}//查询框改变时自动查询privatevoidtbSearch_TextChanged(objectsender,EventArgse){search();}//刷新privatevoidrelogin(){if(tab_num==1){stringsql="select*fromStudent";DataSetshuaxin=MyMeans.GetDataset(sql,"Student");dataGridView1.DataSource=shuaxin.Tables["Student"];}elseif(tab_num==2){stringsql="select*fromteacher";DataSetshuaxin=MyMeans.GetDataset(sql,"teacher");dataGridView2.DataSource=shuaxin.Tables["teacher"];}}//返回privatevoidbt_fanhui_Click(objectsender,EventArgse){frmLoginf1=newfrmLogin();this.Hide();f1.ShowDialog();}privatevoidtextBox2_TextChanged(objectsender,EventArgse){relogin();}privatevoidAdminLogin_FormClosed(objectsender,FormClosedEventArgse){if(MessageBox.Show("你确定退出系统吗?","系统提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation)==DialogResult.OK){Application.Exit();}}}}附录三主功能界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Diagnostics;usingSystem.Drawing;usingSystem.Drawing.Imaging;usingSystem.IO;usingSystem.IO.Ports;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Threading;usingAForge;usingAForge.Video;usingAForge.Video.DirectShow;usingAForge.Imaging;usingAForge.Imaging.Filters;usingAForge.Video.FFMPEG;usingAForge.Controls;usingAForge.Video.VFW;namespaceMyVideo{publicpartialclassForm1:Form{#region全局变量定义privateFilterInfoCollectionvideoDevices;privateVideoCaptureDevicevideoSource1;privateVideoCaptureDevicevideoSource2;privateVideoCaptureDevicevideoSource3;privateVideoCaptureDevicevideoSource4;privatebool_stopREC1=true;privatebool_stopREC2=true;privatebool_stopREC3=true;privatebool_stopREC4=true;privatebool_createNewFile1=true;privatebool_createNewFile2=true;privatebool_createNewFile3=true;privatebool_createNewFile4=true;privateVideoFileWriter_videoWriter1=null;privateVideoFileWriter_videoWriter2=null;privateVideoFileWriter_videoWriter3=null;privateVideoFileWriter_videoWriter4=null;privatestring_videoFileName=string.Empty;//视频文件名privatestring_photoFileName=string.Empty;//视频文件名privatestring_videoFileFullPath1=string.Empty;//视频文件全路径privatestring_videoFileFullPath2=string.Empty;privatestring_videoFileFullPath3=string.Empty;//视频文件全路径privatestring_videoFileFullPath4=string.Empty;privateint_frameRate=8;//默认帧率privatestring_videoPath=AppDomain.CurrentDomain.BaseDirectory+"Video\\";//视频文件路径privatestring_photoPath=AppDomain.CurrentDomain.BaseDirectory+"Photo\\";//照片文件路径#endregion//privatefloatX;//当前窗体的宽度//privatefloatY;//当前窗体的高度publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){//X=this.Width;//获取窗体的宽度//Y=this.Height;//获取窗体的高度//setTag(this);//调用方法try//try-catch语句由一个try块后跟一个或多个catch子句构成,这些子句指定不同的异常处理程序。{//枚举所有视频输入设备videoDevices=newFilterInfoCollection(FilterCategory.VideoInputDevice);if(videoDevices.Count>0){tb_text.Text="设备已找到,但是未打开";}if(videoDevices.Count==0)thrownewApplicationException();//throw指抛出错误异常,让上一级的cath去处理}catch(ApplicationException){//tscbxCameras.Items.Add("Nolocalcapturedevices");MessageBox.Show("Nolocalcapturedevices");videoDevices=null;}timer.Start();}//连接视频1按钮privatevoidbt_Link1_Click(objectsender,EventArgse){if(videoDevices.Count<1){MessageBox.Show("该视频源未找到设备!","系统提示");}elseif(videoDevices.Count>=1){if(!videoSourcePlayer1.IsRunning&&bt_Link1.Text=="连接视频1"){bt_Link1.Text="关闭视频1";videoSource1=newVideoCaptureDevice(videoDevices[0].MonikerString);videoSourcePlayer1.VideoSource=videoSource1;videoSourcePlayer1.Start();//启动设置tb_text.Text="视频已打开";}else{if(bt_Link1.Text=="关闭视频1"){//videoSource1.SignalToStop();videoSourcePlayer1.Stop();bt_Link1.Text="连接视频1";}}}}//连接视频2按钮privatevoidbt_Link2_Click(objectsender,EventArgse){if(videoDevices.Count<2){MessageBox.Show("该视频源未找到设备!","系统提示");}elseif(videoDevices.Count>=2){if(!videoSourcePlayer2.IsRunning&&bt_Link2.Text=="连接视频2"){bt_Link2.Text="关闭视频2";videoSource2=newVideoCaptureDevice(videoDevices[1].MonikerString);videoSourcePlayer2.VideoSource=videoSource2;videoSourcePlayer2.Start();//启动设置tb_text.Text="视频已打开";}else{if(bt_Link2.Text=="关闭视频2"){//videoSource2.SignalToStop();videoSourcePlayer2.Stop();bt_Link2.Text="连接视频2";}}}}//连接视频3按钮privatevoidbt_Link3_Click(objectsender,EventArgse){if(videoDevices.Count<3){MessageBox.Show("该视频源未找到设备!","系统提示");}elseif(videoDevices.Count>=3){if(!videoSourcePlayer3.IsRunning&&bt_Link3.Text=="连接视频3"){bt_Link3.Text="关闭视频3";videoSource3=newVideoCaptureDevice(videoDevices[2].MonikerString);videoSourcePlayer3.VideoSource=videoSource3;videoSourcePlayer3.Start();//启动设置tb_text.Text="视频已打开";}else{if(bt_Link3.Text=="关闭视频3"){//videoSource2.SignalToStop();videoSourcePlayer3.Stop();bt_Link3.Text="连接视频3";}}}}//连接视频4按钮privatevoidbt_Link4_Click(objectsender,EventArgse){if(videoDevices.Count<4){MessageBox.Show("该视频源未找到设备!","系统提示");}elseif(videoDevices.Count>=4){if(!videoSourcePlayer4.IsRunning&&bt_Link4.Text=="连接视频4"){bt_Link4.Text="关闭视频4";videoSource4=newVideoCaptureDevice(videoDevices[3].MonikerString);videoSourcePlayer4.VideoSource=videoSource4;videoSourcePlayer4.Start();//启动设置tb_text.Text="视频已打开";}else{if(bt_Link4.Text=="关闭视频4"){//videoSource2.SignalToStop();videoSourcePlayer4.Stop();bt_Link4.Text="连接视频4";}}}}#region拍照//拍照privatevoidbt_Capture_Click(objectsender,EventArgse){if(!videoSourcePlayer1.IsRunning&&!videoSourcePlayer2.IsRunning&&!videoSourcePlayer3.IsRunning&&!videoSourcePlayer4.IsRunning){MessageBox.Show("请打开摄像头","提示");}else{if(videoSourcePlayer1.IsRunning){videoSource1.NewFrame+=newNewFrameEventHandler(videoSource1_NewFrame);}if(videoSourcePlayer2.IsRunning){videoSource2.NewFrame+=newNewFrameEventHandler(videoSource2_NewFrame);}if(videoSourcePlayer3.IsRunning){videoSource3.NewFrame+=newNewFrameEventHandler(videoSource3_NewFrame);}if(videoSourcePlayer4.IsRunning){videoSource4.NewFrame+=newNewFrameEventHandler(videoSource4_NewFrame);}tb_text.Text="拍照成功,完成时间:"+DateTime.Now.ToString("yyyyMMddhhmmss");}}voidvideoSource1_NewFrame(objectsender,AForge.Video.NewFrameEventArgseventArgs){Bitmapbmp=(Bitmap)eventArgs.Frame.Clone();_videoFileName=DateTime.Now.ToString("1-yyyyMMddhhmmss")+".bmp";bmp.Save(_photoPath+_videoFileName,System.Drawing.Imaging.ImageFormat.Bmp);//如果这里不写这个,一会儿会不停的拍照,videoSource1.NewFrame-=newNewFrameEventHandler(videoSource1_NewFrame);}voidvideoSource2_NewFrame(objectsender,AForge.Video.NewFrameEventArgseventArgs){Bitmapbmp=(Bitmap)eventArgs.Frame.Clone();_videoFileName=DateTime.Now.ToString("2-yyyyMMddhhmmss")+".bmp";bmp.Save(_photoPath+_videoFileName,System.Drawing.Imaging.ImageFormat.Bmp);videoSource2.NewFrame-=newNewFrameEventHandler(videoSource2_NewFrame);}voidvideoSource3_NewFrame(objectsender,AForge.Video.NewFrameEventArgseventArgs){Bitmapbmp=(Bitmap)eventArgs.Frame.Clone();_videoFileName=DateTime.Now.ToString("3-yyyyMMddhhmmss")+".bmp";bmp.Save(_photoPath+_videoFileName,System.Drawing.Imaging.ImageFormat.Bmp);videoSource3.NewFrame-=newNewFrameEventHandler(videoSource3_NewFrame);}voidvideoSource4_NewFrame(objectsender,AForge.Video.NewFrameEventArgseventArgs){Bitmapbmp=(Bitmap)eventArgs.Frame.Clone();_videoFileName=DateTime.Now.ToString("4-yyyyMMddhhmmss")+".bmp";bmp.Save(_photoPath+_videoFileName,System.Drawing.Imaging.ImageFormat.Bmp);videoSource4.NewFrame-=newN

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论