Add Field to Sales Order Screen  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Add Field to Sales Order Screen

Postby Microsharp » Thu Oct 27, 2022 3:38 am

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?
Microsharp
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Wed Apr 29, 2015 4:51 pm
Topics Solved: 1

Re: Add Field to Sales Order Screen

Postby SBarnes » Thu Oct 27, 2022 8:57 am

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
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Add Field to Sales Order Screen

Postby Microsharp » Thu Oct 27, 2022 8:45 pm

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
Microsharp
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Wed Apr 29, 2015 4:51 pm
Topics Solved: 1

Re: Add Field to Sales Order Screen

Postby SBarnes » Fri Oct 28, 2022 8:05 am

Can I suggest you post the actual plugin as an attachment, is difficult to try and give advice against code in a forum post.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Add Field to Sales Order Screen

Postby Mike.Sheen » Fri Oct 28, 2022 11:03 am

SBarnes wrote: is difficult to try and give advice against code in a forum post.


And code not formatted / marked up.
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: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Add Field to Sales Order Screen

Postby perry » Fri Oct 28, 2022 12:02 pm

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)
Perry Ma
S. Programmer
Lonicera Pty Ltd
http://www.lonicera.com.au
perry
Frequent Contributor
Frequent Contributor
 
Posts: 173
Joined: Mon Oct 27, 2008 2:26 pm
Topics Solved: 15

Re: Add Field to Sales Order Screen

Postby Microsharp » Fri Oct 28, 2022 12:27 pm

Thanks Stuart/Mike, i have attached the plugin.

I will try Perry's suggestion as well
Attachments
Plugin Microsharp - Sales Order Total Quantity Ordered.xml
(38.62 KiB) Downloaded 72 times
Microsharp
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Wed Apr 29, 2015 4:51 pm
Topics Solved: 1

Re: Add Field to Sales Order Screen  Topic is solved

Postby SBarnes » Sat Oct 29, 2022 4:16 pm

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();
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Add Field to Sales Order Screen

Postby Microsharp » Thu Nov 03, 2022 6:14 pm

Thank you so so much Stuart for your help.
Microsharp
Occasional Contributor
Occasional Contributor
 
Posts: 19
Joined: Wed Apr 29, 2015 4:51 pm
Topics Solved: 1


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 39 guests