I just ran VisualStudio debugging and I am getting an error:
System.IndexOutOfRangeException: 'Index -1 is either negative or above rows count.'
On this line:
int OJI = System.Convert.ToInt32(edvOJI.dataView[edvOJI.Row]["Number01"]);
Full Code For Refernce:
// **************************************************
// Custom code for JobEntryForm
// Created: 1/29/2018 10:55:01 AM
// **************************************************
extern alias Erp_Contracts_BO_Project;
extern alias Erp_Contracts_BO_Part;
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;
//using System.Reflection;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
private UD06Adapter _ud06Adapter;
private EpiDataView _edvJobHead;
private DataTable UD06_Column;
private EpiDataView _edvUD06;
private string _Key1UD06;
private string _Key2UD06;
private string _Key3UD06;
private string _Key4UD06;
private string _Key5UD06;
private DataView JobHead_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
InitializeUD06Adapter();
this._Key1UD06 = string.Empty;
this._Key2UD06 = string.Empty;
this._Key3UD06 = string.Empty;
this._Key4UD06 = string.Empty;
this._Key5UD06 = string.Empty;
this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD06);
this.JobEntryForm.BeforeToolClick += new Ice.Lib.Framework.BeforeToolClickEventHandler(this.JobEntryForm_BeforeToolClickForUD06);
this.JobEntryForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.JobEntryForm_AfterToolClickForUD06);
this.JobHead_Row.EpiRowChanged += new EpiRowChanged(this.JobHead_AfterRowChangeForUD06);
this.JobHead_DataView = this.JobHead_Row.dataView;
this.JobHead_DataView.ListChanged += new ListChangedEventHandler(this.JobHead_DataView_ListChangedForUD06);
this.JobHead_Row.BeforeResetDataView += new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.JobHead_BeforeResetDataViewForUD06);
this.JobHead_Row.AfterResetDataView += new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.JobHead_AfterResetDataViewForUD06);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// End Wizard Added Custom Method Calls
//FieldInfo fInfo = _edvJobHead.GetType().GetField("hasChildren", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField);
//if ( fInfo != null ) { fInfo.SetValue(_edvJobHead, false); }
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
if ((this._ud06Adapter != null))
{
this._ud06Adapter.Dispose();
this._ud06Adapter = null;
}
this._edvUD06 = null;
this._edvJobHead = null;
this.UD06_Column = null;
this._Key1UD06 = null;
this._Key2UD06 = null;
this._Key3UD06 = null;
this._Key4UD06 = null;
this._Key5UD06 = null;
this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD06);
this.JobEntryForm.BeforeToolClick -= new Ice.Lib.Framework.BeforeToolClickEventHandler(this.JobEntryForm_BeforeToolClickForUD06);
this.JobEntryForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.JobEntryForm_AfterToolClickForUD06);
this.JobHead_Row.EpiRowChanged -= new EpiRowChanged(this.JobHead_AfterRowChangeForUD06);
this.JobHead_DataView.ListChanged -= new ListChangedEventHandler(this.JobHead_DataView_ListChangedForUD06);
this.JobHead_DataView = null;
this.JobHead_Row.BeforeResetDataView -= new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.JobHead_BeforeResetDataViewForUD06);
this.JobHead_Row.AfterResetDataView -= new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.JobHead_AfterResetDataViewForUD06);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void InitializeUD06Adapter()
{
// Create an instance of the Adapter.
this._ud06Adapter = new UD06Adapter(this.oTrans);
this._ud06Adapter.BOConnect();
// Add Adapter Table to List of Views
// This allows you to bind controls to the custom UD Table
this._edvUD06 = new EpiDataView();
this._edvUD06.dataView = new DataView(this._ud06Adapter.UD06Data.UD06);
this._edvUD06.AddEnabled = true;
this._edvUD06.AddText = "New UD06";
if ((this.oTrans.EpiDataViews.ContainsKey("UD06View") == false))
{
this.oTrans.Add("UD06View", this._edvUD06);
}
// Initialize DataTable variable
this.UD06_Column = this._ud06Adapter.UD06Data.UD06;
// Initialize EpiDataView field.
this._edvJobHead = ((EpiDataView)(this.oTrans.EpiDataViews["JobHead"]));
Erp.UI.FrameWork.JobLib.EpiDataViewRelation jobHeadUD06Relation = new Erp.UI.FrameWork.JobLib.EpiDataViewRelation(this._edvUD06);
Erp.UI.FrameWork.JobLib.EpiDataViewRelation UD06Relation = new Erp.UI.FrameWork.JobLib.EpiDataViewRelation(this._edvJobHead);
// Set the parent view / keys for UD child view
string[] parentKeyFields = new string[3];
string[] childKeyFields = new string[3];
parentKeyFields[0] = "JobNum";
childKeyFields[0] = "Key2";
parentKeyFields[1] = "PartNum";
childKeyFields[1] = "Key1";
parentKeyFields[2] = "RevisionNum";
childKeyFields[2] = "Key3";
jobHeadUD06Relation.SetParent(UD06Relation, parentKeyFields, childKeyFields);
// Magic Here
Erp.UI.FrameWork.JobLib.EpiDataViewFilterManager x = new Erp.UI.FrameWork.JobLib.EpiDataViewFilterManager(this.oTrans);
x.AddRelation(jobHeadUD06Relation);
if ((this.oTrans.PrimaryAdapter != null))
{
// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD06.dataView.Table.Clone())
}
}
private void GetUD06Data(string key1, string key2, string key3, string key4, string key5)
{
if ((this._Key1UD06 != key1) || (this._Key2UD06 != key2) || (this._Key3UD06 != key3) || (this._Key4UD06 != key4) || (this._Key5UD06 != 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("UD06", whereClause);
// Call the adapter search.
SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
this._ud06Adapter.InvokeSearch(searchOptions);
if ((this._ud06Adapter.UD06Data.UD06.Rows.Count > 0))
{
this._edvUD06.Row = 0;
} else
{
this._edvUD06.Row = -1;
}
// Notify that data was updated.
this._edvUD06.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD06.Row, this._edvUD06.Column));
// Set key fields to their new values.
this._Key1UD06 = key1;
this._Key2UD06 = key2;
this._Key3UD06 = key3;
this._Key4UD06 = key4;
this._Key5UD06 = key5;
//MessageBox.Show("Made it here!");
}
//MessageBox.Show("Made it here too!");
EpiDataView edvOJI = (EpiDataView)(oTrans.EpiDataViews["UD06View"]);
int OJI = System.Convert.ToInt32(edvOJI.dataView[edvOJI.Row]["Number01"]);
MessageBox.Show("Got OJI! " + OJI.ToString());
txtOJI.Text = OJI.ToString();
}
private void GetNewUD06Record()
{
DataRow parentViewRow = this._edvJobHead.CurrentDataRow;
// Check for existence of Parent Row.
if ((parentViewRow == null))
{
return;
}
if (this._ud06Adapter.GetaNewUD06())
{
string jobnum = parentViewRow["JobNum"].ToString();
string partnum = parentViewRow["PartNum"].ToString();
string revisionnum = parentViewRow["RevisionNum"].ToString();
// Get unique row count id for Key5
int rowCount = this._ud06Adapter.UD06Data.UD06.Rows.Count;
int lineNum = rowCount;
bool goodIndex = false;
while ((goodIndex == false))
{
// Check to see if index exists
DataRow[] matchingRows = this._ud06Adapter.UD06Data.UD06.Select("Key5 = \'" + lineNum.ToString() + "\'");
if ((matchingRows.Length > 0))
{
lineNum = (lineNum + 1);
} else
{
goodIndex = true;
}
}
// Set initial UD Key values
DataRow editRow = this._ud06Adapter.UD06Data.UD06.Rows[(rowCount - 1)];
editRow.BeginEdit();
editRow["Key1"] = jobnum;
editRow["Key2"] = partnum;
editRow["Key3"] = revisionnum;
editRow["Key4"] = string.Empty;
editRow["Key5"] = lineNum.ToString();
editRow.EndEdit();
// Notify that data was updated.
this._edvUD06.Notify(new EpiNotifyArgs(this.oTrans, (rowCount - 1), this._edvUD06.Column));
}
}
private void SaveUD06Record()
{
// Save adapter data
this._ud06Adapter.Update();
}
private void DeleteUD06Record()
{
// Check to see if deleted view is ancestor view
bool isAncestorView = false;
Ice.Lib.Framework.EpiDataView parView = this._edvUD06.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._ud06Adapter.UD06Data.UD06.Select("Key1 = \'" + this._Key1UD06 + "\' AND Key2 = \'" + this._Key2UD06 + "\' AND Key3 = \'" + this._Key3UD06 + "\' AND Key4 = \'" + this._Key4UD06 + "\'");
for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
{
this._ud06Adapter.Delete(drsDeleted[i]);
}
} else
{
if ((this.oTrans.LastView == this._edvUD06))
{
if ((this._edvUD06.Row >= 0))
{
DataRow drDeleted = ((DataRow)(this._ud06Adapter.UD06Data.UD06.Rows[this._edvUD06.Row]));
if ((drDeleted != null))
{
if (this._ud06Adapter.Delete(drDeleted))
{
if ((_edvUD06.Row > 0))
{
_edvUD06.Row = (_edvUD06.Row - 1);
}
// Notify that data was updated.
this._edvUD06.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD06.Row, this._edvUD06.Column));
}
}
}
}
}
}
private void UndoUD06Changes()
{
this._ud06Adapter.UD06Data.RejectChanges();
// Notify that data was updated.
this._edvUD06.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD06.Row, this._edvUD06.Column));
}
private void ClearUD06Data()
{
this._Key1UD06 = string.Empty;
this._Key2UD06 = string.Empty;
this._Key3UD06 = string.Empty;
this._Key4UD06 = string.Empty;
this._Key5UD06 = string.Empty;
this._ud06Adapter.UD06Data.Clear();
// Notify that data was updated.
this._edvUD06.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD06.Row, this._edvUD06.Column));
}
private void baseToolbarsManager_ToolClickForUD06(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "EpiAddNewNew UD06":
GetNewUD06Record();
break;
case "ClearTool":
ClearUD06Data();
break;
case "UndoTool":
UndoUD06Changes();
break;
}
}
private void JobEntryForm_BeforeToolClickForUD06(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "SaveTool":
SaveUD06Record();
break;
}
}
private void JobEntryForm_AfterToolClickForUD06(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "DeleteTool":
if ((args.Cancelled == false))
{
DeleteUD06Record();
}
break;
}
}
private void JobHead_AfterRowChangeForUD06(EpiRowChangedArgs args)
{
// ** add AfterRowChange event handler
string jobnum = args.CurrentView.dataView[args.CurrentRow]["JobNum"].ToString();
string partnum = args.CurrentView.dataView[args.CurrentRow]["PartNum"].ToString();
string revisionnum = args.CurrentView.dataView[args.CurrentRow]["RevisionNum"].ToString();
GetUD06Data(jobnum, partnum, revisionnum, string.Empty, string.Empty);
MessageBox.Show("JobHead_AfterRowChangeForUD06");
}
private void JobHead_DataView_ListChangedForUD06(object sender, ListChangedEventArgs args)
{
// ** add ListChanged event handler
string jobnum = JobHead_DataView[0]["JobNum"].ToString();
string partnum = JobHead_DataView[0]["PartNum"].ToString();
string revisionnum = JobHead_DataView[0]["RevisionNum"].ToString();
GetUD06Data(jobnum, partnum, revisionnum, string.Empty, string.Empty);
MessageBox.Show("JobHead_DataView_ListChangedForUD06");
}
private void JobHead_BeforeResetDataViewForUD06(object sender, EventArgs args)
{
// ** remove ListChanged event handler
this.JobHead_DataView.ListChanged -= new ListChangedEventHandler(this.JobHead_DataView_ListChangedForUD06);
MessageBox.Show("JobHead_BeforeResetDataViewForUD06");
}
private void JobHead_AfterResetDataViewForUD06(object sender, EventArgs args)
{
// ** reassign DataView and add ListChanged event handler
this.JobHead_DataView = this.JobHead_Row.dataView;
this.JobHead_DataView.ListChanged += new ListChangedEventHandler(this.JobHead_DataView_ListChangedForUD06);
MessageBox.Show("JobHead_AfterResetDataViewForUD06");
}
}

