普通的USB扫描枪,窗口上有一个文本框来获取扫描的内容,扫描枪扫描的数据类似于键盘输入一样,在文本框中一个一个字符出现,扫描一维条码的时候没有什么问题,但是在扫描2维条码的就出现问题,2维条码的内容太多,textbox显示都需要5秒钟左右,扫描过程是连续扫描,要是中间错了一个,会导致后面的都存不进系统,需要重新扫描,并且还要寻找从那一个开始时错误的。1.有没有办法能够快速的获取扫描枪的内容并且显示在textbox上?
2.能否直接从USB口读取数据?
2.能否直接从USB口读取数据?
解决方案 »
- 有那位C#高手成功的做出了office转Pdf的效果的。
- winform DataGridView 导出到Excel问题
- C# winform程序中将一个相机视频控件放入panel中,显示视频会不会一直调用Panel的Onpaint方法?
- C# windows 捕获键盘消息??????????????????
- C# 关于Treeview的问题,如何向一个节点添加从数据库读出来的数据,如何单击一个节点然后就将该节点的内容作为条件从数据库中进行查询相应的数据
- 江湖救急!!!!!!!
- .NET c# 安装程序的错误
- 请问关于ADO.NET的问题
- 如何获得分数?
- 关于线程`
- 关于Oledb的方式连接Oracle的问题
- C# WinForm ListBox控件设置排序图标
我的独家代码
public partial class CutMeatRecordInfo : Form
{
BarcodeLib.Barcode b = new BarcodeLib.Barcode();
private PrintTest.net.greeniot.www.GrwlImplService ws = new PrintTest.net.greeniot.www.GrwlImplService();
public CutMeatRecordInfo()
{
InitializeComponent(); } private void tb_view_Click(object sender, EventArgs e)
{
//Barcode barcode1 = new Barcode();
//DotNetBarcode barcode = new DotNetBarcode();
//Bitmap bitmap = new Bitmap(600, 340);
//Graphics gs = Graphics.FromImage(bitmap);
//gs.Clear(Color.White);
//gs.DrawString(this.txtTimes.Text.Trim(), new Font("黑体", 8), new SolidBrush(Color.Black), new Rectangle(255, 80, 130, 50));
//barcode.Type = DotNetBarcode.Types.QRCode;
//barcode.WriteBar(this.tb_number.Text.Trim(), 230, 120, 110, 110, gs);
//System.Drawing.Image image = barcode1.Encode(TYPE.CODE128, this.tb_number.Text.Trim(), Color.Black, Color.White, 190, 50);
//gs.DrawImage(image, new Rectangle(0, 140, 230, 50));
//gs.DrawString(this.tb_number.Text.Trim(), new Font("宋体", 8), new SolidBrush(Color.Black), new Rectangle(40, 180, 190, 20));
//pictureBox4.Image = bitmap;
}
/// <summary>
/// 确认按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnYes_Click(object sender, EventArgs e)
{
Barcode barcode1 = new Barcode();
DotNetBarcode barcode = new DotNetBarcode();
Bitmap bitmap = new Bitmap(140, 140);//保存二维条码形状
Bitmap bitmap2 = new Bitmap(170, 21);//保存条码号
Graphics gs = Graphics.FromImage(bitmap);
gs.Clear(Color.White); Graphics gs1 = Graphics.FromImage(bitmap2);
gs1.Clear(Color.White);
barcode.Type = DotNetBarcode.Types.QRCode;
//生成二维条码
//barcode.WriteBar("标签编号:'" + tb_number.Text + "'" + "分割部位:" + "'" + cmbPosition.Text + "'" + "分割肉重量:" + "'" + txtWeight.Text + "'", 1, 1, 60, 60, gs);
barcode.WriteBar("全程溯源 国内首创" + "\r\n " + " 产品介绍:" + "\r\n " + "http:// www " + "\r\n " + " 有限公司 荣誉出品", 1, 1, 140, 140, gs);
gs1.DrawString(tb_number.Text.Trim(), new Font("宋体", 8), new SolidBrush(Color.Black), new Rectangle(0, 0, 209, 33));
pictureBox3.Image = bitmap;
}
private void ClearCotrol()
{
txtTabNo.Text = "";
cmbPosition.SelectedIndex = -1;
txtWeight.Text = "";
txtWeight.Text = "";
}
/// <summary>
/// 返回按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCanncel_Click(object sender, EventArgs e)
{
this.Close();
MainFrame mf = new MainFrame();
mf.Show();
}
/// <summary>
/// 下一笔
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnNext_Click(object sender, EventArgs e)
{ } private void CutMeatRecordInfo_Load(object sender, EventArgs e)
{
pictureBox5.Visible = false;
cbEncodeType.Text = "Code 128";
string color = "";
try
{
ManageTxtFile mt = new ManageTxtFile();
string strPath = mt.GetAppPath();
string strData = mt.ReadTxtFile(strPath, "Login.txt");
string[] info = Regex.Split(strData, @"\|\|");//正则获取数据
color = ws.getLabelColorAndShape(info[1]);
txtTimes.Text = ws.getBarCodeBatches();
}
catch (System.Exception ex)
{
MessageBox.Show("网络服务连接失败,请检查链接后重新登录!", "系统信息");
return;
} string[] strInfo = Regex.Split(color, @"\|");//正则获取数据
string everyone = "";//保存每一组
string[] strEveryOne;//将每一组再分组
string flag = "";//每一组分组后再分组的每一个的标示位
string value = "";//每一组分组后再分组的每一个的值
string num = "";//每一组分组后再分组的每一个的符号 DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("形状", typeof(string)));
dt.Columns.Add(new DataColumn("形状编号", typeof(string)));
DataTable dt1 = new DataTable();
dt1.Columns.Add(new DataColumn("颜色", typeof(string)));
dt1.Columns.Add(new DataColumn("颜色编号", typeof(string))); for (int i = 0; i < strInfo.Length - 1; i++)
{
DataRow dr = dt.NewRow();
DataRow dr1 = dt1.NewRow();
everyone = strInfo[i];
strEveryOne = Regex.Split(everyone, ":");//正则获取数据
flag = strEveryOne[2];
//if (flag == "0")
//{
// dr["形状"] = strEveryOne[0];
// dr["形状编号"] = strEveryOne[1];
// dt.Rows.Add(dr);
//}
//if (flag == "1")
//{
// dr1["颜色"] = strEveryOne[0];
// dr1["颜色编号"] = strEveryOne[1];
// dt1.Rows.Add(dr1);
//}
} //this.cmbShape.DataSource = dt;
//this.cmbShape.DisplayMember = "形状";
//this.cmbShape.ValueMember = "形状编号"; //this.cmbColor.DataSource = dt1;
//this.cmbColor.DisplayMember = "颜色";
//this.cmbColor.ValueMember = "颜色编号";
//cmbColor.SelectedIndex = -1;
//cmbShape.SelectedIndex = -1;
//获取分割部位数据
string position = "";
try
{
ManageTxtFile mt = new ManageTxtFile();
string strPath = mt.GetAppPath();
string strData = mt.ReadTxtFile(strPath, "Login.txt");
string[] strInfomation = Regex.Split(strData, @"\|\|");//正则获取数据
position = ws.getSplitPositionDic(strInfomation[1]);
}
catch (System.Exception ex)
{
MessageBox.Show("网络服务连接失败,请检查链接后重新登录!", "系统信息");
return;
}
string[] cutPosition = Regex.Split(position, @"\|");//正则获取数据
string po = "";//保存每一组中每一项
string[] posi;//保存每一组中每一项再按正则分成一组
DataTable dtPosion = new DataTable();
dtPosion.Columns.Add(new DataColumn("部位", typeof(string)));
dtPosion.Columns.Add(new DataColumn("部位编号", typeof(string)));
for (int j = 0; j < cutPosition.Length - 1; j++)
{
po = cutPosition[j];
posi = Regex.Split(po, ":");//正则获取数据
DataRow drPosion = dtPosion.NewRow();
drPosion["部位"] = posi[0];
drPosion["部位编号"] = posi[1];
dtPosion.Rows.Add(drPosion);
}
this.cmbPosition.DataSource = dtPosion;
this.cmbPosition.DisplayMember = "部位";
this.cmbPosition.ValueMember = "部位编号";
cmbPosition.SelectedIndex = -1;
} private void txtWeight_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
{
if (e.KeyChar == '.')
{
if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
e.Handled = true;
}
else
e.Handled = true;
}
else
{
if (e.KeyChar <= 31)
{
e.Handled = false;
}
else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
{
if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
e.Handled = true;
}
}
} private void tb_print_Click(object sender, EventArgs e)
{
printDocument1.Print();
} private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
////e.Graphics.DrawImage(picLable.Image, 60, 140);//商标picLable 宽度,高度。
//e.Graphics.DrawImage(piclable2.Image, 18, 147);//产品追溯码
//e.Graphics.DrawImage(pictureBox3.Image, 130, 140);//二维码
//e.Graphics.DrawImage(pictureBox4.Image, 17, 200);//一维码
////e.Graphics.DrawImage(picNetAddr.Image, 15, 215);//网址
////e.Graphics.DrawImage(pictureBox6.Image, 15, 226);//网址
//e.Graphics.DrawImage(pictureBox5.Image, 15, 1);//产品追溯码
e.Graphics.DrawImage(pictureBox3.Image, 57, -10);//二维码
//e.Graphics.DrawImage(pictureBox4.Image, 15, 60);//一维码
} private void btnForeColor_Click(object sender, EventArgs e)
{
using (ColorDialog cdialog = new ColorDialog())
{
cdialog.AnyColor = true;
if (cdialog.ShowDialog() == DialogResult.OK)
{
this.b.ForeColor = cdialog.Color;
this.btnForeColor.BackColor = this.b.ForeColor;
}//if
}//using
} private void btnBackColor_Click(object sender, EventArgs e)
{
using (ColorDialog cdialog = new ColorDialog())
{
cdialog.AnyColor = true;
if (cdialog.ShowDialog() == DialogResult.OK)
{
this.b.BackColor = cdialog.Color;
this.btnBackColor.BackColor = this.b.BackColor;
}//if
}//using
}
//获取新批次
private void btnNewTimes_Click(object sender, EventArgs e)
{
try
{
txtTimes.Text = ws.getBarCodeNewBatches();
}
catch (System.Exception ex)
{
MessageBox.Show("网络服务连接有问题!", "系统提示!");
return;
} }
}
[email protected] or [email protected]
谢谢 !