package dell_system;
|
import mac.Dell_mac;
|
import mac.MachineCodeGenerator;
|
import mac.SoftwareLicenseSystem;
|
import javax.swing.*;
|
|
import databases.DBConnector;
|
import mac.KeyGeneratorTool;
|
|
import java.awt.*;
|
import java.awt.datatransfer.StringSelection;
|
import java.awt.event.ActionEvent;
|
import java.sql.SQLException;
|
import java.util.ResourceBundle;
|
|
public class VersionInfoPanel extends JPanel {
|
private static final long serialVersionUID = 1L;
|
private final ResourceBundle messages;
|
private JTextField activationField;
|
private JTextField expiryField;
|
|
public VersionInfoPanel(ResourceBundle messages) {
|
this.messages = messages;
|
initUI();
|
}
|
|
private void initUI() {
|
setLayout(new GridBagLayout());
|
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
|
setBackground(new Color(240, 245, 249));
|
|
GridBagConstraints gbc = new GridBagConstraints();
|
gbc.insets = new Insets(10, 10, 10, 10);
|
gbc.anchor = GridBagConstraints.WEST;
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
// Èí¼þ°æ±¾
|
gbc.gridwidth = 1;
|
gbc.gridx = 0;
|
gbc.gridy = 0;
|
add(createLabel(messages.getString("SOFTWARE_VERSION")), gbc);
|
|
gbc.gridx = 1;
|
JTextField softwareField = createTextField("1.0.0");
|
add(softwareField, gbc);
|
gbc.gridx = 2;
|
add(new JLabel(), gbc); // ռλ
|
|
// Ëã·¨°æ±¾
|
gbc.gridy++;
|
gbc.gridx = 0;
|
add(createLabel(messages.getString("ALGORITHM_VERSION")), gbc);
|
|
gbc.gridx = 1;
|
JTextField algorithmField = createTextField("2.1.3");
|
add(algorithmField, gbc);
|
|
|
|
//¼¤»îÂë
|
gbc.gridy++;
|
gbc.gridx = 0;
|
add(createLabel(messages.getString("ACTIVATION_CODE")), gbc);
|
|
gbc.gridx = 1;
|
activationField = createTextField(Dell_mac.getjihuoma());
|
add(activationField, gbc);
|
|
// ÔÚ¼¤»îÂëÎı¾¿òºóÃæÌí¼ÓÉú³É°´Å¥
|
gbc.gridx = 2;
|
JButton generateButton = new JButton(messages.getString("GENERATE_BUTTON"));
|
generateButton.setBackground(new Color(70, 130, 180));
|
generateButton.setForeground(Color.WHITE);
|
generateButton.addActionListener(e -> generateActivationCode());
|
add(generateButton, gbc);
|
|
|
// »úÆ÷Âë
|
gbc.gridy++;
|
gbc.gridx = 0;
|
add(createLabel(messages.getString("MACHINE_CODE")), gbc);
|
|
gbc.gridx = 1;
|
JTextField machineField = createTextField(getMachineCode());
|
add(machineField, gbc);
|
|
gbc.gridx = 2;
|
JButton copyButton = new JButton(messages.getString("COPY_BUTTON"));
|
copyButton.setBackground(new Color(70, 130, 180));
|
copyButton.setForeground(Color.WHITE);
|
copyButton.addActionListener(e -> copyToClipboard(machineField.getText(), activationField.getText()));
|
add(copyButton, gbc);
|
|
// ½ØÖ¹ÈÕÆÚ
|
gbc.gridy++;
|
gbc.gridx = 0;
|
add(createLabel(messages.getString("EXPIRY_DATE")), gbc);
|
|
gbc.gridx = 1;
|
expiryField = createTextField(SoftwareLicenseSystem.usedata(Dell_mac.getpassmac(),Dell_mac.getjihuoma()));
|
add(expiryField, gbc);
|
|
// ×¢²á°´Å¥·ÅÔÚ½ØÖ¹ÈÕÆÚÏ·½
|
gbc.gridy++;
|
gbc.gridx = 1;
|
gbc.gridwidth = 2;
|
JButton registerButton = new JButton(messages.getString("REGISTER_BUTTON"));
|
registerButton.setBackground(new Color(46, 139, 87));
|
registerButton.setForeground(Color.WHITE);
|
registerButton.setPreferredSize(new Dimension(150, 30));
|
registerButton.addActionListener(this::registerAction);
|
add(registerButton, gbc);
|
}
|
|
private JLabel createLabel(String text) {
|
JLabel label = new JLabel(text + ":");
|
label.setFont(new Font("΢ÈíÑźÚ", Font.BOLD, 14));
|
return label;
|
}
|
|
// ÐÞ¸ÄÕâ¸ö·½·¨£¬½«Îı¾¿ò³¤¶ÈÔö¼Óµ½450ÏñËØ£¨ÔÀ´µÄ1.5±¶£©
|
private JTextField createTextField(String text) {
|
JTextField field = new JTextField(text);
|
field.setEditable(false);
|
field.setBackground(Color.WHITE);
|
field.setBorder(BorderFactory.createCompoundBorder(
|
BorderFactory.createLineBorder(new Color(200, 200, 200)),
|
BorderFactory.createEmptyBorder(5, 10, 5, 10)
|
));
|
// ½«¿í¶È´Ó300Ôö¼Óµ½450ÏñËØ£¨1.5±¶£©
|
field.setPreferredSize(new Dimension(450, 30));
|
return field;
|
}
|
|
private String getMachineCode() {
|
try {
|
return MachineCodeGenerator.getMachineCode();
|
} catch (Exception e) {
|
return "Error: " + e.getMessage();
|
}
|
}
|
|
private void copyToClipboard(String machineCode, String activationCode) {
|
String data = messages.getString("MACHINE_CODE") + ": " + machineCode + "\n" +
|
messages.getString("ACTIVATION_CODE") + ": " + activationCode;
|
Toolkit.getDefaultToolkit().getSystemClipboard()
|
.setContents(new StringSelection(data), null);
|
JOptionPane.showMessageDialog(this,
|
messages.getString("COPY_SUCCESS"),
|
messages.getString("SUCCESS"),
|
JOptionPane.INFORMATION_MESSAGE);
|
}
|
|
private void registerAction(ActionEvent e) {
|
String newCode = JOptionPane.showInputDialog(
|
this,
|
messages.getString("REGISTER_PROMPT"),
|
messages.getString("REGISTER_TITLE"),
|
JOptionPane.PLAIN_MESSAGE
|
);
|
|
if (newCode != null && !newCode.trim().isEmpty()) {
|
try {
|
// ¸üÐÂÊý¾Ý¿â
|
updateActivationCode(newCode);
|
|
// ¸üнçÃæÏÔʾ
|
activationField.setText(newCode);
|
String BASE64_SECRET_KEY=activationField.getText();
|
expiryField.setText(SoftwareLicenseSystem.usedata(newCode,BASE64_SECRET_KEY));
|
|
JOptionPane.showMessageDialog(this,
|
messages.getString("REGISTER_SUCCESS"),
|
messages.getString("SUCCESS"),
|
JOptionPane.INFORMATION_MESSAGE);
|
} catch (SQLException ex) {
|
JOptionPane.showMessageDialog(this,
|
messages.getString("REGISTER_FAILED") + ": " + ex.getMessage(),
|
messages.getString("ERROR"),
|
JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
}
|
|
private void updateActivationCode(String newCode) throws SQLException {
|
String sql = "UPDATE tb_mac SET passmac = '" + newCode + "' WHERE id = 0";
|
DBConnector.executeUpdate(sql);
|
Dell_mac.getAllCompanies().get(0).setPassmac(newCode);
|
}
|
|
private void generateActivationCode() {
|
// Éú³ÉÐµļ¤»îÂë
|
String newActivationCode = KeyGeneratorTool.getjihuoma();
|
|
// ¸ü줻îÂëÎı¾¿ò
|
activationField.setText(newActivationCode);
|
|
try {
|
// ¸üÐÂÊý¾Ý¿âÖеÄmac×Ö¶Î
|
String sql = "UPDATE tb_mac SET mac = '" + newActivationCode + "' WHERE id = 0";
|
DBConnector.executeUpdate(sql);
|
|
// ¸üÐÂÄÚ´æÖе碌îÂë
|
Dell_mac.getAllCompanies().get(0).setMac(newActivationCode);
|
|
JOptionPane.showMessageDialog(this,
|
messages.getString("GENERATE_SUCCESS"),
|
messages.getString("SUCCESS"),
|
JOptionPane.INFORMATION_MESSAGE);
|
} catch (SQLException ex) {
|
JOptionPane.showMessageDialog(this,
|
messages.getString("GENERATE_FAILED") + ": " + ex.getMessage(),
|
messages.getString("ERROR"),
|
JOptionPane.ERROR_MESSAGE);
|
}
|
}
|
}
|