About Me

My photo
a Dynamic and Energetic guy.....

Thursday, April 23, 2009

Play with SQL

// getting today
SET @today = CONVERT(CHAR(8), GETDATE(), 112)

//getting first day of month
SELECT DATEADD(DAY, - DATEPART(DAY, CONVERT(CHAR(8), GETDATE(), 112)) + 1, CONVERT(CHAR(8), GETDATE(), 112)) AS firstDay

//getting last day of month
SELECT DATEADD(DAY, - DATEPART(DAY, CONVERT(CHAR(8), GETDATE(), 112)), DATEADD(MONTH, 1, CONVERT(CHAR(8), GETDATE(), 112))) AS lstDay


IF EXISTS

(
SELECT
Date,IsUnblock
FROM
SOSupervisorRemarks
WHERE (Date = '11/30/2009 12:00:00 AM')
)
UPDATE SOSupervisorRemarks SET IsUnblock='False' WHERE Date = '11/30/2009 12:00:00 AM'
ELSE
INSERT INTO SOSupervisorRemarks (Date,IsUnblock) VALUES ('11/30/2009 12:00:00 AM', 'false')


//Getting Date Value from DateTime
dateadd(dd,0, datediff(dd,0,tblSLSale.ExchangeDate)) as ExchangeDate

Monday, April 20, 2009

Apply a style sheet + style class programatically

Finally we were managed to do this(Apply a style sheet programatically ) :)

Table objTable = new Table();

objTable.Attributes.Add("href", "txtstyle.css");
objTable.Attributes.Add("type", "text/css");
objTable.Attributes.Add("rel", "stylesheet");
objTable.Attributes.Add("class", "ph11");

Page.Controls.Add(objTable);


Remember to add tag in "ASPX" page also
<
link
href="txtstyle.css"
rel="stylesheet"
type="text/css"
/>

Friday, April 17, 2009

Tips in Windows Mobile Development

*** It is a scale down version, So you wont get all features as .NET framework
*** You should install .NET Compact framework(3.5) + SQL compact version.

*** Try to use ShowDialog() other than Show()
*** Use Singleton pattern to avoid load many occurances of single form
*** Its easy to user picture/image buttons than menu click
*** Its good to use cursor until data is loading to the form

*** SQL Compact framework doesn't support statements like "IF EXITS"

*** If you want to connect to a Mobile(Compact) DB in ASP.NET add following method
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
this allow you to connect to a DB that has .SDF extension :)


Thursday, March 12, 2009

Active Directory Properties

Now its simple, You can get more details using the "DirectoryEntry" object

It consists of a hashtable, that includes properties

"countrycode"

"cn"

"lastlogoff"

"usncreated"

"whenchanged"

"memberof"

"accountexpires"

"displayname"

"primarygroupid"

"badpwdcount"

"samaccounttype"

"givenname"

"mail"

"adspath"

"pwdlastset"

"manager"

"logoncount"

"name"

"usnchanged"

"userprincipalname"

"admincount"

"badpasswordtime"

"objectsid"

"distinguishedname"

"lastlogontimestamp"

Sunday, March 8, 2009

How to find selected checkbox controls inside Webpage

using System.Collections.Generic;

