public UserInfoEntity[] FindUsers(UserInfoSearchCriteria userInfoSearchCriteria)
        {
            if (userInfoSearchCriteria == null) return new UserInfoEntity[] { };
            DataTable dt = new DataTable();
            DbHelper helper = new DbHelper();

            DbCommand command = helper.BuildDbCommand("P_IC_USER_INFO_SEARCH");

            var appName = NCS.IConnect.Security.ExtendedMembership.ApplicationName;
            helper.AssignParameterValues(
                command,
                SearchHelper.TranslateWildcard(userInfoSearchCriteria.UserName),
                SearchHelper.TranslateWildcard(userInfoSearchCriteria.UserStatus),
                userInfoSearchCriteria.CreatedFrom,
                userInfoSearchCriteria.CreatedTo,
                SearchHelper.TranslateWildcard(userInfoSearchCriteria.Display),
                SearchHelper.TranslateWildcard(userInfoSearchCriteria.Email),
                userInfoSearchCriteria.UserType,
                SearchHelper.TranslateWildcard(userInfoSearchCriteria.Office),
                appName
                );
            Helper.Fill(dt, command);

            Dictionary<string, UserInfoEntity> arrayList = new Dictionary<string, UserInfoEntity>();
            const string Yes = "Y";

            DataRow[] matchedRecords = dt.Select(string.Format("IS_MASTER='{0}'", Yes));

            //1. add the records that is the default office
            foreach (DataRow row in matchedRecords)
            {
                string userId = row["USER_ID"].ToString();
                //if (!(string.IsNullOrEmpty(userInfoSearchCriteria.Office)
                //    || SearchHelper.IsRegexMatch(row["DEFAULT_OFFICE"].ToString(), userInfoSearchCriteria.Office, @"\w|\W")))
                //{
                //    //Not match office criteria
                //    continue;
                //}
                if (arrayList.ContainsKey(userId))
                {
                    //Duplicated
                    continue;
                }
                arrayList.Add(userId, CreatEntity(row));
            }

            //2.Union the records that have no default office

            matchedRecords = dt.Select(string.Format("IS_MASTER<>'{0}'",Yes));

            foreach (DataRow row in matchedRecords)
            {
                string userId = row["USER_ID"].ToString();
                //if (!(string.IsNullOrEmpty(userInfoSearchCriteria.Office)
                //   || SearchHelper.IsRegexMatch(row[""].ToString(), userInfoSearchCriteria.Office, @"\w|\W")))
                //{
                //    //Not match office criteria
                //    continue;
                //}

                if (arrayList.ContainsKey(userId))
                {
                    //Duplicated or has default office records.
                    continue;
                }

                UserInfoEntity entity = CreatEntity(row);
            entity.Office = string.Empty;
                arrayList.Add(userId, entity);
            }

            //Compine all offices for every user
            foreach (KeyValuePair<string,UserInfoEntity> user in arrayList)
            {
                string userId = user.Key;
                matchedRecords = dt.Select(string.Format("USER_ID='{0}'", userId));
                StringBuilder allOffices = new StringBuilder();

                foreach (var row in matchedRecords)
                {
                    allOffices.Append(row["DEFAULT_OFFICE"].ToString());
                    allOffices.Append(",");
                }
                user.Value.AllOffices = allOffices.ToString().TrimEnd(',');
            }
            dt.Dispose();
            return arrayList.Values.ToArray<UserInfoEntity>();
        }
Exemplo n.º 2
0
        private UserInfoSearchCriteria GetSearchCriteria()
        {
            UserInfoSearchCriteria userInfoSearchCriteria = new UserInfoSearchCriteria();
            userInfoSearchCriteria.UserName = this.txt_username.Text;
            if (this.cb_status.Value != null)
            {
                userInfoSearchCriteria.UserStatus = this.cb_status.Value.ToString();
            }
            else
            {
                // For exception handler
                userInfoSearchCriteria.UserStatus = String.Empty;
            }
            if (this.dt_createdfrom.Value != null)
            {
                userInfoSearchCriteria.CreatedFrom = this.dt_createdfrom.DateTime;
            }
            else
            {
                userInfoSearchCriteria.CreatedFrom = this.dt_createdfrom.MinDate;
            }
            if (this.dt_createdto.Value != null)
            {
                userInfoSearchCriteria.CreatedTo = this.dt_createdto.DateTime;
            }
            else
            {
                userInfoSearchCriteria.CreatedTo = this.dt_createdto.MaxDate;
            }
            userInfoSearchCriteria.Display = this.txt_display.Text;
            userInfoSearchCriteria.Email = this.txt_email.Text;

            userInfoSearchCriteria.UserType = (this.cb_userType.Value == DBNull.Value) ? null : (this.cb_userType.Value as bool?);

            userInfoSearchCriteria.Office = this.txt_office.Text;

            return userInfoSearchCriteria;
        }