繁体   English   中英

C# dataGridView发票打印

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM