📄 creditsaleframe.java
字号:
actionCommand.equals("restoreSaleLedger") |
actionCommand.equals("sign")) {
int result = stockManagementData.isCurrentLedger(ledgerDate);
if(result == 0){
JOptionPane.showMessageDialog(null, ledgerDate + "是往期账套,不能进行添加、修改和撤消操作.");
return;
}
}
//检查销售单是否完成
if (actionCommand.equals("updateSaleLedger") |
actionCommand.equals("cancelSaleLedger") |
actionCommand.equals("restoreSaleLedger")|
actionCommand.equals("sign")) {
if(jList1.isSelectionEmpty()){
JOptionPane.showMessageDialog(null, "请选择销售单.");
return;
}
int selectedIndex = jList1.getSelectedIndex();
int onProcess = Integer.parseInt(saleLedgers[selectedIndex][9]);
if(onProcess == 2){
JOptionPane.showMessageDialog(null, saleLedgers[selectedIndex][0]
+ "销售单已经完成,不可以进行修改、撤消、恢复、电子签名操作.");
return;
}
}
//检查销售单是否撤消
if (actionCommand.equals("sign")) {
if(jList1.isSelectionEmpty()){
JOptionPane.showMessageDialog(null, "请选择销售单.");
return;
}
int selectedIndex = jList1.getSelectedIndex();
int onProcess = Integer.parseInt(saleLedgers[selectedIndex][9]);
if(onProcess == 1){
JOptionPane.showMessageDialog(null, saleLedgers[selectedIndex][0]
+ "销售单已经撤消,不可以进行电子签名操作.");
return;
}
}
if (actionCommand.equals("search")) {
//查询
search();
}else if(actionCommand.equals("createSaleLedger")){
action = "create";
this.clearSaleLedger();
this.checkBtn(true);
this.checkSubBtn(true);
}else if(actionCommand.equals("updateSaleLedger")){
action = "update";
this.checkBtn(true);
}else if(actionCommand.equals("cancelSaleLedger")){
action = "cancel";
this.checkBtn(true);
}else if(actionCommand.equals("restoreSaleLedger")){
action = "restore";
this.checkBtn(true);
}else if(actionCommand.equals("sign")){
action = "sign";
this.checkBtn(true);
}else if(actionCommand.equals("ok")){
//创建销售账套数据表的单个记录数组
String[] saleLedger = new String[11];
//取得销售单的值
saleLedger[1] = "1"; //1表示信用销售单
saleLedger[2] = jTextField5.getText().trim();
saleLedger[3] = jTextField9.getText().trim(); //柜台
saleLedger[4] = user.getUserName(); //信用销售员
saleLedger[5] = "";
saleLedger[6] = jTextField6.getText().trim(); //送货地址
saleLedger[7] = dataMethod.getCurrentDate().toString(); //填写日期
saleLedger[8] = null; //完成日期
saleLedger[9] = "0"; //完成状态
saleLedger[10] = jTextArea1.getText().trim();
if (action.equals("update") | action.equals("cancel") |
action.equals("restore") | action.equals("sign")) {
int selectedIndex = jList1.getSelectedIndex();
//取得原来的单据编号
saleLedger[0] = saleLedgers[selectedIndex][0].trim();
}
int result = 0;
if(action.equals("update") | action.equals("create")){
//检查销售单的客户
result = stockManagementData.checkCustomer(saleLedger[2]);
if(result == 0){
JOptionPane.showMessageDialog(null, saleLedger[2] + "在客户数据库中"
+ "不存在,请打开客户数据管理窗口添加.");
return;
}
//检查销售单的柜台名字
result = stockManagementData.checkWarehouse(saleLedger[3]);
if(result == 0){
JOptionPane.showMessageDialog(null, saleLedger[3] + "在仓库数据库中"
+ "不存在,请打开仓库数据管理窗口添加.");
return;
}
//检查商品条形码
result = this.checkSaleSubLedgerGoodsBarCode();
if(result == 0) return;
//检查销售单明细账的商品数量是否小于等于库存数
result = this.checkStockQuantity();
if(result == 0) return;
//重新计算卖出金额
this.recountGoodsAmount();
double amount = Double.parseDouble(jTextField13.getText());
//检客户的信用限额
result = stockManagementData.checkCustomerCreditLimit(saleLedger[2], amount);
if(result == 0){
JOptionPane.showMessageDialog(null, saleLedger[2] + "的信用额度不够.");
return;
}
//转换表格数组
this.transferTableData();
}
if(action.equals("create")){
//检查明细账是否为空
if(saleSubLedgerObjects.length == 0){
JOptionPane.showMessageDialog(null, "明细账数据表为空,不可以创建销售单.");
return;
}
//添加销售单
result = stockManagementData.createSaleLedgerAndSub(ledgerDate,
saleLedger, saleSubLedgers);
if(result == 1){
JOptionPane.showMessageDialog(null, "销售单添加成功,请重新执行查询操作显示新的销售单.");
}else{
JOptionPane.showMessageDialog(null, "销售单添加失败,请检查输入值是否大于字段范围.");
}
}else if (action.equals("update")){
//修改销售单
result = stockManagementData.updateSaleLedgerAndSub(ledgerDate,
saleLedger, saleSubLedgers);
if(result == 1){
JOptionPane.showMessageDialog(null, "销售单修改成功.");
//更新数组的数据
int selectedIndex = jList1.getSelectedIndex();
for(int i = 0; i < 11; i++){
saleLedgers[selectedIndex][i] = saleLedger[i];
}
}else{
JOptionPane.showMessageDialog(null, "销售单修改失败,请检查输入值是否大于字段范围.");
}
}else if (action.equals("cancel")){
//撤消销售单
result = stockManagementData.signSaleLedgerAndSub(ledgerDate, "creditUser", user.getUserName(),
saleLedger[0], 1, saleLedger[10]);
if(result == 1){
JOptionPane.showMessageDialog(null, "销售单撤消成功.");
//更新完成状态编辑框的值
jTextField12.setText(onProcesses[1]);
//更新数组的数据
int selectedIndex = jList1.getSelectedIndex();
saleLedgers[selectedIndex][9] = "1";
saleLedgers[selectedIndex][10] = saleLedger[10];
}else{
JOptionPane.showMessageDialog(null, "销售单撤消失败.");
}
}else if (action.equals("restore")){
//恢复销售单
result = stockManagementData.signSaleLedgerAndSub(ledgerDate, "creditUser", user.getUserName(),
saleLedger[0], 0, saleLedger[10]);
if(result == 1){
JOptionPane.showMessageDialog(null, "销售单恢复成功.");
//更新完成状态编辑框的值
jTextField12.setText(onProcesses[0]);
//更新数组的数据
int selectedIndex = jList1.getSelectedIndex();
saleLedgers[selectedIndex][9] = "0";
saleLedgers[selectedIndex][10] = saleLedger[10];
}else{
JOptionPane.showMessageDialog(null, "销售单恢复失败.");
}
}else if (action.equals("sign")){
int selectedIndex = jList1.getSelectedIndex();
//对销售单进行电子签名
result = stockManagementData.creditUserSignSaleLedgerAndSub(ledgerDate,
user.getUserName(), saleLedger[10], saleLedgers[selectedIndex][3],
saleLedgers[selectedIndex][0], saleLedgers[selectedIndex][2]);
if(result == 1){
JOptionPane.showMessageDialog(null, "电子签名成功.");
//更新完成状态编辑框的值
jTextField12.setText(onProcesses[2]);
//更新数组的数据
saleLedgers[selectedIndex][9] = "2";
saleLedgers[selectedIndex][10] = saleLedger[10];
}else{
JOptionPane.showMessageDialog(null, "电子签名失败.");
}
}
this.checkSubBtn(false);
this.checkBtn(false);
}else if(actionCommand.equals("cancel")){
this.jList1_valueChanged(null);
this.checkBtn(false);
this.checkSubBtn(false);
}else if(actionCommand.equals("printSaleOrder")){
int selectedIndex = jList1.getSelectedIndex();
if(selectedIndex == -1){
JOptionPane.showMessageDialog(null, "先选择销售单.");
return;
}
//取得选择销售单的数据
String[] saleLedger = new String[11];
for(int i = 0; i < saleLedger.length; i++){
if(saleLedgers[selectedIndex][i] == null){
saleLedger[i] = "";
}else{
saleLedger[i] = saleLedgers[selectedIndex][i];
}
}
//取得销售单的明细账数据
String[][] saleSubLedgerForPrint = new String[saleSubLedgerObjects.length][4];
for(int i = 0; i < saleSubLedgers.length; i++){
saleSubLedgerForPrint[i][0] = (String)saleSubLedgerObjects[i][2];
saleSubLedgerForPrint[i][1] = ((Double)saleSubLedgerObjects[i][5]).toString();
saleSubLedgerForPrint[i][2] = ((Integer)saleSubLedgerObjects[i][6]).toString();
saleSubLedgerForPrint[i][3] = ((Double)saleSubLedgerObjects[i][7]).toString();
}
//显示销售单打印窗口
if(saleOrderPrintFrame == null){
saleOrderPrintFrame = new SaleOrderPrintFrame();
//使窗口居中对齐
setCenterPosition(saleOrderPrintFrame);
saleOrderPrintFrame.setVisible(true);
}else{
saleOrderPrintFrame.setVisible(true);
}
//为打印窗口传入数组参数
saleOrderPrintFrame.setSaleLedger(saleLedger);
saleOrderPrintFrame.setSaleSubLedger(saleSubLedgerForPrint);
//显示总页码
saleOrderPrintFrame.splitPage();
}else if(actionCommand.equals("printAccountReceivable")){
int selectedIndex = jList1.getSelectedIndex();
if(selectedIndex == -1){
JOptionPane.showMessageDialog(null, "先选择销售单.");
return;
}
//取得销售单标识和完成状态
String saleId = saleLedgers[selectedIndex][0];
int onProcess = Integer.parseInt(saleLedgers[selectedIndex][9]);
if(onProcess != 2){
JOptionPane.showMessageDialog(null, "销售单未完成,不能打印应付票据.");
return;
}
//根据销售单标识取得往来账数组
String[] currentAccountLedger = stockManagementData.
getCurrentAccountLedgerBylinkId(ledgerDate, "sa" + saleId);
for(int i = 0; i < currentAccountLedger.length; i++){
if(currentAccountLedger[i] == null){
if(i == 9){
currentAccountLedger[i] = "0";
}else{
currentAccountLedger[i] = "";
}
}
}
//显示应收票据打印窗口
if(accountReceivablePrintFrame == null){
accountReceivablePrintFrame = new AccountReceivablePrintFrame();
//使窗口居中对齐
setCenterPosition(accountReceivablePrintFrame);
accountReceivablePrintFrame.setVisible(true);
}else{
accountReceivablePrintFrame.setVisible(true);
}
//为打印窗口传入数组参数
accountReceivablePrintFrame.setCurrentAccountLedger(currentAccountLedger);
//显示应收票据内容
accountReceivablePrintFrame.showOnePage();
}else if(actionCommand.equals("createSub")){
//为销售账套明细表添加一个空行
int objectsLength = saleSubLedgerObjects.length;
Object[][] tempObjs = new Object[objectsLength + 1][8];
System.arraycopy(saleSubLedgerObjects, 0, tempObjs, 0, objectsLength);
tempObjs[objectsLength][0] = new Integer(0);
tempObjs[objectsLength][1] = new String("");
tempObjs[objectsLength][2] = new String("");
tempObjs[objectsLength][3] = new Double(0); //销售价
tempObjs[objectsLength][4] = new Double(0); //折扣
tempObjs[objectsLength][5] = new Double(0); //实际售价
tempObjs[objectsLength][6] = new Integer(0); //数量
tempObjs[objectsLength][7] = new Double(0); //金额
saleSubLedgerObjects = tempObjs;
this.showTableData(saleSubLedgerObjects);
}else if(actionCommand.equals("deleteSub")){
if(jTable1.getSelectedRowCount() == 0){
JOptionPane.showMessageDialog(null, "请选择明细记录.");
return;
}
//删除选择的记录
int selectedIndex = jTable1.getSelectedRow();
Object[][] tempObjs = new Object[saleSubLedgerObjects.length - 1][8];
int line = 0;
for(int i = 0; i < saleSubLedgerObjects.length; i++){
if(i == selectedIndex){
continue;
}else{
for(int j = 0; j < 8; j++){
tempObjs[line][j] = saleSubLedgerObjects[i][j];
}
line++;
}
}
saleSubLedgerObjects = tempObjs;
this.showTableData(saleSubLedgerObjects);
}else if(actionCommand.equals("exit")){
exit();
}
}
//使窗口居中的方法
public void setCenterPosition(JFrame frame){
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -