一、数据库
数据库仍用yy_textile表,前几篇博文都叙述过这里就不再叙述
在fiber_yy数据库下创建yy_textile表
初始数据库信息
二、页面
admin_undercarriage
三、代码实现
admin_undercarriage
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;namespace yy_Textile_fabric_inventory_management_system
{public partial class admin_undercarriage : Form{string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";//string str_conn = "";DataSet dsall;SqlDataAdapter mDataAdapter;public admin_undercarriage(){InitializeComponent();/*connect yy = new connect();string str = yy.str_conn();str_conn = str;*/// MessageBox.Show(str_conn);}private void button1_Click(object sender, EventArgs e){try{SqlConnection conn = new SqlConnection(str_conn);conn = new SqlConnection(str_conn);conn.Open();mDataAdapter = new SqlDataAdapter("SELECT name AS '面料名称',number AS '面料品号',warp_density AS '经密度' ,weft_density AS '纬密度',warp_linear_density AS '经纱线密度',weft_linear_density AS '纬纱线密度',material AS '原料成分',square_meter_weight AS '平方米重量',width_of_cloth AS '幅宽',horse_length AS '匹长',organization AS '所用组织',stock AS '库存量' FROM yy_textile", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "all_fiber");dataGridView1.DataSource = dsall.Tables["all_fiber"];conn.Close();}catch (Exception ex){MessageBox.Show(ex.Message);}}private void button2_Click(object sender, EventArgs e){try{string number = textBox1.Text;if (number.Length == 0) {MessageBox.Show("请输入纺织面料品号");}else{byte[] MyData = new byte[0];string sql = "SELECT stock FROM yy_textile WHERE number='" + number + "'";SqlConnection conn = new SqlConnection(str_conn);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();string account = cmd.ExecuteScalar().ToString();//MessageBox.Show(account);//int a = int.Parse(account);SqlConnection conn2 = new SqlConnection(str_conn);conn2 = new SqlConnection(str_conn);mDataAdapter = new SqlDataAdapter("SELECT name AS '面料名称',number AS '面料编号',warp_density AS '经密度' ,weft_density AS '纬密度',warp_linear_density AS '经纱线密度',weft_linear_density AS '纬纱线密度',material AS '原料成分',square_meter_weight AS '平方米重量',width_of_cloth AS '幅宽',horse_length AS '匹长',organization AS '所用组织',stock AS '库存量' FROM yy_textile where number='" + number + "'", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "fiber");dataGridView1.DataSource = dsall.Tables["fiber"];SqlConnection conn1 = new SqlConnection(str_conn);conn1.Open();SqlCommand cmd1 = new SqlCommand();cmd1.Connection = conn1;cmd1.CommandText = "select * from yy_textile where number='" + number + "'";SqlDataReader sdr = cmd1.ExecuteReader();sdr.Read();object o = sdr["picture"];MyData = (byte[])sdr["picture"];//读取第一个图片的位流MemoryStream memoryStream = null;memoryStream = new MemoryStream(MyData);pictureBox1.Image = Image.FromStream(memoryStream);//将图片赋给pictureBox1控件MessageBox.Show("读取成功");}}catch{MessageBox.Show("读取失败 over");}}private void button3_Click(object sender, EventArgs e){string number = textBox1.Text;string sql = "delete from yy_textile WHERE number='" + number + "'";SqlConnection conn = new SqlConnection(str_conn);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();int count = cmd.ExecuteNonQuery();//MessageBox.Show(count.ToString());if (count != 0){MessageBox.Show("下架成功");textBox1.Text="";}else {MessageBox.Show("下架失败");}}private void button4_Click(object sender, EventArgs e){new user_mainpage().Show();this.Close();}}
}
四、运行效果
检索功能
根据纺织面料品号查询详细信息
下架
重新检索
1014品号纺织面料已被下架