一、數據庫
數據庫仍用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品號紡織面料已被下架