当前位置:网站首页>3、 Upload fabric photos to SQL server and provide name to display fabric photos
3、 Upload fabric photos to SQL server and provide name to display fabric photos
2022-06-13 01:41:00 【Beyond proverb】
One 、 The establishment of database
Still fiber_yy Create... Under database images surface
images The table is designed as follows
Two 、 Page perfect design
main_page The function of the page is improved
Warehousing management system
warehousing page
Inventory query system
query page
The previous blog posts on the login registration page have been implemented , I will repeat it here , Still use the previous login page and database
3、 ... and 、 Code implementation
main_page 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(" Quit successfully ");
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 page
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"; // File filtering Filter files that can be opened
ofdlgTest.Filter = "";
ofdlgTest.Multiselect = false; // Set that multiple files cannot be selected
// The file open dialog box is displayed
DialogResult result = ofdlgTest.ShowDialog();
// When selecting the open button , Display the file name in the text box
if (result == DialogResult.OK) // Determine whether to open the file
{
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); // Add the picture of the specified path to FileStream Class
BinaryReader br = new BinaryReader(fs);// adopt FileStream Object instantiation BinaryReader object
byte[] imgBytesIn = br.ReadBytes(Convert.ToInt32(fs.Length));// Convert pictures to binary data
//Save(imgBytesIn);// call ( A way to write by yourself )
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 sentence
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(" Image upload succeeded ");
}
private void button3_Click(object sender, EventArgs e)
{
new main_page().Show();
this.Hide();
}
}
}
query page
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 + "'"; // Write the picture you want to check name Information
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
object o = sdr["Image"];
MyData = (byte[])sdr["Image"];// Read the bit stream of the first picture
MemoryStream memoryStream = null;
memoryStream = new MemoryStream(MyData);
pictureBox1.Image = Image.FromStream(memoryStream);// Assign pictures to pictureBox1 Control
MessageBox.Show(" Read successful ");
}
catch
{
MessageBox.Show(" Read failed , Please check if the fabric is present ");
}
}
}
}
Four 、 Effect demonstration
The program runs
I won't demonstrate if I register , Please refer to the previous blog posts
from yy_user Find an account and password in the table , Direct user login
Login successful
Entry system
At present, we have preliminarily realized Warehousing management function and Inventory query function
First demonstrate Warehousing management system
Original database information
At present, the warehousing management function mainly stores the fabric name and fabric photo entered by the user
Upload photos
Put in storage
View database information
Right click images surface Choose the former 1000 That's ok , Update database information
The last one is the newly stored picture
Next, click return , Go back to the main page , Demonstrate the inventory query function
Click on button1
Optimization continues …
边栏推荐
- Page optimization - Notes
- Stack stack LIFO
- A summary of global variables and typedef
- Introduction to common ROS commands
- Realization of flip animation
- 路径字段是什么? ——竞价广告
- 机器学习基础 SVM(支持向量机)
- Service creation and operation example of ROS
- [projet cs144 de Stanford Computing Network] lab1: Stream reassembler
- D template instance does not match declaration
猜你喜欢
A problem discovery and attempted solution to the strange stop of server script
Set and array conversion, list, array
Realization of flip animation
Machine learning basic SVM (support vector machine)
Jeux de plombiers
水管工遊戲
The storage structure of a tree can adopt the parent representation, that is, the parent pointer array representation. Try to give the corresponding class definition. Each tree node contains two membe
Explanation and application of prefix sum (one-dimensional, two-dimensional)
C language implementation of the classic eight queens problem
Plumber game
随机推荐
How to print infinite symbol in WPS
受众群体应该选择观察模式还是定位模式?
Stack stack LIFO
[MySQL password management] - [administrator password known, unknown (forgotten), cracked]
[official document summary] writing standards for academic dissertations of National University of science and technology
Machine learning basic SVM (support vector machine)
Lecture on Compilation Principles
ES6 deconstruction assignment
六、出库管理功能的实现
项目实训(十七)---个人工作总结
MySQL related summary
Stone from another mountain: Web3 investment territory of a16z
Detailed explanation of Joseph problem
Temporary objects and compilation optimization
MySQL download and installation
开发者来稿|AMD赛灵思中文论坛分享 - 提问的智慧
Introduction to ROS runtime
Leetcode find duplicates
About the proposed signature file migration to industry standard format pkcs12
Leetcode question brushing 07 double pointer