Get client browser details in asp.net

Get client browser details in asp.net

Description:-

Here is one more example to read client browser detail using HttpContext.Current.Request.Browser. Here I have read Client browser detail through code and display information on webpage to see which client come from which browser or else we can store client browser information in our database to keep in touch that’s coming more than one time. Here is the demo example to read browser detail in dot net.

Default.aspx.cs:-

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    Response.Write(GetBrowserDetails());
  }
}

public static string GetBrowserDetails()
{
  string browserDetails = string.Empty;
  System.Web.HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
  browserDetails =
    "Name = " + browser.Browser + ",<br/>"
    + "Type = " + browser.Type + ",<br/>"
    + "Version = " + browser.Version + ",<br/>"
    + "Major Version = " + browser.MajorVersion + ",<br/>"
    + "Minor Version = " + browser.MinorVersion + ",<br/>"
    + "Platform = " + browser.Platform + ",<br/>"
    + "Is Beta = " + browser.Beta + ",<br/>"
    + "Is Crawler = " + browser.Crawler + ",<br/>"
    + "Is AOL = " + browser.AOL + ",<br/>"
    + "Is Win16 = " + browser.Win16 + ",<br/>"
    + "Is Win32 = " + browser.Win32 + ",<br/>"
    + "Supports Frames = " + browser.Frames + ",<br/>"
    + "Supports Tables = " + browser.Tables + ",<br/>"
    + "Supports Cookies = " + browser.Cookies + ",<br/>"
    + "Supports VBScript = " + browser.VBScript + ",<br/>"
    + "Supports JavaScript = " + "," + browser.EcmaScriptVersion.ToString() + ",<br/>"
    + "Supports Java Applets = " + browser.JavaApplets + ",<br/>"
    + "Supports ActiveX Controls = " + browser.ActiveXControls + ",<br/>"
    + "Supports JavaScript Version = " + browser["JavaScriptVersion"];
  return browserDetails;
}

Get Image coordinates in Asp.Net

Get Image coordinates in Asp.Net

Description:-

In this article we will see about image coordinates. You can get image co-ordinates using the position of you mouse pointer. To read it you have to get the x and y value on your mouse pointer and you can after get the co-ordinates of image. In actual format formats is nothing but the mouse pointer position to read it you have to X and Y value from you page. So you can directly read it.

Default.aspx:-

<form name="pointform" method="post">
<div style="position: absolute; left: 20px; top: 20px;"> Get Image coordinates</div>
<div style="clear: both; height: 5px;"> </div>
<div id="pointer_div" onclick="point_it(event)" style="background-image: url('water.png');
background-repeat: no-repeat; width: 900px; height: 262px;">
</div>
<div style="position: absolute; left: 20px; top: 280px;"> You pointed on x =
  <input type="text" name="form_x" size="4"/>- y =
  <input type="text" name="form_y" size="4"/>
</div>
</form>

JavaScript Code:-

<script language="JavaScript"type="text/javascript">
function point_it(event) {
  pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("pointer_div").offsetLeft;
  pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("pointer_div").offsetTop;
  document.pointform.form_x.value = pos_x;
  document.pointform.form_y.value = pos_y;
}
</script>

Now you can run your application and get X and Y Co-ordinates of your Image.
How to create edt lookup in dialogbox in dynamics ax

How to create edt lookup in dialogbox in dynamics ax

Description:-

Here we will see how to create EDT Lookup in Dialog. Here I have created job for display lookup in dialog when I run this job that dialog will create and inside  my lookup will be there from EDT.

Code:-

static void DialogSampleCode(Args _args)
{
    Dialog      dialog;
    DialogField field;
    ;
    dialog = new Dialog("My Dialog");
    dialog.addText("Select your favorite customer:");
    field = dialog.addField((extendedTypeStr(CustAccount)));
 
    dialog.run();
    if (dialog.closedOk())
    {
        info(field.value());
    }
} 

Display gridview row as coloumn in asp.net

Display gridview row as coloumn in asp.net

Description:-

In this example we explain that how to convert GridView columns to row or convert GridView columns to GridView row in asp.net. Sometime in project there are many clients that required the GridView data should be displayed in reverse format means GridView columns display as GridView row and GridView rows should be displayed as GridView columns.

Default.aspx.cs:-

Protected void Page_Load(object sender, EventArgs e)
{
  if (!Page.IsPostBack)
  {
    PopulateGrid();
  }
}

protectedvoidPopulateGrid()
{
  DataTabledt = newDataTable();
  dt.Columns.Add("Emp_Id", typeof(Int32));
  dt.Columns.Add("Emp_Name", typeof(string));
  dt.Columns.Add("Designation", typeof(string));
  dt.Columns.Add("Email-ID", typeof(string));
  dt.Columns.Add("MobileNo", typeof(Int64));
  DataRowdtrow = dt.NewRow();
  // Create First Row 
  dtrow["Emp_Id"] = 1;
  dtrow["Emp_Name"] = "Umesh";
  dtrow["Designation"] = "MCA";
  dtrow["Email-ID"] = "Umesh@gmail.com";
  dtrow["MobileNo"] = 9485768594;
  dt.Rows.Add(dtrow);
  dtrow = dt.NewRow();
  // Create Second Row 
  dtrow["Emp_Id"] = 2;
  dtrow["Emp_Name"] = "Chirag";
  dtrow["Designation"] = "ITI";
  dtrow["Email-ID"] = "Chirag@gmail.com";
  dtrow["MobileNo"] = 2345987456;
  dt.Rows.Add(dtrow);
  dtrow = dt.NewRow();
  // Create third Row 
  dtrow["Emp_Id"] = 3;
  dtrow["Emp_Name"] = "Kirit";
  dtrow["Designation"] = "MCA";
  dtrow["Email-ID"] = "Kirit@gmail.com";
  dtrow["MobileNo"] = 2038945456;
  dt.Rows.Add(dtrow);
  dtrow = dt.NewRow();
  // Create Fourth Row 
  dtrow["Emp_Id"] = 4;
  dtrow["Emp_Name"] = "Harpal";
  dtrow["Designation"] = "PGDCA";
  dtrow["Email-ID"] = "Harpal@gmail.com";
  dtrow["MobileNo"] = 2345898764;
  dt.Rows.Add(dtrow);
  gv_Defaultgrid.DataSource = dt;
  gv_Defaultgrid.DataBind();
  gv_convertedgrid.DataSource = ConvertColumnsAsRows(dt);
  gv_convertedgrid.DataBind();
  gv_convertedgrid.HeaderRow.Visible = false;
}

Protected void gv_convertedgrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    e.Row.Cells[0].CssClass = "gridcss";
  }
}

// This function is used to convert columns to rows 
Public DataTable ConvertColumnsAsRows(DataTabledt)
{
  DataTabledt_temp = newDataTable();
  //Convert all the rows to columns 
  for (int i = 0; i <= dt.Rows.Count; i++)
  {
    dt_temp.Columns.Add(Convert.ToString(i));
  }
  DataRowdr;
  // Convert All the Columns to Rows 
  for (int j = 0; j <dt.Columns.Count; j++)
  {
    dr = dt_temp.NewRow();
    dr[0] = dt.Columns[j].ToString();
    for (int k = 1; k <= dt.Rows.Count; k++)
    dr[k] = dt.Rows[k - 1][j];
    dt_temp.Rows.Add(dr);
  }
  returndt_temp;
}

How to Generate Barcode for String Value in Ax 2012

Here is the job for Generate Barcode for String value in Ax 2012. 

static void Barcode(Args _args)
{
    str Number;
    BarcodeCode128 Mybarcode;
    Number = "1254879856";
    Mybarcode= BarcodeCode128::construct();
    Mybarcode.string(true,Number );
    Mybarcode.encode();
    info(strFmt("%1",Mybarcode.barcodeStr()));
    info(strFmt("%1",Mybarcode.barcodeStrHR()));
}

Output:
How to get active Dimension for Item in Ax 2012

How to get active Dimension for Item in Ax 2012

Here I have Created job for get active dimension for item in Ax 2012.

static void ActiveDimension(Args _args)
{
    InventTable     inventTable;
    InventDimParm   inventDimParm;
    ;
    inventTable   = InventTable::find('ItemId');
    inventDimParm =  InventDimParm::activeDimFlag(InventDimGroupSetup::newInventTable(inventTable));
    if(inventDimParm.InventBatchIdFlag)
    {
        info("BatchIdFlag Enabled");
    }
    if(inventDimParm.WMSPalletIdFlag)
    {
        info("Pallet Enabled");
    }
    if(inventDimParm.ConfigIdFlag)
    {
        info("Configuration Enabled");
    }
    if(inventDimParm.InventColorIdFlag)
    {
        info("Color Enabled");
    }
    if(inventDimParm.InventSerialIdFlag)
    {
        info("Serial Id Enabled");
    }
    if(inventDimParm.InventStyleIdFlag)
    {
        info("Style Enabled");
    }
    if(inventDimParm.InventSizeIdFlag)
    {
        info("Size Enabled");
    }
}
Perform a PackingSlip Update through code in ax 2012

