using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TSDome
{
    public partial class DecGroup : Form
    {
        public NetSDK.NET_SDK_USER_MANAGE_INFO m_userlist;
        public int m_lUserID = 0;
        public DecGroup()
        {
            InitializeComponent();
        }
        public void Init()
        {
            comboBoxGroupName.Items.Clear();
            for (int i = 0; i < m_userlist.groupNum; i++)
            {
                comboBoxGroupName.Items.Insert(i, new string(m_userlist.groupList[i].name));
                comboBoxGroupName.SelectedIndex = 0;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(comboBoxGroupName.SelectedIndex<0)
            {
                return;
            }
            else
            {
                NetSDK.NET_SDK_USER_GROUP_INFO groupinfo = new NetSDK.NET_SDK_USER_GROUP_INFO();
                groupinfo = m_userlist.groupList[comboBoxGroupName.SelectedIndex];
                IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NetSDK.NET_SDK_USER_INFO)));
                Marshal.StructureToPtr(groupinfo, pt, false);
                int nRet = NetSDK.NET_SDK_SetDevConfig(m_lUserID, (uint)NetSDK.NET_SDK_CONFIG_TYPE.NET_SDK_COFIG_DELETE_GROUP, -1, pt, Marshal.SizeOf(typeof(NetSDK.NET_SDK_USER_GROUP_INFO)), 2000);
                if (nRet > 0)
                {
                    Close();
                }
                else
                {
                    MessageBox.Show("failed to delete");
                }
            }
        }
    }
}
