方案规划
第一方案A工序 程序界面
第一方案 A工序代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Data.Sql; using System.Data.SqlClient; namespace 防窜货系统 { public partial class F_Master : Form { public F_Master() { InitializeComponent(); } SqlConnection con = new SqlConnection("server = 172.168.0.15;database = factory ;uid= sa ;pwd= 123456789"); string invcode = ""; #region 装箱 private void TsmZX_Click(object sender, EventArgs e) { panelMaster.Visible = true; tbInvcode.Focus(); tbBoxCode.Enabled = false; try { con.Open(); if (con.State == ConnectionState.Open) { labMessage.Text = "系统准备就绪!"; } else { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } con.Close(); } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } #endregion #region 拆箱 private void tsmCX_Click(object sender, EventArgs e) { F_Del f = new F_Del(this); this.Enabled = false; f.ShowDialog(this); } #endregion #region 程序载入 private void F_Master_Load(object sender, EventArgs e) { tbMcode.Text = Dns.GetHostName(); } #endregion #region 扫入产品码 private void tbInvcode_KeyDown(object sender, KeyEventArgs e) { con.Open(); if (e.KeyCode == Keys.Enter) { if (tbInvcode.Text != "") { labBoxcodeMsg.Text = ""; labInvcodeMsg.Text = ""; labMessage.Text = ""; string selectInvcode = "select * from SuporMaster where invcode = '" + tbInvcode.Text.ToString().Trim() + "' "; SqlCommand cmd = new SqlCommand(selectInvcode, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables[0].Rows.Count==0) { invcode = tbInvcode.Text.ToString(); tbBoxCode.Text = ""; tbBoxCode.Enabled = true; tbBoxCode.Focus(); tbInvcode.Enabled = false; } else { labInvcodeMsg.Text = "产品:" + tbInvcode.Text.ToString(); labMessage.Text = "已存在装箱记录,不能重复装箱,请检查!"; labMessage.ForeColor = Color.Red; labInvcodeMsg.ForeColor = Color.Red; tbInvcode.Text = ""; } } else { labMessage.Text = "产品码不能为空!"; labMessage.ForeColor = Color.Red; } } con.Close(); } #endregion #region 扫入箱码 private void tbBoxCode_KeyDown(object sender, KeyEventArgs e) { con.Open(); if (e.KeyCode == Keys.Enter) { if (tbBoxCode.Text != "") { string selectBoxCode = "select * from SuporMaster where boxnum = '" + tbBoxCode.Text.ToString().Trim() + "'"; SqlCommand cmdA = new SqlCommand(selectBoxCode, con); SqlDataAdapter sda = new SqlDataAdapter(cmdA); DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables[0].Rows.Count==0) { tbInvcode.Enabled = true; tbInvcode.Text = ""; tbInvcode.Focus(); string productid = tbBoxCode.Text + invcode; string str = " insert into SuporMaster (ProductNum,BoxNum,Invcode,date,Mcode,OutsideBox) values ('" + productid + "','" + tbBoxCode.Text.ToString() + "','" + invcode + "' ,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + tbMcode.Text.ToString() + "' ,'1')"; try { if (con.State == ConnectionState.Open) { SqlCommand cmd = new SqlCommand(str, con); try { cmd.ExecuteNonQuery(); labInvcodeMsg.Text = "产品:" + invcode; labBoxcodeMsg.Text = "彩箱:" + tbBoxCode.Text.ToString(); labMessage.Text = "装箱成功!"; labInvcodeMsg.ForeColor = Color.Green; labBoxcodeMsg.ForeColor = Color.Green; labMessage.ForeColor = Color.Green; } catch { labMessage.Text = "装箱失败!"; labMessage.ForeColor = Color.Red; } } tbBoxCode.Enabled = false; tbBoxCode.Text = ""; } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } else { labBoxcodeMsg.Text = "彩箱:" + tbBoxCode.Text.ToString(); labMessage.Text = "已存在装箱记录,不能重复装箱,请检查!"; labMessage.ForeColor = Color.Red; labBoxcodeMsg.ForeColor = Color.Red; tbBoxCode.Text = ""; } } else { labMessage.Text = "彩箱码不能为空!"; labMessage.ForeColor = Color.Red; } } con.Close(); } #endregion } }
第一方案 B工序程序界面
第一方案B工序代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Data.Sql; using System.Data.SqlClient; namespace 防窜货系统 { public partial class F_Master : Form { public F_Master() { InitializeComponent(); } SqlConnection con = new SqlConnection("server = 172.168.0.15;database = factory ;uid= sa ;pwd= 12346789"); string oldMcode = ""; //存之前的机号 string boxNum = ""; //存彩箱号 string strOutsideBox = "";//存数据库中现有的外箱码 #region 装箱 private void TsmZX_Click(object sender, EventArgs e) { panelMaster.Visible = true; tbBoxCode.Focus(); tbOutsideBox.Enabled = false; try { con.Open(); if (con.State == ConnectionState.Open) { labMessage.Text = "系统准备就绪!"; } else { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } con.Close(); } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } #endregion #region 拆箱 private void tsmCX_Click(object sender, EventArgs e) { F_Del f = new F_Del(this); this.Enabled = false; f.ShowDialog(this); } #endregion #region 程序载入 private void F_Master_Load(object sender, EventArgs e) { tbMcode.Text = Dns.GetHostName(); } #endregion #region 扫入彩箱码 private void tbInvcode_KeyDown(object sender, KeyEventArgs e) { con.Open(); if (e.KeyCode == Keys.Enter) { if (tbBoxCode.Text != "") { labOutsideMsg.Text = ""; labBoxcodeMsg.Text = ""; labMessage.Text = ""; string selectBOXcode = "select * from SuporMaster where BoxNum = '" + tbBoxCode.Text.ToString().Trim() + "' "; SqlCommand cmd = new SqlCommand(selectBOXcode, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables[0].Rows.Count != 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { oldMcode = ds.Tables[0].Rows[i]["Mcode"].ToString(); strOutsideBox = ds.Tables[0].Rows[i]["OutsideBox"].ToString(); } boxNum = tbBoxCode.Text; //将彩箱码赋于变量boxnum if (strOutsideBox != "1") { labBoxcodeMsg.ForeColor = Color.Red; labOutsideMsg.ForeColor = Color.Red; labMessage.ForeColor = Color.Red; labBoxcodeMsg.Text = "彩箱:<" + boxNum + ">已经与"; labOutsideMsg.Text = "外箱:<" + strOutsideBox + ">装过箱"; labMessage.Text = "请检查!"; // tbOutsideBox.Text = ""; tbBoxCode.Text = ""; tbBoxCode.Enabled = true; tbBoxCode.Focus(); } else { tbOutsideBox.Text = ""; //将外箱码置空 tbOutsideBox.Enabled = true; //外箱码激活 tbOutsideBox.Focus(); //外箱码获取焦点 tbBoxCode.Enabled = false; // 彩箱码锁定 } } else { labBoxcodeMsg.Text = "彩箱:<" + tbBoxCode.Text.ToString() + ">"; labMessage.Text = "不存在产品装箱记录,请检查!"; labMessage.ForeColor = Color.Red; labBoxcodeMsg.ForeColor = Color.Red; tbBoxCode.Text = ""; } } else { labMessage.Text = "彩箱码不能为空!"; labMessage.ForeColor = Color.Red; } } con.Close(); } #endregion #region 扫入外箱码 private void tbBoxCode_KeyDown(object sender, KeyEventArgs e) { con.Open(); string strBoxCode = ""; //存数据库中现在有彩箱码 if (e.KeyCode == Keys.Enter) { if (tbOutsideBox.Text != "" && tbBoxCode.Text != "") { string selectBoxCode = "select * from SuporMaster where OutsideBox ='" + tbOutsideBox.Text.ToString().Trim() + "'"; SqlCommand cmdA = new SqlCommand(selectBoxCode, con); SqlDataAdapter sda = new SqlDataAdapter(cmdA); DataSet ds = new DataSet(); sda.Fill(ds); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { strBoxCode = ds.Tables[0].Rows[i]["BoxNum"].ToString(); strOutsideBox = ds.Tables[0].Rows[i]["OutsideBox"].ToString(); } if (strOutsideBox == "1" && tbOutsideBox.Text.ToString() != strOutsideBox) { tbBoxCode.Enabled = true; tbBoxCode.Text = ""; tbBoxCode.Focus(); string mcode = oldMcode + "|" + Dns.GetHostName(); //拼接原机号和现机号 //更新外箱号和机号 string str = " update SuporMaster set outsidebox ='" + tbOutsideBox.Text.ToString().Trim() + "', Mcode='" + mcode + "' where BoxNum='" + boxNum + "'"; try { if (con.State == ConnectionState.Open) { SqlCommand cmd = new SqlCommand(str, con); try { cmd.ExecuteNonQuery(); labBoxcodeMsg.Text = "彩箱:" + boxNum; ; labOutsideMsg.Text = "外箱:" + tbOutsideBox.Text.ToString(); labMessage.Text = "装箱成功!"; labBoxcodeMsg.ForeColor = Color.Green; labOutsideMsg.ForeColor = Color.Green; labMessage.ForeColor = Color.Green; } catch { labMessage.Text = "装箱失败!"; labMessage.ForeColor = Color.Red; } } tbOutsideBox.Enabled = false; tbOutsideBox.Text = ""; } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } else { labBoxcodeMsg.ForeColor = Color.Red; labOutsideMsg.ForeColor = Color.Red; labMessage.ForeColor = Color.Red; labBoxcodeMsg.Text = "外箱:<" + strOutsideBox + ">已经与"; labOutsideMsg.Text = "彩箱:<" + strBoxCode + ">装过箱"; labMessage.Text = "请检查!"; // tbOutsideBox.Text = ""; tbBoxCode.Text = ""; tbBoxCode.Enabled = true; tbBoxCode.Focus(); } } else { labMessage.Text = "彩箱码或者外箱码为空,请检查!"; labMessage.ForeColor = Color.Red; } } con.Close(); } #endregion } }
第二方案 A工序 程序界面
第二方案 A工序代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Data.Sql; using System.Data.SqlClient; namespace 防窜货系统 { public partial class F_Master : Form { public F_Master() { InitializeComponent(); } SqlConnection con = new SqlConnection("server = 172.168.0.15;database = factory ;uid= sa ;pwd= 123456789"); #region 程序载入 private void F_Master_Load(object sender, EventArgs e) { tbMcode.Text = Dns.GetHostName(); try { con.Open(); if (con.State == ConnectionState.Open) { labMessage.Text = "系统准备就绪!"; labMessage.ForeColor = Color.Green; } else { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } con.Close(); } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } #endregion #region 扫入产品码 private void tbInvcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (tbInvcode.Text != "") { if (falg() == true) { con.Open(); string str = "insert into SuporFCH(invcode,McodeA,DateA)values('" + tbInvcode.Text.ToString().Trim() + "','" + tbMcode.Text.ToString().Trim() + "','" + DateTime.Now.ToString() + "') "; try { if (con.State == ConnectionState.Open) { SqlCommand cmd = new SqlCommand(str, con); try { cmd.ExecuteNonQuery(); labMessage.Text = tbInvcode.Text.ToString().Trim() + "扫码成功!"; labMessage.ForeColor = Color.Green; } catch { labMessage.Text = "装箱失败!"; labMessage.ForeColor = Color.Red; } } } catch { labMessage.Text = "数据库连接错误,请检查网络连接!"; } con.Close(); } else { labMessage.Text = tbInvcode.Text.ToString().Trim()+"重复,请检查!"; labMessage.ForeColor = Color.Red; } } else { labMessage.Text = "产品码不能为空,请检查!"; labMessage.ForeColor = Color.Red; } tbInvcode.Text = ""; } } #endregion //判断产品码是否重复 private bool falg() { con.Open(); string str ="select * from SuporFCH where invcode='"+tbInvcode.Text.ToString().Trim()+"'" ; SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); con.Close(); if (ds.Tables[0].Rows.Count == 0) { return true; } else { return false; } } } }
第二方案 B工序界面
第二方案 B工序代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; using System.Data.Sql; using System.Data.SqlClient; namespace 防窜货系统 { public partial class F_Master : Form { public F_Master() { InitializeComponent(); } SqlConnection con = new SqlConnection("server = 172.168.0.15;database = factory ;uid= sa ;pwd= 123456789"); #region 程序载入 private void F_Master_Load(object sender, EventArgs e) { tbMcode.Text = Dns.GetHostName(); selectFalg(); selectAll(); try { con.Open(); if (con.State == ConnectionState.Open) { labMessage.Text = "系统准备就绪!"; labMessage.ForeColor = Color.Green; } else { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } con.Close(); } catch { labMessage.Text = "数据库连接错误,请检查网络设置或联系开发人员!"; labMessage.ForeColor = Color.Red; } } #endregion #region 扫入外箱码 private void tbInvcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (tbBoxCode.Text != "") { if (flag() == true) { con.Open(); string str = " update SuporFCH set boxcode = '"+tbBoxCode.Text.ToString().Trim()+"',mcodeB='"+tbMcode.Text.ToString().Trim()+"',dateb='"+DateTime.Now.ToString()+"' where ID=(select MIN(id) as id from SuporFCH where boxcode is null)"; SqlCommand cmd = new SqlCommand(str, con); try { cmd.ExecuteNonQuery(); labMessage.Text = "<" + tbBoxCode.Text.ToString().Trim() + ">装箱成功,请检查!"; labMessage.ForeColor = Color.Green; } catch { labMessage.Text = "<" + tbBoxCode.Text.ToString().Trim() + ">装箱失败,请检查!"; labMessage.ForeColor = Color.Red; } con.Close(); } else { labMessage.Text = "外箱码<" + tbBoxCode.Text.ToString().Trim() + ">重复,请检查!"; labMessage.ForeColor = Color.Red; } selectFalg(); selectAll(); } else { labMessage.Text = "彩箱码不能为空!"; labMessage.ForeColor = Color.Red; } tbBoxCode.Text = ""; } } #endregion //显示产品码 private void selectFalg() { con.Open(); string str = " select ID as 流水号,invcode as 产品码 from suporfch where boxcode is null order by id"; try { if (con.State == ConnectionState.Open) { SqlDataAdapter sda = new SqlDataAdapter(str, con); DataSet ds = new DataSet(); sda.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } } catch { labMessage.Text = "数据库连接出错,请检查网络!"; labMessage.ForeColor = Color.Red; } con.Close(); } //判断箱码是否重复 private bool flag() { con.Open(); string str = " select * from SuporFCH where boxcode='" + tbBoxCode.Text.ToString().Trim() + "' "; SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sda.Fill(ds); con.Close(); if (ds.Tables[0].Rows.Count == 0) { return true; } else { return false; } } //显示扫入的外箱码 private void selectAll() { con.Open(); string str = "select top 100 ID as 流水号,invcode as 产品码,boxcode as 外箱码 from suporfch where boxcode is not null order by ID desc"; try { if (con.State == ConnectionState.Open) { SqlDataAdapter sda = new SqlDataAdapter(str, con); DataSet ds = new DataSet(); sda.Fill(ds); dataGridView2.DataSource = ds.Tables[0]; } } catch { labMessage.Text = "数据库连接出错,请检查网络!"; labMessage.ForeColor = Color.Red; } con.Close(); } //拆箱 private void butCX_Click(object sender, EventArgs e) { F_Del f = new F_Del(this); this.Enabled = false; f.ShowDialog(this); } private void timer1_Tick(object sender, EventArgs e) { selectFalg(); } } }