一、数据库的建立
还是在fiber_yy数据库下创建images表
images表设计如下
二、页面完善设计
main_page页面进行功能完善
入库管理系统
warehousing页面
库存查询系统
query页面
登录注册页面前面几个博文已经实现过了,这里就再赘述了,仍是沿用前面的登录注册页面及数据库
三、代码实现
main_page页面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace fiber_yy
{public partial class main_page : Form{public main_page(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){MessageBox.Show("退出成功");this.Close();new Form1().Show();}private void button2_Click(object sender, EventArgs e){this.Close();new warehousing().Show();}private void button3_Click(object sender, EventArgs e){this.Close();new shipment().Show();}private void button4_Click(object sender, EventArgs e){this.Close();new query().Show();}}
}
warehousing页面
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace fiber_yy
{public partial class warehousing : Form{public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";public warehousing(){InitializeComponent();}private void button2_Click(object sender, EventArgs e){OpenFileDialog ofdlgTest = new OpenFileDialog();//ofdlgTest.Filter = "*.jpg|*.png"; //文件过滤 筛选可以打开的文件ofdlgTest.Filter = "";ofdlgTest.Multiselect = false; //设置不可以选择多个文件//显示文件打开对话框DialogResult result = ofdlgTest.ShowDialog();//选择打开按钮的时候,将文件名显示到文本框中if (result == DialogResult.OK) //判断是否打开文件{this.textBox9.Text = ofdlgTest.FileName;pictureBox1.Image = Image.FromFile(ofdlgTest.FileName);}}private void button1_Click(object sender, EventArgs e){string path = textBox9.Text;FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); //将指定路径的图片添加到FileStream类中BinaryReader br = new BinaryReader(fs);//通过FileStream对象实例化BinaryReader对象byte[] imgBytesIn = br.ReadBytes(Convert.ToInt32(fs.Length));//将图片转为二进制数据//Save(imgBytesIn);//调用(自己写的一个方法)SqlConnection conn = new SqlConnection(constr);conn.Open();string name = textBox1.Text;SqlCommand cmd = new SqlCommand("insert into images (name,image) values(@name,@Image);", conn); //SQL语句cmd.Parameters.Add("@name", SqlDbType.VarChar);cmd.Parameters["@name"].Value = name;cmd.Parameters.Add("@Image", SqlDbType.Image);cmd.Parameters["@Image"].Value = imgBytesIn;cmd.ExecuteNonQuery();conn.Close();MessageBox.Show("图片上传成功");}private void button3_Click(object sender, EventArgs e){new main_page().Show();this.Hide();}}
}
query页面
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;namespace fiber_yy
{public partial class query : Form{public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";public query(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){try{byte[] MyData = new byte[0];SqlConnection conn = new SqlConnection(constr);string name = textBox1.Text;conn.Open();SqlCommand cmd = new SqlCommand();cmd.Connection = conn;cmd.CommandText = "select * from images where name='" + name + "'"; //写自己要查图片的name信息SqlDataReader sdr = cmd.ExecuteReader();sdr.Read();object o = sdr["Image"];MyData = (byte[])sdr["Image"];//读取第一个图片的位流MemoryStream memoryStream = null;memoryStream = new MemoryStream(MyData);pictureBox1.Image = Image.FromStream(memoryStream);//将图片赋给pictureBox1控件MessageBox.Show("读取成功");}catch {MessageBox.Show("读取失败,请检查是否存在该织物");}}}
}
四、效果演示
程序运行
注册我就不演示了,请参考前几篇博文
从yy_user表中找个账号密码,直接用户登录
登录成功
进入系统
目前先初步实现了入库管理功能和库存查询功能
先演示入库管理系统
原先数据库信息
入库管理功能目前主要是通过用户输入的面料名称和面料照片来存储
上传照片
入库
查看数据库信息
右击 images表 选择前1000行,更新数据库信息
最后一个为新入库的图片
接下来点击返回,返回到主页面,演示库存查询功能
点击button1
优化仍在继续…