📄 frm_add_edit_salesrep.java
字号:
JLContNo.setBounds(5,182,105,20);
JLContNo.setFont(new Font("Dialog",Font.PLAIN,12));
JTFContNo.setBounds(110,182,200,20);
JTFContNo.setFont(new Font("Dialog",Font.PLAIN,12));
JPContainer.add(JLContNo);
JPContainer.add(JTFContNo);
//-- Add Contact Number Input Field
JLEmerContName.setBounds(5,204,105,20);
JLEmerContName.setFont(new Font("Dialog",Font.PLAIN,12));
JTFEmerContName.setBounds(110,204,200,20);
JTFEmerContName.setFont(new Font("Dialog",Font.PLAIN,12));
JPContainer.add(JLEmerContName);
JPContainer.add(JTFEmerContName);
//-- Add E-mail Address Input Field
JLEmerContNo.setBounds(5,226,105,20);
JLEmerContNo.setFont(new Font("Dialog",Font.PLAIN,12));
JTFEmerContNo.setBounds(110,226,200,20);
JTFEmerContNo.setFont(new Font("Dialog",Font.PLAIN,12));
JPContainer.add(JLEmerContNo);
JPContainer.add(JTFEmerContNo);
//******************** End adding of input field
//-- Add the JBUpdate
JBUpdate.setBounds(5,270,105,25);
JBUpdate.setFont(new Font("Dialog", Font.PLAIN, 12));
JBUpdate.setMnemonic(KeyEvent.VK_A);
JBUpdate.addActionListener(JBActionListener);
JBUpdate.setActionCommand("update");
JPContainer.add(JBUpdate);
//-- Add the JBReset
JBReset.setBounds(112,270,99,25);
JBReset.setFont(new Font("Dialog", Font.PLAIN, 12));
JBReset.setMnemonic(KeyEvent.VK_R);
JBReset.addActionListener(JBActionListener);
JBReset.setActionCommand("reset");
JPContainer.add(JBReset);
//-- Add the JBCancel
JBCancel.setBounds(212,270,99,25);
JBCancel.setFont(new Font("Dialog", Font.PLAIN, 12));
JBCancel.setMnemonic(KeyEvent.VK_C);
JBCancel.addActionListener(JBActionListener);
JBCancel.setActionCommand("cancel");
JPContainer.add(JBCancel);
getContentPane().add(JPContainer);
setSize(325,335);
setResizable(false);
setLocation((screen.width - 325)/2,((screen.height-335)/2));
}
private boolean RequiredFieldEmpty(){
if(JTFId.getText().equals("") || JTFName.getText().equals("") || JTFAddr.getText().equals("")){
JOptionPane.showMessageDialog(null,"Some required fields is/are empty.\nPlease check it and try again.","Naparansoft Inventory System",JOptionPane.WARNING_MESSAGE);
JTFId.requestFocus();
return true;
}else{
return false;
}
}
private void clearFields(){
JTFId.setText("");
JTFName.setText("");
JTFAddr.setText("");
JTFCity.setText("");
JTFStateProv.setText("");
JTFZipCode.setText("");
JTFContNo.setText("");
JTFEmerContName.setText("");
JTFEmerContNo.setText("");
}
ActionListener JBActionListener = new ActionListener(){
public void actionPerformed(ActionEvent e){
String srcObj = e.getActionCommand();
if(srcObj=="update"){
if(RequiredFieldEmpty()==false){
if(ADDING_STATE == true){
try{
stAES.executeUpdate("INSERT INTO tblSalesRep (SalesRepID,Name,Address,CityTown,StateProvince,ZipCode,ContactNo,EmerContactNo,EmerContactName) " +
"VALUES ('" +
JTFId.getText() + "', '" +
JTFName.getText() + "', '" +
JTFAddr.getText() + "', '" +
JTFCity.getText() + "', '" +
JTFStateProv.getText() + "', '" +
JTFZipCode.getText() + "', '" +
JTFContNo.getText() + "', '" +
JTFEmerContNo.getText() + "', '" +
JTFEmerContName.getText() +
"')");
// Start Display the new record
int total =0;
total = clsPublicMethods.getMaxNum("SELECT * FROM tblSalesRep ORDER BY SalesRepIndex ASC",cnAES,"SalesRepIndex");
if(total != 0){
FrmSalesRep.reloadRecord("SELECT * FROM tblSalesRep WHERE SalesRepIndex = " + total + " ORDER BY Name ASC");
}else{
FrmSalesRep.reloadRecord("SELECT * FROM tblSalesRep ORDER BY Name ASC");
}
total =0;
// End Display the new record
JOptionPane.showMessageDialog(null,"New record has been successfully added.","Naparansoft Inventory System",JOptionPane.INFORMATION_MESSAGE);
String ObjButtons[] = {"Yes","No"};
int PromptResult = JOptionPane.showOptionDialog(null,"Do you want add another record?","Naparansoft Inventory System",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE,null,ObjButtons,ObjButtons[0]);
if(PromptResult==0){
clearFields();
JTFId.requestFocus(true);
}else{
dispose();
}
}catch(SQLException sqlEx){
System.out.println(sqlEx.getMessage());
}
}else{
try{
String RowIndex;
RowIndex = rsAES.getString("SalesRepIndex");
stAES.executeUpdate("UPDATE tblSalesRep SET SalesRepID = '" +
JTFId.getText() + "', Name = '" +
JTFName.getText() + "', Address = '" +
JTFAddr.getText() + "', CityTown = '" +
JTFCity.getText() + "', StateProvince = '" +
JTFStateProv.getText() + "', ZipCode = '" +
JTFZipCode.getText() + "', ContactNo = '" +
JTFContNo.getText() + "', EmerContactNo = '" +
JTFEmerContNo.getText() + "', EmerContactName = '" +
JTFEmerContName.getText() +
"' WHERE SalesRepIndex = " + RowIndex);
FrmSalesRep.reloadRecord("SELECT * FROM tblSalesRep WHERE SalesRepIndex = " + RowIndex +" ORDER BY Name ASC");
JOptionPane.showMessageDialog(null,"Changes in the record has been successfully save.","Naparansoft Inventory System",JOptionPane.INFORMATION_MESSAGE);
RowIndex="";
dispose();
}catch(SQLException sqlEx){
System.out.println(sqlEx.getMessage());
}
}
}
}else if(srcObj=="reset"){
clearFields();
}else if(srcObj=="cancel"){
dispose();
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -