📄 readerform.cs
字号:
private string fname="result";
private DateTime scanTime;
private string connSql;
private System.Data.DataTable data_uid;
private System.Data.DataTable data_test;
private System.Data.DataTable data_ybkh;
private PDA_test.SY_HSXC lc_syhscx;
private PDA_test.JZ_HSXC lc_jzhsxc;
private System.Data.SqlClient.SqlConnection sql_conn;
private System.Data.SqlClient.SqlDataAdapter sql_da;
private System.Data.SqlClient.SqlCommandBuilder sql_cb;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button2;
private System.Data.SqlClient.SqlCommand sql_cmd;
/// <summary>
/// The main entry point for the application.
/// </summary>
/// <summary>
/// Occurs before the form is displayed for the first time.
/// </summary>
///
private void ReaderForm_Load(object sender, System.EventArgs e)
{
textBox1.Focus();
// If we can initialize the Reader
//初始化条码扫描
if ( this.InitReader() )
{
// Start a read on the reader
this.StartRead();
}
else
{
// If not, close this form
this.Close();
return;
}
// Add MainMenu if Pocket PC
if(Symbol.Win32.PlatformType == "PocketPC")
{
this.Menu = new MainMenu();
}
//keypd=new Symbol.Keyboard.KeyPad();
try
{
sql_conn = new SqlConnection( Sql_string );
}
catch (SqlException ex)
{
MessageBox.Show( "Error connecting to the server: " + ex.Message );
}
}
/// <summary>
/// Click from the close button
/// </summary>
private void CloseButton_Click(object sender, System.EventArgs e)
{
// Close this form
//Login.LoginForm.Show();
//ReaderForm.frm1.Hide();
//this.Close();
this.timer1.Dispose();
this.mF_Form.Show();
this.Close();
}
/// <summary>
/// Handles when the user selects the close button from the keyboard.
/// </summary>
private void CloseButton_KeyUp(object sender, KeyEventArgs e)
{
// Checks to see if the key pressed was the enter key (character code 13)
if (e.KeyValue == (char)13)
CloseButton_Click(null, e);
}
/// <summary>
/// Display about box
/// </summary>
private void AboutButton_Click(object sender, System.EventArgs e)
{
}
/// <summary>
/// Handles when the user selects the about button from the keyboard.
/// </summary>
private void AboutButton_KeyDown(object sender, KeyEventArgs e)
{
// Checks to see if the key pressed was the enter key (character code 13)
if (e.KeyValue == (char)13)
this.AboutButton_Click(null, e);
}
/// <summary>
/// Application is closing
/// </summary>
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
// Terminate reader
this.TermReader();
base.OnClosing(e);
}
/// <summary>
/// Initialize the reader.
/// </summary>
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();
this.MyReader.Parameters.Feedback.Success.BeepTime = 0;
this.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\Pegconn.wav";
// Attach to activate and deactivate events
this.Activated +=new EventHandler(ReaderForm_Activated);
this.Deactivate +=new EventHandler(ReaderForm_Deactivate);
return true;
}
/// <summary>
/// Stop reading and disable/close reader
/// </summary>
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;
}
}
/// <summary>
/// Start a read on the reader
/// </summary>
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);
}
}
/// <summary>
/// Stop all reads on the reader
/// </summary>
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();
}
}
/// <summary>
/// Read complete or failure notification
/// </summary>
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();
}
}
/// <summary>
/// Handle data from the reader
/// </summary>
private void HandleData(Symbol.Barcode.ReaderData TheReaderData)
{
//this.exec_check_mz(TheReaderData.Text);
// if (exec_save(TheReaderData.Text.ToString().Trim(),gonghao.Text.ToString().Trim(),label_name.Text.ToString().Trim()))
// {
// MessageBox.Show("该记录保存成功","成功");
// textBox1.Text="";
// }
// else
// {
// MessageBox.Show("写入错误","错误");
// }
string code;
code=TheReaderData.Text.ToString().Trim();
textBox1.Text="";
this.confirm_start=new confirm(this);
confirm_start.setCode(code);
this.confirm_start.Show();
//this.confirm_start.Capture="success";
this.Hide();
//string MessageToDisplay;
//MessageToDisplay = TheReaderData.Source + ": '" + TheReaderData.Text + "'";
//textBox1.Text=TheReaderData.Text;
//ReaderDataListBox.Items.Add(MessageToDisplay);
// 扫描数据完成
// if (Form2.frm2 == null)
// {
// Form2.frm2 = new Form2();
// }
// frm1=this;
// Form2.frm2.Show();
// sn2=TheReaderData.Text;
// Form2.frm2.sn=TheReaderData.Text;
// //lastcode=textBox1.Text;
// textBox1.Text="";
// //Form2.frm2.textBox1.Text=Form2.frm2.sn;
// if (Form2.frm2.isShow2)
// {
// Form2.frm2.isShow=true;
// //this.MyReader.Parameters.Feedback.Success.WaveFile = "";
// }
// else
// {
// Form2.frm2.isShow=false;
// Form2.frm2.isShow2=true;
// //this.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";
// }
// //this.MyReader.Actions.Disable();
////this.MyReader.Actions.Enable();
// frm1.Hide();
// While we have too many items to fit without scrolling
while ( ReaderDataListBox.Items.Count > 13 )
{
// Remove the oldest item
ReaderDataListBox.Items.RemoveAt(0);
}
}
/// <summary>
/// Handler for when the form is actived. This would occur when this application becomes the current
/// application
/// </summary>
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();
}
/// <summary>
/// Handler for when the form is deactivated. This would be called if another application became the current
/// application. This stops the reading of data from the reader.
/// </summary>
private void ReaderForm_Deactivate(object sender, EventArgs e)
{
this.StopRead();
}
/// <summary>
/// If the controls lose the keyboard focus, then the about button will be given the keyboard
/// focus when a key is pressed.
/// </summary>
private void ReaderForm_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
//扫描错误
if (this.MyReader == null)
{
//textBox1.Text="err";
return;
}
if(textBox1.Text=="")
{
//this.MyReader.Actions.Enable();
//this.MyReader.Parameters.Feedback.Success.BeepTime = 0;
//this.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";
this.MyReader.Actions.ToggleSoftTrigger();
}
else
{
// if (Form2.frm2 == null)
// {
// Form2.frm2 = new Form2();
// }
// frm1=this;
// if (Form2.frm2.isShow2)
// {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -