Exemple #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "")
            {
                MessageBox.Show("请输入供应商编号后再查询!", "提示");
                return;
            }

            try
            {
                supplierIDSearch = txtSearch.Text.Trim();

                s = supplierBLL.FindByID(supplierIDSearch);
                list.Add(s);
                //将查询到的结果填充到
                dgSupplierInfo.DataSource = list;

                //把上一次查找到的行取消反蓝色显示
                dgSupplierInfo.Rows[currentRowsIndex].Selected = false;

                //找到查询的项的索引值(获取索引值)
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].SupplierID == s.SupplierID)
                    {
                        //查找到的行反蓝色显示
                        dgSupplierInfo.Rows[i].Selected = true;
                        currentRowsIndex = i;

                        //自动跳转到查找到的行
                        dgSupplierInfo.FirstDisplayedScrollingRowIndex = currentRowsIndex;
                        break;
                    }
                }
                //当更新按钮 或者 删除按钮被单击时 执行赋值语句
                if (op == Operation.UPDATE || op == Operation.DELETE)
                {
                    //给控件赋值(封装为方法)
                    SetValueToTextBox();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("没有该记录!", "提示");
            }
        }
Exemple #2
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            string seach = ""; //存储查询条件

            try
            {
                if (cbQuery.SelectedIndex == 0)
                {
                    BindData();
                    return;
                }
                else if (cbQuery.SelectedIndex == 1)
                {
                    seach = txtQueryValue.Text.Trim(); //从文本框取出查询值
                    if (seach == "")                   //判断是否为空
                    {
                        MessageBox.Show("请输入查询值!");
                        txtQueryValue.Focus();
                        return;
                    }
                    s = sBLL.FindByID(seach);
                    if (s != null)
                    {
                        list = new List <Supplier>();
                        list.Add(s);
                        dgSupplierInfo.DataSource = null;
                        dgSupplierInfo.DataSource = list;
                        if (list.Count > 0)
                        {
                            dgSupplierInfo.CurrentCell.Selected = false; //取消反蓝
                        }
                        return;
                    }
                    else
                    {
                        MessageBox.Show("没有查询到记录!");
                        txtQueryValue.Text = "";
                        txtQueryValue.Focus();
                        return;
                    }
                }
                else if (cbQuery.SelectedIndex == 2)
                {
                    seach = txtQueryValue.Text.Trim(); //从文本框取出查询值
                    if (seach == "")                   //判断是否为空
                    {
                        MessageBox.Show("请输入查询值!");
                        txtQueryValue.Focus();
                        return;
                    }
                    list = sBLL.FindByName(txtQueryValue.Text.Trim());
                    if (list == null)
                    {
                        MessageBox.Show("没有查询到记录!");
                        txtQueryValue.Text = "";
                        txtQueryValue.Focus();
                        return;
                    }
                    if (list.Count > 0)
                    {
                        dgSupplierInfo.DataSource           = null;
                        dgSupplierInfo.DataSource           = list;
                        dgSupplierInfo.CurrentCell.Selected = false; //取消反蓝
                        return;
                    }
                    else
                    {
                        MessageBox.Show("没有查询到记录!");
                        txtQueryValue.Text = "";
                        txtQueryValue.Focus();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }