on 11-04-2013 4:28 PM
Hello,
I just started developing an addon for SAP Business One 9.0.
I need some advanced components (e.g. a complex tree-grid). SAP UI API is quite poor in components. I know I can insert third-party ActiveX controls inside UI API forms, it works, but in this way my choice is limited to ActiveX controls and also developing an addon in this way is intricate...
So I wonder if I can do the opposite: can I create a classic Windows application, embedding SAP UI API controls when I need them? I could launch it from a B1 menu item.
It's an idea, what do you think? Everybody make do with SAP UI API? Or are there other solutions? Thanks
Hi simone.pastorin,
first solution maybe is using sap for visual studio, where it has it's on designer like win forms has.
which can connect to sap system forms and your created forms as well.
Second solution
It's possible to embed windows.forms in SAP UI,
but it will limit to custom created forms, not SAP system forms.
also one important thing is that you will not be able to bind win forms controls to sap data sources.
So with windows form you are adding system.windows.forms components on designer, but you will need to handle all data processing by hand, it will not be automated, I gave up on this method as sap for vs is better choice though it has lack of customisable controls and activex nowadays is hard to mantananse.
private static void SapApp_MenuEvent(ref MenuEvent data, out bool bubbleEvent)
{
bubbleEvent = true;
if (!data.BeforeAction) return;
try
{
//this is my custom created form
if (data.MenuUID == "MNU_Form1")
{
var par = SapApp.CreateObject(BoCreatableObjectType.cot_FormCreationParams) as FormCreationParams;
par.UniqueID = "Form1";
par.FormType = "Form1";
par.BorderStyle = BoFormBorderStyle.fbs_Fixed;
par.Modality = BoFormModality.fm_None;
var sapForm = SapApp.Forms.AddEx(par);
sapForm.Title = "Form1";
var type = _formsAssembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(WindowsForm)) && !t.IsAbstract)
.FirstOrDefault();
var t = new System.Threading.Thread((start) =>
{
//WindowsForm is child class of Form with additional method void Register where I path SAP.Form object
var winForm = Activator.CreateInstance(type) as WindowsForm;
winForm.Visible = true;
winForm.ShowInTaskbar = true;
winForm.TopMost = true;
winForm.ControlBox = true;
winForm.Register(sapForm);
winForm.Show();
winForm.Activate();
winForm.Focus();
//this is where I load my win form into sap UI
System.Windows.Forms.Application.Run(winForm);
});
t.Start();
//sapForm.Visible = true;
//sapForm.Select();
}
}
catch (Exception ex)
{
HandleException(ex, "Exception occurred during MenuEvent handling.", true);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, this is so intresting, can you explain 2 omitted things?
the _formassembly variable wich assembly metadata contains? I've tried to get with reflection the assembly that contains the UserFormBase class, but it seems that in this assembly there are no Windows.Forms.Form descendants.
For the WindowsForm class, if i'm correct you've inherited Windows.Forms.Form and added Register method, can you post the "Register" code?
_formsAssembly is just System.Reflection.Assembly nothing more.
this code block is just for sample. from Assembly Im trying to get first class that inherits from WindowsForms base class. that itself is child of Form (System.Windows.Forms)
var type = _formsAssembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(WindowsForm)) && !t.IsAbstract)
.FirstOrDefault();
in working app you should have some property medaData for example that has MNU_Form1 as value and some other options that you will need. in that case you will be able to get some correct class type that was clicked and not just FirstOrDefault().
public class WindowsForm : Form
{
public SAP.Form SapForm { get; private set; }
public void Register(SAP.Form sapForm)
{
if (SapForm != null)
{
throw new InvalidOperationException("Form has already been registered!");
}
SapForm = sapForm ?? throw new ArgumentNullException(nameof(sapForm));
}
}
WindowsForms class was made just for demonstrating sample. Have not done farther research in this part
and last part Form1
public partial class Form1 : WindowsForm
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
BeeApp.SapApp.MessageBox($"Windows Form button click!");
}
}
Hi Simone Pastorin,
The first, you must install some things :
1. DI API Installation : to do with object and database of SAP Business One. You can create Window Application to communication to SAP Business One.
2. SAP Business One SDK : to do with UI of SAP Business One. You can create UI form in SAP Business One like the standard UI of SAP Business One.
I hope to help you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nguyen,
I know all these things, I already work with them. My question goes beyond..
I'd like to achieve this: in B1 the user clicks on a menu item, a Windows form application is launched. In this application I'd like to have some SAP UI API components, like "choose from list" functionality for instance. The rest of the application should be made of normal WinForm components (which are more powerful for me). Am I clear?
Hi Simone,
i guess this is not possible! SAP has it's own drawing routines and controls. I guess they just don't use standard .Net Controls or ActiveX controls. This is why you can't use it in your own windows application.
You may go another way. Try to create your form as a standalone control in .Net und force SAP B1 to show your control in a normal SAP Form in SAP B1.
User | Count |
---|---|
107 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.