Hi everyone,
I have been asked to update a customisation that was done on our Project Entry (Not by Me).
We have a grid as pictured below, where I have been asked to add a column displaying the TerritoryID. As you can see I have done the easy bit by adding the column but I don’t how to edit the code to actually populate it with the TerritoryID. Can any customisation experts help me?
Here is the code;
// **************************************************
// Custom code for ProjectEntryForm
// Created: 26/04/2017 14:28:07
// **************************************************
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 Infragistics.Win.UltraWinGrid;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
private UD20Adapter _ud20Adapter;
private EpiDataView _edvProject;
private DataTable UD20_Column;
private EpiDataView _edvUD20;
private string _Key1UD20;
private string _Key2UD20;
private string _Key3UD20;
private string _Key4UD20;
private string _Key5UD20;
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
InitializeUD20Adapter();
this._Key1UD20 = string.Empty;
this._Key2UD20 = string.Empty;
this._Key3UD20 = string.Empty;
this._Key4UD20 = string.Empty;
this._Key5UD20 = string.Empty;
this.baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD20);
this.ProjectEntryForm.BeforeToolClick += new Ice.Lib.Framework.BeforeToolClickEventHandler(this.ProjectEntryForm_BeforeToolClickForUD20);
this.ProjectEntryForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClickForUD20);
this.Project_Row.EpiRowChanged += new EpiRowChanged(this.Project_AfterRowChangeForUD20);
this.Project_DataView = this.Project_Row.dataView;
this.Project_DataView.ListChanged += new ListChangedEventHandler(this.Project_DataView_ListChangedForUD20);
this.UD20_Column.ColumnChanged += new DataColumnChangeEventHandler(this.UD20_AfterFieldChange);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
SetExtendedProperties();
// 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._ud20Adapter != null))
{
this._ud20Adapter.Dispose();
this._ud20Adapter = null;
}
this._edvUD20 = null;
this._edvProject = null;
this.UD20_Column = null;
this._Key1UD20 = null;
this._Key2UD20 = null;
this._Key3UD20 = null;
this._Key4UD20 = null;
this._Key5UD20 = null;
this.baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.baseToolbarsManager_ToolClickForUD20);
this.ProjectEntryForm.BeforeToolClick -= new Ice.Lib.Framework.BeforeToolClickEventHandler(this.ProjectEntryForm_BeforeToolClickForUD20);
this.ProjectEntryForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.ProjectEntryForm_AfterToolClickForUD20);
this.Project_Row.EpiRowChanged -= new EpiRowChanged(this.Project_AfterRowChangeForUD20);
this.Project_DataView.ListChanged -= new ListChangedEventHandler(this.Project_DataView_ListChangedForUD20);
this.Project_DataView = null;
this.UD20_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.UD20_AfterFieldChange);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void SearchOnCountryAdapterFillDropDown()
{
// 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 recSelected;
string whereClause = string.Empty;
System.Data.DataSet dsCountryAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "CountryAdapter", out recSelected, false, whereClause);
if (recSelected)
{
// Set EpiUltraCombo Properties
this.CountryCmb.ValueMember = "CountryNum";
this.CountryCmb.DataSource = dsCountryAdapter;
this.CountryCmb.DisplayMember = "Description";
string[] fields = new string[] {
"Description"};
this.CountryCmb.SetColumnFilter(fields);
}
}
private void ProjectEntryForm_Load(object sender, EventArgs args)
{
// Add Event Handler Code
EpiUltraGrid projCustGrid = ((EpiUltraGrid)csm.GetNativeControlReference("443cbd92-c1f6-4848-a739-7588302d4e3e"));
UltraGridBand projCustGridBand = projCustGrid.DisplayLayout.Bands[0];
projCustGridBand.Columns["Number01"].ValueList = baqCustNum;
projCustGridBand.Columns["Number01"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
projCustGridBand.Columns["ShortChar01"].ValueList = CustTypeCmb;
projCustGridBand.Columns["ShortChar01"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
CountryCmb.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
SalesRepTxt.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
SearchOnCountryAdapterFillDropDown();
SearchOnSalesRepAdapterFillDropDown();
}
private void SearchOnSalesRepAdapterFillDropDown()
{
// 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 recSelected;
string whereClause = string.Empty;
System.Data.DataSet dsSalesRepAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "SalesRepAdapter", out recSelected, false, whereClause);
if (recSelected)
{
// Set EpiUltraCombo Properties
this.SalesRepTxt.ValueMember = "SalesRepCode";
this.SalesRepTxt.DataSource = dsSalesRepAdapter;
this.SalesRepTxt.DisplayMember = "Name";
string[] fields = new string[] {
"Name"};
this.SalesRepTxt.SetColumnFilter(fields);
}
}
private void InitializeUD20Adapter()
{
// Create an instance of the Adapter.
this._ud20Adapter = new UD20Adapter(this.oTrans);
this._ud20Adapter.BOConnect();
// Add Adapter Table to List of Views
// This allows you to bind controls to the custom UD Table
this._edvUD20 = new EpiDataView();
this._edvUD20.dataView = new DataView(this._ud20Adapter.UD20Data.UD20);
this._edvUD20.AddEnabled = true;
//this._edvUD20.AddText = "New UD20";
this._edvUD20.AddText = "New Project Customer";
if ((this.oTrans.EpiDataViews.ContainsKey("UD20View") == false))
{
this.oTrans.Add("UD20View", this._edvUD20);
}
// Initialize DataTable variable
this.UD20_Column = this._ud20Adapter.UD20Data.UD20;
// 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._edvUD20.SetParentView(this._edvProject, parentKeyFields, childKeyFields);
if ((this.oTrans.PrimaryAdapter != null))
{
// this.oTrans.PrimaryAdapter.GetCurrentDataSet(Ice.Lib.Searches.DataSetMode.RowsDataSet).Tables.Add(this._edvUD20.dataView.Table.Clone())
}
}
private void GetUD20Data(string key1, string key2, string key3, string key4, string key5)
{
if ((this._Key1UD20 != key1) || (this._Key2UD20 != key2) || (this._Key3UD20 != key3) || (this._Key4UD20 != key4) || (this._Key5UD20 != 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("UD20", whereClause);
// Call the adapter search.
SearchOptions searchOptions = SearchOptions.CreateRuntimeSearch(whereClauses, DataSetMode.RowsDataSet);
this._ud20Adapter.InvokeSearch(searchOptions);
if ((this._ud20Adapter.UD20Data.UD20.Rows.Count > 0))
{
this._edvUD20.Row = 0;
} else
{
this._edvUD20.Row = -1;
}
// Notify that data was updated.
this._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD20.Row, this._edvUD20.Column));
// Set key fields to their new values.
this._Key1UD20 = key1;
this._Key2UD20 = key2;
this._Key3UD20 = key3;
this._Key4UD20 = key4;
this._Key5UD20 = key5;
}
}
private void GetNewUD20Record()
{
DataRow parentViewRow = this._edvProject.CurrentDataRow;
// Check for existence of Parent Row.
if ((parentViewRow == null))
{
return;
}
else
{
oTrans.Update();
}
if (this._ud20Adapter.GetaNewUD20())
{
string projectid = parentViewRow["ProjectID"].ToString();
// Get unique row count id for Key5
int rowCount = this._ud20Adapter.UD20Data.UD20.Rows.Count;
int lineNum = rowCount;
bool goodIndex = false;
while ((goodIndex == false))
{
// Check to see if index exists
DataRow[] matchingRows = this._ud20Adapter.UD20Data.UD20.Select("Key5 = \'" + lineNum.ToString() + "\'");
if ((matchingRows.Length > 0))
{
lineNum = (lineNum + 1);
} else
{
goodIndex = true;
}
}
// Set initial UD Key values
DataRow editRow = this._ud20Adapter.UD20Data.UD20.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._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, (rowCount - 1), this._edvUD20.Column));
}
}
private void SaveUD20Record()
{
// Save adapter data
this._ud20Adapter.Update();
}
private void DeleteUD20Record()
{
// Check to see if deleted view is ancestor view
bool isAncestorView = false;
Ice.Lib.Framework.EpiDataView parView = this._edvUD20.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._ud20Adapter.UD20Data.UD20.Select("Key1 = \'" + this._Key1UD20 + "\' AND Key2 = \'" + this._Key2UD20 + "\' AND Key3 = \'" + this._Key3UD20 + "\' AND Key4 = \'" + this._Key4UD20 + "\'");
for (int i = 0; (i < drsDeleted.Length); i = (i + 1))
{
this._ud20Adapter.Delete(drsDeleted[i]);
}
}/* else
{
MessageBox.Show("processing for not ancestor");
if ((this.oTrans.LastView == this._edvUD20))
{
MessageBox.Show("in 1");
if ((this._edvUD20.Row >= 0))
{
MessageBox.Show("in 2");
DataRow drDeleted = ((DataRow)(this._ud20Adapter.UD20Data.UD20.Rows[this._edvUD20.Row]));
if ((drDeleted != null))
{
MessageBox.Show("in 3");
if (this._ud20Adapter.Delete(drDeleted))
{
MessageBox.Show("in 4");
if ((_edvUD20.Row > 0))
{
MessageBox.Show("in 5");
_edvUD20.Row = (_edvUD20.Row - 1);
}
// Notify that data was updated.
MessageBox.Show("before notify");
this._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD20.Row, this._edvUD20.Column));
MessageBox.Show("after notify");
}
}
}
}
}*/
}
private void UndoUD20Changes()
{
this._ud20Adapter.UD20Data.RejectChanges();
// Notify that data was updated.
this._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD20.Row, this._edvUD20.Column));
}
private void ClearUD20Data()
{
this._Key1UD20 = string.Empty;
this._Key2UD20 = string.Empty;
this._Key3UD20 = string.Empty;
this._Key4UD20 = string.Empty;
this._Key5UD20 = string.Empty;
this._ud20Adapter.UD20Data.Clear();
// Notify that data was updated.
this._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD20.Row, this._edvUD20.Column));
}
private void baseToolbarsManager_ToolClickForUD20(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "EpiAddNewNew Project Customer":
GetNewUD20Record();
break;
case "ClearTool":
ClearUD20Data();
break;
case "UndoTool":
UndoUD20Changes();
break;
}
}
private void ProjectEntryForm_BeforeToolClickForUD20(object sender, Ice.Lib.Framework.BeforeToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "SaveTool":
SaveUD20Record();
break;
case "DeleteTool":
DeleteUD20RecordBefore();
break;
}
}
private void ProjectEntryForm_AfterToolClickForUD20(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
// EpiMessageBox.Show(args.Tool.Key);
switch (args.Tool.Key)
{
case "DeleteTool":
if ((args.Cancelled == false))
{
DeleteUD20Record();
}
oTrans.Refresh();
break;
}
}
private void Project_AfterRowChangeForUD20(EpiRowChangedArgs args)
{
// ** add AfterRowChange event handler
string projectid = args.CurrentView.dataView[args.CurrentRow]["ProjectID"].ToString();
GetUD20Data(projectid, string.Empty, string.Empty, string.Empty, string.Empty);
}
private void Project_DataView_ListChangedForUD20(object sender, ListChangedEventArgs args)
{
// ** add ListChanged event handler
string projectid = Project_DataView[0]["ProjectID"].ToString();
GetUD20Data(projectid, string.Empty, string.Empty, string.Empty, string.Empty);
}
private void SetExtendedProperties()
{
// Begin Wizard Added EpiDataView Initialization
EpiDataView edvUD20View = ((EpiDataView)(this.oTrans.EpiDataViews["UD20View"]));
// End Wizard Added EpiDataView Initialization
// Begin Wizard Added Conditional Block
if (edvUD20View.dataView.Table.Columns.Contains("Character01"))
{
// Begin Wizard Added ExtendedProperty Settings: edvUD20View-ShortChar01
edvUD20View.dataView.Table.Columns["Character01"].ExtendedProperties["ReadOnly"] = true;
// End Wizard Added ExtendedProperty Settings: edvUD20View-ShortChar01
}
// End Wizard Added Conditional Block
}
private void UD20_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "Number01":
SearchOnCustomerAdapterNoShowDialog();
break;
}
}
private void SearchOnCustomerAdapterNoShowDialog()
{
// 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 recSelected;
string whereClause = string.Empty;
EpiDataView edvUD20View = ((EpiDataView)(this.oTrans.EpiDataViews["UD20View"]));
System.Data.DataRow edvUD20ViewRow = edvUD20View.CurrentDataRow;
if ((edvUD20ViewRow != null))
{
whereClause = "CustNum = " + Convert.ToInt32(edvUD20ViewRow["Number01"]);
System.Data.DataSet dsCustomerAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "CustomerAdapter", out recSelected, false, whereClause);
if (recSelected)
{
System.Data.DataRow adapterRow = dsCustomerAdapter.Tables[0].Rows[0];
// Map Search Fields to Application Fields
edvUD20ViewRow.BeginEdit();
edvUD20ViewRow["Character01"] = adapterRow["Name"];
edvUD20ViewRow.EndEdit();
}
}
}
private void DeleteUD20RecordBefore()
{
// Check to see if deleted view is ancestor view
bool isAncestorView = false;
Ice.Lib.Framework.EpiDataView parView = this._edvUD20.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)
{
if ((this.oTrans.LastView == this._edvUD20))
{
if ((this._edvUD20.Row >= 0))
{
DataRow drDeleted = ((DataRow)(this._ud20Adapter.UD20Data.UD20.Rows[this._edvUD20.Row]));
if ((drDeleted != null))
{
if (this._ud20Adapter.Delete(drDeleted))
{
if ((_edvUD20.Row > 0))
{
_edvUD20.Row = (_edvUD20.Row - 1);
}
// Notify that data was updated.
this._edvUD20.Notify(new EpiNotifyArgs(this.oTrans, this._edvUD20.Row, this._edvUD20.Column));
oTrans.Refresh();
}
}
}
}
}
}
}
Best regards
Adrian