下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实现功能:把图片及人员信息存入数据库并可通过编号查找显示在picturebox中,同时实现照片及信息的更新。数据库构建:PhotoID int 4;EmployeeNO Varchar 20;EmployeeName Varchar 50 ;PhotoContent image 16;Ramrk text 16点击“选择图片”打开一个对话框,选择一个图片放到picturebox中预览private void button1_Click(object sender, EventArgs e) using (OpenFileDialog ofd = new OpenFileDialog() ofd
2、.Title = "请选择要插入的图片" ofd.Filter = "*jpg|*.JPG|*.GIF|*.GIF|*.BMP|*.BMP" ofd.CheckFileExists = true; ofd.CheckPathExists = true; ofd.Multiselect = false; if (ofd.ShowDialog(this) = DialogResult.OK) txtfile = ofd.FileName; this.pb.ImageLocation = ofd.FileName; 点击“按钮”,调用update方法,以实现信
3、息及照片的存储和更改 private void btSave_Click(object sender, EventArgs e) if (txtfile = "") HrBll.AppFrame.BllPhoto.update(txtRemark.Text,txtEmpNO .Text); else Update(txtfile, txtRemark.Text, txtEmpNO.Text); Empty(); Update方法的代码Private void Update(string fullpath,string remark,string empno) FileStr
4、eam fs = new FileStream(fullpath, FileMode.Open); byte imagebytes = new bytefs.Length; BinaryReader br = new BinaryReader(fs); imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length); string SQLstr = string.Format("update T_Photo set PhotoContent=photo,Remark=remark where EmployeeNO=empno");
5、SqlCommand com = new SqlCommand(SQLstr, Common.DataAccess.GetConn(); com.Parameters.Add("photo", SqlDbType.Image); com.Parameters"photo".Value = imagebytes; com.Parameters.Add("empno",SqlDbType.Char); com.Parameters"empno".Value = empno; com.Parameters.Add(&qu
6、ot;remark", SqlDbType.Char); com.Parameters"remark".Value = remark; com.ExecuteNonQuery(); Common.DataAccess.GetConn().Close(); MessageBox.Show("更新成功", MessageBoxButtons.OK, MessageBoxIcon.Information); 点击“查找”按钮,调用Find和img方法实现查找信息,并把文本信息显示在textbox中,照片显示在picturebox中private vo
7、id tbFind_Click(object sender, EventArgs e) if (cbItem.Text = "") MessageBox.Show("请输入员工编号", "提示º?", MessageBoxButtons.OK, MessageBoxIcon.Information); else string sql = string.Format("select count(*) from T_Photo where EmployeeNO='0'", cbItem.Tex
8、t); SqlCommand cmd = new SqlCommand(sql, Common.DataAccess.GetConn(); int i = (int)cmd.ExecuteScalar(); if (i = 1) txtEmpNO.Text = "" txtName.Text = "" txtRemark.Text = "" pb.Image = null; dataGridView1.DataSource =.Find(cbItem.Text); txtEmpNO.Text =.Find(cbItem.Text).R
9、ows01.ToString(); txtName.Text =.Find(cbItem.Text).Rows02.ToString(); txtRemark.Text =.Find(cbItem.Text).Rows03.ToString(); pb.Image =.img(txtEmpNO.Text, txtName.Text); else MessageBox.Show("此员工不存在", "提示º?", MessageBoxButtons.OK, MessageBoxIcon.Information); Find方法(即返回一个data
10、table)Private static DataTable Find(string s) return Common.DataAccess.GetDatatable("select T_Photo.PhotoID,T_Photo.EmployeeNO,T_Employee.EmployeeName," + "T_Photo.Remark from T_Photo inner join T_Employee on T_Photo.EmployeeNO=T_Employee.EmployeeNO where T_Photo.EmployeeNO= " +
11、s); Img方法Private static Image img(string txtno,string txtname) string sql1 = string.Format("select PhotoContent from T_Photo where EmployeeNO='0'", txtno); SqlCommand cmd1 = new SqlCommand(sql1, Common.DataAccess.GetConn(); SqlDataReader dr = cmd1.ExecuteReader(); while (dr.Read()
12、if (dr"PhotoContent"= System.DBNull.Value) string message = string.Format("没?有®D0的Ì?照?片?,ê?请?添¬¨ª加¨®",txtname); MessageBox.Show(message,"提¬¨¢示º?",MessageBoxButtons.OK,MessageBoxIcon.Information); else MemoryStr
13、eam ms = new MemoryStream(byte)dr0); Image img = Image.FromStream(ms); return img; return null; 点击datagridview显示数据private void dataGridView1_Click(object sender, EventArgs e) txtEmpNO.Text = dataGridView1.RowsdataGridView1.CurrentCell.RowIndex.Cells1.Value.ToString(); txtName.Text = dataGridView1.RowsdataGridView1.CurrentCell.RowIndex.Cells2.V
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国家用一次性厨房垃圾袋行业消费态势与竞争趋势预测报告
- 2025-2026学年苏少版(2012)初中美术九年级下册全册(教学设计)教案
- 4.1 音频标注核心认知
- 电力设备新能源行业市场前景及投资研究报告:历次行情复盘户储投资机遇储能
- 长途客运站消防管理
- 2025-2026学年广东省深圳市高三下学期第六次检测化学试卷(含答案解析)
- 非遗泥塑动漫角色制作教程:传统技艺与现代创意的融合
- 某化工品公司产品储存细则
- 麻纺厂设备维修应急预案
- 2026年生态系统结构中生物量分配规律研究基于中国森林生态系统的解析
- 淇河流域水文地球化学环境对缠丝鸭蛋形成的影响探究
- 2026山东济南市中城市发展集团有限公司社会招聘备考题库附答案详解
- 乐山国有资产投资运营(集团)有限公司乐山产业投资(集团)有限公司2026年社会公开招聘考试备考试题及答案解析
- 市政道路工程旁站监理实施细则
- 2026年蜀道投资集团有限责任公司校园招聘笔试备考试题及答案解析
- 交通安全设施施工安全技术交底记录
- 海南省海口市2024-2025学年八年级下学期期中考试道德与法治试卷(含答案)
- GB/T 17622-2008带电作业用绝缘手套
- 标准制修订培训课件
- 吕必松《对外汉语教学概论》讲义-第5章
- 桩基础负摩阻计算表格(自动版)
评论
0/150
提交评论