PO Box 1128 Yorktown Heights, NY 10598
+1 914-407-2442
+1 914-407-2432

Call a Custom Quick Search

To simply call a custom quick search on  a button click you can make a call to the InvokeAdapterMethod of the ProcessCaller library. The Quick Search Adapter implements the ShowQuickSearchForm method which when called will show you and let you execute a given Quick Search. This is the simplest way to call a Quick Search Form on demand, the resulting object will be either the selected key (if single select) or an ArrayList of all the selected values

object ret = ProcessCaller.InvokeAdapterMethod(oTrans.EpiBaseForm, ˮQuickSearchAdapterˮ, ˮShowQuickSearchFormˮ, new object[] {oTrans.EpiBaseForm, ˮYOURQUICKSEARCHNAMEˮ, false /* multi-select */, new DataTable() });
 
// user cancelled
if (ret == null) return;
 
// If multi-select, ret is an ArrayList whose elements are the selected values
 
// If single-select, ret is the selected value string
 
// Perform a native lookup with the returned result
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
opts.NamedSearch.WhereClauses.Add("ABCCode", string.Format("SysRowID='{0}'",ret.ToString()));
opts.DataSetMode = DataSetMode.RowsDataSet;
ABCCodeAdapter _adapter = (ABCCodeAdapter)csm.TransAdaptersHT["oTrans_adapter"];
_adapter.InvokeSearch(opts);
oTrans.NotifyAll();

There is a more advanced option which allows you to on the fly pre-filter the results that will be returned from the Quick Search. I do warn you though , this is not for the faint of heart. You will have to add references to your customization for the Adapter, Business Object and UI (User Interface) Dlls related to Quick Search Entry

sender = oTrans.EpiBaseForm;
QuickSearchAdapter _qdA = new QuickSearchAdapter(oTrans);
_qdA.BOConnect();
_qdA.GetByID("","ABCCodeNoA");
QuickSearchDataSet qsds = _qdA.QuickSearchData;
//I have a criteria item in my Quick Search that I  need to pass dynamically.
//so I look through all the criteria items until I find mine and I replace
//the CriteriaValue with the value I want to filter on.
foreach(QuickSearchDataSet.QuickSearchCriteriaRow r in qsds.QuickSearchCriteria)
{
    if(r.FieldName.Equals("ABCCode") && r.CriteriaType.Equals("Constant"))
    {
        r.CriteriaValue = txtFilter.Text;
        break;
    }
}
 
try
{
    using(QuickSearchPanel panel = _qdA.GetQuickSearchPanel(oTrans.EpiBaseForm))
    {
        if(panel !=null)
        {
            using(QuickSearchForm form = new QuickSearchForm(_qdA))
            {
                form.LastQS = "ABCCodeNoA";
                System.Reflection.MethodInfo mi = form.GetType().GetMethod("addQuickSearchPanel",System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                mi.Invoke(form, new object[]{panel});
 
                SearchOptions options = SearchOptions.CreateSearchForm(DataSetMode.ListDataSet);
                options.Sender = sender;
 
                options.SelectMode = SelectMode.SingleSelect;
                form.ShowDialog(new Ice.Lib.Searches.EpiSearchEngine((EpiBaseAdapter)_qdA),options);
                System.Reflection.FieldInfo fi = form.GetType().GetField("selectObject", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                object o= fi.GetValue(form);
                if(o!=null)
                {
 
                    //o is a String containing your returned key
                    //if multi select o is an ArrayList containing all selected keys.
                    if (o == null)
                           return;
                    SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
                    opts.NamedSearch.WhereClauses.Add("ABCCode", string.Format("SysRowID='{0}'",o.ToString()));
                    opts.DataSetMode = DataSetMode.RowsDataSet;
                    ABCCodeAdapter _adapter = (ABCCodeAdapter)csm.TransAdaptersHT["oTrans_adapter"];
                    _adapter.ClearData();
                    _adapter.InvokeSearch(opts);
                    oTrans.NotifyAll();
                    EpiDataView edvA = oTrans.Factory("ABCCode");
                    edvA.Row=0;
                    edvA.Notify(new EpiNotifyArgs(oTrans, 0, EpiTransaction.NotifyType.Initialize));
 
                }
            }
        }
    }
}
catch(Exception ex)
{
}

Related Posts

Leave a reply