一、数据库的创建
在fiber_yy数据库下创建yy_textile表
先随便添加几条数据
二、页面的完善
登录注册页面我就不演示了,前几篇博文也都有介绍
warehousing入库页面
main_page页面进行功能完善
三、代码实现
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.textBox11.Text = ofdlgTest.FileName;pictureBox1.Image = Image.FromFile(ofdlgTest.FileName);}}private void button1_Click(object sender, EventArgs e){try{string path = textBox11.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;int number = int.Parse(textBox2.Text);float warp_density = float.Parse(textBox3.Text);float weft_density = float.Parse(textBox4.Text);float warp_linear_density = float.Parse(textBox5.Text);float weft_linear_density = float.Parse(textBox6.Text);string material = textBox7.Text;float square_meter_weight = float.Parse(textBox8.Text);float width_of_cloth = float.Parse(textBox9.Text);float horse_length = float.Parse(textBox10.Text);string organization = textBox12.Text;int stock = int.Parse(textBox13.Text);SqlCommand cmd = new SqlCommand("insert into yy_textile (name,number,warp_density,weft_density,warp_linear_density,weft_linear_density,material,square_meter_weight,width_of_cloth,horse_length,picture,organization,stock) " +"values(@name,@number,@warp_density,@weft_density,@warp_linear_density,@weft_linear_density,@material,@square_meter_weight,@width_of_cloth,@horse_length,@picture,@organization,@stock);", conn); //SQL语句cmd.Parameters.Add("@name", SqlDbType.VarChar);cmd.Parameters["@name"].Value = name;cmd.Parameters.Add("@number", SqlDbType.Int);cmd.Parameters["@number"].Value = number;cmd.Parameters.Add("@warp_density", SqlDbType.Float);cmd.Parameters["@warp_density"].Value = warp_density;cmd.Parameters.Add("@weft_density", SqlDbType.Float);cmd.Parameters["@weft_density"].Value = weft_density;cmd.Parameters.Add("@warp_linear_density", SqlDbType.Float);cmd.Parameters["@warp_linear_density"].Value = warp_linear_density;cmd.Parameters.Add("@weft_linear_density", SqlDbType.Float);cmd.Parameters["@weft_linear_density"].Value = weft_linear_density;cmd.Parameters.Add("@material", SqlDbType.VarChar);cmd.Parameters["@material"].Value = material;cmd.Parameters.Add("@square_meter_weight", SqlDbType.Float);cmd.Parameters["@square_meter_weight"].Value = square_meter_weight;cmd.Parameters.Add("@width_of_cloth", SqlDbType.Float);cmd.Parameters["@width_of_cloth"].Value = width_of_cloth;cmd.Parameters.Add("@horse_length", SqlDbType.Float);cmd.Parameters["@horse_length"].Value = horse_length;cmd.Parameters.Add("@picture", SqlDbType.Image);cmd.Parameters["@picture"].Value = imgBytesIn;cmd.Parameters.Add("@organization", SqlDbType.VarChar);cmd.Parameters["@organization"].Value = organization;cmd.Parameters.Add("@stock", SqlDbType.Int);cmd.Parameters["@stock"].Value = stock;cmd.ExecuteNonQuery();conn.Close();MessageBox.Show("图片上传成功");}catch {MessageBox.Show("请核对输入信息");}}private void button3_Click(object sender, EventArgs e){new main_page().Show();this.Hide();}}
}
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();}}
}
四、效果演示
程序运行
注册我就不演示了,请参考前几篇博文
从yy_user表中找个账号密码,直接用户登录
登录成功
进入系统
首先演示下入库管理功能
入库