Ejemplo n.º 1
0
        public bool Logon(string userName, string password, System.Net.Sockets.TcpClient connection, out LogonModel.User logonUser, out string errorCode)
        {
            logonUser = null;
            errorCode = string.Empty;
            var originalEmployee = EmployeeService.QueryEmployee(userName);

            if (originalEmployee == null)
            {
                errorCode = "1";
                return(false);
            }
            if (originalEmployee.UserPassword != Utility.MD5EncryptorService.MD5FilterZero(password, "utf-8"))
            {
                errorCode = "4";
                return(false);
            }
            if (!originalEmployee.Enabled)
            {
                errorCode = "5";
                return(false);
            }
            var originalCompany = CompanyService.GetCompanyDetail(originalEmployee.Owner);

            if (originalCompany == null)
            {
                errorCode = "6";
                return(false);
            }
            if (!originalCompany.Enabled)
            {
                errorCode = "7";
                return(false);
            }
            if (originalCompany.CompanyType == CompanyType.Platform)
            {
                errorCode = "8";
                return(false);
            }
            var isExpired = false;

            if (originalCompany.PeriodStartOfUse.HasValue)
            {
                isExpired |= originalCompany.PeriodStartOfUse.Value.Date > DateTime.Today;
            }
            if (originalCompany.PeriodEndOfUse.HasValue)
            {
                isExpired |= originalCompany.PeriodEndOfUse.Value.Date < DateTime.Today;
            }
            var companyType = CompanyType.Purchaser;

            if (originalCompany.Audited || !isExpired)
            {
                companyType = originalCompany.CompanyType;
            }
            LogonModel.Company company = null;
            if (!m_companies.TryGetValue(originalCompany.CompanyId, out company))
            {
                company = new LogonModel.Company(originalCompany.CompanyId)
                {
                    Name = originalCompany.AbbreviateName,
                    Type = companyType
                };
                m_companies.Add(company.Id, company);
            }
            logonUser = new LogonModel.User(originalEmployee.Id, connection)
            {
                Name           = userName,
                Owner          = company,
                WorkOnCustomNO = originalCompany.CustomNO_On
            };
            if (logonUser.WorkOnCustomNO)
            {
                logonUser.CustomNOs = string.Join(",", CompanyService.GetCustomNumberByEmployee(originalEmployee.Id).Select(c => c.Number));
            }
            company.RegisterMember(logonUser);
            m_users.Add(logonUser.BatchNo, logonUser);
            DataProcessor.Instance.Start();
            return(true);
        }
Ejemplo n.º 2
0
 public LogonModel.Company GetCompany(Guid company)
 {
     LogonModel.Company result = null;
     m_companies.TryGetValue(company, out result);
     return(result);
 }