private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { var itemlist = barBll.GetList().Where(b => b.CodeBard.Equals(txtCodeBard.Text)).AsQueryable(); int Num = itemlist.ToList().Count; if (Num > 0) { // txtItemName.Enabled = false; // txtBrandName.Enabled = false; if (Num == 1) { txtBrandCode.Text = itemlist.SingleOrDefault().BrandCode; txtBrandName.Text = itemlist.SingleOrDefault().BrandName; txtItemCode.Text = itemlist.SingleOrDefault().ItemCode; txtItemName.Text = itemlist.SingleOrDefault().ItemName; } else { loaditem(itemlist.ToList()); groupBox6.Visible = true; dataGridView6.Focus(); } } else { var takelist = takeBll.GetList().Where(b => b.CodeBard.Equals(txtCodeBard.Text)).AsQueryable(); Num = takelist.ToList().Count; if (Num > 0) { if (Num == 1) { txtBrandCode.Text = takelist.SingleOrDefault().BrandCode; txtBrandName.Text = takelist.SingleOrDefault().BrandName; txtItemCode.Text = takelist.SingleOrDefault().ItemCode; txtItemName.Text = takelist.SingleOrDefault().ItemName; } else { var blist = takeBll.GetList().Where(b => b.CodeBard.Equals(txtCodeBard.Text)).GroupBy(a => new { a.ItemCode, a.ItemName, a.BrandCode, a.BrandName }).Select(c => c.Key).ToList().Select(c => new BarCodeInfo { ItemCode = c.ItemCode, ItemName = c.ItemName, BrandCode = c.BrandCode, BrandName = c.BrandName }).ToList(); loaditem(blist); groupBox6.Visible = true; dataGridView6.Focus(); } } txtItemName.Enabled = true; txtBrandName.Enabled = true; } label5.Text = checkexitsbar(txtCodeBard.Text); txtCodeBard.SelectAll(); txtTV1.Focus(); } }
public void GetBaseInfo() { this.Invoke(new Action(() => { this.lblprocessmsg.Text = "开始从服务器获取数据..."; this.button1.Enabled = false; })); try { var suc = new SoapUnitTOM.SoapUnitClient(); DataTable dt = suc.GetData(1, "BAR_FOR_STOCK", null); BarCodeInfo barCodeinfo; // OleDbConnection acn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "\\StoreTake.mdb"); // OleDbCommand amd; // acn.Open(); this.Invoke(new Action(() => { this.lblprocessmsg.Text = "待更新条码数" + dt.Rows.Count.ToString(); this.button1.Enabled = false; })); // barCodeInfoBll.RemoveAll(); for (int i = 0; i < dt.Rows.Count; i++) { barCodeinfo = new BarCodeInfo(); barCodeinfo.ItemCode = dt.Rows[i]["ItemCode"].ToString(); barCodeinfo.ItemName = dt.Rows[i]["ItemName"].ToString(); barCodeinfo.CodeBard = dt.Rows[i]["CodeBard"].ToString(); barCodeinfo.BrandCode = dt.Rows[i]["BrandCode"].ToString(); barCodeinfo.BrandName = dt.Rows[i]["BrandName"].ToString(); this.Invoke(new Action(() => { this.lblprocessmsg.Text = "更新条码" + dt.Rows[i][0].ToString(); this.button1.Enabled = false; })); string _itemcode = dt.Rows[i]["ItemCode"].ToString(); BarCodeInfo result = barCodeInfoBll.GetList().Where(b => b.ItemCode.Equals(_itemcode)).SingleOrDefault(); if (result != null) { barCodeInfoBll.Remove(result.ID); } if (barCodeInfoBll.Add(barCodeinfo)) { this.Invoke(new Action(() => { this.lblprocessmsg.Text = "更新" + dt.Rows[i]["CodeBard"].ToString(); this.button1.Enabled = false; })); } //this.Invoke(new Action(() => //{ // this.richTextBox1.Text = "insert into BarCodeInfo(ItemCode,ItemName,CodeBard,BrandCode,BrandName) values('" + dt.Rows[i]["ItemCode"].ToString() + "','" + dt.Rows[i]["ItemName"].ToString() + "','" + dt.Rows[i]["CodeBard"].ToString() + "','" + dt.Rows[i]["BrandCode"].ToString() + "','" + dt.Rows[i]["BrandName"] + "')"; // this.lblprocessmsg.Text = dt.Rows[i]["ItemCode"].ToString() + "下载插入中..."; // this.button1.Enabled = false; //})); } // acn.Close(); this.Invoke(new Action(() => { this.lblprocessmsg.Text = "同步数据完成!"; this.button1.Enabled = true; })); } catch (Exception ee) { MessageBox.Show(ee.ToString()); this.Invoke(new Action(() => { this.richTextBox1.AppendText(ee.ToString()); this.button1.Enabled = true; })); return; } }