Perform a PackingSlip Update through code in ax 2012

Description:-

Here I have given salesid an perform a packslip update on it.

public packSlipUpSO(SalesId _salesid)
{
   SalesFormLetter SalesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip,true);
   SalesTable SalesTable = SalesTable::Find(_salesId);
   ; 

   SalesFormLetter.update(SalesTable,systemDateGet(), SalesUpdate::ALL, AccountOrder::None, false, false);
}

This is in short form, because that is what someone left comments about on the last post, so I thought I would put this in short form just for them! Anyway, if you notice the 'SalesUpdate::ALL'. This enum tells the update posting that take the entire sales order and mark it has being packing slip updated. If you only wanted what was set as delivered now from within the sales line, then you could change this to the value: SalesUpdate::DeliverNow.
Create Auto number from table method in ax 2012

Create Auto number from table method in ax 2012

Description:-

In this article we will see about how to create auto number sequence when we create row in table. Here is the example to create auto number sequence while create row in table.

public void initValue()
{
    str 60 _newCode;
    int max1;
    Stamp ObjStamp;
    super();
    select firstOnly StampId from ObjStamp order by RecId desc;
    if(!ObjStamp.StampId)
    {
        ttsBegin;
        _newCode=strRFix(int2str(1),4, "0");
        this.StampId = _newCode;
        ttsCommit;
    }
    else
    {
        ttsBegin;
        max1=str2int(subStr(ObjStamp.StampId,4,4))+1;
        this.StampId =strRFix(int2str(max1),4, "0");
        ttsCommit;
    }
}

Read XML file in datatable and bind to datalist in asp.net

Description:-

In this article we will see about how to read Xml File in Datatable and bind into datalist in dotnet. Here I have created student xml file and bind into datalist. Here notice that XML file should be physical location t means in your project so we can read it using server method.

Design.aspx:-

    <div>
        <div>
            <asp:Button ID="Button1" runat="server" Text="Click To Read XML" OnClick="Button1_Click" />
        </div>
        <asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#3366CC"
            BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Both">
            <ItemStyle BackColor="White" ForeColor="#003399" />
            <ItemTemplate>
                Id :
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label><br />
                Name :
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("name") %>'></asp:Label><br />
                Address :
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("address") %>'></asp:Label>
            </ItemTemplate>
        </asp:DataList>
    </div>

Default.aspx.cs:-

        public void Button1_Click(object sender, EventArgs e)
        {
            DataTable objDataTable = new DataTable();
            string filepathe = @"XMLFile\XMLFile1.xml";
            objDataTable = ReadXMLFile1(filepathe);
            DataList1.DataSource = objDataTable;
            DataList1.DataBind();
        }

        public DataTable ReadXMLFile1(string filePath)
        {
            DataSet objds = new DataSet();
            objds.ReadXml(Server.MapPath(filePath));
            return objds.Tables[0];
        }

XML File:-

<students>
  <student>
    <id>1</id>
    <name>Umesh Patel</name>
    <address>Ahmedabad</address>
  </student>
  <student>
    <id>2</id>
    <name>Kirit Patel</name>
    <address>Ahmedabad</address>
  </student>
  <student>
    <id>1</id>
    <name>Harpalshinh Gohil</name>
    <address>Ahmedabad</address>
  </student>
  <student>
    <id>1</id>
    <name>Chirag Patel</name>
    <address>Ahmedabad</address>
  </student>
</students>

Output:-

Generate Number Sequence based on Fynancial year in ax 2012

Generate Number Sequence based on Fynancial year in ax 2012

Description:-

