int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
// Suspend the screen.
Console.ReadLine();
// Compose a string that consists of three lines.
string lines = "First line.\r\nSecond line.\r\nThird line.";
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
file.WriteLine(lines);
file.Close();
Monday, October 25, 2010
Sunday, October 24, 2010
Paging in SQL Server
declare @PageIndex int
declare @pageSize int
declare @startindex int
declare @endindex int
set @PageIndex = 1
set @pageSize = 10
set @startindex = @pageindex
set @endindex = @pagesize
if
(@pageindex > 1)
begin
set @endindex = @pageSize * @PageIndex
set @startindex = (@endindex - @pageSize ) + 1
end
Declare @totalrows int
select @totalrows =count(company_code) from tbl_CMT_Company
select *,@totalrows as totalRecords from
(
select Company_code,name,Arabic_name,
Row_number() over (order by Company_code) as rowindex
from tbl_CMT_Company
) as pageresult
where rowindex >=@startindex and rowindex <=@endindex
declare @pageSize int
declare @startindex int
declare @endindex int
set @PageIndex = 1
set @pageSize = 10
set @startindex = @pageindex
set @endindex = @pagesize
if
(@pageindex > 1)
begin
set @endindex = @pageSize * @PageIndex
set @startindex = (@endindex - @pageSize ) + 1
end
Declare @totalrows int
select @totalrows =count(company_code) from tbl_CMT_Company
select *,@totalrows as totalRecords from
(
select Company_code,name,Arabic_name,
Row_number() over (order by Company_code) as rowindex
from tbl_CMT_Company
) as pageresult
where rowindex >=@startindex and rowindex <=@endindex
Friday, October 22, 2010
how to search value in Array
using System;
class Program
{
static void Main()
{
//
// Example integer array is declared.
//
int[] array = new int[6];
array[0] = 1;
array[1] = 3;
array[2] = 5;
array[3] = 7;
array[4] = 8;
array[5] = 5;
//
// Find index of element with value 5.
//
int index1 = Array.IndexOf(array, 5);
//
// Find index of value 3.
//
int index2 = Array.IndexOf(array, 3);
//
// Find last index of 5.
//
int index3 = Array.LastIndexOf(array, 5);
//
// Write the results.
//
Console.WriteLine(index1);
Console.WriteLine(index2);
Console.WriteLine(index3);
}
}
=== Output of the program ===
2
1
5
if (Array.IndexOf("StringArray", "ValueToFind") != -1)
{
//If found
//your code goes here
}
else
// Not found
class Program
{
static void Main()
{
//
// Example integer array is declared.
//
int[] array = new int[6];
array[0] = 1;
array[1] = 3;
array[2] = 5;
array[3] = 7;
array[4] = 8;
array[5] = 5;
//
// Find index of element with value 5.
//
int index1 = Array.IndexOf(array, 5);
//
// Find index of value 3.
//
int index2 = Array.IndexOf
//
// Find last index of 5.
//
int index3 = Array.LastIndexOf(array, 5);
//
// Write the results.
//
Console.WriteLine(index1);
Console.WriteLine(index2);
Console.WriteLine(index3);
}
}
=== Output of the program ===
2
1
5
if (Array.IndexOf
{
//If found
//your code goes here
}
else
// Not found
Thursday, October 21, 2010
Flagging Unsaved Data
*script language="javascript" type="text/javascript"&
var myarray;
window.onload = function(e)
{
myarray=new Array(document.forms["aspnetForm"].elements.length)
for (var j=0; j < document.forms["aspnetForm"].elements.length; j++)
myarray[j]=new Array(3)
for (var i = 0; i < document.forms["aspnetForm"].elements.length; i++)
{
var element = document.forms["aspnetForm"].elements[i];
var type = element.type;
myarray[i][0] = element;
myarray[i][1] = type;
if (type == "checkbox" || type == "radio")
{
if (element.checked)
myarray[i][2] = true;
else
myarray[i][2] = false;
}
else if (type == "password" || type == "text" ||
type == "textarea")
{
// if( type == "textarea")
// {
// var textDesc = this.editor_getHTML('ctl00_ContentPlaceHolder1_txtBodyMessage');
// if(textDesc != undefined || textDesc != null)
// myarray[i][2] = textDesc;
// else
// {
// if(element.value != "")
// myarray[i][2] = element.value;
// else
// myarray[i][2] = "";
// }
// }
// else
if(element.value != "")
myarray[i][2] = element.value;
else
myarray[i][2] = "";
}
else if (type == "select-one" || type == "select-multiple")
{
for (var j = 0; j < element.options.length; j++)
{
if (element.options[j].selected)
myarray[i][2] = j;
}
}
else
myarray[i][2] = "";
}
};
window.onbeforeunload = function(e)
{
e = e || window.event;
var hdnButton = document.getElementById("hdnClicked");
if( hdnButton != null && hdnButton != '' && hdnButton != undefined)
{
if(hdnButton.value != "save")
{
if (formIsDirty(document.forms["aspnetForm"]))
{
if (e)
e.returnValue = "You have unsaved data on this page and are attempting to navigate away without saving.";
}
}
}
else
{
if (formIsDirty(document.forms["aspnetForm"]))
{
if (e)
e.returnValue = "You have unsaved data on this page and are attempting to navigate away without saving.";
}
}
};
function formIsDirty(form)
{
for (var i = 0; i < form.elements.length; i++)
{
var element = form.elements[i];
var type = element.type;
if (type == "checkbox" || type == "radio")
{
if(myarray[i][2] != undefined)
{
if (element.checked != myarray[i][2])
return true;
}
}
else if (type == "password" || type == "text" ||
type == "textarea")
{
if( myarray[i][2] != undefined)
{
// if(type =="textarea")
// {
// if(element.value != "
// {
// if (element.value != myarray[i][2])
// return true;
// }
// }
// else
if (element.value != myarray[i][2])
return true;
}
}
else if (type == "select-one" || type == "select-multiple")
{
for (var j = 0; j < element.options.length; j++)
{
if (element.options[j].selected)
{
if( j != myarray[i][2])
return true;
}
}
}
}
return false;
}
function GetClicked()
{
var hdnButton = document.getElementById("hdnClicked");
if( hdnButton != null && hdnButton != '' && hdnButton != undefined)
hdnButton.value = "save";
}
*/script*
OnClick="btnSave_Click" ValidationGroup="vldSave" OnClientClick="GetClicked();" />
CS
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
scriptManager.RegisterPostBackControl(btnCancel);
var myarray;
window.onload = function(e)
{
myarray=new Array(document.forms["aspnetForm"].elements.length)
for (var j=0; j < document.forms["aspnetForm"].elements.length; j++)
myarray[j]=new Array(3)
for (var i = 0; i < document.forms["aspnetForm"].elements.length; i++)
{
var element = document.forms["aspnetForm"].elements[i];
var type = element.type;
myarray[i][0] = element;
myarray[i][1] = type;
if (type == "checkbox" || type == "radio")
{
if (element.checked)
myarray[i][2] = true;
else
myarray[i][2] = false;
}
else if (type == "password" || type == "text" ||
type == "textarea")
{
// if( type == "textarea")
// {
// var textDesc = this.editor_getHTML('ctl00_ContentPlaceHolder1_txtBodyMessage');
// if(textDesc != undefined || textDesc != null)
// myarray[i][2] = textDesc;
// else
// {
// if(element.value != "")
// myarray[i][2] = element.value;
// else
// myarray[i][2] = "";
// }
// }
// else
if(element.value != "")
myarray[i][2] = element.value;
else
myarray[i][2] = "";
}
else if (type == "select-one" || type == "select-multiple")
{
for (var j = 0; j < element.options.length; j++)
{
if (element.options[j].selected)
myarray[i][2] = j;
}
}
else
myarray[i][2] = "";
}
};
window.onbeforeunload = function(e)
{
e = e || window.event;
var hdnButton = document.getElementById("hdnClicked");
if( hdnButton != null && hdnButton != '' && hdnButton != undefined)
{
if(hdnButton.value != "save")
{
if (formIsDirty(document.forms["aspnetForm"]))
{
if (e)
e.returnValue = "You have unsaved data on this page and are attempting to navigate away without saving.";
}
}
}
else
{
if (formIsDirty(document.forms["aspnetForm"]))
{
if (e)
e.returnValue = "You have unsaved data on this page and are attempting to navigate away without saving.";
}
}
};
function formIsDirty(form)
{
for (var i = 0; i < form.elements.length; i++)
{
var element = form.elements[i];
var type = element.type;
if (type == "checkbox" || type == "radio")
{
if(myarray[i][2] != undefined)
{
if (element.checked != myarray[i][2])
return true;
}
}
else if (type == "password" || type == "text" ||
type == "textarea")
{
if( myarray[i][2] != undefined)
{
// if(type =="textarea")
// {
// if(element.value != "
")
// {
// if (element.value != myarray[i][2])
// return true;
// }
// }
// else
if (element.value != myarray[i][2])
return true;
}
}
else if (type == "select-one" || type == "select-multiple")
{
for (var j = 0; j < element.options.length; j++)
{
if (element.options[j].selected)
{
if( j != myarray[i][2])
return true;
}
}
}
}
return false;
}
function GetClicked()
{
var hdnButton = document.getElementById("hdnClicked");
if( hdnButton != null && hdnButton != '' && hdnButton != undefined)
hdnButton.value = "save";
}
*/script*
CS
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
scriptManager.RegisterPostBackControl(btnCancel);
Yield
using System;
using System.Collections.Generic;
using System.Text;
namespace Yield
{
class Yield
{
public static class NumberList
{
// Create an array of integers.
public static int[] ints = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
// Define a property that returns only the even numbers.
public static IEnumerable GetEven()
{
// Use yield to return the even numbers in the list.
foreach (int i in ints)
if (i % 2 == 0)
yield return i;
}
// Define a property that returns only the even numbers.
public static IEnumerable GetOdd()
{
// Use yield to return only the odd numbers.
foreach (int i in ints)
if (i % 2 == 1)
yield return i;
}
}
static void Main(string[] args)
{
// Display the even numbers.
Console.WriteLine("Even numbers");
foreach (int i in NumberList.GetEven())
Console.WriteLine(i);
// Display the odd numbers.
Console.WriteLine("Odd numbers");
foreach (int i in NumberList.GetOdd())
Console.WriteLine(i);
}
}
}
using System.Collections.Generic;
using System.Text;
namespace Yield
{
class Yield
{
public static class NumberList
{
// Create an array of integers.
public static int[] ints = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 };
// Define a property that returns only the even numbers.
public static IEnumerable
{
// Use yield to return the even numbers in the list.
foreach (int i in ints)
if (i % 2 == 0)
yield return i;
}
// Define a property that returns only the even numbers.
public static IEnumerable
{
// Use yield to return only the odd numbers.
foreach (int i in ints)
if (i % 2 == 1)
yield return i;
}
}
static void Main(string[] args)
{
// Display the even numbers.
Console.WriteLine("Even numbers");
foreach (int i in NumberList.GetEven())
Console.WriteLine(i);
// Display the odd numbers.
Console.WriteLine("Odd numbers");
foreach (int i in NumberList.GetOdd())
Console.WriteLine(i);
}
}
}
Subscribe to:
Posts (Atom)