package server.userpane;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.io.File;
import java.io.FilenameFilter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.border.Border;
import server.dao.UserDAO;
import server.factory.DaoFactory;
import server.login.ServerFrme;
import utils.StaticUtils;
/**
* 用于显示、添加、修改用户信息的对话框
* @author 洪景泉
*
*/
public class DialogPane extends JDialog {
private ServerFrme qqServerFrm = null;
// 状态参数
private int flag;
// 面板
private JPanel centerPane = null;
private JPanel bottomPane = null;
// 对话框面板组件
private JLabel IDLab = null; // 编号
private JTextField IDText = null;
private JLabel nameLab = null; // 姓名
private JTextField nameText = null;
private JLabel nickNameLab = null; // 昵称
private JTextField nickNameText = null;
private JLabel pwdLab = null; // 密码
private JPasswordField pwdText = null;
private JLabel sexLab = null; // 性别
private JComboBox sexCom = null;
private JLabel addressLab = null; // 地址
private JTextField addressText = null;
private JLabel ageLab = null; // 年龄
private JTextField ageText = null;
private JLabel departmentLab = null; // 所在部门
private JComboBox departmentCom = null;
private JLabel phoneLab = null; // 电话
private JTextField phoneText = null;
private JLabel lastLoginLab = null; // 最后登陆时间
private JTextField lastLoginText = null;
private JLabel regTimeLab = null; // 注册时间
private JTextField regTimeText = null;
private JLabel loginCountLab = null; //登录次数
private JTextField loginCountText = null;
private JLabel onlineLab = null; //是否在线
private JTextField onLineText = null;
private JComboBox iconCom = null; //头像
// 中间面板盒子
private Box hBox1 = null;
private Box hBox2 = null;
private Box hBox3 = null;
private Box hBox4 = null;
private Box hBox5 = null;
private Box hBox6 = null;
private Box hBox7 = null;
private Box hBox8 = null;
private Box hBox9 = null;
private Box hBox10 = null;
private Box hBox11 = null;
private Box vBox1 = null;
private Box vBox2 = null;
private Box vBox3 = null;
// 底部面板组件
private JButton SaveBtn = null;
private JButton cancleBtn = null;
// 底部面板盒子
private Box vBoxBtn = null;
private Box hBoxBtn = null;
//保存头像的抽象路径名所表示的目录中的文件和目录的名称所组成字符串数组。
private String pic[] = null;
/**
* 添加构造函数
* @param id 自动生成的用户ID
* @param qqServerFrm 主界面对象
* @param title 标题
* @param flag flag=1 表示添加 flag=2 表示修改 flag=3 表示详细信息
*/
public DialogPane(String id,ServerFrme qqServerFrm,String title,int flag){
super(qqServerFrm,title);
this.qqServerFrm=qqServerFrm;
this.flag=flag;
ini();
//flag=1表示添加新用户
if(flag==1){
IDText.setText(id);
IDText.setEditable(false);
lastLoginText.setText("从未登陆");
lastLoginText.setEditable(false);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String curDate = df.format(new Date(System.currentTimeMillis()));
regTimeText.setText(curDate);
regTimeText.setEditable(false);
onLineText.setText("不在线");
onLineText.setEditable(false);
loginCountText.setText("0");
loginCountText.setEditable(false);
}else if(flag==2){//修改构造函数
// 初始化
String colList="*";
Map<String, String> sqlMap=new HashMap<String, String>();
sqlMap.put("ID",id);
//OracleDAO userDao = new OracleDAO();
UserDAO userDao=DaoFactory.getUserDao();
Vector<Vector<String>> datas = userDao.select(colList,sqlMap);
Vector vector =datas.get(0);
IDText.setText((String) vector.get(0));
IDText.setEditable(false);
nameText.setText((String) vector.get(1));
nickNameText.setText((String)vector.get(2));//注意这边不能用toString()因为昵称可能为空,要是为空就会出现空值异常
//System.out.println(vector.get(2)==null); //测试语句
pwdText.setText((String) vector.get(3));
/*
* 测试语句
* */
// String sex="\""+(String) vector.get(4)+"\"";
// System.out.println(sex);
sexCom.setSelectedItem(((String) vector.get(4)));
if(!(vector.get(5).toString().trim().equals("0"))){
ageText.setText((String) vector.get(5));
}
phoneText.setText((String) vector.get(6));
departmentCom.setSelectedItem((String) vector.get(7));
addressText.setText((String) vector.get(8));
if(vector.get(9).equals("0")){
onLineText.setText("不在线");
}else{
onLineText.setText("在线");
}
onLineText.setEditable(false);
if(vector.get(10)==null){
lastLoginText.setText("从未登陆");
}else{
lastLoginText.setText((String)vector.get(10));
}
lastLoginText.setEditable(false);
loginCountText.setText((String)vector.get(11));
loginCountText.setEditable(false);
regTimeText.setText((String)vector.get(12));
regTimeText.setEditable(false);
//System.out.println((String) vector.get(13));
String icon = (String) vector.get(13);
iconCom.setSelectedIndex(Integer.parseInt(icon) - 1);
}else if(flag==3){//详细信息按钮事件
String colList="*";
Map<String, String> sqlMap=new HashMap<String, String>();
sqlMap.put("ID",id);
//OracleDAO userDao = new OracleDAO();
UserDAO userDao=DaoFactory.getUserDao();
Vector<Vector<String>> datas = userDao.select(colList,sqlMap);
Vector vector =datas.get(0);
IDText.setText((String) vector.get(0));
IDText.setEditable(false);
nameText.setText((String) vector.get(1));
nameText.setEditable(false);
nickNameText.setText((String)vector.get(2));//注意这边不能用toString()因为昵称可能为空,要是为空就会出现空值异常
nickNameText.setEditable(false);
//System.out.println(vector.get(2)==null); //测试语句
pwdText.setText((String) vector.get(3));
pwdText.setEditable(false);
sexCom.setSelectedItem(((String) vector.get(4)).trim());
sexCom.setEnabled(false);
if(!(vector.get(5).toString().trim().equals("0"))){
ageText.setText((String) vector.get(5));
}
ageText.setEditable(false);
phoneText.setText((String) vector.get(6));
phoneText.setEditable(false);
departmentCom.setSelectedItem((String) vector.get(7));
departmentCom.setEnabled(false);
addressText.setText((String) vector.get(8));
addressText.setEditable(false);
if(vector.get(9).equals("0")){
onLineText.setText("不在线");
}else{
onLineText.setText("在线");
}
onLineText.setEditable(false);
if(vector.get(10)==null){
lastLoginText.setText("从未登陆");
}else{
lastLoginText.setText((String)vector.get(10));
}
lastLoginText.setEditable(false);
loginCoun