Пример #1
0
        public List <userModel> search(userModel data)
        {
            if (BaseData.Connection.State == System.Data.ConnectionState.Closed)
            {
                BaseData.Connection.Open();
            }

            string query = "SELECT top 20  * from users where 1=1 ";

            if (data.name != "")
            {
                query += " and name like '%" + data.name + "%'";
            }

            if (data.family != "")
            {
                query += " and family like '%" + data.family + "%'";
            }

            if (data.melli != "")
            {
                query += " and melli like '%" + data.melli + "%'";
            }

            if (data.location != "")
            {
                query += " and location like '%" + data.location + "%'";
            }


            if (data.id > 0)
            {
                query += " and id= " + data.id;
            }

            if (data.userType != UserType.Administrator)
            {
                query += " and user_type =" + (int)data.userType;
            }

            SqlCeCommand command = new SqlCeCommand(query, BaseData.Connection);
            var          reader  = command.ExecuteReader();

            List <userModel> result = new List <userModel>();

            while (reader.Read())
            {
                result.Add(map(reader));
            }

            BaseData.Connection.Close();
            return(result);
        }
Пример #2
0
        public userModel map(SqlCeDataReader reader)
        {
            userModel result = new userModel();

            try
            {
                result.id       = Convert.ToInt16(reader["id"]);
                result.name     = reader["name"].ToString();
                result.family   = reader["family"].ToString();
                result.userName = reader["userName"].ToString();
                result.melli    = reader["melli"].ToString();
                result.carPelak = reader["car_pelak"].ToString();
                result.address  = reader["address"].ToString();
                result.location = reader["location"].ToString();

                result.userType = (UserType)reader["User_type"];
            }
            catch
            {
            }
            return(result);
        }