一、系统主页面—Form1
系统运行加载页面,主要包含三个功能,①登录、②注册、③退出系统
程序运行图:
登录功能,跳转到登录页面
注册功能,跳转到注册页面
退出系统,程序结束运行
代码如下:
using System;
using System.Windows.Forms;namespace fiber_yy
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){this.Hide();new login().Show();}private void button3_Click(object sender, EventArgs e){MessageBox.Show("see you again~");Application.Exit(); //退出进程}private void button2_Click(object sender, EventArgs e){this.Hide();new register().Show();}}
}
二、用户注册—register
统一创建数据库fiber_yy
用户注册功能,用户需要填写账号、密码、性别、手机号
对应表名为yy_user,id为主键自增、username为账号、password为密码、sex为性别、phone为手机号
其中账号和密码长度为3-8,并且账号不允许重复,性别通过选择Checked方法来获取用户点击性别,手机号为11位数
若输入都符合要求,点击用户注册按钮,旁边的label6-label9会显示√,提示用户输入格式全部正确
若账号重复会弹窗提示此账号已存在~~~,点击确定,账号输入框自动清除,其他输入框保持原始记录
若账号、密码、手机号长度不对也会给予相应的弹窗提示
若全部格式输入成功,点击用户注册,弹窗提示注册成功!,点击确定,自动跳转Form1系统主页面
返回主页面按钮会返回到From1系统主页面
用户注册
当然,√也可以设置为红色,这种外观自己设置吧
代码如下:
using System;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace fiber_yy
{public partial class register : Form{/*server 主机名称Initial Catalog 数据库名称User ID=sa 默认不变pwd 数据库密码*/public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public register(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string sex="man";//默认值我设置为manlong phone_number=0;int account_number, password, sum=0;//若输入信息不满足要求sum会自加,最终判断sum为0时表示一切都符合要求account_number = textBox1.Text.Length;password = textBox2.Text.Length;phone_number = long.Parse(textBox3.Text);if (account_number <= 3 || account_number >= 8){label6.Text = "账号长度应该在3~8字符之间";sum++;}else{label6.Text = "校验成功";}if (password <= 3 || password >= 8){label7.Text = "密码长度应该在3~8字符之间";sum++;}else{label7.Text = "校验成功";}if (radioButton1.Checked){sex = "man";label8.Text = "校验成功";}else if (radioButton2.Checked){sex = "woman";label8.Text = "校验成功";}else{label8.Text = "请选择性别";}if (phone_number < 10000000000 || phone_number > 99999999999){label9.Text = "请输入正确的手机号";sum++;}else{label9.Text = "校验成功";}if (sum == 0){label6.Text = "√";label7.Text = "√";label8.Text = "√";label9.Text = "√";try{string sql = string.Format("select count(*) from yy_user where username='{0}'", textBox1.Text);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();int a = (int)cmd.ExecuteScalar();//返回一个值,看用户是否存在 1存在 0不存在StringBuilder strsql = new StringBuilder();if(a==1){MessageBox.Show("此账号已存在~~~");textBox1.Text = "";label6.Text = "";label7.Text = "";label8.Text = "";label9.Text = "";}else{string INSERT_sql = string.Format("INSERT INTO yy_user VALUES ('{0}','{1}','{2}','{3}')", textBox1.Text.Trim(), textBox2.Text.Trim(), sex, textBox3.Text.Trim());SqlCommand INSERT_cmd = new SqlCommand(INSERT_sql, conn);int count = INSERT_cmd.ExecuteNonQuery();if (count > 0){MessageBox.Show("注册成功!");conn.Close();this.Close();new Form1().Show();}else {MessageBox.Show("注册失败!");}}}catch(Exception ex){MessageBox.Show(ex.Message);}}}private void button2_Click(object sender, EventArgs e){this.Close();new Form1().Show();}}
}
三、用户登录—login
用户输入账号和密码以及验证码,验证码为随机生成的5个随机数
用户登录所用到的表为yy_user
用户登录
登录成功跳转到主页面main_page
登录的时候,同时会将用户的信息以及登录时间存入表yy_user_record中
yy_user_record表设计如下
username为登录账号、sex为账号用户的性别、phone为账号用户的手机号、time为此账号登录时间
没有存储密码是为了安全起见,此记录会在流水查询功能中进行展示
代码如下:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;namespace fiber_yy
{public partial class login : Form{public string name = "";public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public string identification = null;public login(){InitializeComponent();}private void button1_Click(object sender, EventArgs e)//登录{string sex = "";string phone = "";string day = DateTime.Now.ToLocalTime().ToString();//获取当前时间string username = textBox1.Text;string password = textBox2.Text;string identify = textBox3.Text;if (username.Equals("") || password.Equals("") || identify.Equals(""))//不能为空{MessageBox.Show("提示:请输入用户名、密码、验证码!", "警告");}else{string sqlSel = "select count(*) from yy_user where username = '" + username + "' and password = '" + password + "'";SqlCommand cmd = new SqlCommand(sqlSel, conn);conn.Open();if (Convert.ToInt32(cmd.ExecuteScalar()) > 0 )//账号密码正确{string sql = "select username,sex,phone from yy_user where username = '" + username + "'";SqlCommand com = new SqlCommand(sql, conn);SqlDataReader read = com.ExecuteReader();while (read.Read())//获取yy_user表中的username,sex,phone{name = read["username"].ToString();sex = read["sex"].ToString();phone = read["phone"].ToString();}read.Close();if (identify==identification)//判断验证码是否输入正确{string INSERT_sql = string.Format("INSERT INTO yy_user_record VALUES ('{0}','{1}','{2}','{3}')", name,sex,phone, DateTime.Now.ToLocalTime());SqlCommand INSERT_cmd = new SqlCommand(INSERT_sql, conn);int count = INSERT_cmd.ExecuteNonQuery();if (count > 0){MessageBox.Show("登录成功");conn.Close();new main_page().Show();this.Close();}else{MessageBox.Show("记录用户失败");conn.Close();}}else {MessageBox.Show("验证码输入错误");conn.Close();}}else{MessageBox.Show("请检查账号密码");conn.Close();}}}private void pictureBox1_Click(object sender, EventArgs e)//验证码{Random r = new Random();string str = null;for (int i = 0; i < 5; i++){int n = r.Next(0, 10);str += n;//包括字符串在内}identification = str;Bitmap b = new Bitmap(100, 15);Graphics g = Graphics.FromImage(b);for (int i = 0; i < 5; i++){String[] fonts = { "宋体", "黑体", "隶书", "仿宋", "微软雅黑" };//字体数组Color[] colors = { Color.Red, Color.Black, Color.Blue,Color.YellowGreen ,Color.Green };//颜色数组Font f = new Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);SolidBrush s = new SolidBrush(colors[r.Next(0, 5)]);//定义一个单独的画笔,使每个字符的颜色随机Point p = new Point(i * 20, 0);//每个字符间隔20g.DrawString(str[i].ToString(), Font, s, p);}for (int a = 0; a < 5; a++){Point p1 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));Point p2 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));//线的两点不能超过图片的长和宽Pen pen = new Pen(Brushes.Cyan);//青色线段g.DrawLine(pen, p1, p2);}pictureBox1.Image = b;}private void button2_Click(object sender, EventArgs e){new Form1().Show();this.Close();}private void button3_Click(object sender, EventArgs e){new retrieve_password().Show();this.Close();}}
}
四、找回密码—retrieve_password
找回密码
输入账号和注册时填写的手机号即可进行校验,校验通过进行修改密码,跳转change_password修改密码页面
可以设置显示验证码框
验证通过跳转change_password修改密码页面
代码如下:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;namespace fiber_yy
{public partial class retrieve_password : Form{public string name = "";public string identification = null;public string phone = "";public string phone_db = "";public string username = "";public string username_db = "";public string identify = "";public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public retrieve_password(){InitializeComponent();}private void pictureBox1_Click(object sender, EventArgs e){Random r = new Random();string str = null;for (int i = 0; i < 5; i++){int n = r.Next(0, 10);str += n;//包括字符串在内}identification = str;Bitmap b = new Bitmap(100, 15);Graphics g = Graphics.FromImage(b);for (int i = 0; i < 5; i++){String[] fonts = { "宋体", "黑体", "隶书", "仿宋", "微软雅黑" };//字体数组Color[] colors = { Color.Red, Color.Black, Color.Blue, Color.YellowGreen, Color.Green };//颜色数组Font f = new Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);SolidBrush s = new SolidBrush(colors[r.Next(0, 5)]);//定义一个单独的画笔,使每个字符的颜色随机Point p = new Point(i * 20, 0);//每个字符间隔20g.DrawString(str[i].ToString(), Font, s, p);}for (int a = 0; a < 5; a++){Point p1 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));Point p2 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));//线的两点不能超过图片的长和宽Pen pen = new Pen(Brushes.Cyan);//青色线段g.DrawLine(pen, p1, p2);}pictureBox1.Image = b;}private void button1_Click(object sender, EventArgs e){username = textBox1.Text;phone = textBox2.Text;identify = textBox3.Text;if (identify == identification)//判断验证码是否输入正确{conn.Open();string sql = "select username,phone from yy_user where username = '" + username + "'";SqlCommand com = new SqlCommand(sql, conn);SqlDataReader read = com.ExecuteReader();while (read.Read())//获取yy_user表中的username,sex,phone{username_db = read["username"].ToString();phone_db = read["phone"].ToString();}read.Close();if(phone_db==phone){conn.Close();MessageBox.Show("校验通过");new change_password(username).Show();this.Close();}else {conn.Close();MessageBox.Show("注册手机号不对");}}else{conn.Close();MessageBox.Show("验证码输入错误");}}private void button2_Click(object sender, EventArgs e){new login().Show();this.Hide();}}}
五、修改密码—change_password
修改yy_user表中账号对应的密码
点击确定,自动跳转至登录页面login
代码如下:
using System;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace fiber_yy
{public partial class change_password : Form{public string name = "";public string password = "";public string password1 = "";public string username = "";public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public change_password(){InitializeComponent();}public change_password(string yy)//接收登录用户的账号信息{InitializeComponent();username = yy;}private void button1_Click(object sender, EventArgs e){password = textBox1.Text;password1 = textBox2.Text;conn.Open();if (password.Length <= 3 || password.Length >= 8){label3.Text = "密码长度应该在3~8字符之间";conn.Close();}else if(password != password1){label3.Text = "两次输入密码不一致";conn.Close();}else if(password==password1){string sql = "update yy_user set password = '"+ password + "' where username = '" + username + "'";SqlCommand com = new SqlCommand(sql, conn);com.ExecuteNonQuery();//返回值为操作的条数MessageBox.Show("修改成功");conn.Close();new login().Show();this.Close();}}}
}
六、主页面—main_page
主页面也就起到跳转的作用
代码如下:
using System;
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();}private void button5_Click(object sender, EventArgs e){this.Close();new flow_query().Show();}}
}
七、入库管理功能—warehousing
所用到yy_textile表
入库管理页面warehousing
代码如下:
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
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 = "";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.Close();}}
}
八、出库管理功能—shipment
出库管理功能,用户通过查询数据库中织物信息,通过织物唯一编号来查看织物信息,输入出库数量即可出库。此时的出库信息将会被记录到数据表yy_textile_record中,用户可以通过流水查询功能进行查看。并且,若织物库存小于100,则检索时会进行库存不足提示
涉及到出库记录表yy_textile_record
用于记录什么时候哪个账号,该账号手机号是多少,出库了哪个织物多少库存信息
代码如下:
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;namespace fiber_yy
{public partial class shipment : Form{private DataSet dsall;public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";private SqlDataAdapter mDataAdapter;public login login = new login();public shipment(){InitializeComponent();try{string username = login.name;MessageBox.Show(username);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 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)//查看织物信息{try{string number = textBox1.Text;byte[] MyData = new byte[0];string sql = "SELECT stock FROM yy_textile WHERE number='" + number + "'";SqlConnection conn = new SqlConnection(constr);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();string account = cmd.ExecuteScalar().ToString();int a = int.Parse(account);if (a > 100){SqlConnection conn2 = new SqlConnection(constr);conn2 = 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 where number='" + number + "'", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");dataGridView1.DataSource = dsall.Tables["hard"];SqlConnection conn1 = new SqlConnection(constr);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("读取成功");}else {conn.Close();MessageBox.Show("库存不足100请及时补充!!!");}}catch{MessageBox.Show("读取失败 over");}}private void button3_Click(object sender, EventArgs e)//出库{string time = DateTime.Now.ToLocalTime().ToString();try{string sql1;string number = this.textBox1.Text;int count = int.Parse(textBox2.Text);SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);string sql = "SELECT number FROM yy_textile WHERE number='" + number + "'";SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();string amount = cmd.ExecuteScalar().ToString();int a = int.Parse(amount);if (a>count) {sql1 = "update yy_textile set stock = stock - '" + count + "' where number='" + number + "'";mDataAdapter = new SqlDataAdapter(sql1, conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");dataGridView1.DataSource = dsall.Tables["hard"];MessageBox.Show("出库成功!!!");string username = "";string sql2 = "SELECT TOP 1 username from yy_user_record order by id desc";SqlCommand com = new SqlCommand(sql2, conn);SqlDataReader read = com.ExecuteReader();while (read.Read())//获取yy_user表中的username,sex,phone{username = read["username"].ToString();MessageBox.Show(username);}read.Close();string INSERT_sql = string.Format("INSERT INTO yy_textile_record VALUES ('{0}','{1}','{2}','{3}')", number, count, username, DateTime.Now.ToLocalTime());SqlCommand INSERT_cmd = new SqlCommand(INSERT_sql, conn);int count1 = INSERT_cmd.ExecuteNonQuery();if (count1 > 0){MessageBox.Show("记录纤维出库信息成功!");conn.Close();}else{MessageBox.Show("记录纤维出库信息失败");conn.Close();}}else {MessageBox.Show("库存不足无法出库");conn.Close();}}catch (Exception ex) { MessageBox.Show(ex.Message); }finally{ }}private void button4_Click(object sender, EventArgs e){new main_page().Show();this.Close();}}
}
九、库存查询—query
库存查询所用数据表为yy_textile和七中表一样,查询表中的指定数据信息
代码如下:
using System;
using System.IO;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
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);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, "hard");dataGridView1.DataSource = dsall.Tables["hard"];conn.Close();}catch {MessageBox.Show("读取失败,请检查是否存在该织物");}}private void button2_Click(object sender, EventArgs e){new main_page().Show();this.Close();}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;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"];conn.Close();}catch{MessageBox.Show("读取失败,请检查是否存在该织物");}}}
}
十、流水查询—flow_query
流水查询功能主要包括用户登录信息的查询以及所有出库纺织品信息,用到yy_user_record表和yy_textile_record表
代码如下:
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace fiber_yy
{public partial class flow_query : Form{private DataSet dsall;public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";private SqlDataAdapter mDataAdapter;public flow_query(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){try{SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);conn.Open();mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',sex AS '性别',phone AS '手机号',time AS '登录时间' FROM yy_user_record", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");MessageBox.Show(dsall.ToString());dataGridView1.DataSource = dsall.Tables["hard"];conn.Close();}catch{MessageBox.Show("读取失败");}}private void button2_Click(object sender, EventArgs e){string account = textBox1.Text;try{SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);conn.Open();mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',sex AS '性别',phone AS '手机号',time AS '登录时间' FROM yy_user_record WHERE username='" + account + "'", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");dataGridView1.DataSource = dsall.Tables["hard"];conn.Close();}catch{MessageBox.Show("读取失败");}}private void button3_Click(object sender, EventArgs e){try{SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);conn.Open();mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',number AS '纤维品号',stock AS '取货数量',time AS '出货时间' FROM yy_textile_record", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");MessageBox.Show(dsall.ToString());dataGridView2.DataSource = dsall.Tables["hard"];conn.Close();}catch{MessageBox.Show("读取失败");}}private void button4_Click(object sender, EventArgs e){string number = textBox2.Text;try{SqlConnection conn = new SqlConnection(constr);conn = new SqlConnection(constr);conn.Open();mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',number AS '纤维品号',stock AS '取货数量',time AS '出货时间' FROM yy_textile_record WHERE number='" + number + "'", conn);dsall = new DataSet();mDataAdapter.Fill(dsall, "hard");dataGridView2.DataSource = dsall.Tables["hard"];conn.Close();}catch{MessageBox.Show("读取失败");}}}
}
后续仍会进行优化…
未完待续…