Part Validation in a Custom module

I have a Custom Inventory module (utilizing the UD102 & UD102A tables).
My part validation works great, however, after the Inventory group is posted I do not want any changes allowed to the Part Number, Quantity Counted, or the Void Tag checkbox.
Currently using a Switch / Case statement which works for ShortChar01(Part Number). It will not allow a change to be made to the part number after it is posted. When I add Case 2: Count Quantity(Number02) and Case 3: VoidTag(CheckBox02) it won’t allow a part number to be entered even if the Inventory Group is not posted.
This is the code:

private void UD102A_BeforeFieldChange(object sender, DataColumnChangeEventArgs args)
	{
		switch (args.Column.ColumnName)
		{
			case "ShortChar01":
			//case "Number02":
			//case "CheckBox02":
			if ((bool)isPosted (edvUD102.dataView[edvUD102.Row]["Key1"].ToString())== false)
			{
			//MessageBox.Show(args.ProposedValue.ToString());
				getPartInformation(args.ProposedValue.ToString(),false); 
			}
			else
			{
			MessageBox.Show("Inventory group is posted");
			oTrans.Refresh();
			}		
			break;
		}

	}

Any suggestions would be appreciated.
Thanks,
Carol

Try the following:

switch (args.Column.ColumName)
{
case "ShortChar01":
    goto case "Checkbox02";
case "Number02":
    goto case "Checkbox02";
case "Checkbox02":
    If ...{
        }
    break;
}

Edit

See: if and switch statements - select a code path to execute | Microsoft Learn

Particularly:

Upon further reading of that MS article I posted, it looks like your original code should work as you have only one case ever executing, and it has a break; at the end. Maybe you just need to add

default:
    break;

At the end of the switch() block

I tried what you suggested and it disallows changing the part number and the quantity, however it allowed me to check the “void tag” checkbox.

case “ShortChar01”:

goto case “Number02”;

case “Number02”:

gotocase “Checkbox02”;

case “Checkbox02”:

Then I went in and created a new group, but it does not recognize any Part number.

image001.png

Is Checkbox02 the field your using for “void tag” ?

What do you mean by “Inventory group is posted” ? Cycle counting? Phys Inventory? Or something else?

In case it is something weird with the switch…case, see if the following works:

private void UD102A_BeforeFieldChange(object sender, DataColumnChangeEventArgs args)
    {
    if((args.Column.ColumnName == "ShortChar01") 
      || (args.Column.ColumnName == "Number02")
      || (args.Column.ColumnName == "CheckBox02") ) 
        {
        if ((bool)isPosted (edvUD102.dataView[edvUD102.Row]["Key1"].ToString())== false)
            {
            //MessageBox.Show(args.ProposedValue.ToString());
            getPartInformation(args.ProposedValue.ToString(),false);
            }
        else
            {
            MessageBox.Show("Inventory group is posted");
            oTrans.Refresh();
            }
        }
    }

And are you sure the it’s CheckBox02 and not Checkbox02 ??

Yes, CheckBox02 is the field I am using for “void tag”.

This resulted in an error with the getPartInformation method.

The suggestion you had prior using the goto case…. Would the default: break; be after the closing curly for the switch or before ?

So UD102.CheckBox02 is set by whatever that posting process you mentioned. And you want to prevent changes to fields ShortChar01, Number02, and CheckBox02, of records that have CheckbBox02 set. That correct?

Would this be simpler with an extended properties wizard? Or even an In-Tran DD on UD102 that stops updates of records where CheckBox02 is already set.

The default: would be just like one of the case statements, so at the same level.

switch(i){
  case 0:
    /* do something if i == 0*/
    break;
  case 1:
    /* do something if i == 1*/
    break;
  default:
    /* stuf to do if none of the cases matched*/
    break;
  }

Actually, CheckBox01 is set to true when the Update Counts process is ran (which updates our inventory on hand).

But once the process is ran and the group is “posted” , I do not want users to be able to go back in and change a part number, or change a quantity, or check the void tag checkbox.

What indicates if a posting occurred?

edit

I think I see now.

“Posted” means the record has been written to UD102. Correct? What is creating the “Group”?

Is UD102 holding the “Group” info and UD102A holding the line item records of that group?

Yes,
A new group (UD102Key1) is created by the User. There is a method to generate the desired tag number range ChildKey1. This allows us to create our own tag numbers which is necessary for our inventory process.
After all tags are entered and variances are reviewed and any/all corrections are made the Update Counts method updates our on hand for the warehouse selected.
Once this process runs the Inventory Group cannot be modified or deleted. The last piece is to disallow any change to the Part number, quantity or to check/uncheck a tag that was marked “void”.

I’d put a DD on UD102A to prevent updates to those fields when UD102.CheckBoxXX is set (your flag that a group was posted).

In the form that you enter the UD102 and UD102A info, use the wizard for Extend Properties, to make those fields read only, when the posted field is set. Not really necessary, as the DD would prevent changes - but it looks better when you disable those fields, so that people know that they’ve been posted.

Thank Calvin,

I will give that a try. I appreciate the help!:slight_smile:

Hi Calvin,

I’m not totally familiar with Data directives. Would I use In-Transaction?

And something like the following;

The ttUD102.RowMod field of the changed row is equal to the “U” expression

And

Number of rows in the inventoryUpdated query is more or equal to 1

(the query would be the ttUD102 table and UD102A table (where the CheckBox01 = true) for both the Parent & Child Tables)?

Then use a Set Field (but not sure what to do with this).

Thank you

Carol

I’d put an In-Tran DD on UD102, like:

image

That will prevent somone from unchecking CheckBox01 of the parent table. This is so that once it’s posted it can’t be changed back to unposted.

Then put a In-Tran on UD102A, like:

With the Conditions Query:

and the table criteria

image

With these two DD’s enabled:

  • You can not un-check the CheckBox01 on the parent (my “posted” flag)
  • You cannot save a child record if its parten has CheckBox01 checked, and either the Number01 or ShortChar01 are changed)

The UI will let you change thes, but saves won’t happen. Down side is the UI retains the changes made to the protected field. Hitting Refresh will show that actual value in the DB.
This is why the second part would be to customize the form to disable those fields when the parten’s posted field is set.

Thank you so much for the help!

I was wrong abput what to do in the customization. Don’t use the Extend Props wizard. But instead use the Rule Wizard:

The first Row Rule disables the Parents checkbox when it is set.

In a nutshell:
IF Parent.Checkbox01 == true then Parent.Checkbox01 is disabled.

The second rule also checks the value of the parent’s checkbox, but applies actions to the child:

In a nutshell:

IF Parent.Checkbox01 == true then 
  Child.Number01 is disabled.
  Child.Character01 is readonly
END IF

I made one disabled and one read only, to see the difference. It’s barely noticable with my theme.
image

The row rule wizard worked wonderfully!!

Thank you so much.

Carol

Have a great weekend!!