Saturday, May 8, 2010

Loading Bar with JavaScript

Add divs code to your page body, or wherever you want
<div id="div1"> <div
id="Div2" style="border: solid 1px #000000; width: 7px; height: 7px; background-color:
#D3D3D3; float: left; margin-right: 5px; margin-left: 5px;">
<
/div>
<div id="Div3"
style="border: solid 1px #000000; width: 7px; height: 7px; background-color: #D3D3D3;
margin-right: 5px; float: left;"> </div> <div
id="Div4" style="border: solid 1px #000000; width: 7px; height: 7px; background-color:
#D3D3D3; margin-right: 5px; float: left;"> </div>
<
div id="Div5" style="border:
solid 1px #000000; width: 7px; height: 7px; background-color: #D3D3D3; margin-right:
5px; float: left;"><
/div
> <div id="Div6" style="border: solid 1px #000000;
width: 7px; height: 7px; background-color: #D3D3D3; margin-right: 5px; float: left;">< /div>
<div id="Div7"
style="border: solid 1px #000000; width: 7px; height: 7px; background-color: #D3D3D3;
margin-right: 5px; float: left;"> </div
> <div id="Div8" style="border: solid 1px #000000;
width: 7px; height: 7px; background-color: #D3D3D3; margin-right: 5px; float: left;">
</div> </div>

Add these two buttons at the buttom of your progress bar (divs)
<input type ="button" id="btn_StartLoad" value ="Stop Loading" onclick ="StartLoading();" />

<input type="button" id="btn_StopLoad" value="Stop Loading" onclick="StopLoading();" />


Add these javascript functions to the same page which including divs and the two buttons.
var index = 1;
var prevIndex = 0;
var divCount = 7;
var loaded = false;
var Loading;

function StartLoading() {
    if (!loaded)
   {
      Loading = setInterval(DoLoading, 450);
   }
}

function DoLoading() {
  loaded = true;
  if (index > 1 && index != prevIndex) {
    prevIndex = index - 1;
    document.getElementById("loading"
+ prevIndex).style.backgroundColor = "#D3D3D3";
    document.getElementById("loading"
+ prevIndex).style.border = "solid 1px #000000";
  }
  else if (index > 1 && index == prevIndex)
{
    document.getElementById("loading"
+ (prevIndex - 1)).style.backgroundColor = "#000000";
    document.getElementById("loading"
+ (prevIndex - 1)).style.border = "solid 1px red";
    index = 1;
  }
  if (index <= divCount) {     document.getElementById("loading"
+ index).style.backgroundColor = "#000000";
    document.getElementById("loading"
+ index).style.border = "solid 1px red";
  if ((prevIndex - 1) == divCount) {
    document.getElementById("loading"
+ (prevIndex - 1)).style.backgroundColor = "#D3D3D3";
    document.getElementById("loading"
+ (prevIndex - 1)).style.border = "solid 1px #000000";
  }
  index++;
  if (index > divCount) {
    prevIndex = index;
  }
}
}

function StopLoading() {
  clearInterval(Loading);
  for (i = 1; i <= divCount; i++) {     document.getElementById("loading"
+ (i)).style.backgroundColor = "#D3D3D3";
    document.getElementById("loading"
+ (i)).style.border = "solid 1px #000000";
  }
  loaded = false;
  index = 1;
  prevIndex = 0;
  }

Example:


Friday, April 30, 2010

How to display From & To Date Range from Query in Dynamics Ax

If you build a report that use range date you will need to show user which date range he choose 
when he view the report, this method print the date range which user selected it just  add it into
your report header and it'll be like that

Date Range: 01/01/2010..10/01/2010

(Date Range) is the the label of the display method



Display str DateRange()
{
    str rangeValue;
    QueryBuildDataSource datasource;
    QueryBuildRange range;
    ;
    datasource =  element.query().dataSourceTable(tableNum(YourDatasourceTable));
    range = datasource.findRange(fieldnum(YourDatasourceTable, YourDateField));
    if(range)
    {
       rangeValue = range.value();
    }
    return rangeValue;
}

Saturday, September 12, 2009

3 ways to loop into LINQ query output

