当前位置:网站首页>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 …
边栏推荐
- 30: Kakfa simulates JSON data generation and transmission
- Leetcode question brushing 03 stack
- How to print infinite symbol in WPS
- 水管工遊戲
- [Andoid][踩坑]CTS 11_r3开始出现的testBootClassPathAndSystemServerClasspath_nonDuplicateClasses FAIL问题分析
- Using OpenCV in go
- D template instance does not match declaration
- Uuid/guid introduction, generation rules and generation codes
- Leetcode question brushing 02 linked list operation
- [wsl2]wsl2 migrate virtual disk file ext4 vhdx
猜你喜欢

Leetcode question brushing 03 stack

How to solve the problems when using TV focusable to package APK in uni app

RSA encryption colloquial explanation

Quickly set the computer to turn off automatically

Record the VMware installation process of VMware Tools and some problems encountered
![[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx](/img/e9/4e08e07c2de2f99c2938e79f7f1c44.png)
[WSL2]WSL2迁移虚拟磁盘文件ext4.vhdx

Uuid/guid introduction, generation rules and generation codes

【斯坦福计网CS144项目】Lab1: StreamReassembler

Camera model_

Explanation and application of prefix sum (one-dimensional, two-dimensional)
随机推荐
[MySQL password management] - [administrator password known, unknown (forgotten), cracked]
numpy多维数组转置transpose
Torch. Distributions. Normal
Set and array conversion, list, array
Add default right-click menu
Sonarqube local installation
Leetcode 01 array
Record the VMware installation process of VMware Tools and some problems encountered
Should the audience choose observation mode or positioning mode?
他山之石:a16z 的 Web3 投资版图
如何通过受众群体定位解决实际问题?
DFS and BFS notes (II): depth first search (implemented in C language)
FSOs forest simulation optimization model learning notes
深度学习调参技巧详解
QT color extraction
Detailed explanation of deep learning parameter adjustment skills
#pragma comment(lib,“urlmon.lib“)
V-inline-date, similar to Ctrip, flying pig, time selection with price
The interviewer only asked me five questions and the interview was over
D template instance does not match declaration