📄 frmsalesrep.java
字号:
System.out.println(sqlE.getMessage());
}else{
JOptionPane.showMessageDialog(null,"Please select a record in the list to modify.","No Record Selected",JOptionPane.INFORMATION_MESSAGE);
}
}
}
//Search Record
}else if(srcObj=="search"){
JDialog JDSearchRec = new FrmSearchSalesRep(JFParentFrame);
JDSearchRec.show(true);
//Print Record
}else if(srcObj=="print"){
if(total != 0){
try{
if(JTSlrTable.getValueAt(JTSlrTable.getSelectedRow(),JTSlrTable.getSelectedColumn()) != null){
clsPublicMethods PrintingClass = new clsPublicMethods();
ResultSet rsPrint = stSlr.executeQuery("SELECT * FROM tblSalesRep WHERE SalesRepIndex = " + JTSlrTable.getValueAt(JTSlrTable.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";
RecordToPrint += " SalesRep ID: " + rsPrint.getString("SalesRepID") + " SalesRep Name: " + rsPrint.getString("SalesRepName") + "\n\n";
RecordToPrint += " Primary Address: " + rsPrint.getString("Address1") + "\n";
RecordToPrint += " Secondary Address: " + rsPrint.getString("Address2") + "\n";
RecordToPrint += " City: " + rsPrint.getString("City") + "\n";
RecordToPrint += " State/Province: " + rsPrint.getString("StateProvince") + "\n";
RecordToPrint += " Zip Code: " + rsPrint.getString("ZipCode") + "\n";
RecordToPrint += " Contact No: " + rsPrint.getString("ContactNo") + "\n";
RecordToPrint += " Email Address: " + rsPrint.getString("EmailAddress") + "\n\n";
RecordToPrint += "-----------------------------------------------------------------------------------\n\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(JTSlrTable.getValueAt(JTSlrTable.getSelectedRow(),JTSlrTable.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){
stSlr.execute("DELETE * FROM tblSalesRep WHERE SalesRepIndex = " + JTSlrTable.getValueAt(JTSlrTable.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 SalesRep because it already used in product table.\nIn order to delete this SalesRep, delete all the product of this SalesRep.","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","Sales Rep. ID","Name"
};
try{
rsSlr = stSlr.executeQuery(strSQL);
total = 0;
//Move to the last record
rsSlr.afterLast();
//Get the current record position
if(rsSlr.previous())total = rsSlr.getRow();
//Move back to the first record;
rsSlr.beforeFirst();
if(total != 0){
Content = new String[total][3];
while(rsSlr.next()){
Content[rowNum][0] = "" + rsSlr.getString("SalesRepIndex");
Content[rowNum][1] = "" + rsSlr.getString("SalesRepID");
Content[rowNum][2] = "" + rsSlr.getString("Name");
rowNum++;
}
}else{
Content = new String[0][3];
Content[0][0] = " ";
Content[0][1] = " ";
Content[0][2] = " ";
}
}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(500);
//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;
SlrTableJSP.getViewport().remove(JTSlrTable);
JTSlrTable=CreateTable();
SlrTableJSP.getViewport().add(JTSlrTable);
JPContainer.repaint();
}
public static void reloadRecord(){
SlrTableJSP.getViewport().remove(JTSlrTable);
JTSlrTable=CreateTable();
SlrTableJSP.getViewport().add(JTSlrTable);
JPContainer.repaint();
}
/*************************** End Custom method ****************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -