Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Wednesday, November 27, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - SalesLogix Scripting & Customization
Forum to discuss writing script in Architect plugins for SalesLogix & general SalesLogix customization topics (for Windows client only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Scripting & Customization | New ThreadView:  Search:  
 Author  Thread: Trouble "Leveraging .NET in SLX 6.2"
Christopher Morley
Posts: 21
 
Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 12:11 PM
fiogf49gjkf0d
Hi all.
I am following to the T the "start to finish" video demo of Leveraging .NET (C# though),
When I click to view the tab, AXFormChange is being called, and my .NET DataGridView appears.
However, when I click to go to next account, only the Native Plugin part refreshes.
So, Label1's Caption changes to the new ACCOUNTID, however the .NET part, which should come up with the AXFormChange, does not refresh. In fact, it goes away entirely, and doesn't come back. I can make it always come back if I have a button to refresh it.
It seems like AXFormChange is just not getting called at all. AXFormMouseMove is the only Sub that seems to get called a lot for me (although that can't be the right place to put the code.) Here is the Script in my Saleslogix form:


option explicit

Sub AXFormChange(Sender)
Dim loader
If Application.GlobalInfo.IndexOf("EmbedControlObject") = -1 Then
Set loader = CreateObject("DccSlx.EmbedExternalHistoryControl")
loader.Init Form.HWND
loader.AccountID = Form.CurrentID
Application.GlobalInfo.Add "EmbedControlObject", loader
Else
Set loader = Application.GlobalInfo("EmbedControlObject")
loader.AccountID = Form.CurrentID
End If
End Sub
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 1:30 PM
fiogf49gjkf0d
Everything looks right for the code you've posted.

Is this on a tab or on the main detail screen?

You say you have a label or something bound to the primary ID field and it is properly changing when moving from record or record?

If you put a "stop" statement in right before the "IF" block, and go into the debugger to step through the script, does it properly fall into the "else" part on subsequent record changes?
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 1:51 PM
fiogf49gjkf0d
This is on a tab at the account level only for now (I plan to make one for Contact and Opportunity levels once I get this working).

I have a TLabel called Label1 which has its Caption attribute bound to ACCOUNT:ACCOUNTID and so yes, that does change properly when moving from record to record.

Thanks for the tip about Stop. Rebecca Harris thanks you too on that one.

It does seem to drop correctly into the Else, however it does so twice.

(On initial create, it drops first into the If, and then a second time into the else, even on the first time).
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 2:23 PM
fiogf49gjkf0d
okay. I got it sort of working, so perhaps the error is in my .NET user control.
It works if I call this (again) in the Else part (after getting loader from Application.GlobalInfo and before setting the CurrentID):

loader.Init Form.HWND

So maybe I'm just not saving the parent right in the loader object.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 2:27 PM
fiogf49gjkf0d
Sounds like you might not be keeping a reference to the UserControl in you .NET assembly. So, each time you need to recreate and embed the control since you've lost the reference to the original one. Just a guess, but it would have to be something like that.

Feel free to post your C# code that does the embedding as well if you need to.
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 2:36 PM
fiogf49gjkf0d
//***************************************** Listing of Loader.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ComVisible(true), ProgId("DccSlx.EmbedExternalHistoryControl")]
public class Loader : IDisposable
{
private HistoryControl _ctrl = null;

public Loader() { }

public void Dispose()
{
if (_ctrl != null)
{
Win32.SetParent(_ctrl.Handle, IntPtr.Zero);
_ctrl.Dispose();
}
}

public void Init(object handle)
{
if (handle != null)
{
IntPtr hwnd = new IntPtr((int)handle);
if (_ctrl == null) _ctrl = new HistoryControl();
Win32.SetParent(_ctrl.Handle, hwnd);
ResizeControl(hwnd);
}
}

public bool toReload
{
get
{
if (_ctrl != null)
{
return _ctrl.toReload;
}
else
{
return true;
}
}
}

public string AccountID
{
set
{
if (_ctrl != null)
{
_ctrl.AccountID = value;
}
}
}

public string ContactID
{
set
{
if (_ctrl != null)
{
_ctrl.ContactID = value;
}
}
}

public string OpportunityID
{
set
{
if (_ctrl != null)
{
_ctrl.OpportunityID = value;
}
}
}

private void ResizeControl(IntPtr hwnd)
{
Win32.RECT rect;
if (Win32.GetWindowRect(hwnd, out rect) && _ctrl != null)
{
_ctrl.Size = rect.Size;
}
}

}
}


//***************************************** Listing of Win32.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace ClassLibrary1
{
internal class Win32
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[Serializable, StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(int left_, int top_, int right_, int bottom_)
{
Left = left_;
Top = top_;
Right = right_;
Bottom = bottom_;
}

public int Height { get { return Bottom - Top; } }
public int Width { get { return Right - Left; } }
public Size Size { get { return new Size(Width, Height); } }
public Point Location { get { return new Point(Left, Top); } }

public Rectangle ToRectangle()
{ return Rectangle.FromLTRB(Left, Top, Right, Bottom); }

public static RECT FromRectangle(Rectangle rectangle)
{ return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom); }

public static implicit operator Rectangle(RECT rect)
{ return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom); }

public static implicit operator RECT(Rectangle rect)
{ return new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom); }

public override int GetHashCode()
{
return Left ^ ((Top << 13) | (Top >> 0x13))
^ ((Width << 0x1a) | (Width >> 6))
^ ((Height << 7) | (Height >> 0x19));
}
}
}
}

