下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/SSFS 0006-2023蛋白肽粉类产品品质的多级红外光谱快速评价方法
- T/SCPP 0001-2024城市管理综合执法辅助岗位职业化建设规范
- T/CTS 17-2023公安交通管理执勤执法记录仪数据管理信息系统
- T/CI 1028-2025美丽乡村配电网建设和管理规范
- DB31/T 1477-2024空间地理数据归集技术要求
- T/CNCA 163-2025煤矿用锚杆钻架电液控制系统通用技术规范
- 2025~2026学年河北省邢台市威县七级镇七级堡小学冀教版三年级上册第二次月考数学测试卷【附答案】
- PHP技术面试题及详细参考答案(完整版)
- Photoshop CS3 试题及完整解答
- 2025-2026学年四川省内江市初中数学八年级期末下册自测黑金试卷附答案
- 野村-中国:中国人民银行对人民币及全球失衡的立场-China:The P BoCs stance on RMB and global imbalances-20261008
- 2026年广东省公需课《人工智能赋能高质量发展》试题答案
- 2026工商银行校园招聘笔试真题(完整版+详细答案解析)
- 开学思政第一课2026年秋季学期开学典礼校长致辞
- 2026年北京市中考语文试卷真题及答案详解(精校打印)
- 2026年广东省检察官逐级遴选笔试题目及答案
- IQC电子物料抽样检验标准手册
- 2026年贵州中考(数学)考试试卷(真题)答案解析
- 中国汽车防撞梁行业发展动态与市场需求研究研究报告
- 电力工程施工安全专项方案范本
- 国家职业技术技能标准 6-31-03-03 生化检验员(试行) 2024年版
评论
0/150
提交评论