Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VERY SERIOUS PROBLEM. PLEASE HELP!

Status
Not open for further replies.

rohithere

Programmer
Oct 27, 2003
51
IN
Hi,
I had made a report having CardLayout as its Layout Manager.This report spans multiple pages(i.e. cards).I had problem with this setup e.g. It used to miss some records on each cards .Also It used to give wrong totals.So I combined all records of all cards into one single card.This way it does not skip the records and also gives totals correctly.
But it has lead to another problem and that is:
In the previous setup of multiple cards there was no printing problem as I used to print each card i.e each page.
But with this modified setup i.e. all records into one card Iam finding it difficult to print as the contents of the report are very vast that it spans vast area both vertically as well as horizontly and so I don't get the info on paper as it gets cut,as the content of the report is very vast.and the content is related that is I cannot affored to either miss on the Horizontal wise cut and neither the vertical wise cut in print.


As printing the above long page is not possible.Below Iam sending you my code.Please tell me as Iam unable to find out, why from going from one card to another it misses on some values as mentioned above.

salesReportStateWise.java

if(radioPartyProductPrice.isSelected())
{
// Product selected by user is stored in variable productS.
String productS = (String)JOptionPane.showInputDialog(null, "Choose One Product :", "Product Series List",JOptionPane.INFORMATION_MESSAGE, null, possibleProductvalues, possibleProductvalues[0]);

String outOptionPane = "";
//System.out.println(productS);
try
{
//Here U format the above value and store this formatted value inside another variable outOptionPane.
outOptionPane = productS.trim().substring(0,1);

}
catch(Exception ee)
{
ee.printStackTrace();
}
String[][] analysisinfo = null;
double[][] prod = null;

String[]companyinfo = transactionhelper.getCompanyHeaderInfo(); //retrieves the Co. Header Info.
String[][] productcodes=null ;
String partyName = "";
double qty=0,price=0;
int n=0;

if(productS.equals("Select All"))
{
productcodes = transactionhelper.getProductNames();
analysisinfo = transactionhelper.getSalesAnalysisPartyProductPriceWise (txtFromM.getText()+"/"+txtFromD.getText()+"/"+txtFromY.getText(), txtToM.getText()+"/"+txtToD.getText()+"/"+txtToY.getText(), (String)txtState.getSelectedItem());
//----- Added for Horizontal Total


partyName = analysisinfo[0][4];
prod = new double[analysisinfo.length][2];
for(int i=0;i<analysisinfo.length;i++)
{
//added for serieswise Total
if(!(analysisinfo[4].trim()).equals(partyName.trim()))
{
prod[n][0]=qty;
prod[n][1]=price;
n=i;
qty=0;
price=0;
partyName=analysisinfo[4];
}
double tempqty=0,tempprice=0;
try
{
tempqty = Double.parseDouble(analysisinfo[3].trim());
tempprice = Double.parseDouble(analysisinfo[1].trim()) * Double.parseDouble(analysisinfo[3]) / Double.parseDouble(analysisinfo[2].trim());
}
catch(Exception eee)
{ tempqty=0;
tempprice=0;
}

qty+=tempqty;
price+=tempprice;
}//end for loop
//---------------End of Horizontal Total
prod[n][0]=qty;
prod[n][1]=price;
}
else
{
//for serieswise output
productcodes = transactionhelper.getProductNamesSeries(outOptionPane);

analysisinfo = transactionhelper.getSalesAnalysisPartyProductPriceWise1 (txtFromM.getText()+&quot;/&quot;+txtFromD.getText()+&quot;/&quot;+txtFromY.getText(), txtToM.getText()+&quot;/&quot;+txtToD.getText()+&quot;/&quot;+txtToY.getText(), (String)txtState.getSelectedItem(),outOptionPane);

//----- Added for Horizontal Total
partyName = analysisinfo[0][4];
prod = new double[analysisinfo.length][2];
//double qty=0,price=0;
//int n=0;
for(int i=0;i<analysisinfo.length;i++)
{
//added for serieswise Total
//double ab=0,cd=0;
if(!(analysisinfo[4].trim()).equals(partyName.trim())) //Check if the customerName is not same as stored in variable partyName
{
prod[n][0] = qty;
prod[n][1] = price;
//qty=qty+ab
//price=price+cd
n = i;
qty = 0;
price = 0;
partyName = analysisinfo[4];
}

double tempqty=0,tempprice=0;

try
{
tempqty = Double.parseDouble(analysisinfo[3].trim());
tempprice = Double.parseDouble(analysisinfo[1].trim()) * Double.parseDouble(analysisinfo[3].trim()) / Double.parseDouble(analysisinfo[2].trim());
}
catch(Exception eee)
{
tempqty=0;
tempprice=0;
System.out.println(eee);
}

qty += tempqty;
price += tempprice;

}//end for loop


//----- End of Horizontal Total

prod[n][0]=qty;
prod[n][1]=price;

}//end if's else condition


if((companyinfo==null)||(productcodes==null)||(analysisinfo==null))
{
mb.errMsg(&quot;Error&quot;,&quot;DataBase Error !!!&quot;, this);
return;
}

String state = &quot;&quot;;
int nostates = 0;

for(int i = 0;i<analysisinfo.length;i++)
{
if (!state.equals(analysisinfo[4]))
{
nostates ++;
state = analysisinfo[4];
}
}

//System.out.println(&quot;States : &quot;+ nostates);
int pages = (int)(nostates/35);
if((nostates%35)==0) --pages ;
// pages = 1;//need to change
int pagepart = (int)(productcodes.length/12);//23
if((productcodes.length%12)==0) --pagepart ; //23

//mb.errMsg(&quot;Error&quot;,nostates +&quot;DataBase Error !!!&quot;+pagepart, this);

DecimalFormat formatterddmm = new DecimalFormat(&quot;00&quot;);
DecimalFormat formatteryyyy = new DecimalFormat(&quot;0000&quot;);

String fromdate = formatterddmm.format(Integer.parseInt(txtFromD.getText())) + &quot;/&quot; + formatterddmm.format(Integer.parseInt(txtFromM.getText())) + &quot;/&quot; + formatteryyyy.format(Integer.parseInt(txtFromY.getText()));

String todate = formatterddmm.format(Integer.parseInt(txtToD.getText())) + &quot;/&quot; + formatterddmm.format(Integer.parseInt(txtToM.getText())) + &quot;/&quot; + formatteryyyy.format(Integer.parseInt(txtToY.getText()));


JFrame j = new JFrame(&quot;Party/Product/Price-Wise Sales Analysis For &quot;+(String)txtState.getSelectedItem()+&quot; From &quot;+fromdate+&quot; To &quot;+todate);
JScrollPane sp[] = new JScrollPane[(pages+1)*(pagepart+1)];

SalesReportPartyProductPriceWiseView viewform[] = new SalesReportPartyProductPriceWiseView[(pages+1)*(pagepart+1)];

view = new JPanel();
card= new CardLayout();
view.setLayout(card);
next = new JButton(&quot;Next&quot;);
previous = new JButton(&quot;Previous&quot;);
print = new JButton(&quot;Print Me&quot;);
next.addActionListener(this);
previous.addActionListener(this);
print.addActionListener(this);
JPanel bottom =new JPanel();
bottom.setLayout( new FlowLayout(FlowLayout.CENTER,30,5));
bottom.add(next);
bottom.add(previous);
bottom.add(print);
int k = -1;
for(int i=0;i<=pagepart;i++)
{
for(n=0;n<=pages;n++)
{
++k;
viewform[k]=new SalesReportPartyProductPriceWiseView(n+1,i+1,fromdate,todate, companyinfo, productcodes, analysisinfo,(String)txtState.getSelectedItem(),pagepart+1,prod,pages);
viewform[k].print=false;
sp[k] = new JScrollPane(viewform[k]);
view.add(sp[k],k+&quot;&quot;);
}
}

Container con=j.getContentPane();
//con.setLayout(null);
//view.setBounds(0,0,600,500);
//bottom.setBounds(0,500,600,100);
con.add(view,BorderLayout.CENTER);
con.add(bottom,BorderLayout.SOUTH);
j.setSize(700,600);
j.setVisible(true);


}//End radioStateProduct

}//End btnView

if(source == next)
{
card.next(view);
}
if(source == previous)
{
card.previous(view);
}


if(source == print)
{
Component[]comp=view.getComponents();

Component[]printcomp = new Component[comp.length];


for(int i=0;i<comp.length;i++)
{
if (((JScrollPane)comp).getViewport().getView()instanceof SalesReportStateWiseView)
{
printcomp=(SalesReportStateWiseView)((JScrollPane)comp).getViewport().getView();
((SalesReportStateWiseView)printcomp).print=true;
}
else if(((JScrollPane)comp).getViewport().getView()instanceof SalesReportStateProductPriceWiseView)
{
printcomp=(SalesReportStateProductPriceWiseView)((JScrollPane)comp).getViewport().getView();
((SalesReportStateProductPriceWiseView)printcomp).print=true;
}
else if(((JScrollPane)comp).getViewport().getView()instanceof SalesReportStateCityWiseView)
{
printcomp=(SalesReportStateCityWiseView)((JScrollPane)comp).getViewport().getView();
((SalesReportStateCityWiseView)printcomp).print=true;
}
else if(((JScrollPane)comp).getViewport().getView()instanceof SalesReportStatePartyWiseView)
{
printcomp=(SalesReportStatePartyWiseView)((JScrollPane)comp).getViewport().getView();
((SalesReportStatePartyWiseView)printcomp).print=true;
}
else if(((JScrollPane)comp).getViewport().getView()instanceof SalesReportStateProductPriceWiseViewNew)
{
printcomp=(SalesReportStateProductPriceWiseViewNew)((JScrollPane)comp).getViewport().getView();
((SalesReportStateProductPriceWiseViewNew)printcomp).print=true;
}
else if(((JScrollPane)comp).getViewport().getView() instanceof SalesReportPartyProductPriceWiseView)
{
PrintUtilities.printComponent(viewform1);
}
// for(int m=0;m<=2500;m=m+480)
// {
// Point p=((JScrollPane)comp).getViewport().getViewPosition();
// p.x=0;
// p.y=m;
//
// ((JScrollPane)comp).getViewport().setViewPosition(p);
//
// wml.writeToTextFileTestComp(&quot;JScroll&quot;,p);
// wml.writeToTextFileTestInt(&quot;P.Y&quot;,p.y);
// PrintUtilities.printComponent(view);

// int nmembers = view.getComponentCount();
// for (int g = 0 ; g < nmembers ; g++)
// {
// Component m = view.getComponent(g);
// if (m.isVisible()) {



// }
// }
//
// }

}

PrintUtilities.printAll(printcomp);

}//end btnPrint
}//End actionPerformed



------------------------------------

class SalesReportPartyProductPriceWiseView extends JPanel implements Printable
{
SimpleDateFormat formatter = new SimpleDateFormat (&quot;dd/MM/yyyy&quot;);
DecimalFormat numberformatter = new DecimalFormat(&quot;#0000.00&quot;);
writeMessageLog wr = new writeMessageLog();
TransactionHelper transactionhelper;
Font f;
FontMetrics fm;
int pageno,pagepart,lastpart,lastpageno;
String fromdate,todate,statename;
String[]companyinfo;
String[][]productcodes,reportinfo;
String[] CustomerNames=null;
double[][]prod;
boolean print=false;

public SalesReportPartyProductPriceWiseView(int pageno,int pagepart, String fromdate,String todate, String[]companyinfo, String[][] productcodes, String[][] reportinfo,String statename,int lastpart,double[][]prod,int lastpageno)
{

this.pageno=pageno;
this.pagepart=pagepart;
this.fromdate=fromdate;
this.todate=todate;
this.companyinfo=companyinfo;
this.productcodes=productcodes;
this.reportinfo=reportinfo;
this.statename=statename;
this.lastpart=lastpart;
this.prod=prod;
this.lastpageno=lastpageno;
setMinimumSize(new Dimension(1100,900));
setPreferredSize(new Dimension(1100,900));

}

public void paintBody(Graphics g)
{
f=new Font(null,Font.PLAIN,12);
g.setFont(f);
g.drawString (&quot;Sales Analysis Party/Product/Price Wise For &quot;+statename+&quot; From &quot;+fromdate+&quot; To &quot;+todate+&quot; Page No. &quot;+pagepart + &quot;.&quot;+pageno,10,120);
f=new Font(null,Font.PLAIN,10);
g.setFont(f);
fm = this.getFontMetrics(g.getFont());//get FontMatrics

g.drawLine(0,140,1100,140);
g.drawString(&quot;Party Name&quot;,10,155);
g.drawString(&quot;Town&quot;,110,155);
g.drawLine(0,160,1100,160);
int x = 150;
int y=170;
int srno=1;
double[] totalqty = new double[25];
double[] totalamt = new double[25];
double gTotalQty=0; //Added to get the total of qty series wise
double gTotalAmt=0; //Added to get the total of Amount series wise
String PartyName = reportinfo[0][4];
int statecount=0; //statecount

for (int i=0;i<reportinfo.length ;i++ )
{
//double d=0;

if(statecount==((pageno*24)))break;

x = 250;
int col = -1;
if(statecount==((pageno*24)-24))PartyName = &quot;&quot;;

//statecount++;
// printing party and place name
if((PartyName.equals(reportinfo[4])==false) &&(PartyName.length()>0))
{
PartyName = reportinfo[4];
statecount++;


if((statecount>(pageno*24)-24)&&(statecount<(pageno*24)))
{
y+=25;

g.drawString(Validate.writeSubString(reportinfo[4],fm,95),10,y);
g.drawString(Validate.writeSubString(reportinfo[0],fm,85),110,y);

//printing the Total , Total Qty and Total Amount for all series
// if(pagepart==lastpart)
// {
g.drawString(&quot;Total&quot;,800 - fm.stringWidth(&quot;Total&quot;),155);


double x1 = prod[0];
String x2= (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,800 - fm.stringWidth(x2),y);

x1 = prod[1];
x2= (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,800 - fm.stringWidth(x2),y+10);

gTotalQty += prod[0];
gTotalAmt += prod[1];
// }
}
}
else if(PartyName.trim().equalsIgnoreCase(reportinfo[4].trim())==false)
{
PartyName = reportinfo[4].trim();
statecount++;
if((statecount>(pageno*24) - 24) && (statecount<(pageno*24)))
{
g.drawString(Validate.writeSubString(reportinfo[4].trim(),fm,95),10,y);
g.drawString(Validate.writeSubString(reportinfo[0].trim(),fm,85),110,y);

// if(pagepart==lastpart)
// {
g.drawString(&quot;Total&quot;,800 - fm.stringWidth(&quot;Total&quot;),155);
//eleminating the zero value in prod array
int tempi = i;
while(prod[tempi][0]==0)tempi--;
i=tempi;
double x1 = prod[0];
String x2= (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,800 - fm.stringWidth(x2),y);
//wr.writeToTextFile(&quot;Total3 :-&quot;+x2);

x1 = prod[1];
x2 = (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,800 - fm.stringWidth(x2),y+10);
//wr.writeToTextFile(&quot;Total4 :-&quot;+x2);

gTotalQty += prod[0];
gTotalAmt += prod[1];
// }
}

}


// printing product details
for(int j=((pagepart-1)*12);j<productcodes.length;j++)//23
{
if(j==(pagepart * 12))//23
{
break;
}

//printing product code
g.drawString(productcodes[j][0].trim(),x - fm.stringWidth(productcodes[j][0].trim()),155);
++col;

//printing vertical total
if(reportinfo[5].trim().equalsIgnoreCase(productcodes[j][0].trim()))
{
totalqty[col] += Double.parseDouble(reportinfo[3].trim());
totalamt[col] += Double.parseDouble(reportinfo[1].trim()) * Double.parseDouble(reportinfo[3].trim()) / Double.parseDouble(reportinfo[2].trim());

if(statecount<((pageno*24)-24))
{
x += 50;
continue;
}

//if(statecount<(pageno*24))
//{
g.drawString((int)Double.parseDouble(reportinfo[3].trim())+&quot;&quot;,x - fm.stringWidth((int)Double.parseDouble(reportinfo[3].trim())+&quot;&quot;) ,y);

g.drawString((int)(Double.parseDouble(reportinfo[1].trim()) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ &quot;&quot;,x - fm.stringWidth((int)(Double.parseDouble(reportinfo[1]) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ &quot;&quot;),y+10);
//}
}
x += 50;

}
}

y+=15;
g.drawLine(0,y,1100,y);

if(pageno==lastpageno)
{
g.drawLine(0,y+15,1100,y+15);
x = 250;
int col = 0;

for(int j=((pagepart-1)*12);j<productcodes.length;j++)//23
{
if(j==(pagepart * 12))break; //

g.drawString(&quot;GRAND TOTAL :->&quot;,75 - fm.stringWidth(&quot;Grand Total :->&quot;),y+25);
g.drawString(&quot;Quantity:>&quot;,180 - fm.stringWidth(&quot;Quantity:>&quot;),y+25);
g.drawString(&quot; Amount:>&quot;,180 - fm.stringWidth(&quot; Amount:>&quot;),y+35);

g.drawString(productcodes[j][0].trim(),x - fm.stringWidth(productcodes[j][0]),y+10);

//Printing the Vertical Total(Need to shift somewhere else)
double x1 = totalqty[col];
String x2= (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,x - fm.stringWidth(x2),y+25);
x1 = totalamt[col];
x2 = (Math.round(x1)+&quot;&quot;).trim();
g.drawString(x2,x - fm.stringWidth(x2),y+35);
//end of Vertical Total
if (pagepart==lastpart)
{
g.drawString(Math.round(gTotalQty)+&quot;&quot;,800 - fm.stringWidth(Math.round(gTotalQty)+&quot;&quot;),y+25);

g.drawString(Math.round(gTotalAmt)+&quot;&quot;,800 - fm.stringWidth(Math.round(gTotalAmt)+&quot;&quot;),y+35);

}

++col;
x+=50;
}
g.drawLine(0,y+40,1100,y+40);
}
//else
//{
g.drawLine(0,y+5,1100,y+5);
//}

}//End paintBody

public void paint(Graphics g)
{
if(print)
{
((Graphics2D)g).scale(1,1);
}
else
{
((Graphics2D)g).scale(1.1,1.1);
}
Dimension d=getSize();
g.setColor(Color.white);
g.fillRect(0,0,(int)d.getWidth(),(int)d.getHeight());
g.setColor(Color.black);
paintBody(g);
PaintHeader.paintHeader(companyinfo,g);
}

//Add method print(Graphics g,PageFormat pageFormat,int pages)for printing
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
{
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
disableDoubleBuffering(this);
this.paint(g2d);
enableDoubleBuffering(this);
return(PAGE_EXISTS);
}//End print

public static void disableDoubleBuffering(Component c)
{
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(false);
}

/** Re-enables double buffering globally. */

public static void enableDoubleBuffering(Component c)
{
RepaintManager currentManager = RepaintManager.currentManager(c);
currentManager.setDoubleBufferingEnabled(true);
}
}//end file


IAM IN SERIOUS PROBLEM.

PLEASE HELP ME.DEADLINE IS TOMMORROW.

IT IS VERY URGENT.
Thanks.
 
int counter = 0;
for(int i=0;i<analysisinfo.length;i++)
{
//added for serieswise Total
//double ab=0,cd=0;
if(!(analysisinfo[4].trim()).equals(partyName.trim())) //Check if the customerName is not same as stored in variable partyName
{
prod[counter][0] = qty;
prod[counter][1] = price;
counter++;
//qty=qty+ab
//price=price+cd
...
}
...
}
// try using counter to replace n
 
Hi,
I tried your solution,There is a new problem in it.It is displaying the records of the first page as usual, But in the second page it is repeating the records of the first page.

Kindly help me solve it.

Thanks for u r help.

 
It is difficult to trace logic in program connecting database for outsider.
If you can remark the database connection part of your java program and fill the sample data by yourself, it will become easier to trace the logic by yourself and outsider.

It is difficult for us to trace logic if we cannot compile and run the program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top