How to Open Browser Form in Ax 2012

How to Open Browser Form in Ax 2012

Description:-

In this Form we will see How to Open Browser in Ax from using ActiveX.

Step 1: Now Create Form Node and Design your form like below.
  • Expand AOT Node.
  • Select Form Node and Right Click Select New Form and Name it “A_OpenBrowser”.
  • Now Drag and Drop Table in Form DataSource.
  • Select Design Node Right Click and Select New Controls and Add Grid Controls in Design Node.
Step 2: Now Right click the Design node of form and add ActiveX control.
Step 3: Select Microsoft Web Browser from ActiveX control window list.
Step 4: Now override init Method of Form Method and Code for Navigate ActiveX Control where you want to Navigate.

ActiveX.Navigate ("www.google.com");

ActiveX Control is the Name of the Control

Step 5: Now run your form and check output.
find in container OR how to use confind() in dynamics ax

find in container OR how to use confind() in dynamics ax

Description:-

In this Article we will see about container in ax. There are more functionality in container to do in ax it’s like array to store data in container and read it from container. A container can be stored in the database as a dataBasecoloumn created through AOT especially used to store images/files as a blob. For example assignment of a container to another container variable and container functions such as conIns(), conDel(), conPoke(), += etc. are actually creating a new copy of the container. Here is the demo Example of container in Ax.

confind:- Use confind to locate a sequence of items in a container.

EX:-  int conFind (container container, anytype element,... )

static void conFindExample(Args _args)
{
    container c = ["item1", "item2", "item3"];
    int i;
    int j;
    ; 
    i = conFind(c, "item2");
    j = conFind(c, "item4");
    print "Position of 'item2' in container is " + int2Str(i);
    print "Position of 'item4' in container is " + int2Str(j);
    pause;
}

Create HTML using HtmlTextWriter class in dynamics ax


Description:-

HtmlTextWriter class is used to output properly formed HTMLinto a web page.  TheHtmlTextWriter allows the developer to code attributes, style attributes, andtags etc.

The HtmlTextWriter class permits the developer to generatepage output in a non-browser specific way; that is to say, the burden ofdeveloping alternative Markup is typically removed by using theHtmlTextWriter.  The HtmlTextWriter class exposes properties, fields, andmethods that permit the developer to format HTML 4.0 compliant output. 

For example, in the job below i added static string and  an image using the HtmlTextWriter class. 

Code:-

static void HTMLTextWriter(Args _args)
{
    HTMLTextWriterhtw = new HTMLTextWriter();
    TextBuffer     txtBuffer = new TextBuffer();
    CCHTMLString   staticString;
    ;
    staticString = @'At Solugenix we know our success results from taking a long term view in all our relationships: clients, employees, industries and technologies.;   
    htw.renderBeginTag(HtmlTextWriterTag::table());   
    htw.renderBeginTag(HtmlTextWriterTag::tr());   
    htw.write(staticString);   
    htw.addAttribute(HtmlTextWriterAttribute::class_Attribute(), 'ms-vb');   
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '26px');   
    htw.addStyleAttribute(HtmlTextWriterStyle::padding_top(), '3px');   
    htw.renderBeginTag(HtmlTextWriterTag::td());   
    htw.addAttribute(HtmlTextWriterAttribute::src(), 'http://www.holidayegreetingssite.com/index_files/image3121.jpg’);//getthe image from web   
    htw.addStyleAttribute(HtmlTextWriterStyle::width(), '100');   
    htw.addStyleAttribute(HtmlTextWriterStyle::height(), '50');   
    htw.renderBeginTag(HtmlTextWriterTag::img(), true);
    htw.renderEndTag();
    //close <Td>
    htw.renderEndTag();
    //close <Table>   
    txtBuffer.setText(htw.getHtmlString());   
    txtBuffer.toFile('f:\\DynamicsAX.html'); //please provide your path to save thefile
}

How to read an Excel file in asp.net

How to read an Excel file in asp.net

Description:-

The following program illustrates how to open an existing Excel spreadsheet in C# using .NET Framework COM interop capability. Also you can see how to find Named Ranges in Excel and get the range of occupied cells (Used area) in excel sheet.

The following C# source code using Microsoft Excel 12.0 Object Library for reading an Excel file. In the previous section we saw how to import Microsoft Excel 12.0 Object Library in the CSharp project.

Source Code:-

