3

我是报告和 .net 的新手,我已经使用SSRS完成了报告,但现在我想将条形码添加到报告中。我已经有一个 Web 服务正在为我生成条形码图像,但现在仅适用于数据矩阵格式我想在该 Web 服务中编写该方法,该方法将为我提供我搜索并遇到的条形码图像或字符串

Microsoft.Dynamics.AX

课程,但我不知道如何使用它们 msdn 也没有提供任何帮助,所以我的问题是

1) Is it possible to use the Microsoft.Dynamics.AX classes in to the web service? 
2) If possible how to add references any links will be helpful ?
3) If not then any other way for it ? any links will be helpful ?

我知道有很多第三方工具,但我想知道是否可以通过自我编码来做到这一点?提前感谢您的帮助。

4

1 回答 1

2

1) 是 2) 您需要这些才能从 AX 中访问信息。

using Microsoft.Dynamics.AX.Framework.Linq.Data;
using U23 = Microsoft.Dynamics.AX.ManagedInterop;
using U22 = Microsoft.Dynamics.AX.Framework.Linq.Data;
using Microsoft.Dynamics.Portal.Application.Proxy;

最后,这是我在 C# 中的访问层的基本布局。

private U23.Session _axSession = new U23.Session();
public U23.Session Connection
{
    get
    {
        return this._axSession;
    }
}
/// <summary>
/// Checks to see if the AX session is connected. If it's null we return false. 
/// Then we check to see if it's logged in, then return true. Otherwise it's not logged in.
/// </summary>
public bool Connected
{
    get
    {
        if (this._axSession == null)
        {
            return false;
        }
        else if (this._axSession.isLoggedOn())
        {
            return true;
        }
        return false;
    }
}

/// <summary>
/// This connects to the AX session. If it's already connected then we don't need to connect
/// again, so we return true. Otherwise we'll try to initiate the session. 
/// </summary>
/// <returns>
/// True: Connection openned successfully, or was already open.
/// False: Connection failed.
/// </returns>
public bool OpenConnection()
{
    if (this.Connected)
    {
        return true;
    }
    else
    {
        try
        {
            _axSession.Logon(null, null, null, null);
            return true;
        }
        catch
        {
            return false;
        }
    }
}

/// <summary>
/// If the session is logged on we will try to close it.
/// </summary>
/// <returns>
/// True: Connection closed successfully
/// False: Problem closing the connection
/// </returns>
public bool CloseConnection()
{
    bool retVal = false;
    if (this.Connection.isLoggedOn())
    {
        try
        {
            _axSession.Logoff();
            retVal = true;
        }
        catch
        {
            retVal = false;
        }
    }
    else
    {
        retVal = true;
    }
    this.Connection.Dispose();
    return retVal;
}

然后要访问 AX 中的某些功能,您只需:

public Somethings GetSomethingsById(int id)
    {
        Somethings retVal = new Somethings();
        U22.QueryProvider provider = new U22.AXQueryProvider(null);
        U22.QueryCollection<Somethings> somethings = new U22.QueryCollection<Somethings>(provider);
        var somethings2 = somethings.Where(x => x.SomethingId == id);
        retVal = somethings2.FirstOrDefault();
        return retVal;
    }

最后,如果你想更新一些东西:

public bool UpdateSomething(Something something)
        {
            U23.RuntimeContext.Current.TTSBegin();
            try
            {
                if (something.Count == 0)
                {
                    something.Delete();
                }
                something.Update();
                U23.RuntimeContext.Current.TTSCommit();
                return true;
            }
            catch
            {
                U23.RuntimeContext.Current.TTSAbort();
                return false;
            }
        }

但请确保您在Something计划更新时选择了 .ForUpdate() 。

您还必须将您计划使用的任何对象添加到应用程序代理(例如 EPApplicationProxies)并从您的项目中引用它。

于 2013-08-08T19:42:23.233 回答