Page 1 of 1

Add Field to Sales Order Screen

PostPosted: Thu Oct 27, 2022 3:38 am
by Microsharp
Hi Mike/Scott,

We are trying to add one field to Sales Order screen under Total Cubic Size and got stuck.

In Form Plugin our code is as below

#region UI
JiwaFinancials.Jiwa.JiwaApplication.Controls.NumericEditor numTotalQuantity = new JiwaFinancials.Jiwa.JiwaApplication.Controls.NumericEditor();
Infragistics.Win.Misc.UltraLabel lblTotalQuantity = new Infragistics.Win.Misc.UltraLabel();

((System.ComponentModel.ISupportInitialize)numTotalQuantity).BeginInit();
numTotalQuantity.Anchor = AnchorStyles.Top | AnchorStyles.Right;
numTotalQuantity.Location = new Point(frmSalesOrders.TotalWeightNumericEditor.Location.X, frmSalesOrders.TotalCubicNumericEditor.Location.Y);
numTotalQuantity.Name = "numTotalQuantity";
numTotalQuantity.Size = frmSalesOrders.TotalWeightNumericEditor.Size;
numTotalQuantity.DecimalPlaces = 2;
numTotalQuantity.Appearance = frmSalesOrders.TotalWeightNumericEditor.Appearance;

lblTotalQuantity.Anchor = AnchorStyles.Top | AnchorStyles.Right;
lblTotalQuantity.Location = new Point(frmSalesOrders.lblTotalWeight.Location.X, frmSalesOrders.lblTotalCubic.Location.Y);
lblTotalQuantity.Name = "lblTotalQuantity";
lblTotalQuantity.Size = frmSalesOrders.lblTotalWeight.Size;
lblTotalQuantity.Text = "Total Qty.";
lblTotalQuantity.Appearance = frmSalesOrders.lblTotalWeight.Appearance;

frmSalesOrders.UltraPanel1.ClientArea.Controls.Add(lblTotalQuantity);
frmSalesOrders.UltraPanel1.ClientArea.Controls.Add(numTotalQuantity);

((System.ComponentModel.ISupportInitialize)numTotalQuantity).EndInit();

frmSalesOrders.Manager.MakeReadOnly(numTotalQuantity, true);
#endregion

Can you please help us getting the field in that area?

Re: Add Field to Sales Order Screen

PostPosted: Thu Oct 27, 2022 8:57 am
by SBarnes
By the looks of it you are adding your controls to the wrong control i.e. Ultrapanel1, below is the lines from InitializeComponent for the form

Code: Select all
this.TableLayoutPanel1.Controls.Add(this.TotalCubicNumericEditor, 5, 5);
this.TableLayoutPanel1.Controls.Add(this.TotalWeightNumericEditor, 5, 4);


for adding controls to a Tab Layout see https://learn.microsoft.com/en-us/dotne ... esktop-6.0

Re: Add Field to Sales Order Screen

PostPosted: Thu Oct 27, 2022 8:45 pm
by Microsharp
Thanks Stuart,

I tried but still could not make it show on Sales Order screen under Total Cubic Size

Below is the code for FormPlugin

#region "FormPlugin"
public class FormPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaFormPlugin
{
public override object InitializeLifetimeService()
{
// returning null here will prevent the lease manager
// from deleting the Object.
return null;
}

public void SetupBeforeHandlers(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
}

public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
//if (JiwaForm is JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.MainForm)
if (JiwaForm is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
{
//JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.MainForm frmPurchaseOrders = JiwaForm as JiwaFinancials.Jiwa.JiwaPurchaseOrdersUI.MainForm;
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm frmSalesOrders = JiwaForm as JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm;

#region UI
JiwaFinancials.Jiwa.JiwaApplication.Controls.NumericEditor numTotalQuantity = new JiwaFinancials.Jiwa.JiwaApplication.Controls.NumericEditor();
Infragistics.Win.Misc.UltraLabel lblTotalQuantity = new Infragistics.Win.Misc.UltraLabel();

((System.ComponentModel.ISupportInitialize)numTotalQuantity).BeginInit();
numTotalQuantity.Anchor = AnchorStyles.Top | AnchorStyles.Right;
numTotalQuantity.Location = new Point(frmSalesOrders.TotalWeightNumericEditor.Location.X, frmSalesOrders.TotalCubicNumericEditor.Location.Y);
numTotalQuantity.Name = "numTotalQuantity";
numTotalQuantity.Size = frmSalesOrders.TotalWeightNumericEditor.Size;
numTotalQuantity.DecimalPlaces = 2;
numTotalQuantity.Appearance = frmSalesOrders.TotalWeightNumericEditor.Appearance;

lblTotalQuantity.Anchor = AnchorStyles.Top | AnchorStyles.Right;
lblTotalQuantity.Location = new Point(frmSalesOrders.lblTotalWeight.Location.X, frmSalesOrders.lblTotalCubic.Location.Y);
lblTotalQuantity.Name = "lblTotalQuantity";
lblTotalQuantity.Size = frmSalesOrders.lblTotalWeight.Size;
lblTotalQuantity.Text = "Total Qty.";
lblTotalQuantity.Appearance = frmSalesOrders.lblTotalWeight.Appearance;

frmSalesOrders.TableLayoutPanel1.Controls.Add(lblTotalQuantity, 5, 6);
frmSalesOrders.TableLayoutPanel1.Controls.Add(numTotalQuantity, 6, 6);


((System.ComponentModel.ISupportInitialize)numTotalQuantity).EndInit();

frmSalesOrders.Manager.MakeReadOnly(numTotalQuantity, true);
#endregion

frmSalesOrders.SalesOrder.ReadEnd += delegate (object sender, EventArgs e)
{
numTotalQuantity.Value = frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered);
};

frmSalesOrders.SalesOrder.CreateEnd += delegate (object sender, EventArgs e)
{
numTotalQuantity.Value = decimal.One;
};

frmSalesOrders.SalesOrder.CopyEnd += delegate (object sender, EventArgs e)
{
numTotalQuantity.Value = frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered);
};

frmSalesOrders.SalesOrder.SaveStart += delegate (object sender, EventArgs e)
{
JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue cfvTotalOrderQuantity = frmSalesOrders.SalesOrder.CustomFieldValues.get_ItemFromSettingName("TotalQuantityOrdered", Plugin.Name);
if (cfvTotalOrderQuantity.Contents != null)
{
cfvTotalOrderQuantity.Contents = Convert.ToString(frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered));
}
};