In this article we will see about how to generate number sequence based on financial year in ax 2012.
Here I have Create code for generate number sequence.
Create DataSource Create method and copy paste below code and change your table objects.

    str 60 Value;
    str 60 _newCode;
    int max1;
    FiscalCalendarYear  ObjFiscalCalendarYear;
    str CurrentYear,PreYear,NextYear;
    ;
    super(_append);
    //Getting Year start
    select firstOnly ObjFiscalCalendarYear order by ObjFiscalCalendarYear.StartDate desc
    where ObjFiscalCalendarYear.StartDate <= today()
    && ObjFiscalCalendarYear.EndDate >= today();
    if(ObjFiscalCalendarYear)
    {
       CurrentYear = subStr(int2str(year(ObjFiscalCalendarYear.StartDate)),3,2);
       NextYear = subStr(int2str(year(ObjFiscalCalendarYear.StartDate)+1),3,2);
    }
    if(CurrentYear != NextYear)
    {
        select ObjProdEfficiencyTable order by RecId desc
        where ObjProdEfficiencyTable.ProdEfficiencyNo like subStr(int2str(year(ObjFiscalCalendarYear.StartDate)),3,2)+"*";
        if(!ObjProdEfficiencyTable)
        {
            _newCode= CurrentYear + strRFix(int2str(1),8, "0");
            ProdEfficiencyTable.ProdEfficiencyNo =_newCode;
        }
         else
        {
            max1=str2int(subStr(ObjProdEfficiencyTable.ProdEfficiencyNo,8,4))+1;
            ProdEfficiencyTable.ProdEfficiencyNo = CurrentYear + strRFix(int2str(max1),8, "0");
        }
    }

OUTPUT:- 160000001 160000002 160000003
How to validate number in ax 2012

How to validate number in ax 2012

Description:-

In this article we will see about how to validate number based on some expression or else if we want to validate some particular expression like number should be First 5 char, after 5 number after 3 char.

Here is some validation expression so you can use for validate your string value or else in any other object value for some specific Fields.

public boolean validateWrite()
{
    boolean ret;
    #define.alphabets('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
    #define.numbers('0123456789')
    #define.10(10)
    #define.12(12)

    ret = super();

    if (ret && (strkeep(substr(this.RegistrationNumber, 1, 4), #alphabets) != substr(this.RegistrationNumber, 1, 4)) ||
        (strkeep(substr(this.RegistrationNumber, 5, 5), #numbers)   != substr(this.RegistrationNumber, 5, 5)) ||
        (strlen(this.RegistrationNumber)                            != #10)                                   ||
        (strkeep(substr(this.RegistrationNumber, 10, 1), #alphabets)!= substr(this.RegistrationNumber, 10, 1)))
    {
        ret = ret && checkFailed("@GLS5456");
    }
}
Journal has already been posted and, consequently, is not open in ax 2012

Journal has already been posted and, consequently, is not open in ax 2012

Description:-

The cause of this error is when you are trying to post a Journal which is already posted.This mostly happens when you are trying to post using X++ code.

Check if you are passing new record(LedgerJournalTable) to Class LedgerJournalCheckPost everytime you call it for posting.

First time you call the class the selected record gets posted but second time it is stopped in the validation process.As the record is already posted once.
Open form on button click and passing arguements in ax 2012

Open form on button click and passing arguements in ax 2012

Description:-

In this article we will see about how to pass arg, parameter, query and array object in one form through another while clicking on button.

Here is the sample code I have written form opening form and passing multiple arguments in another form.
From-1(on button click event)
void clicked()
{
    FormRun formRun;
    Args    args = new Args();
    str         multiSelectString;
    container   con;
    super();
    con = conIns(con,1, InventTrans.ItemId);
    con = conIns(con,2, InventTransOriginMovement.ReferenceId);
    con = conIns(con,3, _RecId);

    multiSelectString = con2Str(con,',');

    args.name(formstr(Display Menuitem));
    args.caller(this);
    args.parm(multiSelectString);
    args.record(DataSource name);
    args.parmObject(new Query(Pass Query));
    formRun = classfactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.wait();
    formRun.detach();
}

In another form Form-2 check for DataSource what DataSource we are getting from form-1. Here I have override form init method for checking Which table we are getting from Form-1. Also you can check in DataSource init method. Like below.
public void init()
{
    //if not from InventDim dataset
    if( element.args().dataset() == tableNum(InventDim))
    {
        super();
    }
    //if directly open
    if(!element.args().caller())
    {
        throw error("Cannot Run Directly.");
    }
}

In DataSource init method you can get those arguments which you are passing in Form-1. Like below.

//dataset start
    if(element.args().dataset())
    {
        //parmObject start
        if(element.args().parmObject())
        {
            ObjInventDim1 = element.args().record();
            //Getting multipleRecords Value start
            multipleRecords = element.args().parm();
            con = str2con(multipleRecords,",");
            for(i1 = 1;i1<= conLen(con) ;i1++)
            {
                if(i1==1){_ItemId = conPeek(con,i1);}
                if(i1==2){_SalesId = conPeek(con,i1);}
                if(i1==3){_RecId = conPeek(con,i1);}
            }
            //Getting multipleRecords Value end

            query1 = new Query(element.args().parmObject());
            Arrays = element.args().parmObject();
}
//parmObject end
    }
//dataset end