Wednesday, 28 January 2015

Create Transport order in ax 2012 R3 EP

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TransforOrder.ascx.cs" Inherits="TransforOrder" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls" TagPrefix="dynamics" %>

<dynamics:AxDataSource ID="TransOrder" runat="server"
    DataSetName="EPSalesTableEdit" ProviderView="SalesTable"  >
</dynamics:AxDataSource>

 <dynamics:AxMultiSection ID="AxMultiSection1" runat="server">
     <dynamics:AxSection ID="AxSection1" runat="server">
         <dynamics:AxMultiColumn ID="AxMultiColumn1" runat="server">
             <dynamics:AxColumn ID="AxColumn1" runat="server">
                 <table style="width: 401px">
                 <tr>
                <td style="padding-left:19px;" align="left" class="style5">              
                    <asp:Label ID="lblSalesId" runat="server" AssociatedControlID="tbSalesId"
                        Text="Sales Id   " style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbSalesId" Width="100%"
                        ToolTip="Enter the sales id" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="AxLookup1" runat="server" AutoPostBack="true"
                    TargetControlId="tbSalesId"
                    OnLookup="DropDownSalesId_Lookup" TabIndex="1"
                    onokclicked="DropDownSalesId_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>             <tr>
                <td style="padding-left:19px;" align="left" class="style1">              
                    <asp:Label ID="lblModeOfTransport" runat="server" AssociatedControlID="tbModeOfTransport"
                        Text="Mode of transport   " style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbModeOfTransport" Width="100%"
                        ToolTip="Enter the mode of transport" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownModeOfTransport" runat="server" AutoPostBack="true"
                    TargetControlId="tbModeOfTransport"
                    OnLookup="DropDownModeOfTransport_Lookup" TabIndex="1"
                    onokclicked="DropDownModeOfTransport_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
             <tr>
                <td style="padding-left:19px;" align="left" class="style2">              
                    <asp:Label ID="lblTransportProvider" runat="server" AssociatedControlID="tbTransportProvider"
                        Text="Transport provider" style="font-weight: 700"></asp:Label>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbTransportProvider" Width="100%"
                        ToolTip="Enter the transport provider" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownTransportProvider" runat="server" AutoPostBack="true"
                    TargetControlId="tbTransportProvider"
                    OnLookup="DropDowntbTransportProvider_Lookup" TabIndex="1"
                    onokclicked="DropDowntbTransportProvider_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>

            <tr>
                <td style="padding-left:19px;" align="left" class="style3">              
                    <asp:Label ID="lblRoutecard" runat="server" AssociatedControlID="tbRoutecard"
                        Text="Route card" style="font-weight: 700"></asp:Label>
                </td>
                 <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbRoutecard" Width="100%"
                        ToolTip="Enter the route card" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                 <td>
                    <dynamics:AxLookup ID="DropDownRoutecard" runat="server" AutoPostBack="true"
                    TargetControlId="tbRoutecard"
                    OnLookup="DropDowntbRoutecard_Lookup" TabIndex="1"
                    onokclicked="DropDowntbRoutecard_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
             <tr>
                <td style="padding-left:19px;" align="left" class="style4">              
                    <asp:Label ID="Label1" runat="server" AssociatedControlID="tbRatecard"
                        Text="Rate card" style="font-weight: 700"></asp:Label>
                </td>
                 <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbRatecard" Width="100%"
                        ToolTip="Enter the rate card" runat="server" ReadOnly="False"
                        Enabled="True" style="margin-left: 0px"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxLookup ID="DropDownRatecard" runat="server" AutoPostBack="true"
                    TargetControlId="tbRatecard"
                    OnLookup="DropDowntbRatecard_Lookup" TabIndex="1"
                    onokclicked="DropDowntbRatecard_OkClicked">
                    </dynamics:AxLookup>
                </td>
            </tr>
 </table>
             </dynamics:AxColumn>
         </dynamics:AxMultiColumn>
     </dynamics:AxSection>
</dynamics:AxMultiSection>


<p>
<asp:Button ID="Button1" runat="server" Text="Create" onclick="Button1_Click"
        style="margin-left: 243px" Width="60px" />
<asp:Button ID="Button2" runat="server" Text="Cancel" onclick="Button2_Click"
        style="margin-left: 5px" Width="50px" />
</p>
<dynamics:AxForm runat="server" ID="formEPSalesTableEdit"
    DataKeyNames="RecId"
    DataMember="SalesTable_Current"
    DataSourceID="TransOrder" DefaultMode="Edit" UpdateOnPostBack="true"
    AutoGenerateEditButton="False" ShowButtonsInActionPane="false" >
</dynamics:AxForm>
___________________________________________________________________________  
#region using
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.Framework.Portal.UI;
using Microsoft.Dynamics.Framework.Portal.CommonControls;