protected void StoreSelectedDates()
{
Control[] allControls = FlattenHierachy(Page);

foreach (Control control in allControls)
{
CheckBox mycheckBox = control as CheckBox;
if (mycheckBox != null)
{
if (mycheckBox.Checked)
{
try
{
string setDay = mycheckBox.ID.Substring(3);
}
catch (Exception ex)
{}
}
}
}


private Control[] FlattenHierachy(Control root)

{
List list = new List();
list.Add(root);
if (root.HasControls())
{
foreach (Control control in root.Controls)
{
list.AddRange(FlattenHierachy(control));
}
}
return list.ToArray();
}



How to write a Stored Procedure with a Cursor

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: chanaka
-- Create date: 04/03/2009
-- Description:
-- =============================================
CREATE PROCEDURE dbo.SearchRegionWise
-- Add the parameters for the stored procedure here
@firstPara nvarchar(25),
@secondPara nvarchar(25)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
DROP TABLE TemporySearchData
CREATE TABLE TemporySearchData(OfferID nvarchar(50), UserID nvarchar(50), StartLocation nvarchar(100), Destination nvarchar(100))
DECLARE @firstName nvarchar(25)
DECLARE @nextName nvarchar(25)
DECLARE @addString nvarchar(25)
DECLARE @UserID nvarchar(50)
DECLARE @StartLocation nvarchar(50)
DECLARE @Destination nvarchar(50)

DECLARE firstCursor CURSOR FOR (SELECT LocationName FROM dbo.tblLocation WHERE (RegionId =
(SELECT RegionId FROM dbo.tblLocation AS tblLocation_1 WHERE (LocationName = @firstPara))))
OPEN firstCursor
FETCH NEXT FROM firstCursor INTO @firstName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @firstName

DECLARE loopCursor CURSOR READ_ONLY FOR (SELECT LocationName FROM dbo.tblLocation WHERE (RegionId =
(SELECT RegionId FROM dbo.tblLocation AS tblLocation_1 WHERE (LocationName = @secondPara))))
OPEN loopCursor
FETCH NEXT FROM loopCursor INTO @nextName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @nextName

DECLARE loopInfo CURSOR READ_ONLY FOR (SELECT DISTINCT dbo.tblTravelOffer.tblTravelId, dbo.tblTravelOffer.UserId, dbo.tblTravelOffer.StartLocation, dbo.tblTravelOffer.Destination FROM dbo.tblTravelOffer WHERE dbo.tblTravelOffer.StartLocation = @firstName AND dbo.tblTravelOffer.Destination = @nextName)
OPEN loopInfo
FETCH NEXT FROM loopInfo INTO @addString, @UserID, @StartLocation, @Destination
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO TemporySearchData (OfferID, UserID, StartLocation, Destination)
VALUES (@addString, @UserID, @StartLocation, @Destination)
FETCH NEXT FROM loopInfo INTO @addString, @UserID, @StartLocation, @Destination
END
CLOSE loopInfo
DEALLOCATE loopInfo
FETCH NEXT FROM loopCursor INTO @nextName
END
CLOSE loopCursor
DEALLOCATE loopCursor
FETCH NEXT FROM firstCursor INTO @firstName
END
CLOSE firstCursor
DEALLOCATE firstCursor
select * from dbo.TemporySearchData
END
GO

Friday, March 6, 2009

Get User belongs Active Groups

public string[] getUserBelongsGroup(string userName)
{
DirectoryEntry objDirEntry = GetUserInforamtionFromAD(userName);

PropertyValueCollection objPVC = objDirEntry.Properties["memberof"];
string[] strData = new string[objPVC.Count];
for (int count = 0; count < objPVC.Count; count++)
{
strData[count] = objPVC[count].ToString().Split(new char[] { ',' })[0].Substring(3);
}
return strData;
}


public DirectoryEntry GetUserInforamtionFromAD(string _UserName)
{
// Create a DirectorySearcher object using the user name as the LDAP search filter. If using a directory other than Exchange, use sAMAccountName instead of mailNickname.
string strActualName = _UserName.Split(new char[] {'\\'})[1].ToString();
DirectorySearcher searcher = new DirectorySearcher("(cn=" + strActualName + ")");

// Search for the specified user.
SearchResult result = searcher.FindOne();


if (result == null)
{
return null;
}
else
{
// Create a DirectoryEntry object to retrieve the collection of attributes (properties) for the user.
DirectoryEntry user = result.GetDirectoryEntry();
return user;
}
}

Thursday, February 19, 2009

Create Record Repository inside Sharepoint

1.Create a web application

2.Use “Record Center” template to create site

[eg: http://server03:2222]

3. Central administration --> Application Management --> External Services --> Records Center --> ”Ironone Record Center” -->

http://server03:2222/_vti_bin/officialfile.asmx

4. Create a document library --> Add a document

5. Right Click the document --> Send to "Ironone Record Center"

Tuesday, January 27, 2009

Simple AJAX Application

(1) Install ASP.NET AJAX VS2008

(2) Go to C:\Program Files\Microsoft ASP.NET, you can see ASP.NET 2.0 AJAX Templates for Visual Studio 2008 folder --> that implies your installation is succeeded J

(3) Open Ajax enabled ASP.NET web application through VS 2008

(4) Add two labels & one button(say Button1)

(5) Add following code sample into Page_Load() method

Label1.Text = DateTime.Now.ToString();

Label2.Text = DateTime.Now.ToString() ;

(6) Run the application & check the text changes in labels(both change)

(7) Now time to add AJAX extensions

a. Toolbox --> AJAX Extensions --> UpdatePanel

(8) Add “UpdatePanel” control into webpage

(9) Drag Label2 into the “UpdatePanel” area

(10) Run the application & check the changes in labels(both change)

(11) Now go to the “Source” tab of webpage

(12) After the > ContentTemplate tag add the following code sample

<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />

</Triggers>

(13) Run the application & check the changes in labels(Now only Label1 change)

(14) Your AJAX panel is working J

Tuesday, January 6, 2009

CCF Tips

Problem --> Are you suffering to get "CCF Activities" items in your toolbox?
Solution --> Find C:\Program Files\Microsoft CCF 2008\Source Code\Framework\ InstallCcfActivityToolbox.exe

Note --> Still suffering?
Solution --> Close the Visual Studio, Click
InstallCcfActivityToolbox.exe again, Open Visual Studio again

:)


My Masters