Solved

C# and Crystal Report

Posted on 2011-02-23
8
833 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:g_johnson
  • 4
  • 3
8 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 34964322
I don't believe there is anything in the viewer.

You need to use the report object.  It has the printer setup.  
This tutorial will show you how to do it
http://www.businessobjects.com/global/pdf/dev_zone/VS2005_Walkthroughs.pdf

mlmcc
0
 
LVL 7

Expert Comment

by:jdavistx
ID: 34964348
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.
0
 
LVL 4

Author Comment

by:g_johnson
ID: 34971795
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();
                    }
                }
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 100

Expert Comment

by:mlmcc
ID: 34972788
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
0
 
LVL 4

Author Comment

by:g_johnson
ID: 34973078
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.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34973750
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
0
 
LVL 4

Author Comment

by:g_johnson
ID: 35008464
This turned out to be a driver issue.  However, I did find the one comment to be useful and will be awarding point accordingly.
0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 35008476
This does accurately answer the question of how to set the orientation programatically.  Thanks!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Keyboard 2 41
HttpPostedFile 1 30
Please explain the parts of these 2 LINQ expressions 3 54
C# Service FileSystemwatcher isse 9 27
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question