#endregion


public partial class TransforOrder : System.Web.UI.UserControl
{
    DataSetViewRow row;
    AxUrlMenuItem menuItem;
    string recId;

    /// <summary>
    /// Web part private
    /// </summary>
    AxBaseWebPart _baseWebpart = null;
    #region Properties
    /// <summary>
    /// Webpart
    /// </summary>
    AxBaseWebPart BaseWebpart
    {
        get
        {
            //return the basewebpart if it is not null
            if (this._baseWebpart != null)
                return this._baseWebpart;
            //get the webpart if basewebpart is null
            this._baseWebpart = AxBaseWebPart.GetWebpart(this);
            return this._baseWebpart;
        }
    }
    /// <summary>
    /// Gets the current Web Part Session.
    /// </summary>
    ISession AxSession
    {
        get
        {
            return BaseWebpart.Session;
        }
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Title = "Release to transport";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Proxy.Info objInfoLog = new Proxy.Info(this.AxSession.AxaptaAdapter);
        string test,local;

        //String SalesidName = (String)this.TransOrder.GetDataSet().DataSetRun.AxaptaObjectAdapter.Call("getSalesId");
        test = this.tbSalesId.Text + this.tbModeOfTransport.Text + this.tbTransportProvider.Text + this.tbRoutecard.Text + this.tbRatecard.Text;
        if (test != "")
        {
            local = this.tbSalesId.Text;
            if (local != "")
            {
                AxSession.AxaptaAdapter.CallStaticRecordMethod("SalesTable", "localvalue",
                                                          this.tbSalesId.Text,
                                                          this.tbModeOfTransport.Text,
                                                          this.tbTransportProvider.Text,
                                                          this.tbRoutecard.Text,
                                                          this.tbRatecard.Text);

                DialogHelper.Close();
            }
            else
            {
                objInfoLog.add(Proxy.Exception.Warning, "Please select the Sales order");
            }
        }
        else
        {
            objInfoLog.add(Proxy.Exception.Warning, "Please select the parameters");
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DialogHelper.Close();
    }

    protected void DropDownSalesId_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownSalesId_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "Salestable")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "SalesTable", "OrderTransported")).value = "0";
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "SalesTable", "Salesid"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["SalesId"]));
            // Specify the select field
            nameLookup.SelectField = "SalesId";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDownModeOfTransport_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDownModeOfTransport_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_ModeOfTrans")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                   // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_ModeOfTrans", "ModeOfTransport"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["ModeOfTransport"]));
            // Specify the select field
            nameLookup.SelectField = "ModeOfTransport";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbTransportProvider_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbTransportProvider_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_TransportProviderMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_TransportProviderMaster", "DIPL_TransportProvider"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_TransportProvider"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_TransportProvider";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbRoutecard_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbRoutecard_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_RoutecardMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_RoutecardMaster", "DIPL_Routecard"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_Routecard"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_Routecard";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
    protected void DropDowntbRatecard_OkClicked(object sender, AxLookupEventArgs e)
    {
        //this.loadProdGroupDrpDown();
    }
    protected void DropDowntbRatecard_Lookup(object sender, AxLookupEventArgs e)
    {
        AxLookup nameLookup = e.LookupControl;
        //TxtWarehouseCode.Text = "";
        try
        {
            AxLookup lookup = (AxLookup)sender;
            // Create the lookup dataset - we will do a lookup in the DirPartyTable table
            using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, "DIPL_RatecardMaster")))
            {
                // Set the run time generated data set as the lookup data set
                nameLookup.LookupDataSet = new Microsoft.Dynamics.AX.Framework.Portal.Data.DataSet(this.AxSession, sysDataSetBuilder.toDataSet());
            }
            // DataSet has to be init'ed before accessing the data sources
            nameLookup.LookupDataSet.Init();
            // Filter the lookup
            using (Proxy.Query query = nameLookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
            {
                using (Proxy.QueryBuildDataSource qbds = query.dataSourceNo(1))
                {
                    // qbds.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, "PriceMasterTable", "BPGroup")).value = this.tbBPGroup.Text;
                    qbds.addOrderByField(TableDataFieldMetadata.FieldNum(this.AxSession, "DIPL_RatecardMaster", "DIPL_Ratecard"));
                    qbds.orderMode = (int)OrderMode.GroupBy;
                }
            }
            // Specify the lookup fields used
            nameLookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession, nameLookup.LookupDataSetViewMetadata.ViewFields["DIPL_Ratecard"]));
            // Specify the select field
            nameLookup.SelectField = "DIPL_Ratecard";
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // The exception is system fatal - in this case we re-throw.                                  
                throw;
            }
        }
    }
 
}

No comments:

Post a Comment