Jump to content


Photo

มีมาให้ติชม กันอีกแล้ว TableExcel Account Ledger โปรแกรม ครับผม เชิญท่านอาจารย์ ชี้แนะครับ


This topic has been archived. This means that you cannot reply to this topic.
5 ความเห็นในกระทู้นี้

#1 ทรงธรรม

ทรงธรรม

    ต่อให้ต้องเรียนจนแก่ ก็จะเรียนต่อไป คนเราพัฒนาได้ทุกคน

  • Members
  • PipPipPip
  • 2,157 posts

ตอบ 4 เมษายน พ.ศ. 2556 - 15:13

import java.awt.*;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
import java.util.TreeSet;
import java.util.Set;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class TableExcel4 extends JPanel {
	private JTable tableExcel;
	private JTextField fileNameText;
	private JButton choose;
	private JLabel fileChoose;
	private boolean DEBUG;
	private String fileName;
	private JTextField result1, result2, result3, result4, result5, result6,
			result7;
	private static Object[] result = new Object[7];
	private JButton send;
	private JLabel ledNo;
	private JTextField ledNoText;
	private JButton submit;
	private Set<Led01> gl = new TreeSet<Led01>();
	private static Object[] inv = new Object[7];
	private JButton sendInv;
	private static JTextArea selected;
	private JTextArea area1, area2, area3, area4, area5, area6;
	private final static String newline = "\n";
	private List<JTextArea> totalArea = new ArrayList<>();
	private static int count;
	private JComboBox selectPrint;
	private JLabel selectP;
	private JButton print;

	public TableExcel4() {
		setLayout(new GridLayout(3, 1));
		MyTableModel model = new MyTableModel();
		tableExcel = new JTable(model);
		tableExcel.setRowSorter(new TableRowSorter(model));
		ListSelectionModel lsm = tableExcel.getSelectionModel();
		lsm.addListSelectionListener(new ListSelectionListener() {

			public void valueChanged(ListSelectionEvent e) {
				if (e.getValueIsAdjusting())
					return;

				ListSelectionModel lsm = (ListSelectionModel) e.getSource();
				int first = lsm.getMinSelectionIndex();
				int last = lsm.getMaxSelectionIndex();
				int row = tableExcel.getSelectedRow();
				int col = tableExcel.getSelectedColumnCount();
				if (((last - first) == 0) && (col == 7)) {
					for (int i = 0; i < col; i++) {
						result[i] = tableExcel.getValueAt(row, i);
					}
				}
				System.out.println((last - first) + " " + col);

			}

		});
		tableExcel.setPreferredScrollableViewportSize(new Dimension(500, 70));
		tableExcel.setFillsViewportHeight(true);
		tableExcel.setCellSelectionEnabled(true);

		// Create the scroll pane and add the table to it.
		JScrollPane scrollPane = new JScrollPane(tableExcel);

		// Add the scroll pane to this panel.
		add(scrollPane);
		fileNameText = new JTextField(20);
		choose = new JButton("O.K.");
		choose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fileName = fileNameText.getText();
				ReadCSV(fileName);
			}
		});
		fileChoose = new JLabel("File Name");
		fileChoose.setLabelFor(fileNameText);
		result1 = new JTextField(15);
		result2 = new JTextField(15);
		result3 = new JTextField(15);
		result4 = new JTextField(15);
		result5 = new JTextField(15);
		result6 = new JTextField(15);
		result7 = new JTextField(15);
		JPanel panel = new JPanel();
		panel.add(fileChoose);
		panel.add(fileNameText);
		panel.add(choose);
		panel.add(result1);
		panel.add(result2);
		panel.add(result3);
		JPanel panel1 = new JPanel();
		panel1.add(result4);
		panel1.add(result5);
		panel1.add(result6);
		panel1.add(result7);
		send = new JButton("Send");
		send.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				result1.setText(result[0].toString());
				result2.setText(result[1].toString());
				result3.setText(result[2].toString());
				result4.setText(result[3].toString());
				String original = result[4].toString();
				String trunk = original.replace(".0", "");
				result5.setText(trunk);
				result6.setText(result[5].toString());
				result7.setText(result[6].toString());

			}
		});
		panel1.add(send);

		JPanel panel2 = new JPanel();
		sendInv = new JButton("send to Inv");
		sendInv.addActionListener(new ActionListener() {
			boolean ensure = false;

			public void actionPerformed(ActionEvent arg0) {
				inv[0] = result1.getText();
				inv[1] = result2.getText();
				inv[2] = result3.getText();
				inv[3] = result4.getText();
				inv[4] = result5.getText();
				inv[5] = result6.getText();
				inv[6] = result7.getText();
				Limit01 lm = new Limit01(inv, gl);
				ensure = lm.limitAll();
				Called01 ca = new Called01(inv, gl);
				Led01 temLed = ca.callTo();
				temLed.passLedger(ensure, inv);
				for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
					Led01 showLed = it.next();
					String[] showArea = showLed.showLedgerAll();
					String show = "";

					for (Iterator<JTextArea> ita = totalArea.iterator(); ita
							.hasNext();) {
						JTextArea tem = ita.next();
						if (tem.getAccessibleContext().getAccessibleName() == showLed
								.toString()) {
							for (int i = 0; i < showArea.length; i++) {

								show += showArea[i];
							}
							tem.setText(show);
						}
					}

				}

			}

		});
		ledNo = new JLabel("set LedNo");
		ledNoText = new JTextField(10);
		ledNo.setLabelFor(ledNoText);
		submit = new JButton("submit");
		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String led = ledNoText.getText();
				gl.add(new Led01(led));

				JTextArea tem = totalArea.get(count++);
				tem.getAccessibleContext().setAccessibleName(led);
				selectPrint.addItem(led);
				System.out.println(tem.getAccessibleContext()
						.getAccessibleName());
				for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
					Led01 temp = it.next();
					System.out.println(temp);

				}
			}

		});
		selectPrint = new JComboBox();
		selectPrint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JComboBox cb = (JComboBox) e.getSource();
				String accName = (String) cb.getSelectedItem();
				for (Iterator<JTextArea> ita = totalArea.iterator(); ita
						.hasNext();) {
					JTextArea tem = ita.next();
					if (tem.getAccessibleContext().getAccessibleName() == accName) {
						selected = tem;
					}
				}
			}

		});
		selectP = new JLabel("select to Print");
		selectP.setLabelFor(selectPrint);
		print = new JButton("Print");
		print.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String select = selected.getAccessibleContext()
						.getAccessibleName();
				for (Iterator<JTextArea> ita = totalArea.iterator(); ita
						.hasNext();) {
					JTextArea tem = ita.next();
					if (tem.getAccessibleContext().getAccessibleName() == select) {
						try {
						    boolean complete = tem.print();
						    if (complete) {
						        /* show a success message  */
						        
						    } else {
						        /*show a message indicating that printing was cancelled */
						        
						    }
						} catch (PrinterException pe) {
						    /* Printing failed, report to the user */
						    
						}
					}
				}
			}

		});
		panel2.add(sendInv);
		panel2.add(ledNo);
		panel2.add(ledNoText);
		panel2.add(submit);
		panel2.add(selectP);
		panel2.add(selectPrint);
		panel2.add(print);
		JPanel panel3 = new JPanel();
		panel3.setLayout(new GridLayout(2, 3));
		area1 = new JTextArea(5, 10);
		JScrollPane sPane = new JScrollPane(area1);
		panel3.add(sPane);
		area2 = new JTextArea(5, 10);
		sPane = new JScrollPane(area2);
		panel3.add(sPane);
		area3 = new JTextArea(5, 10);
		sPane = new JScrollPane(area3);
		panel3.add(sPane);
		area4 = new JTextArea(5, 10);
		sPane = new JScrollPane(area4);
		panel3.add(sPane);
		area5 = new JTextArea(5, 10);
		sPane = new JScrollPane(area5);
		panel3.add(sPane);
		area6 = new JTextArea(5, 10);
		sPane = new JScrollPane(area6);
		panel3.add(sPane);
		totalArea.add(area1);
		totalArea.add(area2);
		totalArea.add(area3);
		totalArea.add(area4);
		totalArea.add(area5);
		totalArea.add(area6);

		JPanel bpane = new JPanel();

		bpane.setLayout(new GridLayout(3, 1));
		bpane.add(panel);
		bpane.add(panel1);
		bpane.add(panel2);
		add(bpane);
		add(panel3);
	}

	public void ReadCSV(String fileName) {
		MyTableModel model = (MyTableModel) tableExcel.getModel();
		try {

			// ..
			FileInputStream file = new FileInputStream(fileName);
			// Get the workbook instance for XLS file
			HSSFWorkbook workbook = new HSSFWorkbook(file);
			// Get first sheet from the workbook
			HSSFSheet sheet = workbook.getSheetAt(0);
			// Get iterator to all the rows in current sheet
			Iterator rowIter = sheet.iterator();
			while (rowIter.hasNext()) {
				HSSFRow myRow = (HSSFRow) rowIter.next();
				model.addRow(myRow);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class MyTableModel extends DefaultTableModel {
		private String[] columnNames = { "Invoice No.", "Date", "Description",
				"Vendor", "Account No.", "Debit", "Credit" };
		private Object[][] data;

		public int getColumnCount() {
			return columnNames.length;
		}

		public void addRow(HSSFRow row) {
			Iterator cellIter = row.cellIterator();
			Vector<Object> cellStoreVector = new Vector<>();
			while (cellIter.hasNext()) {
				HSSFCell myCell = (HSSFCell) cellIter.next();
				cellStoreVector.addElement(myCell);
			}
			addRow(cellStoreVector);
		}

		public String getColumnName(int col) {
			return columnNames[col];
		}

		/*
		 * Don't need to implement this method unless your table's editable.
		 */
		public boolean isCellEditable(int row, int col) {
			// Note that the data/cell address is constant,
			// no matter where the cell appears onscreen.
			if (col < 2) {
				return false;
			} else {
				return true;
			}
		}

		/*
		 * Don't need to implement this method unless your table's data can
		 * change.
		 */
		public void setValueAt(Object value, int row, int col) {
			if (DEBUG) {
				System.out.println("Setting value at " + row + "," + col
						+ " to " + value + " (an instance of "
						+ value.getClass() + ")");
			}

			data[row][col] = value;
			fireTableCellUpdated(row, col);

			if (DEBUG) {
				System.out.println("New value of data:");
				printDebugData();
			}
		}

		private void printDebugData() {
			int numRows = getRowCount();
			int numCols = getColumnCount();

			for (int i = 0; i < numRows; i++) {
				System.out.print("    row " + i + ":");
				for (int j = 0; j < numCols; j++) {
					System.out.print("  " + data[i][j]);
				}
				System.out.println();
			}
			System.out.println("--------------------------");
		}
	}

	/**
	 * Create the GUI and show it. For thread safety, this method should be
	 * invoked from the event-dispatching thread.
	 */
	private static void createAndShowGUI() {
		// Create and set up the window.
		JFrame frame = new JFrame("TableExcel");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Create and set up the content pane.
		TableExcel4 newContentPane = new TableExcel4();
		newContentPane.setOpaque(true); // content panes must be opaque
		frame.setContentPane(newContentPane);

		// Display the window.
		frame.pack();
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		// Schedule a job for the event-dispatching thread:
		// creating and showing this application's GUI.
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}

}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class Led01 implements Comparable<Led01> {
	String led;
	List<Double> left = new ArrayList<>();
	List<Double> right = new ArrayList<>();
	List<Object[]> sum = new ArrayList<Object[]>();
	private final static String newline = "\n";
	public Led01(String input) {
		
		led = input;
	}

	public boolean testForName(String input) {

		return (input.equals(led));
	}

	public void addListLeft(Double b1, boolean en) {
		if (en)
			left.add(b1);
	}

	public void addListRight(Double b1, boolean en) {
		if (en)
			right.add(b1);
	}
	public Double takeBF(int index){
		Double suml = 0.0;
		Double sumr = 0.0;
		Double sumb = 0.0;
		suml = left.get(index);
		sumr = right.get(index);
		if(index<=0){
			sumb = 0.0;
		}else if(index>0){
		sumb = takeBF(index-1);
		}
		return (suml - sumr + sumb);
	
	}

	public Double takeBalance(int index,Double sumb) {

		Double suml = 0.0;
		Double sumr = 0.0;
		
		suml = left.get(index);
		sumr = right.get(index);
		return (suml - sumr + sumb);
	}

	public String showLedgerLine(int index) {
		String outline = null;
		//int suml = 0;
		//int sumr = 0;
		//suml = left.get(index);
			//System.out.print(suml + "    ");
		//sumr = right.get(index);
		
			//System.out.print(sumr + "    ");
		Double result = (index==0)?0:takeBF(index-1);
		outline = Double.toString((takeBalance(index,result)));
		return outline;
	}

	public String toString() {
		return led;
	}

	public void passLedger(boolean en, Object[] inv) {
		Object [] sum = null;
		if (en) {
			boolean ensure = testForName((String) inv[4]);
			addListLeft(Double.parseDouble(inv[5].toString()), ensure);
			addListRight(Double.parseDouble(inv[6].toString()), ensure);
			sum = new Object[7];
			System.arraycopy(inv, 0, sum, 0, inv.length);
			
		}
		this.sum.add(sum);
	}
	//public void addSum(Object []o){
		//sum.add(o);
	//}
	//public void showSum(){
		//for (Iterator<Object[]> it = sum.iterator(); it.hasNext(); ){
			//Object[] temp = it.next();
			//for(int i = 0;i<temp.length;i++){
				//System.out.print(temp[i] + "  ");
			//}
		//}
	//}
	public String showInvoice(Object [] o){
		String outlook = "";
		for(int i = 0;i<o.length;i++ ){
		outlook += (o[i] + "  ");
		}
		return outlook;
	}
	public void sortSum(List<Object[]> ob){
		Collections.sort(ob,new Comparator<Object[]>() {
            public int compare(Object[] strings, Object[] otherStrings) {
                return ((String) strings[1]).compareTo
                		((String) otherStrings[1]);
            }
        });
	}
	public String[] showLedgerAll(){
		String ledname = toString()+newline;
		String [] outlooks = new String[7];
		sortSum(sum);
		for(int j=0;j<outlooks.length;j++){
			outlooks[j]= "";
		}
		Object[] temp = left.toArray();
		for(int i =0;i<temp.length;i++){
			Object[] obtem = sum.get(i);
			String outlook = showInvoice(obtem)+"   ";
			System.out.println("outlook"+outlook);
			String outline = showLedgerLine(i)+newline;
			System.out.println("outline" +outline);
			outlooks[i] = outlook+outline;
		}
		
		return outlooks;
	}

	@Override
	public int compareTo(Led01 other) {
		int last = new Integer(Integer.parseInt(this.led)).compareTo(new Integer
				(Integer.parseInt(other.led)));
		return last;
	}
	

}





import java.util.Iterator;
import java.util.Set;
public class Called01 {
	Object[] b1;
	Set<Led01> gl;
	public Called01(Object[] b,Set<Led01> g){
		b1 = b;
		gl = g;
	}
	public Led01 callTo(){
		String temp = (String)b1[4];
		Led01 sure = null;
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
		if(temp.equals(l.toString())){
		 sure = l;
		}
		}
		if(sure==null){
			System.out.println("Not in Ledger List");
		}
		return sure;
	}
}

import java.util.TreeSet;
import java.util.Iterator;
import java.util.Set;
public class Limit01 {
	Object[] line;
	Set<Led01> gl = new TreeSet<Led01>();

	public Limit01(Object[] l, Set<Led01> g) {
		line = l;
		gl = g;

	}

	public boolean limitString(String input) {

		int i = 0;
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
			if (input.equals(l.toString())) {
				i++;
			}
		}
		if (i == 1) {
			return true;
		} else {
			System.out.println("Not in Ledger list");
			return false;

		}

	}

	public boolean limitDouble(Double l, Double r) {
		if (l < 0 || l > 1000000000 || r < 0 || r > 1000000000) {
			return false;
		} else {
			return true;
		}
	}

	public boolean limitAll() {

		boolean chk = limitString((String) line[4]);
		boolean chk1 = limitDouble(
				Double.parseDouble(line[5].toString()), 
				Double.parseDouble(line[6].toString()));
		return (chk && chk1);
	}
}

 


