Skip to main content

Filter Columns List using Textbox in Business Activity Manager

It was a god practice for me to customize the Business Activity Manager (BAM) by adding text box and writing some code to filter the columns list and I got it work after a lot of test.




Here it’s the code:
The code has been tested in Epicor 9.05.604 version.

using System;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Searches;
using System.Collections.Generic;
using Epicor.Mfg.BO;



public static class Script
{
    //Collection List used to store the columns.
    private static List<string> list = new List<string>();
    private static EpiListBox lbSource;  // column source List
    private static EpiListBox lbTarget;  // Column Target List
    private static EpiButton btnDeselect; // Deselect button
    private static EpiButton btnDeselectAll; //Deselect All Button
    private static EpiButton btnSelect;      //Select Button
    private static EpiButton btnSelectAll;  //Select All Button
    private static EpiUltraCombo coTable;  // Table name drop down list




    public static void InitializeCustomCode()
    {

        //use TextChange event to filter the list
        epiTextBoxC1.TextChanged += new System.EventHandler(Script.epiTextBoxC1_TextChanged);

        // Use the MouseEnter event to copy all columns into the cllection list
        // Only For the new created BAM.
        epiTextBoxC1.MouseEnter += new System.EventHandler(Script.epiTextBoxC1_MouseEnter);


        coTable = (EpiUltraCombo)csm.GetNativeControlReference("cd124472-994e-4ad5-870f-8db23a48a592");
        coTable.TextChanged += new System.EventHandler(Script.coTable_TextChanged);

        btnDeselect = (EpiButton)csm.GetNativeControlReference("13c171c8-460a-4ab4-80a9-eaabe7444ae5");
        btnDeselect.Click += new System.EventHandler(Script.btnDeselect_Click);

        btnDeselectAll = (EpiButton)csm.GetNativeControlReference("02938527-4ee7-4ffc-b13d-d37f2e798e8e");
        btnDeselectAll.Click += new System.EventHandler(Script.btnDeselect_Click);

        btnSelect = (EpiButton)csm.GetNativeControlReference("98da085f-432c-47b8-b3b8-c1f91f2f59c4");
        btnSelect.Click += new System.EventHandler(Script.btnSelect_Click);

        btnSelectAll = (EpiButton)csm.GetNativeControlReference("cc74f05e-c188-42b7-9013-89ed294f0ee8");
        btnSelectAll.Click += new System.EventHandler(Script.btnSelect_Click);

        // End Wizard Added Custom Method Calls
        lbSource = (EpiListBox)csm.GetNativeControlReference("15cbb74d-7df2-49e3-9933-a474f9b2fcae");
        lbTarget = (EpiListBox)csm.GetNativeControlReference("26bd0e42-6fc2-4895-8db6-a23b709b441e");
    }



    public static void DestroyCustomCode()
    {

        // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
        // Begin Wizard Added Object Disposal
        epiTextBoxC1.TextChanged -= new System.EventHandler(Script.epiTextBoxC1_TextChanged);
        btnDeselect.Click -= new System.EventHandler(Script.btnDeselect_Click);
        btnDeselectAll.Click -= new System.EventHandler(Script.btnDeselect_Click);
        btnSelect.Click -= new System.EventHandler(Script.btnSelect_Click);
        btnSelectAll.Click -= new System.EventHandler(Script.btnSelect_Click);

        coTable.TextChanged -= new System.EventHandler(Script.coTable_TextChanged);

    }


    private static void btnDeselect_Click(object sender, System.EventArgs args)
    {
        foreach (String str in lbSource.Items)
        {
            if (!list.Contains(str))
                list.Add(str);
        }
        epiTextBoxC1.Text = "";
    }


    private static void btnSelect_Click(object sender, System.EventArgs args)
    {
        if (lbTarget.Items.Count > 0)
        {
            string fields = "";
            foreach (String str in lbTarget.Items)
            {
                fields += str + "~";
                if (list.Contains(str))
                    list.Remove(str);
            }
            fields = fields.Substring(0, (fields.Length - 1));
            // this is very imprtant step to add the selected columns into the UseFieldList column in ChgLogGA Table
            // Without this step you can filter the list but when you select column(s) and save the selected columns will not be saved.
            EpiDataView dataView = (EpiDataView)oTrans.EpiDataViews["ChgLogGA"];
            DataRow currRow = dataView.CurrentDataRow;
            if (currRow != null)
                currRow["UseFieldList"] = fields;
            epiTextBoxC1.Text = "";
        }
    }


    private static void epiTextBoxC1_MouseEnter(object sender, System.EventArgs args)
    {
        if (list.Count == 0)
        {
            list.Clear();
            foreach (String str in lbSource.Items)
            {
                list.Add(str);
            }
            if (String.IsNullOrEmpty(epiTextBoxC1.Text.Trim()) == false)
                epiTextBoxC1.Text = "";
        }
    }


    private static void epiTextBoxC1_TextChanged(object sender, System.EventArgs args)
    {
        //  ** Place Event Handling Code Here **

        if (String.IsNullOrEmpty(epiTextBoxC1.Text.Trim()) == false)
        {
            lbSource.Items.Clear();
            foreach (string str in list)
            {
                if (str.ToLower().StartsWith(epiTextBoxC1.Text.ToLower().Trim()))
                {
                    lbSource.Items.Add(str);
                }
            }
        }

        else
        {
            lbSource.Items.Clear();

            foreach (string str in list)
            {
                lbSource.Items.Add(str);
            }
        }
    }

    private static void coTable_TextChanged(object sender, System.EventArgs args)
    {
        //  ** Place Event Handling Code Here **
        list.Clear();
        foreach (String str in lbSource.Items)
        {
            list.Add(str);
        }
        if (String.IsNullOrEmpty(epiTextBoxC1.Text.Trim()) == false)
            epiTextBoxC1.Text = "";
    }

}



Comments

  1. Have you also used this solution in an Epicor10 environment? Would you have an example?

    ReplyDelete

Post a Comment

Popular posts from this blog

Epicor 9 ToolBars

Like any other application, Epicor has list of toolbars and it uses the Infragistics controls and you can modify these toolbars in your code by adding new tools or change the properties for the existing toolbars and Tools.

How to Use the Business Activity Query Export Process

Business Activity Query Export Process let you export the BAQ data in XML or CSV format. You can export the BAQ data manually and you can schedule it to run automatically (Daily, Weekly, ,Monthly,Once,startup..etc) and you can configure this in the “system agent maintenance” and I will explain this later in this article.