Example #1
0
        /// <summary>
        /// Search Data in UserState table
        /// </summary>
        /// <param name="iDto">
        /// Dto of UserState form
        /// </param>
        /// <param name="dtResult">
        /// Out a Datatable that contains search result(all columns) in UserState table
        /// </param>
        /// <returns>
        /// 0: Update successful
        /// 1: Access denied, login to database fail(invalid username, invalid password)
        /// 2: Invalid host, cannot find server(host) that set in app config file
        /// 3: Invalid database, cannot find database that set in DbConfig file
        /// 4: Lost connection, cannot connect to database because lost connection
        /// 5: Duplicate key: insert Primary Key or Unique Key that already exist in database
        /// 6: Forgeign key not exist: insert a foreign key that not exist in primary key
        /// 7: Foreign Key Violation: Foreign Key Violation (delete primary key that is foreign key in other table)
        /// 8: Data not found: Delete or Update data that not exist in database
        /// 9: Exception occured: other exception
        /// </returns>
        public int SearchData(IDto searchDto, out DataTable dtResult)
        {
            SYS_UserStateDao dao = new SYS_UserStateDao();
            SYS_UserStateDto dto = (SYS_UserStateDto)searchDto;

            return(dao.SelectData(dto, out dtResult));
        }
Example #2
0
        /// <summary>
        /// Search Data in ms_ItemGroup table
        /// </summary>
        /// <param name="selectDto">
        /// Dto that contains conditions: Code, Name(VN), Name(EN), Name(JP), Type
        /// </param>
        /// <param name="dtResult">
        /// Out a Datatable that contains search result(all columns) in ms_ItemGroup table
        /// </param>
        /// <returns>
        /// 0: Search successful
        /// others: Sql Exception
        /// </returns>
        public int SelectData(SYS_UserStateDto selectDto, out DataTable dtResult)
        {
            int returnCode = CommonData.DbReturnCode.Succeed;

            dtResult = new DataTable();
            using (BaseDao context = new BaseDao())
            {
                try
                {
                    IQueryable <ms_users> lstUsers = context.ms_users.AsQueryable();

                    #region Search Condition

                    //Filter by Code
                    if (!CommonMethod.IsNullOrEmpty(selectDto.Code))
                    {
                        lstUsers = lstUsers.Where(ig => ig.Code.Contains(selectDto.Code));
                    }

                    //Filter by IPAddress
                    if (!CommonMethod.IsNullOrEmpty(selectDto.IPAddress))
                    {
                        lstUsers = lstUsers.Where(ig => ig.IPAddress.Contains(selectDto.IPAddress));
                    }

                    //Filter by ComputerName
                    if (!CommonMethod.IsNullOrEmpty(selectDto.ComputerName))
                    {
                        lstUsers = lstUsers.Where(ig => ig.ComputerName.Contains(selectDto.ComputerName));
                    }

                    //Filter by UserState
                    if (!CommonMethod.IsNullOrEmpty(selectDto.LogonState))
                    {
                        lstUsers = lstUsers.Where(ig => ig.LogonState == selectDto.LogonState);
                        //if (selectDto.UserState == CommonData.UserState.Online)
                        //{
                        //    lstUsers = lstUsers.Where(ig => ig.IPAddress != CommonData.StringEmpty && ig.IPAddress != null);
                        //}
                        //else if (selectDto.UserState == CommonData.UserState.Offine)
                        //{
                        //    lstUsers = lstUsers.Where(ig => ig.IPAddress == CommonData.StringEmpty || ig.IPAddress == null);
                        //}
                    }

                    #endregion Search Condition

                    #region Search data

                    IEnumerable <SYS_UserStateDto> lstResult = lstUsers.Select(ig => new SYS_UserStateDto
                    {
                        ID           = ig.ID,
                        Code         = ig.Code,
                        DisplayName  = ig.DisplayName,
                        IPAddress    = ig.IPAddress,
                        ComputerName = ig.ComputerName,
                        LogonState   = ig.LogonState,
                    });

                    dtResult = base.ToDataTable(lstResult);

                    #endregion Search data
                }
                catch (Exception ex)
                {
                    returnCode = this.ProcessDbException(ex);
                }
            }
            return(returnCode);
        }