Friday, June 26, 2009

Working with Windows Service Using VS 2005

A Windows Serviceis a program which runs continuously in the background of an Operating System. It was formerly known as NT services. Window service internally uses the Service Control Manager (SCM) of the operating system. A service must be installed in a SCM database before it can be launched. SCM controls the entire lifetime of each installed service.

http://www.codeproject.com/KB/cs/MyWindowService.aspx

Monday, June 15, 2009

DataSet Checked Unchecked

This code is used to differenciate between two dataset which are check and which are not
DataSet dsChecked;

DataSet dsUnChecked.Tables[0].Columns.Add("Flag");


for (int counterUC = 0; counterUC < dsUnChecked.Tables[0].Rows.Count; counterUC++)
{

for (int counterCD = 0; counterCD < dsChecked.Tables[0].Rows.Count; counterCD++)
{
if (dsUnChecked.Tables[0].Rows[counterUC]["Route_Code"].ToString() == dsChecked.Tables[0].Rows[counterCD]["Route_Code"].ToString() && (dsUnChecked.Tables[0].Rows[counterUC]["Region_Code"].ToString() == dsChecked.Tables[0].Rows[counterCD]["Region_Code"].ToString()))
{
dsUnChecked.Tables[0].Rows[counterUC]["Flag"] = "1";
break;
}
else
{
dsUnChecked.Tables[0].Rows[counterUC]["Flag"] = "0";
}
}

}

ListBox Operations

Duplicate Data Check
This Code Snippet Is used to Check if Left ListBox has duplicate Data of Right List Box or not
protected void CheckDuplicateItemsFromBox(ListBox lsbRight, ListBox lsbLeft)
{
for (int countRight = 0; countRight < lsbRight.Items.Count; countRight++)
{
for (int countLeft = 0; countLeft < lsbLeft.Items.Count; countLeft++)
{
if (lsbRight.Items[countRight].Text == lsbLeft.Items[countLeft].Text)
{
lsbLeft.Items.RemoveAt(countLeft);
}
}

}
}




Move Left ListBox to Right

protected void MoveLeftListBoxToRightListBox(ListBox leftListBox, ListBox rightListBox)
{
while (leftListBox.Items.Count > 0 && leftListBox.SelectedItem != null)
{
ListItem selectedItem = leftListBox.SelectedItem;
selectedItem.Selected = false;
rightListBox.Items.Add(selectedItem);
leftListBox.Items.Remove(selectedItem);
}

}


Move Right ListBox to Left


protected void MoveRightListBoxToLeftListBox(ListBox leftListBox, ListBox rightListBox)
{
while (rightListBox.Items.Count > 0 && rightListBox.SelectedItem != null)
{
ListItem selectedItem = rightListBox.SelectedItem;
selectedItem.Selected = false;
leftListBox.Items.Add(selectedItem);
rightListBox.Items.Remove(selectedItem);
}
}