fuliqi
2024-08-29 4163c93761115c7524ef74a557a1f5e01eafb429
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
package com.ycl.api.YS.user;
 
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_LEVEL_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_MODIFY_DETAIL_INFO_S;
 
import javax.swing.*;
 
/**
 * @description To modify the information of user.
 */
public class ModifyUser {
    /**
     * @description To modify the information of user.
     * @introduction Calling the interface of NETDEV_ModifyUser.
     */
    public static void modifyUser() {  
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(0 == NetDemo.UserListTableModel.getRowCount()  || NetDemo.jTableUserList.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find user or seletc user first.");
            return;
        }    
        NETDEV_USER_MODIFY_DETAIL_INFO_S stUserInfo = new NETDEV_USER_MODIFY_DETAIL_INFO_S();
        if(NetDemo.jTextFieldModifyUserUserName.getText()==null||NetDemo.jTextFieldModifyUserUserName.getText().equals("")) 
        {
            JOptionPane.showMessageDialog(null, "Please input username");
            return;
        }
        if(NetDemo.jTextFieldlblModifyUserNewPasswd.getText()==null||NetDemo.jTextFieldlblModifyUserNewPasswd.getText().equals("")) 
        {
            JOptionPane.showMessageDialog(null, "Please input new Pssword");
            return;
        }
        Common.stringToByteArray(NetDemo.jTextFieldModifyUserUserName.getText(), stUserInfo.stUserInfo.szUserName);
        Common.stringToByteArray(NetDemo.jTextFieldModifyUserOldPassword.getText(), stUserInfo.szCurrentPassword);
        Common.stringToByteArray(NetDemo.jTextFieldlblModifyUserNewPasswd.getText(), stUserInfo.szNewPassword);
        if(NetDemo.jComboBoxModifyUserUserType.getSelectedIndex() == 0)
        {
            stUserInfo.stUserInfo.udwLevel = NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_OPERATOR;
        }
        else if(NetDemo.jComboBoxModifyUserUserType.getSelectedIndex() == 1)
        {
            stUserInfo.stUserInfo.udwLevel = NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_USER;
        }
        /* 管理员修改自己的信息 */
        if(NetDemo.jTextFieldModifyUserUserName.getText().compareTo("Admin") == 0)
        {
            stUserInfo.bIsModifyOther = 0;
        }
        else
        {
            stUserInfo.bIsModifyOther = 1;
        }
        /* 如果旧密码和新密码一样 */
        if(NetDemo.jTextFieldModifyUserOldPassword.getText().compareTo(NetDemo.jTextFieldlblModifyUserNewPasswd.getText()) == 0)
        {
            stUserInfo.bIsModifyPassword = 0;
        }
        else
        {
            stUserInfo.bIsModifyPassword = 1;
        }
        boolean bRet = NetDemo.netdevsdk.NETDEV_ModifyUser(NetDemo.lpUserID, stUserInfo);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Modify user failed. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_ModifyUser failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "Modify user success");
            NetDemo.jTextFieldModifyUserUserName.setText(null);    
            NetDemo.jTextFieldModifyUserOldPassword.setText(null);    
            NetDemo.jTextFieldlblModifyUserNewPasswd.setText(null);
            NetDemo.jComboBoxModifyUserUserType.setSelectedIndex(0);
            NetDemo.changeName=null;
        }
        NetDemo.jButtonUserListGetUserList.doClick();
    }
}