Solved

C# and Crystal Report

Posted on 2011-02-23
8
824 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now