Exemplo n.º 1
0
        //TODO:传Sql语句,需要改进
        private void Search_Click(object sender, EventArgs e)
        {
            #region  条件搜索公告

            if (CheckCookie())
            {
                StringBuilder builder = new StringBuilder();
                if (!poster.Text.Equals(""))
                {
                    builder.Append("[poster] LIKE '%");
                    builder.Append(poster.Text);
                    builder.Append("%'");
                }

                if (!title.Text.Equals(""))
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" AND ");
                    }
                    builder.Append("[title] LIKE '%");
                    builder.Append(title.Text);
                    builder.Append("%'");
                }

                if (!postdatetimeStart.SelectedDate.ToString().Equals(""))
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" AND ");
                    }
                    builder.Append("[starttime] >= '");
                    builder.Append(postdatetimeStart.SelectedDate.ToString());
                    builder.Append("'");
                }

                if (!postdatetimeEnd.SelectedDate.AddDays(1).ToString().Equals(""))
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" AND ");
                    }
                    builder.Append("[starttime] <= '");
                    builder.Append(postdatetimeEnd.SelectedDate.ToString());
                    builder.Append("'");
                }

                if (builder.Length > 0)
                {
                    builder.Insert(0, " WHERE ");
                }
                DataGrid1.BindData(Announcements.GetAnnouncementsByCondition(builder.ToString()));
            }

            #endregion
        }