I’ve been reading though several threads about adding a new UD table. Not sure if this is accurate, but from what I can tell, not all forms are created equal when adding UD rows. I need help on what I’m doing wrong.
I’m trying a add a new UD row on the Case Entry form. My objective is to add a new CAPA (Corrective Action Preventative Action) per Case Number if required. I’ve already added the new Tabs per the Sheet Wizard.
After adding the sheets, I added a User defined Table as a Child. See steps below
I then added en epiUltraGrid and Binded UD14View to the form.
I save a restart the form. When I go to add a new UD row, I get nothing to return.
Is there a step I’m missing?
See code below
// **************************************************
// Custom code for HelpDeskForm
// Created: 8/7/2023 1:20:31 PM
// **************************************************
extern alias Erp_Contracts_BO_SalesOrder;
extern alias Erp_Contracts_BO_Quote;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_RMAProc;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_Reason;
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 UD14Adapter _ud14Adapter;
private EpiDataView _edvHDCase;
private DataTable UD14_Column;
private EpiDataView _edvUD14;
private string _Key1UD14;
private string _Key2UD14;
private string _Key3UD14;
private string _Key4UD14;
private string _Key5UD14;
private DataView HDCase_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
InitializeUD14Adapter();
this._Key1UD14 = string.Empty;
this._Key2UD14 = string.Empty;
this._Key3UD14 = string.Empty;
this._Key4UD14 = string.Empty;
this._Key5UD14 = string.Empty;
this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD14);
this.HelpDeskForm.BeforeToolClick += new Ice.Lib.Framework.BeforeToolClickEventHandler(this.HelpDeskForm_BeforeToolClickForUD14);
this.HelpDeskForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.HelpDeskForm_AfterToolClickForUD14);
this.HDCase_Row.EpiRowChanged += new EpiRowChanged(this.HDCase_AfterRowChangeForUD14);
this.HDCase_DataView = this.HDCase_Row.dataView;
this.HDCase_DataView.ListChanged += new ListChangedEventHandler(this.HDCase_DataView_ListChangedForUD14);
this.HDCase_Row.BeforeResetDataView += new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.HDCase_BeforeResetDataViewForUD14);
this.HDCase_Row.AfterResetDataView += new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.HDCase_AfterResetDataViewForUD14);
// 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._ud14Adapter != null))
{
this._ud14Adapter.Dispose();
this._ud14Adapter = null;
}
this._edvUD14 = null;
this._edvHDCase = null;
this.UD14_Column = null;
this._Key1UD14 = null;
this._Key2UD14 = null;
this._Key3UD14 = null;
this._Key4UD14 = null;
this._Key5UD14 = null;
this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD14);
this.HelpDeskForm.BeforeToolClick -= new Ice.Lib.Framework.BeforeToolClickEventHandler(this.HelpDeskForm_BeforeToolClickForUD14);
this.HelpDeskForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.HelpDeskForm_AfterToolClickForUD14);
this.HDCase_Row.EpiRowChanged -= new EpiRowChanged(this.HDCase_AfterRowChangeForUD14);
this.HDCase_DataView.ListChanged -= new ListChangedEventHandler(this.HDCase_DataView_ListChangedForUD14);
this.HDCase_DataView = null;
this.HDCase_Row.BeforeResetDataView -= new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.HDCase_BeforeResetDataViewForUD14);
this.HDCase_Row.AfterResetDataView -= new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.HDCase_AfterResetDataViewForUD14);
this._edvHDCase.AddEnabled = true;
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void InitializeUD14Adapter()
{
// Create an instance of the Adapter.
this._ud14Adapter = new UD14Adapter(this.oTrans);
this._ud14Adapter.BOConnect();
// Add Adapter Table to List of Views
// This allows you to bind controls to the custom UD Table
this._edvUD14 = new EpiDataView();
this._edvUD14.dataView = new DataView(this._ud14Adapter.UD14Data.UD14);
this._edvUD14.AddEnabled = true;
this._edvUD14.AddText = "New UD14";
if ((this.oTrans.EpiDataViews.ContainsKey("UD14View") == false))
{
this.oTrans.Add("UD14View", this._edvUD14);
}
// Initialize DataTable variable
this.UD14_Column = this._ud14Adapter.UD14Data.UD14;
// Initialize EpiDataView field.
this._edvHDCase = ((EpiDataView)(this.oTrans.EpiDataViews["HDCase"]));
// Set the parent view / keys for UD child view
string[] parentKeyFields = new string[1];
string[] childKeyFields = new string[1];
parentKeyFields[0] = "HDCaseNum";
childKeyFields[0] = "Key1";
this._edvUD14.SetParentView(this._edvHDCase, parentKeyFields, childKeyFields);
if ((this.oTrans.PrimaryAdapter != null))
{
// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD14.dataView.Table.Clone())
}
}
private void GetUD14Data(string key1, string key2, string key3, string key4, string key5)
{
if ((this._Key1UD14 != key1) || (this._Key2UD14 != key2) || (this._Key3UD14 != key3) || (this._Key4UD14 != key4) || (this._Key5UD14 != 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("UD14", whereClause);
// Call the adapter search.
SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
this._ud14Adapter.InvokeSearch(searchOptions);
if ((this._ud14Adapter.UD14Data.UD14.Rows.Count > 0))
{
this._edvUD14.Row = 0;
} else
{
this._edvUD14.Row = -1;
}
// Notify that data was updated.
this._edvUD14.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD14.Row, this._edvUD14.Column));
// Set key fields to their new values.
this._Key1UD14 = key1;
this._Key2UD14 = key2;
this._Key3UD14 = key3;
this._Key4UD14 = key4;
this._Key5UD14 = key5;
}
}
private void GetNewUD14Record()
{
DataRow parentViewRow = this._edvHDCase.CurrentDataRow;
// Check for existence of Parent Row.
if ((parentViewRow == null))
{
return;
}
if (this._ud14Adapter.GetaNewUD14())
{
string hdcasenum = parentViewRow["HDCaseNum"].ToString();
// Get unique row count id for Key5
int rowCount = this._ud14Adapter.UD14Data.UD14.Rows.Count;
int lineNum = rowCount;
bool goodIndex = false;
while ((goodIndex == false))
{
// Check to see if index exists
DataRow[] matchingRows = this._ud14Adapter.UD14Data.UD14.Select("Key5 = \'" + lineNum.ToString() + "\'");
if ((matchingRows.Length > 0))
{
lineNum = (lineNum + 1);
} else
{
goodIndex = true;
}
}
// Set initial UD Key values
DataRow editRow = this._ud14Adapter.UD14Data.UD14.Rows[(rowCount - 1)];
editRow.BeginEdit();
editRow["Key1"] = hdcasenum;
editRow["Key2"] = string.Empty;
editRow["Key3"] = string.Empty;
editRow["Key4"] = string.Empty;
editRow["Key5"] = lineNum.ToString();
editRow.EndEdit();
// Notify that data was updated.
this._edvUD14.Notify(new EpiNotifyArgs(this.oTrans, (rowCount - 1), this._edvUD14.Column));
}
}
private void SaveUD14Record()
{
// Save adapter data
this._ud14Adapter.Update();
}
private void DeleteUD14Record()
{
// Check to see if deleted view is ancestor view
bool isAncestorView = false;
Ice.Lib.Framework.EpiDataView parView = this._edvUD14.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._ud14Adapter.UD14Data.UD14.Select("Key1 = \'" + this._Key1UD14 + "\' AND Key2 = \'" + this._Key2UD14 + "\' AND Key3 = \'" + this._Key3UD14 + "\' AND Key4 = \'" + this._Key4UD14 + "\'");
for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
{
this._ud14Adapter.Delete(drsDeleted[i]);
}
} else
{
if ((this.oTrans.LastView == this._edvUD14))
{
if ((this._edvUD14.Row >= 0))
{
DataRow drDeleted = ((DataRow)(this._ud14Adapter.UD14Data.UD14.Rows[this._edvUD14.Row]));
if ((drDeleted != null))
{
if (this._ud14Adapter.Delete(drDeleted))
{
if ((_edvUD14.Row > 0))
{
_edvUD14.Row = (_edvUD14.Row - 1);
}
// Notify that data was updated.
this._edvUD14.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD14.Row, this._edvUD14.Column));
}
}
}
}
}
}
private void UndoUD14Changes()
{
this._ud14Adapter.UD14Data.RejectChanges();
// Notify that data was updated.
this._edvUD14.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD14.Row, this._edvUD14.Column));
}
private void ClearUD14Data()
{
this._Key1UD14 = string.Empty;
this._Key2UD14 = string.Empty;
this._Key3UD14 = string.Empty;
this._Key4UD14 = string.Empty;
this._Key5UD14 = string.Empty;
this._ud14Adapter.UD14Data.Clear();
// Notify that data was updated.
this._edvUD14.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD14.Row, this._edvUD14.Column));
}
private void baseToolbarsManager_ToolClickForUD14(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "EpiAddNewNew UD14":
GetNewUD14Record();
break;
case "ClearTool":
ClearUD14Data();
break;
case "UndoTool":
UndoUD14Changes();
break;
}
}
private void HelpDeskForm_BeforeToolClickForUD14(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "SaveTool":
SaveUD14Record();
break;
}
}
private void HelpDeskForm_AfterToolClickForUD14(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "DeleteTool":
if ((args.Cancelled == false))
{
DeleteUD14Record();
}
break;
}
}
private void HDCase_AfterRowChangeForUD14(EpiRowChangedArgs args)
{
// ** add AfterRowChange event handler
string hdcasenum = args.CurrentView.dataView[args.CurrentRow]["HDCaseNum"].ToString();
GetUD14Data(hdcasenum, string.Empty, string.Empty, string.Empty, string.Empty);
}
private void HDCase_DataView_ListChangedForUD14(object sender, ListChangedEventArgs args)
{
// ** add ListChanged event handler
string hdcasenum = HDCase_DataView[0]["HDCaseNum"].ToString();
GetUD14Data(hdcasenum, string.Empty, string.Empty, string.Empty, string.Empty);
}
private void HDCase_BeforeResetDataViewForUD14(object sender, EventArgs args)
{
// ** remove ListChanged event handler
this.HDCase_DataView.ListChanged -= new ListChangedEventHandler(this.HDCase_DataView_ListChangedForUD14);
}
private void HDCase_AfterResetDataViewForUD14(object sender, EventArgs args)
{
// ** reassign DataView and add ListChanged event handler
this.HDCase_DataView = this.HDCase_Row.dataView;
this.HDCase_DataView.ListChanged += new ListChangedEventHandler(this.HDCase_DataView_ListChangedForUD14);
}
}


