UD Table Load issues

Hello,

So I am new to using UD Tables. I have set up UD01 and loaded some data into it using a menu shortcut and that seems to be ok.

Ultimately though when my customization loads the UD01 epibound fields are grayed out and blank.

Maybe its where I am connecting the UD table thats a problem. I am customizing the PO Print form so I can enter emails that bind with UD01 Key2 to ReportParam PONum. I then added UD01 as a child table of the ReportParam View. Ive made sure to keep my code simple to make sure it wasnt something else causing the problem, but it just seems like the data just doesnt load. Even though I know for a fact there is a field in the UD01 table that has the same PO number in Key2 that I am bringing the form up as.

I really do not know what the problem is.

Ultimately I would also like to check to see is the UD01 Table has a row with the Key2 field matching and if not create one on form load, but if I cannot get preloaded data to work I cant even begin on that next step yet.

I appreciate any advice.

What does your code look like

-Jose

1 Like
// **************************************************
// Custom code for POForm
// Created: 10/22/2017 10:01:37 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

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

	private UD01Adapter _ud01Adapter;
	private EpiDataView _edvReportParam;
	private DataTable UD01_Column;
	private EpiDataView _edvUD01;
	private string _Key1UD01;
	private string _Key2UD01;
	private string _Key3UD01;
	private string _Key4UD01;
	private string _Key5UD01;
	private DataView ReportParam_DataView;
	private EpiDataView edvUD01View;
	// 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

		InitializeUD01Adapter();
		this._Key1UD01 = string.Empty;
		this._Key2UD01 = string.Empty;
		this._Key3UD01 = string.Empty;
		this._Key4UD01 = string.Empty;
		this._Key5UD01 = string.Empty;
		this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD01);
		this.POForm.BeforeToolClick += new Ice.Lib.Framework.BeforeToolClickEventHandler(this.POForm_BeforeToolClickForUD01);
		this.POForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.POForm_AfterToolClickForUD01);
		this.ReportParam_Row.EpiRowChanged += new EpiRowChanged(this.ReportParam_AfterRowChangeForUD01);
		this.ReportParam_DataView = this.ReportParam_Row.dataView;
		this.ReportParam_DataView.ListChanged += new ListChangedEventHandler(this.ReportParam_DataView_ListChangedForUD01);
		this.edvUD01View = ((EpiDataView)(this.oTrans.EpiDataViews["UD01View"]));
		this.edvUD01View.EpiViewNotification += new EpiViewNotification(this.edvUD01View_EpiViewNotification);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// 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._ud01Adapter != null))
		{
			this._ud01Adapter.Dispose();
			this._ud01Adapter = null;
		}
		this._edvUD01 = null;
		this._edvReportParam = null;
		this.UD01_Column = null;
		this._Key1UD01 = null;
		this._Key2UD01 = null;
		this._Key3UD01 = null;
		this._Key4UD01 = null;
		this._Key5UD01 = null;
		this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD01);
		this.POForm.BeforeToolClick -= new Ice.Lib.Framework.BeforeToolClickEventHandler(this.POForm_BeforeToolClickForUD01);
		this.POForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.POForm_AfterToolClickForUD01);
		this.ReportParam_Row.EpiRowChanged -= new EpiRowChanged(this.ReportParam_AfterRowChangeForUD01);
		this.ReportParam_DataView.ListChanged -= new ListChangedEventHandler(this.ReportParam_DataView_ListChangedForUD01);
		this.ReportParam_DataView = null;
		this.edvUD01View.EpiViewNotification -= new EpiViewNotification(this.edvUD01View_EpiViewNotification);
		this.edvUD01View = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void InitializeUD01Adapter()
	{
		// Create an instance of the Adapter.
		this._ud01Adapter = new UD01Adapter(this.oTrans);
		this._ud01Adapter.BOConnect();

		// Add Adapter Table to List of Views
		// This allows you to bind controls to the custom UD Table
		this._edvUD01 = new EpiDataView();
		this._edvUD01.dataView = new DataView(this._ud01Adapter.UD01Data.UD01);
		this._edvUD01.AddEnabled = true;
		this._edvUD01.AddText = "New UD01";
		if ((this.oTrans.EpiDataViews.ContainsKey("UD01View") == false))
		{
			this.oTrans.Add("UD01View", this._edvUD01);
		}

		// Initialize DataTable variable
		this.UD01_Column = this._ud01Adapter.UD01Data.UD01;

		// Initialize EpiDataView field.
		this._edvReportParam = ((EpiDataView)(this.oTrans.EpiDataViews["ReportParam"]));

		// Set the parent view / keys for UD child view
		string[] parentKeyFields = new string[1];
		string[] childKeyFields = new string[1];
		parentKeyFields[0] = "PONum";
		childKeyFields[0] = "Key2";
		this._edvUD01.SetParentView(this._edvReportParam, parentKeyFields, childKeyFields);

		if ((this.oTrans.PrimaryAdapter != null))
		{
			// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD01.dataView.Table.Clone())
		}

	}

	private void GetUD01Data(string key1, string key2, string key3, string key4, string key5)
	{
		if ((this._Key1UD01 != key1) || (this._Key2UD01 != key2) || (this._Key3UD01 != key3) || (this._Key4UD01 != key4) || (this._Key5UD01 != 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("UD01", whereClause);

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

			if ((this._ud01Adapter.UD01Data.UD01.Rows.Count > 0))
			{
				this._edvUD01.Row = 0;
			} else
			{
				this._edvUD01.Row = -1;
			}

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

			// Set key fields to their new values.
			this._Key1UD01 = key1;
			this._Key2UD01 = key2;
			this._Key3UD01 = key3;
			this._Key4UD01 = key4;
			this._Key5UD01 = key5;
		}
	}

	private void GetNewUD01Record()
	{
		DataRow parentViewRow = this._edvReportParam.CurrentDataRow;
		// Check for existence of Parent Row.
		if ((parentViewRow == null))
		{
			return;
		}
		if (this._ud01Adapter.GetaNewUD01())
		{
			string ponum = parentViewRow["PONum"].ToString();

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

			// Set initial UD Key values
			DataRow editRow = this._ud01Adapter.UD01Data.UD01.Rows[(rowCount - 1)];
			editRow.BeginEdit();
			editRow["Key1"] = ponum;
			editRow["Key2"] = string.Empty;
			editRow["Key3"] = string.Empty;
			editRow["Key4"] = string.Empty;
			editRow["Key5"] = lineNum.ToString();
			editRow.EndEdit();

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

	private void SaveUD01Record()
	{
		// Save adapter data
		this._ud01Adapter.Update();
	}

	private void DeleteUD01Record()
	{
		// Check to see if deleted view is ancestor view
		bool isAncestorView = false;
		Ice.Lib.Framework.EpiDataView parView = this._edvUD01.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._ud01Adapter.UD01Data.UD01.Select("Key1 = \'" + this._Key1UD01 + "\' AND Key2 = \'" + this._Key2UD01 + "\' AND Key3 = \'" + this._Key3UD01 + "\' AND Key4 = \'" + this._Key4UD01 + "\'");
			for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
			{
				this._ud01Adapter.Delete(drsDeleted[i]);
			}
		} else
		{
			if ((this.oTrans.LastView == this._edvUD01))
			{
				if ((this._edvUD01.Row >= 0))
				{
					DataRow drDeleted = ((DataRow)(this._ud01Adapter.UD01Data.UD01.Rows[this._edvUD01.Row]));
					if ((drDeleted != null))
					{
						if (this._ud01Adapter.Delete(drDeleted))
						{
							if ((_edvUD01.Row > 0))
							{
								_edvUD01.Row = (_edvUD01.Row - 1);
							}

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

	private void UndoUD01Changes()
	{
		this._ud01Adapter.UD01Data.RejectChanges();

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

	private void ClearUD01Data()
	{
		this._Key1UD01 = string.Empty;
		this._Key2UD01 = string.Empty;
		this._Key3UD01 = string.Empty;
		this._Key4UD01 = string.Empty;
		this._Key5UD01 = string.Empty;

		this._ud01Adapter.UD01Data.Clear();

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

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

			case "ClearTool":
				ClearUD01Data();
				break;

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

	private void POForm_BeforeToolClickForUD01(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
	{
		// EpiMessageBox.Show(args.Tool.Key);
		switch (args.Tool.Key)
		{
			case "SaveTool":
				SaveUD01Record();
				break;
		}
	}

	private void POForm_AfterToolClickForUD01(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
	{
		// EpiMessageBox.Show(args.Tool.Key);
		switch (args.Tool.Key)
		{
			case "DeleteTool":
				if ((args.Cancelled == false))
				{
					DeleteUD01Record();
				}
				break;
		}
	}

	private void ReportParam_AfterRowChangeForUD01(EpiRowChangedArgs args)
	{
		// ** add AfterRowChange event handler
		string ponum = args.CurrentView.dataView[args.CurrentRow]["PONum"].ToString();
		GetUD01Data(ponum, string.Empty, string.Empty, string.Empty, string.Empty);
	}

	private void ReportParam_DataView_ListChangedForUD01(object sender, ListChangedEventArgs args)
	{
		// ** add ListChanged event handler
		string ponum = ReportParam_DataView[0]["PONum"].ToString();
		GetUD01Data(ponum, string.Empty, string.Empty, string.Empty, string.Empty);
	}

	private void edvUD01View_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
	{
		// ** Argument Properties and Uses **
		// view.dataView[args.Row]["FieldName"]
		// args.Row, args.Column, args.Sender, args.NotifyType
		// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
		if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
		{
			if ((args.Row > -1))
			{
			}
		}
	}

	private void POForm_Load(object sender, EventArgs args)
	{
		// Add Event Handler Code
		string ponum = _edvReportParam.dataView[0]["PONum"].ToString();
		GetUD01Data(string.Empty, ponum, string.Empty, string.Empty, string.Empty);
	}
}

Your GetUD01 is using All the Keys… that’s a problem if you are only using Key1 and Key2 try adjusting the GetUD01Data function to only apply Where whereClause to Key 2 (PoNum)

1 Like

Ill give it a shot. Looking at the code myself though it looks like although the GetUD01Data method uses all keys, most of the keys they are being fed are string.Empty, and as such it is my understanding that they should not really add anything to the where clause. Am I misunderstanding this?

GetUD01Data(string.Empty, ponum, string.Empty, string.Empty, string.Empty);

They do it would require Key1 to be empty for example… is your Key1 empty?

Ah, no. I have a static “Type” key there. I know what to do now, Ill edit the data I feed the where clause to work correctly with the static key. Your suggested fix worked, so I can confirm the rest of the code works now. This is what I get for being too clever for my own abilities, haha.

Thanks a ton for the help!

Great! please mark the post as solved to aid others in their search with similar issues.
Thanks!