Your full service technology partner! 
-Collapse +Expand
Search C# Group:

-Collapse +Expand C# To/From
-Collapse +Expand C# Study Test
-Collapse +Expand C# Store

Prestwood eMagazine

December Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingC#   Print This     
An Inventory Transaction Report in C#
Posted 13 months ago on 11/13/2020
Take Away:

This article describes a C# module I created that will generate an inventory transaction report.



This discussion will focus on a C# module that will accept a transaction date range input for an inventory transaction report. The programming code will show the inventory additions and subtractions that occurred within the entered transaction date range upon the report’s preview. Please click here to see the full code readout.


The first thing to do is to prompt the user for a transaction date range that will be used to extract data for the report. This will trap additions and subtractions of part numbers in the inventory system that fall within the date range inputs. The transaction date range input screen looks like this.


After clicking the Proceed button, the detail inventory records that are trapped within the specified transaction date range will be appended to a newly created binary text file I call currdir +”ireport.txt”, where currdir is the path of the current directory. The date comparison process I use here explodes the dates into month, day and year components. These date elements are used in a proprietary algorithm I created that also compensates for the Y2K issue. This date comparison algorithm may seem crude and unorthodox, but it does work consistently. I have used this in many software development projects with very reliable results.

This uses a nested looping mechanism to extract the needed detail inventory transaction records. The master inventory data file, currdir + “mastitem.txt”, acts as the outer loop. MASTERLEN is the record length of each master inventory record used in the outer loop. With each pass through, the current master inventory record’s detail transaction data file name is retrieved and opened. This detail inventory transaction file acts as the inner loop of the data extraction algorithm. The DETAILEN defined constant represents the record length of each detail inventory transaction record used in the inner loop.

The date comparison algorithm and transaction data extraction will occur within the inner loop. Data from each transaction data record will be appended to the currdir + “ireport.txt” binary data file. Also, the running balance will be calculated for each line of detail transaction data that appears in the inventory transaction report.


The code below illustrates how the print preview window is constructed after the detail inventory transaction data has been extracted and appended to currdir +”ireport.txt”. I have set the PageCount variable to 1 to initialize the page counting mechanism. Also, the master_inventory_record_increment file stream position offset variable, has been initialized to 0.

  1. // this will fire after clicking the ‘Proceed‘ button on the transaction
  2. // date input screen.  
  3. private void ProceedButton_Click(object sender, System.EventArgs e)  
  4. {  
  5. (preceding code to process data....see full code readout)             
  6. .  
  7. .  
  8. .  
  9. // use constructors to create objects needed to create
  10. // the print preview window of the report.
  11. PrintPreviewDialog printPreviewDialog1 = newPrintPreviewDialog();  
  12. PrintDocument printDocument1 = newPrintDocument();  
  13. Document = printDocument1;  
  14. master_inventory_record_increment = 0;  
  15. PageCount = 1;  
  16. Size = newSize(900, 700);  
  17. PrintPage += newPrintPageEventHandler(this.printDocument1_PrintPage);  
  18. PrintDialog d = newPrintDialog();  
  19. Document = printDocument1;  
  20. DialogResult r = d.ShowDialog();  
  21. if(r == DialogResult.OK)  
  22. {  
  23. // now show the report.
  24. ShowDialog();  
  25. }  
  26. }  

