zxl
15 小时以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
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
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_DETAIL_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_LEVEL_E;
 
import javax.swing.*;
 
/**
 * @description To add user.
 * @introduction Only support NVR.
 */
public class AddUser {
    /**
     * @description To add user.
     * @introduction Calling the interface of NETDEV_CreateUser.
     */
    @SuppressWarnings("deprecation")
    public static void addUser() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.jButtonUserListGetUserList.doClick();
        NETDEV_USER_DETAIL_INFO_S stUserInfo = new NETDEV_USER_DETAIL_INFO_S();
        if(NetDemo.jTextFieldAddUserUserName.getText()==null||NetDemo.jTextFieldAddUserUserName.getText().equals("")) 
        {
            JOptionPane.showMessageDialog(null, "Username can not be null");
            return;
        }
        if(NetDemo.UserListTableModel.getRowCount()>0) 
        {
            for(int i=0;i<NetDemo.UserListTableModel.getRowCount();i++) {
                String username=(String) NetDemo.UserListTableModel.getValueAt(i, 1);
                if(NetDemo.jTextFieldAddUserUserName.getText().equals(username)) {
                    JOptionPane.showMessageDialog(null, "User is alerady existence");
                    NetDemo.jTextFieldAddUserUserName.setText(null);
                    NetDemo.jTextFieldlAddUserPasswd.setText(null);
                    return;
                }
            }
        }
        if(NetDemo.jTextFieldlAddUserPasswd.getText()==null||NetDemo.jTextFieldlAddUserPasswd.getText().equals("")) 
        {
            JOptionPane.showMessageDialog(null, "Password can not null");
            return;
        }
        Common.stringToByteArray(NetDemo.jTextFieldAddUserUserName.getText(), stUserInfo.szUserName);
        Common.stringToByteArray(NetDemo.jTextFieldlAddUserPasswd.getText(), stUserInfo.szPassword);
        if(NetDemo.jComboBoxAddUserUserType.getSelectedIndex() == 0)
        {
            stUserInfo.udwLevel = NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_OPERATOR;
        }
        else if(NetDemo.jComboBoxAddUserUserType.getSelectedIndex() == 1)
        {
            stUserInfo.udwLevel = NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_USER;
        }
        boolean bRet = NetDemo.netdevsdk.NETDEV_CreateUser(NetDemo.lpUserID, stUserInfo);
        if(bRet != true)
        {
            System.out.printf("NETDEV_CreateUser failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            JOptionPane.showMessageDialog(null, "Create user failed. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else 
        {
            JOptionPane.showMessageDialog(null, "Add user success");
            NetDemo.jTextFieldAddUserUserName.setText(null);
            NetDemo.jTextFieldlAddUserPasswd.setText(null);
        }
        NetDemo.jButtonUserListGetUserList.doClick();
    }
}