Page 1 of 1

Sales Order Delivery Address Search

PostPosted: Wed Sep 14, 2022 10:04 am
by Ernst
We want to add deliveryName to the delivery address search from the sales order on the delivery tab. Search No33.

Though this would be easy. See attached. But of course it select all delivery addresses, not just the ones for that debtor. I was hoping the JIWA query would add the where clause.

How do add a debtor id into my search?
Plugin LubeNZ Custom Searches.xml
(28.22 KiB) Downloaded 81 times


Thx for help

Re: Sales Order Delivery Address Search  Topic is solved

PostPosted: Wed Sep 14, 2022 10:25 am
by SBarnes
Hi Ernst

What you need to do is to use the setup before handler in the form plugin and attach to it like this, here is an example of where I have done something similar for a customer, it's not exactly the same as what you want to do but is similar. The other trick is throwing the client cancel exception to stop the the Jiwa code then firing.

Code: Select all
salesform.DeliveryAddress1EditableLookup.ButtonClicked += DeliveryAddress1EditableLookup_ButtonClicked;


Code: Select all
        private void DeliveryAddress1EditableLookup_ButtonClicked(object sender, EventArgs e)
        {
            clsSearch search = this.manager.Search;
            search.Clear();
            search.FilterNo = 33;
            search.CurrentOption = 1;
            search.Caption = string.Concat("Debtors Delivery Addresses For ", this.salesorder.Debtor.Name);
            search.UsePinBoard = false;
            SearchOption searchOption = this.manager.CollectionItemFactory.CreateCollectionItem<SearchOption>();
            SearchOption searchOption1 = searchOption;
            searchOption1.Title = "Address (by postcode)";
            searchOption1.SQLStr = string.Concat(@"SELECT Address1
                                                  ,Address2
                                                  ,Address3
                                                  ,Address4
                                                  ,PostCode
                                                  ,Country
                                                  ,Notes
                                                  ,CourierDetails
                                                  ,FName
                                                  ,SName
                                                  ,Mobile
                                                  ,FName2
                                                  ,SName2
                                                  ,Mobile2
                                                   ,RecID
                                                   FROM vAttk_DB_DeliveryAddressWithContacts  WHERE DebtorID = ", this.manager.Database.FormatChar(this.salesorder.Debtor.DebtorID));
            searchOption1.OrderBy = "ORDER BY PostCode";
            searchOption1.AddColumn("Address 1", VariantType.String, "L", 10, 1, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Address 2", VariantType.String, "L", 8, 2, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Address 3", VariantType.String, "L", 8, 3, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Address 4", VariantType.String, "L", 8, 4, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Post Code", VariantType.String, "L", 5, 5, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Country", VariantType.String, "L", 5, 6, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Notes", VariantType.String, "L", 0, 7, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Courier", VariantType.String, "L", 0, 8, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("First Name", VariantType.String, "L", 8, 9, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Surname", VariantType.String, "L", 8, 10, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Mobile", VariantType.String, "L", 8, 11, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("First Name 2", VariantType.String, "L", 8, 12, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Surname 2", VariantType.String, "L", 8, 13, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("Mobile 2", VariantType.String, "L", 8, 14, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            searchOption1.AddColumn("RecID", VariantType.String, "L", 0,15, ".", 2, Column.DecimalPlacesTypes.HardCoded, false, ",", -1);
            this.manager.Search.AddSearchOption(ref searchOption);
            searchOption = null;
            clsSearch _clsSearch = this.manager.Search;
            string recid = "";
            if (_clsSearch.Show(salesform) == DialogResult.OK && _clsSearch.Results.Count != 0)
            {
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].DelAddress1 = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(1), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].DelAddress2 = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(2), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].DelAddress3 = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(3), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].DelAddress4 = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(4), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].PostCode = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(5), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].DeliveryAddressCountry = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(6), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].Notes = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(7), null, "FieldValue", new object[0], null, null, null));
                this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].CourierDetails = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(8), null, "FieldValue", new object[0], null, null, null));
                //recid = Conversions.ToString(NewLateBinding.LateGet(_clsSearch.get_Fields(9).ToString(), null, "FieldValue", new object[0], null, null, null));
               
                recid = ((JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)_clsSearch.get_Fields(15)).FieldValue.ToString();
                if (recid != null && recid != "")
                {
                    DBDeliveryAddressContact dacon = this.manager.CollectionItemFactory.CreateCollectionItem<DBDeliveryAddressContact>();
                    dacon.Read(recid);
                    string histid = this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo].RecID;
                    this.salesorder.SalesOrderHistorys[histid].DelContactName = dacon.ContactName1String;
                    SOHistorySecondContact secon = secondcontacts.GetSecondContactForHistID(histid);
                    secon.SalesOrderHistory = this.salesorder.SalesOrderHistorys[this.salesorder.SelectedHistoryNo];
                    secon.Contact2Name = dacon.ContactName2String;
                    secon.Mobile1 = dacon.ContactName1.Mobile;
                    secon.Mobile2 = dacon.ContactName2.Mobile;
                    SetExtraControlValues(secon);
                }
               
            }
            _clsSearch = null;
            throw new ClientCancelledException();
        }

