传智HRMS条件搜索

     private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            List<string> whereList = new List<string>();
            List<SqlParameter>paramslist=new List<SqlParameter>();
            if(cbSearchByOperator.IsChecked==true)
            {
                if (cmbOperator.SelectedIndex < 0)
                {
                    MessageBox.Show("请选择操作员");
                }
                whereList.Add("OperatorId=@OperatorId");
                paramslist.Add(new SqlParameter("@OperatorId", cmbOperator.SelectedValue));
            }
            if (cbSearchByMakeDate.IsChecked == true)
            {
                whereList.Add("MakeDate Between @BeginDate and @EndDate");
                paramslist.Add(new SqlParameter("@BeginDate",dpBeginDate.SelectedDate));
                paramslist.Add(new SqlParameter("@EndDate", dpEndDate.SelectedDate));
            }
            if (cbSearchByAction.IsChecked == true)
            {
                whereList.Add("ActionDesc like @ActionDesc");
                paramslist.Add(new SqlParameter("@ActionDesc",
                    "%"+txtAcionDesc.Text+"%"));
            }
            if (whereList.Count <= 0)
            {
                MessageBox.Show("至少选择一个查询条件");
            }
            string sql = "select * from T_OperationLog where "
                + string.Join(" and ", whereList);//whereList是一个字符串,它保存了查询条件
            T_OperationLog[] logs =
                           new T_OperationLogDAL().Search(sql, paramslist.ToArray());//转为数组类型
            datagrid.ItemsSource = logs;
        }
posted @ 2015-07-29 19:04  Alfred.Xu  阅读(172)  评论(0编辑  收藏  举报