예제 #1
0
        /// <summary>
        /// 添加商品信息到销售记录表中
        /// </summary>
        /// <param name="id">商品ID</param>
        public void InsertSeall(string id)
        {
            SqlConnection sqlconn2 = ConnectionClass.MyConnection();

            sqlconn.Open();
            sqlconn2.Open();
            Random ran     = new Random();
            int    RandKey = ran.Next(1000, 999999);

            string        searchSql = "select Products_id,sealling_price,products_num,seall_date from Products_temp where Products_id=" + id;
            string        insertSql = "insert into Sell_detail values(";
            SqlCommand    cmd       = new SqlCommand(searchSql, sqlconn);
            SqlDataReader dr        = cmd.ExecuteReader();

            while (dr.Read())
            {
                insertSql += "'" + RandKey + "'," + dr["products_id"] + ",";
                insertSql += dr["sealling_price"] + "," + dr["products_num"] + ",'";
                insertSql += dr["seall_date"].ToString() + "')";

                Console.WriteLine(insertSql);

                SqlCommand    cmd2 = new SqlCommand(insertSql, sqlconn2);
                SqlDataReader dr2  = cmd2.ExecuteReader();
                dr2.Close();
            }
            sqlconn.Close();
            sqlconn2.Close();
        }
예제 #2
0
        /// <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();
            }
        }
예제 #3
0
        /// <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();
        }