826220679@qq.com
2025-08-07 4d6cd980c5c69e4d9d150669c89734642297e0cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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);
        }
    }
}