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 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()+"/"+txtFromD.getText()+"/"+txtFromY.getText(), txtToM.getText()+"/"+txtToD.getText()+"/"+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("Error","DataBase Error !!!", this);
return;
}
String state = "";
int nostates = 0;
for(int i = 0;i<analysisinfo.length;i++)
{
if (!state.equals(analysisinfo[4]))
{
nostates ++;
state = analysisinfo[4];
}
}
//System.out.println("States : "+ 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("Error",nostates +"DataBase Error !!!"+pagepart, this);
DecimalFormat formatterddmm = new DecimalFormat("00"
;
DecimalFormat formatteryyyy = new DecimalFormat("0000"
;
String fromdate = formatterddmm.format(Integer.parseInt(txtFromD.getText())) + "/" + formatterddmm.format(Integer.parseInt(txtFromM.getText())) + "/" + formatteryyyy.format(Integer.parseInt(txtFromY.getText()));
String todate = formatterddmm.format(Integer.parseInt(txtToD.getText())) + "/" + formatterddmm.format(Integer.parseInt(txtToM.getText())) + "/" + formatteryyyy.format(Integer.parseInt(txtToY.getText()));
JFrame j = new JFrame("Party/Product/Price-Wise Sales Analysis For "+(String)txtState.getSelectedItem()+" From "+fromdate+" To "+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("Next"
;
previous = new JButton("Previous"
;
print = new JButton("Print Me"
;
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+""
;
}
}
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("JScroll",p);
// wml.writeToTextFileTestInt("P.Y",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 ("dd/MM/yyyy"
;
DecimalFormat numberformatter = new DecimalFormat("#0000.00"
;
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 ("Sales Analysis Party/Product/Price Wise For "+statename+" From "+fromdate+" To "+todate+" Page No. "+pagepart + "."+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("Party Name",10,155);
g.drawString("Town",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 = "";
//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("Total",800 - fm.stringWidth("Total"
,155);
double x1 = prod[0];
String x2= (Math.round(x1)+""
.trim();
g.drawString(x2,800 - fm.stringWidth(x2),y);
x1 = prod[1];
x2= (Math.round(x1)+""
.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("Total",800 - fm.stringWidth("Total"
,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)+""
.trim();
g.drawString(x2,800 - fm.stringWidth(x2),y);
//wr.writeToTextFile("Total3 :-"+x2);
x1 = prod[1];
x2 = (Math.round(x1)+""
.trim();
g.drawString(x2,800 - fm.stringWidth(x2),y+10);
//wr.writeToTextFile("Total4 :-"+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())+"",x - fm.stringWidth((int)Double.parseDouble(reportinfo[3].trim())+""
,y);
g.drawString((int)(Double.parseDouble(reportinfo[1].trim()) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ "",x - fm.stringWidth((int)(Double.parseDouble(reportinfo[1]) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ ""
,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("GRAND TOTAL :->",75 - fm.stringWidth("Grand Total :->"
,y+25);
g.drawString("Quantity:>",180 - fm.stringWidth("Quantity:>"
,y+25);
g.drawString(" Amount:>",180 - fm.stringWidth(" Amount:>"
,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)+""
.trim();
g.drawString(x2,x - fm.stringWidth(x2),y+25);
x1 = totalamt[col];
x2 = (Math.round(x1)+""
.trim();
g.drawString(x2,x - fm.stringWidth(x2),y+35);
//end of Vertical Total
if (pagepart==lastpart)
{
g.drawString(Math.round(gTotalQty)+"",800 - fm.stringWidth(Math.round(gTotalQty)+""
,y+25);
g.drawString(Math.round(gTotalAmt)+"",800 - fm.stringWidth(Math.round(gTotalAmt)+""
,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.
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 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()+"/"+txtFromD.getText()+"/"+txtFromY.getText(), txtToM.getText()+"/"+txtToD.getText()+"/"+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("Error","DataBase Error !!!", this);
return;
}
String state = "";
int nostates = 0;
for(int i = 0;i<analysisinfo.length;i++)
{
if (!state.equals(analysisinfo[4]))
{
nostates ++;
state = analysisinfo[4];
}
}
//System.out.println("States : "+ 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("Error",nostates +"DataBase Error !!!"+pagepart, this);
DecimalFormat formatterddmm = new DecimalFormat("00"
DecimalFormat formatteryyyy = new DecimalFormat("0000"
String fromdate = formatterddmm.format(Integer.parseInt(txtFromD.getText())) + "/" + formatterddmm.format(Integer.parseInt(txtFromM.getText())) + "/" + formatteryyyy.format(Integer.parseInt(txtFromY.getText()));
String todate = formatterddmm.format(Integer.parseInt(txtToD.getText())) + "/" + formatterddmm.format(Integer.parseInt(txtToM.getText())) + "/" + formatteryyyy.format(Integer.parseInt(txtToY.getText()));
JFrame j = new JFrame("Party/Product/Price-Wise Sales Analysis For "+(String)txtState.getSelectedItem()+" From "+fromdate+" To "+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("Next"
previous = new JButton("Previous"
print = new JButton("Print Me"
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+""
}
}
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("JScroll",p);
// wml.writeToTextFileTestInt("P.Y",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 ("dd/MM/yyyy"
DecimalFormat numberformatter = new DecimalFormat("#0000.00"
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 ("Sales Analysis Party/Product/Price Wise For "+statename+" From "+fromdate+" To "+todate+" Page No. "+pagepart + "."+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("Party Name",10,155);
g.drawString("Town",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 = "";
//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("Total",800 - fm.stringWidth("Total"
double x1 = prod[0];
String x2= (Math.round(x1)+""
g.drawString(x2,800 - fm.stringWidth(x2),y);
x1 = prod[1];
x2= (Math.round(x1)+""
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("Total",800 - fm.stringWidth("Total"
//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)+""
g.drawString(x2,800 - fm.stringWidth(x2),y);
//wr.writeToTextFile("Total3 :-"+x2);
x1 = prod[1];
x2 = (Math.round(x1)+""
g.drawString(x2,800 - fm.stringWidth(x2),y+10);
//wr.writeToTextFile("Total4 :-"+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())+"",x - fm.stringWidth((int)Double.parseDouble(reportinfo[3].trim())+""
g.drawString((int)(Double.parseDouble(reportinfo[1].trim()) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ "",x - fm.stringWidth((int)(Double.parseDouble(reportinfo[1]) * Double.parseDouble(reportinfo[3]) / Double.parseDouble(reportinfo[2]))+ ""
//}
}
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("GRAND TOTAL :->",75 - fm.stringWidth("Grand Total :->"
g.drawString("Quantity:>",180 - fm.stringWidth("Quantity:>"
g.drawString(" Amount:>",180 - fm.stringWidth(" Amount:>"
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)+""
g.drawString(x2,x - fm.stringWidth(x2),y+25);
x1 = totalamt[col];
x2 = (Math.round(x1)+""
g.drawString(x2,x - fm.stringWidth(x2),y+35);
//end of Vertical Total
if (pagepart==lastpart)
{
g.drawString(Math.round(gTotalQty)+"",800 - fm.stringWidth(Math.round(gTotalQty)+""
g.drawString(Math.round(gTotalAmt)+"",800 - fm.stringWidth(Math.round(gTotalAmt)+""
}
++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.