ขอให้พวกเรา ชาวหลากสี และพันธมิตร จงมีชีวิตรอด จากภาวะเศรษฐกิจตกต่ำ ฝีมือปูนา ไปตลอดรอดฝั่งด้วยครับ

 

PEMDAS ย่อมาจาก ลำดับการคำนวณ Parentheses , Exponentials , Multiply , Divide , Add , Subtract

 

FWGHSO ย่อมาจาก ลำดับการประเมินผลของ query  FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY


#2 ทรงธรรม

ทรงธรรม

    ต่อให้ต้องเรียนจนแก่ ก็จะเรียนต่อไป คนเราพัฒนาได้ทุกคน

  • Members
  • PipPipPip
  • 2,157 posts

ตอบ 4 เมษายน พ.ศ. 2556 - 15:29

อะแฮ่ม เป็น โปรแกรม ที่เรียก file จาก excel ที่ใช้บันทึกบัญชีครับ

 

แต่ข้อแม้คือ ใน excel ต้อง key ตามหัวข้อครับ เรียงเป็นคอลัมน์ นะครับ

 

1. เลขที่ INV 2. วันที่ 3 รายการ 4 ลูกค้า 5 เลขที่บัญชี 6 จำนวนเงินเดบิต 7 จำนวนเงินเครดิต

 

