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
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
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;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_DETAIL_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_DETAIL_LIST_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_USER_LEVEL_E;
 
import javax.swing.*;
import java.util.Vector;
 
/**
 * 
 * @introduction The module of user list.
 * @description Only support NVR 
 */
public class Userlist {
    
    /** 
     * @introduction To acquire the user list.
     * @description Calling the interface of NETDEV_GetUserDetailList.
     */
    public static void getUserList() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.UserListTableModel.setRowCount(0);
        NETDEV_USER_DETAIL_LIST_S stUserDetailList = new NETDEV_USER_DETAIL_LIST_S();
        for(int i = 0; i<NetDEVSDKLib.NETDEV_LEN_64; i++)
        {
            stUserDetailList.astUserInfo[i] = new NETDEV_USER_DETAIL_INFO_S();
        }
        stUserDetailList.write();
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetUserDetailList(NetDemo.lpUserID, stUserDetailList);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Get user list,maybe not support. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_GetUserDetailList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        for(int i = 0; i < stUserDetailList.udwNum; i++)
        {
            Vector<String> UserListVector= new Vector<String>();
 
            UserListVector.add(String.valueOf(i+1));
            UserListVector.add(Common.byteArrayToString(stUserDetailList.astUserInfo[i].szUserName));
            if(stUserDetailList.astUserInfo[i].udwLevel == NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_ADMINISTRATOR)
            {
                UserListVector.add("ADMINISTRATOR");
            }
            else if(stUserDetailList.astUserInfo[i].udwLevel == NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_OPERATOR)
            {
                UserListVector.add("OPERATOR");
            }
            else if(stUserDetailList.astUserInfo[i].udwLevel == NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_USER)
            {
                UserListVector.add("USER");
            }
            else if(stUserDetailList.astUserInfo[i].udwLevel == NETDEV_USER_LEVEL_E.NETDEV_USER_LEVEL_Default)
            {
                UserListVector.add("Default");
            }
            NetDemo.UserListTableModel.addRow(UserListVector);
        }
    }
    /** 
     * @introduction To delete the user .
     * @description Calling the interface of NETDEV_DeleteUser.
     */
    public static void deleteUser() {
        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;
        }
        String strUserName = (String) NetDemo.jTableUserList.getValueAt(NetDemo.jTableUserList.getSelectedRow(), 1);
        boolean bRet = NetDemo.netdevsdk.NETDEV_DeleteUser(NetDemo.lpUserID, strUserName);
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Delete user failed. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_DeleteUser failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        } 
        NetDemo.jButtonUserListGetUserList.doClick();
    }
    /** 
     * @introduction To acquire the information of the user.
     */
    public static void getUserInfo() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.jTableUserList.getSelectedRows().length == 1)
        {
            if(null == NetDemo.lpUserID)
            {
                JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0)
            {
                String userName = NetDemo.jTableUserList.getValueAt(NetDemo.jTableUserList.getSelectedRow(), 1).toString();
                MaintenaceUserInfoWindow ma=new MaintenaceUserInfoWindow(NetDemo.lpUserID,NetDemo.ChannelID,userName);
                ma.setVisible(true);
            }
            else if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 1)
            {
                JOptionPane.showMessageDialog(null, "Only Support NVR Equipment.");
            }
            
        }
        else if(NetDemo.jTableUserList.getSelectedRows().length>1)
        {
            JOptionPane.showMessageDialog(null, "Only select one.");
            return;
        }
        else if(NetDemo.jTableUserList.getSelectedRows().length == 0)
        {
            JOptionPane.showMessageDialog(null, "Please select one.");
            return;
        }
    }
}