Page break

artistunknown

New member
Joined
Dec 15, 2011
Messages
4
Programming Experience
1-3
Well I have gotten this far on my own but i would lilke to make the program where I just update the master.txt instead changing everything if anyone knows a better way to make the PrintDetailLine() method that would be great here's the code


C#:
 using System;
using System.IO;
using System.Text.RegularExpressions;


namespace GladRagsCompany
{
    class Set
    {
        const string INPUTFILE = "C:\\MyProjects\\GladRagsCompany\\GladRagsCompany\\Master.txt";
        const string OUTPUTFILE = "C:\\MyProjects\\GladRagsCompany\\GladRagsCompany\\Report.txt";

        
        static uint pageCount = 1;
        static uint maxDetailLines = 30;
        static uint maxData = 45;
       
        
      
        static string[] customerNumber = new string[100];
       

        static StreamReader fileIn;
        static StreamWriter fileOut;

        

        static void Main()
        {
            if (OpenFiles())
            {
                InputValues();
                PrintReportProgram();
            }
         
            CloseFiles();
            Console.ReadKey();
        }

        static bool OpenFiles()
        {
            bool sucessOpeningFiles = true;

            if (File.Exists(INPUTFILE))
            {
                fileIn = File.OpenText(INPUTFILE);
                Console.WriteLine("{0} was opened", INPUTFILE);
            }
            else 
            {
                Console.WriteLine("Error: {0} does not exist\n", INPUTFILE);
                sucessOpeningFiles = false;
            }
            fileOut = File.CreateText(OUTPUTFILE);
            if (File.Exists(OUTPUTFILE))
                Console.WriteLine("{0} was created\n", OUTPUTFILE);
            else
            {
                Console.WriteLine("Error: {0} could not be created\n", OUTPUTFILE);
                sucessOpeningFiles = false;
            }
            return sucessOpeningFiles;
        }


        static void InputValues()
        {
            uint i;
            string lineIn;
           

            i = 0;
            while ((lineIn = fileIn.ReadLine()) != null)
            {
              
                i++;
                ParseLineIn(lineIn, i);
                
            }
            maxData = i;
        }

        static void ParseLineIn(string lineIn, uint i)
        {
            string[] words;

            lineIn = lineIn.Trim();
            while(Regex.IsMatch(lineIn,"[ ]{2}"))
                lineIn = lineIn.Replace("  "," ");
            words             = lineIn.Split(' ');
            customerNumber[i] = words[0];
        }

        static void PrintReportProgram()
        {
            
            ProcessThisRecord();


            
        }

        static void PrintPageHeadings()
        {


           
            fileOut.WriteLine();
            fileOut.WriteLine("                                  GLAD RAGS CLOTHING COMPANY                                     ");
            fileOut.WriteLine("              CURRENT ACCOUNT BALANCES                                               PAGE: {0}", pageCount);
            fileOut.WriteLine("CUSTOMER      CUSTOMER NAME           CUSTOMER ADDRESS                                 ACCOUNT");
            fileOut.WriteLine("NUMBER                                                                                 BALANCE");
            fileOut.WriteLine();
            pageCount++;
           
           
           
        }

        static void ProcessThisRecord()
        {
            PrintDetailLine();
           
            
        }
    
        static void PrintDetailLine()
        {

            uint i = 1;


            PrintPageHeadings();
      
            for(i=1; i <= maxDetailLines; i++)
                fileOut.WriteLine("{0,-15}", customerNumber[i]);

            PrintPageHeadings();

            for (i = 1; i <= maxData - maxDetailLines; i++)
                fileOut.WriteLine("{0,-15}", customerNumber[i]);
                   
            
               
          
        }

        static void CloseFiles()
        {
            fileIn.Close(); fileOut.Close();
        }

    }
}
 
Well I discovered I wasn't doing a page break at all what I need to do is print a page of 35 detail lines then print another 35 detail lines on the the next page using the printer anyone know how to do that I know its not form feed character I think I might have to open the printer somehow like opening a txt file for reading or writing sorry guys I don't know how to post the report its a txt file
 
Back
Top Bottom