Change EpiShape status based on approved revision

Try to exchange PartRev.Column with myFKVTable and do:

EpiDataView myFKV;  //in custom variables
DataTable myFKVTable;

//in init
myFKV = oTrans.Factory("Name of your FKV");
myFKVTable = myFKV.dataView.Table;

//now you should be able to substitute as mentioned above

This threw a lot of errors…

Error: CS1061 - line 50 (371) - 'Script' does not contain a definition for 'myFKVTable_Column' and no extension method 'myFKVTable_Column' accepting a first argument of type 'Script' could be found (are you missing a using directive or an assembly reference?)
Error: CS1061 - line 50 (371) - 'Script' does not contain a definition for 'PartRev_AfterFieldChange' and no extension method 'PartRev_AfterFieldChange' accepting a first argument of type 'Script' could be found (are you missing a using directive or an assembly reference?)
Error: CS1061 - line 63 (384) - 'Script' does not contain a definition for 'myFKVTable_Column' and no extension method 'myFKVTable_Column' accepting a first argument of type 'Script' could be found (are you missing a using directive or an assembly reference?)
Error: CS1061 - line 63 (384) - 'Script' does not contain a definition for 'PartRev_AfterFieldChange' and no extension method 'PartRev_AfterFieldChange' accepting a first argument of type 'Script' could be found (are you missing a using directive or an assembly reference?)

Code:

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

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	EpiDataView myFKV;
	DataTable myFKVTable;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization
		myFKV = oTrans.Factory("Part");
		myFKVTable = myFKV.dataView.Table;
		this.myFKVTable_Column.ColumnChanged += new DataColumnChangeEventHandler(this.PartRev_AfterFieldChange);
		// 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

		this.myFKVTable_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.PartRev_AfterFieldChange);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void myFKVTable_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 "Approved":
				MessageBox.Show("TEST");
				break;
		}
	}
}

try:

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

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
	EpiDataView myFKV;
	DataTable myFKVTable;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization
		myFKV = oTrans.Factory("Part");
		myFKVTable = myFKV.dataView.Table;
		this.myFKVTable.ColumnChanged += new DataColumnChangeEventHandler(this.myFKVTable_AfterFieldChange);
		// 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

		this.myFKVTable.ColumnChanged -= new DataColumnChangeEventHandler(this.myFKVTable_AfterFieldChange);
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
	}

	private void myFKVTable_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 "Approved":
				MessageBox.Show("TEST");
				break;
		}
	}
}

But isnt Part an existing system dataview?

To get to PartRev, I had to go to OrderDtl and create an FKV for Part, and then I created a STV on Part that linked to OrderDtl to get the revision number.

So you’ll want to use your STV name

I am still getting getting the “‘Script’ does not contain a definition for ‘mySTVTable_Column’…”

Thats because there is no mySTVTable_Column, its just mySTVTable

U know maybe I’ve taken you too far down the rabbit hole. How about you just place a change event on the row of the order detail (which would change the PN and ultimately drive the STV change) - inside of it, we’d just look up your value:

EpiDataView mySTV;
mySTV = oTrans.Factory("STV NAME");
bool myVal = (bool)mySTV.dataView[mySTV.Row]["Approved"];

The code compiles…but nothing happens when I change the revision in the dropdown.

private void OrderDtl_AfterRowChange(EpiRowChangedArgs args)
{
	// ** Argument Properties and Uses **
	// args.CurrentView.dataView[args.CurrentRow]["FieldName"]
	// args.LastRow, args.CurrentRow, args.CurrentView
	// Add Event Handler Code
	EpiDataView mySTV;
	mySTV = oTrans.Factory("PartRev");
	bool myVal = (bool)mySTV.dataView[mySTV.Row]["Approved"];
	if (myVal == true)
	{
		MessageBox.Show("APPROVED");
	}
	else
	{
		MessageBox.Show("NOT APPROVED");
	}
}

Lol - I’ll get you there eventually. Do the same thing in an AfterField change on the OrderDtl.RevisionNum field By golly if that dont work we’ll hook directly to the damn control :smiley:

Something happens now! Strangely, the message box shows the opposite of what it should say. I’ve now changed it over to an EpiShape. If I select an unapproved revision, the color changes to yellow, but when I select an approved revision, it stays yellow. Then when I select an unapproved revision, it changes to green. It seems like it’s changing to the color that corresponds to the previous selection. I’ll try switching up the if statement.

Also, the title in EpiShape is not changing accordingly…

As for the second part of my comment…I thought the properties of the EpiShape determe the caption (enabled vs disabled)…that’s not what I was looking for. There must be a property of EpiShape that changes that.

Okay…I’m not sure what’s going on now. Even when I swapped the if statement, some unapproved revisions are showing up green.

I had my own learning curve with EpiShape:

I actually found that thread before, that’s how I learned about the Status.

It looks like the color is reflecting the approval status of the previously selected revision.

i was afraid of that. That’s firing before the subtable is being updated.

We need to get that event firing on the STV itself

When I change it to PartRev, I get the errors described previously.

Sticking with OrderDtl for the trigger, could there be a way to force updating the subtable view before running the if statement?

I ended up going back to the checkbox bound to STV_PartRev.Approved, then created an event for when the custom checkbox gets checked or unchecked. I then put an if statement in the event handler that changes the color and caption for the epiShape.

private void epiCheckBoxC1_CheckedChanged(object sender, System.EventArgs args)
{
	// ** Place Event Handling Code Here **
	bool myVal = epiCheckBoxC1.Checked;
	if (myVal == true)
	{
		epiShapeC1.Status = StatusTypes.OK;
		epiShapeC1.EnabledCaption = "Approved";
	}
	else
	{
		epiShapeC1.Status = StatusTypes.Warning;
		epiShapeC1.EnabledCaption = "Not Approved";
	}	
}
1 Like