ถ้าจำนวนเงินเดบิต หรือ เครดิต ด้านใด เป็น ศูนย์ ให้ใส่ ศูนย์ ด้วยครับ

 

 

วิธีการใช้ เบื้องต้น ต้องทำการ set เลขที่บัญชี ก่อนนะครับ ที่ ช่องว่าง set ledNo แล้วกด submit

 

แต่อนุญาต ให้แค่ 6 เลขที่บัญชีครับ เพราะผมมีพื้นที่แสดงแค่ 6 ช่อง ฮ่า ๆ ลองดู เฉย ๆ ครับ

 

(ยังทำ database ไม่เป็น ไม่งั้น ได้เยอะกว่านี้ แน่นอนครับ)

 

 

หลังจากนั้น ทำการพิมพ์ ชื่อ file excel ในช่อง File Name นะครับ อย่าลืมว่า ใน java ตัว \ (backslash) ต้องเบิ้ลเป็น \\ นะครับ

 

แล้วกด ok แล้ว file ใน excel จะมาปรากฎ ใน table ข้างบน ครับ

 

 

แล้ว ให้เราเลือก บรรทัด ที่จะทำการผ่านบัญชี ไปยัง บัญชีที่ เรา submit ไปก่อนหน้านี้ ให้ดูที่ ตรง combobox จะปรากฎ ชื่อบัญชี

 

ที่เราใส่เข้าไปครับ ถ้ายังไม่ submit ให้ submit ก่อนครับ

 

 

การเลือกบรรทัด ทำโดย ใช้ mouse คลิกที่ คอลัมน์แรก แล้วใช้ shift แล้ว กด ขวาเลือกไปจนสุด เน้น ต้องสุดเท่านั้น

 

แล้วต้อง (อันนี้จำเป็น ถึงดูไร้สาระก็เหอะ)  ยังกด shift อยู่นะ เลื่อนลง มา 1 บรรทัด แล้วเลื่อนกลับขึ้นไป อยู่ที่บรรทัดเดียว เหมือนเดิม

 

พูดง่าย ๆ เลือกได้ บรรทัดเดียวล่ะ (แต่มัน ต้องทำงี่เง่า แบบที่บอก เพราะ ไม่งั้นจะ error)

 