Next, you see the code that paints the print preview window so the inventory transactions report will display.

  1. // this will render the print preview of the inventory report.  
  2. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)  
  3. {  
  4. // declare local variables for the ‘print‘ event.
  5. floatx1 = 0.0F;  
  6. floaty1 = 0.0F;  
  7. floatline_counter;  
  8. floatwidth_quartervalue;  
  9. stringstringDateRange;  
  10. // construct objects to facilitate the printing process.
  11. Drawing.Font printFont = newSystem.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Regular);  
  12. Drawing.Font printFontB = newSystem.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);  
  13. Drawing.Font printFontTitle = newSystem.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);  
  14. Graphics.PageUnit = GraphicsUnit.Inch;  
  15. SizeF sz, sz1, sz2;  
  16. // set this ‘width_quartervalue‘ variable that will
  17. // be used to assist with centering information on
  18. // the preview and printed output. 
  19. width_quartervalue = 8.50f / 4.0f;  
  20. // render the heading information: date, page number, title, etc.
  21. DateTime saveNow = DateTime.Now;  
  22. dtString = saveNow.ToString();  
  23. Graphics.DrawString(dtString, printFont, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + 0.4f);  
  24. Graphics.DrawString("Page: ", printFont, System.Drawing.Brushes.Black, x1 + 7.5f, y1 + 0.4f);  
  25. sz1 = ev.Graphics.MeasureString("Page: ", printFont);  
  26. Graphics.DrawString(PageCount.ToString(), printFont, System.Drawing.Brushes.Black, x1 + 7.5f + sz1.Width, y1 + 0.4f);  
  27. sz = ev.Graphics.MeasureString("Items Inventory Transaction List", printFontTitle);  
  28. Graphics.DrawString("Items Inventory Transaction List", printFontTitle, System.Drawing.Brushes.Black, x1 + (width_quartervalue * 2) - (sz.Width / 2), y1 + 0.5f);  
  29. stringDateRange = strStartDate.ToString() + " To "+ strEndDate.ToString();  
  30. sz2 = ev.Graphics.MeasureString(stringDateRange, printFont);  
  31. Graphics.DrawString(stringDateRange, printFont, System.Drawing.Brushes.Black, x1 + (width_quartervalue * 2) - (sz2.Width / 2), y1 + 0.9f);  
  32. line_counter = 0.7f;  
  33. // render the column labels of the report.
  34. line_counter = line_counter + 0.10f;  
  35. Graphics.DrawString("Date ", printFontB, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + line_counter + 0.9f);  
  36. Graphics.DrawString("P.O.# ", printFontB, System.Drawing.Brushes.Black, x1 + 1.1f, y1 + line_counter + 0.9f);  
  37. Graphics.DrawString("Item ", printFontB, System.Drawing.Brushes.Black, x1 + 2.05f, y1 + line_counter + 0.9f);  
  38. Graphics.DrawString("Description ", printFontB, System.Drawing.Brushes.Black, x1 + 3.35f, y1 + line_counter + 0.9f);  
  39. Graphics.DrawString("Q IN ", printFontB, System.Drawing.Brushes.Black, x1 + 5.8f, y1 + line_counter + 0.9f);  
  40. Graphics.DrawString("Q OUT", printFontB, System.Drawing.Brushes.Black, x1 + 6.55f, y1 + line_counter + 0.9f);  
  41. Graphics.DrawString("Balance", printFontB, System.Drawing.Brushes.Black, x1 + 7.3f, y1 + line_counter + 0.9f);  
  42. line_counter = line_counter + 0.25f;  
  43. FileInfo datafileinfo = newFileInfo(currdir + "ireport.txt");  
  44. sizeofdatafile = datafileinfo.Length;  
  45. StreamReader streamobj = newStreamReader(currdir + "ireport.txt");  
  46. BaseStream.Seek(master_inventory_record_increment, SeekOrigin.Begin);  
  47. do
  48. {  
  49. stringVal = streamobj.ReadLine();  
  50. if(stringVal != null)  
  51. {  
  52. if(stringVal.Substring(0, 4) != "Date")  
  53. {  
  54. // display the pertinent data beneath each of the column headings.
  55. Graphics.DrawString(stringVal.Substring(0, 8), printFont, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + line_counter + 0.9f);  
  56. Graphics.DrawString(stringVal.Substring(8, 10), printFont, System.Drawing.Brushes.Black, x1 + 1.1f, y1 + line_counter + 0.9f);  
  57. Graphics.DrawString(stringVal.Substring(18, 15), printFont, System.Drawing.Brushes.Black, x1 + 2.05f, y1 + line_counter + 0.9f);  
  58. Graphics.DrawString(stringVal.Substring(33, 30), printFont, System.Drawing.Brushes.Black, x1 + 3.35f, y1 + line_counter + 0.9f);  
  59. Graphics.DrawString(stringVal.Substring(63, 5), printFont, System.Drawing.Brushes.Black, x1 + 5.8f, y1 + line_counter + 0.9f);  
  60. Graphics.DrawString(stringVal.Substring(68, 5), printFont, System.Drawing.Brushes.Black, x1 + 6.55f, y1 + line_counter + 0.9f);  
  61. Graphics.DrawString(stringVal.Substring(73, 7), printFont, System.Drawing.Brushes.Black, x1 + 7.3f, y1 + line_counter + 0.9f);  
  62. line_counter = line_counter + 0.15f;  
  63. }  
  64. }  
  65. master_inventory_record_increment = master_inventory_record_increment + REPORTRECORDLEN;  
  66. while(line_counter < 8.0f && master_inventory_record_increment < sizeofdatafile);  
  67. Close();  
  68. // if the filestream offset ‘master_inventory_record_increment‘ has not reached the 
  69. // end of the data file currdir + "ireport.txt", then continue printing; otherwise
  70. // stop. 
  71. if(master_inventory_record_increment < sizeofdatafile)  
  72. {  
  73. // if there are more pages in the report, then continue.
  74. PageCount++;  
  75. HasMorePages = true;  
  76. }  
  77. else
  78. {  
  79. // if there are no more pages in the report, then stop.  
  80. HasMorePages = false;  
  81. master_inventory_record_increment = 0;  
  82. PageCount = 1;  
  83. }  
  84. }  

Here is a snapshot of what the first page of the print preview of the inventory transactions report looks like for an input date range of 01/01/13 through 12/31/13 using sample data.


During the course of building an application, it’s important to consider the human engineering side of the equation. A program must put its best foot forward to get people to use it. This report is both simple to operate and fast. That is what customers really want – not some overdone programming behemoth that scares off potential users. In addition to custom software design, I also offer computer repair services in my local area of Cleveland, Ohio USA.


Share a thought or comment...
First Comment
Comment 1 of 7

<spam removed>

Posted 6 months ago

Comment 2 of 7

<spam removed>

Posted 6 months ago

Comment 3 of 7

<spam removed>

Posted 6 months ago

Comment 4 of 7

<spam removed>

Posted 6 months ago

Comment 5 of 7

<spam removed>

Posted 6 months ago

Comment 6 of 7

Thanks for the informative and helpful post, obviously in your blog everything is good.. Cars in oman

Posted 70 days ago

Latest Comment
Comment 7 of 7

As a student, if you are facing issues in finishing your History assignment then you should purchase the History assignment help online from our website and finish your assignment. We have Ph.D.-level experts working with us and they will write the assignment for you. The assignment made by our experts is 100% free from plagiarism and errors. Browse our website to know more about our services.

Posted 59 days ago
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P195A1
Enter key:
Article Contributed By NE Ohio Computer Guy:

Please visit my software developer website for more information about my services. I offer application development as well as Android app coding services. My developer skills are best suited to dealing with custom software projects. I can perform programming for Corel Paradox as well as C# and PHP.

In my local area of northeast Ohio, I can cater to computer repair and "fix my computer" issues. And don‘t forget to check out my YouTube Channel. It is full of cool videos and has something for everyone!

Use my contact web page today to reach me about any software design ideas you have.

Visit Profile

 KB Article #104922 Counter
Since 11/13/2020
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site:

©1995-2021 Prestwood IT Solutions.   [Security & Privacy]