一、數據庫的建立
由于查詢功能和之前的 入庫管理功能 所用的數據庫都一樣,這里仍使用yy_textile表
在fiber_yy數據庫下創建yy_textile表
初始數據庫信息
二、頁面的完善
登錄注冊頁面我就不演示了,前幾篇博文也都有介紹
query查詢頁面
main_page頁面進行功能完善
三、代碼實現
query查詢頁面
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{private DataSet dsall;public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";private SqlDataAdapter mDataAdapter;public query(){InitializeComponent();comboBox1.Items.Add("根據面料名稱查詢");comboBox1.Items.Add("根據品號查詢");}private void button1_Click(object sender, EventArgs e){try{SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);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, "hard");dataGridView1.DataSource = dsall.Tables["hard"];}catch {MessageBox.Show("讀取失敗,請檢查是否存在該織物");}}private void button2_Click(object sender, EventArgs e){this.Hide();new main_page().Show();}private void button3_Click(object sender, EventArgs e){try{string model = comboBox1.SelectedItem.ToString();string command = textBox1.Text;byte[] MyData = new byte[0];SqlConnection conn = new SqlConnection(constr);conn.Open();SqlCommand cmd = new SqlCommand();cmd.Connection = conn;//cmd.CommandText = "select * from yy_textile where '" + model + "'='" + command + "'"; //sql語句按指定條件進行if (model == "根據面料名稱查詢"){cmd.CommandText = "select * from yy_textile where name='" + command + "'";model = "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 name='" + command + "'";}if (model == "根據品號查詢"){cmd.CommandText = "select * from yy_textile where number='" + command + "'";model = "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='" + command + "'";}SqlDataReader sdr = cmd.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("讀取成功");conn = new SqlConnection(constr);mDataAdapter = new SqlDataAdapter(model, conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");dataGridView1.DataSource = dsall.Tables["hard"];}catch{MessageBox.Show("讀取失敗,請檢查是否存在該織物");}}}
}
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表中找個賬號密碼,直接用戶登錄
登錄成功
進入系統
演示庫存查詢
查閱所含全部織物信息
精確查找
根據面料名稱查詢
根據品號查詢