อ้ออออ  แต่ถ้า ใช้ mouse drag (คือกดค้าง แล้วลาก น่ะแหล่ะ) ไม่จำเป็นต้องทำงี่เง่า แบบใช้ ลูกศร บนคีย์บอร์ด อะ

 

เอ่อ ไม่รู้เพราะอะไร ทีใช้ mouse เครื่องดัน ตรวจจับได้ตามปกติ

 

 

หลัีงจากนั้น กด send

 

แล้วข้อมูลจะมาปรากฎ บน ช่องว่าง ทั้ง 7

 

แล้วถึง จะกด send to inv เพื่อผ่านไปยัง บัญชี แยกประเภทได้ครับ (ช่องว่างใหญ่ 6 ช่อง นั่นแหละ)

 

ก็ทำตามขั้นตอน เลือกบรรทัด ใน table ไปเรื่อย ๆ นะครับ (อย่าเลือกซ้ำนะ เพราะผมยัง เซนเซอร์ ไม่ให้ซ้ำ ไม่ได้)

 

พอ ผ่านบัญชี ไปยัง ช่องว่าง ใหญ่ เรียบร้อยแล้ว

 

 

ก็จะสามารถ สั่ง print ได้โดย เลือก เลขที่บัญชี จาก combobox (ได้ 6 บัญชี) แล้วกด print ครับผม

 

 

ปล. การเลือกบรรทัด ไม่จำเป็นต้องเรียงลำดับ นะครับ อันไหน เผลอข้ามแล้ว ย้อนกลับมาใหม่ได้

 

ไม่ต้องกลัว เพราะผม สั่งให้มัน sort ตาม เลขที่ inv อยู่แล้ว ครับ

 

ปล. 2 เลือก file ได้มากกว่า 1 file นะครับ

 

ถ้าเลือก file ที่สอง ที่สาม .... มันจะต่อกับอันแรก ไปเรื่อย ๆ ครับ (น่าจะได้เรื่อย ๆ นะ)

 

แล้ว สำหรับ บรรทัดใน ช่องว่างใหญ่ ผมทำให้มันบรรจุได้แค่ 7 บรรทัด

 

ถ้าจะเปลี่ยน ไปแก้ที่ code ใน class Led01

 

method showLedgerAll() บรรทัด ที่สอง

 

String [] outlooks = new String[7];

 

อันนี้ ให้แก้เป็น ตัวเลขที่ต้องการ แทน 7 ละกัน ฮับ


Edited by ทรงธรรม, 4 เมษายน พ.ศ. 2556 - 16:17.

ขอให้พวกเรา ชาวหลากสี และพันธมิตร จงมีชีวิตรอด จากภาวะเศรษฐกิจตกต่ำ ฝีมือปูนา ไปตลอดรอดฝั่งด้วยครับ

 

PEMDAS ย่อมาจาก ลำดับการคำนวณ Parentheses , Exponentials , Multiply , Divide , Add , Subtract

 

FWGHSO ย่อมาจาก ลำดับการประเมินผลของ query  FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY


#3 ทรงธรรม

ทรงธรรม

    ต่อให้ต้องเรียนจนแก่ ก็จะเรียนต่อไป คนเราพัฒนาได้ทุกคน

  • Members
  • PipPipPip
  • 2,157 posts

ตอบ 4 เมษายน พ.ศ. 2556 - 16:02

ถ้ากรณี อยากเพิ่ม ช่องว่างใหญ่ ที่ใช้ผ่านบัญชี ก็ทำได้ครับ

 

โดยการ declare     JTextArea เพิ่มเป็น area 7 area 8 and so on.. (ฮี่ ๆ ล่อภาษาปะกิต)

 

แล้วทำการ instantiate มันโดย เช่น area7 = new JTextArea(5,10); (5 บรรทัด 10 คอลัมน์ น่ะแหละ)

 

แล้วทำการ บรรจุลงใน JScrollPane นะครับ โดย

 

JScrollPane sPane = new JScrollPane(area7); (สมมุติใส่ area7 เข้าไป ก็เพื่อให้มันสามารถ scroll ลงไปดู ที่มันไม่โผล่ในจอได้ครับ)

 

แล้วอย่าลืมทำการ เติม area ที่เพิ่มเข้าไปใน List <JTextArea> นะครับ โดยใส่ว่า

 

totalArea.add(area7); (เป็นการบรรจุใส่ไว้ใน List เพื่อมันจะได้ ควานหา บัญชี แยกประเภท ให้เราถูกครับ)

 

อ้อ ถ้าเพิ่ม หลาย area ควรเพิ่ม JPanel ไปรองรับมันนะครับ

 

ก็โดย JPanel panel4 = new JPanel();

 

panel4.setLayout(new GridLayout(1,3)) ; (คือ ให้ panel นี้บรรจุ scrollpane ได้ 3 คอลัมน์ 1 แนวนอน  แต่จะเพิ่มจำนวนแนวนอน ก็ได้นะครับ)

 

แล้วสุดท้าย ก็ทำการ add เข้าไป ใน contentpane โดยการ

 

add(panel4);

 

เอ้อ เกือบลืม จุดสำคัญ ต้องทำการ แก้ค่า ตรงที่ setLayout ตรงจุดเริ่มต้นของ constructor ให้เป็น

 

