Ok good. Is the user entering in the part num into this field? If so, just take the value of the PartNumBox field.
Keep in mind there are many many ways to skin this cat.
Yes. The user is typing in the part number, and I want to validate that itās a good part number before they move on.
If youāve got a better way to skin this cat, Iām all ears. Iām just trying to apply what little I know. Please correct me if I so something dumb.
I think what youāre doing is fine for this purpose.
so what do I have to do to get it to grab the value in the box the first time? Do I have the right event?
Hmm. Grabbing the value from a control can sometimes be messy. If you want, you could try handling this off of the dataview instead. You could potentially hang this code off of a āBeforeFieldChangeā event and would have access to the āproposed valueā, which you could test on. It would also allow a rollback
ok, we can try that. If I use the wizard to add that, I get this code from the wizard. Now I donāt need the value from the text box because I am using UDCharacter01 right? How do I plug in the GetById to the switch case?
private void UD10_BeforeFieldChange(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 "Character01":
break;
}
}
Well, you could plug it in very much like youāre doing on the Leave event.
private void UD10_BeforeFieldChange(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 āCharacter01ā:
PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
if(adapterPart.GetByID(args.ProposedValue))
{
MessageBox.Show(āit workedā);
}
adapterPart.Dispose();
break;
}
}
Thanks, It was the args.ProposedValue part that I didnāt know.
Unfortunately, itās doing the works no matter what thing again.
private void UD10_BeforeFieldChange(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 "Character01":
PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
if(adapterPart.GetByID(args.ProposedValue))
{
MessageBox.Show("it worked");
}
adapterPart.Dispose();
break;
}
}
If i were you, Iād play around with the data going into the column. Maybe first try doing some tests by showing the proposed value and how it interacts with the leave event? Rather than focus on the adapter for nowā¦
This event seems to be working much better than the leave event. It only fires when there is a change, which is much better. I added the args.ProposedValue into the āit workedā message box, and the value coming through is matching what is in the text box. So that seems to be working great.
Edit, it need .ToString(). Now it works as expected.
private void UD10_BeforeFieldChange(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 "Character01":
PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
if(adapterPart.GetByID(args.ProposedValue.ToString()))
{
MessageBox.Show("it worked " + args.ProposedValue);
}
adapterPart.Dispose();
break;
}
}
So I switched this over to a try statement, because I want to be able to display a message that says something intelligible. It doesnāt revert, but for this case, Iām not worried about that. I will have BPMās in place to catch the actual save event. (or I can try to throw an exception in this code too)
So I need to learn how to get something from that lookup other than just a validation. For this use case, I want to pull the part description and load it into a call context field so that I can display it in a text box. I would put that into the successful try block. Do I need a call to create a dataset here? Or does the GetByID do that already? I didnāt see any data set values in the trace so Iām assuming that it doesnāt. But I also donāt see that in the trace for part entry either. Iām trying to find examples, but havenāt found one close enough for me to understand.
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "Character01":
PartAdapter adapterPart = new PartAdapter(oTrans);
adapterPart.BOConnect();
try//(adapterPart.GetByID(args.ProposedValue.ToString()))
{
adapterPart.GetByID(args.ProposedValue.ToString());
MessageBox.Show("it worked " + args.ProposedValue);
}
catch
{
MessageBox.Show(args.ProposedValue +" is not a valid part number");
}
adapterPart.Dispose();
break;
}
}
GetByID will return the dataset which is part of the adapter data.
To access the data, you would reference it like so:
adapterPart.PartData.Part[0].YourColumnHere
Just for reference, when using the UD screen, you have to add Erp.Contracts.BO.Part as a custom reference to make that line work.
First order of learning. How do I look up what I can use with an adapter? Is that somewhere in the object explorer? I am trying to understand how to use adapters in general so the next time I want to use an adapter, I can figure out what I can do without help. I donāt want to have other people write my code for me forever.
ok, so now I have that value, and I can put it into a message box. How so I get that value to show up on the text box?
Iām trying a bunch of stuff, but am not sure where I should be going. I have the text box bound to a BPM call context field. Should I simply have an unbound field and set it it code using the part adapter?
I wish learning this stuff wasnāt like pulling teeth.
I figured it out
I set up the text box in the variables then I can use use this code (I found the example in the object explorer) and it now sets the value.
{
adapterPart.GetByID(args.ProposedValue.ToString());
DescBox.Value = adapterPart.PartData.Part[0].PartDescription.ToString();
}
The object explorer is your friend here
Yeah, Iām trying to figure out how to use it. Starting to get better and knowing what Iām looking at. I was able to throw the lookup into an epiview notification and it works much better.
So I have the field validation working for the part number.
Next I need to get the field validation working for the bin number as well, but I am missing something.
I can get a second case to pop off, but itās calling it successful when it shouldnāt be.
Iām trying to find in the object explorer how to use GetByID for the WhseBinAdapter but I can find it. Can someone show me (with screen shots preferably) where in the object explorer I can find how I can do a lookup with the WhseBinAdapter?
Hereās what I am trying to do, but the try is coming back successful when it shouldnāt.
switch(args.Column.ColumnName)
{
case "Character02":
WhseBinAdapter adapterBin = new WhseBinAdapter(oTrans);
adapterBin.BOConnect();
try
{
adapterBin.GetByID(args.ProposedValue.ToString());
MessageBox.Show("bin lookup good");
}
catch
{
MessageBox.Show(args.ProposedValue +" is not a valid Bin number");
}
adapterBin.Dispose();
break;
}
I even try removing the ToString() part, and then it comes up bad no matter what.
Itās always going to show you message in the try because itās simply falling through the code. If you make the message box contintigent on the return value of the GetByID, it should work the way you want.
Remember, GetByID returns a boolean, so if you do
bool recSelected = adapterBin.GetByID(args.ProposedValue.ToString());
if(recSelected)//meaning we found a bin
{
MessageBox.Show(ābin lookup goodā);
}
So I I had to add the warehouse in the lookup, now itās working, but only for the warehouse that Iāve coded.
Is there really no way to look this stuff up?
switch(args.Column.ColumnName)
{
case "Character02":
WhseBinAdapter adapterBin = new WhseBinAdapter(oTrans);
adapterBin.BOConnect();
try
{
adapterBin.GetByID("GEN",args.ProposedValue.ToString());
MessageBox.Show(args.ProposedValue +" this is a good check");
}
catch
{
MessageBox.Show(args.ProposedValue +" is not a valid Bin number");
}
adapterBin.Dispose();
break;
}