Click here to Skip to main content
16,004,458 members

Comments by MIDCOPC (Top 15 by date)

MIDCOPC 8-Nov-23 7:56am View    
RainHat, thank you for the reply. I got it working with the code below. Not sure if this is the correct way but it is working.

public void invoicePostingReportPrintReportButton_Click(object sender, EventArgs e)
{
if (invoicemainresults == null)
{
MessageBox.Show("You must create a report before you can print it");
invoicePostingReportStartDateTimePicker.Focus();
return;
}

// Get list of printers from Personnel table
var getPrinters = GlobalConfig.PersonnelTable.GetByPersonCodeForPrinting(_userId);

if (getPrinters != null && getPrinters.PrinterNameReports != null)
{
printTo = getPrinters.PrinterPathReports;

// Create a PrintDocument object
PrintDocument printDocument1 = new PrintDocument();

// Set up print settings
printDocument1.PrinterSettings.PrinterName = printTo;
printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Letter", 850, 1100);

// Set up event handler for printing
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);

// Calculate the number of items per page
int itemsPerPage = 30; // Adjust this value as needed

// Calculate the total number of pages
int totalPages = (int)Math.Ceiling((double)invoicemainresults.Count / itemsPerPage);

// Print each page
for (int currentPage = 1; currentPage <= totalPages; currentPage++)
{
// Set the starting and ending index for the current page
int startIndex = (currentPage - 1) * itemsPerPage;
int endIndex = Math.Min(startIndex + itemsPerPage - 1, invoicemainresults.Count - 1);

// Clear the variables
this._sProNumber = string.Empty;
this._sLoadNumber = string.Empty;
this._sShipmentNumber = string.Empty;
this._sBillDate = string.Empty;
this._sInvoiceCreatedDate = string.Empty;
this._sInvoicePostedDate = string.Empty;
this._sTotalCharges = string.Empty;
this._sTotalPayments = string.Empty;
this._sBalanceDue = string.Empty;

// Populate the variables with data for the current page
for (int i = startIndex; i <= endIndex; i++)
{
var result = invoicemainresults[i];
_sProNumber += result.ProNumber + Environment.NewLine + Environment.NewLine;
_sLoadNumber += result.LoadNumber + Environment.NewLine + Environment.NewLine;
_sShipmentNumber += result.ShipmentNumber + Environment.NewLine + Environment.NewLine;
_sBillDate += result.BillDate.ToShortDateString() + Environment.NewLine + Environment.NewLine;
_sInvoiceCreatedDate += result.InvoiceCreatedDate.ToShortDateString() + Environment.NewLine + Environment.NewLine;
_sInvoicePostedDate += result.InvoicePostedDate.ToShortDateString() + Environment.NewLine + Environment.NewLine;
_sTotalCharges += result.TotalCharges + Environment.NewLine + Environment.NewLine;
_sTotalPayments += result.TotalPayments + Environment.NewLine + Environment.NewLine;
_sBalanceDue += result.BalanceDue + Environment.NewLine + Environment.NewLine;
}

// Print the current page
printDocument1.Print();
}
}
}
MIDCOPC 21-Jul-23 9:32am View    
We set custom format on the DTP to " ". In our environment, we schedule appointments. If the DPT shows a date, say today's date, we can't trust our users to change the date of the appointment, so we have it blank when the form.
MIDCOPC 18-Jul-23 7:34am View    
This solution will work as long as there is an existing date in the DTP. When I open the winform, the date is blank.
MIDCOPC 8-Jul-21 19:53pm View    
Thank you. After reading this I was able to get what I needed.
MIDCOPC 7-Jul-21 17:14pm View    
I don't know where to start. I have the file list going to the console but I need save it in memory then search the table to see if any file names match records in the table.