public TableExcel4() {
        setLayout(new GridLayout(4, 1));

 

 

นะครับ ไม่งั้น เดี๋ยวไอ้ที่ เรา add panel4 จะไม่โผล่ แฮ่ม


Edited by ทรงธรรม, 4 เมษายน พ.ศ. 2556 - 16:03.

ขอให้พวกเรา ชาวหลากสี และพันธมิตร จงมีชีวิตรอด จากภาวะเศรษฐกิจตกต่ำ ฝีมือปูนา ไปตลอดรอดฝั่งด้วยครับ

 

PEMDAS ย่อมาจาก ลำดับการคำนวณ Parentheses , Exponentials , Multiply , Divide , Add , Subtract

 

FWGHSO ย่อมาจาก ลำดับการประเมินผลของ query  FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY


#4 ทรงธรรม

ทรงธรรม

    ต่อให้ต้องเรียนจนแก่ ก็จะเรียนต่อไป คนเราพัฒนาได้ทุกคน

  • Members
  • PipPipPip
  • 2,157 posts

ตอบ 5 เมษายน พ.ศ. 2556 - 13:42

import java.awt.*;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
import java.util.TreeSet;
import java.util.Set;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class TableExcel6 extends JPanel {
	private JTable tableExcel;
	private JTextField fileNameText;
	private JButton choose;
	private JLabel fileChoose;
	private boolean DEBUG;
	private String fileName;
	private JTextField result1, result2, result3, result4, result5, result6,
			result7;
	private static Object[] result = new Object[7];
	private JButton send;
	private JLabel ledNo;
	private JTextField ledNoText;
	private JButton submit;
	private Set<Led01> gl = new TreeSet<Led01>();
	private static Object[] inv = new Object[7];
	private JButton sendInv;
	private static JTextArea selected;
	private JTextArea area1, area2, area3, area4, area5, area6;
	private final static String newline = "\n";
	private List<JTextArea> totalArea = new ArrayList<>();
	private static int count;
	private JComboBox selectPrint;
	private JLabel selectP;
	private JButton print;
	private JButton limitTwo;
	private JButton open;
	private JFileChooser fc;
	public TableExcel6() {
		setLayout(new GridLayout(3, 1));
		MyTableModel model = new MyTableModel();
		tableExcel = new JTable(model);
		tableExcel.setRowSorter(new TableRowSorter(model));
		ListSelectionModel lsm = tableExcel.getSelectionModel();
		lsm.addListSelectionListener(new ListSelectionListener() {

			public void valueChanged(ListSelectionEvent e) {
				if (e.getValueIsAdjusting())
					return;

				ListSelectionModel lsm = (ListSelectionModel) e.getSource();
				
				int col = tableExcel.getSelectedColumnCount();
				int first = lsm.getMinSelectionIndex();
				int last = lsm.getMaxSelectionIndex();
				int row = tableExcel.getSelectedRow();
				if (((last - first) == 0) && (col == 7)) {
					for (int i = 0; i < col; i++) {
						result[i] = tableExcel.getValueAt(row, i);
					}
				}
				System.out.println((last - first) + " " + col);

			}

		});
		tableExcel.setPreferredScrollableViewportSize(new Dimension(500, 70));
		tableExcel.setFillsViewportHeight(true);
		tableExcel.setCellSelectionEnabled(true);

		// Create the scroll pane and add the table to it.
		JScrollPane scrollPane = new JScrollPane(tableExcel);

		// Add the scroll pane to this panel.
		add(scrollPane);
		open = new JButton("Open file");
		open.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				int returnVal = fc.showOpenDialog(TableExcel6.this);
				 
	            if (returnVal == JFileChooser.APPROVE_OPTION) {
	                File file = fc.getSelectedFile();
	                fileNameText.setText(file.getAbsolutePath());
	            }
			}
			
		});
		fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		JPanel panel0 = new JPanel();
		
		panel0.add(open);
		fileNameText = new JTextField(20);
		choose = new JButton("O.K.");
		choose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fileName = fileNameText.getText();
				ReadCSV(fileName);
			}
		});
		fileChoose = new JLabel("File Name");
		fileChoose.setLabelFor(fileNameText);
		result1 = new JTextField(15);
		result2 = new JTextField(15);
		result3 = new JTextField(15);
		result4 = new JTextField(15);
		result5 = new JTextField(15);
		result6 = new JTextField(15);
		result7 = new JTextField(15);
		JPanel panel = new JPanel();
		panel.add(fileChoose);
		panel.add(fileNameText);
		panel.add(choose);
		panel.add(result1);
		panel.add(result2);
		panel.add(result3);
		JPanel panel1 = new JPanel();
		panel1.add(result4);
		panel1.add(result5);
		panel1.add(result6);
		panel1.add(result7);
		send = new JButton("Send");
		send.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				result1.setText(result[0].toString());
				result2.setText(result[1].toString());
				result3.setText(result[2].toString());
				result4.setText(result[3].toString());
				String original = result[4].toString();
				String trunk = original.replace(".0", "");
				result5.setText(trunk);
				result6.setText(result[5].toString());
				result7.setText(result[6].toString());

			}
		});
		limitTwo = new JButton("check duplicated");
		limitTwo.addActionListener(new ActionListener(){
			boolean test;
			Object[] options = {"Yes,delete existing","No,cancelled it"};
			public void actionPerformed(ActionEvent arg0) {
				inv[0] = result1.getText();
				inv[1] = result2.getText();
				inv[2] = result3.getText();
				inv[3] = result4.getText();
				inv[4] = result5.getText();
				inv[5] = result6.getText();
				inv[6] = result7.getText();
				LimitTwo lmt = new LimitTwo(gl,inv);
				test = lmt.testTwo();
				System.out.println(inv[0]+" "+ inv[4]+" "+test);
				String s = "";
				int index = 0;
				Double le = null;
				Double ri = null;
				int inle = 0;
				int inri = 0;
				if(!test){
					Object[] tem = lmt.getDuplicated();
					int select = JOptionPane.showOptionDialog(TableExcel6.this,
							"Duplicated Invoice please select way",
							"Way for duplicated", JOptionPane.YES_NO_OPTION, 
							JOptionPane.QUESTION_MESSAGE, null,
							options, options[0]);
					if(select==JOptionPane.YES_OPTION){
						for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
							Led01 l = it.next();
							List<Object[]> lob = l.sum;
							for(Iterator<Object[]> ito = lob.iterator();ito.hasNext();){
								Object[] ob = ito.next();
								if(ob.equals(tem)){
									s = l.toString();
									index = lob.indexOf(ob);
									le = (Double)Double.parseDouble(ob[5].toString());
									ri = (Double)Double.parseDouble(ob[6].toString());
									inle = l.left.indexOf(le);
									inri = l.right.indexOf(ri);
									System.out.println(s + " " + index
											+" " + le + " " + ri
											+" " + inle + " " +inri);
								}
							}
						}
						for(Iterator<Led01> it = gl.iterator(); it.hasNext();) {
							Led01 l = it.next();
							if(l.toString().equals(s)){
							List<Object[]> lob = l.sum;
							lob.remove(index);
							
							l.left.remove(inle);
							l.right.remove(inri);
							}
						}	
						
					}else if(select==JOptionPane.NO_OPTION){
						JOptionPane.showMessageDialog(TableExcel6.this, 
								"Please select new transaction.", 
							"Cancelled transaction", JOptionPane.INFORMATION_MESSAGE);
					}
				}
			}
			
		});
		panel1.add(send);
		panel1.add(limitTwo);

		JPanel panel2 = new JPanel();
		sendInv = new JButton("send to Inv");
		sendInv.addActionListener(new ActionListener() {
			boolean ensure = false;

			public void actionPerformed(ActionEvent arg0) {
				
				Limit01 lm = new Limit01(inv, gl);
				ensure = lm.limitAll();
				Called01 ca = new Called01(inv, gl);
				Led01 temLed = ca.callTo();
				temLed.passLedger(ensure, inv);
				for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
					Led01 showLed = it.next();
					String[] showArea = showLed.showLedgerAll();
					String show = "";

					for (Iterator<JTextArea> ita = totalArea.iterator(); ita
							.hasNext();) {
						JTextArea tem = ita.next();
						if (tem.getAccessibleContext().getAccessibleName() == showLed
								.toString()) {
							for (int i = 0; i < showArea.length; i++) {

								show += showArea[i];
							}
							tem.setText(show);
						}
					}

				}

			}

		});
		ledNo = new JLabel("set LedNo");
		ledNoText = new JTextField(10);
		ledNo.setLabelFor(ledNoText);
		submit = new JButton("submit");
		submit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String led = ledNoText.getText();
				gl.add(new Led01(led));

				JTextArea tem = totalArea.get(count++);
				tem.getAccessibleContext().setAccessibleName(led);
				selectPrint.addItem(led);
				System.out.println(tem.getAccessibleContext()
						.getAccessibleName());
				for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
					Led01 temp = it.next();
					System.out.println(temp);

				}
			}

		});
		selectPrint = new JComboBox();
		selectPrint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JComboBox cb = (JComboBox) e.getSource();
				String accName = (String) cb.getSelectedItem();
				for (Iterator<JTextArea> ita = totalArea.iterator(); ita
						.hasNext();) {
					JTextArea tem = ita.next();
					if (tem.getAccessibleContext().getAccessibleName() == accName) {
						selected = tem;
					}
				}
			}

		});
		selectP = new JLabel("select to Print");
		selectP.setLabelFor(selectPrint);
		print = new JButton("Print");
		print.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String select = selected.getAccessibleContext()
						.getAccessibleName();
				for (Iterator<JTextArea> ita = totalArea.iterator(); ita
						.hasNext();) {
					JTextArea tem = ita.next();
					if (tem.getAccessibleContext().getAccessibleName() == select) {
						try {
						    boolean complete = tem.print();
						    if (complete) {
						        /* show a success message  */
						        
						    } else {
						        /*show a message indicating that printing was cancelled */
						        
						    }
						} catch (PrinterException pe) {
						    /* Printing failed, report to the user */
						    
						}
					}
				}
			}

		});
		panel2.add(sendInv);
		panel2.add(ledNo);
		panel2.add(ledNoText);
		panel2.add(submit);
		panel2.add(selectP);
		panel2.add(selectPrint);
		panel2.add(print);
		JPanel panel3 = new JPanel();
		panel3.setLayout(new GridLayout(2, 3));
		area1 = new JTextArea(5, 10);
		JScrollPane sPane = new JScrollPane(area1);
		panel3.add(sPane);
		area2 = new JTextArea(5, 10);
		sPane = new JScrollPane(area2);
		panel3.add(sPane);
		area3 = new JTextArea(5, 10);
		sPane = new JScrollPane(area3);
		panel3.add(sPane);
		area4 = new JTextArea(5, 10);
		sPane = new JScrollPane(area4);
		panel3.add(sPane);
		area5 = new JTextArea(5, 10);
		sPane = new JScrollPane(area5);
		panel3.add(sPane);
		area6 = new JTextArea(5, 10);
		sPane = new JScrollPane(area6);
		panel3.add(sPane);
		totalArea.add(area1);
		totalArea.add(area2);
		totalArea.add(area3);
		totalArea.add(area4);
		totalArea.add(area5);
		totalArea.add(area6);

		JPanel bpane = new JPanel();

		bpane.setLayout(new GridLayout(4, 1));
		bpane.add(panel0);
		bpane.add(panel);
		bpane.add(panel1);
		bpane.add(panel2);
		add(bpane);
		add(panel3);
	}

	public void ReadCSV(String fileName) {
		MyTableModel model = (MyTableModel) tableExcel.getModel();
		try {

			// ..
			FileInputStream file = new FileInputStream(fileName);
			// Get the workbook instance for XLS file
			HSSFWorkbook workbook = new HSSFWorkbook(file);
			// Get first sheet from the workbook
			HSSFSheet sheet = workbook.getSheetAt(0);
			// Get iterator to all the rows in current sheet
			Iterator rowIter = sheet.iterator();
			while (rowIter.hasNext()) {
				HSSFRow myRow = (HSSFRow) rowIter.next();
				model.addRow(myRow);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class MyTableModel extends DefaultTableModel {
		private String[] columnNames = { "Invoice No.", "Date", "Description",
				"Vendor", "Account No.", "Debit", "Credit" };
		private Object[][] data;

		public int getColumnCount() {
			return columnNames.length;
		}

		public void addRow(HSSFRow row) {
			Iterator cellIter = row.cellIterator();
			Vector<Object> cellStoreVector = new Vector<>();
			while (cellIter.hasNext()) {
				HSSFCell myCell = (HSSFCell) cellIter.next();
				cellStoreVector.addElement(myCell);
			}
			addRow(cellStoreVector);
		}

		public String getColumnName(int col) {
			return columnNames[col];
		}

		/*
		 * Don't need to implement this method unless your table's editable.
		 */
		public boolean isCellEditable(int row, int col) {
			// Note that the data/cell address is constant,
			// no matter where the cell appears onscreen.
			if (col < 2) {
				return false;
			} else {
				return true;
			}
		}

		/*
		 * Don't need to implement this method unless your table's data can
		 * change.
		 */
		public void setValueAt(Object value, int row, int col) {
			if (DEBUG) {
				System.out.println("Setting value at " + row + "," + col
						+ " to " + value + " (an instance of "
						+ value.getClass() + ")");
			}

			data[row][col] = value;
			fireTableCellUpdated(row, col);

			if (DEBUG) {
				System.out.println("New value of data:");
				printDebugData();
			}
		}

		private void printDebugData() {
			int numRows = getRowCount();
			int numCols = getColumnCount();

			for (int i = 0; i < numRows; i++) {
				System.out.print("    row " + i + ":");
				for (int j = 0; j < numCols; j++) {
					System.out.print("  " + data[i][j]);
				}
				System.out.println();
			}
			System.out.println("--------------------------");
		}
	}

	/**
	 * Create the GUI and show it. For thread safety, this method should be
	 * invoked from the event-dispatching thread.
	 */
	private static void createAndShowGUI() {
		// Create and set up the window.
		JFrame frame = new JFrame("TableExcel");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Create and set up the content pane.
		TableExcel6 newContentPane = new TableExcel6();
		newContentPane.setOpaque(true); // content panes must be opaque
		frame.setContentPane(newContentPane);

		// Display the window.
		frame.pack();
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		// Schedule a job for the event-dispatching thread:
		// creating and showing this application's GUI.
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});
	}

}