This article shows us how to iterate into LINQ query output.
to know how let's see this example.

first let's say that we have this class


//Customer class
public class Customer
{
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}

private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}

private string _city;
public string City
{
get { return _city; }
set { _city = value; }
}
}

//then we use object initialization to initialize a list of "Customer"
List<Customer> listofCustomers = new List
<Customer
>{
new Customer{ Id = 1, Name = "ahmed", City = "Cairo" },
new Customer{ Id = 2, Name = "mohamed", City = "Alex" },
new Customer{ Id = 3, Name = "Sameh", City = "Luxor" } };

//now we need to create our LINQ query
var query = listofCustomers
.Where(city => city.City.ToLower() == "alex".ToLower() && city.City.ToLower() == "cairo".ToLower())
.Select(s => new { s.Id, s.Name, s.City }).OrderBy(c => c.City);


now if we need to get data from our query we have many ways here will see 3 ways

1- First way (for loop):
------------------------
int x = query.Count();
for (int z = 0; z < x; z++) { Response.Write(string.Format( "ID = {0}, Name = {1}, City Name ={2}",
query.ElementAt(z).Id, query.ElementAt(z).Name, query.ElementAt(z).City));
}


2-Second way (List.ForEach):
--------------------------------
query.ToList().ForEach(obj => Response.Write(string.Format("ID = {0}, Name = {1}, City Name ={2}", obj.Id, obj.Name, obj.City)));


3- Third way (foreach):
-----------------------------
foreach (var obj in query)
{
Response.Write(string.Format("ID = {0}, Name = {1}, City Name ={2} ", obj.Id,
obj.Name, obj.City));
}

Saturday, April 4, 2009

How to Select All Database tables and columns with datatypes and length in SQL Server 2005

SELECT SysObjects.[Name] as TableName,
SysColumns.[Name] as ColumnName,
CASE SysTypes.[Name]
WHEN
'sysname'
THEN
'nvarchar'
ELSE
SysTypes.[Name]
END
AS [Name]
,
CASE SysTypes.[Name]
WHEN
'nvarchar'
THEN
SysColumns.[Length] / 2
WHEN
'sysname'
THEN
SysColumns.[Length] / 2
ELSE
SysColumns.[Length]
END
AS [Length]
FROM
SysObjects INNER JOIN SysColumns
ON SysObjects.[Id] = SysColumns.[Id]
INNER JOIN SysTypes
ON SysTypes.[xtype] = SysColumns.[xtype]
WHERE SysObjects.[type] =
'U'
ORDER BY SysObjects.[Name]

Friday, July 20, 2007

Control.ClientID in ASP.NET

Hello everyBody,
Today i'll describe a very important things for developers who are working with "ASP.NET" and handle some Codes with "JavaScript " this problem is the [Controls ID on Client Side] when they use (Master Page) or (User Controls) Cause on run time controls take an ID Mostly different to the ID which them specified it at design time
EX:
Design Time:
<input type="button" value="Test" ID="btn_test"/>
______________________________
Run Time:
------------------
Case: Directly Page
{
<input type="button" value="Test" id="btn_test"/>
}
______________________________
Case: UserControl
{
<input type="button" value="Test" id="WebUserControl_btn_test"/>
}
______________________________
Case: Master Page
{
<input type="button" value="Test" id="ct100_Defult_btn_test"/>
}
-----------------------------------------------------------------------------
So if you typed a java script code like that


<script type="text/javascript" language="javascript">
function message()
{
alert(document.getElementById("btn_Test").id);
}
(/script)
------------------------------------------------
it will give us this JavaScript Error
[Object Expected]
Cause the (id) of the control changed so now there is no control with this id, i wish it's clear now.
___________________________
ok io think now you are asking,
what's the solution?
The solution is so simple i think who use ASP classic know it it's one line or less

< % = ControlName in design Time.ClientID % > :)
=================
Tip:
Remove Spaces<%=ControlName in desgin Name.ClientID%>
<%=ControlName in desgin Name.ClientID%>
<%=ControlName in desgin Name.ClientID%>
=================
realy it's so powerful solution for this issue ;)
wish i could help u :)