Re: Sales Order Delivery Address Search

PostPosted: Wed Sep 14, 2022 10:37 am
by Ernst
Thx for quick response. I'll give that a go.

Re: Sales Order Delivery Address Search

PostPosted: Thu Oct 06, 2022 2:13 pm
by Ernst
Hi Stuart,

OK couldnt get your DeliveryAddress1EditableLookup_ButtonClicked Breakout going, as I had no access to the plugin, from there, so couldnt do your line
clsSearch search = this.manager.Search

Is you code linked to the plugin with this. ?

Managed to get it working like this from form.manager.search, and saved the debtorid in a public field. on read and create.

Thanks.

Code: Select all
AddHandler salesOrderForm.Manager.Search.Showing, AddressOf SalesOrder_Search_Showing

Private Sub SalesOrder_Search_Showing (sender As Object, e As System.EventArgs)
      Dim SQL As String
      Dim OrderBy As String
      Dim AOption As JiwaApplication.JiwaSearch.SearchOption
      
       Dim searchObject As JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch = DirectCast(sender, JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch)
      
       With searchObject.Manager.Search
         
If .FilterNo = 33 Then
      SQL = " SELECT Address1, Address2, Address3, Address4, PostCode, Country, Notes, CourierDetails,DeliveryAddressName  FROM DB_DeliveryAddress  WHERE DB_DeliveryAddress.DebtorID = '" & MyDebtorID & "'"
 
      OrderBy = "ORDER BY DB_DeliveryAddress.PostCode "
 
      AOption = New JiwaApplication.JiwaSearch.SearchOption
      With AOption
            .Title = "ByAddressName"
            .SQLStr = SQL
            .OrderBy = OrderBy
            .AddColumn ("Address1", vbString, "", 20, 1)
         .AddColumn ("Address2", vbString, "", 15, 2)
         .AddColumn ("Address3", vbString, "", 10, 3)
         .AddColumn ("Address4", vbString, "", 10, 4)
         .AddColumn ("Postcode", vbString, "", 4, 5)
         .AddColumn ("Country", vbString, "", 5, 6)
         .AddColumn ("Notes", vbString, "", 5, 7)
         .AddColumn ("Courier", vbString, "", 5, 8)
         .AddColumn ("AddressName", vbString, "", 25, 9)
      End With
      .Options.Add(AOption)
End If
      End With
   End Sub

Re: Sales Order Delivery Address Search

PostPosted: Fri Dec 09, 2022 6:18 pm
by Mike.Sheen
Ernst wrote:OK couldnt get your DeliveryAddress1EditableLookup_ButtonClicked Breakout going, as I had no access to the plugin, from there, so couldnt do your line
clsSearch search = this.manager.Search


A trick you can use is to inject whatever parameters you like into an event handler using a lambda which has access to all the variables in scope at the time of adding the handler.

So you could have passed the plugin as a parameter to the DeliveryAddress1EditableLookup.ButtonClicked event handler.

For example, in a FormPlugin class:

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup      
   If TypeOf JiwaForm Is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm Then
      Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = JiwaForm
               
      AddHandler salesOrderForm.DeliveryAddress1EditableLookup.ButtonClicked, Sub(sender As Object, e As System.EventArgs) DeliveryAddress1EditableLookup_ButtonClicked(sender, e, Plugin)
   End If
      
End Sub

Private Sub DeliveryAddress1EditableLookup_ButtonClicked(sender As Object, e As System.EventArgs, Plugin As JiwaApplication.Plugin.Plugin)
   System.Windows.Forms.MessageBox.Show(String.Format("I'm in DeliveryAddress1EditableLookup_ButtonClicked and I know about {0}", Plugin.Name))
End Sub


All we're doing in the above is in the AddHandler instead of just passing the AddressOf the DeliveryAddress1EditableLookup_ButtonClicked like you would normally do, is instead provide a lambda method and that calls DeliveryAddress1EditableLookup_ButtonClicked. The lambda can be considered like a local method inside the current method - and it has access to all the variables in scope at that time.

Re: Sales Order Delivery Address Search

PostPosted: Tue Dec 20, 2022 2:16 pm
by Ernst
THanks Mike, will give it a try.