📄 frmsupplier.java
字号:
}
}
//Search Record
}else if(srcObj=="search"){
JDialog JDSearchRec = new FrmSearchSupplier(JFParentFrame);
JDSearchRec.show(true);
//Print Record
}else if(srcObj=="print"){
if(total != 0){
try{
if(JTSupTable.getValueAt(JTSupTable.getSelectedRow(),JTSupTable.getSelectedColumn()) != null){
clsPublicMethods PrintingClass = new clsPublicMethods();
ResultSet rsPrint = stSup.executeQuery("SELECT * FROM tblSupplier WHERE SupplierIndex = " + JTSupTable.getValueAt(JTSupTable.getSelectedRow(),0));
if(rsPrint.next()==true){
String RecordToPrint = "";
java.util.Date CurrentDate = new java.util.Date();
SimpleDateFormat SDFDateFormatter = new SimpleDateFormat("MMM. dd, yyyy",Locale.getDefault());
RecordToPrint += " S U P P L I E R R E C O R D \n";
RecordToPrint += " " + SDFDateFormatter.format(CurrentDate).toString() + "\n\n\n";
RecordToPrint += "___________________________________________________________________________________\n\n\n";
RecordToPrint += " Supplier ID: " + rsPrint.getString("SupplierID") + " Company Name: " + rsPrint.getString("CompanyName") + "\n";
RecordToPrint += "___________________________________________________________________________________\n";
RecordToPrint += "___________________________________________________________________________________\n\n";
RecordToPrint += " Contact Person: " + rsPrint.getString("ContactName") + "\n";
RecordToPrint += " Contact Title: " + rsPrint.getString("ContactTitle") + "\n";
RecordToPrint += " Address: " + rsPrint.getString("Address") + "\n";
RecordToPrint += " City: " + rsPrint.getString("CityTown") + "\n";
RecordToPrint += " State/Province: " + rsPrint.getString("StateProvince") + "\n";
RecordToPrint += " Zip Code: " + rsPrint.getString("ZipCode") + "\n";
RecordToPrint += " Country: " + rsPrint.getString("Country") + "\n";
RecordToPrint += " Phone: " + rsPrint.getString("Phone") + "\n";
RecordToPrint += " Fax: " + rsPrint.getString("Fax") + "\n\n";
RecordToPrint += " Website: " + rsPrint.getString("Website") + "\n\n";
RecordToPrint += "___________________________________________________________________________________\n\n";
PrintingClass.printRecord(RecordToPrint,JFParentFrame);
CurrentDate=null;
SDFDateFormatter=null;
RecordToPrint=null;
}else{
JOptionPane.showMessageDialog(null,"The selected record has been change since last modified. Please click the 'Reload' button and try again!","No record to print",JOptionPane.WARNING_MESSAGE);
}
//Dispose the variable
rsPrint=null;
}
}catch(Exception sqlE){
if(sqlE.getMessage() != null){
System.out.println(sqlE.getMessage());
}else{
JOptionPane.showMessageDialog(null,"Please select a record in the list to print.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
}
}
}
//Delete Record
}else if(srcObj=="delete"){
if(total != 0){
try{
if(JTSupTable.getValueAt(JTSupTable.getSelectedRow(),JTSupTable.getSelectedColumn()) != null){
String ObjButtons[] = {"Yes","No"};
int PromptResult = JOptionPane.showOptionDialog(null,"Are you sure you want to delete the selected record?","Delete Record",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,null,ObjButtons,ObjButtons[1]);
if(PromptResult==0){
stSup.execute("DELETE * FROM tblSupplier WHERE SupplierIndex = " + JTSupTable.getValueAt(JTSupTable.getSelectedRow(),0));
reloadRecord();
JOptionPane.showMessageDialog(null,"Record has been successfully deleted.","Comfirm Delete",JOptionPane.INFORMATION_MESSAGE);
}
}
}catch(Exception sqlE){
if(sqlE.getMessage()!=null){
JOptionPane.showMessageDialog(null,"You cannot delete this Supplier because it already have an invoice transaction.\nIn order to delete this Supplier, delete its invoice first.","Comfirm Delete",JOptionPane.WARNING_MESSAGE);
}else{
JOptionPane.showMessageDialog(null,"Please select a record in the list to deleted.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
}
}
}
//Reload Record
}else if(srcObj=="reload"){
reloadRecord();
//Close the Form
}
}
};
/*************************** End event handling ***************************/
/************************** Start Custom class ***************************/
public static JTable CreateTable(){
String ColumnHeaderName[] = {
"Index","Supplier ID","Company Name","Contact Name"
};
try{
rsSup = stSup.executeQuery(strSQL);
total = 0;
//Move to the last record
rsSup.afterLast();
//Get the current record position
if(rsSup.previous())total = rsSup.getRow();
//Move back to the first record;
rsSup.beforeFirst();
if(total > 0){
Content = new String[total][4];
while(rsSup.next()){
Content[rowNum][0] = "" + rsSup.getString("SupplierIndex");
Content[rowNum][1] = "" + rsSup.getString("SupplierID");
Content[rowNum][2] = "" + rsSup.getString("CompanyName");
Content[rowNum][3] = "" + rsSup.getString("ContactName");
rowNum++;
}
}else{
Content = new String[0][4];
Content[0][0] = " ";
Content[0][1] = " ";
Content[0][2] = " ";
Content[0][3] = " ";
}
}catch(Exception eE){
}
JTable NewTable = new JTable (Content,ColumnHeaderName){
public boolean isCellEditable (int iRows, int iCols) {
return false;
}
};
NewTable.setPreferredScrollableViewportSize(new Dimension(727, 320));
NewTable.setBackground(Color.white);
//Start resize the table column
NewTable.getColumnModel().getColumn(0).setMaxWidth(0);
NewTable.getColumnModel().getColumn(0).setMinWidth(0);
NewTable.getColumnModel().getColumn(0).setWidth(0);
NewTable.getColumnModel().getColumn(0).setPreferredWidth(0);
NewTable.getColumnModel().getColumn(1).setPreferredWidth(100);
NewTable.getColumnModel().getColumn(2).setPreferredWidth(300);
NewTable.getColumnModel().getColumn(3).setPreferredWidth(200);
//End resize the table column
//Disposed variables
ColumnHeaderName=null;
Content=null;
rowNum = 0;
return NewTable;
}
/**************************** End Custom class ****************************/
/************************** Start Custom method ***************************/
public static void reloadRecord(String srcSQL){
strSQL = srcSQL;
SupTableJSP.getViewport().remove(JTSupTable);
JTSupTable=CreateTable();
SupTableJSP.getViewport().add(JTSupTable);
JPContainer.repaint();
}
public static void reloadRecord(){
SupTableJSP.getViewport().remove(JTSupTable);
JTSupTable=CreateTable();
SupTableJSP.getViewport().add(JTSupTable);
JPContainer.repaint();
}
/*************************** End Custom method ****************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -