Need help tweaking some code.

I have some C# code that was created from a GUI.  My issue is when the records come up it is only showing records that match key1, key2, key3, and key4 and ignores key5.  Because of this it is not showing all the records.  What I would like it to do is bring back all records that match key1 only but do not know how to code it.  Hoping someone here can help.

// **************************************************
// Custom code for PREmployeeForm
// Created: 9/18/2017 3:14:46 PM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	private UD02Adapter _ud02Adapter;
	private EpiDataView _edvPREmployee;
	private EpiDataView _edvUD02;
	private string _Key1UD02;
	private string _Key2UD02;
	private string _Key3UD02;
	private string _Key4UD02;
	private string _Key5UD02;
	private string _ShortChar01UD02;
	private string _Date5UD02;
	private DataView PREmployee_DataView;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this._Key1UD02 = string.Empty;
		this._Key2UD02 = string.Empty;
		this._Key3UD02 = string.Empty;
		this._Key4UD02 = string.Empty;
		this._Key5UD02 = string.Empty;
		this._ShortChar01UD02 = string.Empty;
		this._Date5UD02 = string.Empty;
		this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD02);
		this.PREmployeeForm.BeforeToolClick += new Epicor.Mfg.UI.FrameWork.BeforeToolClickEventHandler(this.PREmployeeForm_BeforeToolClickForUD02);
		this.PREmployee_Row.EpiRowChanged += new EpiRowChanged(this.PREmployee_AfterRowChangeForUD02);
		this.PREmployee_DataView = this.PREmployee_Row.dataView;
		this.PREmployee_DataView.ListChanged += new ListChangedEventHandler(this.PREmployee_DataView_ListChangedForUD02);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		InitializeUD02Adapter();

		// End Wizard Added Custom Method Calls
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		if ((this._ud02Adapter != null))
		{
			this._ud02Adapter.Dispose();
			this._ud02Adapter = null;
		}
		this._edvUD02 = null;
		this._edvPREmployee = null;
		this._Key1UD02 = null;
		this._Key2UD02 = null;
		this._Key3UD02 = null;
		this._Key4UD02 = null;
		this._Key5UD02 = null;
		this._ShortChar01UD02 = null;
		this._Date5UD02 = null;
		this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD02);
		this.PREmployeeForm.BeforeToolClick -= new Epicor.Mfg.UI.FrameWork.BeforeToolClickEventHandler(this.PREmployeeForm_BeforeToolClickForUD02);
		this.PREmployee_Row.EpiRowChanged -= new EpiRowChanged(this.PREmployee_AfterRowChangeForUD02);
		this.PREmployee_DataView.ListChanged -= new ListChangedEventHandler(this.PREmployee_DataView_ListChangedForUD02);
		this.PREmployee_DataView = null;

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void InitializeUD02Adapter()
	{
		// Create an instance of the Adapter.
		this._ud02Adapter = new UD02Adapter(this.oTrans);
		this._ud02Adapter.BOConnect();

		// Add Adapter Table to List of Views
		// This allows you to bind controls to the custom UD Table
		this._edvUD02 = new EpiDataView();
		this._edvUD02.dataView = new DataView(this._ud02Adapter.UD02Data.UD02);
		this._edvUD02.AddEnabled = true;
		this._edvUD02.AddText = "New UD02";
		if ((this.oTrans.EpiDataViews.ContainsKey("UD02View") == false))
		{
			this.oTrans.Add("UD02View", this._edvUD02);
		}

		// Initialize EpiDataView field.
		this._edvPREmployee = ((EpiDataView)(this.oTrans.EpiDataViews["PREmployee"]));

		// Set the parent view / keys for UD child view
		string[] parentKeyFields = new string[6];
		string[] childKeyFields = new string[6];
		parentKeyFields[0] = "EmpID";
		childKeyFields[0] = "Key1";
		parentKeyFields[1] = "ExpenseCode";
		childKeyFields[1] = "Key2";
		parentKeyFields[2] = "JCDept";
		childKeyFields[2] = "Key3";
		parentKeyFields[3] = "Shift";
		childKeyFields[3] = "Key4";
		parentKeyFields[4] = "Name";
		childKeyFields[4] = "ShortChar01";
		parentKeyFields[5] = "HireDate";
		childKeyFields[5] = "Date05";

		this._edvUD02.SetParentView(this._edvPREmployee, parentKeyFields, childKeyFields);

		if ((this.oTrans.PrimaryAdapter != null))
		{
			// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Epicor.Mfg.UI.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD02.dataView.Table.Clone())
		}

	}

	private void GetUD02Data(string key1, string key2, string key3, string key4, string key5)
	{
		if ((this._Key1UD02 != key1) || (this._Key2UD02 != key2) || (this._Key3UD02 != key3) || (this._Key4UD02 != key4) || (this._Key5UD02 != key5))
		{
			// Build where clause for search.
			string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\' And Key3 = \'" + key3 + "\' And Key4 = \'" + key4 + "\'";
			System.Collections.Hashtable whereClauses = new System.Collections.Hashtable(1);
			whereClauses.Add("UD02", whereClause);

			// Call the adapter search.
			SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
			this._ud02Adapter.InvokeSearch(searchOptions);

			if ((this._ud02Adapter.UD02Data.UD02.Rows.Count > 0))
			{
				this._edvUD02.Row = 0;
			} else
			{
				this._edvUD02.Row = -1;
			}

			// Notify that data was updated.
			this._edvUD02.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD02.Row, this._edvUD02.Column));

			// Set key fields to their new values.
			this._Key1UD02 = key1;
			this._Key2UD02 = key2;
			this._Key3UD02 = key3;
			this._Key4UD02 = key4;
			this._Key5UD02 = key5;
		}
	}

	private void GetNewUD02Record()
	{
		DataRow parentViewRow = this._edvPREmployee.CurrentDataRow;
		// Check for existence of Parent Row.
		if ((parentViewRow == null))
		{
			return;
		}
		if (this._ud02Adapter.GetaNewUD02())
		{
			string empid = parentViewRow["EmpID"].ToString();
			string expensecode = parentViewRow["ExpenseCode"].ToString();
			string jcdept = parentViewRow["JCDept"].ToString();
			string shift = parentViewRow["Shift"].ToString();
			string name = parentViewRow["Name"].ToString();
			string hiredate = parentViewRow["HireDate"].ToString();

			// Get unique row count id for Key5
			int rowCount = this._ud02Adapter.UD02Data.UD02.Rows.Count;
			int lineNum = rowCount;
			bool goodIndex = false;
			while ((goodIndex == false))
			{
				// Check to see if index exists
				DataRow[] matchingRows = this._ud02Adapter.UD02Data.UD02.Select("Key5 = \'" + lineNum.ToString() + "\'");
				if ((matchingRows.Length > 0))
				{
					lineNum = (lineNum + 1);
				} else
				{
					goodIndex = true;
				}
			}

			// Set initial UD Key values
			DataRow editRow = this._ud02Adapter.UD02Data.UD02.Rows[(rowCount - 1)];
			editRow.BeginEdit();
			editRow["Key1"] = empid;
			editRow["Key2"] = expensecode;
			editRow["Key3"] = jcdept;
			editRow["Key4"] = shift;
			editRow["Key5"] = lineNum.ToString();
			editRow["ShortChar01"] = name;
			editRow["Date05"] = hiredate;
			editRow.EndEdit();

			// Notify that data was updated.
			this._edvUD02.Notify(new EpiNotifyArgs(this.oTrans, (rowCount - 1), this._edvUD02.Column));
		}
	}

	private void SaveUD02Record()
	{
		// Save adapter data
		this._ud02Adapter.Update();
	}

	private void DeleteUD02Record()
	{
		// Check to see if deleted view is ancestor view
		bool isAncestorView = false;
		Epicor.Mfg.UI.FrameWork.EpiDataView parView = this._edvUD02.ParentView;
		while ((parView != null))
		{
			if ((this.oTrans.LastView == parView))
			{
				isAncestorView = true;
				break;
			} else
			{
				parView = parView.ParentView;
			}
		}

		// If Ancestor View then delete all child rows
		if (isAncestorView)
		{
			DataRow[] drsDeleted = this._ud02Adapter.UD02Data.UD02.Select("Key1 = \'" + this._Key1UD02 + "\' AND Key2 = \'" + this._Key2UD02 + "\' AND Key3 = \'" + this._Key3UD02 + "\' AND Key4 = \'" + this._Key4UD02 + "\'");
			for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
			{
				this._ud02Adapter.Delete(drsDeleted[i]);
			}
		} else
		{
			if ((this.oTrans.LastView == this._edvUD02))
			{
				if ((this._edvUD02.Row >= 0))
				{
					DataRow drDeleted = ((DataRow)(this._ud02Adapter.UD02Data.UD02.Rows[this._edvUD02.Row]));
					if ((drDeleted != null))
					{
						if (this._ud02Adapter.Delete(drDeleted))
						{
							if ((_edvUD02.Row > 0))
							{
								_edvUD02.Row = (_edvUD02.Row - 1);
							}

							// Notify that data was updated.
							this._edvUD02.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD02.Row, this._edvUD02.Column));
						}
					}
				}
			}
		}
	}

	private void UndoUD02Changes()
	{
		this._ud02Adapter.UD02Data.RejectChanges();

		// Notify that data was updated.
		this._edvUD02.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD02.Row, this._edvUD02.Column));
	}

	private void ClearUD02Data()
	{
		this._Key1UD02 = string.Empty;
		this._Key2UD02 = string.Empty;
		this._Key3UD02 = string.Empty;
		this._Key4UD02 = string.Empty;
		this._Key5UD02 = string.Empty;
		this._ShortChar01UD02 = string.Empty;

		this._ud02Adapter.UD02Data.Clear();

		// Notify that data was updated.
		this._edvUD02.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD02.Row, this._edvUD02.Column));
	}

	private void baseToolbarsManager_ToolClickForUD02(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
	{
		// EpiMessageBox.Show(args.Tool.Key);
		switch (args.Tool.Key)
		{
			case "EpiAddNewNew UD02":
				GetNewUD02Record();
				break;

			case "ClearTool":
				ClearUD02Data();
				break;

			case "DeleteTool":
				DeleteUD02Record();
				break;

			case "UndoTool":
				UndoUD02Changes();
				break;
		}
	}

	private void PREmployeeForm_BeforeToolClickForUD02(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
	{
		// EpiMessageBox.Show(args.Tool.Key);
		switch (args.Tool.Key)
		{
			case "SaveTool":
				SaveUD02Record();
				break;
		}
	}

	private void PREmployee_AfterRowChangeForUD02(EpiRowChangedArgs args)
	{
		// ** add AfterRowChange event handler
		string empid = args.CurrentView.dataView[args.CurrentRow]["EmpID"].ToString();
		string expensecode = args.CurrentView.dataView[args.CurrentRow]["ExpenseCode"].ToString();
		string jcdept = args.CurrentView.dataView[args.CurrentRow]["JCDept"].ToString();
		string shift = args.CurrentView.dataView[args.CurrentRow]["Shift"].ToString();
		string name = args.CurrentView.dataView[args.CurrentRow]["Name"].ToString();
		string hiredate = args.CurrentView.dataView[args.CurrentRow]["HireDate"].ToString();
		GetUD02Data(empid, expensecode, jcdept, shift, string.Empty);
	}

	private void PREmployee_DataView_ListChangedForUD02(object sender, ListChangedEventArgs args)
	{
		// ** add ListChanged event handler
		string empid = PREmployee_DataView[0]["EmpID"].ToString();
		string expensecode = PREmployee_DataView[0]["ExpenseCode"].ToString();
		string jcdept = PREmployee_DataView[0]["JCDept"].ToString();
		string shift = PREmployee_DataView[0]["Shift"].ToString();
		string name = PREmployee_DataView[0]["Name"].ToString();
		string hiredate = PREmployee_DataView[0]["HireDate"].ToString();
		GetUD02Data(empid, expensecode, jcdept, shift, string.Empty);
	}

}

Open in new window

LVL 3
Trygve ThayerIT DirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
In GetUD02Data, this line appears to limit the data returned:
string whereClause = "Key1 = \'" + key1 + "\' And Key2 = \'" + key2 + "\' And Key3 = \'" + key3 + "\' And Key4 = \'" + key4 + "\'";

Open in new window

To only bring back Key1, change this line to below should meet your needs:
string whereClause = "Key1 = \'" + key1 + "\'";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Trygve ThayerIT DirectorAuthor Commented:
I just tried it but did not seem to make a difference
0
Dustin SaundersDirector of OperationsCommented:
A screenshot of what the results look like would be helpful-- did the results change at all?
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Trygve ThayerIT DirectorAuthor Commented:
To give some more details the gui is within our Epicor Software that lets us customize screens and has wizzards you can use that adds code in the background.  One particular function I used was to join a blank table to an employee view.  When I changed the code I saw no change.  On the SQL server I did a query and saw 2 records.  In the screen I am working on there is only one record.
0
Trygve ThayerIT DirectorAuthor Commented:
Well played around with this some more and found a piece I was missing.  That along with Shaun Kline's suggestion fixed it.  Below is the other piece I had to modify which I just remarked out.  Works fine now.

	private void InitializeUD02Adapter()
	{
		// Create an instance of the Adapter.
		this._ud02Adapter = new UD02Adapter(this.oTrans);
		this._ud02Adapter.BOConnect();

		// Add Adapter Table to List of Views
		// This allows you to bind controls to the custom UD Table
		this._edvUD02 = new EpiDataView();
		this._edvUD02.dataView = new DataView(this._ud02Adapter.UD02Data.UD02);
		this._edvUD02.AddEnabled = true;
		this._edvUD02.AddText = "New UD02";
		if ((this.oTrans.EpiDataViews.ContainsKey("UD02View") == false))
		{
			this.oTrans.Add("UD02View", this._edvUD02);
		}

		// Initialize EpiDataView field.
		this._edvPREmployee = ((EpiDataView)(this.oTrans.EpiDataViews["PREmployee"]));

		// Set the parent view / keys for UD child view
		string[] parentKeyFields = new string[1];
		string[] childKeyFields = new string[1];
		parentKeyFields[0] = "EmpID";
		childKeyFields[0] = "Key1";
		//parentKeyFields[1] = "ExpenseCode";
		//childKeyFields[1] = "Key2";
		//parentKeyFields[2] = "JCDept";
		//childKeyFields[2] = "Key3";
		//parentKeyFields[3] = "Shift";
		//childKeyFields[3] = "Key4";
		//parentKeyFields[4] = "Name";
		//childKeyFields[4] = "ShortChar01";
		//parentKeyFields[5] = "HireDate";
		//childKeyFields[5] = "Date05";

		this._edvUD02.SetParentView(this._edvPREmployee, parentKeyFields, childKeyFields);

		if ((this.oTrans.PrimaryAdapter != null))
		{
			// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Epicor.Mfg.UI.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD02.dataView.Table.Clone())
		}

	}

Open in new window

0
Trygve ThayerIT DirectorAuthor Commented:
Thanks for the help at Experts-Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.