Link to home
Start Free TrialLog in
Avatar of g_johnson
g_johnsonFlag for United States of America

asked on

C# and Crystal Report

I have a C# project (VS2005) with a Crystal Report Viewer.  The code to call the crystal report is attached.  It prints a series of labels based upon a batch number in a table, then, if the user indicates a problem, does it again until the user says all is okay.

It is pointed at a Zebra ZM400 printer.

The report, if printed via Crystal itself, prints okay.  When it is called by the program, the orientation is wrong.

Any suggestions what to look at, what to do?  I can find nothing in the crv object that allows me to set orientation.
while (!Done)
                {
                    crvMain.ReportSource = this._PalletLabelPath;
                    crvMain.SelectionFormula = "{esna_PLUserInput.BatchId} = " + (char)34 + Batch + (char)34;

                    crvMain.PrintReport();

                    if (MessageBox.Show(this, "Did The Labels Print Correctly?", "Label Program", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //clear the screen and reset focus
                        this.ClearScreen2();

                        //set flag
                        Done = true;
                    }
                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdavistx
jdavistx

With your crystal report open in Visual Studio...

Go to the "Crystal Reports" menu on the toolbar.
Go to "Design"
Go to "Page Setup"

See if that will let you set the desired orientation, and then try again.
Avatar of g_johnson

ASKER

The Crystal report is "stand-alone", i.e., not "in" VS.  In CRXI it is set to portrait mode.  

I have changed my code as follows, but it seems to have no affect on the printing.  We are getting inconsistent results.  Without changing anything in the program, under certain circumstances it prints landscape in others it prints portrait.  That seems to have to do with how we are connected as follows:  the app is installed on Machine A and Machine B.  If run directly from either machine, the orientation is wrong.  If we remote from Machine A to Machine B and run it from that remote session then the orientation is correct.  Also, from this remote session, we can choose either the remote or the local printer, and in both cases it prints correctly.

Here is my latest code:

                while (!Done)
                {
                    ReportDocument rd = new ReportDocument();
                    rd.Load(this._RollLabelPath);
                    if (this._Orientation == "P")
                        rd.PrintOptions.PaperOrientation = PaperOrientation.Portrait;
                    else
                        rd.PrintOptions.PaperOrientation = PaperOrientation.Landscape;

                    crvMain.ReportSource = rd;

                    //crvMain.ReportSource = this._RollLabelPath;
                    crvMain.SelectionFormula = "{esna_LbLReptMast.BatchId} = " + (char)34 + BatchId + (char)34;

                    crvMain.PrintReport();

                    if (MessageBox.Show(this, "Did The Labels Print Correctly?", "Label Program", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //clear functional table
                        f.ClearTable(this._Conn, BatchId);

                        //clear the screen and reset focus
                        this.ClearScreen();

                        //set flag
                        Done = true;
                    }
                    else
                    {
                        //if start-over, get info, adjust table if necessary, and run Crystal again
                        fRestart fR = new fRestart();
                        fR.ConnString = this._Conn;
                        fR.BatchId = BatchId;

                        fR.ShowDialog();
                    }
                }
Are you trying to change the orientation of the report on the fly?

Normally you set the printer to match the report developed orientation.

mlmcc
Well, what we're doing is troubleshooting.  We're not getting what we want when it's run from the program, though it runs fine from Crystal.  So we are tyring to force the issue via the program.
I found in some instances a report will switch the printer to Portrait but not the other way.  I set my printer to default to landscape since most of the reports were landscape and it seemed to work.

mlmcc
This turned out to be a driver issue.  However, I did find the one comment to be useful and will be awarding point accordingly.
This does accurately answer the question of how to set the orientation programatically.  Thanks!