using System;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel; 

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Application xlApp ;
            Excel.Workbook xlWorkBook ;
            Excel.Worksheet xlWorkSheet ;
            Excel.Range range ;
            string str;
            int rCnt = 0;
            int cCnt = 0;
            xlApp = new Excel.Application();
            xlWorkBook = xlApp.Workbooks.Open("csharp.net-informations.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
            range = xlWorkSheet.UsedRange;
            for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
            {
                for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
                {
                    str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
                    MessageBox.Show(str);
                }
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();

            releaseObject(xlWorkSheet);
            releaseObject(xlWorkBook);
            releaseObject(xlApp);
        }

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        } 
    }
}

How to add row in gridview dynamically in Asp.net

Description:-

This article talks about a small project that presents the idea of having a GridView which facilitates the add rows dynamically at run time. In this article, I'm going to wrap up everything into one for easy reference. The following are the main features that you will see:

  • Adding rows of TextBox, DropDownlist, Radio button and Checkbox.
  • Retain TextBox values and DropDownlist selected values across Postback.
  • Ability to remove rows.
  •     Save all values at once. 
To get started fire up Visual Studio and then add a new Web Form page. Add a GridView control to the page. Here's the GridView HTML markup:

Default.aspx:-

<div>
<asp:GridView ID="Gridview1" runat="server" ShowFooter="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical">
  <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
      <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
        <asp:TemplateField HeaderText="First Name">
          <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Last Name">
          <ItemTemplate>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Gender">
          <ItemTemplate>
            <asp:RadioButtonList ID="RBLGender" runat="server"RepeatDirection="Horizontal">
              <asp:ListItem Value="M">Male</asp:ListItem>
              <asp:ListItem Value="F">Female</asp:ListItem>
            </asp:RadioButtonList>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Status">
          <ItemTemplate>
            <asp:CheckBoxList ID="Status" runat="server"RepeatDirection="Horizontal">
              <asp:ListItem>Single</asp:ListItem>
              <asp:ListItem>Married</asp:ListItem>
            </asp:CheckBoxList>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Qualification">
          <ItemTemplate>
            <asp:DropDownList ID="drpQualification" runat="server">
              <asp:ListItem Value="G">Graduate</asp:ListItem>
              <asp:ListItem Value="P">Post Graduate</asp:ListItem>
            </asp:DropDownList>
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Grade">
          <ItemTemplate>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
          </ItemTemplate>
          <FooterStyle HorizontalAlign="Right" />
          <FooterTemplate>
            <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click" />
          </FooterTemplate>
        </asp:TemplateField>
      </Columns>
      <FooterStyle BackColor="#CCCCCC" />
      <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
      <PagerStyle BackColor="#999999" ForeColor="Black"HorizontalAlign="Center" />
      <SelectedRowStyle BackColor="#000099" Font-Bold="True"ForeColor="White" />
      <SortedAscendingCellStyle BackColor="#F1F1F1" />
      <SortedAscendingHeaderStyle BackColor="#808080" />
      <SortedDescendingCellStyle BackColor="#CAC9C9" />
      <SortedDescendingHeaderStyle BackColor="#383838" />
  </asp:GridView>
</div>

Default.aspx.cs:-

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    SetInitialRow();
  }
}

private void SetInitialRow()
{
  DataTable dt = new DataTable();
  DataRow dr = null;
  dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
  dt.Columns.Add(new DataColumn("Column1", typeof(string)));
  dt.Columns.Add(new DataColumn("Column2", typeof(string)));
  dt.Columns.Add(new DataColumn("Column3", typeof(string)));
  dt.Columns.Add(new DataColumn("Column4", typeof(string)));
  dt.Columns.Add(new DataColumn("Column5", typeof(string)));
  dt.Columns.Add(new DataColumn("Column6", typeof(string)));

  dr = dt.NewRow();
  dr["RowNumber"] = 1;
  dr["Column1"] = string.Empty;
  dr["Column2"] = string.Empty;
  dr["Column3"] = string.Empty;
  dr["Column4"] = string.Empty;
  dr["Column5"] = string.Empty;
  dr["Column6"] = string.Empty;

  dt.Rows.Add(dr);
  //dr = dt.NewRow();
  //Store the DataTable in ViewState
  ViewState["CurrentTable"] = dt;
  Gridview1.DataSource = dt;
  Gridview1.DataBind();
}