import java.util.TreeSet;
import java.util.Iterator;
import java.util.Set;
public class Limit01 {
	Object[] line;
	Set<Led01> gl = new TreeSet<Led01>();

	public Limit01(Object[] l, Set<Led01> g) {
		line = l;
		gl = g;

	}

	public boolean limitString(String input) {

		int i = 0;
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
			if (input.equals(l.toString())) {
				i++;
			}
		}
		if (i == 1) {
			return true;
		} else {
			System.out.println("Not in Ledger list");
			return false;

		}

	}

	public boolean limitDouble(Double l, Double r) {
		if (l < 0 || l > 1000000000 || r < 0 || r > 1000000000) {
			return false;
		} else {
			return true;
		}
	}

	public boolean limitAll() {

		boolean chk = limitString((String) line[4]);
		boolean chk1 = limitDouble(
				Double.parseDouble(line[5].toString()), 
				Double.parseDouble(line[6].toString()));
		return (chk && chk1);
	}
}

import java.util.TreeSet;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
public class LimitTwo {
	Set<Led01> gl = new TreeSet<Led01>();
	Object[] line;
	public LimitTwo(Set<Led01> g,Object[] l){
		gl = g;
		line = l;
	}
	public boolean testTwo(){
		boolean test = false;
		int count = 0;
		System.out.println(line[0]+" "+line[4]);
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
			if(l.sum.isEmpty()){
				++count;
			}else{
			List<Object[]> lob = l.sum;
			
			for(Iterator<Object[]> ito = lob.iterator();ito.hasNext();){
				Object[] ob = ito.next();
				System.out.println(ob[0]+" "+ob[4]);
				
				if(ob[0].toString().equals(line[0].toString())&&
						ob[4].toString().equals(line[4].toString())){
					test = false;
					break;
				}else{
					test = true;
				}
				
			}
			if(!test)break;
			}
		}
		int gsize = gl.size();
		if(count==gsize){
			test = true;
		}
		return test;
	}
	public Object[] getDuplicated(){
		Object[] tem = new Object[7];
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
			List<Object[]> lob = l.sum;
			for(Iterator<Object[]> ito = lob.iterator();ito.hasNext();){
				Object[] ob = ito.next();
				if(ob[0].toString().equals(line[0].toString())&&
						ob[4].toString().equals(line[4].toString())){
					tem = ob;
				}
			}
		}	
		return tem;
	}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

public class Led01 implements Comparable<Led01> {
	String led;
	List<Double> left = new ArrayList<>();
	List<Double> right = new ArrayList<>();
	List<Object[]> sum = new ArrayList<Object[]>();
	private final static String newline = "\n";
	public Led01(String input) {
		
		led = input;
	}

	public boolean testForName(String input) {

		return (input.equals(led));
	}

	public void addListLeft(Double b1, boolean en) {
		if (en)
			left.add(b1);
	}

	public void addListRight(Double b1, boolean en) {
		if (en)
			right.add(b1);
	}
	public Double takeBF(int index){
		Double suml = 0.0;
		Double sumr = 0.0;
		Double sumb = 0.0;
		suml = left.get(index);
		sumr = right.get(index);
		if(index<=0){
			sumb = 0.0;
		}else if(index>0){
		sumb = takeBF(index-1);
		}
		return (suml - sumr + sumb);
	
	}

	public Double takeBalance(int index,Double sumb) {

		Double suml = 0.0;
		Double sumr = 0.0;
		
		suml = left.get(index);
		sumr = right.get(index);
		return (suml - sumr + sumb);
	}

	public String showLedgerLine(int index) {
		String outline = null;
		//int suml = 0;
		//int sumr = 0;
		//suml = left.get(index);
			//System.out.print(suml + "    ");
		//sumr = right.get(index);
		
			//System.out.print(sumr + "    ");
		Double result = (index==0)?0:takeBF(index-1);
		outline = Double.toString((takeBalance(index,result)));
		return outline;
	}

	public String toString() {
		return led;
	}

	public void passLedger(boolean en, Object[] inv) {
		Object [] sum = null;
		if (en) {
			boolean ensure = testForName((String) inv[4]);
			addListLeft(Double.parseDouble(inv[5].toString()), ensure);
			addListRight(Double.parseDouble(inv[6].toString()), ensure);
			sum = new Object[7];
			System.arraycopy(inv, 0, sum, 0, inv.length);
			
		}
		this.sum.add(sum);
	}
	
	public String showInvoice(Object [] o){
		String outlook = "";
		for(int i = 0;i<o.length;i++ ){
		outlook += (o[i] + "  ");
		}
		return outlook;
	}
	public void sortSum(List<Object[]> ob){
		Collections.sort(ob,new Comparator<Object[]>() {
            public int compare(Object[] strings, Object[] otherStrings) {
            	
                return ((String) strings[1]).compareTo
                		((String) otherStrings[1]);
            }
        });
	}
	public boolean objectCorrespondList(List<Double> ld,List<Double> ld1){
		boolean test = false;
		int countl = 0;
		int startl = 0;
		int startr = 0;
		for(Iterator<Object[]> it = sum.iterator();it.hasNext();){
			Object[] tem = it.next();
			Object ob= tem[5];
			Object obr= tem[6];
			if(ld.get(startl++).equals((Double)Double.parseDouble(ob.toString()))
					&&ld1.get(startr++).equals((Double)Double.parseDouble(obr.toString()))){
				++countl;
			}
		}
		int sSize = sum.size();
		if(countl==sSize){
			test = true;
		}else{
			test = false;
		}
		return test;
	}
	public void swapList(List<Double> ld,List<Double> ld1){
		
		if(!objectCorrespondList(ld,ld1)){
			ld.clear();
			ld1.clear();
			for(Iterator<Object[]> it = sum.iterator();it.hasNext();){
				Object[] tem = it.next();
				Object obl= tem[5];
				Object obr= tem[6];
				Double le = (Double)Double.parseDouble(obl.toString());
				Double ri = (Double)Double.parseDouble(obr.toString());
				ld.add(le);
				ld1.add(ri);
			}
		}else{
			return;
		}
	}
	public String[] showLedgerAll(){
		String ledname = toString()+newline;
		String [] outlooks = new String[7];
		sortSum(sum);
		swapList(left,right);
		for(int j=0;j<outlooks.length;j++){
			outlooks[j]= "";
		}
		Object[] temp = left.toArray();
		for(int i =0;i<temp.length;i++){
			Object[] obtem = sum.get(i);
			String outlook = showInvoice(obtem)+"   ";
			//System.out.println("outlook"+outlook);
			String outline = showLedgerLine(i)+newline;
			//System.out.println("outline" +outline);
			outlooks[i] = outlook+outline;
		}
		
		return outlooks;
	}

	@Override
	public int compareTo(Led01 other) {
		int last = new Integer(Integer.parseInt(this.led)).compareTo(new Integer
				(Integer.parseInt(other.led)));
		return last;
	}
	

}





import java.util.Iterator;
import java.util.Set;
public class Called01 {
	Object[] b1;
	Set<Led01> gl;
	public Called01(Object[] b,Set<Led01> g){
		b1 = b;
		gl = g;
	}
	public Led01 callTo(){
		String temp = (String)b1[4];
		Led01 sure = null;
		for (Iterator<Led01> it = gl.iterator(); it.hasNext();) {
			Led01 l = it.next();
		if(temp.equals(l.toString())){
		 sure = l;
		}
		}
		if(sure==null){
			System.out.println("Not in Ledger List");
		}
		return sure;
	}
}


ขอให้พวกเรา ชาวหลากสี และพันธมิตร จงมีชีวิตรอด จากภาวะเศรษฐกิจตกต่ำ ฝีมือปูนา ไปตลอดรอดฝั่งด้วยครับ

 

PEMDAS ย่อมาจาก ลำดับการคำนวณ Parentheses , Exponentials , Multiply , Divide , Add , Subtract

 

FWGHSO ย่อมาจาก ลำดับการประเมินผลของ query  FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY


#5 ทรงธรรม

ทรงธรรม

    ต่อให้ต้องเรียนจนแก่ ก็จะเรียนต่อไป คนเราพัฒนาได้ทุกคน

  • Members
  • PipPipPip
  • 2,157 posts

ตอบ 5 เมษายน พ.ศ. 2556 - 13:48

มากันอีกแล้วครับ คราวนี้ เป็น เวอร์ชั่น 2

 

ที่พัฒนา จาก เวอร์ชั่น แรก คือเพิ่ม ความสามารถ ไปอีก 2 อย่าง

 

1. สามารถ เลือก file จาก คอมของเรา ด้วย ปุ่ม open file เพิ่มขึ้นมา กดแล้ว ให้เลือก file ได้เลย

 

พอเลือกได้แล้ว จะโชว์ ชื่อ file ใน ช่องว่าง เอง ก็กด ok ต่อ ได้เลยนะครับ

 

2. สามารถ ตรวจจับ ข้อมูล บรรทัด ที่ซ้ำกันได้แล้วนะครับ

 

โดยก่อนกดปุ่ม send to inv ให้กด ปุ่ม check to duplicate ก่อนนะครับ

 

ถ้าซ้ำ จะขึ้นให้เลือก ลบบรรทัดนี้ ที่มีอยู่ใน แยกประเภท (JTextArea) หรือไม่

 

ถ้าเลือกใช่ ให้ลบ ข้อมูลบรรทัดนี้ จะถูกลบ (แต่ยังไม่โชว์ จนกว่า จะทำการเลือก ข้อมูล ต่อไป แล้วกด send to inv เรียบร้อยแล้ว)

 

ถ้าไม่เลือก ลบ ให้กด No แล้ว ก็จะมีข้อความเตือน ให้ เืลือก ข้อมูล บรรทัดใหม่ นะครับ


ขอให้พวกเรา ชาวหลากสี และพันธมิตร จงมีชีวิตรอด จากภาวะเศรษฐกิจตกต่ำ ฝีมือปูนา ไปตลอดรอดฝั่งด้วยครับ

 

PEMDAS ย่อมาจาก ลำดับการคำนวณ Parentheses , Exponentials , Multiply , Divide , Add , Subtract

 

FWGHSO ย่อมาจาก ลำดับการประเมินผลของ query  FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY


#6 เคนอิจิ-นามิ

เคนอิจิ-นามิ

    สมาชิกขั้นสูง

  • Banned
  • PipPipPipPip
  • 4,447 posts

ตอบ 10 เมษายน พ.ศ. 2556 - 21:43

มากันอีกแล้วครับ คราวนี้ เป็น เวอร์ชั่น 2

ที่พัฒนา จาก เวอร์ชั่น แรก คือเพิ่ม ความสามารถ ไปอีก 2 อย่าง

1. สามารถ เลือก file จาก คอมของเรา ด้วย ปุ่ม open file เพิ่มขึ้นมา กดแล้ว ให้เลือก file ได้เลย

พอเลือกได้แล้ว จะโชว์ ชื่อ file ใน ช่องว่าง เอง ก็กด ok ต่อ ได้เลยนะครับ

2. สามารถ ตรวจจับ ข้อมูล บรรทัด ที่ซ้ำกันได้แล้วนะครับ

โดยก่อนกดปุ่ม send to inv ให้กด ปุ่ม check to duplicate ก่อนนะครับ

ถ้าซ้ำ จะขึ้นให้เลือก ลบบรรทัดนี้ ที่มีอยู่ใน แยกประเภท (JTextArea) หรือไม่

ถ้าเลือกใช่ ให้ลบ ข้อมูลบรรทัดนี้ จะถูกลบ (แต่ยังไม่โชว์ จนกว่า จะทำการเลือก ข้อมูล ต่อไป แล้วกด send to inv เรียบร้อยแล้ว)

ถ้าไม่เลือก ลบ ให้กด No แล้ว ก็จะมีข้อความเตือน ให้ เืลือก ข้อมูล บรรทัดใหม่ นะครับ

ผมมีหนังสือดีๆ (แต่โครตจะเก่า) อยู่สองเล่ม
นอนอยู่ชั้นใต้สุดของตู้หนังสือ
รอวันจะได้เจ้าของใหม่

หนังสือจาวา ภาษาไทย แต่น่าจะเวอร์ชั่น 1-2 เลยมั้ง :D
แต่น่าจะดูเป็นแนวได้

ส่วน datastructure เป็นอะไรที่ทึกคน"ต้องรู้"
แต่อยู่ในรูป ภาษา ซี และเป็นภาษาอังกฤษทั้งเล่ม
คิดว่าน่าจะอ่านได้อยู่ เป็นพื้นฐานตั้งแต่ array stac sort รวมถึง recursive เป็นแค่ส่วนจ้อยของมัน

ทั้งสองเล่มเก่าแล้ว ถ้าคุณคิดว่า มันจะยังพอมีประโยชน์ ส่งที่อยู่มา จะส่งไปให้ครับ
เผื่อจะได้อ่านตอนหยุดสงกรานต์นี้ (ถ้าไม่ไปเที่ยวไหนนะ)

Edited by เคนอิจิ-นามิ, 10 เมษายน พ.ศ. 2556 - 21:44.

ตรรกของผมที่แตกต่างจากสมาชิกคนอื่นใน สรท นิ๊ดเดียว  :D http://webboard.seri...e-3#entry634878

รอแมงวันหน้าสันขวานดิ้นดุ๊กดิ้กมาขอขมาอยู่นะ http://webboard.seri...-แวร์/?p=609037

ความตอแหลขอไอ้แมงวัน  http://webboard.seri...-แวร์/?p=609177