frmSalesOrders.SalesOrder.SalesOrderLines.Added += delegate (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item)
{
numTotalQuantity.Value = frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered);
};

frmSalesOrders.SalesOrder.SalesOrderLines.Removed += delegate (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item)
{
numTotalQuantity.Value = frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered);
};

frmSalesOrders.SalesOrder.SalesOrderLines.Changed += delegate (JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine item, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Quantity")
{
numTotalQuantity.Value = frmSalesOrders.SalesOrder.SalesOrderLines.Cast<JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine>()
.Sum(l => l.QuantityOrdered);
}
};
}
}
}
#endregion

Re: Add Field to Sales Order Screen

PostPosted: Fri Oct 28, 2022 8:05 am
by SBarnes
Can I suggest you post the actual plugin as an attachment, is difficult to try and give advice against code in a forum post.

Re: Add Field to Sales Order Screen

PostPosted: Fri Oct 28, 2022 11:03 am
by Mike.Sheen
SBarnes wrote: is difficult to try and give advice against code in a forum post.


And code not formatted / marked up.

Re: Add Field to Sales Order Screen

PostPosted: Fri Oct 28, 2022 12:02 pm
by perry
It's either the point or the parent control.

It is easier to use an existing control as anchor point like
Code: Select all
  .Location = New Point(soform.grdTotals.Location.X - 100, soform.grdTotals.Location.Y)


and add to its parent control like this
Code: Select all
soform.grdTotals.Parent.Controls.Add(FxTotal)


complete code below
Code: Select all
Dim FxTotal As New JiwaApplication.Controls.NumericEditor
            CType(FxTotal, System.ComponentModel.ISupportInitialize).BeginInit()

            With FxTotal
                .Location = New Point(soform.grdTotals.Location.X - 100, soform.grdTotals.Location.Y)
                .Appearance = soform.DebtorCreditLimitNumericEditor.Appearance
                .Dock = System.Windows.Forms.DockStyle.None
                .Name = "FX Total"
                .Enabled = False
                .Size = New Size(80, soform.DebtorCreditLimitNumericEditor.Height)
                .Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right
            End With
            Dim FXTotalLabel = New Infragistics.Win.Misc.UltraLabel
            With FXTotalLabel
                .Location = New System.Drawing.Point(FxTotal.Location.X - 80, FxTotal.Location.Y)
                .Appearance = soform.lblReference.Appearance
                .Dock = System.Windows.Forms.DockStyle.None
                .Name = "FXTotalLabel"
                .Size = New Size(70, FxTotal.Height)
                .Text = "FX Total"
                .Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right
            End With
            soform.grdTotals.Parent.Controls.Add(FxTotal)
            soform.grdTotals.Parent.Controls.Add(FXTotalLabel)

Re: Add Field to Sales Order Screen

PostPosted: Fri Oct 28, 2022 12:27 pm
by Microsharp
Thanks Stuart/Mike, i have attached the plugin.

I will try Perry's suggestion as well

Re: Add Field to Sales Order Screen  Topic is solved

PostPosted: Sat Oct 29, 2022 4:16 pm
by SBarnes
There is are two reasons why your plugin is not working the first is that you need a a form reference to the sales order form under the forms references on the plugin, without it your code is not ever being called as Jiwa doesn't know that it should run you plugin code when the sales order form is loaded like below

formsref.jpg



Your second problem was the code had the wrong values for adding the controls to the table layout it should be like below

Code: Select all
  frmSalesOrders.TableLayoutPanel1.Controls.Add(lblTotalQuantity, 4, 6);
            frmSalesOrders.TableLayoutPanel1.Controls.Add(numTotalQuantity, 5, 6);


The final result is

finalresult.jpg


In the future to check that things are running put the the two lines below in the setup function of the plugin and have Visual Studio launch to see that things are executing and hence the reason I said post the entire plugin as just seeing the code was never going to find the main issue for why this was not working.

Code: Select all
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();

Re: Add Field to Sales Order Screen

PostPosted: Thu Nov 03, 2022 6:14 pm
by Microsharp
Thank you so so much Stuart for your help.