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

Automatic Login to Epicor

Overview: When the user double-clicks on the program icon in the desktop, Epicor Login window will appear and ask the user to enter the user name and password. But you can modify the configuration setting file so the user can automatically login into the application.

How to use Process Sets Maintenance

The process sets program uses to group a list of task together to be run in a schedule and you can order the task to be run in your order especially if you have a task depend another task.