📄 mainframe.java
字号:
j.toConnetion("test");
String Card = this.jTextField1.getText();
String pwd = this.jPasswordField1.getText();
sql = "select ID,UserName,Pwd from Card where ID = '" + Card +
"' and Pwd = '" + pwd + "'";
j.doSelect(sql);
if (Card.equals("") || pwd.equals("")) {
JOptionPane.showMessageDialog(this, "用户名或密码不得为空!");
return;
}
try {
if (j.rs.next() == true) {
JOptionPane.showMessageDialog(this, "登陆成功,计费开始!");
String userName = j.rs.getString(2);
j.doClose();
j.toConnetion("test");
String str = (String)this.jComboBox1.getSelectedItem();
sql = "update Computer set OnUse ='1' where ID='" + str + "'";
sql1 =
"insert Record(ID,CardId,ComputerId,BeginTime) values('" +
Card + "','" + userName + "','" + str + "','" +
strNowTime + "')";
j.doUpdate(sql);
j.doUpdate(sql1);
} else {
JOptionPane.showMessageDialog(this, "卡号或者密码错误!");
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage().toString());
}
}
public int calFee(String beginTime, String endTime) {
//从字符串形式的日期获取年,月,日,小时,分
int fee = 0;
int bYear = Integer.parseInt(beginTime.substring(0, 4));
int bMonth = Integer.parseInt(beginTime.substring(5, 7));
int bDay = Integer.parseInt(beginTime.substring(8, 10));
int bHout = Integer.parseInt(beginTime.substring(11, 13));
int bMinute = Integer.parseInt(beginTime.substring(14, 16));
int eYear = Integer.parseInt(endTime.substring(0, 4));
int eMonth = Integer.parseInt(endTime.substring(5, 7));
int eDay = Integer.parseInt(endTime.substring(8, 10));
int eHout = Integer.parseInt(endTime.substring(11, 13));
int eMinute = Integer.parseInt(endTime.substring(14, 16));
//计算上机时间,单位为分钟
int playMinute = 0;
playMinute = ((eYear - bYear) * 365 * 24 * 60 +
(eMonth - bMonth) * 30 * 24 * 60 +
(eDay - bDay) * 24 * 60 +
(eHout - bHout) * 60 + (eMinute - bMinute));
//计算费用
int modNum = playMinute % 60;
int playHour = playMinute / 60;
if (playHour == 0 || (modNum > 5 && playHour > 0)) {
playHour++;
}
fee = playHour * 2;
return fee; //返回本次上机费用
}
//求余额方法
int left;
public int balance(String id,int fee){
int balance;
j.toConnetion("test");
sql2="select Balance from Card where ID='"+id+"'";
j.doSelect(sql2);
try {
while (j.rs.next()) {
balance = Integer.parseInt(j.rs.getString(1));
left=balance-fee;
}
} catch (SQLException ex) {
}
return left;
}
//更新Card表余额方法
public void updateBalance(String id,int fee){
j.toConnetion("test");
sql="update Card set Balance=Balance-'"+fee+"' where ID='"+id+"'";
j.doUpdate(sql);
}
String id;
JMenuItem jMenuItem6 = new JMenuItem();
JPanel jPanel4 = new JPanel();
public void jButton3_actionPerformed(ActionEvent e) {
int f=0;
String beginStr="";
j.toConnetion("test");
String str = (String)this.jComboBox2.getSelectedItem();
sql2="select top 1 BeginTime ,ID from Record where ComputerId='" + str + "' order by BeginTime DESC ";
j.doSelect(sql2);
try {
while (j.rs.next()) {
beginStr = j.rs.getString(1);
id=j.rs.getString(2);
}
} catch (SQLException ex) {
}
f =calFee(beginStr,strNowTime);
left=this.balance(id,f);
this.updateBalance(id,f);
j.doClose();
sql1 = "update Record set EndTime= '" + strNowTime + "' ,Fee='"+f+"' where BeginTime=(select top 1 BeginTime from Record where ComputerId='" + str + "' order by BeginTime DESC)";
j.toConnetion("test");
sql = "update Computer set OnUse ='0' where ID='" + str + "'";
j.doUpdate(sql);
int i=j.doUpdate(sql1);
if(i>0){
JOptionPane.showMessageDialog(this, ""+str.trim()+"号机器成功下机!" +"\n上机时间:"+beginStr + "\n下机时间:"+strNowTime+"\n上机费用:"+f+"元\n上网卡号:"+id+"\n卡内余额:"+left+"");
}
}
public void jMenuItem3_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void jMenuItem5_actionPerformed(ActionEvent e) {
System.exit(0);
}
public void jMenuItem4_actionPerformed(ActionEvent e) {
AboutDialog about =new AboutDialog();
about.setSize(200,100);
about.setTitle("关于");
about.setLocation(400,350);
about.setModal(true);
about.show();
}
class MainFrame_jButton3_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jButton3_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}
class MainFrame_jButton1_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class MainFrame_this_windowAdapter extends WindowAdapter {
private MainFrame adaptee;
MainFrame_this_windowAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void windowOpened(WindowEvent e) {
adaptee.this_windowOpened(e);
}
}
class MainFrame_jMenuItem2_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jMenuItem2_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem2_actionPerformed(e);
}
}
class MainFrame_jMenuItem1_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jMenuItem1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem1_actionPerformed(e);
}
}
}
class MainFrame_jMenuItem4_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jMenuItem4_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem4_actionPerformed(e);
}
}
class MainFrame_jMenuItem5_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jMenuItem5_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem5_actionPerformed(e);
}
}
class MainFrame_jMenuItem3_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jMenuItem3_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuItem3_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -