需要为 sdk ZKTeco 设备 fb100 编辑代码 "user info"

Need to edit the code "user info" for sdk ZKTeco device fb100

我有此代码 100% 工作,但只有一台设备 zkt fb100,此代码用于设置用户名、卡号,以及设备的 ID 以注册它:

public int sta_SetUserInfo(ListBox lblOutputInfo, TextBox txtUserID, TextBox txtName, ComboBox cbPrivilege, TextBox txtCardnumber, TextBox txtPassword)
{
    if (GetConnectState() == false)
    {
        lblOutputInfo.Items.Add("*Please connect first!");
        return -1024;
    }

    if (txtUserID.Text.Trim() == "" || cbPrivilege.Text.Trim() == "")
    {
        lblOutputInfo.Items.Add("*Please input data first!");
        return -1023;
    }

    int iPrivilege = cbPrivilege.SelectedIndex;
    
    bool bFlag = false;
    if (iPrivilege == 5)
    {
        lblOutputInfo.Items.Add("*User Defined Role is Error! Please Register again!");
        return -1023;
    }

    /*
    if(iPrivilege == 4)
    {
        axCZKEM1.IsUserDefRoleEnable(iMachineNumber, 4, out bFlag);

        if (bFlag == false)
        {
            lblOutputInfo.Items.Add("*User Defined Role is unable!");
            return -1023;
        }
    }
     */
    //lblOutputInfo.Items.Add("[func IsUserDefRoleEnable]Temporarily unsupported");

    int iPIN2Width = 0;
    int iIsABCPinEnable = 0;
    int iT9FunOn = 0;
    string strTemp = "";
    axCZKEM1.GetSysOption(GetMachineNumber(), "~PIN2Width", out strTemp);
    iPIN2Width = Convert.ToInt32(strTemp);
    axCZKEM1.GetSysOption(GetMachineNumber(), "~IsABCPinEnable", out strTemp);
    iIsABCPinEnable = Convert.ToInt32(strTemp);
    axCZKEM1.GetSysOption(GetMachineNumber(), "~T9FunOn", out strTemp);
    iT9FunOn = Convert.ToInt32(strTemp);
    /*
    axCZKEM1.GetDeviceInfo(iMachineNumber, 76, ref iPIN2Width);
    axCZKEM1.GetDeviceInfo(iMachineNumber, 77, ref iIsABCPinEnable);
    axCZKEM1.GetDeviceInfo(iMachineNumber, 78, ref iT9FunOn);
    */

    if (txtUserID.Text.Length > iPIN2Width)
    {
        lblOutputInfo.Items.Add("*User ID error! The max length is " + iPIN2Width.ToString());
        return -1022;
    }

    if (iIsABCPinEnable == 0 || iT9FunOn == 0)
    {
        if (txtUserID.Text.Substring(0,1) == "0")
        {
            lblOutputInfo.Items.Add("*User ID error! The first letter can not be as 0");
            return -1022;
        }

        foreach (char tempchar in txtUserID.Text.ToCharArray())
        {
            if (!(char.IsDigit(tempchar)))
            {
                lblOutputInfo.Items.Add("*User ID error! User ID only support digital");
                return -1022;
            }
        }   
    }

    int idwErrorCode = 0;
    string sdwEnrollNumber = txtUserID.Text.Trim();
    string sName = txtName.Text.Trim();
    string sCardnumber = txtCardnumber.Text.Trim();
    string sPassword = txtPassword.Text.Trim();

    bool bEnabled = true;
    /*if (iPrivilege == 4)
    {
        bEnabled = false;
        iPrivilege = 0;
    }
    else
    {
        bEnabled = true;
    }*/

    axCZKEM1.EnableDevice(iMachineNumber, false);
    axCZKEM1.SetStrCardNumber(sCardnumber);//Before you using function SetUserInfo,set the card number to make sure you can upload it to the device
    if (axCZKEM1.SSR_SetUserInfo(iMachineNumber, sdwEnrollNumber, sName, sPassword, iPrivilege, bEnabled))//upload the user's information(card number included)
    {
        lblOutputInfo.Items.Add("Set user information successfully");
    }
    else
    {
        axCZKEM1.GetLastError(ref idwErrorCode);
        lblOutputInfo.Items.Add("*Operation failed,ErrorCode=" + idwErrorCode.ToString());
    }
    axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed
    axCZKEM1.EnableDevice(iMachineNumber, true);

    return 1;
}

但是如果我有两个设备,我应该在这里更改什么? . 我尝试更改 iMachineNumber 以使第一台设备为 1,第二台设备为 2,但也无法正常工作!

最后我找到了解决方案:在连接到设备的按钮中,需要为一个设备循环插入上述代码,然后为下一个设备循环,依此类推。