//***************************************** Listing of HistoryControl.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ClassLibrary1
{
public partial class HistoryControl : UserControl
{

bool reload = false;

public HistoryControl()
{
InitializeComponent();
reload = false;
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("click");
reload = true;
}

public bool toReload
{
get { return reload; }
}

public string AccountID
{
get { return label1.Text; }
set { label1.Text = value;
this.spvDCC_FastAccountHistoryTableAdapter1.Fill(this.dccslX_PRODDataSet1.spvDCC_FastAccountHistory, AccountID, "ADMIN");
}
}

public string ContactID
{
get { return label2.Text; }
set { label2.Text = value; }
}

public string OpportunityID
{
get { return label3.Text; }
set { label3.Text = value; }
}

private void button1_Click_1(object sender, EventArgs e)
{

}

}
}
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 4:19 PM
fiogf49gjkf0d
Now it's working. Here's the new code below. I just went back and simplified out extra stuff that I had put in there. I must have taken out something that was causing problems (code that was meant for future use: reload, opportunityid, contactid, buttonclick). As before, closed Saleslogix completely and reinstalled the ClassLibrary1.dll using a batch file which I will also post.

Seems brittle that it should "just work" now even though I didn't consciously "fix it".

//***************************************** Win32.cs, - no changes
//***************************************** New Listing of Loader.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ClassLibrary1
{
[ComVisible(true), ProgId("DccSlx.EmbedExternalHistoryControl")]
public class Loader : IDisposable
{
private HistoryControl _ctrl = null;

public Loader() { }

public void Dispose()
{
if (_ctrl != null)
{
Win32.SetParent(_ctrl.Handle, IntPtr.Zero);
_ctrl.Dispose();
}
}

public void Init(object handle)
{
if (handle != null)
{
IntPtr hwnd = new IntPtr((int)handle);
if (_ctrl == null) _ctrl = new HistoryControl();
Win32.SetParent(_ctrl.Handle, hwnd);
ResizeControl(hwnd);
}
}

public string AccountID
{
set
{
if (_ctrl != null)
{
_ctrl.AccountID = value;
}
}
}

private void ResizeControl(IntPtr hwnd)
{
Win32.RECT rect;
if (Win32.GetWindowRect(hwnd, out rect) && _ctrl != null)
{
_ctrl.Size = rect.Size;
}
}

}
}


//***************************************** New Listing of HistoryControl.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ClassLibrary1
{
public partial class HistoryControl : UserControl
{

public HistoryControl()
{
InitializeComponent();
}

public string AccountID
{
get { return label1.Text; }
set { label1.Text = value;
this.spvDCC_FastAccountHistoryTableAdapter1.Fill(this.dccslX_PRODDataSet1.spvDCC_FastAccountHistory, AccountID, "ADMIN");
}
}

}
}
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 4:21 PM
fiogf49gjkf0d
REM Listing of Install.bat
regasm -u ClassLibrary1.dll
del c:\windows\system32\ClassLibrary1.dll
del "c:\Program Files\Saleslogix\ClassLibrary1.dll"
copy ClassLibrary1.dll c:\windows\system32\ClassLibrary1.dll
copy ClassLibrary1.dll "c:\Program Files\Saleslogix\ClassLibrary1.dll"
regasm ClassLibrary1.dll
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 13 Mar 07 4:26 PM
fiogf49gjkf0d
Now this is weird. With the Plugin open in Architect, I did Save As and gave a new name. Now they don't work as before (copied and original), even with now code. It is like a CTRL F5 isn't always enough to get new scripts?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 14 Mar 07 12:21 AM
fiogf49gjkf0d
Quote:
Originally posted by Christopher Morley

Now this is weird. With the Plugin open in Architect, I did Save As and gave a new name. Now they don't work as before (copied and original), even with now code. It is like a CTRL F5 isn't always enough to get new scripts?


A CTRL+F5 does not clear globals, so if you've saved an instance of your .NET object in a global, it will still be there after a CTRL+F5 - this is probably what you are seeing.
[Reply][Quote]
Christopher Morley
Posts: 21
 
Re: Trouble "Leveraging .NET in SLX 6.2"Your last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 15 Mar 07 8:39 AM
fiogf49gjkf0d
Yes that's probably what confused me there, Thanks Ryan
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/27/2024 8:44:53 AM