Monday 10 September 2012

EP lookup filterization with two ranges

protected void Item_Lookup(object sender, AxLookupEventArgs e)
    {
        // Boundfield is the sender
        AxBoundField field = (AxBoundField)sender;

        // The underlying control in this case is the lookup control
        AxLookup lookup = e.LookupControl;
        String lookupTable;
        string field_storeAreaId;
        string field_ItemId;
        string field_InventLocationId;
        string field_SiteId;
        string field_ItemName;
        lookupTable = "ItemStoreCombination";
        field_storeAreaId = "storeAreaId";
        field_InventLocationId = "InventLocationId";
        field_ItemId = "ItemId";
        field_SiteId = "SiteId";
        field_ItemName = "ItemName";



        using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, lookupTable)))
        {
            lookup.LookupDataSet = new DataSet(this.AxSession, sysDataSetBuilder.toDataSet());

            // DataSet has to be init'ed before accessing the data sources
            lookup.LookupDataSet.Init();



            // Specify the lookup fields used
            lookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, lookup.LookupDataSetViewMetadata.ViewFields[field_ItemId]));
            lookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, lookup.LookupDataSetViewMetadata.ViewFields[field_ItemName]));
            lookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, lookup.LookupDataSetViewMetadata.ViewFields[field_SiteId]));
            lookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, lookup.LookupDataSetViewMetadata.ViewFields[field_InventLocationId]));
            DataSetViewRow ItemTableRow = this.AxDataSource2.GetDataSourceView("InventRequestLine").DataSetView.GetCurrent();
            if (ItemTableRow!= null)
            {
                using (IAxaptaRecordAdapter record = ItemTableRow.GetRecord())
                {
                    if (record != null)
EP Lookup Filterization



                    {
                        // Filter the lookup
                        using (Proxy.Query query = lookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
                        {
                            using (Proxy.QueryBuildDataSource dataSource = query.dataSourceNo(1))
                            {
                                using (Proxy.QueryBuildRange range = dataSource.addRange(
                                    TableDataFieldMetadata.FieldNum(AxSession, "ItemStoreCombination", "InventLocationId")))
                                using (Proxy.QueryBuildRange range2 = dataSource.addRange(
                                    TableDataFieldMetadata.FieldNum(AxSession, "ItemStoreCombination", "storeAreaId")))
                                {
                                    range.status = (int)Proxy.RangeStatus.Hidden;
                                    range.value = (string)record.GetField("InventLocationId");
                                    range2.status = (int)Proxy.RangeStatus.Hidden;
                                    range2.value = (string)record.GetField("storeAreaId");
                                }
                            }
                          

                        }
                    }
                }

            }


        }
        // Specify the select field
        lookup.SelectField = field_ItemId;

    }