[英]C# dataGridView invoice printing
在我的代碼中,除了未在 Invoice 中打印的 dataGridView 中的總數之外,一切正常。 怎么解決。 此外,我需要以粗體顯示列文本(UID、項目和價格)並稍微增加字體大小。 該程序將過濾掉 RFID UID,然后獲取數據庫並將記錄加載到 DGV 中。
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.StartsWith("[") && textBox1.Text.EndsWith("]"))
{
string S = textBox1.Text.Replace("[", "").Replace("]", "").Replace("Cart#1:", "");
var values = new List<string>(S.Split(',')).Select(x => x.Trim()).ToList();
var PositiveList = values.Where(x => x.StartsWith("+")).ToList();
var NegativeList = values.Where(x => x.StartsWith("-")).ToList();
for (int i = 0; i < NegativeList.Count; i++){NegativeList[i] = NegativeList[i].Replace("-", "");}
for (int i = 0; i < PositiveList.Count; i++){PositiveList[i] = PositiveList[i].Replace("+", "");}
foreach (string string1 in NegativeList){PositiveList.Remove(string1);}
listBox4.DataSource = PositiveList;//listBox2.DataSource = values;//listBox3.DataSource = NegativeList;
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Dell\OneDrive\Desktop\Database1.mdb";
connection.Open();
for (int i = 0; i < PositiveList.Count; i++)
{
String A = PositiveList[i];
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM item where UID='" + A + "'", connection);
DataTable dt = new DataTable();
oda.Fill(dt);
int n = dataGridView2.Rows.Add();
dataGridView2.Rows[n].Cells[0].Value = dt.Rows[0][1].ToString();
dataGridView2.Rows[n].Cells[1].Value = dt.Rows[0][2].ToString();
dataGridView2.Rows[n].Cells[2].Value = dt.Rows[0][3].ToString();
}
dataGridView2[1, dataGridView2.Rows.Count - 1].Value = "Total";
decimal tot = 0;
for (int j = 0; j < dataGridView2.Rows.Count; j++)
{
var value = dataGridView2.Rows[j].Cells[2].Value;
if (value != DBNull.Value){tot += Convert.ToDecimal(value);}
}
if (tot == 0){ }
dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[2].Value = tot.ToString();
DGVPrinter printer = new DGVPrinter();
printer.Title = "Smart Shopping Invoice"; //give your report name
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
printer.PageNumbers = true; // if you need page numbers you can keep this as true other wise false
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "footer"; //this is the footer
printer.FooterSpacing = 15;
printer.printDocument.DefaultPageSettings.Landscape = true;
printer.PrintDataGridView(dataGridView2);
}
}
在我的代碼中,除了未在 Invoice 中打印的 dataGridView 中的總數之外,一切正常。 怎么解決。 此外,我需要以粗體顯示列文本(UID、項目和價格)並稍微增加字體大小。 該程序將過濾掉 RFID UID,然后獲取數據庫並將記錄加載到 DGV 中。
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.StartsWith("[") && textBox1.Text.EndsWith("]"))
{
string S = textBox1.Text.Replace("[", "").Replace("]", "").Replace("Cart#1:", "");
var values = new List<string>(S.Split(',')).Select(x => x.Trim()).ToList();
var PositiveList = values.Where(x => x.StartsWith("+")).ToList();
var NegativeList = values.Where(x => x.StartsWith("-")).ToList();
for (int i = 0; i < NegativeList.Count; i++){NegativeList[i] = NegativeList[i].Replace("-", "");}
for (int i = 0; i < PositiveList.Count; i++){PositiveList[i] = PositiveList[i].Replace("+", "");}
foreach (string string1 in NegativeList){PositiveList.Remove(string1);}
listBox4.DataSource = PositiveList;//listBox2.DataSource = values;//listBox3.DataSource = NegativeList;
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Dell\OneDrive\Desktop\Database1.mdb";
connection.Open();
for (int i = 0; i < PositiveList.Count; i++)
{
String A = PositiveList[i];
OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM item where UID='" + A + "'", connection);
DataTable dt = new DataTable();
oda.Fill(dt);
int n = dataGridView2.Rows.Add();
dataGridView2.Rows[n].Cells[0].Value = dt.Rows[0][1].ToString();
dataGridView2.Rows[n].Cells[1].Value = dt.Rows[0][2].ToString();
dataGridView2.Rows[n].Cells[2].Value = dt.Rows[0][3].ToString();
}
dataGridView2[1, dataGridView2.Rows.Count - 1].Value = "Total";
decimal tot = 0;
for (int j = 0; j < dataGridView2.Rows.Count; j++)
{
var value = dataGridView2.Rows[j].Cells[2].Value;
if (value != DBNull.Value){tot += Convert.ToDecimal(value);}
}
if (tot == 0){ }
dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[2].Value = tot.ToString();
DGVPrinter printer = new DGVPrinter();
printer.Title = "Smart Shopping Invoice"; //give your report name
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
printer.PageNumbers = true; // if you need page numbers you can keep this as true other wise false
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "footer"; //this is the footer
printer.FooterSpacing = 15;
printer.printDocument.DefaultPageSettings.Landscape = true;
printer.PrintDataGridView(dataGridView2);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.