Lock a sales order line  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Lock a sales order line

Postby DannyC » Sat Aug 14, 2021 6:00 pm

I want to lock a sales order line from any editing.

I've tried the following but it doesn't work. Obviously removing the comments ;)
Code: Select all
foreach (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine line in salesOrderForm.SalesOrder.SalesOrderLines)
{
   if (!line.CommentLine && line.QuantityDemand > 0)
   {
      //salesOrderForm.grdLines.LockRow(line.ItemNo, true);               doesn't work
      //salesOrderForm.grdLines.ActiveSheet.ActiveRow.Locked = true;      doesn't work either      
   }
}


Any other tip?
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Lock a sales order line

Postby SBarnes » Sun Aug 15, 2021 11:07 am

That is because LockRow takes a first parameter of the row in the grid not the line item number, if you loop over the actual grid and then get the line by record id and get the value from the Key column and then check your conditions it will work below is how to get the key value.

What I am saying is the link between the lines and the grid is line's ID in the collection and the first hidden column in the grid where Jiwa puts the ID when it displays the lines. Jiwa does this for nearly all grids, you just have to work out what that first column is which you can usually find by looking at the setup function in the form.

Code: Select all
string LineID = salesOrderForm.grdLines.get_GridText("Key",row).ToString();


to get the line use


Code: Select all
SalesOrderLine line = salesOrderForm.SalesOrder.SalesOrderLines[LineID];
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Lock a sales order line

Postby DannyC » Mon Aug 16, 2021 9:58 am

So what's the difference between your line
Code: Select all
SalesOrderLine line = salesOrderForm.SalesOrder.SalesOrderLines[LineID];


and my line?
Code: Select all
foreach (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine line in salesOrderForm.SalesOrder.SalesOrderLines)


It's the same line isn't it?
The first parameter of salesOrderForm.grdLines.LockRow takes an integer.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Lock a sales order line

Postby SBarnes » Mon Aug 16, 2021 10:21 am

There is no difference but if you use your for each loop you are then going to need a loop to roll over the grid inside it, basically you will end up with one loop if you look up the id of the line from the key column, below is the code for LockRow, the first value must be valid as the row you want to lock all it then does is go over the columns and locks the cells. The sales order line number also has nothing to do with the row number in the grid.


Code: Select all
        public void LockRow(int Row, bool LockValue)
        {
            IEnumerator enumerator = null;
            try
            {
                enumerator = ((IEnumerable)base.ActiveSheet.Columns).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Column current = (Column)enumerator.Current;
                    base.ActiveSheet.Cells[Row, current.Index].Locked = LockValue;
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Lock a sales order line

Postby DannyC » Mon Aug 16, 2021 11:50 am

The sales order line number also has nothing to do with the row number in the grid.

OK. But then by that reasoning this should work. It doesn't.
Code: Select all
for(int row = 0; row <= salesOrderForm.grdLines.ActiveSheet.RowCount - 1; row++)
{
   salesOrderForm.grdLines.LockRow(row, true); 
}
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Lock a sales order line

Postby Mike.Sheen » Mon Aug 16, 2021 11:50 am

Another important aspect is to where you are performing this locking of cells / rows.

We performing locking / unlocking of cells as part of the DisplayLine in the form - which is called in reaction to all sorts of events... and then permissions set might also lock grid columns.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Lock a sales order line

Postby DannyC » Mon Aug 16, 2021 12:04 pm

We performing locking / unlocking of cells as part of the DisplayLine in the form

Ahhh! That might be the hint I'm looking for! Cheers Mike.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Lock a sales order line

Postby SBarnes » Mon Aug 16, 2021 12:08 pm

Of course the other way of doing things would be to not lock the line but add a change event handler for the grid in the set up before handlers and simply tell the user they can't change the line and then simply client cancel exception and then Jiwa will never know the user did anything.

Not quite as elegant as locking the row but it would achieve what you need fairly simply.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Lock a sales order line

Postby SBarnes » Mon Aug 16, 2021 12:20 pm

I just remembered I had to do a slight of hand to let certain columns be editable on a snapshot greater than 1 adding a change event to grid behind Jiwa worked.

I can't see why doing the same to lock columns wouldn't work as easily as unlocking them
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Lock a sales order line

Postby DannyC » Mon Aug 16, 2021 1:05 pm

I think I have it sussed.....basically I reckon I've possibly determined that LockRow doesn't work. Might need more testing to check.

I need to use LockColumn and just specify each column, kinda like the plugin Sales Orders - Round Cash Sales to Nearest 5c.
In that plugin is
Code: Select all
   public void SalesOrderForm_LineDisplayed(object sender, System.EventArgs e, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine SalesOrderLine, int Row)
   {
      JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm salesOrderForm = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)sender;
      if (SalesOrderLine.PartNo == "ZRounding" && SalesOrderLine.NonStock)
      {
         for(int row = 0; row <= salesOrderForm.grdLines.ActiveSheet.RowCount - 1; row++)
         {
            if (salesOrderForm.grdLines.get_GridText("Key", row).ToString() == SalesOrderLine.RecID)
            {
               salesOrderForm.grdLines.LockColumn(true, "UnitOfMeasure", row);
               salesOrderForm.grdLines.LockColumn(true, "QuantityUnitOfMeasure", row);
               salesOrderForm.grdLines.LockColumn(true, "QuantityOrdered", row);
               salesOrderForm.grdLines.LockColumn(true, "QuantityBackOrdered", row);
               salesOrderForm.grdLines.LockColumn(true, "QuantityDemand", row);
               salesOrderForm.grdLines.LockColumn(true, "QuantityThisDelivery", row);
               salesOrderForm.grdLines.LockColumn(true, "SellPrice", row);
               salesOrderForm.grdLines.LockColumn(true, "PriceIncGST", row);
               salesOrderForm.grdLines.LockColumn(true, "ExtPrice", row);
               break;
            }
         }
      }
   }


so I just used that same concept & it seems to be doing what I was hoping.

EDIT: So I've done more testing. LockRow does work after all!
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Next

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 2 guests