/// <summary> /// DataGridView委托赋值函数 /// </summary> /// <param name="view"></param> /// <param name="info"></param> private void SetDataGridViewInfo(DataGridView view, APIClient.MerchandiseInfoShow info) { if (view.InvokeRequired) { setDataGridViewInfo setThis = new setDataGridViewInfo(SetDataGridViewInfo); view.Invoke(setThis, view, info); } else { view.ColumnCount = 8; view.Columns[0].Name = "ID"; view.Columns[1].Name = "店内码"; view.Columns[2].Name = "条形码"; view.Columns[3].Name = "名称"; view.Columns[4].Name = "品牌"; view.Columns[5].Name = "规模"; view.Columns[6].Name = "厂家"; view.Columns[7].Name = "单位"; string[] row = new string[] { info.ID, info.Code, info.Barcode, info.Name, info.Brand, info.Scale, info.Factory, info.Unit }; view.Rows.Clear(); view.Rows.Add(row); } }
/// <summary> /// 将条形码查询所得的商品信息显示在界面上 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowMerchandiseInfoInDatagrid(object sender, TX200Scanner.BarcodeScannerEventArgs e) { if (e.Code != "") { char[] trimchars = new char[2] { '\0', ' ' }; string code = e.Code.Trim(trimchars); APIClient.MerchandiseInfoShow info = client.GetMerchandiseInfo(new APIClient.Barcode() { barcode = code }); System.Threading.Thread.Sleep(3000); SetDataGridViewInfo(dataGridView1, info); //保存本次查询结果 lastinfo = info; //启动RFID扫描器 startInventory(); //启动定时器,在后续3s内扫到RFID tag为有效 UHFtimer.Stop(); UHFtimer.Interval = 3000; UHFtimer.Start(); } }
/// <summary> /// DataGridView委托赋值函数 /// </summary> /// <param name="view"></param> /// <param name="info"></param> private void SetDataGridViewTag(DataGridView view, APIClient.Tag tag, APIClient.MerchandiseInfoShow info, string status) { if (view.InvokeRequired) { setDataGridViewTag setThis = new setDataGridViewTag(SetDataGridViewTag); view.Invoke(setThis, view, tag, info, status); } else { view.ColumnCount = 7; view.Columns[0].Name = "ID"; view.Columns[1].Name = "店内码"; view.Columns[2].Name = "条形码"; view.Columns[3].Name = "名称"; view.Columns[4].Name = "EPC"; view.Columns[5].Name = "TID"; view.Columns[6].Name = "状态"; //view.Columns[7].Name = "操作"; string[] row = new string[] { tag.merchandiseID, info.Code, info.Barcode, info.Name, tag.EPC, tag.TID, status, }; //view.Rows.Clear(); view.Rows.Add(row); DataGridViewButtonColumn btn = new DataGridViewButtonColumn(); view.Columns.Add(btn); btn.HeaderText = "操作"; if (status == "添加成功") { btn.Text = "点击可添加或删除"; } else if (status == "删除成功") { btn.Text = "点击可添加或删除"; } else { btn.Text = "查看左侧错误提示"; } btn.Name = "btn"; btn.UseColumnTextForButtonValue = true; } }
private void button1_Click(object sender, EventArgs e) { if (lastinfo.ID == null) { return; } if (lasttag.strEPC == "") { return; } APIClient.Tag tag = new APIClient.Tag(); tag.EPC = TextBoxMethod.RemoveSpaceFromString(lasttag.strEPC.Trim('\0')); tag.TID = TextBoxMethod.RemoveSpaceFromString(lasttag.strPC.Trim('\0')); tag.merchandiseID = lastinfo.ID; string status = string.Empty; if (client.CreateTagInStock(tag, out status)) { stopInventory(); SetDataGridViewTag(dataGridView2, tag, lastinfo, status); } else { stopInventory(); SetDataGridViewTag(dataGridView2, tag, lastinfo, status); } System.Threading.Thread.Sleep(200); //clear all for next time lastinfo = new APIClient.MerchandiseInfoShow(); lasttag = new RXInventoryTag(); SetDataText(richTextBox1, string.Empty); SetDataText(richTextBox2, string.Empty); SetDataText(richTextBox3, string.Empty); }