Adding column to Time Phase

I tried searching first but did not see anyone using the same method as I am for adding a new column, and don’t quite want to start over yet.

Below the code should be working to add a new column to the grid, but it is not showing up when the form launches. I am reusing code from somewhere else that it is working on, but I cannot seem to figure out why the column is not being added.

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **
	Ice.Lib.Framework.EpiUltraGrid timePhaseGrid;
	private JobEntryAdapter _JobEntryAdapter;
	private SalesOrderAdapter _SOAdapter;
	private EpiDataView edvMisc;
	// 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

		this.edvMisc = ((EpiDataView)(this.oTrans.EpiDataViews["Misc"]));
		this.edvMisc.EpiViewNotification += new EpiViewNotification(this.edvMisc_EpiViewNotification);
		// End Wizard Added Variable Initialization
		timePhaseGrid = (Ice.Lib.Framework.EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
		timePhaseGrid.DisplayLayout.Bands[0].Columns.Add("PType","Project Type");
		// Begin Wizard Added Custom Method Calls
		timePhaseGrid.InitializeRow += new InitializeRowEventHandler(timePhaseGrid_InitializeRow);
		// End Wizard Added Custom Method Calls
	}

@livingstonmarc TimePhase is a unique program, so did not try to add a column I just borrowed a somewhat ignored one to hold my data. I filled SourceFile on post processing of GoTimePhas with the data I needed, relabeled the header and called it a day.

1 Like

I’m with Greg - I usually just grab an unused column and borrow that, overwriting on a post-processing BPM.

Another trick if you have multiple fields you want. Take a field like the transaction reference, and on the post-processing BPM append your other fields to it with a tilde separator. So, transaction reference might be:
TRANSREF~PONUM~UDFIELD1~UDFIELD2~AndSoOn

Then, when you get the data back in the UI, parse those fields out and add to the new fields you added in the UI (similar to what you did above).

Hope that gets you pointed in the right direction.

1 Like

I managed to do this with a customization and by calling a BAQ that gets the data and populates 2 new columns. But it is waaay too slow and I’m seriously thinking of removing it completely. I mean it gets from around 3-4 secs without the columns to 20+ seconds with them. Sometimes even more.

My issue right now is not that the columns won’t populate, it is that the columns are completely missing from the grid.

I didnt spend too much time on it… Here is quick way

PS: Code does not follow best practices such as row rules what not… just quick dirty.

// **************************************************
// Custom code for TimePhasForm
// Created: 12/4/2017 9:09:10 AM
//

extern alias Erp_Contracts_BO_PartPlantSearch;
extern alias Erp_Contracts_BO_Part;
extern alias Ice_Adapters_DynamicReport;

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;
using System.Drawing;


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 edvTimePhas;
	private EpiDataView edvPartPlant;
	private EpiDataView edvPart;
	private EpiDataView edvMisc;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	DataTable allOrders;
	DataTable allJobs;
	DataTable allPOs;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		this.edvTimePhas = ((EpiDataView)(this.oTrans.EpiDataViews["TimePhas"]));
		this.edvTimePhas.EpiViewNotification += new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
		this.edvPartPlant = ((EpiDataView)(this.oTrans.EpiDataViews["PartPlant"]));
		this.edvPartPlant.EpiViewNotification += new EpiViewNotification(this.edvPartPlant_EpiViewNotification);
		this.edvPart = ((EpiDataView)(this.oTrans.EpiDataViews["Part"]));
		this.edvPart.EpiViewNotification += new EpiViewNotification(this.edvPart_EpiViewNotification);
		this.edvMisc = ((EpiDataView)(this.oTrans.EpiDataViews["Misc"]));
		this.edvMisc.EpiViewNotification += new EpiViewNotification(this.edvMisc_EpiViewNotification);
		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls
		InitializeBAQData();

		// 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.edvTimePhas.EpiViewNotification -= new EpiViewNotification(this.edvTimePhas_EpiViewNotification);
		this.edvTimePhas = null;
		this.edvPartPlant.EpiViewNotification -= new EpiViewNotification(this.edvPartPlant_EpiViewNotification);
		this.edvPartPlant = null;
		this.edvPart.EpiViewNotification -= new EpiViewNotification(this.edvPart_EpiViewNotification);
		this.edvPart = null;
		this.edvMisc.EpiViewNotification -= new EpiViewNotification(this.edvMisc_EpiViewNotification);
		this.edvMisc = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void TimePhasForm_Load(object sender, EventArgs args)
	{
		// Add Event Handler Code
		TimePhasForm.Text = TimePhasForm.Text + " 21.11.10";

		EpiCheckBox chkSugs = (EpiCheckBox)csm.GetNativeControlReference("cdf4e0c8-4643-4c8b-9aaf-a53c47ce9985");
		EpiCheckBox chkTrns = (EpiCheckBox)csm.GetNativeControlReference("7ceb719a-f574-4989-bf03-18263d5719f4");
		EpiCheckBox chkPlan = (EpiCheckBox)csm.GetNativeControlReference("7f8e2894-a0c1-4ce6-a392-7bd7fc1faba0");

		chkSugs.Checked = false;
		chkTrns.Checked = false;
		chkPlan.Checked = false;

		// Allows it to work with Open With...
		if (oTrans.CurrentPart != string.Empty) {
			oTrans.Refresh();
		}
	}

	// Will load data and store it in memory
	private void InitializeBAQData()
	{
		using (DynamicQueryAdapter adDynamic = new DynamicQueryAdapter(this.oTrans))
		{
			adDynamic.BOConnect();

			Ice.BO.QueryExecutionDataSet parameters = new Ice.BO.QueryExecutionDataSet();
			adDynamic.ExecuteByID("CODE-TPI-AllOrders", parameters);
			allOrders = adDynamic.QueryResults.Tables[0].Copy();

			adDynamic.ExecuteByID("CODE-TPI-AllJobs", parameters);
			allJobs = adDynamic.QueryResults.Tables[0].Copy();

			adDynamic.ExecuteByID("CODE-TPI-AllPOs", parameters);
			allPOs = adDynamic.QueryResults.Tables[0].Copy();
		}
	}

	private void UpdateFields()
	{
		if (edvTimePhas.dataView.Table.Rows.Count <= 0)
		{
			return;
		}

		// Only Add Columns back if they dont exist
		if (!edvTimePhas.dataView.Table.Columns.Contains("ProjectID"))
		{
			DataColumn dcProject = new DataColumn("ProjectID");
			edvTimePhas.dataView.Table.Columns.Add(dcProject);
			DataColumn dcBlanket = new DataColumn("Blanket Order");
			edvTimePhas.dataView.Table.Columns.Add(dcBlanket);
			EpiUltraGrid grdTimePhas = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
			for (int i = 0; i < grdTimePhas.DisplayLayout.Bands[0].Columns.Count; i++) grdTimePhas.DisplayLayout.Bands[0].Columns[i].CellActivation = Activation.NoEdit;
			grdTimePhas.DisplayLayout.Bands[0].Columns["Blanket Order"].Hidden = true;
			grdTimePhas.DisplayLayout.Bands[0].Columns["ProjectID"].Header.VisiblePosition = 8;
		}

		using (DynamicQueryAdapter adDynamic = new DynamicQueryAdapter(TimePhasForm))
		{
			adDynamic.BOConnect();

			foreach (DataRow tp in edvTimePhas.dataView.Table.Rows)
			{
				if (tp["ProjectID"].ToString() != string.Empty)
				{
					continue;
				}

				if (tp["PONum"].ToString() != string.Empty && tp["PONum"].ToString() != "0")
				{
					string where = string.Format("PORel_PONum = {0} AND PORel_POLine = {1} AND PORel_PORelNum = {2}", tp["PONum"].ToString(), tp["POLine"].ToString(), tp["PORelNum"].ToString());
					DataRow[] rows = allPOs.Select(where, "PORel_PONum ASC");

					if (rows != null)
					{
						tp["ProjectID"] = rows[0]["PORel_ProjectID"];
					}
				}
				else if (tp["JobNum"].ToString() != string.Empty)
				{
					string where = string.Format("JobHead_JobNum = '{0}'", tp["JobNum"].ToString());
					DataRow[] rows = allJobs.Select(where, "JobHead_JobNum ASC");

					if (rows != null)
					{
						tp["ProjectID"] = rows[0]["JobHead_ProjectID"];
					}
				}
				else if (tp["OrderNum"].ToString() != string.Empty && tp["OrderNum"].ToString() != "0")
				{
					string where = string.Format("OrderDtl_OrderNum = {0} AND OrderDtl_OrderLine = {1}", tp["OrderNum"].ToString(), tp["OrderLine"].ToString());
					DataRow[] rows = allOrders.Select(where, "OrderDtl_OrderNum ASC");

					if (rows != null)
					{
						tp["ProjectID"] = rows[0]["OrderDtl_ProjectID"];
						tp["Blanket Order"] = rows[0]["OrderHed_CheckBox03"];
					}
				}
			}
		}

		EpiUltraGrid grdTimePhas2 = (EpiUltraGrid)csm.GetNativeControlReference("7908565c-cc3c-43d1-b85b-9921ad88fb89");
		foreach (Infragistics.Win.UltraWinGrid.UltraGridRow line in grdTimePhas2.Rows)
		{
			if (line.Cells["Blanket Order"].Value != DBNull.Value && Convert.ToBoolean(line.Cells["Blanket Order"].Value))
			{
				line.Appearance.BackColor = Color.Yellow;
				line.Appearance.BackColorDisabled = Color.Yellow;
				line.CellAppearance.BackColor = Color.Yellow;
				line.CellAppearance.BackColorDisabled = Color.Yellow;
			}
		}
	}

	private void edvPartPlant_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 && args.Row > -1 && args.BruteForce == false)
		{
			UpdateFields();
		}
	}

	private void edvPart_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.Row > -1))
		{
			// UpdateFields();
		}
	}

	private void edvTimePhas_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 && args.Row > -1 && args.ReEvaluateRowRules == true)
		{
			UpdateFields();
		}
	}

	private void edvMisc_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 && args.Row > -1 && args.BruteForce == false)
		{
			if (args.Sender is EpiCheckBox && oTrans.CurrentPart != string.Empty)
			{
				UpdateFields();
			}
		}
	}
}
3 Likes