Finding number of records of the tables in more simple way in Dynamics Ax

Description:-

A quick post about a small option for your development use which may come handy.
How many times you have written a job to find the number of records for a specific table by using count function?

But, actually to know the number of records, you don’t have to code anything. Microsoft has already taken care about it.

You just have to open your developer workspace and go to "Tools" >> "Number of records". Once you click on it, a form will open which will show all the list of tables with “number of records” in the adjacent fields.

Note: The form will show number of records with respect to the present company.


Get length of container in dynamics ax

Get length of container 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.

conlen :- Use conlen to find out how many items there are in a container.

EX:- int conLen(container container)

static void conLenExample(Args _arg)
{
    container c;
    int i;
    ;
 
    c = conins(["item1", "item2"], 1); 
    for (i = 1 ; i <= conLen(c) ; i++)
    {
        print conPeek(c, i);
     }
    pause;
}

How to Convert HTML to Plain Text in asp.net


Description:-

In this example we explain that how to convert Text to HTML in asp.net with c#. or how to convert HTML to Formatted Plain Text in asp.net.

Sometimes we needs to display text from a file or database that contain a HTML text or string. This text may be entered by the user that has not been formatted for HTML. In these cases, the text must be converted.

.Net already provide the HttpUtility.HtmlEncode () method to encode special characters so that they will appear as expected in a web browser. But problem is that , this method won't do anything with line breaks and paragraphs.

So When your application needs to convert or display unformatted text to Formatted Plain Text that contains multiple lines and paragraphs on a Web page, a little more work or code is required that we describe bellows.

Default.aspx:-

<div>
  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>

Default.aspx.cs:-


protected void Page_Load(object sender, EventArgs e)
{
  Label1.Text = StripHTML("<html><head></head><p>Hi how are you </p><h1> this is heading </h1></html>");
}

