private void pandian_Load(object sender, EventArgs e)
{
if (this.InitReader())
{
// Start a read on the reader
this.StartRead();
}
else
{
// If not, close this form
this.Close();
return;
}
}
private void txt_tiaoma_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
if (txt_tiaoma.Text == "")
{
MessageBox.Show("条码不能为空");
}
else
{
data dt = new data();
SqlCeDataReader dr = dt.read("select * from tiaomadan where tiaoma='"+this.txt_tiaoma.Text+"'");
if (dr.Read())
{
if (biaozhi == "0")
{
this.txt_shuliang.Text = "1";
this.txt_shuliang.SelectAll();
this.listBox1.Items.Clear();
this.listBox1.Items.Add("单号:"+danhao);
this.listBox1.Items.Add("物料代码:"+dr[1].ToString());
this.listBox1.Items.Add("物料名称:"+dr[2].ToString());
this.listBox1.Items.Add("物料批号:"+dr[4].ToString());
this.listBox1.Items.Add("有效日期:"+dr[5].ToString());
SqlCeDataReader dr1 = dt.read("select * from rukudan where wuliaodaima='"+dr[1].ToString()+"' and danhao='"+danhao+"'");
if (dr1.Read() == true)
{
this.listBox1.Items.Add("总体数量:" + dr1[4].ToString() + dr1[3].ToString());
dr1.Close();
}
else
{
this.listBox1.Items.Add("总体数量:"+"没有找到编码");
dr1.Close();
}
SqlCeDataReader dr2 = dt.read("select sum(shuliang) from jilurukudan where danhao='" + danhao + "' and wuliaodaima='" + dr[1].ToString() + "'");
if (dr2.Read() == true)
{
this.listBox1.Items.Add("已扫数量:" + dr2[0].ToString());
dr2.Close();
}
else
{
this.listBox1.Items.Add("已扫数量:"+"0");
dr2.Close();
}
this.txt_shuliang.Focus();
//rukudan
}
if (biaozhi == "1")
{
this.txt_shuliang.Text = "1";
this.txt_shuliang.SelectAll();
this.listBox1.Items.Clear();
this.listBox1.Items.Add("单号:" + danhao);
this.listBox1.Items.Add("物料代码:" + dr[1].ToString());
this.listBox1.Items.Add("物料名称:" + dr[2].ToString());
this.listBox1.Items.Add("物料批号:" + dr[4].ToString());
this.listBox1.Items.Add("有效日期:" + dr[5].ToString());
SqlCeDataReader dr1 = dt.read("select * from chukudan where wuliaodaima='" + dr[1].ToString() + "' and danhao='" + danhao + "'");
if (dr1.Read() == true)
{
this.listBox1.Items.Add("总体数量:" + dr1[4].ToString() + dr1[3].ToString());
dr1.Close();
}
else
{
this.listBox1.Items.Add("总体数量:" + "没有找到编码");
dr1.Close();
}
SqlCeDataReader dr2 = dt.read("select sum(shuliang) from jiluchukudan where danhao='" + danhao + "' and wuliaodaima='" + dr[1].ToString() + "'");
if (dr2.Read() == true)
{
this.listBox1.Items.Add("已扫数量:" + dr2[0].ToString());
dr2.Close();
}
else
{
this.listBox1.Items.Add("已扫数量:" + "0");
dr2.Close();
}
this.txt_shuliang.Focus();
private bool InitReader()
{
// If reader is already present then fail initialize
if (this.MyReader != null)
{
return false;
}
// Create new reader, first available reader will be used.
this.MyReader = new Symbol.Barcode.Reader();
// Create reader data
this.MyReaderData = new Symbol.Barcode.ReaderData(
Symbol.Barcode.ReaderDataTypes.Text,
Symbol.Barcode.ReaderDataLengths.MaximumLabel);
// Create event handler delegate
this.MyEventHandler = new EventHandler(MyReader_ReadNotify);
// Enable reader, with wait cursor
this.MyReader.Actions.Enable();
// Attach to activate and deactivate events
this.Activated += new EventHandler(ReaderForm_Activated);
this.Deactivate += new EventHandler(ReaderForm_Deactivate);
return true;
}
private void TermReader()
{
// If we have a reader
if (this.MyReader != null)
{
// Disable the reader
this.MyReader.Actions.Disable();
// Free it up
this.MyReader.Dispose();
// Indicate we no longer have one
this.MyReader = null;
}
// If we have a reader data
if (this.MyReaderData != null)
{
// Free it up
this.MyReaderData.Dispose();
// Indicate we no longer have one
this.MyReaderData = null;
}
}
private void StartRead()
{
// If we have both a reader and a reader data
if ((this.MyReader != null) &&
(this.MyReaderData != null))
{
// Submit a read
this.MyReader.ReadNotify += this.MyEventHandler;
this.MyReader.Actions.Read(this.MyReaderData);
}
}
private void StopRead()
{
// If we have a reader
if (this.MyReader != null)
{
// Flush (Cancel all pending reads)
this.MyReader.ReadNotify -= this.MyEventHandler;
this.MyReader.Actions.Flush();
}
}
private void MyReader_ReadNotify(object sender, EventArgs e)
{
Symbol.Barcode.ReaderData TheReaderData = this.MyReader.GetNextReaderData();
// If it is a successful read (as opposed to a failed one)
if (TheReaderData.Result == Symbol.Results.SUCCESS)
{
// Handle the data from this read
this.HandleData(TheReaderData);
// Start the next read
this.StartRead();
}
}
private void HandleData(Symbol.Barcode.ReaderData TheReaderData)
{
string MessageToDisplay;
MessageToDisplay = TheReaderData.Text ;
this.txt_tiaoma.Text = MessageToDisplay;
txt_tiaoma_KeyDown(txt_tiaoma, new KeyEventArgs(System.Windows.Forms.Keys.Enter));
// While we have too many items to fit without scrolling
}
private void ReaderForm_Activated(object sender, EventArgs e)
{
// If there are no reads pending on MyReader start a new read
if (!this.MyReaderData.IsPending)
this.StartRead();
}
private void ReaderForm_Deactivate(object sender, EventArgs e)
{
this.StopRead();
}
}