コード例 #1
0
        private void VerifiyUser()
        {
            if (CompanySyncProcess.GetSyncProcessEnum(CompanySyncProcess.NoCompany, EnumSyncType.System) != EnumSyncProcess.NotSyncing)
            {
                GuiCommon.ShowMessage("First time use or sync broken, need to Sync Users.");
                btnSync.Focus();
                return;
            }

            if (teUsername.EditValue == null)
            {
                GuiCommon.ShowMessage("Please enter a user name.");
                return;
            }

            if (tePassword.EditValue == null)
            {
                GuiCommon.ShowMessage("Please enter a password.");
                return;
            }

            IntPtr userHandle = IntPtr.Zero;
            bool   winValid   = LogonUser(teUsername.EditValue.ToString(),
                                          System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName,
                                          tePassword.EditValue.ToString(),
                                          2, 0, ref userHandle);

            if (!winValid)
            {
                GuiCommon.ShowMessage("Failed in windows authentication. Incorrect Username/Password.");
                return;
            }

            int?id = LoginUser.ValidUser(teUsername.EditValue.ToString());

            if (id == null)
            {
                GuiCommon.ShowMessage("Cannot find this user.");
                return;
            }
            else
            {
                LoginUser.CurrUser = LoginUser.GetUser(id.Value);
                DataManage.UpdateCodeVersion();
                if (LoginUser.MaxCodeVersion() != LoginUser.CurrUser.CodeVersion)
                {
                    GuiCommon.ShowMessage("Code verion is not correct, please log out and restart.");
                    return;
                }

                luCompany.Properties.DataSource = Company.List.Where(x => LoginUser.CurrUser.AccessList.Select(a => a.CompanyId).Contains(x.MatchId)).Select(x => new { CompanyID = x.MatchId, CompanyName = x.CompanyName });
                if (LoginUser.CurrUser.AccessList.Count == 1)
                {
                    luCompany.ItemIndex = 0;//autoload the only company
                }
            }
        }