0
打印標籤從數據庫中選擇的結果我已經先說這個,我是新來的windows編程,我如何使用循環
我有一個要求打印一組結果從搜索查詢得到的。每個結果行應打印在單個標籤上。查詢中包含樣本結果集。什麼是達到此目的的最佳方法。條形碼所示的欄應該打印爲條形碼,而另外兩欄應打印在標籤的上方和下方。 通常,我們可能必須在單擊一次按鈕時打印最多500個標籤。
下面我添加了我正在使用的代碼。在頁面加載事件中,我通過ID來加載數據庫中特定項目的數據。但是我需要使用選定的項目列表自動化,而不是一個。 Result set
public partial class PrintLabel : Form
{
string s_desc = "";
string s_date = "";
Image bCodeImage;
public PrintLabel()
{
InitializeComponent();
}
private void PrintLabel_Load(object sender, EventArgs e)
{
FillData(735);
}
private void Print_Click(object sender, EventArgs e)
{
ItemPrint();
this.Close();
}
void FillData(int ID)
{
string str = Properties.Settings.Default.ConW;
using (SqlConnection conn = new SqlConnection(str))
{
try
{
string query = "select item.ID+'-'+item.ItemLookupCode as Barcode,ExtendedDescription,GETDATE()+180 Expiry from Item where ID=" + ID + ";";
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader dtr = cmd.ExecuteReader();
if (dtr.Read())
{
GenerateBarcode(dtr[0].ToString());
s_desc = dtr[1].ToString();
s_date = dtr[2].ToString();
lblDescription.Text = s_desc;
lblExpiry.Text = s_date;
PBBarcode.Image = bCodeImage;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void GenerateBarcode(string _bCodeImage)
{
string barCode = _bCodeImage;
Bitmap bitmap = new Bitmap(barCode.Length * 60, 750);
using (Graphics grapics = Graphics.FromImage(bitmap))
{
Font ofont = new System.Drawing.Font("IDAHC39M Code 39 Barcode", 14);
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
grapics.FillRectangle(white, 0, 0, bitmap.Width, bitmap.Height);
grapics.DrawString("*" + barCode + "*", ofont, black, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Png);
bCodeImage = bitmap;
}
}
private void ItemPrint()
{
PrintDialog printdg = new PrintDialog();
if (printdg.ShowDialog() == DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings = printdg.PrinterSettings;
pd.PrintPage += PrintPage;
pd.Print();
pd.Dispose();
}
}
private void PrintPage(object o, PrintPageEventArgs e)
{
lblDescription.Text = s_desc;
lblExpiry.Text = s_date;
PBBarcode.InitialImage = bCodeImage;
}
}
這裏有什麼問題?你使用什麼技術?它是桌面應用程序上的ASP.NET應用程序嗎?另外考慮閱讀[如何提問](http://stackoverflow.com/help/how-to-ask) –
如果你需要在紙上打印,那麼你應該去一些報告SDK(水晶報告,報告銳利的射手等) – Michael
你使用哪種語言?你有任何代碼嗎?你需要在屏幕或紙上打印? –