Exemplo n.º 1
0
        /// <summary>
        /// 检索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void search_button_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

                // 检索条件对象
                DBSearchCondition condition = new DBSearchCondition();
                if (search_id_numericUpDown.Text.Trim() != "")
                {
                    condition.m_iTfsId = int.Parse(search_id_numericUpDown.Text.Trim());
                }
                condition.m_strGroupName = search_group_comboBox.Text.Trim();
                condition.m_strCoder     = search_code_textBox.Text.Trim();
                condition.m_strReviewer  = search_review_textBox.Text.Trim();

                string strDate = search_start_dateTimePicker.Text.Trim();
                condition.m_strReviewDateStart = DateTime.Parse(strDate).ToShortDateString();
                strDate = search_end_dateTimePicker.Text.Trim();
                condition.m_strReviewDateEnd = DateTime.Parse(strDate).ToShortDateString();

                // 检索数据库信息
                MySqlDataReader reader = DatabaseInterface.SearchRecord(condition);
                if (reader.HasRows == false)
                {
                    this.record_listView.Items.Clear();
                    this.Cursor = System.Windows.Forms.Cursors.Arrow;
                    MainForm.WarningMessage("没有检索到数据!");
                    return;
                }

                // 填充List
                this.FillList(reader);
                reader.Close();

                this.Cursor = System.Windows.Forms.Cursors.Arrow;
            }
            catch (System.Exception ex)
            {
                this.Cursor = System.Windows.Forms.Cursors.Arrow;
                MainForm.ErrorMessage(ex.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询记录
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static MySqlDataReader SearchRecord(DBSearchCondition condition)
        {
            StringBuilder         sb        = new StringBuilder();
            List <MySqlParameter> paramList = new List <MySqlParameter>();

            try
            {
                sb.Append("SELECT * FROM review_record_tbl");

                sb.Append(" WHERE ");
                if (condition.m_iId != -1)
                {
                    sb.Append("id = ?id AND ");
                    MySqlParameter param = new MySqlParameter("?id", MySqlDbType.Int32);
                    param.Value = condition.m_iId;
                    paramList.Add(param);
                }
                if (condition.m_iTfsId != -1)
                {
                    sb.Append("tfs_id = ?tfs_id AND ");
                    MySqlParameter param = new MySqlParameter("?tfs_id", MySqlDbType.Int32);
                    param.Value = condition.m_iTfsId;
                    paramList.Add(param);
                }
                if (condition.m_strGroupName != "")
                {
                    sb.Append("group_name = ?group_name AND ");
                    MySqlParameter param = new MySqlParameter("?group_name", MySqlDbType.String);
                    param.Value = condition.m_strGroupName;
                    paramList.Add(param);
                }
                if (condition.m_strCoder != "")
                {
                    sb.Append("coder = ?coder AND ");
                    MySqlParameter param = new MySqlParameter("?coder", MySqlDbType.String);
                    param.Value = condition.m_strCoder;
                    paramList.Add(param);
                }
                if (condition.m_strReviewer != "")
                {
                    sb.Append("reviewer = ?reviewer AND ");
                    MySqlParameter param = new MySqlParameter("?reviewer", MySqlDbType.String);
                    param.Value = condition.m_strReviewer;
                    paramList.Add(param);
                }
                if (condition.m_strReviewDateStart != "")
                {
                    sb.Append("Date(review_date) >= Date(?review_date) AND ");
                    MySqlParameter param = new MySqlParameter("?review_date", MySqlDbType.Date);
                    param.Value = condition.m_strReviewDateStart.ToString();
                    paramList.Add(param);
                }
                if (condition.m_strReviewDateEnd != "")
                {
                    sb.Append("Date(review_date) <= Date(?review_date_end) AND ");
                    MySqlParameter param = new MySqlParameter("?review_date_end", MySqlDbType.Date);
                    param.Value = condition.m_strReviewDateEnd;
                    paramList.Add(param);
                }
                sb.Append(" 1 = 1 ");

                //排序
                sb.Append(" ORDER BY id");
                return(SQLHelper.ExecuteReader(sb.ToString(), CommandType.Text, paramList.ToArray()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }