Exemplo n.º 1
0
        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            string         key = null;
            Nullable <int> loaiHang = null, slTonTu = null, slTonDen = null, slQuayTu = null, slQuayDen = null;

            if (cheKey.Checked == true)
            {
                if (sctKey.Text != "")
                {
                    key = sctKey.Text;
                }
            }
            if (cheLoai.Checked == true)
            {
                if (lueLoaiHang.Text.Trim() != "")
                {
                    DataRowView row = lueLoaiHang.Properties.GetDataSourceRowByKeyValue(lueLoaiHang.EditValue) as DataRowView;
                    try
                    {
                        loaiHang = int.Parse(row.Row["MaLoaiHang"].ToString());
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Không thể lấy mã loại!");
                        return;
                    }
                }
            }
            if (cheSLTon.Checked == true)
            {
                if (cbbSLTonTu.Text != "")
                {
                    try
                    {
                        slTonTu = int.Parse(cbbSLTonTu.Text);
                    }
                    catch (Exception)
                    {
                    }
                }
                if (cbbSLTonDen.Text != "")
                {
                    try
                    {
                        slTonDen = int.Parse(cbbSLTonDen.Text);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (cheSLQuay.Checked == true)
            {
                if (cbbSLQuayTu.Text != "")
                {
                    try
                    {
                        slQuayTu = int.Parse(cbbSLQuayTu.Text);
                    }
                    catch (Exception)
                    {
                    }
                }
                if (cbbSLQuayDen.Text != "")
                {
                    try
                    {
                        slQuayDen = int.Parse(cbbSLQuayDen.Text);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (key == null && loaiHang == null && slTonTu == null && slTonDen == null && slQuayTu == null && slQuayDen == null)
            {
                grcHangHoa.DataSource = HangHoaService.LoadDataTable();
            }
            else
            {
                grcHangHoa.DataSource = HangHoaService.Search1(key, loaiHang, slTonTu, slTonDen, slQuayTu, slQuayDen);
            }
        }