私は新しい月であるかどうかをチェックするコードを比較する日付を書いていて、毎月の最初の日付から655,000にバランスをリセットします。コードは現在の日付がisn次の月の1日と同じで、現在の月が次の月と等しくない場合、からその月の最初の取引を引きます。今すぐすぐに新しい(654,900)、私は(654900-(2回目の取引の合計費用))として2番目の取引の後に残高を保存したいと思うし、スイートに従うべきであることを意味する以降の取引ではまでcurrentday = 1とnextmonth、新しい月の最初の日のための最初のトランザクションを再起動します全体のプロセスは、その総コストはから減算した他のすべてのトランザクションは、その後スイート日付で月単位のエントリをリセットする方法
をたどる==現在の月私のデータベースこの出力イムexpecting.I'm洙簡潔ない説明のために非常に残念以前
**CustomerID||InvoiceID||BalanceDate ||ChequeSum||CreditSum||CashSum||ReversalSum||Balance**
201743112026 10286202 2017-04-18 13:12:01 100.0 0.0 0.0 0.0 654900 (655000-100)
201743112021 10476202 2017-04-18 13:12:09 609.0 0.0 0.0 0.0 654291 (654900-100)
private void dayCount() {
Date theDate = new Date();
Calendar myCal = new GregorianCalendar();
myCal.setTime(theDate);
int currentDay = myCal.get(Calendar.DAY_OF_MONTH);
int currentMonth = myCal.get(Calendar.MONTH) + 1;
int currentYear = myCal.get(Calendar.YEAR);
int nextday = currentDay + 1;
int nextMonth = currentMonth + 1;
int tempMonth = currentMonth;
System.out.println("Day: " + currentDay);
System.out.println("Month: " + currentMonth);
System.out.println("Year: " + currentYear);
System.out.println("nextday: " + nextday);
System.out.println("nextMonth: " + nextMonth);
System.out.println("tempMonth: " + tempMonth);
if (currentDay != 1 && currentMonth == tempMonth && currentMonth != nextMonth) {
if (counts == 0) {// count returns zero if no tranction has occured so deduction starts frim 655000
if (countz == 0) {// countz returns 0 if no cash,credit or cheque transaction has been computed yet and 1 if vice versa
System.out.println("counts value is " + counts);
FirstEntry();
}
} else if (counts == 1) {
if (countz != 0) {
System.out.println("counts value is " + counts);
LatterEntry();
}
}
} else {
FirstEntry();
}
}
/* currentRBalance returns cuurent balance in database */
private void FirstEntry() {
transT = transType.getSelectedItem().toString();
if (transT.equals("Cash")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, "" + 0.00);
ps.setString(5, "" + 0.00);
ps.setString(6, ovrallT.getText());
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (655000.0 - Double.parseDouble(invtotal.getText())));
ps.execute();
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 1 " + e.getMessage());
}
} else if (transT.equals("Cheque")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, "" + ovrallT.getText());
ps.setString(5, "" + 0.00);
ps.setString(6, "" + 0.00);
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (655000.0 - Double.parseDouble(invtotal.getText())));
ps.execute();
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 2 " + e.getMessage());
}
} else if (transT.equals("Credit")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, "" + 0.00);
ps.setString(5, "" + ovrallT.getText());
ps.setString(6, "" + 0.00);
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (655000.0 - Double.parseDouble(invtotal.getText())));
ps.execute();
countz++;
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 3 " + e.getMessage());
}
}
countz++;
}
private void LatterEntry() {
transT = transType.getSelectedItem().toString();
if (transT.equals("Cash")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, "" + 0.00);
ps.setString(5, "" + 0.00);
ps.setString(6, ovrallT.getText());
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (myCurrentRBalance - Double.parseDouble(invtotal.getText())));
ps.execute();
InvDate = ((JTextField) invDate.getDateEditor().getUiComponent()).getText();
System.out.println(invDate + "------");
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 4" + e.getMessage());
}
} else if (transT.equals("Credit")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, ovrallT.getText());
ps.setString(5, "" + 0.00);
ps.setString(6, "" + 0.00);
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (myCurrentRBalance - Double.parseDouble(invtotal.getText())));
ps.execute();
InvDate = ((JTextField) invDate.getDateEditor().getUiComponent()).getText();
System.out.println(invDate + "------");
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 5 " + e.getMessage());
}
} else if (transT.equals("Credit")) {
try { // actual crud functions can be undertaken
stmt = DBConnection.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
con = DBConnection.getConnection();
String sql;
sql = "insert into reducingbalances (CustomerID, InvoiceID, BalanceDate, ChequeSum, CreditSum, CashSum, ReversalSum, Balance) values (?,?,?,?,?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, code);
ps.setString(2, cusInv.getSelectedItem().toString());
ps.setString(3, ((JTextField) invDate.getDateEditor().getUiComponent()).getText());
ps.setString(4, "" + 0.00);
ps.setString(5, ovrallT.getText());
ps.setString(6, "" + 0.00);
ps.setString(7, "" + 0.00);
ps.setString(8, "" + (myCurrentRBalance - Double.parseDouble(invtotal.getText())));
ps.execute();
InvDate = ((JTextField) invDate.getDateEditor().getUiComponent()).getText();
System.out.println(invDate + "------");
JOptionPane.showMessageDialog(this, "Record saved successfully");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Unable to insert record 6 " + e.getMessage());
}
}
}
コードにインデントを修正してもよろしいですか? –
訂正ありがとう – jaYjaY
私は正確に何をしようとしているのか分かりませんでした。あなたはあなたの質問を編集して、入力と予想される出力の例を追加してください。 –