我们如何通过数据库保存/检索条形码 [英] how we can save/retrive barcode by database
本文介绍了我们如何通过数据库保存/检索条形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用基于窗口的应用程序。我遇到了如何保存/检索数据库中生成的条形码以便进一步使用的问题。请帮助我.........
生成条形码的代码如下所示 -
< span class =code-keyword>使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 BarcodeLib;
使用 System.Drawing.Printing;
使用 System.IO;
命名空间 CAIMS.Forms
{
public partial class BarCodeGeneration:Form
{
Image bmIm;
string date = ;
public BarCodeGeneration()
{
InitializeComponent();
}
私有 void BarCodeGeneration_Load( object sender,EventArgs e)
{
}
private bool GenerateBacode( string _data, string _filename,< span class =code-keyword> string 剩余部分)
{
尝试
{
BarcodeLib .Barcode bar = new BarcodeLib.Barcode(_filename,TYPE.CODE39)
{
IncludeLabel = false
};
图片img2 = bar.Encode(TYPE.CODE39,_data,System.Drawing.Color.Black,System.Drawing.Color.White, 345 ,< span class =code-digit> 70 );
// img2.Save(@D:\ Image.bmp);
var bmp = img2; // Bitmap.FromFile(img2.bmp);
var newImage = new 位图(bmp.Width,bmp.Height + 120 );
var gr = Graphics.FromImage(newImage);
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
gr.DrawImageUnscaled(bmp, 0 , 0 );
SolidBrush br = new SolidBrush(Color.Black);
gr.DrawString(_data, new System.Drawing.Font( 影响, 16 ),Brushes.Black,
new RectangleF( 25 ,bmp.Height + 5 ,bmp.Width + 30 , 100 ));
gr.DrawString( CAIMS [ + date + ], new System.Drawing.Font( 影响, 16 ),Brushes.Black,< span class =code-digit> 20 , 98 );
gr.DrawString(txtPatient.Text.Trim(), new System.Drawing.Font( 影响, 16 ),Brushes.Black, 200 , 98 );
gr.DrawString(txtTest.Text.Trim(), new System.Drawing.Font( 影响, 16 ),Brushes.Black, 30 , 128 );
bmIm = newImage;
var bmpImg2 = newImage;
var newImage2 = new 位图(bmpImg2.Width,bmpImg2.Height);
位图位图= 新位图(newImage.Width + newImage2.Width,Math.Max(newImage.Height,newImage2.Height));
if (剩余== 1 )
{
使用(图形g = Graphics.FromImage(位图))
{
g .DrawImage(newImage, 0 , 0 );
bmIm =位图;
PrintImage();
return true ;
}
}
其他
{
使用(Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(newImage, 0 , 0 跨度>);
g.DrawImage(newImage,newImage.Width, 0 );
bmIm =位图;
PrintImage();
return true ;
}
}
// }
< span class =code-comment> // else
// {
// PrintImage();
// return true;
// }
}
catch (Exception ex)
{
MessageBox.Show( 错误 + ex.ToString()+ 出现, 跨度> < span class =code-string> Information,MessageBoxButtons.OK,MessageBoxIcon.Information);
return false ;
}
}
private void txtBookingNumber_Leave( object sender,EventArgs e)
{
Classes.CSBookingSlip objCSBookingSlip = new Classes.CSBookingSlip();
DataSet ds = objCSBookingSlip.GetCancilationTest( 3 ,txtBookingNumber.Text);
if (ds!= null && ds.Tables [ 0 ]。Rows.Count > 0 )
{
// txtPrice.Text = Convert.ToString(ds.Tables [0] .Rows [ 0] []);
for ( int i = < span class =code-digit> 0 ; i < ds.Tables [ 0 ]。Rows.Count; i ++)
{
txtTest.Text = txtTest.Text + Convert.ToString(ds.Tables [ 0 ] .Rows [i] [ TestId])+ |;
}
txtPatient.Text = Convert.ToString(ds.Tables [ 0 ]。行[ 0 ] [ 患者]);
date = Convert.ToString(ds.Tables [ 0 ]。行[ 0 ] [ 日期]);
}
else
{
MessageBox.Show( 找不到此条形码的记录, 信息,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
私有 void PrintImage()
{
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
// pd.PrinterSettings.Copies = 5;
pd.OriginAtMargins = false ;
pd.DefaultPageSettings.Landscape = false ;
pd.PrintPage + = new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
私有 void pd_PrintPage( object sender,System.Drawing.Printing.PrintPageEventArgs e)
{
// bmIm.Save(@C:\ barcodetesting.jpeg);
// Image img = Image.FromFile(@C:\ barcodetesting.jpeg);
double cmToUnits = 100 / 2 。 54 ;
e.Graphics.DrawImage(bmIm, 0 , 0 ,( float )( 10 * cmToUnits),( float )(< span class =code-digit> 2 * cmToUnits));
// e.Graphics.DrawImage(img,0,0,img.Width,(float)( 2 * cmToUnits));
}
private void btnGenerate_Click( object sender,EventArgs e)
{
bool res = false ;
尝试
{
如果(txtPatient.Text!= < span class =code-string> )
{
int Copies = 0 ;
int 剩余= 0 ;
if (Convert.ToInt32(txtNoOfTimes.Text.Trim())> = < span class =code-digit> 2 )
{
Copies = Convert.ToInt32(txtNoOfTimes.Text.Trim())/ 2 跨度>;
剩余= Convert.ToInt32(txtNoOfTimes.Text.Trim())% 2 ;
}
for ( int i = 1 ; i < = Copies; i ++)
{
res = GenerateBacode(txtBookingNumber.Text .Trim(), 。jpeg, );
if (res == false )
断裂跨度>;
}
if (剩余> 0 )
{
for ( int i = 1 ; i < =剩余; i ++)
{
res = GenerateBacode (txtBookingNumber.Text.Trim(), 。jpeg,Remaining.ToString());
}
}
}
else
{
MessageBox.Show( 请填写Patiet名称, 信息,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch
{
MessageBox.Show( 打印时出现错误, 信息,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
如果(res == true )
{
// App_Code.CommonFunctions objCommonFunctions = new App_Code.CommonFunctions();
MessageBox .Show( 条形码生成成功, 信息,MessageBoxButtons.OK,MessageBoxIcon.Information);
尝试
{
// objCommonFunctions.SaveUpdateNotifications(0,tbl_Product,条形码生成,Brcode,UserId,Convert.ToString(Convert.ToInt32(txtNoOfTimes.Text.Trim())* 2)+条形码打印否。+ txtProductName.Text.Trim());
}
catch
{}
txtPatient.Text = ;
txtBookingNumber.Text = ;
txtNoOfTimes.Text = ;
txtTest.Text = ;
}
}
}
}
解决方案
访问这里.... ......
http://www.aspose.com/docs/display/barcodenet/How+to+Save+Retrieve+Barcodes+to+and+from+Database+ in + .NET [ ^ ]
您没有在提问中提及任何错误消息。查看本文有两种保存方法。
条码图像生成库 [ ^ ]
I am working with a window based application . I faced a problem to how save/retrive the generated barcode in database to further use. plese help me.........
the code by which i generate the barcode is as given bellow-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BarcodeLib;
using System.Drawing.Printing;
using System.IO;
namespace CAIMS.Forms
{
public partial class BarCodeGeneration : Form
{
Image bmIm;
string date = "";
public BarCodeGeneration()
{
InitializeComponent();
}
private void BarCodeGeneration_Load(object sender, EventArgs e)
{
}
private bool GenerateBacode(string _data, string _filename, string Remainings)
{
try
{
BarcodeLib.Barcode bar = new BarcodeLib.Barcode(_filename, TYPE.CODE39)
{
IncludeLabel = false
};
Image img2 = bar.Encode(TYPE.CODE39, _data, System.Drawing.Color.Black, System.Drawing.Color.White, 345, 70);
//img2.Save(@"D:\Image.bmp");
var bmp = img2;//Bitmap.FromFile("img2.bmp");
var newImage = new Bitmap(bmp.Width, bmp.Height + 120);
var gr = Graphics.FromImage(newImage);
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None;
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
gr.DrawImageUnscaled(bmp, 0, 0);
SolidBrush br = new SolidBrush(Color.Black);
gr.DrawString(_data, new System.Drawing.Font("Impact", 16), Brushes.Black,
new RectangleF(25, bmp.Height + 5, bmp.Width + 30, 100));
gr.DrawString("CAIMS[" + date + "]", new System.Drawing.Font("Impact", 16), Brushes.Black, 20, 98);
gr.DrawString(txtPatient.Text.Trim(), new System.Drawing.Font("Impact", 16), Brushes.Black, 200,98);
gr.DrawString(txtTest.Text.Trim(), new System.Drawing.Font("Impact", 16), Brushes.Black, 30, 128);
bmIm = newImage;
var bmpImg2 = newImage;
var newImage2 = new Bitmap(bmpImg2.Width, bmpImg2.Height);
Bitmap bitmap = new Bitmap(newImage.Width + newImage2.Width, Math.Max(newImage.Height, newImage2.Height));
if (Remainings == "1")
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(newImage, 0, 0);
bmIm = bitmap;
PrintImage();
return true;
}
}
else
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawImage(newImage, 0, 0);
g.DrawImage(newImage, newImage.Width, 0);
bmIm = bitmap;
PrintImage();
return true;
}
}
//}
//else
//{
// PrintImage();
// return true;
//}
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex.ToString() + " occurs", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
private void txtBookingNumber_Leave(object sender, EventArgs e)
{
Classes.CSBookingSlip objCSBookingSlip = new Classes.CSBookingSlip();
DataSet ds = objCSBookingSlip.GetCancilationTest(3,txtBookingNumber.Text);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
//txtPrice.Text = Convert.ToString(ds.Tables[0].Rows[0][""]);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
txtTest.Text =txtTest.Text + Convert.ToString(ds.Tables[0].Rows[i]["TestId"])+" | ";
}
txtPatient.Text = Convert.ToString(ds.Tables[0].Rows[0]["Patient"]);
date = Convert.ToString(ds.Tables[0].Rows[0]["Date"]);
}
else
{
MessageBox.Show("No record found for this barcode", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void PrintImage()
{
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
//pd.PrinterSettings.Copies = 5;
pd.OriginAtMargins = false;
pd.DefaultPageSettings.Landscape = false;
pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//bmIm.Save(@"C:\barcodetesting.jpeg");
//Image img = Image.FromFile(@"C:\barcodetesting.jpeg");
double cmToUnits = 100 / 2.54;
e.Graphics.DrawImage(bmIm, 0, 0, (float)(10 * cmToUnits), (float)(2 * cmToUnits));
//e.Graphics.DrawImage(img, 0, 0, img.Width, (float)(2 * cmToUnits));
}
private void btnGenerate_Click(object sender, EventArgs e)
{
bool res = false;
try
{
if (txtPatient.Text != "")
{
int Copies = 0;
int Remaining = 0;
if (Convert.ToInt32(txtNoOfTimes.Text.Trim()) >= 2)
{
Copies = Convert.ToInt32(txtNoOfTimes.Text.Trim()) / 2;
Remaining = Convert.ToInt32(txtNoOfTimes.Text.Trim()) % 2;
}
for (int i = 1; i <= Copies; i++)
{
res = GenerateBacode(txtBookingNumber.Text.Trim(), ".jpeg", "");
if (res == false)
break;
}
if (Remaining > 0)
{
for (int i = 1; i <= Remaining; i++)
{
res = GenerateBacode(txtBookingNumber.Text.Trim(), ".jpeg", Remaining.ToString());
}
}
}
else
{
MessageBox.Show("Please fill Patiet Name", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch
{
MessageBox.Show("Some error occured while printing", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (res == true)
{
//App_Code.CommonFunctions objCommonFunctions = new App_Code.CommonFunctions();
MessageBox.Show("Bar code generated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
try
{
//objCommonFunctions.SaveUpdateNotifications(0, "tbl_Product", "Barcode generated", "Brcode", UserId, Convert.ToString(Convert.ToInt32(txtNoOfTimes.Text.Trim()) * 2) + " Barcode Printed of No. " + txtProductName.Text.Trim());
}
catch
{ }
txtPatient.Text = "";
txtBookingNumber.Text = "";
txtNoOfTimes.Text = "";
txtTest.Text = "";
}
}
}
}
解决方案
visit here..........
http://www.aspose.com/docs/display/barcodenet/How+to+Save+Retrieve+Barcodes+to+and+from+Database+in+.NET[^]
You didn't mention any error message in your question. Check this article which has two methods of saving.
Barcode Image Generation Library[^]
这篇关于我们如何通过数据库保存/检索条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文