The first thing to do is 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.
EXTRACT THE DATA FOR THE REPORT
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.
SET UP THE PRINT PREVIEW WINDOW
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.
-
- private void ProceedButton_Click(object sender, System.EventArgs e)
- {
- (preceding code to process data....see full code readout)
- .
- .
- .
-
-
-
- PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
- PrintDocument printDocument1 = new PrintDocument();
- printPreviewDialog1.Document = printDocument1;
- master_inventory_record_increment = 0;
- PageCount = 1;
- printPreviewDialog1.Size = new Size(900, 700);
- printDocument1.PrintPage += new PrintPageEventHandler(this.printDocument1_PrintPage);
- PrintDialog d = new PrintDialog();
- d.Document = printDocument1;
- DialogResult r = d.ShowDialog();
- if (r == DialogResult.OK)
- {
-
- printPreviewDialog1.ShowDialog();
- }
-
- }
Next, you see the code that “paints” the print preview window so the inventory transactions report will display.-
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
- {
-
-
- float x1 = 0.0F;
- float y1 = 0.0F;
- float line_counter;
- float width_quartervalue;
- string stringDateRange;
-
- System.Drawing.Font printFont = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Regular);
- System.Drawing.Font printFontB = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
- System.Drawing.Font printFontTitle = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);
- ev.Graphics.PageUnit = GraphicsUnit.Inch;
- SizeF sz, sz1, sz2;
-
-
-
-
-
- width_quartervalue = 8.50f / 4.0f;
-
-
-
- DateTime saveNow = DateTime.Now;
- dtString = saveNow.ToString();
- ev.Graphics.DrawString(dtString, printFont, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + 0.4f);
- ev.Graphics.DrawString("Page: ", printFont, System.Drawing.Brushes.Black, x1 + 7.5f, y1 + 0.4f);
- sz1 = ev.Graphics.MeasureString("Page: ", printFont);
- ev.Graphics.DrawString(PageCount.ToString(), printFont, System.Drawing.Brushes.Black, x1 + 7.5f + sz1.Width, y1 + 0.4f);
- sz = ev.Graphics.MeasureString("Items Inventory Transaction List", printFontTitle);
- ev.Graphics.DrawString("Items Inventory Transaction List", printFontTitle, System.Drawing.Brushes.Black, x1 + (width_quartervalue * 2) - (sz.Width / 2), y1 + 0.5f);
- stringDateRange = strStartDate.ToString() + " To " + strEndDate.ToString();
- sz2 = ev.Graphics.MeasureString(stringDateRange, printFont);
- ev.Graphics.DrawString(stringDateRange, printFont, System.Drawing.Brushes.Black, x1 + (width_quartervalue * 2) - (sz2.Width / 2), y1 + 0.9f);
-
- line_counter = 0.7f;
-
-
- line_counter = line_counter + 0.10f;
- ev.Graphics.DrawString("Date ", printFontB, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("P.O.# ", printFontB, System.Drawing.Brushes.Black, x1 + 1.1f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("Item ", printFontB, System.Drawing.Brushes.Black, x1 + 2.05f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("Description ", printFontB, System.Drawing.Brushes.Black, x1 + 3.35f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("Q IN ", printFontB, System.Drawing.Brushes.Black, x1 + 5.8f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("Q OUT", printFontB, System.Drawing.Brushes.Black, x1 + 6.55f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString("Balance", printFontB, System.Drawing.Brushes.Black, x1 + 7.3f, y1 + line_counter + 0.9f);
- line_counter = line_counter + 0.25f;
-
- FileInfo datafileinfo = new FileInfo(currdir + "ireport.txt");
- sizeofdatafile = datafileinfo.Length;
-
- StreamReader streamobj = new StreamReader(currdir + "ireport.txt");
- streamobj.BaseStream.Seek(master_inventory_record_increment, SeekOrigin.Begin);
-
- do
- {
-
- stringVal = streamobj.ReadLine();
-
- if (stringVal != null)
- {
-
- if (stringVal.Substring(0, 4) != "Date")
- {
-
-
- ev.Graphics.DrawString(stringVal.Substring(0, 8), printFont, System.Drawing.Brushes.Black, x1 + 0.5f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(8, 10), printFont, System.Drawing.Brushes.Black, x1 + 1.1f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(18, 15), printFont, System.Drawing.Brushes.Black, x1 + 2.05f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(33, 30), printFont, System.Drawing.Brushes.Black, x1 + 3.35f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(63, 5), printFont, System.Drawing.Brushes.Black, x1 + 5.8f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(68, 5), printFont, System.Drawing.Brushes.Black, x1 + 6.55f, y1 + line_counter + 0.9f);
- ev.Graphics.DrawString(stringVal.Substring(73, 7), printFont, System.Drawing.Brushes.Black, x1 + 7.3f, y1 + line_counter + 0.9f);
- line_counter = line_counter + 0.15f;
-
- }
-
- }
-
- master_inventory_record_increment = master_inventory_record_increment + REPORTRECORDLEN;
-
- } while (line_counter < 8.0f && master_inventory_record_increment < sizeofdatafile);
- streamobj.Close();
-
-
-
-
-
- if (master_inventory_record_increment < sizeofdatafile)
- {
-
- PageCount++;
- ev.HasMorePages = true;
- }
- else
- {
-
- ev.HasMorePages = false;
- master_inventory_record_increment = 0;
- PageCount = 1;
- }
-
-
- }
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.
CONCLUSION During the course of building an application, it’s important to consider the “human engineering” side of the equation. A program must be inviting to entice people to use it. This inventory transaction 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 application development, I also offer computer repair services in my local area of Cleveland, Ohio USA.