using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ITC81DB_0H.Part11_UserManager { public partial class UserManager { public delegate void ObjectEventHandler(object data); public static event ObjectEventHandler UserListNewDataEvent; public static event ObjectEventHandler UserListAddDataEvent; public static event ObjectEventHandler UserListModifyUserDataEvent; public static event ObjectEventHandler UserListModifyInfoDataEvent; public static event ObjectEventHandler UserListDeleteDataEvent; public static event ObjectEventHandler UserListLockDataEvent; public static event ObjectEventHandler UserListDefautSettingDataEvent; public static event ObjectEventHandler UserListLoginTimeoutDataEvent; public static event ObjectEventHandler UserListGetListDataEvent; public static event ObjectEventHandler UserListGetListNameDataEvent; public delegate void IntObjectEventHandler(int status, object data); public static event IntObjectEventHandler UserListLoginDataEvent; public delegate void IntEventHandler(int status); public static event IntEventHandler UserListLogoutDataEvent; public static void IntializeUserManager(string folder) { //Console.Write("Initialize User Manger \n"); // regisetr callback fnUserMgrDebugCallBack = UserManager_DebugCallback; DLL_UserMgr_Register_DebugCB(fnUserMgrDebugCallBack); fnUserMgrNewUserCallBack = UserManager_NewUserCallBack; DLL_UserMgr_Register_NewStatusCB(fnUserMgrNewUserCallBack); fnUserMgrAddUserCallBack = UserManager_AddUserCallBack; DLL_UserMgr_Register_AddStatusCB(fnUserMgrAddUserCallBack); fnUserMgrModifyUserCallBack = UserManager_ModifyUserCallBack; DLL_UserMgr_Register_ModifyUserCB(fnUserMgrModifyUserCallBack); fnUserMgrModifyInfoCallBack = UserManager_ModifyInfoCallBack; DLL_UserMgr_Register_ModifyStatusCB(fnUserMgrModifyInfoCallBack); fnUserMgrDelUserCallBack = UserManager_DelUserCallBack; DLL_UserMgr_Register_DelStatusCB(fnUserMgrDelUserCallBack); fnUserMgrUserLockCallBack = UserManager_LockCallBack; DLL_UserMgr_Register_UserLockCB(fnUserMgrUserLockCallBack); fnUserMgrDefaultSettingCallBack = UserManager_DefaultSettingCallBack; DLL_UserMgr_Register_DefaultSettingCB(fnUserMgrDefaultSettingCallBack); fnUserMgrLoginCallBack = UserManager_LoginCallBack; DLL_UserMgr_Register_LoginStausCB(fnUserMgrLoginCallBack); fnUserMgrLogoutCallBack = UserManager_LogoutCallBack; DLL_UserMgr_Register_LogoutStausCB(fnUserMgrLogoutCallBack); fnUserMgrLoginTimeoutCallBack = UserManager_LoginTimeoutCallBack; DLL_UserMgr_Register_LoginTimeoutCB(fnUserMgrLoginTimeoutCallBack); fnUserMgrGetListCallBack = UserManager_GetListCallBack; DLL_UserMgr_Register_GetListCB(fnUserMgrGetListCallBack); fnUsermgrGetListNameCallBack = UserManager_GetListNameCallBack; DLL_UserMgr_Register_GetListNameCB(fnUsermgrGetListNameCallBack); // call the function //DLL_UserMgr_HelloWorld(); DLL_UserMgr_Activation(); IntPtr pFolder = Marshal.StringToBSTR(folder); DLL_UserMgr_SetFolder(pFolder); // Test Only //TestUserListData(); } public static void TestUserListData() { DateTime_t regDateTime = new DateTime_t(); regDateTime.SetDate(2021, 10, 1); regDateTime.SetTime(10, 11, 12); DateTime_t loginDateTime = new DateTime_t(); loginDateTime.SetDate(2021, 9, 1); loginDateTime.SetTime(10, 21, 12); UserManager_UserAdd("Intech", "test12#$", 1, 90, 90, 1, regDateTime, loginDateTime); UserManager_UserAdd("Admin00", "test12#$", 1, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 2); UserManager_UserAdd("Test101", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 3); UserManager_UserAdd("Test102", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 4); UserManager_UserAdd("Test103", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 5); UserManager_UserAdd("Test104", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 6); UserManager_UserAdd("Test105", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test123", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test321", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("ABC001", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("CBA001", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("AAA001", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test000", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test105", "test12#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test106", "test12", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test107", "test#$", 0, 90, 90, 1, regDateTime, loginDateTime); regDateTime.SetDate(2021, 10, 7); UserManager_UserAdd("Test108", "1223#$%", 0, 90, 90, 1, regDateTime, loginDateTime); //UserManager_UserNew("Test200", "test12#$", 0, 20, 30); DLL_UserMgr_GetUserListID(IntPtr.Zero); } public static void DeinitializeUserManger() { DLL_UserMgr_Register_DebugCB(null); DLL_UserMgr_Register_NewStatusCB(null); DLL_UserMgr_Deactivation(); } #region UM_FUNCTION public static void UserManager_GetUserList(String data) { if (String.IsNullOrEmpty(data) == true) DLL_UserMgr_GetUserListID(IntPtr.Zero); else { IntPtr pID = Marshal.StringToBSTR(data); DLL_UserMgr_GetUserListID(pID); } } public static void UserManager_UserAdd(String sID, String sPW, int fAdmin, int expire_period_pw, int expire_period_account, int active_level, DateTime_t password_date, DateTime_t account_date) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sPW.ToString()); DLL_UserMgr_UserAdd(pID, pPW, fAdmin, expire_period_pw, expire_period_account, active_level, password_date, account_date); } public static void UserManager_UserNew(String sID, String sPW, int fAdmin, int expire_period_pw, int expire_period_account, int active_level, MenuID_t menuId) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sPW.ToString()); IntPtr pMenuId = Marshal.AllocHGlobal(Marshal.SizeOf(menuId)); Marshal.StructureToPtr(menuId, pMenuId, false); DLL_UserMgr_UserNew(pID, pPW, fAdmin, expire_period_pw, expire_period_account, active_level, pMenuId); } public static void UserManager_UserAddHistoryPW(String sID, String sHistoryPW) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sHistoryPW.ToString()); DLL_UserMgr_UserAddHistoryPW(pID, pPW); } public static void UserManager_UserResetHistoryPW(String sID) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_UserResetHistoryPW(pID); } public static void UserManager_UserModify(String sID, String sPW, int fAdmin, int expire_period_pw, int expire_period_account, int active_level, MenuID_t menuId) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sPW.ToString()); IntPtr pMenuId = Marshal.AllocHGlobal(Marshal.SizeOf(menuId)); Marshal.StructureToPtr(menuId, pMenuId, false); DLL_UserMgr_UserModify(pID, pPW, fAdmin, expire_period_pw, expire_period_account, active_level, pMenuId); } public static void UserManager_UserModifyPW(String sID, String sNewPW) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sNewPW.ToString()); DLL_UserMgr_UserModifyPW(pID, pPW); } public static void UserManager_UserModifyID(String sID, String sNewID) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pNewID = Marshal.StringToBSTR(sNewID.ToString()); DLL_UserMgr_UserModifyID(pID, pNewID); } public static void UserManager_UserModifyOthers(String sID, int fadmin, int period_expire_pw, int period_expire_account, int active_level) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_UserModifyOthers(pID, fadmin, period_expire_pw, period_expire_account, active_level); } public static void UserManager_UserDel(String sID) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_UserDel(pID); } public static void UserManager_UserAllDel() { DLL_UserMgr_UserAllDel_Default(); } public static void UserManager_UserLockRelease(String sID, bool lock_account, bool lock_password) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_UserLockRelease(pID, lock_account, lock_password); } public static void UserManager_UserLockGet(String sID) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_UserLockGet(pID); } public static void UserManager_UserLoginCB(String sID, String sPW) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sPW.ToString()); DLL_UserMgr_UserLoginCB(pID, pPW); } public static void UserManager_UserLoginDirect(string sID, string sPW, ref UserMgr_user_info_t user_info) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); IntPtr pPW = Marshal.StringToBSTR(sPW.ToString()); DLL_UserMgr_UserLoginDirect(pID, pPW, ref user_info); } public static void UserManager_UserLogout() { DLL_UserMgr_UserLogout(); } public static void UserManager_AutoLogoutTimeoutReset() { DLL_UserMgr_AutoLogoutTimeoutReset(); } public static void UserManager_AutoLogoutTimeoutPause() { DLL_UserMgr_AutoLogoutTimeoutPause(); } public static void UserManager_AutoLogoutSetTimeout(int timeout_min, int warning_timeout_sec) { DLL_UserMgr_AutoLogoutSetTimeout(timeout_min, warning_timeout_sec); } public static void UserManager_GetUserList(int index) { DLL_UserMgr_GetUserList(index); } public static void UserManager_GetUserListID(String sID) { IntPtr pID = Marshal.StringToBSTR(sID.ToString()); DLL_UserMgr_GetUserListID(pID); } public static void UserManager_GetUserListName() { DLL_UserMgr_GetUserListName(); } #endregion #region UM_CALLBACK private static void UserManager_GetListNameCallBack(ref UserMgr_user_list_name_t user_name) { try { if (UserListGetListNameDataEvent != null) UserListGetListNameDataEvent(user_name); } catch { } } private static void UserManager_GetListCallBack(ref UserMgr_user_list_t user_list) { try { if (UserListGetListDataEvent != null) UserListGetListDataEvent(user_list); } catch { } } private static void UserManager_LoginTimeoutCallBack(ref UserMgr_login_timeout_t timeout) { try { if (UserListLoginTimeoutDataEvent != null) UserListLoginTimeoutDataEvent(timeout); } catch { } } private static void UserManager_LogoutCallBack(int status) { try { if (UserListLogoutDataEvent != null) UserListLogoutDataEvent(status); } catch { } } private static void UserManager_LoginCallBack(int status, IntPtr pBuffer) { try { if (UserListLoginDataEvent != null) UserListLoginDataEvent(status, pBuffer); } catch { } } private static void UserManager_LockCallBack(ref UserMgr_user_lock_t user_lock) { try { if (UserListLockDataEvent != null) UserListLockDataEvent(user_lock); } catch { } } private static void UserManager_DefaultSettingCallBack(int status) { try { if (UserListDefautSettingDataEvent != null) UserListDefautSettingDataEvent(status); } catch { } } private static void UserManager_DelUserCallBack(ref UserMgr_user_del_t user_del) { try { if (UserListDeleteDataEvent != null) UserListDeleteDataEvent(user_del); } catch { } } private static void UserManager_ModifyUserCallBack(ref UserMgr_user_modify_t user_mod) { try { if (UserListModifyUserDataEvent != null) UserListModifyUserDataEvent(user_mod); } catch { } } private static void UserManager_ModifyInfoCallBack(ref UserMgr_user_info_t user_info) { try { if (UserListModifyInfoDataEvent != null) UserListModifyInfoDataEvent(user_info); } catch { } } private static void UserManager_AddUserCallBack(ref UserMgr_user_add_t user_add) { try { if (UserListAddDataEvent != null) UserListAddDataEvent(user_add); } catch { } } private static void UserManager_NewUserCallBack(IntPtr pBuffer) { try { if (pBuffer != IntPtr.Zero) { UserMgr_user_info_t user_info = (UserMgr_user_info_t)Marshal.PtrToStructure(pBuffer, typeof(UserMgr_user_info_t)); if (UserListNewDataEvent != null) UserListNewDataEvent(user_info); } } catch { } } private static void UserManager_DebugCallback(int type, StringBuilder pMessage) { try { } catch { } } #endregion } }