private void AddNewRowToGrid()
{
  int rowIndex = 0;
  if (ViewState["CurrentTable"] != null)
  {
    DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
    DataRow drCurrentRow = null;
    if (dtCurrentTable.Rows.Count> 0)
    {
      for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
      {
        //extract the TextBox values
        TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
        TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
        TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
        RadioButtonList box4 = (RadioButtonList)Gridview1.Rows[rowIndex].Cells[3].FindControl("RBLGender");
        DropDownList box5 = (DropDownList)Gridview1.Rows[rowIndex].Cells[5].FindControl("drpQualification");
        CheckBoxList box6 = (CheckBoxList)Gridview1.Rows[rowIndex].Cells[6].FindControl("Status");
        drCurrentRow = dtCurrentTable.NewRow();
        drCurrentRow["RowNumber"] = i + 1;
        dtCurrentTable.Rows[i - 1]["Column1"] = box1.Text;
        dtCurrentTable.Rows[i - 1]["Column2"] = box2.Text;
        dtCurrentTable.Rows[i - 1]["Column3"] = box3.Text;
        dtCurrentTable.Rows[i - 1]["Column4"] = box4.SelectedValue;
        dtCurrentTable.Rows[i - 1]["Column5"] = box5.SelectedValue;
        dtCurrentTable.Rows[i - 1]["Column6"] = box6.SelectedValue;
        rowIndex++;
      }
      dtCurrentTable.Rows.Add(drCurrentRow);
      ViewState["CurrentTable"] = dtCurrentTable;
      Gridview1.DataSource = dtCurrentTable;
      Gridview1.DataBind();
    }
  }
  else
  {
    Response.Write("ViewState is null");
  }
  //Set Previous Data on Postbacks
  SetPreviousData();
}

private void SetPreviousData()
{
  int rowIndex = 0;
  if (ViewState["CurrentTable"] != null)
  {
    DataTable dt = (DataTable)ViewState["CurrentTable"];
    if (dt.Rows.Count> 0)
    {
      for (int i = 0; i <dt.Rows.Count; i++)
      {
        TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
        TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
        TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
        RadioButtonList box4 = (RadioButtonList)Gridview1.Rows[rowIndex].Cells[4].FindControl("RBLGender");
        DropDownList box5 = (DropDownList)Gridview1.Rows[rowIndex].Cells[5].FindControl("drpQualification");
        CheckBoxList box6 = (CheckBoxList)Gridview1.Rows[rowIndex].Cells[6].FindControl("Status");
        box1.Text = dt.Rows[i]["Column1"].ToString();
        box2.Text = dt.Rows[i]["Column2"].ToString();
        box3.Text = dt.Rows[i]["Column3"].ToString();
        box4.SelectedValue = dt.Rows[i]["Column4"].ToString();
        box5.SelectedValue = dt.Rows[i]["Column5"].ToString();
        box6.SelectedValue = dt.Rows[i]["Column6"].ToString();
        rowIndex++;
      }
    }
  }
}

protected void ButtonAdd_Click(object sender, EventArgs e)
{
  AddNewRowToGrid();
}

How to confirm sales order through code in Ax 2012


Description:-

In this post I have create code for sales order confirmation, here we will see how to confirm sales order through code in dynamics ax 2012.This code is straight forward and simple. It has been very useful to me, because we made a lot of changes to the Sales Life cycle of Axapta.
Copy and paste below code and fill you sales order number which you want to confirm.

static void SalesOrderConfirmation(Args _args)
{
    SalesTable salesTable;
    SalesFormLetter salesFormLetter;      
    SalesTable = SalesTable::find(SalesOrderNumber');
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
    salesFormLetter.update(salesTable);
}

Here I have also written code for sales order confirmation through class, you can create method in class and confirm sales order, by passing the sales order number in this method you can confirm sales order.

public boolean confirmSalesOrder(SalesId _salesId)
{
    SalesFormletter SalesFormletter;
    SalesTable SalesTable;
    ;
    SalesFormletter = SalesFormletter::construct(DocumentStatus::Confirmation,true);
    SalesTable.clear();
    SalesTable = SalesTable::find(_salesId);
    SalesFormletter.update(SalesTable,systemDateGet(),SalesUpdate::All,AccountOrder::None,false,false);
}

What I did was create a Class that contained different methods for taking sales orders through the sales life cycle.