Code:
private void printBarcodebutton_Click(object sender, RoutedEventArgs e)
{
BarCodeCrpt pbarcode = new BarCodeCrpt();
pbarcode.SetDataSource(SetbarcodeData());
ReportViewer Viewer = new ReportViewer();
Viewer.setReportSource(pbarcode);
// frmViewer.MdiParent = mdiParent;
Viewer.ShowDialog();
}
private List<Barcode> SetbarcodeData()
{
List<Barcode> code = new List<Barcode>();
Barcode acode = new Barcode();
Product secProduct = productobj;
acode.ProductName = secProduct.ProductName;
acode.ProductPrice = secProduct.SalesPrice;
FileStream fs1 = new FileStream("hhhh.bmp", FileMode.Open, FileAccess.Read);
fs1.Flush();
BinaryReader br = new BinaryReader(fs1);
byte[] imgbyte = new byte[fs1.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs1.Length)));
acode.BarcodeSt = imgbyte;
for (int i = 0; i <9; i++)
{
code.Add(acode);
}
fs1.Close();
return code;
}
Create "hhhh.bmp" Code:
( Add " Neodynamic.WPF.Barcode.dll" in refarence)
private void UpdateBarcodeOnHeader()
{
try
{
if (productobj.Barcode.Length != 12)
{
Microsoft.Windows.Controls.MessageBox.Show("Please enter a value to encode, thanks!");
return;
}
barcodeimage.SetValue(System.Windows.Controls.Image.SourceProperty, null);
//Create an instance of Barcode Professional
BarcodeProfessional bcp = new BarcodeProfessional();
//Barcode settings
bcp.Symbology = Symbology.Code128;
bcp.BarcodeUnit = BarcodeUnit.Inch;
bcp.BarWidth = 1f / 96f;
bcp.BarHeight = 0.5f;
//Set the value to encode
bcp.Code = productobj.Barcode;
imgGet = bcp.GetBarcodeImageBinary();
if (imgGet.Length > 0)
{
FileStream fs1 = new FileStream("hhhh.bmp", FileMode.Create, FileAccess.Write);
fs1.Write(imgGet, 0, imgGet.Length);
fs1.Flush();
fs1.Close();
Bitmap bmp = new Bitmap("hhhh.bmp");
BitmapImage bi = new BitmapImage();
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bi.BeginInit();
ms.Seek(0, SeekOrigin.Begin);
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = ms;
bi.EndInit();
bi.StreamSource.Dispose();
bmp.Dispose();
bmp = null;
ms.Dispose();
ms = null;
this.barcodeimage.Source = bi;
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন