UD Table Delete From Parent Form Error

I have added a UD table to the Project form in a new tab. As I was working with it I got a message that something was out of order (at least I think that is what it said). Add and update work fine in the grid that the UD Table is attached to. I did use the wizard to link it to the Project table. However when I go to delete a record from the UD table I get this error:


I have looked at other forms I have done this with and I can’t see a difference. Does anyone know what I need to add back in to get the delete to work?

Please share your code.

Here is the code. The bulk of the UD32 code was generated from the wizard when I added UD32 as a child to the Project.


extern alias Erp_Contracts_BO_Project;
extern alias Erp_Contracts_BO_ProjPhaseSearch;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_Warehse;
extern alias Erp_Contracts_BO_JobEntry;
extern alias Erp_Contracts_BO_JobAsmSearch;
extern alias Erp_Contracts_BO_JobMtlSearch;
extern alias Ice_Contracts_BO_DynamicQuery;
extern alias Ice_Contracts_BO_UD32;
extern alias Ice_Adapters_UD32;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.BO;
using Ice.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 Ice.Proxy.BO;

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

	private EpiDataView edvProject;
	private EpiBaseAdapter oTrans_projectAdapter;
	private UD32Adapter _ud32Adapter;
	private EpiDataView _edvProject;
	private DataTable UD32_Column;
	private EpiDataView _edvUD32;
	private string _Key1UD32;
	private string _Key2UD32;
	private string _Key3UD32;
	private string _Key4UD32;
	private string _Key5UD32;
	private DataView Project_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
		cmbCustContract.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
		this.edvProject = ((EpiDataView)(this.oTrans.EpiDataViews["Project"]));
		this.edvProject.EpiViewNotification += new EpiViewNotification(this.edvProject_EpiViewNotification);
		this.oTrans_projectAdapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_projectAdapter"]));
		this.ProjectEntryForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClick);
		InitializeUD32Adapter();
		this._Key1UD32 = string.Empty;
		this._Key2UD32 = string.Empty;
		this._Key3UD32 = string.Empty;
		this._Key4UD32 = string.Empty;
		this._Key5UD32 = string.Empty;
		this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD32);
		this.ProjectEntryForm.BeforeToolClick += new Ice.Lib.Framework.BeforeToolClickEventHandler(this.ProjectEntryForm_BeforeToolClickForUD32);
		this.ProjectEntryForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClickForUD32);
		this.Project_Row.EpiRowChanged += new EpiRowChanged(this.Project_AfterRowChangeForUD32);
		this.Project_DataView = this.Project_Row.dataView;
		this.Project_DataView.ListChanged += new ListChangedEventHandler(this.Project_DataView_ListChangedForUD32);
		this.Project_Row.BeforeResetDataView += new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.Project_BeforeResetDataViewForUD32);
		this.Project_Row.AfterResetDataView += new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.Project_AfterResetDataViewForUD32);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		this.btnConProEng.Click += new System.EventHandler(this.btnConProEng_Click);
		this.txtConProEngID.TextChanged += new System.EventHandler(this.txtConProEngID_TextChanged);
		this.txtConProEngID.AfterExitEditMode += new System.EventHandler(this.txtConProEngID_AfterExitEditMode);
		this.txtConPAID.AfterExitEditMode += new System.EventHandler(this.txtConPAID_AfterExitEditMode);
		this.btnPA.Click += new System.EventHandler(this.btnPA_Click);
		SetExtendedProperties();
		this.CobraButton.Click += new System.EventHandler(this.CobraButton_Click);
		this.RevGrid.AfterCellUpdate += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.RevGrid_AfterCellUpdate);
		this.RevGrid.AfterRowInsert += new Infragistics.Win.UltraWinGrid.RowEventHandler(this.RevGrid_AfterRowInsert);
		// 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

		this.edvProject.EpiViewNotification -= new EpiViewNotification(this.edvProject_EpiViewNotification);
		this.edvProject = null;
		this.btnConProEng.Click -= new System.EventHandler(this.btnConProEng_Click);
		this.oTrans_projectAdapter = null;
		this.ProjectEntryForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClick);
		this.txtConProEngID.TextChanged -= new System.EventHandler(this.txtConProEngID_TextChanged);
		this.txtConProEngID.AfterExitEditMode -= new System.EventHandler(this.txtConProEngID_AfterExitEditMode);
		this.txtConPAID.AfterExitEditMode -= new System.EventHandler(this.txtConPAID_AfterExitEditMode);
		this.btnPA.Click -= new System.EventHandler(this.btnPA_Click);
		this.CobraButton.Click -= new System.EventHandler(this.CobraButton_Click);
		if ((this._ud32Adapter != null))
		{
			this._ud32Adapter.Dispose();
			this._ud32Adapter = null;
		}
		this._edvUD32 = null;
		this._edvProject = null;
		this.UD32_Column = null;
		this._Key1UD32 = null;
		this._Key2UD32 = null;
		this._Key3UD32 = null;
		this._Key4UD32 = null;
		this._Key5UD32 = null;
		this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD32);
		this.ProjectEntryForm.BeforeToolClick -= new Ice.Lib.Framework.BeforeToolClickEventHandler(this.ProjectEntryForm_BeforeToolClickForUD32);
		this.ProjectEntryForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClickForUD32);
		this.Project_Row.EpiRowChanged -= new EpiRowChanged(this.Project_AfterRowChangeForUD32);
		this.Project_DataView.ListChanged -= new ListChangedEventHandler(this.Project_DataView_ListChangedForUD32);
		this.Project_DataView = null;
		this.Project_Row.BeforeResetDataView -= new Ice.Lib.Framework.EpiDataView.BeforeResetDataViewDelegate(this.Project_BeforeResetDataViewForUD32);
		this.Project_Row.AfterResetDataView -= new Ice.Lib.Framework.EpiDataView.AfterResetDataViewDelegate(this.Project_AfterResetDataViewForUD32);
		this.RevGrid.AfterCellUpdate -= new Infragistics.Win.UltraWinGrid.CellEventHandler(this.RevGrid_AfterCellUpdate);
		this.RevGrid.AfterRowInsert -= new Infragistics.Win.UltraWinGrid.RowEventHandler(this.RevGrid_AfterRowInsert);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void ProjectEntryForm_Load(object sender, EventArgs args)
	{
		// Add Event Handler Code
		SettingSystemObjectProperties();
	}

	private void SettingSystemObjectProperties()
	{
		/***********Hide Objects***************/
		Ice.Lib.Framework.EpiLabel mylblUsePriceList = (Ice.Lib.Framework.EpiLabel)csm.GetNativeControlReference("f2a636c8-0e24-48c5-b00b-27684d30936c");
		mylblUsePriceList.Left = -416;
		mylblUsePriceList.Top = 54;		
		//Location: 416, 54

		Ice.Lib.Framework.EpiCheckBox mychkUsePriceList = (Ice.Lib.Framework.EpiCheckBox)csm.GetNativeControlReference("c27bbd03-0649-47ce-a698-9d39b418683a");
		mychkUsePriceList.Left = -649;
		mychkUsePriceList.Top = 54;
		//Location: 649, 54
		
		Ice.Lib.Framework.EpiLabel mylblConListCode= (Ice.Lib.Framework.EpiLabel)csm.GetNativeControlReference("328ad627-23f9-41e9-be2f-b4f072b2ee8d");
		mylblConListCode.Left = -416;
		mylblConListCode.Top = 76;
		//Location: 416, 76
		
		Erp.UI.Controls.Combos.PriceLstCombo mycmbConListCode = (Erp.UI.Controls.Combos.PriceLstCombo)csm.GetNativeControlReference("ceec457b-762f-4fd0-b881-e0350afa3dcd");
		mycmbConListCode.Left = -649;
		mycmbConListCode.Top = 76;
		//Location: -649, 76
		/***********Relocate Objects************/
		
		Ice.Lib.Framework.EpiButton mybtnConProjMgr = (Ice.Lib.Framework.EpiButton)csm.GetNativeControlReference("2c31c2c0-7123-4783-82db-7a38f94bd59c");
		mybtnConProjMgr.Left = 471;
		mybtnConProjMgr.Top = 53;
		//Location: 471, 102
		//Re-Location: 471, 53
		
		Ice.Lib.Framework.EpiTextBox mytxtConProjMgr = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("051762b6-650d-4bd8-8a87-b523117c5433");
		mytxtConProjMgr.Left = 649;
		mytxtConProjMgr.Top = 53;
		//Location: 649, 101
		//Re-Location: 649, 53
		
		Ice.Lib.Framework.EpiLabel mylblConProjMgrName = (Ice.Lib.Framework.EpiLabel)csm.GetNativeControlReference("f17fb7e3-887d-4cd1-abc6-bf55c5c9f646");
		mylblConProjMgrName.Left = 420;
		mylblConProjMgrName.Top = 77;
		//Location: 420, 128
		//Re-Location: 420, 77
		
		Ice.Lib.Framework.EpiTextBox mytxtConProjMgrName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("be4fc2c9-6691-4a18-ae09-65eb72295784");
		mytxtConProjMgrName.Left = 649;
		mytxtConProjMgrName.Top = 76;
		//Location: 649, 125
		//Re-Location: 649, 76

		/************Created Objects ****************/
		setProjectEngineerReadOnly(false);
		Ice.Lib.Framework.EpiTextBox mytxtConProEngID = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("80878fb6-12b5-4193-8158-ff9b2fa85d2b");
		mytxtConProEngID.ReadOnly = true;
		Ice.Lib.Framework.EpiTextBox mytxtConProEngName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("2ae2683b-1806-4d60-8ae8-f46ba7820e1d");
		mytxtConProEngName.ReadOnly = true;
	}

	private void setProjectEngineerReadOnly(bool bReadOnly)
	{
		Ice.Lib.Framework.EpiButton mybtnConProEng = (Ice.Lib.Framework.EpiButton)csm.GetNativeControlReference("fa97a217-ab48-49cb-bd90-8b6a0ecc4b94");
		mybtnConProEng.ReadOnly = bReadOnly;
	}

	private string getProjAdminName()
	{
		Ice.Lib.Framework.EpiTextBox mytxtConProAdminName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("60f7ee56-3027-40fc-8cc8-d209319b79ed");
		return mytxtConProAdminName.Text;
	}
	private string getProjEngName()
	{
		Ice.Lib.Framework.EpiTextBox mytxtConProjEngName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("2ae2683b-1806-4d60-8ae8-f46ba7820e1d");
		return mytxtConProjEngName.Text;
	}

	private void setProjAdminName(string sName)
	{
		Ice.Lib.Framework.EpiTextBox mytxtConProAdminName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("60f7ee56-3027-40fc-8cc8-d209319b79ed");
		mytxtConProAdminName.Text = sName;
	}
	private void setProjEngName(string sName)
	{
		Ice.Lib.Framework.EpiTextBox mytxtConProjEngName = (Ice.Lib.Framework.EpiTextBox)csm.GetNativeControlReference("2ae2683b-1806-4d60-8ae8-f46ba7820e1d");
		mytxtConProjEngName.Text = sName;
	}	

	private void edvProject_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.Initialize))
		{
			if ((args.Row > -1))
			{
				if(string.IsNullOrEmpty(view.dataView[args.Row]["ConProjEng_c"].ToString()) == false)
				{
					if(string.IsNullOrEmpty(getProjEngName()) == true)
					{
						SearchOnEmpBasicAdapterShowDialog(view.dataView[args.Row]["ConProjEng_c"].ToString());
					}
				}
				else
				{
					setProjEngName("");
				}
				if(string.IsNullOrEmpty(view.dataView[args.Row]["ConProjAdmin_c"].ToString()) == false)
				{
					if(string.IsNullOrEmpty(getProjAdminName()) == true)
					{
						SearchOnEmpBasicAdapterShowDialogPA(view.dataView[args.Row]["ConProjAdmin_c"].ToString());
					}
				}
				else
				{
					setProjAdminName("");
				}
			}
		}
	}

	private void SearchOnEmpBasicAdapterShowDialog(string sID)
	{
		// Wizard Generated Search Method
		// You will need to call this method from another method in custom code
		// For example, [Form]_Load or [Button]_Click

		bool bShowDialog = string.IsNullOrEmpty(sID);
		string sName = string.Empty;

		bool recSelected;

		string whereClause = (bShowDialog== true ? string.Empty : "EmpID='" + sID + "'");

		System.Data.DataSet dsEmpBasicAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "EmpBasicAdapter", out recSelected, bShowDialog, whereClause);
		if (recSelected)
		{
			System.Data.DataRow adapterRow = dsEmpBasicAdapter.Tables[0].Rows[0];

			// Map Search Fields to Application Fields
			EpiDataView edvProject = ((EpiDataView)(this.oTrans.EpiDataViews["Project"]));
			System.Data.DataRow edvProjectRow = edvProject.CurrentDataRow;
			if ((edvProjectRow != null))
			{
				//if(bShowDialog == true)
				//{
					edvProjectRow.BeginEdit();
					edvProjectRow["ConProjEng_c"] = adapterRow["EmpID"];
					edvProjectRow["ConProjEngName_c"] = adapterRow["Name"].ToString();
					edvProjectRow.EndEdit();

				//}
			}
			//setProjEngName(sName);
		}


	}

	private void SearchOnEmpBasicAdapterShowDialogPA(string sID)
	{

		bool bShowDialog = string.IsNullOrEmpty(sID);
		string sName = string.Empty;

		bool recSelected;

		string whereClause = (bShowDialog== true ? string.Empty : "EmpID='" + sID + "'");

		System.Data.DataSet dsEmpBasicAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "EmpBasicAdapter", out recSelected, bShowDialog, whereClause);
		if (recSelected)
		{
			System.Data.DataRow adapterRow = dsEmpBasicAdapter.Tables[0].Rows[0];

			// Map Search Fields to Application Fields
			EpiDataView edvProject = ((EpiDataView)(this.oTrans.EpiDataViews["Project"]));
			System.Data.DataRow edvProjectRow = edvProject.CurrentDataRow;
			if ((edvProjectRow != null))
			{
				//if(bShowDialog == true)
				//{
					edvProjectRow.BeginEdit();
					edvProjectRow["ConProjAdmin_c"] = adapterRow["EmpID"];
					edvProjectRow["ConProjAdminName_c"] = adapterRow["Name"].ToString();
					edvProjectRow.EndEdit();

				//}
			}
			//setProjAdminName(sName);
		}


	}

	private void btnConProEng_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		SearchOnEmpBasicAdapterShowDialog("");
	}

	private void ProjectEntryForm_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
	{
		int i = 0;
		switch(args.Tool.Key)
		{
			case "ClearTool":
				setProjEngName("");
				setProjAdminName("");
				break;
			default:
				break;
		}
	}

	private void txtConProEngID_TextChanged(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
	}






	private void txtConProEngID_AfterExitEditMode(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		string ID = ((Ice.Lib.Framework.EpiTextBox)sender).Text;
		if(string.IsNullOrEmpty(ID) == true)
		{
			setProjEngName("");
		}
		else
		{
			SearchOnEmpBasicAdapterShowDialog(ID);
		}
	}


	private void txtConPAID_AfterExitEditMode(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		string ID = ((Ice.Lib.Framework.EpiTextBox)sender).Text;
		if(string.IsNullOrEmpty(ID) == true)
		{
			setProjAdminName("");
		}
		else
		{
			SearchOnEmpBasicAdapterShowDialogPA(ID);
		}
	}

	private void btnPA_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		SearchOnEmpBasicAdapterShowDialogPA("");
	}



	private void SetExtendedProperties()
	{
		// Begin Wizard Added EpiDataView Initialization
		EpiDataView edvProjPhase = ((EpiDataView)(this.oTrans.EpiDataViews["ProjPhase"]));
		// End Wizard Added EpiDataView Initialization

		// Begin Wizard Added Conditional Block
		if (edvProjPhase.dataView.Table.Columns.Contains("UserMapData"))
		{
			// Begin Wizard Added ExtendedProperty Settings: edvProjPhase-UserMapData
			edvProjPhase.dataView.Table.Columns["UserMapData"].ExtendedProperties["ReadOnly"] = false;
			// End Wizard Added ExtendedProperty Settings: edvProjPhase-UserMapData
		}
		EpiDataView edvUD32View = ((EpiDataView)(this.oTrans.EpiDataViews["UD32View"]));
			edvUD32View.dataView.Table.Columns["Number08"].ExtendedProperties["ReadOnly"] = true;
			/*edvUD32View.dataView.Table.Columns["Number01"].ExtendedProperties["Format"] = "#,##9.99";
			edvUD32View.dataView.Table.Columns["Number02"].ExtendedProperties["Format"] = "#,##9.99";		
			edvUD32View.dataView.Table.Columns["Number03"].ExtendedProperties["Format"] = "#,##9.99";		
			edvUD32View.dataView.Table.Columns["Number04"].ExtendedProperties["Format"] = "#,##9.99";		
			edvUD32View.dataView.Table.Columns["Number05"].ExtendedProperties["Format"] = "#,##9.99";		
			edvUD32View.dataView.Table.Columns["Number06"].ExtendedProperties["Format"] = "#,##9.99";		
			edvUD32View.dataView.Table.Columns["Number07"].ExtendedProperties["Format"] = "#,##9.99";	*/				
			edvUD32View.dataView.Table.Columns["Number08"].ExtendedProperties["Format"] = "###,###,##9.99";		
		// End Wizard Added Conditional Block
	}

	private void CobraButton_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		EpiTextBox ProjectID = (EpiTextBox)csm.GetNativeControlReference("46710d2c-0584-4be4-8393-a4247570b19b");
		string project = ProjectID.Text;
		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("ASI_Cobra_Project");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("ProjectID", project , "nvarchar",false, Guid.NewGuid(),"A");
		dqa.ExecuteByID("ASI_Cobra_Project",qeds);
		DataTable dt = dqa.QueryResults.Tables["Results"];
		//just go get the first row and result
		DataRow r = dt.Rows[0];
		string Cobra_Project = r["UD19_Character01"].ToString();
		//now go get the data  Cobra_Project_Cost
		qeds = dqa.GetQueryExecutionParametersByID("Cobra_Project_Cost");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("ProjectID", Cobra_Project , "nvarchar",false, Guid.NewGuid(),"A");
		dqa.ExecuteByID("Cobra_Project_Cost",qeds);
		DataTable dtCobra = dqa.QueryResults.Tables["Results"];
		var edv = oTrans.Factory("ProjectCst");
		decimal calcVal = 0;
		edv.dataView[edv.Row].BeginEdit();
		foreach (DataRow dr in dtCobra.Rows)
		{
			if (dr["Calculated_Code_Type"].ToString() == "LABOR")
			{
				edv.dataView[edv.Row]["ManEstCtcLbrHrs"] = dr["Calculated_Total_Labor_Hours"].ToString();
				edv.dataView[edv.Row]["ManEstCtcBurHrs"] = dr["Calculated_Total_Labor_Hours"].ToString();
				calcVal = Convert.ToDecimal(dr["Calculated_Total_Labor_Dollars"].ToString()) - Convert.ToDecimal(edv.dataView[edv.Row]["TotActLbrCost"]) - Convert.ToDecimal(edv.dataView[edv.Row]["TotCtcLbrCost"]);
				edv.dataView[edv.Row]["DocManEstCtcLbrCost"] = calcVal;
				calcVal = Convert.ToDecimal(dr["Calculated_Total_Labor_Burden"].ToString()) - Convert.ToDecimal(edv.dataView[edv.Row]["TotActBurCost"]) - Convert.ToDecimal(edv.dataView[edv.Row]["TotCtcBurCost"]);
				edv.dataView[edv.Row]["DocManEstCtcBurCost"] = calcVal;
			}
			else if (dr["Calculated_Code_Type"].ToString() == "ODC")
			{
				calcVal = Convert.ToDecimal(dr["Calculated_Total_ODC"].ToString()) - Convert.ToDecimal(edv.dataView[edv.Row]["TotActODCCost"]) - Convert.ToDecimal(edv.dataView[edv.Row]["TotCTCODCCost"]);
				edv.dataView[edv.Row]["DocManEstCtcODCCost"] = calcVal;
			}
			else
			{
				calcVal = Convert.ToDecimal(dr["Calculated_Total_Material"].ToString()) - Convert.ToDecimal(edv.dataView[edv.Row]["TotActMtlCost"]) - Convert.ToDecimal(edv.dataView[edv.Row]["TotCtcMtlCost"]);
				edv.dataView[edv.Row]["DocManEstCtcMtlCost"] = calcVal;
				calcVal = Convert.ToDecimal(dr["Calculated_Total_Material_Burden"].ToString()) - Convert.ToDecimal(edv.dataView[edv.Row]["TotActMtlBurCost"]) - Convert.ToDecimal(edv.dataView[edv.Row]["TotCtcMtlBurCost"]);
				edv.dataView[edv.Row]["DocManEstCtcMtlBurCost"] = calcVal;
			}
		}
		edv.dataView[edv.Row].EndEdit();
	}

	private void InitializeUD32Adapter()
	{
		// Create an instance of the Adapter.
		this._ud32Adapter = new UD32Adapter(this.oTrans);
		this._ud32Adapter.BOConnect();

		// Add Adapter Table to List of Views
		// This allows you to bind controls to the custom UD Table
		this._edvUD32 = new EpiDataView();
		this._edvUD32.dataView = new DataView(this._ud32Adapter.UD32Data.UD32);
		this._edvUD32.AddEnabled = true;
		this._edvUD32.AddText = "New Contract Revision";
		if ((this.oTrans.EpiDataViews.ContainsKey("UD32View") == false))
		{
			this.oTrans.Add("UD32View", this._edvUD32);
		}

		// Initialize DataTable variable
		this.UD32_Column = this._ud32Adapter.UD32Data.UD32;

		// Initialize EpiDataView field.
		this._edvProject = ((EpiDataView)(this.oTrans.EpiDataViews["Project"]));

		// Set the parent view / keys for UD child view
		string[] parentKeyFields = new string[1];
		string[] childKeyFields = new string[1];
		parentKeyFields[0] = "ProjectID";
		childKeyFields[0] = "Key1";
		this._edvUD32.SetParentView(this._edvProject, parentKeyFields, childKeyFields);

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

	}

	private void GetUD32Data(string key1, string key2, string key3, string key4, string key5)
	{
		if ((this._Key1UD32 != key1) || (this._Key2UD32 != key2) || (this._Key3UD32 != key3) || (this._Key4UD32 != key4) || (this._Key5UD32 != 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("UD32", whereClause);

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

			if ((this._ud32Adapter.UD32Data.UD32.Rows.Count > 0))
			{
				this._edvUD32.Row = 0;
			} else
			{
				this._edvUD32.Row = -1;
			}

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

			// Set key fields to their new values.
			this._Key1UD32 = key1;
			this._Key2UD32 = key2;
			this._Key3UD32 = key3;
			this._Key4UD32 = key4;
			this._Key5UD32 = key5;
		}
	}

	private void GetNewUD32Record()
	{
		DataRow parentViewRow = this._edvProject.CurrentDataRow;
		// Check for existence of Parent Row.
		if ((parentViewRow == null))
		{
			return;
		}
		if (this._ud32Adapter.GetaNewUD32())
		{
			string projectid = parentViewRow["ProjectID"].ToString();

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

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

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

	private void SaveUD32Record()
	{
		// Save adapter data
		this._ud32Adapter.Update();
	}

	private void DeleteUD32Record()
	{
		MessageBox.Show("In delete");
		// Check to see if deleted view is ancestor view
		bool isAncestorView = false;
		Ice.Lib.Framework.EpiDataView parView = this._edvUD32.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._ud32Adapter.UD32Data.UD32.Select("Key1 = \'" + this._Key1UD32 + "\' AND Key2 = \'" + this._Key2UD32 + "\' AND Key3 = \'" + this._Key3UD32 + "\' AND Key4 = \'" + this._Key4UD32 + "\'");
			for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
			{
				this._ud32Adapter.Delete(drsDeleted[i]);
			}
		} else
		{
			if ((this.oTrans.LastView == this._edvUD32))
			{
				if ((this._edvUD32.Row >= 0))
				{
					DataRow drDeleted = ((DataRow)(this._ud32Adapter.UD32Data.UD32.Rows[this._edvUD32.Row]));
					if ((drDeleted != null))
					{
						if (this._ud32Adapter.Delete(drDeleted))
						{
							if ((_edvUD32.Row > 0))
							{
								_edvUD32.Row = (_edvUD32.Row - 1);
							}

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

	private void UndoUD32Changes()
	{
		this._ud32Adapter.UD32Data.RejectChanges();

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

	private void ClearUD32Data()
	{
		this._Key1UD32 = string.Empty;
		this._Key2UD32 = string.Empty;
		this._Key3UD32 = string.Empty;
		this._Key4UD32 = string.Empty;
		this._Key5UD32 = string.Empty;

		this._ud32Adapter.UD32Data.Clear();

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

	private void baseToolbarsManager_ToolClickForUD32(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
	{
		// EpiMessageBox.Show(args.Tool.Key);
		switch (args.Tool.Key)
		{
			case "EpiAddNewNew Contract Revision":
				GetNewUD32Record();
				break;

			case "ClearTool":
				ClearUD32Data();
				break;

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

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

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

	private void Project_AfterRowChangeForUD32(EpiRowChangedArgs args)
	{
		// ** add AfterRowChange event handler
		string projectid = args.CurrentView.dataView[args.CurrentRow]["ProjectID"].ToString();
		GetUD32Data(projectid, string.Empty, string.Empty, string.Empty, string.Empty);
	}

	private void Project_DataView_ListChangedForUD32(object sender, ListChangedEventArgs args)
	{
		// ** add ListChanged event handler
		string projectid = Project_DataView[0]["ProjectID"].ToString();
		GetUD32Data(projectid, string.Empty, string.Empty, string.Empty, string.Empty);
	}

	private void Project_BeforeResetDataViewForUD32(object sender, EventArgs args)
	{
		// ** remove ListChanged event handler
		this.Project_DataView.ListChanged -= new ListChangedEventHandler(this.Project_DataView_ListChangedForUD32);
	}

	private void Project_AfterResetDataViewForUD32(object sender, EventArgs args)
	{
		// ** reassign DataView and add ListChanged event handler
		this.Project_DataView = this.Project_Row.dataView;
		this.Project_DataView.ListChanged += new ListChangedEventHandler(this.Project_DataView_ListChangedForUD32);
	}

	private void RevGrid_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
	{
		// ** Place Event Handling Code Here **
		//switch (args.Cell.Column.PropertyDescriptor.DisplayName)
		string colName = args.Cell.Column.PropertyDescriptor.Name;
		float cValue;
		//MessageBox.Show('a' + colName + 'a');
		
		if (colName == "Date01")
		{
			//MessageBox.Show("Date " + args.Cell.Row.Cells["Key02"].Value);
			string xdate = args.Cell.Row.Cells["Date01"].Value.ToString();
			string.Format("{0:MM/dd/yyyy}",xdate);
			//MessageBox.Show("In date " + xdate);
		}
		else if (colName ==  "Number01" || colName ==  "Number02" || colName ==  "Number03" || colName ==  "Number04"|| 
				colName ==  "Number05" || colName ==  "Number06" || colName ==  "Number07" )
		{
			//MessageBox.Show("In number " + colName + float.Parse(args.Cell.Row.Cells["Number01"].Value.ToString()) );
			cValue = float.Parse(args.Cell.Row.Cells["Number01"].Value.ToString()) + float.Parse(args.Cell.Row.Cells["Number02"].Value.ToString()) + 
				float.Parse(args.Cell.Row.Cells["Number03"].Value.ToString()) + float.Parse(args.Cell.Row.Cells["Number04"].Value.ToString()) + float.Parse(args.Cell.Row.Cells["Number05"].Value.ToString()) +
				float.Parse(args.Cell.Row.Cells["Number06"].Value.ToString()) + float.Parse(args.Cell.Row.Cells["Number07"].Value.ToString());	
			//MessageBox.Show("calc value = " + cValue.ToString());	
			args.Cell.Row.Cells["Number08"].Value = cValue;
		}
		else
		{
			//MessageBox.Show("Default " + colName);
		}
		//MessageBox.Show("Number " + args.Cell.Row.Cells["Number08"].Value);

	}

	private void RevGrid_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs args)
	{
		// ** Place Event Handling Code Here **
		//set the key on the add row
		EpiTextBox ProjectID = (EpiTextBox)csm.GetNativeControlReference("46710d2c-0584-4be4-8393-a4247570b19b");
		string PID = ProjectID.Text;
		args.Row.Cells["Key01"].Value = PID;
	}
}