?? addcrtype.java
字號:
/* * 文件名:AddcrType.java * 說明;添加客戶類型 */package com.redingsoft.setcrtypeframe;import com.redingsoft.sql.SetSQL;import com.redingsoft.sunsdk.swing.OJButton;import com.redingsoft.sunsdk.swing.xtwh_table;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Vector;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.*;import javax.swing.table.DefaultTableModel;/** * * @author Administrator */public class AddcrType extends JPanel implements ActionListener { //設置6個標簽 //聲明標簽 private JLabel jl1,jl2,jl3,jl4,jl5,jl6; //聲明文本框 private JTextField tf1,tf2,tf3,tf4,tf5,tf6; //聲明2按鈕 private JButton bt1,bt2,bt3; //聲明面板 private JPanel topPane,bottPane,mainPane; //為每個文本框聲明一個面板 JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7,jp8; //聲明一個下啦列表 JComboBox cb; // 聲明一個滾動面板 JScrollPane sp; //聲明一個表格用來顯示輸入信息 JTable tb; //聲明一個2個向量來初始化表格 String[] col={"類型編號","類型名稱","折扣屬性","折扣比例","備注"}; String[][] row=new String[1][5]; //聲明一個表數據模式 DefaultTableModel dftm1; private int count; //創建一個向量存儲數據庫語句 Vector v=new Vector(); //生一個數組初始化組合列表 String [] item={"無折扣","普通折扣","高級折扣"}; String sql=null; //構造方法 public AddcrType (){ //實例化標簽 jl1=new JLabel("類型編號"); jl2=new JLabel("折扣屬性"); jl3=new JLabel("類型名稱"); jl4=new JLabel("折扣比例"); jl5=new JLabel(" 備注"); //實例化按鈕 bt1=new OJButton("com/redingsoft/pic/save.gif","保存","單擊保存到數據庫",true); //添加 bt2=new OJButton("com/redingsoft/pic/cancel.gif","刪除","刪除該類型客戶",true); //刪除 bt3=new OJButton("com/redingsoft/pic/b1.gif","刷新","刷新",true); //刷新 //實例化文本框 tf1=new JTextField(15); //類型編號 // tf2=new JTextField(15); //類型名稱 tf2=new JTextField(15); //折扣屬性 tf3=new JTextField(15); // 折扣比例 tf4=new JTextField(40); //備注 //實例化組合列表 cb=new JComboBox(item); //實例化表格并初始化表格 tb=new JTable(); //實例化表模式 dftm1=new xtwh_table(row,col); sql="select id 類型編號,c_type 類型名稱, dis_attr 折扣屬性 , discount 折扣比例, remark 備注 from customertype where delmark=0"; tb.setModel(dftm1); initTabel(sql); tb.setPreferredSize(new Dimension(400,300)); //實例化滾動面板 sp=new JScrollPane(tb); sp.setPreferredSize(new Dimension(500,200)); //實例化各面板 jp1=new JPanel(); jp2=new JPanel(); jp3=new JPanel(); jp4=new JPanel(); jp5=new JPanel(); jp6=new JPanel(); ////////////////////////// topPane=new JPanel(new FlowLayout(FlowLayout.LEFT,1,10)); bottPane=new JPanel(); mainPane=new JPanel(new BorderLayout()); //添加各種組件到面板 jp1.add(jl1); //類型編號 jp1.add(tf1); jp2.add(jl2); //類型名稱 jp2.add(cb); // jp3.add(jl3); //折扣屬性 jp3.add(tf2); jp4.add(jl4); //折扣比例 jp4.add(tf3); jp5.add(jl5); //備注 jp5.add(tf4); jp6.add(bt1); jp6.add(bt2); jp6.add(bt3); //添加滾動面板到面板bottPanel bottPane.add(sp); //添加組件到topPane topPane.add(jp1); topPane.add(jp2); topPane.add(jp3); topPane.add(jp4); topPane.add(jp5); //設置面板大小 bottPane.setPreferredSize(new Dimension(500,300)); topPane.setPreferredSize(new Dimension(500,100)); topPane.setBorder(BorderFactory.createLineBorder(Color.GRAY)); //添加偵聽 bt1.addActionListener(this); bt2.addActionListener(this); bt3.addActionListener(this); //添加2各面板到主面板 mainPane.add(BorderLayout.NORTH,topPane); mainPane.add(BorderLayout.SOUTH,bottPane); mainPane.add(BorderLayout.CENTER,jp6); this.add(mainPane); /* JDialog j=new JDialog(); j.add(mainPane); j.setBounds(1, 1, 600, 500); j.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); j.setVisible(true); */ } /***********88 public static void main(String args[]){ new AddcrType (); } * ****************/ //初始化表格/* * 函數名:public void initTabel() * 參數:null * 返回值:void * 功能:制作并初始化表格 ***********************************/public void initTabel(String sql){ //設置表格的模式 //初始化表表模式 SetSQL.initDTM(dftm1,sql); if(dftm1.getRowCount()!=0){ tb.setModel(dftm1); // tb=new JTable(); }else{ WarnMsg("提示","還沒有客戶類型信息,請添加。"); }}/******************************************************* * 函數名稱:WarnMsgPane(String title ,String msg ,component null) * 參數:tile 提示標題 msg 提示消息 顯示他的父組件 * 功能:為錯誤的輸入和連接錯誤做出提示 ************************************************************/ public static void WarnMsg(String title,String msg){ JOptionPane.showMessageDialog(null,msg,title,JOptionPane.WARNING_MESSAGE); } public void actionPerformed(ActionEvent e) { // throw new UnsupportedOperationException("Not supported yet."); Object o=e.getSource(); if(o==bt1){ String id=tf1.getText().trim(), //類型編號 disattr=(String) cb.getSelectedItem(), //類型屬性 type=tf2.getText(), //類型名稱 discount=tf3.getText().trim(), //折扣比例 remark=tf4.getText().trim(); //備注 int disc=Integer.valueOf(discount); sql="select * from customertype where id='"+id+"'"; ResultSet rs=SetSQL.executeQuery(sql); int i=0; try { while (rs.next()) { i++; } } catch (SQLException ex) { Logger.getLogger(AddcrType.class.getName()).log(Level.SEVERE, null, ex); } if(i!=0){ WarnMsg("提示","此客戶類型編號已存在請輸入不同的客戶類型!"); }else{ sql="insert into customertype(id,c_type,dis_attr,discount,remark) values('"+id+"','"+type+"','"+disattr+"',"+disc+",'"+remark+"')"; int flag=SetSQL.executeUpdate(sql); if(flag==0){ WarnMsg("提示","客戶類型插入失敗!"); }else{ WarnMsg("提示","客戶類型插入成功。!"); } }//end if(i!=0) } //end if(o==bt1) if(o==bt2){ //刪除 String flag= JOptionPane.showInputDialog("請輸入類型編號",JOptionPane.INFORMATION_MESSAGE); if(flag==null){ }else{ String sqlcode="delete from customertype where id='"+flag+"'"; int num=SetSQL.executeUpdate(sqlcode); if(num==0){ WarnMsg("提示","客戶類型刪除失敗!可能因為此類型不存在。"); }else{ WarnMsg("提示","客戶類型刪除成功!刷新可看到新信息"); } }//end if(flag=null) }//end if(o==bt2) if(o==bt3){ //刷新 sql="select id 類型編號,c_type 類型名稱, dis_attr 折扣屬性 , discount 折扣比例, remark 備注 from customertype where delmark=0"; initTabel(sql); } } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -