Add new column to JiwaGrid and assign a value  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Add new column to JiwaGrid and assign a value

Postby DannyC » Tue Apr 26, 2022 3:21 pm

Hi,

I am wanting to add a SOH column to Bill Maintenance inputs grid.
I can easily add a column but can't work out how I can get the SOH value for each input row. I'm guessing it's fairly easy but for some reason I'm getting a brainblock.

This is what I have so far
Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaForm is JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.BillMaintenance.BillMaintenance)
   {
      JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.BillMaintenance.BillMaintenance BillMaintForm = (JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.BillMaintenance.BillMaintenance)JiwaForm;
      BillMaintForm.InputsJiwaGrid.AddColumn("SOH", new FarPoint.Win.Spread.CellType.NumberCellType(), "SOH", 5, false, true, true, true, 255, false, false, 0, false);
      BillMaintForm.InputsJiwaGrid["SOH", -1] = ????;
   }
}


First problem is that I'm getting an error "Cannot apply indexing with [] to an expression of type JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid. This happens if I just force a static SOH like
Code: Select all
BillMaintForm.InputsJiwaGrid["SOH", -1] = 10;


Second issue is getting the actual SOH value. I'm suspecting I need to loop through the rows in the InputsJiwaGrid, get the InventoryID, the INLogicalID and just do a SQL SELECT to find the SOH. What would be the syntax to loop through the rows? I'm fine to create a decimal function which returns the SOH, it's just the looping I'm having trouble with. Or is that even the best way to get SOH for each input row?
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Add new column to JiwaGrid and assign a value  Topic is solved

Postby SBarnes » Tue Apr 26, 2022 5:18 pm

First thing is you don't set the grid in c# using the indexing you do the following:

Code: Select all
 grid.set_GridText("Address1", num, item.Address1);


and you are kind of right in your answer to the second part yes you need to loop over the grid and fill in your extra column but as the code below shows how the grid gets filled in namely by DisplayInputs which in turn calls DisplayInput you need to work out every where these are called from and follow it with you fill in code, the reason being is that DisplayInputs zeros the rows of the grid that will wipe out any previous values you have put in your column.

What you want to do looks possible though you just have to look at where inputs can be changed, added or removed and the stage changes by the looks of it.


Code: Select all
 public void DisplayInput(InputItem Input, int Row = -1)
        {
            IEnumerator enumerator = null;
            if (Row == -1)
            {
                int rowCount = checked(this.InputsJiwaGrid.ActiveSheet.RowCount - 1);
                int num = 0;
                while (num <= rowCount)
                {
                    if (!Operators.ConditionalCompareObjectEqual(this.InputsJiwaGrid["RecID", num], Input.RecID, false))
                    {
                        num = checked(num + 1);
                    }
                    else
                    {
                        Row = num;
                        break;
                    }
                }
            }
            if (Row != -1)
            {
                try
                {
                    enumerator = ((IEnumerable)this.InputsJiwaGrid.ActiveSheet.Columns).GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Column current = (Column)enumerator.Current;
                        this.InputsJiwaGrid.ActiveSheet.Cells[Row, current.Index].Tag = RuntimeHelpers.GetObjectValue(this.InputsJiwaGrid.ActiveSheet.ColumnHeader.Cells[1, current.Index].Tag);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                this.InputsJiwaGrid["RecID", Row] = Input.RecID;
                this.InputsJiwaGrid["PartNo", Row] = Input.Inventory.PartNo;
                this.InputsJiwaGrid.SetDrillDown("PartNo", Row, "JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm", Input.Inventory.InventoryID);
                this.InputsJiwaGrid["Description", Row] = Input.Inventory.Description;
                this.InputsJiwaGrid.SetDrillDown("Description", Row, "JiwaFinancials.Jiwa.JiwaInventoryUI.InventoryMaintenanceForm", Input.Inventory.InventoryID);
                this.InputsJiwaGrid["QuantityType", Row] = (int)(-Input.IsRatio);
                this.InputsJiwaGrid["Quantity", Row] = Input.Quantity;
                this.InputsJiwaGrid.GridDecimalPlaces("Quantity", Row, Input.Inventory.DecimalPlaces, -2);
                if (!Input.IsBoMItem || Input.SubAssemblyExplodePolicy == InputItem.SubAssemblyExplodePolicyOptions.NeverExplode || Input.SubAssembly != null && Input.SubAssembly.RecID != null && Input.SubAssembly.RecID.Trim().Length != 0)
                {
                    this.InputsJiwaGrid.ActiveSheet.Cells[Row, this.InputsJiwaGrid.ActiveSheet.GetColumnFromTag(null, "SubAssembly").Index].ErrorText = "";
                }
                else
                {
                    this.InputsJiwaGrid.ActiveSheet.Cells[Row, this.InputsJiwaGrid.ActiveSheet.GetColumnFromTag(null, "SubAssembly").Index].ErrorText = "You must select a sub assembly if the explode policy is Always or When Shortfalls";
                }
                if (Input.SubAssembly != null && Input.SubAssembly.BillNo != null && Input.SubAssembly.BillNo.Trim().Length > 0)
                {
                    this.InputsJiwaGrid["SubAssembly", Row] = string.Concat((Input.SubAssembly.BillNo != null ? Input.SubAssembly.BillNo : ""), (Input.SubAssembly.Description == null || Input.SubAssembly.Description.Trim().Length <= 0 ? "" : string.Concat(" (", Input.SubAssembly.Description, ")")));
                    this.InputsJiwaGrid.SetDrillDown("SubAssembly", Row, "JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.BillMaintenance.BillMaintenance", Input.SubAssembly.RecID);
                }
                else if (Input.CircularReferenceException == null)
                {
                    this.InputsJiwaGrid["SubAssembly", Row] = "";
                }
                else
                {
                    this.InputsJiwaGrid["SubAssembly", Row] = Input.CircularReferenceException.Message;
                    this.InputsJiwaGrid.ActiveSheet.Cells[Row, this.InputsJiwaGrid.ActiveSheet.GetColumnFromTag(null, "SubAssembly").Index].ErrorText = "Circular reference detected.";
                }
                if (!Input.IsBoMItem)
                {
                    this.InputsJiwaGrid["SubAssemblyExplodePolicy", Row] = "\"";
                }
                else
                {
                    this.InputsJiwaGrid["SubAssemblyExplodePolicy", Row] = Input.SubAssemblyExplodePolicy.ToString();
                }
                this.InputsJiwaGrid["UnitMeasure", Row] = Input.Inventory.Units;
                this.InputsJiwaGrid["LastCost", Row] = Input.Inventory.LCost;
                this.InputsJiwaGrid.GridDecimalPlaces("LastCost", Row, this.BillMaintenance.SystemSettings.MoneyDecimalPlaces, -2);
                this.InputsJiwaGrid["TotalLineCost", Row] = Input.TotalLineCost;
                this.InputsJiwaGrid.GridDecimalPlaces("TotalLineCost", Row, this.BillMaintenance.SystemSettings.MoneyDecimalPlaces, -2);
                this.InputsJiwaGrid["Note", Row] = Input.Note;
                this._InputCustomFieldsController.DisplayCustomSettingValues(Input, Row);
                this.InputsJiwaGrid.LockColumn(true, "PartNo", Row);
                this.InputsJiwaGrid.LockColumn(true, "PartNoLookup", Row);
                this.InputsJiwaGrid.LockColumn(false, "Quantity", Row);
                this.InputsJiwaGrid.LockColumn(false, "QuantityType", Row);
                this.InputsJiwaGrid.LockColumn(!Input.IsBoMItem, "SubAssemblyLookup", Row);
                this.InputsJiwaGrid.LockColumn(!Input.IsBoMItem, "SubAssemblyExplodePolicy", Row);
                this.InputsJiwaGrid.LockColumn(false, "Note", Row);
                this.InputsJiwaGrid.LockColumn(false, "Bin", Row);
            }
        }

        public void DisplayInputs(JiwaFinancials.Jiwa.JiwaBillOfMaterials.BillMaintenance.Stage Stage)
        {
            IEnumerator enumerator = null;
            this.InputsJiwaGrid.ActiveSheet.RowCount = 0;
            try
            {
                enumerator = Stage.InputItems.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    InputItem current = (InputItem)enumerator.Current;
                    SheetView activeSheet = this.InputsJiwaGrid.ActiveSheet;
                    activeSheet.RowCount = checked(activeSheet.RowCount + 1);
                    this.DisplayInput(current, checked(this.InputsJiwaGrid.ActiveSheet.RowCount - 1));
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            SheetView rowCount = this.InputsJiwaGrid.ActiveSheet;
            rowCount.RowCount = checked(rowCount.RowCount + 1);
            this.InputsJiwaGrid.LockColumn(false, "PartNo", checked(this.InputsJiwaGrid.ActiveSheet.RowCount - 1));
            this.InputsJiwaGrid.LockColumn(false, "PartNoLookup", checked(this.InputsJiwaGrid.ActiveSheet.RowCount - 1));
            this.InputsJiwaGrid.LockColumn(true, "Bin", checked(this.InputsJiwaGrid.ActiveSheet.RowCount - 1));
            this._InputCustomFieldsController.LineCustomFieldValuesHostCollection = Stage.InputItems;
        }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 12 guests