Thursday, 16 October 2014

From date todate filter in ssrs report with ep in ax 2012


Document For EP Report:-
1. ex:-this report EPsalesregister control and URl menu item for reference
2.Crete new report like example HcmBirthday Same
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ARMaster.ascx.cs" Inherits="ARMaster" %>
<%@ 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:AxMultiSection ID="EPSalesByRegionMultiSection" runat="server">
    <dynamics:AxSection ID="EPSalesByRegionSection" runat="server">
     <table>
            <tr>
                <td style="padding-left:19px;" align="right">               
                    <asp:Label ID="lblFromDate" runat="server" AssociatedControlID="tbFromDate"
                        Text="<%$Axlabel:@SYS5209%>"></asp:Label>
                        <dynamics:AxValueFormatValidator ID="axVFVEffectiveDate" runat="server" ControlToValidate="tbFromDate"
                        DisplayErrorInInfolog="true" ValidateEmptyText="True" ValidationGroup="Error"
                        ExtendedDataType="TransDate" SetFocusOnError="True" ErrorMessage="<%$Axlabel:@SYS100987%>"
                        Display="Dynamic">
                    </dynamics:AxValueFormatValidator>                                      
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbFromDate" Width="100%"  ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" Enabled="True"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxDatePicker class="DynamicsDatePickerCalendarButton" ExtendedDataType="FromDate"  TargetControlId="tbFromDate" ID="axButtonFromDate" runat="server" />
                </td>
              
                <td width="75px" align="right">
                    <asp:Label ID="lblToDate" runat="server" AssociatedControlID="tbToDate"
                        Text="<%$Axlabel:@SYS14656%>"></asp:Label>
                    <dynamics:AxValueFormatValidator ID="axVFVExpirationDate" runat="server" ControlToValidate="tbToDate"
                        DisplayErrorInInfolog="true" ErrorMessage="<%$Axlabel:@SYS100987%>" ExtendedDataType="TransDate"
                        SetFocusOnError="True" ValidateEmptyText="True" ValidationGroup="Error" Display="Dynamic">
                    </dynamics:AxValueFormatValidator>
                </td>
                <td align="right">
                    <asp:TextBox class="AxInputField" ID="tbToDate" Width="100%"  ToolTip="<%$Axlabel:@SYS191513%>" runat="server" ReadOnly="False" Enabled="True"></asp:TextBox>
                </td>
                <td>
                    <dynamics:AxDatePicker class="DynamicsDatePickerCalendarButton" ExtendedDataType="ToDate"  TargetControlId="tbToDate" ID="axButtonToDate" runat="server" />
                </td>
                <td>
                    <asp:Button runat="server" ID="ViewReportButton"
                        Text="<%$ AxLabel:@SYS334714 %>" onclick="ViewReportButton_Click1"  />
                </td>
            </tr>
        </table>
    </dynamics:AxSection>
</dynamics:AxMultiSection>
<p>
    &nbsp;<dynamics:AxReportViewer runat="server" ID="SalesByRegion" MenuItemName="ARCustomerStatement" />
</p>//mention hear ssrs report name
   
 
using System;
using System.Collections.Generic;
 
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using Microsoft.Dynamics.AX.Framework.Services.Client;
using Microsoft.Dynamics.Framework.BusinessConnector.Session;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;
using Microsoft.Dynamics.AX.Framework.Reporting.Shared;
using Microsoft.Dynamics.Framework.Portal.UI;
using BCProxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;
 
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using Microsoft.Dynamics.Framework.Portal.UI.WebControls;
using System.Data;
using System.Collections;
using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;
using Microsoft.Dynamics.AX.Framework.Portal.Data;
 
public partial class Pwc_ARMaster : System.Web.UI.UserControl
{
    private const string DateFromParamName = "FromDate";
    private const string DateToParamName = "ToDate";
 
