/* DBDataToolsExt - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
package com.coolservlets.beans.method;
import java.text.DecimalFormat;
import java.util.HashMap;

public class DBDataToolsExt extends DBDataTools
{
    public static String[][] formatCollect
            (String[][] data, String typecolum, String collectcolum)
            throws Exception {
        String[] aTypecolum = genMethod.split(typecolum, ",");
        String[] aCollectcolum = genMethod.split(collectcolum, ",");
        HashMap hmTotal = new HashMap();
        for (int j = 0; j < aCollectcolum.length; j++)
            hmTotal.put(aCollectcolum[j], new Double(0.0));
        String[][] data1 = null;
        int loop = data.length;
        int iAddColums = 0;
        int iAddRows = 0;
        String curstr = "";
        for (int i = 0; i < loop; i++) {
            iAddColums = data[i].length;
            String tcompstr = "";
            int tloop = aTypecolum.length;
            for (int t = 0; t < tloop; t++) {
                String ts = data[i][Integer.parseInt(aTypecolum[t])];
                tcompstr = new StringBuilder(tcompstr).append(ts).append
                        ("@@").toString();
            }
            if (!curstr.equalsIgnoreCase(tcompstr)) {
                iAddRows++;
                curstr = tcompstr;
            }
        }
        if (iAddRows == 0)
            return data;
        data1 = new String[loop + iAddRows][iAddColums];
        int it = loop + iAddRows;
        curstr = "";
        int row1 = 0;
        int xh = 1;
        for (int i = 0; i < loop; i++) {
            String tcompstr = "";
            int tloop = aTypecolum.length;
            for (int t = 0; t < tloop; t++) {
                String ts = data[i][Integer.parseInt(aTypecolum[t])];
                tcompstr = new StringBuilder(tcompstr).append(ts).append
                        ("@@").toString();
            }
            if (i == 0)
                curstr = tcompstr;
            if (!curstr.equalsIgnoreCase(tcompstr) && i > 0) {
                curstr = tcompstr;
                xh = 1;
                data1[row1][Integer.parseInt(aTypecolum[0])] = "\u5c0f\u8ba1";
                int floop = aCollectcolum.length;
                for (int f = 0; f < floop; f++) {
                    String putkey = aCollectcolum[f];
                    Double cost = (Double) hmTotal.get(putkey);
                    data1[row1][Integer.parseInt(putkey)] = cost.toString();
                    hmTotal.put(putkey, new Double(0.0));
                }
                row1++;
            }
            int kloop = data[i].length;
            for (int k = 0; k < kloop; k++) {
                data1[row1][k] = data[i][k];
                if (k == 0)
                    data1[row1][k] = String.valueOf(xh);
                int floop = aCollectcolum.length;
                for (int f = 0; f < floop; f++) {
                    String putkey = aCollectcolum[f];
                    if (k == Integer.parseInt(putkey)) {
                        double totalcost
                                = ((Double) hmTotal.get(putkey)).doubleValue();
                        double curcost
                                = Double.parseDouble(data[i]
                                [Integer.parseInt(putkey)]);
                        totalcost += curcost;
                        hmTotal.put(putkey, new Double(totalcost));
                    }
                }
            }
            row1++;
            xh++;
        }
        data1[row1][Integer.parseInt(aTypecolum[0])] = "\u5c0f\u8ba1";
        int floop = aCollectcolum.length;
        for (int f = 0; f < floop; f++) {
            String putkey = aCollectcolum[f];
            Double cost = (Double) hmTotal.get(putkey);
            data1[row1][Integer.parseInt(putkey)] = cost.toString();
            hmTotal.put(putkey, new Double(0.0));
        }
        return data1;
    }

    public static String formatFloat(String str) throws Exception {
        double cost = 0.0;
        DecimalFormat dfb = null;
        try {
            cost = Double.parseDouble(str);
            dfb = new DecimalFormat("#############.##");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return dfb.format(cost);
    }
}
