/// <summary> /// 商品条码自动补全功能,可以在输入条码过程中自动提示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBoxId_TextChanged(object sender, EventArgs e) { SqlConnection sqlconn = ConnectionClass.MyConnection(); try { sqlconn.Open(); listBox1.Items.Clear(); if (textBoxId.Text.ToString().Length >= 4) { AutoCompleteStringCollection mystring = new AutoCompleteStringCollection(); string strId = textBoxId.Text; DataTable myTable = new DataTable(); myTable.Columns.Add("Products_id"); string strSql = "select Products_id from Products";// where Products_id like '%"; //strSql += strId + "%'"; SqlCommand cmd = new SqlCommand(strSql, sqlconn); SqlDataReader dar = cmd.ExecuteReader(); while (dar.Read()) { myTable.Rows.Add(dar["Products_id"].ToString()); } DataRow[] dr = myTable.Select("Products_id like '%" + textBoxId.Text + "%'"); DataTable newdt = new DataTable(); newdt = myTable.Clone(); foreach (DataRow row in dr) { newdt.Rows.Add(row.ItemArray); } if (myTable.Rows.Count > 0 && (textBoxId.Text != "")) { listBox1.Visible = true; for (int i = 0; i < newdt.Rows.Count; i++) { listBox1.Items.Add(newdt.Rows[i]["Products_id"].ToString()); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sqlconn.Close(); } }
/// <summary> /// 商品销售临时表操作,进行数据的更新 /// </summary> /// <param name="tableId">表中的编号</param> public void OpProductTemp(string tableId) { SqlConnection sqlconn2 = ConnectionClass.MyConnection(); sqlconn.Open(); sqlconn2.Open(); string InsertSql = "insert into Products_Temp values("; string SearchSql = "select products_id,products_name,products_spec,sealling_price from products where products_id=" + tableId; SqlCommand cmd = new SqlCommand(SearchSql, sqlconn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { InsertSql += dr["products_id"] + ",'" + dr["products_name"].ToString() + "','" + dr["products_spec"] + "','"; InsertSql += dr["sealling_price"].ToString() + "'," + 1 + ",'" + DateTime.Now.ToString() + "')"; SqlCommand cmd2 = new SqlCommand(InsertSql, sqlconn2); SqlDataReader dr2 = cmd2.ExecuteReader(); } sqlconn.Close(); sqlconn2.Close(); }