    /// <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
 
 
    #region private Methods
    private void setValues()
    {
        var yr = DateTime.Today.Year;
        var mth = DateTime.Today.Month;
        var firstday = new DateTime(yr,mth,1).AddMonths(-1);
        var lastday =new DateTime(yr,mth,1).AddDays(-1);
 
        Dictionary<string, string> inputParameters = null;
        ISRSReportParameter parameter = null;
        IEnumerable<KeyValuePair<string, ISRSReportParameter>> parms = ReportParameterHelper.GetReportParameters(this.SalesByRegion.MenuItemName, inputParameters);
 
        foreach (KeyValuePair<string, ISRSReportParameter> parm in parms)
        {
            if (parm.Key == DateFromParamName)
            {
                parameter = parm.Value;
                if (parameter != null && !string.IsNullOrEmpty(parameter.DefaultValue))
                {
                    this.tbFromDate.Text = GetDateParameterValues(parameter.DefaultValue, true);
                }
                else
                {
                    this.tbFromDate.Text = firstday.ToShortDateString();
                    DateTime fromDate = DateTime.Parse(this.tbFromDate.Text);
                }
            }
            else if (parm.Key == DateToParamName)
            {
                parameter = parm.Value;
                if (parameter != null && !string.IsNullOrEmpty(parameter.DefaultValue))
                {
                    this.tbToDate.Text = GetDateParameterValues(parameter.DefaultValue, false);
                }
                else
                {
 
                    this.tbToDate.Text = lastday.ToShortDateString();
                    DateTime todate = DateTime.Parse(this.tbToDate.Text);
                }
            }
        }
    }
 
    private string GetDateParameterValues(string dateValue, bool isFromDate)
    {
        string returnDate = string.Empty;
        bool isCorrectlyParsed = false;
 
        try
        {
            DateTime dateTime = DateTime.Parse(dateValue);
            returnDate = dateTime.ToString();
            isCorrectlyParsed = true;
        }
        catch (ArgumentNullException)
        {
        }
        catch (FormatException)
        {
        }
        catch (Exception)
        {
        }
 
        if (!isCorrectlyParsed)
        {
            if (isFromDate)
            {
                returnDate = DateTime.MinValue.ToString();
            }
            else
            {
                returnDate = DateTime.MaxValue.ToString();
            }
        }
 
        return returnDate;
    }
 
    #endregion
 
    #region Events
 
    protected void Page_Load(object sender, EventArgs e)
    {
        string curUserId = AxSession.SessionInfo.UserId;
        bool accepted = bool.Parse(AxSession.AxaptaAdapter.CallStaticRecordMethod("UserAcceptanceTable", "exists", curUserId).ToString());
        if (accepted == false)
        {
            AxUrlMenuItem urlHomePage = new AxUrlMenuItem("Test");
            Response.Redirect(urlHomePage.Url.OriginalString, true);
        }
        if (!this.IsPostBack)
        {
            this.setValues();
 
            Dictionary<string, object> parms = new Dictionary<string, object>();
            this.SalesByRegion.AddParameters(parms);
        }
    }
 
    protected void ViewReportButton_Click1(object sender, EventArgs e)
    {
        Dictionary<string, object> parms = new Dictionary<string, object>();
        IAxContext axContext = AxContextHelper.FindIAxContext(this);
 
        if (tbToDate.Text == "" || tbFromDate.Text == "")
        {
            string alertScript = "<script type=\"text/javascript\"> alert('Please provide date filters to proceed.');</script>";
            ScriptManager.RegisterStartupScript(this, GetType(), "FilterAlert", alertScript, false);
            return;
        }
        DateTime fromDate = DateTime.Parse(tbFromDate.Text);
        DateTime toDate = DateTime.Parse(tbToDate.Text);
 
        if (fromDate > toDate)
        {
            string alertScript = "<script type=\"text/javascript\"> alert('From date should be less than to date.');</script>";
            ScriptManager.RegisterStartupScript(this, GetType(), "FilterAlert", alertScript, false);
            return;
        }
 
 
        try
        {
            if (!string.IsNullOrEmpty(this.tbFromDate.Text))
            {
                parms.Add(DateFromParamName, DateTime.Parse(this.tbFromDate.Text, axContext.CultureInfo).ToString("G"));
            }
            if (!string.IsNullOrEmpty(this.tbToDate.Text))
            {
                parms.Add(DateToParamName, DateTime.Parse(this.tbToDate.Text, axContext.CultureInfo).ToString("G"));
            }
            this.SalesByRegion.AddParameters(parms);
        }
        catch (FormatException)
        {
            using (BCProxy.Info infolog = new BCProxy.Info(this.AxSession.AxaptaAdapter))
            {
                infolog.add(BCProxy.Exception.Error, Labels.GetLabel("@SYS100987"));
            }
        }
        catch (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;
            }
        }
    }
 
    #endregion
 
   
}
 

No comments:

Post a Comment