private string StripHTML(string source)
{
  try
  {
    string result;
    // Remove HTML Development formatting
    // Replace line breaks with space
    // because browsers inserts space
    result = source.Replace("\r", " ");
    // Replace line breaks with space
    // because browsers inserts space
    result = result.Replace("\n", " ");
    // Remove step-formatting
    result = result.Replace("\t", string.Empty);
    // Remove repeating spaces because browsers ignore them
    result = System.Text.RegularExpressions.Regex.Replace(result, @"( )+", " ");
    // Remove the header (prepare first by clearing attributes)
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*head([^>])*>", "<head>",     System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"(<( )*(/)( )*head( )*>)", "</head>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, "(<head>).*(</head>)",     string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // remove all scripts (prepare first by clearing attributes)
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*script([^>])*>", "<script>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"(<( )*(/)( )*script( )*>)", "</script>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    //result = System.Text.RegularExpressions.Regex.Replace(result,
    // @"(<script>)([^(<script>\.</script>)])*(</script>)",
    // string.Empty,
    // System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"(<script>).*(</script>)", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // remove all styles (prepare first by clearing attributes)
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*style([^>])*>", "<style>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"(<( )*(/)( )*style( )*>)", "</style>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, "(<style>).*(</style>)", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // insert tabs in spaces of <td> tags
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*td([^>])*>", "\t",     System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // insert line breaks in places of <BR> and <LI> tags
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*br( )*>", "\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*li( )*>", "\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // insert line paragraphs (double line breaks) in place
    // if <P>, <DIV> and <TR> tags
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*div([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*tr([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<( )*p([^>])*>", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Remove remaining tags like <a>, links, images,
    // comments etc - anything that's enclosed inside <>
    result = System.Text.RegularExpressions.Regex.Replace(result, @"<[^>]*>", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // replace special characters:
    result = System.Text.RegularExpressions.Regex.Replace(result, @" ", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&bull;", " * ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&lsaquo;", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&rsaquo;", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&trade;", "(tm)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&frasl;", "/", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&lt;", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&gt;", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&copy;", "(c)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&reg;", "(r)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Remove all others. More can be added, see
    // http://hotwired.lycos.com/webmonkey/reference/special_characters/
    result = System.Text.RegularExpressions.Regex.Replace(result, @"&(.{2,6});", string.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // for testing
    //System.Text.RegularExpressions.Regex.Replace(result,
    // this.txtRegex.Text,string.Empty,
    // System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // make line breaking consistent
    result = result.Replace("\n", "\r");
    // Remove extra line breaks and tabs:
    // replace over 2 breaks with 2 and over 4 tabs with 4.
    // Prepare first to remove any whitespaces in between
    // the escaped characters and remove redundant tabs in between line breaks
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)( )+(\r)", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\t)( )+(\t)", "\t\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\t)( )+(\r)", "\t\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)( )+(\t)", "\r\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Remove redundant tabs
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)(\t)+(\r)", "\r\r", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Remove multiple tabs following a line break with just one tab
    result = System.Text.RegularExpressions.Regex.Replace(result, "(\r)(\t)+", "\r\t", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    // Initial replacement target string for line breaks
    string breaks = "\r\r\r";
    // Initial replacement target string for tabs
    string tabs = "\t\t\t\t\t";
    for (int index = 0; index <result.Length; index++)
    {
      result = result.Replace(breaks, "\r\r");
      result = result.Replace(tabs, "\t\t\t\t");
      breaks = breaks + "\r";
      tabs = tabs + "\t";
    }
    // That's it.
    return result;
  }
  catch
  {
    return source;
  }
}

How to Display the Form With Different Colors For a Particular Control Value or Rows Color in Ax 2012

Description:- 
Record color coding can be easily achieved by overriding the displayOption method on the form data source and writing the certain color code statements based on the required conditions in AX.

It is not possible with the list page as you cannot override the displayOption method on the query data source used to show data on list page grid, neither this can be done in the ListPageInteraction class.

We can use an alternative to fulfil our requirement, in which we can set an indicator on the first column of the grid of the list page.This indicator can be the colourful small icon images. Which can be returned by display method of that particular table based on the conditions.

You need in sometimes to colorize specific rows with different color to do anything in your business rule.Sometimes,during development and test we often switch between different companies in our installation. To not mistaken us, so we always make changes in the correct one, we made this small change in the code. With different background-colours.

Here’s some tips on how to color Grid Cells / rows in DAX. I’ve used the Custom table form as an example. The code must be placed in the displayOption () method of the DataSource.

Step 1: Create Table Name it “A_PurchaseOrder”. And Insert Filed in Table.
     1. Expand AOT Node.
     2. Open Data Dictionary Node.
     3. Select Tables and right Click Select New Table.
     4. Name it “A_PurchaseOrder”.
     5. Now open table in Insert Some Data in A_PurchaseOrdertable.

Step 2: Now Create Form and Name it “A_DisplayOptionForm”. And Add List box and StringEdit Controls in Design Node.
     1. Expand AOT Node.
     2. Select Form Node and Right Click Select New Form and Name it “A_DisplayOptionForm”.
     3. Now Drag and Drop Table in Form DataSource.
     4. Design your Form like below.


Step 3: Now set declare variable backcolor in ClassDeclaration.

public class FormRun extends ObjectRun
{
   int backColor;
}

Now Generate Form init Method and Set backcolor for when form open first time.

public void init()
{
    super();
    backColor = WinAPI::RGB2int( 0,255,0 );
}

Now generate button click method and code for selecting color and clear selected previous color of rows/cells color in form grid.

void clicked()
{
    Common  common;
    container c;
    ;
    c = WinAPI::chooseColor(this.hWnd(),0,0,0,NULL);
    if (conlen(c))
    {
        backColor = WinAPI::RGB2int( conpeek(c,1), conpeek(c,2), conpeek(c,3) );
        // Clear the display options for the once which allready has been set.
        for (common = A_PurchaseOrder_ds.getFirst(); common; common = A_PurchaseOrder_ds.getNext())
        {
            A_PurchaseOrder_ds.clearDisplayOption( common );
        }
        A_PurchaseOrder_ds.refreshEx(-1);
    }
    super();
}

Here we will use Conpeek for selecting color RGB value and store in Container for setting in cells/rows. Using the clearDisplayOption () method of DataSource we will clear Previous selected color.

Now override DataSource DisplayOption method and code here for setting color for rows/cells. First of all change in method where Common _record to your datasourcename _objectname. For getting data from DataSource when first time form open for selecting record from DataSource.
Otherwise we cannot set color on each rows/cells in grid.

Now whatever you want to put condition you can put in displayOption method for changing rows/cells color. Here i have set many Condition for Changing Color using if, if else if, Switch Case through.

public void displayOption(A_PurchaseOrder _PO, FormRowDisplayOption _options)
{
    //Using if elseif Condition
    //if (_PO.Purchase_Date<today()-30 )
    //{
        //_options.backColor(backColor);
        //_options.affectedElementsByControl(A_PurchaseOrder_Purchase_Date.id());
    //}

    //Using if elseif Condition
    //if (_PO.Purchase_Amount<3000 )
    //{
        //_options.backColor(backColor);
        //_options.affectedElementsByControl(A_PurchaseOrder_Purchase_Amount.id());
    //}
    //else if (_PO.Purchase_Amount>5000 )
    //{
        //_options.backColor(8421631);
        //_options.affectedElementsByControl(A_PurchaseOrder_Purchase_Amount.id());
    //}

    //Using SwitchCase Condition   PO_Status is BasEnum Value
    Switch(_PO.Status)
    {
        Case PO_Status::Close:
        _options.backColor(backColor); //Light Yellow
        _options.affectedElementsByControl(A_PurchaseOrder_Status.id());
        Break;
    }

    //set legalentity for color
    //Change property of your DataSource CrossCompanyAutoQuery to Yes
    //for Getting Other Company Data in Current Company
    //if (_PO.dataAreaId =="cec")
    //{
        //_options.backColor(backColor);
        //_options.affectedElementsByControl(A_PurchaseOrder_dataAreaId.id());
    //}
    super(_PO, _options);
}

For changing rows color I have used.

_options.backColor(backColor);

For changing text color you can use.

_options.textColor(12582912); //Blue

If you want to Change particular cell color then you have to set auto declare property to Yes for that control. For changing cell color.

_options.affectedElementsByControl(A_PurchaseOrder_Purchase_Amount.id());

If you want to Change particular cell color then you have to set auto declare property to Yes for that control. For changing particular cells text or cell color you can use.

_options.backColor(backColor);

_options.affectedElementsByControl(A_PurchaseOrder_Purchase_Date.id());

Find Nth Highest Salary of Employee from sql server

Find Nth Highest Salary of Employee from sql server

Description:-

In this example we explain that how to find nth highest salary of the employee in Sql server table. This is the most important question that is asked by interviewer in any interview that is write query for find second highest salary of employee in Sql table or find third highest salary of employee in Sql server table.

We all listen that How to find third highest or second maximum salary of an Employee is one of the most frequently asked question in interview.
There are many ways to find nth highest salaries of an employee are as below:
--The following solution is for getting 3th highest salary from Employee table ,

SELECTTOP 1 salary
FROM (
SELECTDISTINCTTOP 3 salary
FROM employee
ORDERBY salary DESC) a
ORDERBY salary

--if you want to find 2 highest salary then put 2 instead of 6 if you want to find 4th highest salary then put 4 instead of 6 and so far.
--put the value in place of n that you want to find

SELECTTOP 1 salary
FROM (
SELECTDISTINCTTOP n salary
FROM employee
ORDERBY salary DESC) a
ORDERBY salary

Alert user using net-send through code in dynamics ax OR Sending messages to the users in network using net-send in dynamics ax


Description:-

Microsoft Windows offers a simple method to send messages to other users or computers on the network – simple Win-popup Messages or Net Send Messages ( in Windows 95, Windows 98, Windows Me, Windows NT, Windows2000, Windows XP and Windows 2003 ).

Prerequisite: Start Messenger service from Start >> Programs >> Administrative tools >> services >> messenger. Here is the job which will send messages to the users/computers on the network.

static void netSend(Args _args)
{       
    COM      netSendCom;
    InteropPermission   permission = newInteropPermission(InteropKind::ComInterop);
    int     output;
    str computerName   =  Winapi::getComputerName();
    str message   = "Hello.. I am alerting from Dynamics AX";
    // Receiving end should start messenger service and alerter service from services.msc
    permission.assert();
    try
    {
        netSendCom = new COM("WScript.Shell");
        output = netSendCom.Run(strFmt("net %1 %2", computerName, message),0,true);
    }
    catch (Exception::Error)
    {
        CodeAccessPermission::revertAssert();
        throw Exception::Error;
    }   
    if (output != 0)
    {
        warning(strfmt("Net send Failed", computerName));
        warning("Check messenger service–Started");
    }   
    CodeAccessPermission::revertAssert();
}

fin XmlNode from Xml File in Dynamics ax

fin XmlNode from Xml File in Dynamics ax

Description:-

find XmlNode from Xml File in Dynamics ax Here we will find xml node from XmlDocument. If you want to find single XmlNode that you can find it by using selectSingleNode using XmlDocument class. Here is the example of finding XmlNode from xml file.

Code:-

static void XMLNodeFind(Args _args)
{
    str xml;
    XmlDocument xmlDoc;
    XmlNode xmlNode;
    ;
    xml = @'<ParentNode>
    <Node>
    <Name1>2003</Name1>
    <Name2>20030630</Name2>
    <Name3>20140225</Name3>
    <Name4>46944000</Name4>
    <Name5>94750099</Name5>
    </Node>
    </ParentNode>';
    xmlDoc = XmlDocument::newXml(xml);
    xmlNode = xmlDoc.selectSingleNode('//Name1');
    info(xmlNode.innerText());
}

How to Format a String as a Number With Padding in Asp.Net

Description:-

Here we will see how to Format string as a number with padding different Character, Number and Sign etc.

Step 1: Drag Labels in your Browser.

<div>
   <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label4" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label5" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label6" runat="server" Text=""></asp:Label>
   <br />
   <asp:Label ID="Label7" runat="server" Text=""></asp:Label>
</div>

Step 2: Now go to Code behind and code for how to set padding in String. Here I have set different Example with padding in String.

protected void Page_Load(object sender, EventArgs e)
{
    //this line create an int variable.
    int number = 123;

    Label1.Text = "formatted string";

    int length = number.ToString().Length + 1;
    string dValue = "D" + length.ToString();

    int length2 = length + 5;

    Label1.Text += "Number: " + number;
    //format string using ToString method
    Label2.Text += "number padding with zero: " + number.ToString("D4");
    //format string using string.format method.
    Label3.Text += "number padding with zero: " + string.Format("{0:D4}", number);

    //dynamically determine number length and format string.
    Label4.Text += "number dynamic padding with zero: " + number.ToString(dValue);

    //another technique to format string using padleft method.
    Label5.Text += "number padding with zero length 10: " + number.ToString().PadLeft(length2, '0');
    Label6.Text += "number padding with plus sign:"+ number.ToString().PadLeft(length2, '+');
    Label7.Text += "number padding with ‘A’ character: " + number.ToString().PadLeft(length2, 'A');
}

Check in your browser and see output.

Fixing Report Viewer control toolbar in Google Chrome

Fixing Report Viewer control toolbar in Google Chrome

Description:-

In this example we explain that how to display Report Viewer toolbar in a single row in Google Chrome browser and Firefox browser. By default it displays toolbar in a multiple rows in Chrome browser.

So here we explain SQL Server Reporting Services Report Viewer control has a toolbar that is not displayed correctly in Google Chrome browser and Firefox because On Google Chrome, each button in the toolbar takes a separate line so how to set toolbar of Report Viewer from multiple rows to single row in Chrome and Firefox browser.

So here we convert code into Browser capability code so in every browser the report viewer toolbar are display in single row with same layout.

I was faced that type of problem and finally I got the solution

As we know that In Chrome browser, Report Viewer (8 & 9) toolbar elements are displayed in multiple rows as shown below.

After implementing below code the report viewer toolbar will be display in single line like

Code:-

<script type="text/javascript">
$(document).ready(function () { 
if ($.browser.webkit) { 
$(".ms-report-viewer-control :nth-child(3) table").each(function (i, item) { 
$(item).css('display', 'inline-block'); 
}); 
} 
}); 
</script>

How to CRUD in DetailsView in Asp.Net

Description:-
In this Example we will see how to Insert, Read, Update and Delete Record from Database using Details view in dot net. Here I have taken Simple Example for CRUD in Details view.

Design your Details view using Template Filed, Footer Controls, Columns and Headers and give some Style for Design. In My previous Example I had Explain all of thing how to Create Column in Grid view Sam Here We will Create Fields in Details view Item Template, Edit Templates.

In your Webpage Drag Details View and What I said like that Design your Details view in your Webpage.

<div>
   <asp:DetailsView ID="DetailsViewExample" AllowPaging="True" AutoGenerateRows="False"
      runat="server" Height="50px" CssClass="DetailsViewClass" CellPadding="3" OnPageIndexChanging="DetailsViewExample_PageIndexChanging"
      OnItemCommand="DetailsViewExample_ItemCommand1" OnItemUpdating="DetailsViewExample_ItemUpdating"
      OnModeChanging="DetailsViewExample_ModeChanging" OnItemInserting="DetailsViewExample_ItemInserting"
      Width="270px" OnItemDeleting="DetailsViewExample_ItemDeleting" 
      BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
      GridLines="Horizontal">
      <Fields>
         <asp:TemplateField HeaderText="First Name">
            <ItemTemplate>
               <asp:Label ID="lblID" Text='<%# Eval("EmpID") %>' Visible="false" runat="server"></asp:Label>
               <asp:Label ID="lblFirstName" Text='<%# Eval("FirstName") %>' runat="server"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:Label ID="lblIDEdit" Text='<%# Eval("EmpID") %>' Visible="false" runat="server"></asp:Label>
               <asp:TextBox ID="txtFirstname" Text='<%# Eval("FirstName") %>' runat="server" CssClass="textbox"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Last Name">
            <ItemTemplate>
               <asp:Label ID="lblLastName" Text='<%# Eval("LastName") %>' runat="server"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtLastName" Text='<%# Eval("LastName") %>' runat="server" CssClass="textbox"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Salary">
            <ItemTemplate>
               <asp:Label ID="lbldob" Text='<%# Eval("Salary") %>' runat="server"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtCity" Text='<%# Eval("Salary") %>' runat="server" CssClass="textbox"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Address">
            <ItemTemplate>
               <asp:Label ID="lblAddress" Text='<%# Eval("Address") %>' runat="server"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtAddress" Text='<%# Eval("Address") %>' runat="server" CssClass="textbox"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Location">
            <ItemTemplate>
               <asp:Label ID="lblLocation" Text='<%# Eval("Location") %>' runat="server"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtLocation" Text='<%# Eval("Location") %>' runat="server" CssClass="textbox"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:CommandField Visible="true" ShowInsertButton="true" ShowCancelButton="true"
            ShowDeleteButton="true" ShowEditButton="true" />
      </Fields>
      <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
      <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
      <PagerStyle CssClass="Foter" BackColor="#E7E7FF" ForeColor="#4A3C8C" 
         HorizontalAlign="Right" />
      <AlternatingRowStyle BackColor="#F7F7F7" />
      <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
      <FieldHeaderStyle Width="80px" CssClass="Header" />
      <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
   </asp:DetailsView>
</div>

Now In your Details view generate item Inserting, deleting, Updating event so we can CRUD in Details view. For Paging we will use PageIndexChanging in Details view. So we will maintain record and read at a time one record in details view.

Now go to Code behind and code for inserting, Updating, Deleting Item in Details view from database.

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

private void bindDetailtView()
{
    try
    {
        DataSet Ds = GetDataSet("Select * from Employee");
        DetailsViewExample.DataSource = Ds;
        DetailsViewExample.DataBind();
    }
    catch (Exception ex) { throw ex; }
}

private DataSet GetDataSet(string Query)
{
    DataSet Ds = new DataSet();
    try
    {
        string strCon = @"ConnectionString";
        SqlConnection Con = new SqlConnection(strCon);
        SqlDataAdapter Da = new SqlDataAdapter(Query, Con);
        Da.Fill(Ds);
    }
    catch (Exception) { }
    return Ds;
}

private void ExecuteQuery(string Query)
{
    try
    {
        string strCon = @" ConnectionString ";
        SqlConnection Con = new SqlConnection(strCon);
        Con.Open();
        SqlCommand cmd = new SqlCommand(Query, Con);
        cmd.ExecuteNonQuery();
        Con.Close();
    }
    catch (Exception ex) { throw ex; }
}

protected void DetailsViewExample_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
    DetailsViewExample.PageIndex = e.NewPageIndex;
    bindDetailtView();
}

protected void DetailsViewExample_ItemCommand1(object sender, DetailsViewCommandEventArgs e)
{
    switch (e.CommandName.ToString())
    {
        case "Edit":
            DetailsViewExample.ChangeMode(DetailsViewMode.Edit);
            bindDetailtView();
            break;
        case "Cancel":
            DetailsViewExample.ChangeMode(DetailsViewMode.ReadOnly);
            bindDetailtView();
            break;
        case "New":
            DetailsViewExample.ChangeMode(DetailsViewMode.Insert);
            bindDetailtView();
            break;
    }
}

protected void DetailsViewExample_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
    TextBox txtFirstname = (TextBox)DetailsViewExample.FindControl("txtFirstname");
    TextBox txtLastName = (TextBox)DetailsViewExample.FindControl("txtLastName");
    TextBox txtCity = (TextBox)DetailsViewExample.FindControl("txtCity");
    TextBox txtAddress = (TextBox)DetailsViewExample.FindControl("txtAddress");
    TextBox txtPinNo = (TextBox)DetailsViewExample.FindControl("txtLocation");
    Label lblIDEdit = (Label)DetailsViewExample.FindControl("lblIDEdit");

    string Query = "Update Employee Set FirstName='" + txtFirstname.Text + "' ,LastName ='" + txtLastName.Text + "' ,Salary ='" + txtCity.Text + "',Address='" + txtAddress.Text + "',Location='" + txtLocation.Text + "' where EmpID =" + lblIDEdit.Text;
    ExecuteQuery(Query);
    DetailsViewExample.ChangeMode(DetailsViewMode.ReadOnly);
    bindDetailtView();
}

protected void DetailsViewExample_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
    TextBox txtFirstname = (TextBox)DetailsViewExample.FindControl("txtFirstname");
    TextBox txtLastName = (TextBox)DetailsViewExample.FindControl("txtLastName");
    TextBox txtCity = (TextBox)DetailsViewExample.FindControl("txtCity");
    TextBox txtAddress = (TextBox)DetailsViewExample.FindControl("txtAddress");
    TextBox txtPinNo = (TextBox)DetailsViewExample.FindControl("txtPinNo");
    string Query = "Insert into Employee ([FirstName] ,[LastName] ,[Salary] ,[Address] ,[Location]) values ('" + txtFirstname.Text + "' ,'" + txtLastName.Text + "' ,'" + txtCity.Text + "','" + txtAddress.Text + "','" + txtLocation.Text + "')";
    ExecuteQuery(Query);
    DetailsViewExample.ChangeMode(DetailsViewMode.ReadOnly);
    bindDetailtView();
}

protected void DetailsViewExample_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
{
    Label lblID = (Label)DetailsViewExample.FindControl("lblID");
    string Query = "Delete from Employee where EmpID =" + lblID.Text;
    ExecuteQuery(Query);
    bindDetailtView();
}

Now run your Webpage and Insert Item from Details view. Edit items and Update with Different name or else delete item.
Folder Creation and Deletion using DirectoryInfo  in Asp.Net

Folder Creation and Deletion using DirectoryInfo in Asp.Net

Description:-

Is the example to show you how to crate folder in current directory using DirectoryInfo class in dot net.

if (Directory.Exists(String.Format(@"{0}\Temp\", Environment.CurrentDirectory)))
{
  System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(String.Format(@"{0}\Temp\", Environment.CurrentDirectory));
  foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
  {
    dir.Delete(true);
  }
  System.GC.Collect();
  System.GC.WaitForPendingFinalizers();
  Directory.Delete(String.Format(@"{0}\Temp\", Environment.CurrentDirectory), true);
}

To Create Directory in Current Directory using Directory Class.

Directory.CreateDirectory(string.Format(@"{0}\Temp", Environment.CurrentDirectory));

How to Restart AOT in Dynamics Ax



Description:-

In this article we will see How to Restart AOT (Application Object Tree) using Job. Here we will Create Job and Restart AOT through Job.

Code:-

static void RestartAOT(Args _args)
{
    // update
    //—————————————-
    SysFlushSystemSequence::doFlush();
        SysEvent::fireEvent(SysEventType::FlushSystemSequence);
    info("@SYS73844");

    //Update dictionnary
    //—————————————-
    SysFlushDictionary::doFlush();
        SysEvent::fireEvent(SysEventType::FlushDictionary);
    info("@SYS68566");

    //Update log and compagnyinfos
    //—————————————-
    SysFlushDatabaseLogSetup::doFlush(curext());
            SysEvent::fireEvent(SysEventType::FlushDatabaseLogSetup,0,[curext()]);

    //—————————————-
    SysFlushData::doFlush();
    SysEvent::fireEvent(SysEventType::FlushData);
    info("@SYS98783");

    //Update AOD
    //—————————————-
    SysFlushAOD::doFlush(); //SysFlushAOD::clearMetadataCaches();
    SysEvent::fireEvent(SysEventType::FlushAOD);
    info("@SYS68564");
}