Beispiel #1
0
        private void btn_SearchArticle_Click(object sender, EventArgs e)
        {
            if (loadingThread != null && loadingThread.IsAlive)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(tb_SearchGalleryID.Text))
            {
                tb_SearchGalleryID.Focus();
                SetStatusMessage("검색할 갤러리 ID를 입력해주세요.");
                return;
            }

            if (string.IsNullOrWhiteSpace(tb_SearchNickName.Text))
            {
                tb_SearchNickName.Focus();
                SetStatusMessage("검색할 닉네임을 입력해주세요.");
                return;
            }

            // 기존 검색목록 삭제
            dgv_SearchArticle.Rows.Clear();
            if (searchedList != null)
            {
                searchedList.Clear();
            }
            else
            {
                searchedList = new List <ArticleInfo>();
            }

            string gall_id, nickname;

            gall_id  = tb_SearchGalleryID.Text.Trim();
            nickname = tb_SearchNickName.Text.Trim();
            GalleryType gallType = GalleryType.Normal;

            if (rb_NormalGallery.Checked)
            {
                gallType = GalleryType.Normal;
            }
            else if (rb_MinorGallery.Checked)
            {
                gallType = GalleryType.Minor;
            }

            loadingThread = new Thread(new ThreadStart(delegate()
            {
                int delay = 50;
                int pos   = 0;
                int page  = 1;
                bool cont = false;
                List <ArticleInfo> newSearchedList;

                lock (lockObject)
                {
                    isSearching = true;
                }

                while (pos != -1)
                {
                    try
                    {
                        newSearchedList = conn.SearchArticles(gall_id, gallType, nickname, ref pos, ref page, out cont);
                    }
                    catch (ThreadAbortException) { throw; }
                    catch (Exception ex)
                    {
                        lock (lockObject)
                        {
                            isSearching = false;
                            SetStatusMessage(ex.Message);
                        }

                        return;
                    }

                    searchedList.AddRange(newSearchedList);

                    this.Invoke(new Action(() =>
                    {
                        LoadSearchedList(newSearchedList);
                    }));

                    Thread.Sleep(delay);
                }

                this.Invoke(new Action(() =>
                {
                    lock (lockObject)
                    {
                        isSearching = false;
                        SetStatusMessage("검색된 글 목록을 불러왔습니다 - 총 " + dgv_SearchArticle.Rows.Count.ToString() + "개");
                    }
                }));
            }));

            SetStatusMessage("글 목록을 검색하는 중입니다...");

            loadingThread.Start();
        }