Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
plz help for this questn its same like that we see in hotel bills
Posted
Updated 17-Jun-23 1:09am
Comments
Wendelius 5-Dec-12 0:59am    
And what tool are you using for printing? Reporting services, plain forms, asp.net page...?
Rohit1207 5-Dec-12 4:46am    
its asp.net page using MVC4...
Programm3r 5-Dec-12 1:14am    
Hi - could you please provide some more information regarding your issue? It is very unclear. Thanks
Rohit1207 5-Dec-12 4:46am    
@Programm3r see i have some items called veg,nonveg items etc....
in database i have their price also as in hotel menu..
so i want logic that if i press id as 1 it shows item name with price and after two three items there grand total as BILL....
Programm3r 5-Dec-12 4:50am    
So you basically want to accumulate the price (of all the items) to a grand total and then print it on a slip? Is this the case?

1 solution

DGVPrinter printer = new DGVPrinter();

                        printer.PageSettings.PaperSize = new PaperSize("A4", 827, 1169);
                        printer.PageSettings.Margins = new Margins(50, 50, 50, 50);

                        string gstin = "GSTIN: 33DQHPK0895R1Z3";
                        string cellNumber = "Cell: 9443106555";
                        string officeName = "KAVIJAYA COMPUTERS";
                        string address = "24/41 Vishalam Complex, Ist Floor, Town Extension,";
                        string place = "Mayiladuthurai";
                        string email = "Email: kavijayacomputer@gmail.com";
                        DateTime currentDateTime = DateTime.Now; // Get the current date and time

                        string customerName = GetCustomerName(); // Replace with the code to retrieve the customer name
                        string customerAddress = GetCustomerAddress(); // Replace with the code to retrieve the customer address
                        string customerPhone = GetCustomerPhone(); // Replace with the code to retrieve the customer phone number
                        string customerEmail = GetCustomerEmail(); // Replace with the code to retrieve the customer email

                        Font detailsFont = new Font(printer.SubTitleFont.FontFamily, 8, FontStyle.Regular);
                        printer.SubTitleFont = detailsFont;

                        Font customerDetailsFont = new Font(printer.SubTitleFont.FontFamily, 10, FontStyle.Bold);
                        printer.SubTitleFont = customerDetailsFont;
                        printer.SubTitleColor = Color.Black;

                        printer.SubTitleFont = new Font(printer.SubTitleFont.FontFamily, 14, FontStyle.Bold);
                        printer.SubTitleFont = customerDetailsFont;
                        printer.SubTitleColor = Color.Red;
                        printer.SubTitleFormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.FitBlackBox;
                        printer.SubTitleAlignment = StringAlignment.Center;

                        printer.Title = $"{gstin}                                                                             {cellNumber}"; // Combine GSTIN and Cell into a single line
                        printer.SubTitle = $"{officeName}\r\n";
                        printer.SubTitle += $"{address}\r\n"; // Add the address line separately
                        printer.SubTitle += $"{place}";
                        printer.SubTitle += $"\r\n{email}";

                        printer.SubTitle += "\r\n".PadRight(75, '_'); // Add a line of underscores

                        printer.SubTitle += $"\r\n\r\nCustomer Details";
                        printer.SubTitle += $"\r\nCustomer Name: {customerName}";
                        printer.SubTitle += $"\r\nCustomer Address: {customerAddress}";
                        printer.SubTitle += $"\r\nPhone: {customerPhone}";
                        printer.SubTitle += $"\r\nEmail: {customerEmail}";
                        printer.SubTitle += "\r\n".PadRight(75, '_'); // Add a line of underscores

                        printer.SubTitleFormat = new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center };



                        // Adjust the font size for GSTIN and Cell
                        Font titleFont = new Font(printer.TitleFont.FontFamily, 10, FontStyle.Italic); // Set the desired font size for GSTIN and Cell
                        printer.TitleFont = titleFont;
                        printer.SubTitleColor = Color.DarkBlue;

                        // Adjust the font and color for the address
                        Font addressFont = new Font("Times New Roman", 13, FontStyle.Bold); // Set the desired font size and style for the address line
                        printer.SubTitleFont = addressFont;
                        printer.SubTitleColor = Color.DarkBlue; // Set the color to blue for the address
                        PrintDocument printDocument = new PrintDocument();

                        // Create a new PrintDocument
                        printDocument.DefaultPageSettings.PaperSize = new PaperSize("A4", 827, 1169); // Set the paper size to A4
                        printDocument.DefaultPageSettings.Landscape = false; // Set the orientation to portrait



                        printDocument.DefaultPageSettings.Margins = new Margins(30, 30, 30, 30);

                        printDocument.PrintPage += (printSender, printEventArgs) =>
                        {
                            Graphics graphics = printEventArgs.Graphics;
                            Font font = new Font("Arial", 8, FontStyle.Regular);
                            SolidBrush brush = new SolidBrush(Color.Black);
                            float x = printEventArgs.MarginBounds.Left;
                            float y = printEventArgs.MarginBounds.Top;

                           

                            // Draw the column headers with decreased width
                            graphics.DrawString("Product Name", font, brush, x, y);
                            x += 100;
                            graphics.DrawString("Quantity", font, brush, x, y);
                            x += 80;
                            graphics.DrawString("Rate", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("Serial Number", font, brush, x, y);
                            x += 100;
                            graphics.DrawString("Warranty", font, brush, x, y);
                            x += 80;
                            graphics.DrawString("CGST %", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("SGST %", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("Total", font, brush, x, y);
                            x += 40;

                            y += font.GetHeight();
                            x = printEventArgs.MarginBounds.Left;

                            // Get the values for the row
                            string productName = txtproduct_name.Text;
                            string quantity = txtQty.Text;
                            string rate = txtRate.Text;
                            string serialNumber = txtSerialNumber.Text;
                            string warranty = txtWarranty.Text;
                            string cgst = txtGST.Text;
                            string sgst = txtSGST.Text;
                            string totalValue = txtTotal.Text;



                            // Draw the row values
                            // Draw the column headers with decreased width
                            graphics.DrawString("Product Name", font, brush, x, y);
                            x += 100;
                            graphics.DrawString("Quantity", font, brush, x, y);
                            x += 80;
                            graphics.DrawString("Rate", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("Serial Number", font, brush, x, y);
                            x += 100;
                            graphics.DrawString("Warranty", font, brush, x, y);
                            x += 80;
                            graphics.DrawString("CGST %", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("SGST %", font, brush, x, y);
                            x += 60;
                            graphics.DrawString("Total", font, brush, x, y);
                            x += 40;


                            // Add the footer section
                            string footer = $"Discount: {txtDiscount.Text}%\r\n" +
                                            $"CGST: 9%\r\n" +
                                            $"SGST: 9%\r\n" +
                                            $"Grand Total: {txtGrandTotal.Text}\r\n" +
                                            "Thank you for doing business with us.\r\n" +
                                            $"Printed on: {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}";

                            float footerHeight = graphics.MeasureString(footer, font).Height;
                            float availableSpace = printEventArgs.MarginBounds.Height - y;

                            if (availableSpace >= footerHeight)
                            {
                                y += 10; // Add some vertical spacing before the footer
                                graphics.DrawString(footer, font, brush, x, y);
                            }
                            else
                            {
                                printEventArgs.HasMorePages = false;
                            }
                        };
                        // Assign the PrintDocument to the DGVPrinter
                        printer.PrintDocument = printDocument;


                        // Set the paper size to A4

                        // Rest of the code remains the same
                        printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
                        printer.PageNumbers = true;
                        printer.PageNumberInHeader = false;
                        printer.PorportionalColumns = true;
                        printer.HeaderCellAlignment = StringAlignment.Near;
                        printer.Footer = $"Discount: {txtDiscount.Text}%\nCGST: 9%\nSGST: 9%\nGrand Total: {txtGrandTotal.Text}\n\nThank you for doing business with us.\n\nPrinted on: {currentDateTime.ToString("dd/MM/yyyy HH:mm:ss")}";
                        printer.HeaderCellAlignment = StringAlignment.Near;
                        printer.RowHeight = DGVPrinter.RowHeightSetting.CellHeight;
                        printer.PorportionalColumns = true;
                        printer.FooterSpacing = 15;
                        printer.PrintPreviewDataGridView(dgvAddedProducts);
                        printer.PorportionalColumns = true;

                        


                        printer.PrintDataGridView(dgvAddedProducts);

                        MessageBox.Show("Transaction Completed Successfully");
 
Share this answer
 
Comments
Dave Kreskowiak 17-Jun-23 10:00am    
Only 11 years too late. Also, a code dump is not an answer. You explain nothing, and that is what makes your answer low quality.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900