示例#1
0
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            lstSearchResult.Visible = false;
            var name = txtSearchProject.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                lblStatusTips.Visible = true;
                lblStatusTips.Text    = "请输入楼盘名称";
                txtSearchProject.Focus();
                return;
            }

            Reset();
            lblStatusTips.Text       = "正在获取楼盘...";
            btnStart.Enabled         = false;
            txtSearchProject.Enabled = false;
            new Task(() =>
            {
                try
                {
                    var pInfo = MainHelper.GetProjectInfo(index_city, name);
                    if (pInfo != null)
                    {
                        if (pInfo.address.Length > 20)
                        {
                            pInfo.address = pInfo.address.Substring(0, 20) + "...";
                        }
                        Invoke(new Action(() =>
                        {
                            lblProjectName.Text   = "楼盘:[" + pInfo.name + "]";
                            lblAddess.Text        = "地址:" + pInfo.address;
                            lblStatusTips.Visible = true;
                            lblStatusTips.Text    = "正在获取评论...";
                            lblPrice.Text         = "价格:" + (pInfo.price == "" ? "暂无" : pInfo.price);
                        }));
                        List <CommentInfo> all_comment = new List <CommentInfo>();
                        dic_tag = MainHelper.GetCommentInfo(name, out all_comment);
                        ShowTag(all_comment);
                        Invoke(new Action(() =>
                        {
                            lblStatusTips.Text = "评论获取完成";
                        }));
                    }
                    else
                    {
                        Invoke(new Action(() =>
                        {
                            lblStatusTips.Visible    = true;
                            lblStatusTips.Text       = "找不到该楼盘";
                            btnStart.Enabled         = true;
                            txtSearchProject.Enabled = true;
                        }));
                    }
                }
                catch (Exception ex)
                {
                    Invoke(new Action(() =>
                    {
#if DEBUG
                        MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace, "异常消息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
#else
                        MessageBox.Show(ex.Message + "\r\n 请重新尝试", "异常消息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
#endif
                        btnStart.Enabled         = true;
                        txtSearchProject.Enabled = true;
                        lblStatusTips.Text       = "获取评论失败";
                    }));
                }
            }).Start();
        }